WO2022027480A1 - 数据采集方法、装置、Modbus系统及存储介质 - Google Patents

数据采集方法、装置、Modbus系统及存储介质 Download PDF

Info

Publication number
WO2022027480A1
WO2022027480A1 PCT/CN2020/107513 CN2020107513W WO2022027480A1 WO 2022027480 A1 WO2022027480 A1 WO 2022027480A1 CN 2020107513 W CN2020107513 W CN 2020107513W WO 2022027480 A1 WO2022027480 A1 WO 2022027480A1
Authority
WO
WIPO (PCT)
Prior art keywords
data
slave
segment
host
instruction information
Prior art date
Application number
PCT/CN2020/107513
Other languages
English (en)
French (fr)
Inventor
胡树燕
杨晓辉
张召
Original Assignee
华为数字能源技术有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 华为数字能源技术有限公司 filed Critical 华为数字能源技术有限公司
Priority to EP20948320.5A priority Critical patent/EP4184831A4/en
Priority to CN202080007710.0A priority patent/CN114391234A/zh
Priority to PCT/CN2020/107513 priority patent/WO2022027480A1/zh
Publication of WO2022027480A1 publication Critical patent/WO2022027480A1/zh
Priority to US18/162,792 priority patent/US20230188380A1/en

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L12/00Data switching networks
    • H04L12/28Data switching networks characterised by path configuration, e.g. LAN [Local Area Networks] or WAN [Wide Area Networks]
    • H04L12/40Bus networks
    • H04L12/40052High-speed IEEE 1394 serial bus
    • H04L12/40071Packet processing; Packet format
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L12/00Data switching networks
    • H04L12/28Data switching networks characterised by path configuration, e.g. LAN [Local Area Networks] or WAN [Wide Area Networks]
    • H04L12/40Bus networks
    • H04L12/40006Architecture of a communication node
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L12/00Data switching networks
    • H04L12/28Data switching networks characterised by path configuration, e.g. LAN [Local Area Networks] or WAN [Wide Area Networks]
    • H04L12/40Bus networks
    • H04L12/403Bus networks with centralised control, e.g. polling
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L12/00Data switching networks
    • H04L12/28Data switching networks characterised by path configuration, e.g. LAN [Local Area Networks] or WAN [Wide Area Networks]
    • H04L12/40Bus networks
    • H04L2012/40208Bus networks characterized by the use of a particular bus standard
    • H04L2012/40228Modbus
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L12/00Data switching networks
    • H04L12/28Data switching networks characterised by path configuration, e.g. LAN [Local Area Networks] or WAN [Wide Area Networks]
    • H04L12/40Bus networks
    • H04L2012/4026Bus for use in automation systems

Definitions

  • the embodiments of the present application relate to the field of communication technologies, and in particular, to a data acquisition method, a device, a Modbus system, and a storage medium.
  • Modbus protocol is a serial communication protocol, which has become the industry standard of communication protocol in the industrial field, and is a common communication method between industrial electronic devices.
  • the Modbus system includes a master and multiple slaves, and the master is responsible for collecting data from each slave.
  • the Modbus standard protocol stipulates that the master and the slave implement data collection by exchanging Modbus messages.
  • the maximum length of a Modbus message is 256 bytes, and the maximum length of the data field is 252 bytes. That is, the amount of data carried in the data field included in a Modbus message is limited. Taking the length of a collected data as one byte as an example, the maximum amount of data carried in the data field is 252. Limited by the length of the data field, if a slave needs to collect a lot of data, multiple requests and responses are required between the master and the slave to collect all the data of the slave.
  • the embodiments of the present application provide a data collection method, device, Modbus system and storage medium, which can reduce the bus occupancy frequency, increase the occupancy rate, and improve the system real-time performance during the process of data collection through the Modbus system.
  • the technical solution is as follows:
  • a data acquisition method is provided, the data acquisition method is used for a host included in a Modbus system, the Modbus system further includes a plurality of slaves, and the method includes:
  • the host sends a data request message to the first slave, where the data request message carries one or more segment collection instruction information, and each segment collection instruction information in the one or more segment collection instruction information is used to indicate
  • the number is greater than 0 and less than or equal to 256.
  • the host and the slave can collect one or more segmented data in one interaction, and the maximum amount of data carried by each segmented data is 256.
  • a data is represented by a minimum of one byte.
  • a data is represented by a byte, such as a coil data
  • the data carried by each segment data is at most 256 bytes, assuming that a data is represented by two bytes.
  • the amount of data that can be collected by the master and the slave in one interaction will be more.
  • the number of interactions between the master and the slave can be reduced, so that the frequency of bus occupancy can be reduced. It will decrease but the occupancy rate will increase and the communication efficiency will increase.
  • the slave machine since the slave machine provides more data in one response, the master machine will not spend a long time on a slave machine, so the real-time performance of the entire Modbus system will be improved. That is, in this solution, the master and the slave exchange long data packets to improve the communication efficiency and improve the real-time performance of the system.
  • the method further includes: the host determines one or more segmented collection indication information according to the address distribution characteristics of the data to be collected on the first slave.
  • the addresses of the data to be collected on the first slave may be continuous or discontinuous, for example, the register addresses are continuous or discontinuous, and the host determines the segmented collection instruction information according to the address distribution characteristics. , which can collect more valid data to the greatest extent, and can avoid some invalid data in the data collected by the host when the addresses are discontinuous.
  • each segment acquisition instruction information in the one or more segment acquisition instruction information includes a start address and a data quantity; each segment data in the one or more segment data includes a The starting address, the amount of data, and the first data, where the first data is the data read by the first slave according to the corresponding segment collection instruction information.
  • a data request message and a data response message are obtained by extending the Modbus message. That is, the data request message includes a first address field, a first function field, and a first data field.
  • the first address field carries the address of the first slave
  • the first function field carries the first function code
  • the first data field Carrying one or more segmented collection instruction information
  • the first function code is used to instruct the master to request the first slave to perform the function of collecting data
  • the data response message includes a second address field, a second function field and a second data field
  • the second address field carries the address of the first slave
  • the second function field carries the second function code
  • the second data field carries one or more segment data
  • the second function code is used to indicate the function actually performed by the first slave .
  • the first data field also carries the first frame sequence number
  • the second data field also carries the The second frame sequence number, the first frame sequence number and the second frame sequence number are used by the host to perform frame matching between the data request message and the data response message. For example, if the sequence number of the first frame is the same as the sequence number of the second frame, it means that the corresponding data request message and data response message are frames matching messages.
  • the first data field also carries the number of segment requests, and the number of segment requests is used to indicate the number of segments of the data collected by the master requesting the first slave segment;
  • the second data field also carries the number of segment responses, which are divided into segments. The number of segment responses is used to indicate the number of segments of the data actually collected by the first slave.
  • the host can flexibly set the collection time for collecting data on each slave, so as to improve the overall performance of the Modbus system, that is, to ensure communication efficiency, communication quality and system real-time sex.
  • the host sends a corresponding data request message to each of the multiple slaves at the same time to complete a round of collection; or, the host sequentially sends each of the multiple slaves according to the polling sequence.
  • Each slave sends a corresponding data request message to complete a round of collection; or, the master determines the collection time corresponding to the corresponding slave according to the amount of data to be collected on each of the multiple slaves. For the acquisition time corresponding to each of the slaves, a corresponding data request message is sent to each of the multiple slaves.
  • the host when the host requests data collection from all the slaves at the same time, the host does not need to wait for a slave to respond before requesting the next one, which greatly shortens the duration of a round of collection and reduces the time-consuming.
  • a question-and-answer method is adopted between the host and the slave, which can ensure that the host successfully polls the data collected on each slave in a round of collection. data.
  • the host machine can more flexibly determine the collection time corresponding to each slave machine, which can improve the flexibility of the collection method, make full use of system resources, and avoid some slave machines.
  • the data volume of the slave machine is large and the response service is too busy, while the data volume of other slave machines is small but cannot be collected for a long time.
  • the host determines the collection time of the corresponding slave according to the service real-time requirement corresponding to each of the multiple slaves, and the host determines the collection time of the corresponding slave according to the collection time corresponding to each of the multiple slaves.
  • the data on the corresponding slave machine is collected at a higher frequency.
  • the master machine collects the data on the corresponding slave machine at a lower frequency.
  • the host determines the collection time of the corresponding slave according to the data volume of the data to be collected on each of the multiple slaves and the corresponding service real-time requirements, and the host determines the collection time of the corresponding slave according to each of the multiple slaves.
  • the corresponding data request message is sent to each of the multiple slaves, so as to take into account the data volume and real-time requirements at the same time, and improve the overall performance of the Modbus system.
  • a data acquisition method is provided.
  • the data acquisition method is used for a first slave included in a Modbus system.
  • the first slave is one of multiple slaves included in the Modbus system.
  • the Modbus system further includes a master. Methods include:
  • the first slave receives a data request message sent by the host, where the data request message carries one or more segment collection instruction information, and each segment collection instruction information in the one or more segment collection instruction information is used for Instruct the host to collect data from the first slave; the first slave collects instruction information according to one or more segments to determine one or more segmented data; the first slave sends a data response message to the host, the The data response packet carries one or more pieces of data, and the amount of data carried by each piece of the one or more pieces of data is greater than 0 and less than or equal to 256.
  • the host and the slave can collect one or more segmented data in one interaction, and the maximum amount of data carried by each segmented data is 256.
  • a data is represented by a minimum of one byte.
  • a data is represented by a byte, such as a coil data
  • the data carried by each segment data is at most 256 bytes, assuming that a data is represented by two bytes.
  • the amount of data that can be collected by the master and the slave in one interaction will be more.
  • the number of interactions between the master and the slave can be reduced, so that the frequency of bus occupancy can be reduced. It will decrease but the occupancy rate will increase and the communication efficiency will increase.
  • the slave machine since the slave machine provides more data in one response, the master machine will not spend a long time on a slave machine, so the real-time performance of the entire Modbus system will be improved. That is, in this solution, the master and the slave exchange long data packets to improve the communication efficiency and improve the real-time performance of the system.
  • each segment collection instruction information in the one or more segment collection instruction information includes a start address and a data quantity; the first slave determines a or multiple pieces of data, including: the first slave reads the data of the first data quantity continuously from the first starting address to obtain the first data, and the first starting address is the starting point included in the first segment collection instruction information address, the first data quantity is the data quantity included in the first segment collection instruction information, and the first segment collection instruction information is one of one or more segment collection instruction information; the first slave sends the first start address, The first data amount and the first data serve as one segment data.
  • the first slave obtains the one or more segment data after reading all the data according to each segment acquisition instruction information in the one or more segment acquisition instruction information.
  • a data request message and a data response message are obtained by extending the Modbus message.
  • the data request message and the data response message please refer to the related introduction of the foregoing first aspect, which will not be repeated here.
  • a data acquisition device in a third aspect, is provided, and the data acquisition device has the function of implementing the behavior of the data acquisition method in the first aspect.
  • the data collection device includes one or more modules, and the one or more modules are used to implement the data collection method provided in the first aspect above.
  • an embodiment of the present application provides a data acquisition device, the device is used for a host included in a Modbus system, the Modbus system further includes a plurality of slaves, and the device includes:
  • a sending module configured to send a data request message to the first slave, where the data request message carries one or more segment collection instruction information, and each segment collection instruction in the one or more segment collection instruction information The information is used to indicate the data that the master needs to collect from the first slave, and the first slave is one of multiple slaves;
  • the receiving module is configured to receive a data response message sent by the first slave, where the data response message carries one or more segment data, and the one or more segment data is the response of the first slave to the one or more segments.
  • the data provided by the collection indication information for each segment, the data quantity carried by each segment data in the one or more segment data is greater than 0 and less than or equal to 256.
  • the device also includes:
  • a determination module configured to determine the one or more segmented collection instruction information according to the address distribution characteristics of the data to be collected on the first slave.
  • each segment collection instruction information in the one or more segment collection instruction information includes a start address and a data quantity
  • Each segment data in the one or more segment data includes a start address, a data quantity and first data, where the first data is data read by the first slave according to the corresponding segment collection instruction information.
  • the data request message includes a first address field, a first function field, and a first data field
  • the first address field carries the address of the first slave
  • the first function field carries the first function code
  • the first data field carries the one or more segmented collection instruction information
  • the first function code is used to instruct the master to request the first slave to perform the function of collecting data
  • the data response message includes a second address field, a second functional field and a second data field.
  • the second address field carries the address of the first slave
  • the second functional field carries the second function code
  • the second data field carries the one or multiple pieces of data
  • the second function code is used to indicate the function actually performed by the first slave.
  • the first data field also carries the first frame serial number
  • the second data field also carries the second frame serial number
  • the first frame serial number and the second frame serial number are used by the host to frame the data request message and the data response message. match.
  • the first data field also carries the segment request number, and the segment request number is used to indicate the segment number of the data collected by the master requesting the first slave segment;
  • the second data field also carries the segment response number, where the segment response number is used to indicate the segment number of the data actually segmented and collected by the first slave.
  • the host sends a corresponding data request message to each of the multiple slaves at the same time to complete a round of collection; or, the host sequentially sends the multiple slaves to the multiple slaves according to the polling sequence.
  • Each of the slaves sends a corresponding data request message to complete a round of collection; or, the host determines the collection time corresponding to the corresponding slave according to the amount of data to be collected on each of the multiple slaves, The host sends a corresponding data request message to each of the multiple slaves according to the collection time corresponding to each of the multiple slaves.
  • a data acquisition device in a fourth aspect, is provided, and the data acquisition device has a function of implementing the behavior of the data acquisition method in the second aspect.
  • the data collection device includes one or more modules, and the one or more modules are used to implement the data collection method provided in the second aspect above.
  • an embodiment of the present application provides a data acquisition device, which is used for a first slave included in a Modbus system, where the first slave is one of a plurality of slaves included in the Modbus system, and the Modbus system also Including the host, the device includes:
  • the receiving module is used to receive a data request message sent by the host, where the data request message carries one or more segment collection instruction information, and each segment collection instruction information in the one or more segment collection instruction information is used for To instruct the master to collect data from the first slave;
  • a determining module configured to collect instruction information according to the one or more segments, and determine one or more segment data
  • a sending module configured to send a data response message to the host, where the data response message carries the one or more segment data, and the amount of data carried by each segment data in the one or more segment data is greater than 0, and Less than or equal to 256.
  • each segment collection instruction information in the one or more segment collection instruction information includes a start address and a data quantity
  • Determining modules include:
  • the reading sub-module is used to continuously read the data of the first data quantity from the first starting address to obtain the first data.
  • the first starting address is the starting address included in the first segmented collection instruction information
  • the first data quantity is the amount of data included in the first segment collection instruction information, where the first segment collection instruction information is one of the one or more segment collection instruction information;
  • a determination submodule is used for taking the first start address, the first data quantity and the first data as one segment data.
  • a data acquisition device is provided, the device is used for a host included in a Modbus system, the Modbus system further includes a plurality of slaves, and the device includes a memory and a processor.
  • the memory is used to store a computer program
  • the processor is used to execute the computer program stored in the memory to implement the data collection method provided in the first aspect.
  • a data acquisition device is provided, the device is used for a first slave included in a Modbus system, the first slave is one of multiple slaves included in the Modbus system, and the Modbus
  • the system also includes a host, and the apparatus includes a processor and a memory.
  • the memory is used to store a computer program, and the processor is used to execute the computer program stored in the memory to implement the data collection method provided in the second aspect above.
  • a Modbus system in a seventh aspect, includes a master and multiple slaves, and the first slave is one of the multiple slaves;
  • the host is used to implement the data collection method provided by the first aspect
  • the first slave is used to implement the data collection method provided in the second aspect.
  • a computer-readable storage medium where a computer program is stored in the computer-readable storage medium, and when it runs on a computer, the computer executes the data described in the first aspect or the second aspect Collection method.
  • a computer program product containing instructions, which, when executed on a computer, cause the computer to execute the data collection method described in the first aspect or the second aspect.
  • the host and the slave can collect one or more segmented data in one interaction, and the maximum amount of data carried by each segmented data is 256.
  • a piece of data is represented by at least one byte, and the data carried by each segmented data is at most 256 bytes. If multiple segmented data can be collected in one interaction, the amount of data that can be collected will be much larger. 252 bytes due to the protocol limit. That is to say, in this solution, the amount of data that can be collected by the master and the slave in one interaction will be more. Under the condition that the amount of data to be collected is certain, the number of interactions between the master and the slave can be reduced, so that the frequency of bus occupancy can be reduced. It will decrease but the occupancy rate will increase and the communication efficiency will increase. In addition, since the slave machine provides more data in one response, the master machine will not spend a long time on a slave machine, so the real-time performance of the entire Modbus system will be improved.
  • FIG. 1 is a system architecture diagram involved in a data collection method provided by an embodiment of the present application.
  • FIG. 2 is a schematic structural diagram of a computer device provided by an embodiment of the present application.
  • FIG. 3 is a flowchart of a data collection method provided by an embodiment of the present application.
  • FIG. 4 is a schematic diagram of frame matching between a host and a first slave provided by an embodiment of the present application
  • FIG. 5 is a schematic diagram of a method for a host to collect data on multiple slaves provided by an embodiment of the present application
  • FIG. 6 is a schematic diagram of another method for a host to collect data on multiple slaves provided by an embodiment of the present application.
  • FIG. 7 is a schematic structural diagram of a data acquisition device provided by an embodiment of the present application.
  • FIG. 8 is a schematic structural diagram of another data acquisition apparatus provided by an embodiment of the present application.
  • the network architecture and service scenarios described in the embodiments of the present application are for the purpose of illustrating the technical solutions of the embodiments of the present application more clearly, and do not constitute a limitation on the technical solutions provided by the embodiments of the present application.
  • the evolution of the architecture and the emergence of new business scenarios, the technical solutions provided in the embodiments of the present application are also applicable to similar technical problems.
  • FIG. 1 is a system architecture diagram involved in a data collection method provided by an embodiment of the present application.
  • the system is a Modbus system, see FIG. 1 , the Modbus system includes a master 101 and a plurality of slaves 102 , and the master 101 and each slave 102 can be connected by wire or wireless for communication.
  • the first slave 102 is one of the multiple slaves 102 , and the host 101 is used to send data to the first slave 102 A request message, where the data request message carries one or more pieces of segment collection indication information, indicating that the master 101 will collect data on the first slave 102 in segments.
  • the first slave 102 is configured to read the corresponding data in segments according to the received data request message to determine one or more segmented data, and send a data response message carrying the segmented data to the host 101 .
  • the master 101 and other slaves 102 in the plurality of slaves 102 except the first slave 102 can all collect data on the corresponding slaves 102 in the same interactive manner as the first slave 102 .
  • the maximum amount of data carried by each segment data collected by the host 101 is 256.
  • the data collected in one request and response of this scheme will not be limited to 252 bytes, that is, this scheme can improve communication efficiency through long data packets.
  • the master 101 is referred to as a centralized controller, a data center, an enterprise command center (ECC), etc.
  • the slave 102 is referred to as a southbound device.
  • the host 101 is a computer, a controller, a server and other equipment
  • any slave 102 is an electromagnetic lock, an automatic sliding door, an access control machine, an emergency button, an access control actuator, a sunroof electromagnetic lock, a sunroof actuator, Wireless local area network (wireless fidelity, WiFi) converter, camera, computer, mobile phone, cabinet door sensor, cabinet electronic lock, temperature sensor, water immersion sensor, sound and light alarm, intelligent remote power distribution unit (rPDU) , Intelligent U position manager, air conditioner, power distribution cabinet, intelligent busway and other equipment.
  • wireless fidelity, WiFi Wireless local area network
  • FIG. 2 is a schematic structural diagram of a computer device according to an embodiment of the present application.
  • the computer device is the host 101 or the slave 102 shown in FIG. 1 , and the computer device includes one or more processors 201 , a communication bus 202 , a memory 203 and one or more communication interfaces 204 .
  • the processor 201 is a general-purpose central processing unit (CPU), a network processor (NP), a microprocessor, or one or more integrated circuits for implementing the solution of the present application, for example, an application-specific integrated circuit ( application-specific integrated circuit, ASIC), programmable logic device (programmable logic device, PLD) or a combination thereof.
  • the above-mentioned PLD is a complex programmable logic device (complex programmable logic device, CPLD), a field-programmable gate array (field-programmable gate array, FPGA), a general array logic (generic array logic, GAL) or any of them. combination.
  • the communication bus 202 is used to transfer information between the aforementioned components.
  • the communication bus 202 is divided into an address bus, a data bus, a control bus, and the like.
  • address bus a data bus
  • control bus a control bus
  • only one thick line is used in the figure, but it does not mean that there is only one bus or one type of bus.
  • the memory 203 is a read-only memory (read-only memory, ROM), a random access memory (random access memory, RAM), an electrically erasable programmable read-only memory (electrically erasable programmable read-only memory, EEPROM) , optical disc (including compact disc read-only memory, CD-ROM, compact disc, laser disc, digital versatile disc, Blu-ray disc, etc.), magnetic disk storage media or other magnetic storage devices, or can be used for portable or any other medium that stores desired program code in the form of instructions or data structures and that can be accessed by a computer, but is not limited thereto.
  • the memory 203 exists independently and is connected to the processor 201 through the communication bus 202, or the memory 203 is integrated with the processor 201.
  • the Communication interface 204 uses any transceiver-like device for communicating with other devices or a communication network.
  • the communication interface 204 includes a wired communication interface and, optionally, a wireless communication interface.
  • the wired communication interface is, for example, an Ethernet interface.
  • the Ethernet interface is an optical interface, an electrical interface or a combination thereof.
  • the wireless communication interface is a wireless local area network (wireless local area network, WLAN) interface, a cellular network communication interface, or a combination thereof.
  • WLAN wireless local area network
  • the computer device includes multiple processors, such as processor 201 and processor 205 as shown in FIG. 2 .
  • processors such as processor 201 and processor 205 as shown in FIG. 2 .
  • Each of these processors is a single-core processor, or a multi-core processor.
  • a processor herein refers to one or more devices, circuits, and/or processing cores for processing data (eg, computer program instructions).
  • the computer device further includes an output device 206 and an input device 207 .
  • the output device 206 is in communication with the processor 201 and can display information in a variety of ways.
  • the output device 206 is a liquid crystal display (LCD), a light emitting diode (LED) display device, a cathode ray tube (CRT) display device, a projector, or the like.
  • the input device 207 communicates with the processor 201 and can receive user input in a variety of ways.
  • the input device 207 is a mouse, a keyboard, a touch screen device, a sensor device, or the like.
  • the memory 203 is used to store program code 210 (also referred to as a computer program) for executing the solutions of the present application, and the processor 201 can execute the program code 210 stored in the memory 203 .
  • the program code 210 includes one or more software modules, and the computer device can implement the data collection method provided by the embodiment of FIG. 3 below through the processor 201 and the program code 210 in the memory 203 .
  • the memory 203 is used to store the program code 210
  • the processor 201 is used to execute the program code 210 stored in the memory 203 to implement the corresponding functions of the host in the data collection method provided by the embodiment of the present application.
  • the program code 210 may include a sending module and a receiving module, and the sending module is used to send data to the slave. Request message, the receiving module is used to receive the data response message sent by the slave.
  • the memory 203 is used to store the program code 210
  • the processor 201 is used to execute the program code 210 stored in the memory 203, so as to realize the corresponding functions of the slave in the data acquisition method provided by the embodiment of the present application .
  • the program code 210 may include a receiving module, a determining module and a sending module, and the receiving module It is used for receiving a data request message sent by the host, the determining module is used for determining segment data according to the data request message, and the sending module is used for sending a data response message to the host.
  • FIG. 3 is a flowchart of a data collection method provided by an embodiment of the present application.
  • the data acquisition method is used in a Modbus system, and the Modbus system includes a master and a plurality of slaves.
  • the method includes the following steps.
  • Step 301 The host sends a data request message to the first slave, the data request message carries one or more segment collection indication information, and each segment collection indication information in the one or more segment collection indication information It is used to indicate the data that the master needs to collect from the first slave.
  • the Modbus system includes a master and multiple slaves, and the master can collect data on each of the multiple slaves, for example, collect register data, coil data, and the like.
  • the master can collect data on each of the multiple slaves, for example, collect register data, coil data, and the like.
  • this will be introduced by taking the host computer collecting data on the first slave as an example, and the first slave is one of multiple slaves.
  • the host sends a data request message to the first slave, where the data request message carries one or more segment collection indication information, and each segment collection in the multiple segment collection instruction information is collected
  • the indication information is used to indicate the data that the master needs to collect from the first slave. That is, in this embodiment of the present application, the master can collect data in the first slave in sections.
  • the addresses of the data to be collected on the first slave may be continuous or discontinuous.
  • the register addresses are continuous or discontinuous, before the master sends a data request message to the first slave, It is also possible to first determine the one or more segmented collection instruction information according to the address distribution characteristics of the data to be collected on the first slave, that is, the address distribution characteristics of the data to be collected on the first slave are used to instruct the host to determine the one or more segments.
  • a segment collection instruction information may be continuous or discontinuous.
  • the developer before the first slave is added to the Modbus system, the developer writes the address distribution characteristics corresponding to the first slave into the master.
  • the supplier provides product-related information of the air conditioner to the developer, and the product-related information includes the address distribution characteristics corresponding to the air conditioner, for example, the address distribution characteristics of registers, the The address distribution feature is used to describe which register is used to store temperature, which register is used to store wind speed, etc., and then the developer writes the product-related information of this air conditioner into the host.
  • the host After this air conditioner is added to the Modbus system, the host When data on this air conditioner needs to be collected, one or more segmented collection instruction information can be determined according to the address distribution characteristics corresponding to this air conditioner.
  • the host determines the segmented collection instruction information according to the address distribution characteristics, which can collect more valid data to the greatest extent, and can avoid some invalid data in the data collected by the host in the case of discontinuous addresses.
  • each piece of the one or more pieces of piece collection indication information includes a start address and a data quantity, so as to indicate the amount of data that needs to be pieced collected in the first slave.
  • Each start address and the corresponding amount of data are a start address and the corresponding amount of data.
  • the length of the start address is two bytes, and the length of the data quantity is one byte, that is, the master can address and collect data from the slave from 0-65535, and the value of the data quantity expressed in binary is greater than 0 and less than or equal to 256, indicating that the corresponding segment collection instruction information is used to instruct the segment to collect at most 256 data, for example, the segment collects at most 256 register data.
  • a data request message is obtained by extending the Modbus message.
  • the data request message includes a first address field, a first functional field, and a first data field.
  • the first address field carries the address of the first slave
  • the first functional field carries the first function code
  • the first data field carries the one or A plurality of segments collect instruction information
  • the first function code is used to instruct the master to request the first slave to perform the function of collecting data.
  • the length of the first address field is one byte, that is, the address of the first slave is represented by one byte, and the length of the first function field is one byte or two bytes.
  • the first function code included in the first function domain is a user-definable function code reserved by the Modbus protocol, that is, any function code in decimal 65-72 and 100-110, the first function code
  • the length of the first function domain is one byte, that is, when the first function domain includes the first function code, the length of the first function domain is one byte.
  • corresponding functions can also be indicated by defining sub-function codes, that is, the first function domain carries the first function code, It also carries a first sub-function code, and the first sub-function code and the first function code together instruct the host to request the first slave to perform the function of collecting data.
  • the length of the first sub-function code is one byte, and the value is any one of 0-255 in decimal. In the case where the first function domain includes the first function code and the first sub-function code, the length of the first function domain is two bytes.
  • the first data field also carries the first frame number
  • the first slave can use the first frame number according to the first frame number.
  • the data response message carries the second frame sequence number.
  • the first frame sequence number and the second frame sequence number are used by the host to match the data request message with The data response message performs frame matching. For example, if the sequence number of the first frame is the same as the sequence number of the second frame, it means that the corresponding data request message and data response message are frames matching messages.
  • the length of the first frame sequence number is one byte, and the value is any one of decimal 0-255, or the first frame sequence number is two bytes, and the value is any one of decimal 0-65535, Or the first frame sequence number is other length. That is, the maximum value of the first frame sequence number can be defined according to communication requirements.
  • the first data field also carries the number of segment requests, where the number of segment requests is used to indicate the number of segments of the data that the master requests the first slave to segment and collect. That is, the host directly carries the requested number of segments in the data request message, and the first slave does not need to accumulate and calculate the number of segments according to one or more segments to collect instruction information.
  • the length of the number of segment requests is a specified length, for example, one byte, indicating that data is collected in at most 256 segments.
  • the maximum length of the packet is limited by the number of segment requests to ensure communication quality.
  • the master needs to collect all the data on the first slave through multiple requests, and collect a part of the data each time.
  • the data response message carrying all the data on the first slave is lost, or when the first slave fails to respond after a timeout, the master cannot collect any data.
  • the length of the number of segment requests is not limited, and the host determines the number of segment requests according to the amount of data to be collected on the first slave and the address distribution characteristics, so as to collect the data on the first slave through one interaction, and the maximum Reduce the number of interactions to a certain extent and improve communication efficiency.
  • the master determines that the data on the first slave can be collected by dividing into 20 segments
  • the length of the segment request number is one byte
  • the decimal value is 20.
  • the length of the segment request number is two bytes, and the decimal value is 500.
  • the first data field also carries a first data length, and the value of the first data length is 0xFF in hexadecimal, indicating that the first data length is an invalid value, and the first slave obtains this value by parsing the data request message.
  • the host does not limit the length of the data to be collected by the first data length, so the first data length is directly ignored.
  • this scheme does not limit The data length is used to improve the communication efficiency by exchanging long data packets.
  • Table 1 is a description of the format of a data request message provided by the embodiment of the present application.
  • the data request message includes a first address field (not shown) and a first protocol data unit (protocol data unit, PDU), the first PDU includes a first functional field and a first data field, and the first functional field Carry the first function code and the first sub-function code.
  • the lengths of the first function code and the first sub-function code are both one byte.
  • the value of the first function code is 0x41 in hexadecimal.
  • the value of the first sub-function code is 0x33 in hexadecimal.
  • the first data field carries the first data length, the first frame sequence number, the number of segment requests, and the collection indication information of n segments.
  • the length of the first data length is one byte, and the value is hexadecimal 0xFF, indicating that the first data length is an invalid value
  • the length of the first frame serial number is one byte
  • the first frame serial number is set by the host.
  • the second frame sequence number backfilled by the first slave in the data response message is the same as the first frame sequence number.
  • each segmented collection instruction information includes a starting address and a data quantity.
  • the length of the starting address is two bytes, and the data quantity is equal to The length is one byte, indicating that the first slave needs to continuously read the data of this amount of data starting from the starting address.
  • a working mode based on the Modbus protocol is selected between the master and the slave, and the working modes of the Modbus protocol include the bus mode of the Modbus remote terminal unit (RTU), the Modbus transmission control protocol (transmission control protocol, TCP) network mode, etc.
  • RTU Modbus remote terminal unit
  • TCP transmission control protocol
  • the data request message sent by the host carries the first address field, the first function field and the first data field.
  • TCP transmission control protocol
  • the data request message sent by the host carries the first address field, the first function field and the first data field.
  • Step 302 The first slave receives the data request message sent by the host.
  • the host after the host sends a data request message to the first slave, it sends the data request message to the first slave according to the address of the first slave carried in the data request message.
  • the slave receives the data request message sent by the master.
  • Step 303 The first slave determines one or more segment data according to the one or more segment collection instruction information, and the amount of data carried by each segment data in the one or more segment data is greater than 0, and less than or equal to 256.
  • the first slave after receiving the data request message, can read the corresponding data in segments according to one or more segment indication information carried in the data request message to determine one or more segments. Multiple segmented data.
  • each segment data in the one or more segment data includes a start address, a data quantity, and first data
  • the first data is an instruction for the first slave to collect according to the corresponding segment Information read data. It should be noted that the amount of data carried by each of the one or more segment data is greater than 0 and less than or equal to 256.
  • each segment acquisition instruction information in the one or more segment acquisition instruction information includes a start address and a data quantity
  • the first slave reads the first data quantity continuously from the first start address. data to obtain the first data, and then the first slave takes the first start address, the first data quantity and the first data as a segmented data.
  • the first starting address is the starting address included in the first segmented collection instruction information
  • the first data quantity is the data quantity included in the first segmented collection instruction information
  • the first segmented collection instruction information is one or more segments One of the segment acquisition instructions.
  • the first slave After the first slave reads all the data according to each segment acquisition instruction information in the one or more segment acquisition instruction information, it obtains the one or more segment data, and the one or more segment data is The data provided for the first slave is responsive to the one or more segment acquisition indication information.
  • the length of the first data included in each segment data is the corresponding data quantity multiplied by the unit data length
  • the unit data length refers to the length of one piece of data collected by the host.
  • the length of one register data is two pieces.
  • the corresponding unit data length is equal to two bytes
  • the length of one coil data is one byte
  • the corresponding unit data length is equal to one byte.
  • the master collects register data on the first slave
  • the length of one register data is two bytes
  • the unit data length is equal to two bytes
  • the above starting address is the register address
  • the number of data is the number of registers
  • the first The data request message received by the slave carries 3 pieces of segment collection instruction information.
  • the first segment collection instruction information includes register address D1 and register number N1
  • the second segment collection instruction information includes register address D2 and register number.
  • the third segment acquisition instruction information includes register address D3 and register number N3, then the first slave reads N1 register data continuously from D1 to obtain the first segment data.
  • the length is 2*N1
  • N2 register data are continuously read from D2 to obtain the second segment data.
  • the length of the second segment data is 2*N2, and N3 register data are continuously read from D3 to obtain
  • the third segment data, the length of the third segment data is 2*N3.
  • the first slave After reading the one or more segmented data, the first slave encapsulates the one or more segmented data in a data response message, that is, the data response message carries the one or more segmented data .
  • the Modbus message is also expanded to obtain a data response message.
  • the data response message includes a second address field, a second function field, and a second data field.
  • the second address field carries the address of the first slave
  • the second function field carries the second function code
  • the second data field carries the one or A plurality of segment data
  • the second function code is used to indicate the function actually performed by the first slave.
  • the length of the second address field is one byte, that is, the address of the first slave is represented by one byte, and the values of the second address field and the second function field are the same.
  • the length of the second functional domain is one byte or two bytes. It should be noted that the value of the second functional domain is the same as the function code carried by the first functional domain, indicating that the first slave has correctly executed the execution requested by the host.
  • the second function domain also includes only the second function code, and when the first slave correctly executes the corresponding function, the second function code and the The first function code is the same.
  • the second function domain also includes the second function code and the second sub-function code, and the first slave is correct.
  • the second function code is the same as the first function code
  • the second sub-function code is also the same as the first sub-function code.
  • the first function domain includes a first function code and a first sub-function code
  • the first function code is 0x41 in hexadecimal
  • the first sub-function code is 0x33 in hexadecimal.
  • the second function field includes the second function code and the second sub-function code, and the second function code is also hexadecimal 0x41, and the second sub-function code is also hexadecimal 0x33 to make.
  • the first data field also carries the first frame serial number.
  • the second data field also carries the second frame serial number, the first frame serial number and
  • the second frame sequence number is used by the host to perform frame matching between the data request message and the data response message. For example, after the first slave parses the data request message and obtains the first frame serial number, the first slave sets the second frame serial number carried in the data response message to be the same as the first frame serial number to instruct the host to respond to the data The message is frame-matched with the data request message.
  • the length of the second frame sequence number is the same as that of the first frame sequence number, which is one byte, two bytes, or other lengths.
  • the second data field also carries the number of segment responses, where the number of segment responses is used to indicate the number of segments of the data actually collected by the first slave. That is, the first slave directly carries the number of segments actually responded in the data response message, without the need for the host to accumulate and calculate the number of segments according to one or more segment data.
  • the number of segment responses is the same as the number of segment requests.
  • the length of the number of segmented responses is the same as the length of the number of segmented requests, that is, the number of segmented responses and the number of segmented requests are corresponding fields, so as to ensure that the host and the slave encapsulate the corresponding fields according to the same length.
  • the message is converted into a message to ensure that both parties in the communication can correctly parse the message.
  • the second data field also carries a second data length, and the value of the second data length is 0xFF in hexadecimal, indicating that the second data length is an invalid value.
  • the first slave when the first slave collects instruction information according to a segment and does not address and read data, the first slave can use the corresponding start address, data quantity and error information as the corresponding Fragmented data to indicate that the host did not get the corresponding data.
  • the error information is represented by one byte, and the value is 0xFF, indicating that the corresponding segment data is invalid.
  • Table 2 is a description of the format of a data response message provided by the embodiment of the present application.
  • the data response message includes a second address field (not shown) and a second protocol data unit (protocol data unit, PDU), the second PDU includes a second functional field and a second data field, and the second functional field Carry the second function code and the second sub-function code.
  • the length of the second function code and the second sub-function code is one byte.
  • the second function code is the same as the first function code, which is ten Hexadecimal 0x41
  • the second sub-function code is the same as the first sub-function code, hexadecimal 0x33.
  • the second data field carries the second data length, the second frame sequence number, the number of segment responses, and n pieces of segment data.
  • the length of the second data length is one byte, and the value is 0xFF in hexadecimal, indicating that the second data length is an invalid value
  • the length of the second frame serial number is one byte
  • the second frame serial number is the same as that of the first frame.
  • each segmented data includes a starting address, a data quantity and a first data
  • the length of the starting address is two bytes
  • the data quantity The length of is one byte, indicating that the first slave has read the amount of data from the starting address
  • the length of the first data is the unit data length multiplied by the corresponding data amount.
  • the length of the first data carried by the segment data is 2*munRegBlocki, and the total length of the i-th segment data is 3+2*munRegBlocki.
  • the number of segment requests and the number of segment responses are both represented by one byte, and the values are both numBlock, then the maximum value of numBlock is 256, indicating that the master segment request and the slave segment response can at most Data is collected in 256 segments.
  • the amount of data carried by each segment is represented by one byte, that is, the maximum amount of data carried by each segment is 256.
  • the data volume of a data can be up to 2*256 bytes, that is, 512 bytes.
  • the working mode configured by the master is the bus mode of Modbus RTU or the network mode of Modbus TCP.
  • the first slave when the master selects the bus mode of Modbus RTU, the first slave also encapsulates the data response according to the bus mode of Modbus RTU.
  • the message that is, the data response message, carries the second address domain, the second functional domain and the second data domain.
  • the host computer selects the Modbus TCP network mode
  • the first slave also encapsulates the data according to the Modbus TCP network mode.
  • the response message that is, the data response message carries the second TCP header, the second Modbus TCP header and the second Modbus data frame, and the second Modbus data frame includes the second address field, the second function field and the second Modbus data frame. data field.
  • Step 304 The first slave sends a data response message to the host, where the data response message carries the one or more segment data.
  • the first slave after encapsulating and obtaining the data response message, the first slave sends the data response message to the host.
  • Step 305 The master receives the data response message sent by the first slave.
  • the host after receiving the data response message sent by the first slave, the host can parse and obtain one or more segmented data carried in the data response message, that is, obtain the data to be collected.
  • the host sends the data request message carried in the data request message with the same first frame sequence number as the second frame sequence number.
  • the message is matched to determine that a correctly matched data response message is received. If the second frame sequence number carried by the data response packet sent by the first slave is different from the first frame sequence number, the host determines that the data response packet is an abnormal packet, and discards the data response packet, or uses it as a historical data response packet. data processing, or other processing.
  • a timeout response mechanism is configured between the master and the first slave, and the master waits for the first slave to respond before the first slave does not respond with a timeout, and when the master receives the first slave response , to determine whether the second frame sequence number of the response is the same as the first frame sequence number of the request. If the frame sequence number is the same, the host receives the data response message normally. If the frame sequence number is different, the host determines that the data response message is an abnormal message. The master continues to wait for the first slave to respond with a correct data response message before the first slave responds with a timeout.
  • the host determines that the data response message is an abnormal message, The host re-sends a data request message to the first slave to request data collection, and the first frame sequence number carried in the data request message sent at this time is the same or different from the first frame sequence number carried in the data request message sent last time.
  • the first slave is the air conditioner 1, the master sends a data request message carrying the frame sequence number 1 to the first slave at time t1, the first slave does not respond after a timeout, and the master sends a data request message to the first slave at time t4.
  • the first slave sends a data request message carrying frame number y, and the host receives a data response message with frame number 1 in response to the first slave response at time t5. Since the frame number of the response is not y, the host will The data response message carrying the frame sequence number 1 is discarded.
  • the host receives the data response message carrying the frame sequence number y sent by the first slave at t6.
  • the data response message does not time out, and the host sends the data response message. Normal parsing is used for data processing.
  • the host takes the interaction between the host and the first slave as an example to introduce the data collection method provided by the embodiment of the present application. It should be noted that, for the multiple slaves included in the Modbus system, except for the first slave For other slaves, the host can collect data on other slaves in the same way as the data collected on the first slave, which will not be repeated here.
  • the host can flexibly set the collection time for collecting data on each slave, so as to improve the overall performance of the Modbus system, that is, to ensure communication efficiency, communication quality and system real-time sex. That is, in the embodiment of the application, there are multiple implementations of the collection method for the master to collect the data on the multiple slaves, and three of the implementations are described below.
  • the host sends a corresponding data request message to each of the multiple slaves at the same time to complete a round of collection.
  • the host sends a corresponding data request message to each of the multiple slaves at the same time, and then the host waits for each slave to respond. After the host receives the data response message sent by each of the multiple slaves, it determines that the current round of collection is completed, and then starts the next round of collection. Alternatively, a collection period is set on the host, and the host waits for each slave to respond within one acquisition period. When the next acquisition period arrives, the host does not wait, but directly starts the next round of acquisition.
  • the master requests data from multiple slaves at the same time, and some slaves may respond at the same time.
  • the master and slaves work in the Modbus TCP network mode, these Even if the slaves respond at the same time, there will be no conflict.
  • the master can successfully receive the responses from these slaves.
  • the master and the slaves work in the bus mode of Modbus RTU, the simultaneous responses of these slaves may conflict, resulting in The master cannot receive replies from these slaves. That is, the first implementation is suitable for the network mode of Modbus TCP.
  • the host requests data from all slaves at the same time at the beginning of a round of collection, without waiting for a slave to respond before requesting the next one, which greatly reduces the duration of a round of collection and reduces the time consuming.
  • the host sends a corresponding data request message to each of the multiple slaves in turn according to the polling sequence, so as to complete a round of collection.
  • a polling sequence is configured on the host, and the host sends a corresponding data request message to each of the multiple slaves in turn according to the polling sequence, that is, the host is sending a corresponding data request message to each of the multiple slaves in turn.
  • a slave sends a data request message, it waits for the first slave to respond, and after the first slave responds, it sends a data request message to the second slave, and so on, until the master sends a data request to the last slave.
  • the slave requests to collect data, and receives the response from the last slave, and the master determines to complete a round of collection.
  • the multiple slaves include air conditioner 1 , air conditioner 2 , busbar 1 and distribution box 1
  • the polling sequence is air conditioner 1 , air conditioner 2 , busbar 1 and distribution box 1
  • the host starts a round of collection, that is, the host sends a data request message carrying frame number 1 to air conditioner 1 at time t1, and after receiving a data response message with frame number 1 responded by air conditioner 1 at time t2 Carry out data processing, send a data request message carrying frame number 2 to air conditioner 2 at time t3, and perform data processing after receiving a data response message carrying frame number 2 responded by air conditioner 2 at time t4, and send it to the air conditioner at time t5.
  • Bus slot 1 sends a data request message carrying frame number n-1, receives a data response message carrying frame number n-1 responded by bus slot 1 at time t6, and performs data processing, and sends it to the power distribution at time t7.
  • Box 1 sends a data request message with frame sequence number n, and receives a data response message with frame sequence number n from distribution box 1 at time t8, and then performs data processing. At this point, a round of collection is completed.
  • a question-and-answer method is adopted between the master and the slave, and the multiple slaves are sequentially requested to complete a round of collection according to the polling sequence, which can ensure that the master successfully polls and collects in a round of collection. to the data on each slave.
  • the host determines the collection time corresponding to the corresponding slave according to the data volume of the data to be collected on each of the multiple slaves, and the host determines the collection time corresponding to each slave in the multiple slaves. At the time of collection, a corresponding data request message is sent to each of the multiple slaves.
  • the host can determine the collection time corresponding to the corresponding slave according to the amount of data to be collected on each slave, for example, the host determines the collection period corresponding to each slave, or the host determines the next collection of a certain The specific time of each slave.
  • the master determines the collection period of slave 1 as 10s, and the registers on slave 2 less, the amount of data to be collected is small, then the host determines the collection period of slave 1 as 1s.
  • the host can more flexibly determine the collection time corresponding to each slave according to the amount of data to be collected on each slave, which can improve the flexibility of the collection method, make full use of system resources, and avoid some slave data. Due to the large amount of data, the response service is too busy, while other slaves have a small amount of data but cannot be collected for a long time.
  • the host determines the collection time of the corresponding slave according to the service real-time requirement corresponding to each of the multiple slaves, and the host determines the collection time of the corresponding slave according to the multiple slaves.
  • the corresponding data request message is sent to each of the multiple slaves, so that the real-time service requirements corresponding to each slave can be met, that is, for the corresponding
  • the master collects data on the corresponding slaves at a higher frequency.
  • the master collects data on the corresponding slaves at a lower frequency.
  • the host determines the collection time of the corresponding slave according to the data volume of the data to be collected on each slave and the real-time requirements of the business corresponding to each slave, so as to take into account the data volume and real-time requirements at the same time, and ensure the improvement of Modbus. the overall performance of the system.
  • the master requests each slave to collect data according to the collection time configured by the user.
  • the host also sends a corresponding data request message to each slave in any other possible implementation, so as to collect data on the corresponding slave.
  • the master and the slave can collect the data on the corresponding slave through one interaction.
  • the host sends a plurality of data request messages to a slave to complete the collection of data on the corresponding slave through multiple interactions.
  • a slave needs to collect thousands of register data, or even more. If so much data is carried through one interaction, it may affect the communication quality and reliability. response, the host will not be able to collect any data on the slave. In this case, if the host collects all data by interacting with the slave multiple times, it is guaranteed to a certain extent that the host can collect the data on the slave. data.
  • the master and the slave use a question-and-answer method to poll each slave to collect data, which can ensure that the polling and collected data are collected.
  • the master and the slave use multiple questions and multiple answers to collect the data on each slave, which can improve the flexibility of the collection method and make full use of system resources.
  • the multiple slave machines include air conditioner 1, air conditioner 2, busway 1 and distribution box 1, and the master machine sends the frame numbers 1 and 2 to the air conditioner 1 at time t1, t2 and t3 respectively. and 3, send a data request message with frame number 4 to air conditioner 2 at time t4, receive a data response message with frame number 1 from air conditioner 1 at time t5, and send it to air conditioner 2 at time t6.
  • Air conditioner 2 sends a data request message carrying frame number 5, receives a data response message carrying frame number 2 from air conditioner 1 at time t7, and sends a data request carrying frame number 6 to bus slot 1 at time t8 message, received the data response message with frame number 4 responded by air conditioner 2 at time t9, received the data response message with frame number 3 responded by air conditioner 1 at time t10, and received air conditioner 2 at time t11.
  • the response message carries the data response message with the frame number 5, and sends a data request message with the frame number 7 to the distribution box 1 at t12, and receives the response from the bus slot 1 at t13.
  • the data with the frame number 6 is 6
  • a data response message with a frame sequence number of 7 and a response from the distribution box 1 is received at time t14.
  • the master and the slave adopt the method of multiple questions and multiple answers.
  • the master does not have to wait for a slave to respond before requesting other slaves, and the slave does not need to immediately respond to a request from the master.
  • the slave machine can reply to the master machine in a relatively idle time, and other services on the slave machine are not affected.
  • the data on the corresponding slave is collected through one interaction between the master and the slave, as shown in Figure 6, the master and the air conditioner 1, the master and the air conditioner 2, or the master and the slave through an interaction to collect the corresponding slave After the data collection on the machine is completed, the host and the busway 1, the host and the wiring box 1 are shown in Figure 6.
  • the host and the slave can collect one or more segmented data in one interaction, and the maximum amount of data carried by each segmented data is 256.
  • a piece of data is represented by at least one byte, and the data carried by each segmented data is at most 256 bytes. If multiple segmented data can be collected in one interaction, the amount of data that can be collected will be much larger. 252 bytes due to the protocol limit. That is to say, in this solution, the amount of data that can be collected by the master and the slave in one interaction will be more. Under the condition that the amount of data to be collected is certain, the number of interactions between the master and the slave can be reduced, so that the frequency of bus occupancy can be reduced. It will decrease but the occupancy rate will increase and the communication efficiency will increase. In addition, since the slave machine provides more data in one response, the master machine will not spend a long time on a slave machine, so the real-time performance of the entire Modbus system will be improved.
  • FIG. 7 is a schematic structural diagram of a data acquisition apparatus provided by an embodiment of the present application.
  • the data acquisition device 700 is implemented by software, hardware or a combination of the two as a host included in the Modbus system, and the Modbus system also includes multiple slaves.
  • the device 700 includes: a sending module 701 and a receiving module 702.
  • a sending module 701 configured to send a data request message to the first slave, where the data request message carries one or more segment collection instruction information, and each segment collection in the one or more segment collection instruction information
  • the instruction information is used to indicate the data that the host needs to collect from the first slave, and the first slave is one of multiple slaves; for the specific implementation, please refer to the detailed description of step 301 in the embodiment of FIG. 3 , which will not be repeated here. .
  • the receiving module 702 is configured to receive a data response message sent by the first slave, where the data response message carries one or more segment data, and the one or more segment data is the response of the first slave to the one or more segments.
  • the data provided by the collection indication information for each segment, the data quantity carried by each segment data in the one or more segment data is greater than 0 and less than or equal to 256.
  • the apparatus 700 further includes:
  • the determining module is configured to determine one or more segmented collection instruction information according to the address distribution characteristics of the data to be collected on the first slave. For a specific implementation manner, please refer to the relevant description of step 301 in the embodiment of FIG. 3 , which will not be repeated here.
  • each segment collection instruction information in the one or more segment collection instruction information includes a start address and a data quantity
  • Each segment data in the one or more segment data includes a start address, a data quantity and first data, where the first data is data read by the first slave according to the corresponding segment collection instruction information.
  • the data request message includes a first address field, a first functional field and a first data field
  • the first address field carries the address of the first slave
  • the first functional field carries the first function code
  • the first data field Carrying one or more segmented collection instruction information
  • the first function code is used to instruct the master to request the first slave to perform the function of collecting data
  • the data response message includes a second address field, a second function field, and a second data field.
  • the second address field carries the address of the first slave
  • the second function field carries the second function code
  • the second data field carries one or more segment data
  • the second function code is used to indicate the function actually performed by the first slave.
  • the first data field also carries the first frame serial number
  • the second data field also carries the second frame serial number
  • the first frame serial number and the second frame serial number are used by the host to frame the data request message and the data response message. match.
  • the first data field also carries the segment request number, and the segment request number is used to indicate the segment number of the data collected by the master requesting the first slave segment;
  • the second data field also carries the number of segment responses, where the number of segment responses is used to indicate the number of segments of the data actually collected by the first slave.
  • the host sends a corresponding data request message to each of the multiple slaves at the same time to complete a round of collection; or,
  • the host sends a corresponding data request message to each of the multiple slaves in turn according to the polling sequence to complete a round of collection; or,
  • the host determines the collection time corresponding to the corresponding slave according to the amount of data to be collected on each of the multiple slaves.
  • Each of the slaves sends a corresponding data request message.
  • step 305 in the embodiment of FIG. 3 and the related description of FIG. 5 and FIG. 6 , and details are not repeated here.
  • the host and the slave can collect one or more segmented data in one interaction, and the maximum amount of data carried by each segmented data is 256.
  • a piece of data is represented by at least one byte, and the data carried by each segmented data is at most 256 bytes. If multiple segmented data can be collected in one interaction, the amount of data that can be collected will be much larger. 252 bytes due to the protocol limit. That is to say, in this solution, the amount of data that can be collected by the master and the slave in one interaction will be more. Under the condition that the amount of data to be collected is certain, the number of interactions between the master and the slave can be reduced, so that the frequency of bus occupancy can be reduced. It will decrease but the occupancy rate will increase and the communication efficiency will increase. In addition, because the slave machine provides more data in one response, the master machine will not spend a long time on a slave machine, so the real-time performance of the entire Modbus system will be improved.
  • FIG. 8 is a schematic structural diagram of another data acquisition apparatus provided by an embodiment of the present application.
  • the data acquisition device 800 is implemented by software, hardware or a combination of the two to become the first slave included in the Modbus system, and the first slave is one of the multiple slaves included in the Modbus system.
  • the Modbus system also Including a host, referring to FIG. 8 , the apparatus 800 includes: a receiving module 801 , a determining module 802 and a sending module 803 .
  • a receiving module 801 configured to receive a data request message sent by the host, where the data request message carries one or more segment collection instruction information, and each segment collection instruction information in the one or more segment collection instruction information It is used to indicate the data that the host needs to collect from the first slave; for the specific implementation, please refer to the detailed description of steps 301 and 302 in the embodiment of FIG. 3 , which will not be repeated here.
  • the determining module 802 is configured to determine one or more segment data according to the one or more segment collection indication information; for a specific implementation method, please refer to the detailed description of step 303 in the embodiment of FIG. 3 , which will not be repeated here.
  • the sending module 803 is configured to send a data response message to the host, where the data response message carries the one or more segment data, and the amount of data carried by each segment data in the one or more segment data is greater than 0, and less than or equal to 256.
  • the data response message carries the one or more segment data, and the amount of data carried by each segment data in the one or more segment data is greater than 0, and less than or equal to 256.
  • each segment collection instruction information in the one or more segment collection instruction information includes a start address and a data quantity
  • the determining module 802 includes:
  • the reading sub-module is used to continuously read the data of the first data quantity from the first starting address to obtain the first data.
  • the first starting address is the starting address included in the first segmented collection instruction information
  • the first data quantity is the amount of data included in the first segment collection instruction information, where the first segment collection instruction information is one of the one or more segment collection instruction information;
  • a determination submodule is used for taking the first start address, the first data quantity and the first data as one segment data.
  • step 303 in the embodiment of FIG. 3 , which is not repeated here.
  • the host and the slave can collect one or more segmented data in one interaction, and the maximum amount of data carried by each segmented data is 256.
  • a piece of data is represented by at least one byte, and the data carried by each segmented data is at most 256 bytes. If multiple segmented data can be collected in one interaction, the amount of data that can be collected will be much larger. 252 bytes due to the protocol limit. That is to say, in this solution, the amount of data that can be collected by the master and the slave in one interaction will be more. Under the condition that the amount of data to be collected is certain, the number of interactions between the master and the slave can be reduced, so that the frequency of bus occupancy can be reduced. It will decrease but the occupancy rate will increase and the communication efficiency will increase. In addition, since the slave machine provides more data in one response, the master machine will not spend a long time on a slave machine, so the real-time performance of the entire Modbus system will be improved.
  • An embodiment of the present application provides a Modbus system, where the Modbus system includes a master and multiple slaves, and the first slave is one of the multiple slaves.
  • the master and the first slave have corresponding functions for implementing the data collection method provided by the foregoing embodiments, so as to realize data collection through the Modbus system.
  • the embodiment in FIG. 3 please refer to the detailed description of the embodiment in FIG. 3 , which will not be repeated here.
  • the host and the slave can collect one or more segmented data in one interaction, and the maximum amount of data carried by each segmented data is 256.
  • a piece of data is represented by at least one byte, and the data carried by each segmented data is at most 256 bytes. If multiple segmented data can be collected in one interaction, the amount of data that can be collected will be much larger. 252 bytes due to the protocol limit. That is to say, in this solution, the amount of data that can be collected by the master and the slave in one interaction will be more. Under the condition that the amount of data to be collected is certain, the number of interactions between the master and the slave can be reduced, so that the frequency of bus occupancy can be reduced. It will decrease but the occupancy rate will increase and the communication efficiency will increase. In addition, since the slave machine provides more data in one response, the master machine will not spend a long time on a slave machine, so the real-time performance of the entire Modbus system will be improved.
  • the computer program product includes one or more computer instructions.
  • the computer may be a general purpose computer, special purpose computer, computer network or other programmable device.
  • the computer instructions may be stored in or transmitted from one computer-readable storage medium to another computer-readable storage medium, for example, the computer instructions may be downloaded from a website site, computer, server, or data center Transmission to another website site, computer, server, or data center by wire (eg, coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (eg, infrared, wireless, microwave, etc.).
  • the computer-readable storage medium can be any available medium that can be accessed by a computer, or a data storage device such as a server, a data center, etc. that includes one or more available media integrated.
  • the available media may be magnetic media (eg: floppy disk, hard disk, magnetic tape), optical media (eg: digital versatile disc (DVD)) or semiconductor media (eg: solid state disk (SSD)) Wait.
  • the computer-readable storage medium mentioned in the embodiments of the present application may be a non-volatile storage medium, in other words, may be a non-transitory storage medium.
  • references herein to "at least one” refers to one or more, and “plurality” refers to two or more.
  • “/” means or means, for example, A/B can mean A or B;
  • "and/or” in this document is only an association that describes an associated object Relation, it means that there can be three kinds of relations, for example, A and/or B can mean that A exists alone, A and B exist at the same time, and B exists alone.
  • words such as “first” and “second” are used to distinguish the same or similar items with basically the same function and effect. Those skilled in the art can understand that the words “first”, “second” and the like do not limit the quantity and execution order, and the words “first”, “second” and the like are not necessarily different.

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Multimedia (AREA)
  • Small-Scale Networks (AREA)
  • Information Transfer Systems (AREA)

Abstract

本申请实施例公开了一种数据采集方法、装置、Modbus系统及存储介质,属于通信技术领域。在本申请实施例中,主机与从机一次交互采集一个或多个分段数据,每个分段数据携带的数据数量最大为256。在Modbus系统中,一个数据最小以一字节表示,则每个分段数据携带的数据可达256字节,如果一次交互采集到多个分段数据,那么能够采集的数据量将远大于协议限制的252字节。也即本方案中一次交互能够采集的数据量更多,在需要采集的数据量一定的情况下,能够减少主机与从机的交互次数,这样总线占用频率降低但占用率提高。且由于从机一次响应的数据量更多,主机不会长时间耗费在一个从机上,因此,Modbus系统的实时性将提高。

Description

数据采集方法、装置、Modbus系统及存储介质 技术领域
本申请实施例涉及通信技术领域,特别涉及一种数据采集方法、装置、Modbus系统及存储介质。
背景技术
Modbus协议是一种串行通信协议,已经成为工业领域通信协议的业界标准,是工业电子设备之间常用的通信方式。Modbus系统包括一个主机和多个从机,主机负责采集各个从机中的数据。
在相关技术中,Modbus标准协议规定,主机与从机之间通过交互Modbus报文来实现数据采集,一个Modbus报文的最大长度为256字节,其中数据域的长度最大为252字节,也即是一个Modbus报文包括的数据域携带的数据数量受限,以所采集的一个数据的长度为一字节为例,数据域携带的数据数量最大为252。受限于数据域的长度,如果某个从机上需要采集的数据较多,那么主机和从机之间需要多次请求和响应,才能将该从机的全部数据采集完成。
由上述可知,相关技术中,如果某个从机上需要采集的数据较多,存在该从机长时间占用总线资源的问题,且由于需要从机多次响应来采集,但从机每次响应的有效数据有限,因此总线占用频繁但占用率不高。此外,如果主机在一个从机上耗费时间较多,会导致整个Modbus系统的实时性较低。
发明内容
本申请实施例提供了一种数据采集方法、装置、Modbus系统及存储介质,能够在通过Modbus系统采集数据的过程中降低总线占用频率、提高占用率,同时提高系统实时性。所述技术方案如下:
第一方面,提供了一种数据采集方法,该数据采集方法用于Modbus系统包括的主机,Modbus系统还包括多个从机,该方法包括:
主机向第一从机发送数据请求报文,该数据请求报文携带一个或多个分段采集指示信息,该一个或多个分段采集指示信息中的每个分段采集指示信息用于指示主机从第一从机中需要采集的数据,第一从机为多个从机中的一个;主机接收第一从机发送的数据响应报文,该数据响应报文携带一个或多个分段数据,该一个或多个分段数据是第一从机响应于该一个或多个分段采集指示信息所提供的数据,该一个或多个分段数据中的每个分段数据携带的数据数量大于0,且小于或等于256。
本申请实施例中,主机与从机在一次交互中能够采集一个或多个分段数据,每个分段数据携带的数据数量最大为256。在Modbus系统中,一个数据最小以一字节表示,假设一个数据以一字节表示,例如一个线圈数据,那么每个分段数据携带的数据最多为256字节,假设一个数据以两字节表示,例如一个寄存器数据,那么每个分段数据携带的数据最多为512字 节。如果一次交互中能够采集到多个分段数据,那么能够采集的数据量将远大于协议限制的252字节。也即本方案中,主机与从机在一次交互中能够采集的数据量将更多,在需要采集的数据量一定的情况下,能够减少主机与从机之间的交互次数,这样总线占用频率将降低但占用率提高,通信效率提高。另外,由于从机一次响应所提供的数据量更多,主机不会长时间耗费在一个从机上,因此,整个Modbus系统的实时性将得到提高。也即是,在本方案中,主机与从机之间通过交互长数据报文来提高通信效率,提高系统实时性。
可选地,主机向第一从机发送数据请求报文之前,还包括:主机根据第一从机上待采集数据的地址分布特征,确定一个或多个分段采集指示信息。
需要说明的是,在本申请实施例中,第一从机上待采集数据的地址可能连续或存在不连续,例如,寄存器地址连续或存在不连续,主机根据地址分布特征来确定分段采集指示信息,能够最大程度的采集更多的有效数据,能够避免在地址不连续的情况下,主机采集到的数据中存在部分无效数据。
可选地,该一个或多个分段采集指示信息中的每个分段采集指示信息包括一个起始地址和一个数据数量;该一个或多个分段数据中的每个分段数据包括一个起始地址、一个数据数量和第一数据,第一数据为第一从机根据相应分段采集指示信息读取的数据。
可选地,在本申请实施例中,通过对Modbus报文进行扩展,得到数据请求报文和数据响应报文。也即是,数据请求报文包括第一地址域、第一功能域和第一数据域,第一地址域携带第一从机的地址,第一功能域携带第一功能码,第一数据域携带一个或多个分段采集指示信息,第一功能码用于指示主机请求第一从机执行采集数据的功能;数据响应报文包括第二地址域、第二功能域和第二数据域,第二地址域携带第一从机的地址,第二功能域携带第二功能码,第二数据域携带一个或多个分段数据,第二功能码用于指示第一从机实际执行的功能。
为了提高主机与从机之间通信的可靠性,解决通信双方帧匹配异常的问题,可选地,在本申请实施例中,第一数据域还携带第一帧序号,第二数据域还携带第二帧序号,第一帧序号和第二帧序号用于主机将数据请求报文与数据响应报文进行帧匹配。例如,第一帧序号与第二帧序号相同,表示相应的数据请求报文和数据响应报文为帧匹配的报文。
可选地,第一数据域还携带分段请求数,分段请求数用于指示主机请求第一从机分段采集的数据的分段数量;第二数据域还携带分段响应数,分段响应数用于指示第一从机实际分段采集的数据的分段数量。
在本申请实施例中,对于Modbus系统包括的多个从机,主机可以灵活设置采集各个从机上的数据的采集时间,以提高Modbus系统的整体性能,也即保证通信效率、通信质量以及系统实时性。
可选地,主机在同一时刻向多个从机中的每个从机发送对应的数据请求报文,以完成一轮采集;或者,主机根据轮询顺序,依次向多个从机中的每个从机发送对应的数据请求报文,以完成一轮采集;或者,主机根据多个从机中的每个从机上待采集数据的数据量,确定相应从机对应的采集时间,主机按照多个从机中的每个从机对应的采集时间,向多个从机中的每个从机发送对应的数据请求报文。
需要说明的是,在主机同时向所有的从机请求采集数据的情况下,主机无需等待某个从机响应完再请求下一个,这样大大缩小了一轮采集的时长,减小了耗时。在主机根据轮询顺 序依次向各个从机请求采集数据的情况下,主机与从机之间采用一问一答的方式,能够保证主机在一轮采集中成功轮询采集到每个从机上的数据。在主机按照各个从机上待采集数据的数据量来请求采集数据的情况下,主机更加灵活地确定各个从机对应的采集时间,能够提高采集方法的灵活性,充分利用系统资源,避免某些从机数据量较大而导致应答业务过忙,而另一些从机数据量较小却迟迟得不到采集。
可选地,主机根据该多个从机中的每个从机对应的业务实时性要求,来确定相应从机的采集时间,主机按照该多个从机中的每个从机对应的采集时间,向该多个从机中的每个从机发送对应的数据请求报文,这样,能够满足各个从机对应的业务实时性要求,也即对于对应的业务实时性较高的从机,主机以较高的频率来采集相应从机上的数据,对于对应的业务实时性较低的从机,主机以较低的频率来采集相应从机上的数据。
可选地,主机根据该多个从机中的每个从机上待采集数据的数据量和对应的业务实时性要求,来确定相应从机的采集时间,主机按照多个从机中的每个从机对应的采集时间,向多个从机中的每个从机发送对应的数据请求报文,以同时兼顾数据量大小和实时性需求,提高Modbus系统的整体性能。
第二方面,提供一种数据采集方法,该数据采集方法用于Modbus系统包括的第一从机,第一从机为Modbus系统包括的多个从机中的一个,Modbus系统还包括主机,该方法包括:
第一从机接收主机发送的数据请求报文,该数据请求报文携带一个或多个分段采集指示信息,该一个或多个分段采集指示信息中的每个分段采集指示信息用于指示主机从第一从机中需要采集的数据;第一从机根据一个或多个分段采集指示信息,确定一个或多个分段数据;第一从机向主机发送数据响应报文,该数据响应报文携带一个或多个分段数据,该一个或多个分段数据中的每个分段数据携带的数据数量大于0,且小于或等于256。
本申请实施例中,主机与从机在一次交互中能够采集一个或多个分段数据,每个分段数据携带的数据数量最大为256。在Modbus系统中,一个数据最小以一字节表示,假设一个数据以一字节表示,例如一个线圈数据,那么每个分段数据携带的数据最多为256字节,假设一个数据以两字节表示,例如一个寄存器数据,那么每个分段数据携带的数据最多为512字节。如果一次交互中能够采集到多个分段数据,那么能够采集的数据量将远大于协议限制的252字节。也即本方案中,主机与从机在一次交互中能够采集的数据量将更多,在需要采集的数据量一定的情况下,能够减少主机与从机之间的交互次数,这样总线占用频率将降低但占用率提高,通信效率提高。另外,由于从机一次响应所提供的数据量更多,主机不会长时间耗费在一个从机上,因此,整个Modbus系统的实时性将得到提高。也即是,在本方案中,主机与从机之间通过交互长数据报文来提高通信效率,提高系统实时性。
可选地,该一个或多个分段采集指示信息中的每个分段采集指示信息包括一个起始地址和一个数据数量;第一从机根据一个或多个分段采集指示信息,确定一个或多个分段数据,包括:第一从机从第一起始地址开始连续读取第一数据数量的数据,得到第一数据,第一起始地址为第一分段采集指示信息包括的起始地址,第一数据数量为第一分段采集指示信息包括的数据数量,第一分段采集指示信息为一个或多个分段采集指示信息中的一个;第一从机将第一起始地址、第一数据数量和第一数据作为一个分段数据。
第一从机根据该一个或多个分段采集指示信息中的每个分段采集指示信息读取完全部数 据之后,得到该一个或多个分段数据。
可选地,在本申请实施例中,通过对Modbus报文进行扩展,得到数据请求报文和数据响应报文。对数据请求报文以及数据响应报文的相关介绍参照前述第一方面的相关介绍,这里不再赘述。
第三方面,提供了一种数据采集装置,所述数据采集装置具有实现上述第一方面中数据采集方法行为的功能。所述数据采集装置包括一个或多个模块,该一个或多个模块用于实现上述第一方面所提供的数据采集方法。
也即是,本申请实施例提供了一种数据采集装置,该装置用于Modbus系统包括的主机,Modbus系统还包括多个从机,该装置包括:
发送模块,用于向第一从机发送数据请求报文,该数据请求报文携带一个或多个分段采集指示信息,该一个或多个分段采集指示信息中的每个分段采集指示信息用于指示主机从第一从机中需要采集的数据,第一从机为多个从机中的一个;
接收模块,用于接收第一从机发送的数据响应报文,该数据响应报文携带一个或多个分段数据,该一个或多个分段数据是第一从机响应于该一个或多个分段采集指示信息所提供的数据,该一个或多个分段数据中的每个分段数据携带的数据数量大于0,且小于或等于256。
可选地,该装置还包括:
确定模块,用于根据第一从机上待采集数据的地址分布特征,确定该一个或多个分段采集指示信息。
可选地,该一个或多个分段采集指示信息中的每个分段采集指示信息包括一个起始地址和一个数据数量;
该一个或多个分段数据中的每个分段数据包括一个起始地址、一个数据数量和第一数据,第一数据为第一从机根据相应分段采集指示信息读取的数据。
可选地,该数据请求报文包括第一地址域、第一功能域和第一数据域,第一地址域携带第一从机的地址,第一功能域携带第一功能码,第一数据域携带该一个或多个分段采集指示信息,第一功能码用于指示主机请求第一从机执行采集数据的功能;
该数据响应报文包括第二地址域、第二功能域和第二数据域,第二地址域携带第一从机的地址,第二功能域携带第二功能码,第二数据域携带该一个或多个分段数据,第二功能码用于指示第一从机实际执行的功能。
可选地,第一数据域还携带第一帧序号,第二数据域还携带第二帧序号,第一帧序号和第二帧序号用于主机将数据请求报文与数据响应报文进行帧匹配。
可选地,第一数据域还携带分段请求数,该分段请求数用于指示主机请求第一从机分段采集的数据的分段数量;
第二数据域还携带分段响应数,该分段响应数用于指示第一从机实际分段采集的数据的分段数量。
可选地,主机在同一时刻向该多个从机中的每个从机发送对应的数据请求报文,以完成一轮采集;或者,主机根据轮询顺序,依次向该多个从机中的每个从机发送对应的数据请求报文,以完成一轮采集;或者,主机根据该多个从机中的每个从机上待采集数据的数据量,确定相应从机对应的采集时间,主机按照该多个从机中的每个从机对应的采集时间,向该多 个从机中的每个从机发送对应的数据请求报文。
第四方面,提供了一种数据采集装置,所述数据采集装置具有实现上述第二方面中数据采集方法行为的功能。所述数据采集装置包括一个或多个模块,该一个或多个模块用于实现上述第二方面所提供的数据采集方法。
也即是,本申请实施例提供了一种数据采集装置,该装置用于Modbus系统包括的第一从机,第一从机为Modbus系统包括的多个从机中的一个,该Modbus系统还包括主机,该装置包括:
接收模块,用于接收主机发送的数据请求报文,该数据请求报文携带一个或多个分段采集指示信息,该一个或多个分段采集指示信息中的每个分段采集指示信息用于指示主机从第一从机中需要采集的数据;
确定模块,用于根据该一个或多个分段采集指示信息,确定一个或多个分段数据;
发送模块,用于向主机发送数据响应报文,数据响应报文携带该一个或多个分段数据,该一个或多个分段数据中的每个分段数据携带的数据数量大于0,且小于或等于256。
可选地,该一个或多个分段采集指示信息中的每个分段采集指示信息包括一个起始地址和一个数据数量;
确定模块包括:
读取子模块,用于从第一起始地址开始连续读取第一数据数量的数据,得到第一数据,第一起始地址为第一分段采集指示信息包括的起始地址,第一数据数量为第一分段采集指示信息包括的数据数量,第一分段采集指示信息为该一个或多个分段采集指示信息中的一个;
确定子模块,用于将第一起始地址、第一数据数量和第一数据作为一个分段数据。
第五方面,提供了一种数据采集装置,所述装置用于Modbus系统包括的主机,所述Modbus系统还包括多个从机,所述装置包括存储器和处理器。所述存储器用于存储计算机程序,所述处理器用于执行所述存储器中存储的计算机程序,实现上述第一方面所提供的数据采集方法。
第六方面,提供了一种数据采集装置,所述装置用于Modbus系统包括的第一从机,所述第一从机为所述Modbus系统包括的多个从机中的一个,所述Modbus系统还包括主机,所述装置包括处理器和存储器。所述存储器,用于存储计算机程序,所述处理器用于执行所述存储器中存储的计算机程序,实现上述第二方面所提供的数据采集方法。
第七方面,提供了一种Modbus系统,所述系统包括主机和多个从机,第一从机为所述多个从机中的一个;
所述主机,用于实现上述第一方面所提供的数据采集方法;
所述第一从机,用于实现上述第二方面所提供的数据采集方法。
第八方面,提供了一种计算机可读存储介质,所述计算机可读存储介质中存储有计算机程序,当其在计算机上运行时,使得计算机执行上述第一方面或第二方面所述的数据采集方 法。
第九方面,提供了一种包含指令的计算机程序产品,当其在计算机上运行时,使得计算机执行上述第一方面或第二方面所述的数据采集方法。
上述第三方面、第四方面、第五方面、第六方面、第七方面、第八方面和第九方面所获得的技术效果与第一方面或第二方面中对应的技术手段获得的技术效果近似,在这里不再赘述。
本申请实施例提供的技术方案至少能够带来以下有益效果:
在本申请实施例中,主机与从机在一次交互中能够采集一个或多个分段数据,每个分段数据携带的数据数量最大为256。在Modbus系统中,一个数据最小以一字节表示,那么每个分段数据携带的数据最多为256字节,如果一次交互中能够采集到多个分段数据,那么能够采集的数据量将远大于协议限制的252字节。也即本方案中,主机与从机在一次交互中能够采集的数据量将更多,在需要采集的数据量一定的情况下,能够减少主机与从机之间的交互次数,这样总线占用频率将降低但占用率提高,通信效率提高。另外,由于从机一次响应所提供的数据量更多,主机不会长时间耗费在一个从机上,因此,整个Modbus系统的实时性将得到提高。
附图说明
图1是本申请实施例提供的一种数据采集方法所涉及的系统架构图;
图2是本申请实施例提供的一种计算机设备的结构示意图;
图3是本申请实施例提供的一种数据采集方法的流程图;
图4是本申请实施例提供的一种主机与第一从机之间进行帧匹配的示意图;
图5是本申请实施例提供的一种主机采集多个从机上数据的方法示意图;
图6是本申请实施例提供的另一种主机采集多个从机上数据的方法示意图;
图7是本申请实施例提供的一种数据采集装置的结构示意图;
图8是本申请实施例提供的另一种数据采集装置的结构示意图。
具体实施方式
为使本申请实施例的目的、技术方案和优点更加清楚,下面将结合附图对本申请实施方式作进一步地详细描述。
本申请实施例描述的网络架构以及业务场景是为了更加清楚的说明本申请实施例的技术方案,并不构成对于本申请实施例提供的技术方案的限定,本领域普通技术人员可知,随着网络架构的演变和新业务场景的出现,本申请实施例提供的技术方案对于类似的技术问题,同样适用。
图1是本申请实施例提供的一种数据采集方法所涉及的系统架构图。该系统为Modbus系统,参见图1,Modbus系统包括一个主机101和多个从机102,主机101与各个从机102之间能够通过有线或无线方式连接以进行通信。
在本申请实施例中,以主机101采集第一从机102上的数据为例,第一从机102为该多个从机102中的一个,主机101用于向第一从机102发送数据请求报文,该数据请求报文携带一个或多个分段采集指示信息,表示主机101将分段采集第一从机102上的数据。第一从机102用于根据接收到的数据请求报文分段读取对应的数据,以确定一个或多个分段数据,并向主机101发送携带这些分段数据的数据响应报文。主机101与该多个从机102中除第一从机102之外的其他从机102,均能够按照与第一从机102相同的交互方式来采集相应从机102上的数据。
需要说明的是,在本申请实施例中,主机101所采集的每个分段数据携带的数据数量最大为256,在主机101一次请求、从机一次响应来采集多个分段数据的情况下,本方案一次请求和响应所采集的数据不会受限于252字节,也即是,本方案能够通过长数据报文来提高通信效率。
在一些实施例中,主机101称为集中控制器、数据中心、总控中心(enterprise command center,ECC)等,从机102称为南向设备。
在本申请实施例中,主机101为电脑、控制器、服务器等设备,任一从机102为电磁锁、自动平移门、门禁机、紧急按钮、门禁执行器、天窗电磁锁、天窗执行器、无线局域网(wireless fidelity,WiFi)转换器、摄像机、电脑、手机、机柜门磁、机柜电子锁、温度传感器、水浸传感器、声光告警器、智能远程电源控制器(remote power distribution unit,rPDU)、智能U位管理器、空调、配电柜、智能母线槽等设备。
请参考图2,图2是根据本申请实施例示出的一种计算机设备的结构示意图。可选地,该计算机设备为图1中所示的主机101或从机102,该计算机设备包括一个或多个处理器201、通信总线202、存储器203以及一个或多个通信接口204。
处理器201为一个通用中央处理器(central processing unit,CPU)、网络处理器(NP)、微处理器、或者为一个或多个用于实现本申请方案的集成电路,例如,专用集成电路(application-specific integrated circuit,ASIC),可编程逻辑器件(programmable logic device,PLD)或其组合。可选地,上述PLD为复杂可编程逻辑器件(complex programmable logic device,CPLD),现场可编程逻辑门阵列(field-programmable gate array,FPGA),通用阵列逻辑(generic array logic,GAL)或其任意组合。
通信总线202用于在上述组件之间传送信息。可选地,通信总线202分为地址总线、数据总线、控制总线等。为便于表示,图中仅用一条粗线表示,但并不表示仅有一根总线或一种类型的总线。
可选地,存储器203为只读存储器(read-only memory,ROM)、随机存取存储器(random access memory,RAM)、电可擦可编程只读存储器(electrically erasable programmable read-only memory,EEPROM)、光盘(包括只读光盘(compact disc read-only memory,CD-ROM)、压缩光盘、激光盘、数字通用光盘、蓝光光盘等)、磁盘存储介质或者其它磁存储设备,或者是能够用于携带或存储具有指令或数据结构形式的期望的程序代码并能够由计算机存取的任何其它介质,但不限于此。存储器203独立存在,并通过通信总线202与处理器201相连接,或者,存储器203与处理器201集成在一起。
通信接口204使用任何收发器一类的装置,用于与其它设备或通信网络通信。通信接口 204包括有线通信接口,可选地,还包括无线通信接口。其中,有线通信接口例如以太网接口等。可选地,以太网接口为光接口、电接口或其组合。无线通信接口为无线局域网(wireless local area networks,WLAN)接口、蜂窝网络通信接口或其组合等。当该计算机设备为主机101时,通信接口204用于与从机102通信,当该计算机设备为从机102时,通信接口204用于与主机101通信。
可选地,在一些实施例中,计算机设备包括多个处理器,如图2中所示的处理器201和处理器205。这些处理器中的每一个为一个单核处理器,或者一个多核处理器。可选地,这里的处理器指一个或多个设备、电路、和/或用于处理数据(如计算机程序指令)的处理核。
在具体实现中,作为一种实施例,计算机设备还包括输出设备206和输入设备207。输出设备206和处理器201通信,能够以多种方式来显示信息。例如,输出设备206为液晶显示器(liquid crystal display,LCD)、发光二级管(light emitting diode,LED)显示设备、阴极射线管(cathode ray tube,CRT)显示设备或投影仪(projector)等。输入设备207和处理器201通信,能够以多种方式接收用户的输入。例如,输入设备207是鼠标、键盘、触摸屏设备或传感设备等。
在一些实施例中,存储器203用于存储执行本申请方案的程序代码210(也称为计算机程序),处理器201能够执行存储器203中存储的程序代码210。该程序代码210中包括一个或多个软件模块,该计算机设备能够通过处理器201以及存储器203中的程序代码210,来实现下文图3实施例提供的数据采集方法。
当该计算机设备为主机101时,存储器203用于存储程序代码210,处理器201用于执行存储器203中存储的程序代码210,实现本申请实施例提供的数据采集方法中主机的相应功能。示例性地,当图7所示实施例中的发送模块701和接收模块702是通过软件实施的情况下,该程序代码210中可以包括发送模块和接收模块,发送模块用于向从机发送数据请求报文,接收模块用于接收从机发送的数据响应报文。
当该计算机设备为从机102时,存储器203用于存储程序代码210,处理器201用于执行存储器203中存储的程序代码210,实现本申请实施例提供的数据采集方法中从机的相应功能。示例性地,当图8所示实施例中的接收模块801、确定模块802和发送模块802是通过软件实施的情况下,该程序代码210中可以包括接收模块、确定模块和发送模块,接收模块用于接收主机发送的数据请求报文,确定模块用于根据数据请求报文确定分段数据,发送模块用于向主机发送数据响应报文。
图3是本申请实施例提供的一种数据采集方法的流程图。在本申请实施例中,数据采集方法用于Modbus系统,Modbus系统包括主机和多个从机。请参考图3,该方法包括如下步骤。
步骤301:主机向第一从机发送数据请求报文,该数据请求报文携带一个或多个分段采集指示信息,该一个或多个分段采集指示信息中的每个分段采集指示信息用于指示该主机从第一从机中需要采集的数据。
在本申请实施例中,Modbus系统包括主机和多个从机,主机能够采集该多个从机中的每个从机上的数据,例如采集寄存器数据、线圈数据等。接下来以主机采集第一从机上的数据为例对此进行介绍,第一从机为多个从机中的一个。
在本申请实施例中,主机向第一从机发送数据请求报文,该数据请求报文携带一个或多个分段采集指示信息,该多个分段采集指示信息中的每个分段采集指示信息用于指示该主机从第一从机中需要采集的数据。也即是,在本申请实施例中,主机能够分段采集第一从机中的数据。
可选地,在本申请实施例中,第一从机上待采集数据的地址可能连续或存在不连续,例如,寄存器地址连续或存在不连续,主机向第一从机发送数据请求报文之前,还能够先根据第一从机上待采集数据的地址分布特征,确定该一个或多个分段采集指示信息,也即第一从机上待采集数据的地址分布特征用于指示主机确定该一个或多个分段采集指示信息。
在本申请实施例中,在第一从机加入Modbus系统之前,由开发人员将第一从机对应的地址分布特征写入主机。示例性地,采购一款空调以加入Modbus系统时,供销商将这款空调的产品相关信息提供给开发人员,产品相关信息包括这款空调对应的地址分布特征,例如,寄存器地址分布特征,寄存器地址分布特征用于描述哪段寄存器用于存储温度、哪段寄存器用于存储风速等等,然后由开发人员将这款空调的产品相关信息写入主机,后续这款空调加入Modbus系统之后,主机需要采集这款空调上的数据时,能够根据这款空调对应的地址分布特征,来确定一个或多个分段采集指示信息。
需要说明的是,主机根据地址分布特征来确定分段采集指示信息,能够最大程度的采集更多的有效数据,可以避免地址不连续的情况下,主机采集到的数据中存在部分无效数据。
在本申请实施例中,该一个或多个分段采集指示信息中的每个分段采集指示信息包括一个起始地址和一个数据数量,以指示第一从机中需要分段采集的数据的每个起始地址和对应的数据数量。
可选地,起始地址的长度为两个字节,数据数量的长度为一个字节,也即,主机可以从0-65535寻址采集从机上的数据,以二进制表示的数据数量的值大于0,且小于或等于256,表示相应分段采集指示信息用于指示该分段最多采集256个数据,例如该分段最多采集256个寄存器数据。
在本申请实施例中,通过对Modbus报文进行扩展,得到数据请求报文。数据请求报文包括第一地址域、第一功能域和第一数据域,第一地址域携带第一从机的地址,第一功能域携带第一功能码,第一数据域携带该一个或多个分段采集指示信息,第一功能码用于指示主机请求第一从机执行采集数据的功能。
可选地,第一地址域的长度为一个字节,也即第一从机的地址以一个字节表示,第一功能域的长度为一个字节或两个字节。
需要说明的是,第一功能域包括的第一功能码为Modbus协议预留的用户可定义的一个功能码,即十进制的65-72和100-110中的任一个功能码,第一功能码的长度为一个字节,也即在第一功能域包括第一功能码的情况下,第一功能域的长度为一个字节。
由于用户可定义的功能码的个数有限,因此,在一些实施例中,还能通过定义子功能码来指示相应的功能,也即是,第一功能域除了携带第一功能码之外,还携带第一子功能码,第一子功能码和第一功能码共同指示主机请求第一从机执行采集数据的功能。可选地,第一子功能码的长度为一个字节,值为十进制的0-255中的任一个。在第一功能域包括第一功能码和第一子功能码的情况下,第一功能域的长度为两个字节。
为了提高主机与从机之间通信的可靠性,解决通信双方帧匹配异常的问题,在本申请实 施例中,第一数据域还携带第一帧序号,第一从机能够根据第一帧序号来响应该数据请求报文,也即第一从机向主机发送数据响应报文,数据响应报文携带第二帧序号,第一帧序号和第二帧序号用于主机将数据请求报文与数据响应报文进行帧匹配。例如,第一帧序号与第二帧序号相同,表示相应的数据请求报文和数据响应报文为帧匹配的报文。
可选地,第一帧序号的长度为一个字节,值为十进制的0-255中的任一个,或者第一帧序号为两个字节,值为十进制的0-65535中的任一个,或者第一帧序号为其他长度。也即是,第一帧序号的最大值可以根据通信需求定义。
可选地,第一数据域还携带分段请求数,分段请求数用于指示主机请求第一从机分段采集的数据的分段数量。也即是,由主机直接将请求的分段数量携带在数据请求报文中,无需第一从机根据一个或多个分段采集指示信息,来累加计算得到该分段数量。
可选地,分段请求数的长度为指定长度,例如为一个字节,表示最多分256个段来采集数据,这样,以通过分段请求数来限制报文最大长度,保证通信质量。示例性地,在第一从机上的全部数据通过256个段无法采集完全的情况下,主机需要通过多次请求来采集第一从机上的全部数据,每次请求采集一部分数据,这样,能够避免在一次交互的情况下,携带第一从机上全部数据的数据响应报文丢失,或者第一从机超时未响应时,主机采集不到任何数据。
或者,分段请求数的长度不作限定,主机根据第一从机上需要采集的数据量、以及地址分布特征,来确定分段请求数,以通过一次交互将第一从机上的数据采集完,最大程度上减少交互次数,提高通信效率。示例性地,假设主机确定需要分20个段即可以将第一从机上的数据采集完,那么分段请求数的长度为一个字节,十进制的值为20。假设主机确定需要分500个段才能将第一从机上的数据采集完,那么分段请求数的长度为两个字节,十进制的值为500。
可选地,第一数据域还携带第一数据长度,第一数据长度的值为十六进制的0xFF,表示第一数据长度为无效值,第一从机在解析数据请求报文得到该值之后,获知主机并不通过第一数据长度来限制需要采集的数据的长度,从而直接忽略第一数据长度,相比于标准协议规定的数据长度以一个字节来表示,本方案并不限定数据长度,以此来实现通过交互长数据报文来提高通信效率。
表1是对本申请实施例提供的一种数据请求报文的格式描述。参见表1,数据请求报文包括第一地址域(未示出)和第一协议数据单元(protocol data unit,PDU),第一PDU包括第一功能域和第一数据域,第一功能域携带第一功能码和第一子功能码,第一功能码和第一子功能码的长度均为一个字节,在本申请实施例中,第一功能码的值为十六进制的0x41,第一子功能码的值为十六进制的0x33。第一数据域携带第一数据长度、第一帧序号、分段请求数和n个分段采集指示信息。其中,第一数据长度的长度为一个字节,值为十六进制的0xFF,表示第一数据长度为无效值,第一帧序号的长度为一个字节,第一帧序号由主机设置,第一从机在数据响应报文中回填的第二帧序号与第一帧序号相同,分段请求数的长度为一个字节,值为十进制的1-256中的任一个,值用符号表示为numBlock,表示分为n段请求,也即n=numBlock。表1中以分段1-n表示这n个分段采集指示信息,每个分段采集指示信息包括一个起始地址和一个数据数量,起始地址的长度为两个字节,数据数量的长度为一个字节,表示第一从机需要从该起始地址开始连续读取该数据数量的数据。
表1
Figure PCTCN2020107513-appb-000001
可选地,主机与从机之间选择基于Modbus协议的一种工作模式,Modbus协议的工作模式有Modbus远程终端单元(remote terminal unit,RTU)的总线模式、Modbus传输控制协议(transmission control protocol,TCP)的网络模式等。在Modbus RTU的总线模式下,主机发送的数据请求报文即携带第一地址域、第一功能域和第一数据域,在Modbus TCP的网络模式下,主机发送的数据请求报文携带第一TCP报文头、第一Modbus TCP报文头和第一Modbus数据帧,第一Modbus数据帧包括第一地址域、第一功能域和第一数据域。
步骤302:第一从机接收主机发送的数据请求报文。
在本申请实施例中,主机向第一从机发送数据请求报文之后,根据数据请求报文中携带的第一从机的地址,将该数据请求报文发送给第一从机,第一从机接收主机发送的该数据请求报文。
步骤303:第一从机根据该一个或多个分段采集指示信息,确定一个或多个分段数据,该一个或多个分段数据中的每个分段数据携带的数据数量大于0,且小于或等于256。
在本申请实施例中,第一从机在接收到数据请求报文之后,能够根据数据请求报文携带的一个或多个分段指示信息,来分段读取相应的数据,以确定一个或多个分段数据。
在本申请实施例中,该一个或多个分段数据中的每个分段数据包括一个起始地址、一个数据数量和第一数据,第一数据为第一从机根据相应分段采集指示信息读取的数据。需要说明的是,该一个或多个分段数据中的每个分段数据携带的数据数量大于0,且小于或等于256。
由前述可知,一个或多个分段采集指示信息中的每个分段采集指示信息包括一个起始地址和一个数据数量,第一从机从第一起始地址开始连续读取第一数据数量的数据,得到第一数据,之后,第一从机将第一起始地址、第一数据数量和第一数据作为一个分段数据。其中,第一起始地址为第一分段采集指示信息包括的起始地址,第一数据数量为第一分段采集指示信息包括的数据数量,第一分段采集指示信息为一个或多个分段采集指示信息中的一个。
第一从机根据该一个或多个分段采集指示信息中的每个分段采集指示信息读取完全部数据之后,得到该一个或多个分段数据,该一个或多个分段数据即为第一从机响应于该一个或多个分段采集指示信息所提供的数据。
需要说明的是,每个分段数据包括的第一数据的长度为相应数据数量乘以单位数据长度,单位数据长度是指主机所采集的一个数据的长度,例如,一个寄存器数据的长度为两个字节,对应的单位数据长度即等于两字节,一个线圈数据的长度为一个字节,对应的单位数据长度 即等于一字节。
示例性地,假设主机采集第一从机上的寄存器数据,一个寄存器数据的长度为两个字节,单位数据长度等于两字节,上述起始地址为寄存器地址,数据数量为寄存器数目,第一从机接收到的数据请求报文携带3个分段采集指示信息,第一个分段采集指示信息包括寄存器地址D1和寄存器数目N1,第二个分段采集指示信息包括寄存器地址D2和寄存器数目N2,第三个分段采集指示信息包括寄存器地址D3和寄存器数目N3,那么第一从机从D1开始连续读取N1个寄存器数据,得到第一个分段数据,第一个分段数据的长度为2*N1,从D2开始连续读取N2个寄存器数据,得到第二个分段数据,第二个分段数据的长度为2*N2,从D3开始连续读取N3个寄存器数据,得到第三个分段数据,第三个分段数据的长度为2*N3。
第一从机在读取到该一个或多个分段数据之后,将该一个或多个分段数据封装在数据响应报文中,也即数据响应报文携带该一个或多个分段数据。
在本申请实施例中,同样对Modbus报文进行扩展,得到数据响应报文。数据响应报文包括第二地址域、第二功能域和第二数据域,第二地址域携带第一从机的地址,第二功能域携带第二功能码,第二数据域携带该一个或多个分段数据,第二功能码用于指示第一从机实际执行的功能。
可选地,第二地址域的长度为一个字节,也即第一从机的地址以一个字节表示,第二地址域和第二功能域的值相同。第二功能域的长度为一个字节或两个字节,需要说明的是,第二功能域的值与第一功能域携带的功能码相同,表示第一从机正确执行了主机请求执行的功能。也即是,在第一功能域仅包括第一功能码的情况下,第二功能域也仅包括第二功能码,且在第一从机正确执行相应功能的情况下,第二功能码与第一功能码相同,在第一功能域包括第一功能码和第一子功能码的情况下,第二功能域也包括第二功能码和第二子功能码,且在第一从机正确执行相应功能的情况下,第二功能码和第一功能码相同,第二子功能码和第一子功能码也相同。
示例性地,假设第一功能域包括第一功能码和第一子功能码,第一功能码为十六进制的0x41,第一子功能码为十六进制的0x33,在第一从机正确执行了相应功能的情况下,第二功能域包括第二功能码和第二子功能码,且第二功能码也为十六进制的0x41,第二子功能码也为十六进制的0x33。
由前述可知,为了提高主机与从机之间通信的可靠性,第一数据域还携带第一帧序号,在这种情况下,第二数据域还携带第二帧序号,第一帧序号和第二帧序号用于主机将数据请求报文与数据响应报文进行帧匹配。例如,第一从机在解析数据请求报文,得到第一帧序号之后,第一从机将数据响应报文携带的第二帧序号设置与第一帧序号相同,以指示主机将该数据响应报文与数据请求报文进行帧匹配。
可选地,第二帧序号的长度与第一帧序号相同,为一个字节,或者两个字节,或为其他长度。
可选地,第二数据域还携带分段响应数,分段响应数用于指示第一从机实际分段采集的数据的分段数量。也即是,由第一从机直接将实际响应的分段数量携带在数据响应报文中,无需主机根据一个或多个分段数据,来累加计算得到该分段数量。
需要说明的是,在第一从机按照该一个或多个分段采集指示信息正确读取数据的情况下,该分段响应数与分段请求数相同。可选地,分段响应数的长度与分段请求数的长度相同,也 即分段响应数与分段请求数为对应的字段,以保证主机和从机将相对应的字段按照相同长度封装成报文,保证通信双方均能正确解析报文。
可选地,第二数据域还携带第二数据长度,第二数据长度的值为十六进制的0xFF,表示第二数据长度为无效值,主机在解析数据响应报文得到该值之后,获知第一从机也并不通过第二数据长度来限制实际读取的数据的长度,从而主机直接忽略第二数据长度。
可选地,在第一从机根据一个分段采集指示信息,并未寻址读取到数据的情况下,第一从机可以将相应的起始地址、数据数量和错误信息,作为相应的分段数据,以指示主机未获取到相应数据。可选地,错误信息由一个字节表示,值为0xFF,表示相应分段数据无效。
表2是对本申请实施例提供的一种数据响应报文的格式描述。参见表2,数据响应报文包括第二地址域(未示出)和第二协议数据单元(protocol data unit,PDU),第二PDU包括第二功能域和第二数据域,第二功能域携带第二功能码和第二子功能码,第二功能码和第二子功能码的长度均为一个字节,在本申请实施例中,第二功能码与第一功能码相同,为十六进制的0x41,第二子功能码与第一子功能码相同,为十六进制的0x33。第二数据域携带第二数据长度、第二帧序号、分段响应数和n个分段数据。其中,第二数据长度的长度为一个字节,值为十六进制的0xFF,表示第二数据长度为无效值,第二帧序号的长度为一个字节,第二帧序号与第一帧序号相同,第二帧序号由第一从机回填,第一从机在数据响应报文中回填的第二帧序号与第一帧序号相同,分段响应数的长度为一个字节,值为十进制的1-256中的任一个,值用符号表示为numBlock,表示分为n段响应,也即n=numBlock,在第一从机正确响应的情况下,分段响应数与分段请求数相同。表2中以分段1-n表示这n个分段数据,每个分段数据包括一个起始地址、一个数据数量和一个第一数据,起始地址的长度为两个字节,数据数量的长度为一个字节,表示第一从机从该起始地址开始读取了该数据数量的数据,第一数据的长度为单位数据长度乘以相应数据数量。表2中以采集寄存器数据为例,一个寄存器数据的长度为2个字节,也即单位数据长度为两字节,假设第i个分段数据携带的数据数量为munRegBlocki,那么第i个分段数据携带的第一数据的长度为2*munRegBlocki,第i个分段数据的总长度为3+2*munRegBlocki。
表2
Figure PCTCN2020107513-appb-000002
在本申请实施例中,假设分段请求数和分段响应数均以一个字节表示,值均为numBlock,那么numBlock的最大值为256,表示主机分段请求以及从机分段响应最多能分256段采集数 据,假设采集寄存器数据,每个分段数据携带的数据数量以一个字节表示,也即每个分段数据最多携带的数据数量为256,那么每个分段数据携带的第一数据的数据量最多可达2*256字节,也即512字节,这样,在最多请求256段,每个分段数据最多携带512字节的有效数据的情况下,主机与第一从机之间通过一次交互即最多可采集131072字节的有效数据,大大提高了通信效率。
由前述可知,主机配置的工作模式有Modbus RTU的总线模式或者Modbus TCP的网络模式,那么,在主机选择Modbus RTU的总线模式的情况下,第一从机也按照Modbus RTU的总线模式封装数据响应报文,也即数据响应报文携带第二地址域、第二功能域和第二数据域,在主机选择Modbus TCP的网络模式的情况下,第一从机也按照Modbus TCP的网络模式封装数据响应报文,也即数据响应报文携带第二TCP报文头、第二Modbus TCP报文头和第二Modbus数据帧,第二Modbus数据帧包括第二地址域、第二功能域和第二数据域。
步骤304:第一从机向主机发送数据响应报文,该数据响应报文携带该一个或多个分段数据。
在本申请实施例中,第一从机在封装得到数据响应报文之后,向主机发送该数据响应报文。
步骤305:主机接收第一从机发送的数据响应报文。
在本申请实施例中,主机在接收到第一从机发送的数据响应报文之后,能够解析获取该数据响应报文携带的一个或多个分段数据,也即获取到需要采集的数据。
可选地,在数据响应报文携带第二帧序号的情况下,主机将发送的数据请求报文中携带的第一帧序号与第二帧序号相同的数据请求报文,与该数据响应报文进行匹配,以确定接收到正确匹配的数据响应报文。如果接收到第一从机发送的数据响应报文携带的第二帧序号与第一帧序号不同,那么主机确定该数据响应报文为异常报文,将该数据响应报文丢弃,或者作为历史数据处理,或者作其他处理。
可选地,主机与第一从机之间配置有超时应答机制,主机在第一从机未超时应答之前,一直等待第一从机应答,且在主机接收到第一从机应答的情况下,判断应答的第二帧序号是否与请求的第一帧序号相同,如果帧序号相同,则主机正常接收数据响应报文,如果帧序号不同,则主机确定该数据响应报文为异常报文,主机在第一从机未超时应答之前,继续等待第一从机应答正确的数据响应报文。可选地,主机在第一从机超时未响应的情况下,如果接收到携带的第二帧序号与第一帧序号相同的数据响应报文,主机确定该数据响应报文为异常报文,主机重新向第一从机发送数据请求报文以请求采集数据,此时发送的数据请求报文携带的第一帧序号与上一次发送的数据求报文携带的第一帧序号相同或不同。
示例性地,参见图4,第一从机为空调1,主机在t1时刻向第一从机发送携带帧序号为1的数据请求报文,第一从机超时未应答,主机在t4时刻向第一从机发送携带帧序号为y的数据请求报文,主机在t5时刻接收到第一从机应答携带帧序号为1的数据响应报文,由于应答的帧序号不是y,因此,主机将携带帧序号为1的数据响应报文丢弃,主机在t6时刻接收到第一从机发送的携带帧序号为y的数据响应报文,该数据响应报文未超时,主机将该数据响应报文正常解析作数据处理。
以上以主机与第一从机之间的交互为例,对本申请实施例提供的数据采集方法进行了介绍,需要说明的是,对于Modbus系统包括的多个从机中除第一从机之外的其他从机,主机均 可以按照与采集第一从机上的数据相同的方法来采集其他各个从机上的数据,这里对此不再赘述。
在本申请实施例中,对于Modbus系统包括的多个从机,主机可以灵活设置采集各个从机上的数据的采集时间,以提高Modbus系统的整体性能,也即保证通信效率、通信质量以及系统实时性。也即是,在申请实施例中,主机采集该多个从机上的数据的采集方法有多种实现方式,接下来介绍其中的三种实现方式。
第一种实现方式、主机在同一时刻向该多个从机中的每个从机发送对应的数据请求报文,以完成一轮采集。
在本申请实施例中,主机在同一时刻向该多个从机中的每个从机发送对应的数据请求报文,之后,主机等待各个从机应答。在主机接收到该多个从机中的每个从机发送的数据响应报文之后,确定本轮采集完成,之后开始下一轮采集。或者,主机上设置有采集周期,主机在一个采集周期内等待各个从机应答,在下一个采集周期到达时,主机不再等待,而直接开始下一轮采集。
需要说明的是,在第一种实现方式中,主机在同一时刻向多个从机请求数据,一些从机可能会同时响应,在主机和从机工作在Modbus TCP的网络模式的情况下,这些从机即使同时响应也不会存在冲突,主机能够顺利接收到这些从机的应答,而在主机和从机工作在Modbus RTU的总线模式的情况下,这些从机同时响应可能会发生冲突,导致主机接收不到这些从机的应答。也即是,第一种实现方式适用于Modbus TCP的网络模式。
在这种实现方式中,主机在一轮采集开始时,同时向所有的从机请求数据,无需等待某个从机响应完再请求下一个,这样大大缩小了一轮采集的时长,减小了耗时。
第二种实现方式、主机根据轮询顺序,依次向该多个从机中的每个从机发送对应的数据请求报文,以完成一轮采集。
在本申请实施例中,主机上配置有轮询顺序,主机按照轮询顺序,依次向该多个从机中的每个从机发送对应的数据请求报文,也即是,主机在向第一个从机发送数据请求报文之后,等待第一个从机应答,在第一个从机应答之后,再向第二个从机发送数据请求报文,以此类推,直至主机向最后一个从机请求采集数据,并接收到最后一个从机的应答,主机确定完成一轮采集。
示例性地,参见图5,该多个从机包括空调1、空调2、母线槽1和配电箱1,轮询顺序为空调1、空调2、母线槽1和配电箱1。在t1时刻主机开始一轮采集,也即主机在t1时刻向空调1发送携带帧序号为1的数据请求报文,在t2时刻接收到空调1应答的携带帧序号为1的数据响应报文之后进行数据处理,在t3时刻向空调2发送携带帧序号为2的数据请求报文,在t4时刻接收到空调2应答的携带帧序号为2的数据响应报文之后进行数据处理,在t5时刻向母线槽1发送携带帧序号为n-1的数据请求报文,在t6时刻接收到母线槽1应答的携带帧序号为n-1的数据响应报文之后进行数据处理,在t7时刻向配电箱1发送携带帧序号为n的数据请求报文,在t8时刻接收到配电箱1应答的携带帧序号为n的数据响应报文之后进行数据处理,到此完成一轮采集。
在这种实现方式中,主机与从机之间采用一问一答的方式,根据轮询顺序依次请求该多个从机以完成一轮采集,能够保证主机在一轮采集中成功轮询采集到每个从机上的数据。
第三种实现方式、主机根据该多个从机中的每个从机上待采集数据的数据量,确定相应 从机对应的采集时间,主机按照该多个从机中的每个从机对应的采集时间,向该多个从机中的每个从机发送对应的数据请求报文。
在本申请实施例中,主机能够根据各个从机上待采集数据的数据量,确定相应从机对应的采集时间,例如,主机确定每个从机对应的采集周期,或者,主机确定下一次采集某个从机的具体时间。
示例性地,假设主机采集各个从机上的寄存器数据,从机1上的寄存器较多,需要采集的数据量较大,那么主机将从机1的采集周期确定为10s,从机2上的寄存器较少,需要采集的数据量较小,那么主机将从机1的采集周期确定为1s。
在这种实现方式中,主机按照各个从机上待采集数据的数据量,更加灵活地确定各个从机对应的采集时间,能够提高采集方法的灵活性,充分利用系统资源,避免某些从机数据量较大而导致应答业务过忙,而另一些从机数据量较小却迟迟得不到采集。
除以上介绍的三种实现方式之外,可选地,主机根据该多个从机中的每个从机对应的业务实时性要求,来确定相应从机的采集时间,主机按照该多个从机中的每个从机对应的采集时间,向该多个从机中的每个从机发送对应的数据请求报文,这样,能够满足各个从机对应的业务实时性要求,也即对于对应的业务实时性较高的从机,主机以较高的频率来采集相应从机上的数据,对于对应的业务实时性较低的从机,主机以较低的频率来采集相应从机上的数据。
可选地,主机根据各个从机上待采集数据的数据量,以及各个从机对应的业务实时性要求,来确定相应从机的采集时间,以同时兼顾数据量大小和实时性需求,保证提高Modbus系统的整体性能。
可选地,主机按照用户配置的采集时间,来向各个从机请求采集数据。
除以上介绍的一些实现方式之外,主机也以其他任一种可能的实现方式向各个从机发送对应的数据请求报文,以采集相应从机上的数据。
由于本方案通过主机与从机之间交互长数据报文来提高通信效率,因此,主机与从机之间能够通过一次交互即将相应从机上的数据采集完。可选地,在一次采集中,主机通过向一个从机发送多个数据请求报文,以通过多次交互将相应从机上的数据采集完。例如,一个从机上需要采集的寄存器数据上千,甚至更多,如果通过一次交互来携带这么多数据量的话,可能会影响通信质量和可靠性,如果存在从机响应的报文丢失或者超时未响应,那么主机将采集不到该从机上的任何数据,在这种情况下,如果主机通过与该从机多次交互来采集所有数据,则在一定程度上保证主机能够采集到该从机上的数据。
另外,需要说明的是,在本申请实施例中,如前述第二种实现方式,主机与从机之间采用一问一答的方式轮询各个从机来采集数据,能够保证轮询采集到每个从机上的数据,又如前述其他实现方式,主机与从机之间采用多问多答的方式来采集各个从机上的数据,能够提高采集方法的灵活性,充分利用系统资源。
示例性地,参见图6,该多个从机包括空调1、空调2、母线槽1和配电箱1,主机在t1、t2和t3时刻分别向空调1发送分别携带帧序号为1、2和3的数据请求报文,在t4时刻向空调2发送携带帧序号为4的数据请求报文,在t5时刻接收到空调1应答的携带帧序号为1的数据响应报文,在t6时刻向空调2发送携带帧序号为5的数据请求报文,在t7时刻接收到空调1应答的携带帧序号为2的数据响应报文,在t8时刻向母线槽1发送携带帧序号为6的数 据请求报文,在t9时刻接收到空调2应答的携带帧序号为4的数据响应报文,在t10时刻接收到空调1应答的携带帧序号为3的数据响应报文,在t11时刻接收到空调2应答的携带帧序号为5的数据响应报文,在t12时刻向配电箱1发送携带帧序号为7的数据请求报文,在t13时刻接收到母线槽1应答的携带帧序号为6的数据响应报文,在t14时刻接收到配电箱1应答的携带帧序号为7的数据响应报文。
由图6可以看出,主机与从机之间采用多问多答的方式,主机不必等待某个从机应答之后再请求其他从机,从机也不必立即应答主机的某次请求,在对应的业务实时性要求较低的情况下,从机在较为空闲的时间应答主机即可,不影响从机上的其他业务。另外,主机与从机之间通过一次交互将相应从机上的数据采集完,如图6所示的主机与空调1、主机与空调2,或者,主机与从机之间通过一次交互将相应从机上的数据采集完,如图6所示的主机与母线槽1、主机与配线箱1。
综上所述,在本申请实施例中,主机与从机在一次交互中能够采集一个或多个分段数据,每个分段数据携带的数据数量最大为256。在Modbus系统中,一个数据最小以一字节表示,那么每个分段数据携带的数据最多为256字节,如果一次交互中能够采集到多个分段数据,那么能够采集的数据量将远大于协议限制的252字节。也即本方案中,主机与从机在一次交互中能够采集的数据量将更多,在需要采集的数据量一定的情况下,能够减少主机与从机之间的交互次数,这样总线占用频率将降低但占用率提高,通信效率提高。另外,由于从机一次响应所提供的数据量更多,主机不会长时间耗费在一个从机上,因此,整个Modbus系统的实时性将得到提高。
图7是本申请实施例提供的一种数据采集装置的结构示意图。可选地,该数据采集装置700由软件、硬件或者两者的结合实现成为Modbus系统包括的主机,Modbus系统还包括多个从机,参见图7,该装置700包括:发送模块701和接收模块702。
发送模块701,用于向第一从机发送数据请求报文,该数据请求报文携带一个或多个分段采集指示信息,该一个或多个分段采集指示信息中的每个分段采集指示信息用于指示主机从第一从机中需要采集的数据,第一从机为多个从机中的一个;具体实现方式请参考图3实施例中步骤301的详细描述,这里不再赘述。
接收模块702,用于接收第一从机发送的数据响应报文,数据响应报文携带一个或多个分段数据,该一个或多个分段数据是第一从机响应于该一个或多个分段采集指示信息所提供的数据,该一个或多个分段数据中的每个分段数据携带的数据数量大于0,且小于或等于256。具体实现方式请参考图3实施例中步骤303-305的详细描述,这里不再赘述。
可选地,该装置700还包括:
确定模块,用于根据第一从机上待采集数据的地址分布特征,确定一个或多个分段采集指示信息。具体实现方式请参考图3实施例中步骤301的相关描述,这里不再赘述。
可选地,该一个或多个分段采集指示信息中的每个分段采集指示信息包括一个起始地址和一个数据数量;
该一个或多个分段数据中的每个分段数据包括一个起始地址、一个数据数量和第一数据,第一数据为第一从机根据相应分段采集指示信息读取的数据。
可选地,数据请求报文包括第一地址域、第一功能域和第一数据域,第一地址域携带第 一从机的地址,第一功能域携带第一功能码,第一数据域携带一个或多个分段采集指示信息,第一功能码用于指示主机请求第一从机执行采集数据的功能;
数据响应报文包括第二地址域、第二功能域和第二数据域,第二地址域携带第一从机的地址,第二功能域携带第二功能码,第二数据域携带一个或多个分段数据,第二功能码用于指示第一从机实际执行的功能。数据请求报文和数据响应报文的具体实现方式请参考图3实施例中步骤301-305的相关描述,这里不再赘述。
可选地,第一数据域还携带第一帧序号,第二数据域还携带第二帧序号,第一帧序号和第二帧序号用于主机将数据请求报文与数据响应报文进行帧匹配。
可选地,第一数据域还携带分段请求数,分段请求数用于指示主机请求第一从机分段采集的数据的分段数量;
第二数据域还携带分段响应数,分段响应数用于指示第一从机实际分段采集的数据的分段数量。
可选地,主机在同一时刻向该多个从机中的每个从机发送对应的数据请求报文,以完成一轮采集;或者,
主机根据轮询顺序,依次向该多个从机中的每个从机发送对应的数据请求报文,以完成一轮采集;或者,
主机根据该多个从机中的每个从机上待采集数据的数据量,确定相应从机对应的采集时间,主机按照该多个从机中的每个从机对应的采集时间,向该多个从机中的每个从机发送对应的数据请求报文。
主机与多个从机交互的具体实现方式请参考图3实施例中步骤305的相关描述,以及对图5和图6的相关描述,这里不再赘述。
在本申请实施例中,主机与从机在一次交互中能够采集一个或多个分段数据,每个分段数据携带的数据数量最大为256。在Modbus系统中,一个数据最小以一字节表示,那么每个分段数据携带的数据最多为256字节,如果一次交互中能够采集到多个分段数据,那么能够采集的数据量将远大于协议限制的252字节。也即本方案中,主机与从机在一次交互中能够采集的数据量将更多,在需要采集的数据量一定的情况下,能够减少主机与从机之间的交互次数,这样总线占用频率将降低但占用率提高,通信效率提高。另外,由于从机一次响应所提供数据量更多,主机不会长时间耗费在一个从机上,因此,整个Modbus系统的实时性将得到提高。
需要说明的是:上述实施例提供的数据采集装置在采集数据时,仅以上述各功能模块的划分进行举例说明,实际应用中,可以根据需要而将上述功能分配由不同的功能模块完成,即将装置的内部结构划分成不同的功能模块,以完成以上描述的全部或者部分功能。另外,上述实施例提供的数据采集装置与数据采集方法实施例属于同一构思,其具体实现过程详见方法实施例,这里不再赘述。
图8是本申请实施例提供的另一种数据采集装置的结构示意图。可选地,该数据采集装置800由软件、硬件或者两者的结合实现成为Modbus系统包括的第一从机,第一从机为Modbus系统包括的多个从机中的一个,该Modbus系统还包括主机,参见图8,该装置800包括:接收模块801、确定模块802和发送模块803。
接收模块801,用于接收主机发送的数据请求报文,该数据请求报文携带一个或多个分段采集指示信息,该一个或多个分段采集指示信息中的每个分段采集指示信息用于指示主机从第一从机中需要采集的数据;具体实现方式请参考图3实施例中步骤301和步骤302的详细描述,这里不再赘述。
确定模块802,用于根据该一个或多个分段采集指示信息,确定一个或多个分段数据;具体实现方式请参考图3实施例中步骤303的详细描述,这里不再赘述。
发送模块803,用于向主机发送数据响应报文,数据响应报文携带该一个或多个分段数据,该一个或多个分段数据中的每个分段数据携带的数据数量大于0,且小于或等于256。具体实现方式请参考图3实施例中步骤303-305的详细描述,这里不再赘述。
可选地,该一个或多个分段采集指示信息中的每个分段采集指示信息包括一个起始地址和一个数据数量;
确定模块802包括:
读取子模块,用于从第一起始地址开始连续读取第一数据数量的数据,得到第一数据,第一起始地址为第一分段采集指示信息包括的起始地址,第一数据数量为第一分段采集指示信息包括的数据数量,第一分段采集指示信息为该一个或多个分段采集指示信息中的一个;
确定子模块,用于将第一起始地址、第一数据数量和第一数据作为一个分段数据。具体实现方式请参考图3实施例中步骤303的相关描述,这里不再赘述。
在本申请实施例中,主机与从机在一次交互中能够采集一个或多个分段数据,每个分段数据携带的数据数量最大为256。在Modbus系统中,一个数据最小以一字节表示,那么每个分段数据携带的数据最多为256字节,如果一次交互中能够采集到多个分段数据,那么能够采集的数据量将远大于协议限制的252字节。也即本方案中,主机与从机在一次交互中能够采集的数据量将更多,在需要采集的数据量一定的情况下,能够减少主机与从机之间的交互次数,这样总线占用频率将降低但占用率提高,通信效率提高。另外,由于从机一次响应所提供的数据量更多,主机不会长时间耗费在一个从机上,因此,整个Modbus系统的实时性将得到提高。
需要说明的是:上述实施例提供的数据采集装置在用于数据采集时,仅以上述各功能模块的划分进行举例说明,实际应用中,可以根据需要而将上述功能分配由不同的功能模块完成,即将装置的内部结构划分成不同的功能模块,以完成以上描述的全部或者部分功能。另外,上述实施例提供的数据采集装置与数据采集方法实施例属于同一构思,其具体实现过程详见方法实施例,这里不再赘述。
本申请实施例提供了一种Modbus系统,Modbus系统包括主机和多个从机,第一从机为该多个从机中的一个。主机和第一从机具有实现前述实施例提供的数据采集方法的相应功能,以通过Modbus系统实现数据采集。具体实现方式请参考图3实施例的详细描述,这里不再赘述。
在本申请实施例中,主机与从机在一次交互中能够采集一个或多个分段数据,每个分段数据携带的数据数量最大为256。在Modbus系统中,一个数据最小以一字节表示,那么每个分段数据携带的数据最多为256字节,如果一次交互中能够采集到多个分段数据,那么能够采集的数据量将远大于协议限制的252字节。也即本方案中,主机与从机在一次交互中能够 采集的数据量将更多,在需要采集的数据量一定的情况下,能够减少主机与从机之间的交互次数,这样总线占用频率将降低但占用率提高,通信效率提高。另外,由于从机一次响应所提供的数据量更多,主机不会长时间耗费在一个从机上,因此,整个Modbus系统的实时性将得到提高。
需要说明的是:上述实施例提供的Modbus系统与数据采集方法实施例属于同一构思,其具体实现过程详见方法实施例,这里不再赘述。
在上述实施例中,可以全部或部分地通过软件、硬件、固件或者其任意结合来实现。当使用软件实现时,可以全部或部分地以计算机程序产品的形式实现。所述计算机程序产品包括一个或多个计算机指令。在计算机上加载和执行所述计算机指令时,全部或部分地产生按照本申请实施例所述的流程或功能。所述计算机可以是通用计算机、专用计算机、计算机网络或其他可编程装置。所述计算机指令可以存储在计算机可读存储介质中,或者从一个计算机可读存储介质向另一个计算机可读存储介质传输,例如,所述计算机指令可以从一个网站站点、计算机、服务器或数据中心通过有线(例如:同轴电缆、光纤、数据用户线(digital subscriber line,DSL))或无线(例如:红外、无线、微波等)方式向另一个网站站点、计算机、服务器或数据中心进行传输。所述计算机可读存储介质可以是计算机能够存取的任何可用介质,或者是包含一个或多个可用介质集成的服务器、数据中心等数据存储设备。所述可用介质可以是磁性介质(例如:软盘、硬盘、磁带)、光介质(例如:数字通用光盘(digital versatile disc,DVD))或半导体介质(例如:固态硬盘(solid state disk,SSD))等。值得注意的是,本申请实施例提到的计算机可读存储介质可以为非易失性存储介质,换句话说,可以是非瞬时性存储介质。
本领域普通技术人员可以理解实现上述实施例的全部或部分步骤可以通过硬件来完成,也可以通过程序来指令相关的硬件完成,所述的程序可以存储于一种计算机可读存储介质中,上述提到的存储介质可以是只读存储器,磁盘或光盘等。
应当理解的是,本文提及的“至少一个”是指一个或多个,“多个”是指两个或两个以上。在本申请实施例的描述中,除非另有说明,“/”表示或的意思,例如,A/B可以表示A或B;本文中的“和/或”仅仅是一种描述关联对象的关联关系,表示可以存在三种关系,例如,A和/或B,可以表示:单独存在A,同时存在A和B,单独存在B这三种情况。另外,为了便于清楚描述本申请实施例的技术方案,在本申请的实施例中,采用了“第一”、“第二”等字样对功能和作用基本相同的相同项或相似项进行区分。本领域技术人员可以理解“第一”、“第二”等字样并不对数量和执行次序进行限定,并且“第一”、“第二”等字样也并不限定一定不同。
以上所述仅为本申请的示例性实施例,并不用以限制本申请,凡在本申请的精神和原则之内,所作的任何修改、等同替换、改进等,均应包含在本申请的保护范围之内。

Claims (15)

  1. 一种数据采集方法,其特征在于,所述数据采集方法应用于Modbus系统中的主机,所述Modbus系统还包括多个从机,所述方法包括:
    所述主机向第一从机发送数据请求报文,所述数据请求报文携带一个或多个分段采集指示信息,所述一个或多个分段采集指示信息中的每个分段采集指示信息用于指示所述主机从所述第一从机中需要采集的数据,所述第一从机为所述多个从机中的一个;
    所述主机接收所述第一从机发送的数据响应报文,所述数据响应报文携带一个或多个分段数据,所述一个或多个分段数据是所述第一从机响应于所述一个或多个分段采集指示信息所提供的数据,所述一个或多个分段数据中的每个分段数据携带的数据数量大于0,且小于或等于256。
  2. 如权利要求1所述的方法,其特征在于,所述主机向第一从机发送数据请求报文之前,还包括:
    所述主机根据所述第一从机上待采集数据的地址分布特征,确定所述一个或多个分段采集指示信息。
  3. 如权利要求1或2所述的方法,其特征在于,所述一个或多个分段采集指示信息中的每个分段采集指示信息包括一个起始地址和一个数据数量;
    所述一个或多个分段数据中的每个分段数据包括一个起始地址、一个数据数量和第一数据,所述第一数据为所述第一从机根据相应分段采集指示信息读取的数据。
  4. 如权利要求1-3任一所述的方法,其特征在于,所述数据请求报文包括第一地址域、第一功能域和第一数据域,所述第一地址域携带所述第一从机的地址,所述第一功能域携带第一功能码,所述第一数据域携带所述一个或多个分段采集指示信息,所述第一功能码用于指示所述主机请求所述第一从机执行采集数据的功能;
    所述数据响应报文包括第二地址域、第二功能域和第二数据域,所述第二地址域携带所述第一从机的地址,所述第二功能域携带第二功能码,所述第二数据域携带所述一个或多个分段数据,所述第二功能码用于指示所述第一从机实际执行的功能。
  5. 如权利要求4所述的方法,其特征在于,所述第一数据域还携带第一帧序号,所述第二数据域还携带第二帧序号,所述第一帧序号和第二帧序号用于所述主机将所述数据请求报文与所述数据响应报文进行帧匹配。
  6. 如权利要求4或5所述的方法,其特征在于,所述第一数据域还携带分段请求数,所述分段请求数用于指示所述主机请求所述第一从机分段采集的数据的分段数量;
    所述第二数据域还携带分段响应数,所述分段响应数用于指示所述第一从机实际分段采集的数据的分段数量。
  7. 如权利要求1-6任一所述的方法,其特征在于,
    所述主机在同一时刻向所述多个从机中的每个从机发送对应的数据请求报文,以完成一轮采集;或者,
    所述主机根据轮询顺序,依次向所述多个从机中的每个从机发送对应的数据请求报文,以完成一轮采集;或者,
    所述主机根据所述多个从机中的每个从机上待采集数据的数据量,确定相应从机对应的采集时间,所述主机按照所述多个从机中的每个从机对应的采集时间,向所述多个从机中的每个从机发送对应的数据请求报文。
  8. 一种数据采集方法,其特征在于,所述数据采集方法应用于Modbus系统中的第一从机,所述第一从机为所述Modbus系统包括的多个从机中的一个,所述Modbus系统还包括主机,所述方法包括:
    第一从机接收所述主机发送的数据请求报文,所述数据请求报文携带一个或多个分段采集指示信息,所述一个或多个分段采集指示信息中的每个分段采集指示信息用于指示所述主机从所述第一从机中需要采集的数据,所述第一从机为所述多个从机中的一个;
    所述第一从机根据所述一个或多个分段采集指示信息,确定一个或多个分段数据;
    所述第一从机向所述主机发送数据响应报文,所述数据响应报文携带所述一个或多个分段数据,所述一个或多个分段数据中的每个分段数据携带的数据数量大于0,且小于或等于256。
  9. 如权利要求8所述的方法,其特征在于,所述一个或多个分段采集指示信息中的每个分段采集指示信息包括一个起始地址和一个数据数量;
    所述第一从机根据所述一个或多个分段采集指示信息,确定一个或多个分段数据,包括:
    所述第一从机从第一起始地址开始连续读取第一数据数量的数据,得到第一数据,所述第一起始地址为第一分段采集指示信息包括的起始地址,所述第一数据数量为所述第一分段采集指示信息包括的数据数量,所述第一分段采集指示信息为所述一个或多个分段采集指示信息中的一个;
    所述第一从机将所述第一起始地址、所述第一数据数量和所述第一数据作为一个分段数据。
  10. 一种数据采集装置,其特征在于,所述装置应用于Modbus系统中的主机,所述Modbus系统还包括多个从机,所述装置包括:
    发送模块,用于向第一从机发送数据请求报文,所述数据请求报文携带一个或多个分段采集指示信息,所述一个或多个分段采集指示信息中的每个分段采集指示信息用于指示所述主机从所述第一从机中需要采集的数据,所述第一从机为所述多个从机中的一个;
    接收模块,用于接收所述第一从机发送的数据响应报文,所述数据响应报文携带一个或多个分段数据,所述一个或多个分段数据是所述第一从机响应于所述一个或多个分段采集指示信息所提供的数据,所述一个或多个分段数据中的每个分段数据携带的数据数量大于0, 且小于或等于256。
  11. 一种数据采集装置,其特征在于,所述装置应用于Modbus系统中的第一从机,所述第一从机为所述Modbus系统包括的多个从机中的一个,所述Modbus系统还包括主机,所述装置包括:
    接收模块,用于接收所述主机发送的数据请求报文,所述数据请求报文携带一个或多个分段采集指示信息,所述一个或多个分段采集指示信息中的每个分段采集指示信息用于指示所述主机从所述第一从机中需要采集的数据;
    确定模块,用于根据所述一个或多个分段采集指示信息,确定一个或多个分段数据;
    发送模块,用于向所述主机发送数据响应报文,所述数据响应报文携带所述一个或多个分段数据,所述一个或多个分段数据中的每个分段数据携带的数据数量大于0,且小于或等于256。
  12. 一种数据采集装置,其特征在于,所述装置用于Modbus系统包括的主机,所述Modbus系统还包括多个从机,所述装置包括存储器和处理器;
    所述存储器,用于存储计算机程序;
    所述处理器,用于执行所述计算机程序时实现权利要求1-7任一所述的方法。
  13. 一种数据采集装置,其特征在于,所述装置用于Modbus系统包括的第一从机,所述第一从机为所述Modbus系统包括的多个从机中的一个,所述Modbus系统还包括主机,所述装置包括处理器和存储器;
    所述存储器,用于存储计算机程序;
    所述处理器,用于执行所述计算机程序时实现权利要求8或9所述的方法。
  14. 一种Modbus系统,其特征在于,所述系统包括主机和多个从机,第一从机为所述多个从机中的一个;
    所述主机,用于实现权利要求1-7任一所述的方法;
    所述第一从机,用于实现权利要求8或9所述的方法。
  15. 一种计算机可读存储介质,其特征在于,所述存储介质内存储有计算机程序,所述计算机程序被处理器执行时实现权利要求1-7任一所述的方法的步骤,或者,实现权利要求8或9所述的方法的步骤。
PCT/CN2020/107513 2020-08-06 2020-08-06 数据采集方法、装置、Modbus系统及存储介质 WO2022027480A1 (zh)

Priority Applications (4)

Application Number Priority Date Filing Date Title
EP20948320.5A EP4184831A4 (en) 2020-08-06 2020-08-06 DATA COLLECTION METHOD AND APPARATUS, MODBUS SYSTEM AND STORAGE MEDIA
CN202080007710.0A CN114391234A (zh) 2020-08-06 2020-08-06 数据采集方法、装置、Modbus系统及存储介质
PCT/CN2020/107513 WO2022027480A1 (zh) 2020-08-06 2020-08-06 数据采集方法、装置、Modbus系统及存储介质
US18/162,792 US20230188380A1 (en) 2020-08-06 2023-02-01 Data collection method and apparatus, modbus system, and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
PCT/CN2020/107513 WO2022027480A1 (zh) 2020-08-06 2020-08-06 数据采集方法、装置、Modbus系统及存储介质

Related Child Applications (1)

Application Number Title Priority Date Filing Date
US18/162,792 Continuation US20230188380A1 (en) 2020-08-06 2023-02-01 Data collection method and apparatus, modbus system, and storage medium

Publications (1)

Publication Number Publication Date
WO2022027480A1 true WO2022027480A1 (zh) 2022-02-10

Family

ID=80119824

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2020/107513 WO2022027480A1 (zh) 2020-08-06 2020-08-06 数据采集方法、装置、Modbus系统及存储介质

Country Status (4)

Country Link
US (1) US20230188380A1 (zh)
EP (1) EP4184831A4 (zh)
CN (1) CN114391234A (zh)
WO (1) WO2022027480A1 (zh)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115208958A (zh) * 2022-06-10 2022-10-18 珠海格力电器股份有限公司 协议自动分段方法和装置

Families Citing this family (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117729258B (zh) * 2024-02-18 2024-04-26 绿城科技产业服务集团有限公司 基于云边协同的边缘服务网关系统及方法
CN117896204B (zh) * 2024-03-14 2024-05-28 季华实验室 基于can的微波电源通信方法、装置、电子设备及存储介质

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101227348A (zh) * 2008-02-02 2008-07-23 杭州华三通信技术有限公司 一种对网络设备的性能统计数据进行采集的方法和服务器
US20080235346A1 (en) * 2007-03-22 2008-09-25 Moxa Technologies Co., Ltd. Method of detecting response time-out based on master-slave protocol architecture
CN102820959A (zh) * 2011-06-10 2012-12-12 哈尔滨工业大学 在Modbus主站与从站之间进行大数据量通信的方法
CN106027686A (zh) * 2016-08-02 2016-10-12 山东乐通达物联网科技有限公司 基于mpeg-2的增强型modbus通信协议
CN104158699B (zh) * 2014-08-08 2017-10-24 广州新科佳都科技有限公司 一种基于优先级和分段的数据采集方法

Family Cites Families (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104811427B (zh) * 2014-01-27 2017-12-19 沈阳中科奥维科技股份有限公司 一种安全的工业控制系统通信方法
CN104601420A (zh) * 2014-12-31 2015-05-06 江西清华泰豪三波电机有限公司 一种利用Modbus灵活读取电站数据的方法
KR20180061885A (ko) * 2016-11-30 2018-06-08 주식회사 케이티 폴링 시간을 줄이는 모드 버스의 통신을 제공하는 장치, 시스템 및 방법

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20080235346A1 (en) * 2007-03-22 2008-09-25 Moxa Technologies Co., Ltd. Method of detecting response time-out based on master-slave protocol architecture
CN101227348A (zh) * 2008-02-02 2008-07-23 杭州华三通信技术有限公司 一种对网络设备的性能统计数据进行采集的方法和服务器
CN102820959A (zh) * 2011-06-10 2012-12-12 哈尔滨工业大学 在Modbus主站与从站之间进行大数据量通信的方法
CN104158699B (zh) * 2014-08-08 2017-10-24 广州新科佳都科技有限公司 一种基于优先级和分段的数据采集方法
CN106027686A (zh) * 2016-08-02 2016-10-12 山东乐通达物联网科技有限公司 基于mpeg-2的增强型modbus通信协议

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115208958A (zh) * 2022-06-10 2022-10-18 珠海格力电器股份有限公司 协议自动分段方法和装置
CN115208958B (zh) * 2022-06-10 2023-08-25 珠海格力电器股份有限公司 协议自动分段方法和装置

Also Published As

Publication number Publication date
EP4184831A1 (en) 2023-05-24
US20230188380A1 (en) 2023-06-15
EP4184831A4 (en) 2023-08-30
CN114391234A (zh) 2022-04-22

Similar Documents

Publication Publication Date Title
WO2022027480A1 (zh) 数据采集方法、装置、Modbus系统及存储介质
US11528235B2 (en) Internet of things resource subscription method, device, and system
US11824787B2 (en) Method and apparatus for node speed limiting, electronic device and storage medium
CN106909081B (zh) 基于家电设备的扩展平台和家电设备
US11847091B2 (en) Data transmission method and device for network on chip and electronic apparatus
CN114338594B (zh) 在Kubernetes环境下的ARP代答方法、装置、设备及存储介质
WO2021088520A1 (zh) 网络数据分析方法、功能实体及电子设备
US20220239761A1 (en) Data Subscription Method, Apparatus, and System
CN111585815B (zh) 一种端口数据采集方法及装置
CN115623358A (zh) 一种抄表方法、抄表装置及抄表系统
US20210399986A1 (en) Data communication method, server device, client device and medium
WO2020177020A1 (zh) 物联网设备的发现方法、装置及终端设备
CN114090623A (zh) 一种缓存资源的创建方法、装置、电子设备及存储介质
US20230063202A1 (en) Method and Apparatus for Scheduling Service, Electronic Device, and Storage Medium
CN112422485B (zh) 一种传输控制协议的通信方法及装置
US11228537B2 (en) Resource processing method and system, storage medium and electronic device
EP4255093A1 (en) Method and apparatus for controlling multi-link device to transmit data, device and storage medium
CN116260725A (zh) 一种服务器的带宽分配方法、装置、电子设备及存储介质
CN115001897A (zh) 通信方法、装置、电子设备及自动驾驶车辆
WO2021022947A1 (zh) 一种部署虚拟机的方法及相关装置
CN110830584A (zh) 接入控制装置、控制方法、庭审主机及可读存储介质
CN116017412B (zh) 一种用于获取设备信息的网关设备、方法及系统
WO2024032599A1 (zh) 会话绑定方法及功能、存储介质及电子设备
WO2023279802A1 (zh) 协议数据传输方法、装置、网络节点及存储介质
CN111885613B (zh) 基于sig mesh的组网方法、节点设备以及计算机设备

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 20948320

Country of ref document: EP

Kind code of ref document: A1

ENP Entry into the national phase

Ref document number: 2020948320

Country of ref document: EP

Effective date: 20230214

NENP Non-entry into the national phase

Ref country code: DE