Modbus instrument data acquisition method and system

By creating a time domain and setting the system clock frequency, combined with function blocks and dedicated data blocks, the wiring and parameter error problems in ModBus instrument data acquisition were solved, achieving fast and stable data acquisition and error logging, and adapting to ModBus instruments from different manufacturers.

CN114911793BActive Publication Date: 2025-12-26WUHAN TIANYUAN GROUP CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202210430912.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-04-22
Publication Date
2025-12-26
Estimated Expiration
2042-04-22

AI Technical Summary

Technical Problem

In water treatment, wastewater treatment, power plant, and chemical plant projects, ModBus instrument data acquisition suffers from wiring errors, parameter setting errors, and software configuration errors, leading to unsuccessful data acquisition and difficulty in troubleshooting. Furthermore, the differences in ModBus data register addresses between instruments from different manufacturers require the writing of multiple instructions, resulting in excessively long debugging times.

Method used

A time domain is created using a pulse generator and accumulator. The system clock frequency is set to control the number of pulses generated by the pulse generator. Parameter settings and association settings for ModBus instruments are performed. Function blocks are used to read data from ModBus instruments from different manufacturers, and the data is stored through dedicated data blocks to achieve rapid acquisition and error logging.

Benefits of technology

It simplifies the data acquisition process of ModBus instruments, reduces repetitive software development work, shortens debugging time, improves acquisition stability and data storage clarity, can quickly locate communication errors, and is compatible with instruments from different manufacturers.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114911793B_ABST
    Figure CN114911793B_ABST
Patent Text Reader

Abstract

A kind of ModBus instrument data acquisition method and system, method includes: step 1, by pulse generator and accumulator, create time domain;Step 2, by function block, the parameter setting of ModBus instrument is carried out, and the association setting of time domain and ModBus instrument is carried out, based on the association setting, the acquisition of ModBus instrument data is carried out.The present application can quickly add multiple individual with ModBus communication instrument, and define the station address of instrument, can quickly according to the difference of different instrument ModBus data register address, directly to different instrument set different reading address, can be adjusted according to the data refresh rate requirement, collection speed, using time axis and time pointer mode to different station address instrument polling, will not because a instrument failure and influence the acquisition of other instruments.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of automatic control system, and in particular to a ModBus instrument data acquisition method and system. BACKGROUND

[0002] At present, large-scale water treatment, sewage treatment, power plant and chemical plant projects generally include: A. multifunctional power meter, B. measuring instrument (flow meter, dissolved oxygen meter, liquid level meter, MLSS meter), C. alarm instrument (smoke alarm, multifunctional toxic gas alarm, oxygen deficiency alarm), D. control instrument (PLC of other manufacturers, liquid level controller, intelligent temperature and humidity controller), ModBus data acquisition has no perfect alarm feedback mechanism, and often because of wiring errors in the debugging process; different instrument parameter setting errors; instrument failure and software system configuration errors, resulting in unsuccessful data acquisition and difficulty in finding faults, and when collecting data through ModBus for different types of instruments of different manufacturers in the on-site debugging process, multiple instructions need to be written to read the data of different manufacturers or different types of instruments due to the differences in ModBus data register addresses of various manufacturers, which will result in spending a lot of time in ModBus data acquisition link during the debugging of each project. SUMMARY

[0003] In view of the technical defects and technical disadvantages in the prior art, the embodiments of the present application provide a ModBus instrument data acquisition method which overcomes the above problems or at least partially solves the above problems, and the specific scheme is as follows:

[0004] As a first aspect of the present application, a ModBus instrument data acquisition method is provided, and the method comprises:

[0005] Step 1, creating a time domain through a pulse generator and an accumulator;

[0006] Step 2, setting parameters of the ModBus instrument through a function block, and setting association between the time domain and the ModBus instrument, and based on the association setting, collecting ModBus instrument data.

[0007] Further, step 1 further comprises setting a data refresh rate by setting a system clock frequency, i.e. setting a cycle period of collecting ModBus instrument data in one round.

[0008] Further, the setting of the data refresh rate by setting the system clock frequency comprises:

[0009] By setting the internal clock frequency of the system, the pulse generator generates a pulse every second, and the accumulator accumulates once every time a pulse is generated;

[0010] Let the system internal clock frequency be A Hz, then the control pulse generator generates A pulses per second, let the time domain "Master".Step be 0-n, n is 255 by default, then the data refresh rate is n / A.

[0011] Further, in step 2, the parameter setting of the ModBus instrument is performed by the function block, the association setting of the time domain and the ModBus instrument is performed, and based on the association setting, the collection of the ModBus instrument data is performed, and the collection of the ModBus instrument data specifically includes:

[0012] Step 2.1, setting the holding register address of the ModBus instrument, setting the station address of each ModBus instrument, setting the starting address of the data of each ModBus instrument in the holding register address and the corresponding data length;

[0013] Step 2.2, when the time domain Master”.Step is i, reading the instrument i of the station address MB_ADDR=i, i.e. the instrument i, from the starting address of the data of the instrument i in the holding register address and the corresponding data length, reading the data of the instrument i;

[0014] Step 2.3, reading the data of each ModBus instrument in turn according to step 2.2, and sequentially writing into the corresponding storage unit of the host computer through the pointer.

[0015] Further, the method further includes:

[0016] After reading each station address, the data of the corresponding station address has been successfully read by setting Master_Step1_DONE=1;

[0017] When reading the station address repeatedly, set Master_Step1_BUSY=1 to indicate that the 485 communication port is occupied, prompting to check the station address setting of the ModBus instrument so that the station address is not repeated;

[0018] When the station address data reading fails, set Master_Step1_ERROR=1 to record error information, and find the error reason by checking the pre-set error list.

[0019] Further, the method further includes:

[0020] Defining a ModBus special data block Master DB31 in the host computer, and defining the data type as an array, each array is used to store the data of a ModBus instrument, and the length of each array is set based on the data of the ModBus instrument; in step 2.2, after reading the data of the instrument i, the pointer points to the starting position of the array corresponding to the instrument i, and the data is sequentially written into the data space of the corresponding array.

[0021] As a second aspect of the present application, a ModBus instrument data acquisition system is provided, comprising a time domain creation module and a data acquisition module;

[0022] The time domain creation module is configured to create a time domain by means of a pulse generator and an accumulator;

[0023] The data acquisition module is configured to set parameters of ModBus instruments by means of a function block, set association between the time domain and the ModBus instruments, and acquire data of the ModBus instruments based on the association.

[0024] Further, the time domain creation module is specifically configured to:

[0025] The system internal clock frequency is set to control the pulse generator to generate A pulses per second, and the accumulator is incremented once per pulse;

[0026] The system internal clock frequency is set to A Hz, the pulse generator is controlled to generate A pulses per second, and the time domain “Master”.Step is set to 0-n, n is set to 255 by default, and the data refresh rate is n / A.

[0027] Further, the data acquisition module is specifically configured to:

[0028] The holding register address of the ModBus instrument is set, the station address of each ModBus instrument is set, and the starting address of data of each ModBus instrument in the holding register address and the corresponding data length are set;

[0029] When the time domain “Master”.Step is i, the instrument i with the station address MB_ADDR=i is read, the starting address of data of the instrument i in the holding register address and the corresponding data length are read, and the data of the instrument i is read;

[0030] The data of each ModBus instrument is sequentially read and sequentially written into the corresponding storage unit of the host computer by means of a pointer.

[0031] Further, the data acquisition module is further configured to define a ModBus special data block Master DB31 in the host computer, define the data type as an array, use each array to store data of one ModBus instrument, set the length of each array based on the data of the ModBus instrument, point to the starting position of the array corresponding to the instrument i after the data of the instrument i is read, and sequentially write the data into the data space of the corresponding array.

[0032] The present application has the following beneficial effects:

[0033] 1. Can be dragged between different projects, greatly reducing the software development of ModBus instrument collection repeat work.

[0034] 2. Simple parameter modification, that is, to collect data of ModBus instruments of any manufacturer, any type and different register addresses, greatly shortening the time spent in collecting ModBus instruments in the field debugging stage.

[0035] 3. Polling mode, instrument data is read in turn, which can quickly locate ModBus communication errors in the debugging stage, and can improve the stability of ModBus collection in the formal operation stage, avoiding the influence of communication errors of some instruments on the data collection of other instruments.

[0036] 3. Special data block, special for storing ModBus instrument data, array structured data block, cooperating with the pointer in the function block to point to the storage area, which can quickly add instrument data and make the data of each instrument clear at a glance.

[0037] 4. The benefits brought by the present application are summarized as follows: shortening the development time, reducing the debugging difficulty, enhancing the running stability, and making the structure clear. BRIEF DESCRIPTION OF DRAWINGS

[0038] Figure 1 A ModBus instrument data collection method flow chart is provided for the embodiment of the present application.

[0039] Figure 2 A program code schematic diagram for creating a time domain is provided for the embodiment of the present application.

[0040] Figure 3 A system internal clock memory schematic diagram is provided for the embodiment of the present application.

[0041] Figure 4 A program code schematic diagram for reading and writing ModBus instruments through a function block is provided for the embodiment of the present application.

[0042] Figure 5 An error list schematic diagram is provided for the embodiment of the present application.

[0043] Figure 6 An array schematic diagram of a special data block Master DB31 is provided for the embodiment of the present application. DETAILED DESCRIPTION

[0044] With reference to the drawings and the embodiments of the present application, the technical solutions in the embodiments of the present application will be clearly and completely described. Obviously, the described embodiments are only a part of, but not all of the embodiments of the present application. Based on the embodiments of the present application, all other embodiments obtained by those of ordinary skill in the art without creative work fall within the scope of the present application.

[0045] As Figure 1 described, as the first embodiment of the present application, a ModBus instrument data acquisition method is provided, the method comprising:

[0046] Step 1, creating a time domain through a pulse generator and an accumulator;

[0047] Step 2, setting parameters of the ModBus instrument through a function block, and setting association of the time domain and the ModBus instrument, and based on the association setting, acquiring ModBus instrument data.

[0048] In the step 1, further comprising setting a data refresh rate by setting a system clock frequency, that is, setting a cycle period of acquiring a round of ModBus instrument data, specifically:

[0049] By setting the system internal clock frequency, the pulse generator generates a pulse every second, and the accumulator accumulates once every time a pulse is generated;

[0050] Let the system internal clock frequency be AHz, then control the pulse generator to generate A pulses every second, and let the time domain "Master".Step be 0-n, n is 255 by default, then the data refresh rate is n / A

[0051] The program for creating the time domain is shown as Figure 2 shown, the system internal clock %M0.5 is a second pulse, cooperating with the accumulator ADD, the time domain "Master".Step is an integer point of 0-255 (the maximum is 255, which can be freely modified), which has covered the maximum number of ModBus communication sites. When "Master".Step exceeds 255 (the maximum is 255, which can be freely modified), it will be reset to 0;

[0052] As Figure 3 shown, when the pulse is controlled by %M0.5, the accumulator accumulates once every second, and "Master".Step is accumulated from 0 to 255 in 255 seconds, that is, the cycle period of the polling mechanism is 255 seconds.

[0053] When the control pulse is in %M0.0, 10 pulses are generated per second, and the accumulator is added ten times per second. The time for "Master".Step to accumulate from 0 to 255 is 25.5 seconds, that is, the cycle period of the polling mechanism is 25.5 seconds.

[0054] In step 2, the parameter setting of the ModBus instrument is performed through the function block, the association setting of the time domain and the ModBus instrument is performed, and based on the association setting, the collection of the ModBus instrument data is performed, and the collection of the ModBus instrument data specifically includes:

[0055] In step 2.1, the holding register address of the ModBus instrument is set, the station address of each ModBus instrument is set, the starting address of the data of each ModBus instrument in the holding register address and the corresponding data length are set;

[0056] In step 2.2, when the time domain "Master".Step is i, the instrument with the station address MB_ADDR=i, that is, instrument i, is read, and the data of instrument i is read from the starting address of the data of instrument i in the holding register address and the corresponding data length;

[0057] In step 2.3, the data of each ModBus instrument is sequentially read according to step 2.2, and is sequentially written into the corresponding storage unit of the upper computer through the pointer.

[0058] The program setting is as shown in Figure 4 .

[0059] For example, when the time domain "Master".Step is 1, the instrument with the station address MB_ADDR=1 is read, the holding register address of the instrument is 40000, the data address to be read is 1001 words after the holding register area, and the length is 2 words, so the read address DATA_ADDR=41001, the data length DATA_LEN=2, and the read data is sequentially written into DB31.DBW2 and DB31.DBW4 through the pointer P#DB31.DBX2.0 as the starting address.

[0060] When the time domain "Master".Step is 2, the instrument with the station address MB_ADDR=2 is read, the holding register address of the instrument is 40000, the data address to be read is 1 word after the holding register area, and the length is 6 words, so the read address DATA_ADDR=40001, the data length DATA_LEN=6, and the read data is sequentially written into DB31.DBW6, DB31.DBW8, DB31.DBW10, DB31.DBW12, DB31.DBW14, DB31.DBW16 through the pointer P#DB31.DBX10.0 as the starting address.

[0061] Through the function block, parameter setting is quickly made, data collection and storage of different register addresses of different manufacturers are quickly completed, and program segment copying and pasting is only required to modify time domain "Master".Step; station address MB_ADDR; reading address DATA_ADDR; data length DATA_LEN; and data storage address P#DB31.DBX. ModBus instruments can be quickly added.

[0062] Through integer points 1, 2, 255 in the time axis Master".Step, only the specified station address instrument is sent with an instruction each time, and even if reading is wrong, the reading of other instruments will not be affected.

[0063] Preferably, the method further comprises storing error information, specifically comprising:

[0064] 1. After each station reading is completed, Master_Step1_DONE = 1, indicating that the data of the station has been successfully read and recorded.

[0065] 2. When there is a repeated station address, Master_Step1_BUSY = 1, indicating that the 485 communication port is occupied, and the instrument station address setting needs to be checked, so that the station address is not repeated.

[0066] 3. When the station data reading fails, Master_Step1_ERROR = 1. At this time, Master_Step1_STATUS will record error information, and by checking the error list, the error reason can be quickly found. The error list is as shown in Figure 5 .

[0067] Error information will only be recorded and will not control the termination of the program. The entire polling process is an open-loop control process, and neither the feedback completion information nor the error information will affect the polling.

[0068] When the instrument data is too much, entering one data at a time will waste a lot of time. Therefore, the application defines a ModBus special data block Master DB31, defines the data type as an array, and each array is used to store the data of an instrument. The length of the array is the data length of the current instrument, such as Figure 6 shown. The Read_DATA1 array stores the data of No. 1 instrument, and the Read_DATA2 array stores the data of No. 2 instrument.

[0069] For example, the meter with station address MB_ADDR=1, data length is 2 word length, its data storage area is array Read_DATA1, its array element contains 0-1 two, which contains Read_DATA1[0], Read_DATA1[1] two words, the starting address pointed by the pointer is P#DB31.DBX2.0, that is, 2 word length is written from DB31.DBW2 to Read_DATA1[0]DB31.DBW2 and Read_DATA1[1]DB31.DBW4 respectively.

[0070] The meter with station address MB_ADDR=2, data length is 6 word length, its data storage area is array Read_DATA2, its array element contains 0-5 six, which contains Read_DATA2[0] Read_DATA2[1], Read_DATA2[2], Read_DATA2[3], Read_DATA2[4], Read_DATA2[5] six words, the starting address pointed by the pointer is P#DB31.DBX6.0, that is, 6 word length is written from DB31.DBW6 to Read_DATA2[0] Read_DATA2[1]Read_DATA2[2] Read_DATA2[3]Read_DATA2[4] Read_DATA2[5] respectively.

[0071] As a second embodiment of the present application, a ModBus meter data acquisition system is also provided, the system comprises: a time domain creation module and a data acquisition module;

[0072] The time domain creation module is used to create a time domain through a pulse generator and an accumulator;

[0073] The data acquisition module is used to set parameters of the ModBus meter through a function block, and set association between the time domain and the ModBus meter, and based on the association setting, acquire data of the ModBus meter.

[0074] The above only describes the preferred embodiments of the present application, and is not used to limit the present application, any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application should be included in the protection scope of the present application.

Claims

1. A method for collecting ModBus instrument data, characterized in that, The method comprises: Step 1, creating a time domain "Master.Step" with a step value cyclically changing from 0 to n through a pulse generator and an accumulator; Step 2, performing parameter setting of the ModBus instrument through a function block, the parameter setting comprising: setting a station address MB_ADDR of each ModBus instrument, and establishing an association between the time domain step value "Master.Step" and the station address MB_ADDR, so that when "Master.Step" is equal to i, a reading operation on the instrument with the station address i is automatically triggered; setting a start address DATA_ADDR and a data length DATA_LEN of data of each ModBus instrument in a holding register; Step 3, collecting data of the ModBus instrument based on the association established in Step 2: when the time domain "Master.Step" is i, reading data with a length of DATA_LEN starting from the start address DATA_ADDR of the instrument with the station address MB_ADDR i; and sequentially writing the read data into an array storage space allocated for the instrument with the station address in a special data block Master DB31 predefined in the upper computer through a pointer; Step 4, setting independent status indication bits for each station address reading operation, including a Master_Stepi_DONE bit for indicating successful data reading, a Master_Stepi_BUSY bit for indicating a station address conflict, and a Master_Stepi_ERROR bit for indicating a reading failure; wherein the status indication bits are only used for recording the reading status of the corresponding station address, and do not interrupt the step cycle and the polling collection process of the entire time domain.

2. A system for collecting ModBus meter data for implementing the method according to claim 1, characterized in that, The system comprises a time domain creation module and a data collection module; The time domain creation module is configured to create a time domain "Master.Step" with a step value cyclically changing from 0 to n through a pulse generator and an accumulator; The data collection module is configured to: perform parameter setting of the ModBus instrument through a function block, the parameter setting comprising: setting a station address MB_ADDR of each ModBus instrument, and establishing an association between the time domain step value "Master.Step" and the station address MB_ADDR, so that when "Master.Step" is equal to i, a reading operation on the instrument with the station address i is automatically triggered; setting a start address DATA_ADDR and a data length DATA_LEN of data of each ModBus instrument in a holding register; collect data of the ModBus instrument based on the established association: when the time domain "Master.Step" is i, read data with a length of DATA_LEN starting from the start address DATA_ADDR of the instrument with the station address MB_ADDR i; and sequentially write the read data into an array storage space allocated for the instrument with the station address in a special data block Master DB31 predefined in the upper computer through a pointer; The independent status indication bits are set for each station address reading operation, including Master_Stepi_DONE bit for indicating successful data reading, Master_Stepi_BUSY bit for indicating station address conflict, and Master_Stepi_ERROR bit for indicating reading failure; wherein the status indication bits are only used for recording reading status of the corresponding station address, without interrupting the entire time domain step-by-step cycle and polling collection process.