CN-122001703-A - Modbus protocol data acquisition method and system for different frequencies of multiple devices
Abstract
The invention discloses a multi-equipment heterogeneous-frequency Modbus protocol data acquisition method and system, which comprise the steps of receiving the attribute acquisition frequency and address of Modbus slave station equipment, grouping the Modbus slave station equipment based on the attribute acquisition frequency and address of the Modbus slave station equipment, starting a timing task for each equipment after frequency grouping, generating a globally unique Modbus Tcp connection and a data source based on the address of the Modbus slave station equipment, generating a data stream processing pipeline based on a pre-constructed responsive programming framework, triggering the timing task, pushing an acquisition request of the Modbus slave station equipment into the data stream processing pipeline for buffering, combining to generate a batch reading request, splitting response data returned based on the execution of the batch reading request in the data stream processing pipeline to obtain independent response data blocks, asynchronously issuing the independent response data blocks, and improving the processing performance of data acquisition.
Inventors
- Liu Houren
- ZENG BIN
- YU YONGZHI
- HU JIAJUN
- XIE YANFEI
- XU XIAOYU
- XIAO RENBO
- HU XUAN
- YU YANHONG
Assignees
- 江西航天鄱湖云科技有限公司
Dates
- Publication Date
- 20260508
- Application Date
- 20251225
Claims (10)
- 1. The Modbus protocol data acquisition method of the multi-equipment different frequencies is characterized by comprising the following steps of: Receiving attribute acquisition frequency and address of Modbus slave station equipment, grouping the Modbus slave station equipment based on the attribute acquisition frequency and address of the Modbus slave station equipment, and starting a timing task for each acquisition frequency; Generating a globally unique Modbus Tcp connection and a data source based on the address of Modbus slave station equipment, and generating a data stream processing pipeline based on a pre-constructed responsive programming framework; And splitting response data returned based on executing the batch reading request in a data stream processing pipeline to obtain independent response data blocks, and asynchronously issuing the independent response data blocks, so that the processing performance of data acquisition is improved.
- 2. The method for collecting Modbus protocol data with different frequencies according to claim 1, wherein the process of grouping Modbus slave devices based on the attribute collection frequency and address of the Modbus slave devices comprises: According to the attribute acquisition frequency grouping of Modbus slave station equipment, each group starts a timing acquisition task so as to reduce the creation of the timing task; Grouping according to addresses of Modbus slave station equipment, wherein each Modbus slave station equipment uses independent threads during acquisition, and acquisition requests of different Modbus slave station equipment are prevented from being blocked.
- 3. The method for collecting data according to claim 1, wherein the address of the Modbus slave station device globally maintains a sink.many data source, and the timing task triggers the downstream responsive flow Flux processing by pushing the collection task to the sink.many data source instead of directly collecting the data.
- 4. The method for collecting data according to the Modbus protocol of different frequencies of multiple devices according to claim 1, wherein when the collecting request of the Modbus slave station device is pushed into the data stream processing pipeline for buffering, the data flow rate is controlled by the buffer area, the upstream data is prevented from flooding the downstream, and the data is buffered and converged based on the mixed buffering strategy of the data arrival and the time window.
- 5. The method for multi-device heterogeneous frequency Modbus protocol data collection according to claim 4, wherein the data arrival and time window based hybrid buffering strategy is as follows: Assuming that the time window is t milliseconds, when the first data arrives, the buffer window is opened, and timing is started, after t milliseconds, the buffer window is closed, the buffered data is sent to downstream processing, and a new buffer window is opened after waiting for the next data to arrive.
- 6. The method for collecting the Modbus protocol data with different frequencies and multiple devices according to claim 1, wherein when the batch read requests are generated by merging, the batch read requests are asynchronously executed through corresponding Modbus TCP connections, and asynchronous non-blocking processing of the requests is realized based on expansion TCPMASTER, so that the batch read requests are obtained.
- 7. The method for collecting Modbus protocol data with different frequencies according to claim 1, wherein the asynchronous issuing of the independent response data blocks comprises: based on the Project Reactor responsive programming framework, batchRead batch acquisition methods are changed into responsive Flux stream processing, so that the results can be processed immediately downstream after each batch request is processed, and the processing is not required to be performed after all requests are processed, thereby improving the real-time performance of data acquisition.
- 8. A multi-device abnormal frequency Modbus protocol data collection system, which adopts the multi-device abnormal frequency Modbus protocol data collection method as set forth in any one of claims 1 to 7, comprising: The device grouping module is used for receiving the attribute acquisition frequency and the address of the Modbus slave station device, grouping the Modbus slave station device based on the attribute acquisition frequency and the address of the Modbus slave station device, and starting a timing task for each acquisition frequency; The request buffer module is used for generating globally unique Modbus Tcp connection and a data source based on the address of the Modbus slave station equipment, and generating a data stream processing pipeline based on a pre-constructed responsive programming framework; And the asynchronous issuing module is used for splitting response data returned based on the execution of the batch reading request in the data stream processing pipeline to obtain independent response data blocks, and asynchronously issuing the independent response data blocks, so that the processing performance of data acquisition is improved.
- 9. A terminal device comprising a memory, a processor and a computer program stored in the memory and capable of running on the processor, wherein the memory stores the computer program capable of running on the processor, and the processor uses a multi-device abnormal frequency Modbus protocol data collection method according to any one of claims 1 to 7 when loading and executing the computer program.
- 10. A computer readable storage medium having a computer program stored therein, wherein the computer program, when loaded and executed by a processor, employs a multi-device abnormal frequency Modbus protocol data collection method according to any one of claims 1 to 7.
Description
Modbus protocol data acquisition method and system for different frequencies of multiple devices Technical Field The invention relates to the technical field of Modbus protocol equipment data acquisition, in particular to a method and a system for acquiring Modbus protocol data of different frequencies of multiple equipment. Background The Modbus protocol is widely applied to data transmission in the field of industrial automation, supports a plurality of communication modes of Modbus RTU, modbus ASCII and Modbus TCP, and can meet the data transmission requirements in different industrial scenes. The industrial field multi-device networking is carried out through the Modbus protocol, the protocol is simple and easy to realize, has strong compatibility, is limited by serial bus characteristics, has the problems of limited transmission rate, easy interference of long-distance transmission, polling delay under a multi-slave station scene and the like, and is mainly suitable for industrial data acquisition scenes with low requirements on real-time performance. The real-time acquisition of multi-equipment different-frequency data is a core link of industrial production monitoring, and various types of equipment often exist on a production line, wherein the equipment has different working frequencies and data transmission rates, and has high real-time requirements, so that higher requirements are put forward on a data acquisition system. In order to solve the problem of overhigh multi-equipment abnormal frequency data acquisition delay, the common solution optimizes Modbus serial data acquisition efficiency by 4 aspects including 1) improving hardware and communication parameters, selecting high baud rate (more than 38400bps, shortening wiring distance, using RS-485 differential transmission to resist interference, 2) optimizing a communication mechanism, adopting a batch read-write register and reasonable partition polling to reduce invalid instructions and frame redundancy, 3) enhancing slave station response, simplifying slave station processing logic, reserving enough response time to avoid frequent heavy transmission, 4) introducing technical upgrading, replacing ASCII mode by RTU mode or adopting gateway to convert into Modbus TCP, combining measures such as verification optimization, interference shielding and the like, and comprehensively reducing transmission delay and data loss rate. However, in the process of monitoring data collection in a production line, for example, the electromagnetic flowmeter needs to collect parameters such as instantaneous flow, cumulative amount and the like at a high frequency, other auxiliary equipment may use a lower collection frequency, and the complexity of data collection at such different frequencies makes it difficult for a traditional data collection system to meet actual requirements, and in particular, many challenges still face in terms of data synchronization, compatibility and transmission efficiency. Disclosure of Invention In order to solve the defects in the background art, the invention aims to provide a Modbus protocol data acquisition method and system with multiple devices and different frequencies, which can improve the data acquisition efficiency. In a first aspect, the present invention provides a method for collecting Modbus protocol data of different frequencies by multiple devices, comprising the following steps: Receiving attribute acquisition frequency and address of Modbus slave station equipment, grouping the Modbus slave station equipment based on the attribute acquisition frequency and address of the Modbus slave station equipment, and starting a timing task for each acquisition frequency; Generating a globally unique Modbus Tcp connection and a data source based on the address of Modbus slave station equipment, and generating a data stream processing pipeline based on a pre-constructed responsive programming framework; And splitting response data returned based on executing the batch reading request in a data stream processing pipeline to obtain independent response data blocks, and asynchronously issuing the independent response data blocks, so that the processing performance of data acquisition is improved. With reference to the first aspect, in certain implementation manners of the first aspect, the method further includes a process of grouping Modbus slave devices based on the attribute acquisition frequency and the address of the Modbus slave devices, including: According to the attribute acquisition frequency grouping of Modbus slave station equipment, each group starts a timing acquisition task so as to reduce the creation of the timing task; Grouping according to addresses of Modbus slave station equipment, wherein each Modbus slave station equipment uses independent threads during acquisition, and acquisition requests of different Modbus slave station equipment are prevented from being blocked. With reference to the first aspect, in