CN112615771A - Data acquisition method and system of rain gauge based on Modbus communication - Google Patents
Data acquisition method and system of rain gauge based on Modbus communication Download PDFInfo
- Publication number
- CN112615771A CN112615771A CN202011519035.8A CN202011519035A CN112615771A CN 112615771 A CN112615771 A CN 112615771A CN 202011519035 A CN202011519035 A CN 202011519035A CN 112615771 A CN112615771 A CN 112615771A
- Authority
- CN
- China
- Prior art keywords
- modbus
- rain gauge
- parameter
- interface
- equipment
- Prior art date
- Legal status (The legal status 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 status listed.)
- Pending
Links
Images
Classifications
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L12/00—Data switching networks
- H04L12/28—Data switching networks characterised by path configuration, e.g. LAN [Local Area Networks] or WAN [Wide Area Networks]
- H04L12/40—Bus networks
- H04L12/40006—Architecture of a communication node
-
- G—PHYSICS
- G01—MEASURING; TESTING
- G01D—MEASURING NOT SPECIALLY ADAPTED FOR A SPECIFIC VARIABLE; ARRANGEMENTS FOR MEASURING TWO OR MORE VARIABLES NOT COVERED IN A SINGLE OTHER SUBCLASS; TARIFF METERING APPARATUS; MEASURING OR TESTING NOT OTHERWISE PROVIDED FOR
- G01D21/00—Measuring or testing not otherwise provided for
- G01D21/02—Measuring two or more variables by means not covered by a single other subclass
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F13/00—Interconnection of, or transfer of information or other signals between, memories, input/output devices or central processing units
- G06F13/38—Information transfer, e.g. on bus
- G06F13/382—Information transfer, e.g. on bus using universal interface adapter
-
- G—PHYSICS
- G16—INFORMATION AND COMMUNICATION TECHNOLOGY [ICT] SPECIALLY ADAPTED FOR SPECIFIC APPLICATION FIELDS
- G16Y—INFORMATION AND COMMUNICATION TECHNOLOGY SPECIALLY ADAPTED FOR THE INTERNET OF THINGS [IoT]
- G16Y20/00—Information sensed or collected by the things
- G16Y20/10—Information sensed or collected by the things relating to the environment, e.g. temperature; relating to location
-
- G—PHYSICS
- G16—INFORMATION AND COMMUNICATION TECHNOLOGY [ICT] SPECIALLY ADAPTED FOR SPECIFIC APPLICATION FIELDS
- G16Y—INFORMATION AND COMMUNICATION TECHNOLOGY SPECIALLY ADAPTED FOR THE INTERNET OF THINGS [IoT]
- G16Y30/00—IoT infrastructure
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L41/00—Arrangements for maintenance, administration or management of data switching networks, e.g. of packet switching networks
- H04L41/08—Configuration management of networks or network elements
- H04L41/0803—Configuration setting
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L67/00—Network arrangements or protocols for supporting network services or applications
- H04L67/01—Protocols
- H04L67/12—Protocols specially adapted for proprietary or special-purpose networking environments, e.g. medical networks, sensor networks, networks in vehicles or remote metering networks
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L12/00—Data switching networks
- H04L12/28—Data switching networks characterised by path configuration, e.g. LAN [Local Area Networks] or WAN [Wide Area Networks]
- H04L12/40—Bus networks
- H04L2012/40208—Bus networks characterized by the use of a particular bus standard
- H04L2012/40228—Modbus
Landscapes
- Engineering & Computer Science (AREA)
- Computing Systems (AREA)
- Signal Processing (AREA)
- Computer Networks & Wireless Communication (AREA)
- General Health & Medical Sciences (AREA)
- Physics & Mathematics (AREA)
- General Physics & Mathematics (AREA)
- Health & Medical Sciences (AREA)
- Theoretical Computer Science (AREA)
- Toxicology (AREA)
- Environmental & Geological Engineering (AREA)
- General Engineering & Computer Science (AREA)
- Medical Informatics (AREA)
- Arrangements For Transmission Of Measured Signals (AREA)
Abstract
The invention discloses a data acquisition method and a data acquisition system of a rain gauge based on Modbus communication, belonging to the technical field of computer communication, aiming at solving the technical problem of how to realize the data reading and acquisition of sensing equipment and finish the integrated sensing detection of rainfall, river flow rate, water level, water depth and the like, and adopting the technical scheme that: the method includes the steps that under the Linux environment, a LibModbus driving library is installed, an industrial personal computer is inserted into a USB (universal serial bus) to 485 module, Modbus A and Modbus B interfaces of a tipping bucket type rain gauge and a radar flowmeter are correctly connected with a serial port to 485 module, a compiled bottom application program calls an interface Modbus _ connect (), connection of the tipping bucket type rain gauge and the radar flowmeter with the industrial personal computer is established, control and parameter acquisition of the tipping bucket type rain gauge and the radar flowmeter are achieved through reading and writing of corresponding function codes of the tipping bucket type rain gauge and the radar flowmeter, and hydrological monitoring through the tipping bucket type rain gauge and the radar flowmeter is further achieved. The system comprises a setting unit, a first acquisition unit, a second acquisition unit and a release unit.
Description
Technical Field
The invention relates to the technical field of computer communication, in particular to a data acquisition method and a data acquisition system of a rain gauge based on Modbus communication.
Background
The ModBus network is an industrial communication system, which is formed by connecting a programmable controller with an intelligent terminal and a computer through a public line or a local private line.
Hydrologic monitoring plays an important role in flood control and drought resistance, river and lake treatment, hydraulic safety and the like all the time, but the integration degree of the current hydrologic station is weak, the traditional integrated detection equipment can only be limited to a certain service scene, the data is not uniform, and the phenomena of data barrier and island are easily caused. How to realize perception equipment data reading and collection, accomplish the perception detection of rainfall, river course velocity of flow, water level, depth of water etc. integration is the problem that awaits the solution at present.
Disclosure of Invention
The technical task of the invention is to provide a data acquisition method and a data acquisition system of a rain gauge based on Modbus communication, so as to solve the problem of how to realize the data reading and acquisition of sensing equipment and finish the integrated sensing detection of rainfall, river flow rate, water level, water depth and the like.
The technical task of the invention is realized according to the following mode, the method for acquiring the data of the rain gauge based on Modbus communication is characterized in that a LibModbus driving library is installed in a Linux environment, an industrial personal computer is inserted into a USB (universal serial bus) to 485 module, Modbus A and Modbus B interfaces of a tipping bucket rain gauge and a radar flowmeter are correctly connected with a serial port to 485 module, a written bottom application program calls an interface Modbus _ connect (), the connection between the tipping bucket rain gauge and the radar flowmeter is established, the control and parameter acquisition of the tipping bucket rain gauge and the radar flowmeter are realized by reading and writing corresponding function codes of the tipping bucket rain gauge and the radar flowmeter, and further hydrological monitoring is realized through the tipping bucket rain gauge and the radar flowmeter; the hydrologic monitoring content comprises parameters of rainfall, water level, flow rate and water quality monitoring.
Preferably, the method is specifically as follows:
setting Modbus serial port parameters;
acquiring the information of the tipping bucket type rain gauge device;
acquiring radar flowmeter information;
and releasing the allocated resources, and further realizing data acquisition and equipment control on the Internet of things sensing equipment through an application program.
Preferably, the Modbus serial port parameter setting is as follows:
initializing a Modbus environment pointer by using an interface Modbus _ new _ rtu;
setting a slave station ID by using an interface modbus _ set _ slave, wherein a parameter 1 is an environment pointer initialized by modbus _ new _ rtu; the parameter 2 is the tipping bucket type rain gauge equipment address provided by a manufacturer;
and establishing connection between the industrial personal computer and the tipping bucket rain gauge and the radar end by using the interface modbus _ connect, and starting serial port communication.
Preferably, the obtaining of the information of the tipping-bucket rain gauge device is as follows:
by checking a dump-bucket rain gauge user manual provided by a manufacturer, register address values of 0x0000H, 0x07D0 and 0x07D1 are a rain value, an equipment address and an equipment baud rate respectively;
in the equipment starting-up stage, acquiring the information of the tipping bucket rain gauge equipment, and respectively reading the values of registers with the addresses of 0x0000H, 0x07D0 and 0x07D1 by using an interface modbus _ read _ registers (), so as to acquire corresponding equipment information;
because the read rainfall value is 10 times of the actual value, the processing of dividing by 10 times is also needed;
if the user wants to clear the current rainfall value, the user operates according to the prompt command, the bottom layer code calls an interface modbus _ write _ register, and a specified clearing command 0x5A is written into the rainfall value address 0x0000H, so that the rainfall value data clearing can be realized.
Preferably, the radar flow meter information is acquired as follows:
reading the rainfall value by using an interface modbus _ read _ registers (), and performing multiple processing operation;
unlike interface getRainDeviceInfo (), the radar interface is placed in the main loop, performing long traversal operations.
Preferably, the releasing the allocated resources specifically includes: and the Modbus environment pointer of the Modbus _ new _ rtu initialization is utilized to close and recover resources, so that resource waste is avoided.
A data acquisition system of a rain gauge for Modbus communication comprises,
the setting unit is used for setting Modbus serial port parameters;
the acquiring unit I is used for acquiring the information of the tipping bucket type rain gauge device;
the acquisition unit II is used for acquiring information of the radar flowmeter;
and the release unit is used for releasing the allocated resources so as to realize data acquisition and equipment control on the Internet of things sensing equipment through an application program.
Preferably, the setting unit includes, in a case,
the configuration module is used for configuring relevant parameters of a Modbus-RTU (485) protocol;
the connection module is used for connecting the industrial personal computer with the Internet of things sensing equipment; the sensing equipment of the Internet of things comprises a tipping bucket type rain gauge and a radar.
Preferably, the working process of the configuration module is as follows:
(1) and line connection: correctly connecting Modbus A and Modbus B interfaces of the Internet of things sensing equipment with a serial port 485 conversion module (A is connected with A, B is connected with B);
(2) downloading the latest LibModbus library in a Linux environment, entering a download directory, and decompressing and installing;
(3) running make and make install to generate folders of include and lib for calling by a main program; after a new static library is generated, the dynamic reference library needs to be reconfigured, specifically as follows: so. conf, open file ld, add "include/usr/local/lib" using a generation editing tool; saving and exiting, inputting Ldconfig in the command line, and re-reading the cache, namely correctly calling the new dynamic library file;
(4) and aiming at the equipment interface condition, establishing a modbus RTU environment: a modbus _ new _ RTU () interface in a LibModbus standard library function is utilized to generate and initialize a modbus structure body to carry out communication in a serial line by using an RTU mode; wherein, the parameter 1 is the name of a serial port processed by a designated OS, such as/dev/ttyS 0 (serial port 0) or/dev/ttyS USB0(USB to serial port 0) under the linux system; parameter 2 is the serial port baud rate, parameter 3 is the parity check bit, parameter 4 is the serial port data digit, and parameter 5 is the stop bit digit;
firstly, if the building is successful, the modbus _ new _ rtu () function returns a pointer pointing to the modbus _ t structure;
if the establishment fails, returning an error code;
(5) and setting a serial port mode: because the current internet-of-things sensing devices are all 485 communication protocols, a serial port mode is set by utilizing a modbus _ rtu _ set _ serial _ mode () interface in a LibModbus standard library function, and a parameter 1 is a serial port mode variable;
(6) and setting a slave station ID: each device has a unique address code, so to control a designated device, the ID of the expected operating device needs to be set, slave station ID setting can be realized by utilizing a modbus _ set _ slave () interface, a parameter 1 is a returned modbus _ t structure pointer, and a parameter 2 is a slave station ID value; the method comprises the following specific steps:
each device has a unique address code, so to control the designated device, the ID of the expected operating device needs to be set, and the slave station ID setting can be realized by utilizing a modbus _ set _ slave () interface; parameter 1 is the returned modbus _ t structure pointer; the parameter 2 is the slave ID value. The rain gauge and the radar flow gauge can be connected on the same line, the premise is that which equipment is connected is defined through a modbus _ set _ slave () interface (the rain gauge address is 0, the radar flow gauge is 1, and the equipment is required to have different equipment address codes), and after a program normally runs, the equipment can be enabled alternately to obtain equipment data circularly only through the interface modbus _ set _ slave ().
Preferably, the working process of the connection module is as follows:
(1) and establishing connection: completing the setting of serial port parameters, Modbus equipment pointers and Modbus equipment slave addresses, establishing connection by using an interface Modbus _ connect (), successfully returning 0 by using the returned Modbus _ t structure pointer as the parameter 1, and returning error codes-1 by mistake;
(2) reading a holding register: when a user needs to read the holding register of the Internet of things sensing equipment, the parameter value of the holding register can be obtained by using an interface modbus _ read _ registers (); wherein, the parameter 1 is a returned modbus _ t structure pointer; parameter 2 is the holding register address value to be read; the parameter 3 is the number of registers to be read; the parameter 4 is the storage location of the read result, and it is noted that the user needs to allocate enough memory to store the result in the storage location of the parameter 4; for example, to read the current rainfall value, look up the equipment manual, the rainfall value register address is 0x1, so it is only necessary to read the register by using the interface;
(3) writing data: when a user needs to write a designated register, if the current internet of things sensing equipment of the internet of things sensing equipment needs to be cleared, an interface modbus _ write _ registers () needs to be called, and a parameter 2 value is written into the address of the parameter 1 register;
(4) when the application program is ended, the created resources need to be recycled, the connection is closed by using an interface modbus _ close (), and then libmodbus environment release is carried out by using modbus _ free ().
The data acquisition method and the data acquisition system of the rain gauge based on Modbus communication have the following advantages that: according to the invention, through a Modbus communication protocol, the data (parameters such as water level, rainfall, flow rate and water quality monitoring) of the Internet of things sensing equipment are read, the integrated sensing detection of rainfall, river flow rate, water level, water depth and the like is completed, and the data reading and acquisition of the sensing equipment are realized by adopting a mode of directly calling a LibModbus library.
Drawings
The invention is further described below with reference to the accompanying drawings.
FIG. 1 is a flow chart of a data acquisition method of a rain gauge based on Modbus communication;
fig. 2 is a flow chart of a working process of a data acquisition system of a rain gauge based on Modbus communication.
Detailed Description
The data acquisition method and the data acquisition system of the rainfall meter based on Modbus communication are described in detail below with reference to the attached drawings and specific embodiments of the specification.
Example 1:
the invention adopts a tipping bucket type rainfall meter of RS-YL-N01-4 of Shandong Kenrecod measurement and control technology Limited company and an HC.FLM-1 radar flowmeter of Haichuan information technology Limited company to carry out hydrological monitoring, such as parameter rainfall, water level, flow rate, water quality monitoring and the like, and an industrial personal computer adopts an industrial gateway of the Shanhua company and operates a Linux system. A tipping bucket type rain gauge and a radar flow meter both adopt a Modbus-RTU (485) communication protocol mode, in order to read the value of a sensing device, firstly, a drive of a 485 converter, such as a USB-SERIAL340 drive, is installed on Windows, an independent USB-to-485 module is needed because a common PC does not have a 485 interface, the 485-A and 485-B interfaces of the sensing device are correctly connected with the module, at the moment, upper computer software provided by a manufacturer is opened, corresponding SERIAL port parameters, such as baud rate, data bit, parity check and stop bit, are set, and corresponding register addresses are provided according to a given specification, so that expected parameter values can be successfully read. However, when the industrial personal computer runs the Linux system, if data of the sensing equipment is to be read successfully, Modbus communication driving codes need to be written manually, such as read-write data operation, transaction processing, request and corresponding task processing functions of the industrial personal computer to the sensing equipment, which can bring complicated code amount and increase of Bug rate, therefore, the method of directly calling the LibModbus library is adopted in the invention to realize data reading and collection of the sensing equipment.
The invention relates to a data acquisition method of a rain gauge based on Modbus communication, which is characterized in that a LibModbus driving library is installed in a Linux environment, an industrial personal computer is inserted into a USB (universal serial bus) to 485 module, Modbus A and Modbus B interfaces of a tipping bucket rain gauge and a radar flowmeter are correctly connected with a serial port to 485 module, a compiled bottom application program calls an interface Modbus _ connect (), the connection between the tipping bucket rain gauge and the radar flowmeter and the industrial personal computer is established, the control and parameter acquisition of the tipping bucket rain gauge and the radar flowmeter are realized by reading and writing corresponding function codes of the tipping bucket rain gauge and the radar flowmeter, and hydrological monitoring is further realized through the tipping bucket rain gauge and the radar flowmeter; the hydrologic monitoring content comprises parameters of rainfall, water level, flow rate and water quality monitoring.
As shown in fig. 1, the present invention is embodied as follows:
s1, setting Modbus serial port parameters;
s2, acquiring the information of the tipping bucket type rain gauge device;
s3, obtaining radar flow meter information;
and S4, releasing the allocated resources, and further realizing data acquisition and equipment control on the Internet of things sensing equipment through an application program.
In this embodiment, the Modbus serial port parameter setting in step S1 is specifically as follows:
s101, initializing a Modbus environment pointer by using an interface Modbus _ new _ rtu;
s102, setting a slave station ID by using an interface modbus _ set _ slave, wherein a parameter 1 is an environment pointer initialized by modbus _ new _ rtu; the parameter 2 is the tipping bucket type rain gauge equipment address provided by a manufacturer;
s103, establishing connection between the industrial personal computer and the tipping bucket rain gauge and the radar end by using the interface modbus _ connect, and starting serial port communication.
The key codes are as follows:
in this embodiment, the obtaining of the information of the dump-bucket rain gauge device in step S2 is specifically as follows:
s201, checking a dump-bucket rain gauge user manual provided by a manufacturer, wherein the 0x0000H, the 0x07D0 and the 0x07D1 are register address values of a rain value, an equipment address and an equipment baud rate respectively;
s202, in the equipment starting-up stage, obtaining the information of the tipping bucket rain gauge equipment, and respectively reading the values of registers with the addresses of 0x0000H, 0x07D0 and 0x07D1 by using an interface modbus _ read _ registers (), so as to obtain corresponding equipment information;
s203, because the read rain amount value is 10 times of the actual value, the processing of dividing by 10 times is also needed;
if the user wants to clear the current rainfall value, the user operates according to the prompt command, the bottom layer code calls an interface modbus _ write _ register, and a specified clearing command 0x5A is written into the rainfall value address 0x0000H, so that the rainfall value data clearing can be realized.
The key codes are as follows:
in this embodiment, the information of the radar flow meter obtained in step S3 is specifically as follows:
s301, reading the rainfall value by using an interface modbus _ read _ registers (), and performing multiple processing operation;
s302, different from the interface getNainDeviceInfo (), the radar interface is placed in the main loop to perform long-time traversal operation.
The key codes are as follows:
in this embodiment, the step S4 of releasing the allocated resources specifically includes: and the Modbus environment pointer of the Modbus _ new _ rtu initialization is utilized to close and recover resources, so that resource waste is avoided.
The key codes are as follows:
modbus_close(mb);
modbus_free(mb)。
example 2:
the invention relates to a data acquisition system of a rain gauge for Modbus communication, which comprises,
the setting unit is used for setting Modbus serial port parameters;
the acquiring unit I is used for acquiring the information of the tipping bucket type rain gauge device;
the acquisition unit II is used for acquiring information of the radar flowmeter;
and the release unit is used for releasing the allocated resources so as to realize data acquisition and equipment control on the Internet of things sensing equipment through an application program.
The setting unit in the present embodiment includes,
the configuration module is used for configuring relevant parameters of a Modbus-RTU (485) protocol;
the connection module is used for connecting the industrial personal computer with the Internet of things sensing equipment; the sensing equipment of the Internet of things comprises a tipping bucket type rain gauge and a radar.
As shown in fig. 2, the working process of the setting unit in this embodiment is as follows:
(1) and line connection: correctly connecting Modbus A and Modbus B interfaces of the Internet of things sensing equipment with a serial port 485 conversion module (A is connected with A, B is connected with B);
(2) downloading the latest LibModbus library in a Linux environment, entering a download directory, and decompressing and installing;
(3) running make and make install to generate folders of include and lib for calling by a main program; after a new static library is generated, the dynamic reference library needs to be reconfigured, specifically as follows: so. conf, open file ld, add "include/usr/local/lib" using a generation editing tool; saving and exiting, inputting Ldconfig in the command line, and re-reading the cache, namely correctly calling the new dynamic library file;
(4) and aiming at the equipment interface condition, establishing a modbus RTU environment: a modbus _ new _ RTU () interface in a LibModbus standard library function is utilized to generate and initialize a modbus structure body to carry out communication in a serial line by using an RTU mode; wherein, the parameter 1 is the name of a serial port processed by a designated OS, such as/dev/ttyS 0 (serial port 0) or/dev/ttyS USB0(USB to serial port 0) under the linux system; parameter 2 is the serial port baud rate, parameter 3 is the parity check bit, parameter 4 is the serial port data digit, and parameter 5 is the stop bit digit;
firstly, if the building is successful, the modbus _ new _ rtu () function returns a pointer pointing to the modbus _ t structure;
if the establishment fails, returning an error code;
(5) and setting a serial port mode: because the current internet-of-things sensing devices are all 485 communication protocols, a serial port mode is set by utilizing a modbus _ rtu _ set _ serial _ mode () interface in a LibModbus standard library function, and a parameter 1 is a serial port mode variable;
(6) and setting a slave station ID: each device has a unique address code, so to control a designated device, the ID of the expected operating device needs to be set, slave station ID setting can be realized by utilizing a modbus _ set _ slave () interface, a parameter 1 is a returned modbus _ t structure pointer, and a parameter 2 is a slave station ID value; the method comprises the following specific steps:
each device has a unique address code, so to control the designated device, the ID of the expected operating device needs to be set, and the slave station ID setting can be realized by utilizing a modbus _ set _ slave () interface; parameter 1 is the returned modbus _ t structure pointer; the parameter 2 is the slave ID value. The rain gauge and the radar flow gauge can be connected on the same line, on the premise that which equipment is connected is defined through a modbus _ set _ slave () interface (the rain gauge address is 0, the radar flow gauge is 1, and the equipment is required to have different equipment address codes), and after a program normally runs, the equipment can be enabled alternately to obtain equipment data circularly only through the interface modbus _ set _ slave ();
(7) and establishing connection: completing the setting of serial port parameters, Modbus equipment pointers and Modbus equipment slave addresses, establishing connection by using an interface Modbus _ connect (), successfully returning 0 by using the parameter 1 as the Modbus _ t structure pointer returned in the step (4), and returning error codes-1 by mistake;
(8) reading a holding register: when a user needs to read the holding register of the Internet of things sensing equipment, the parameter value of the holding register can be obtained by using an interface modbus _ read _ registers (); wherein, the parameter 1 is the modbus _ t structure pointer returned in the step (4); parameter 2 is the holding register address value to be read; the parameter 3 is the number of registers to be read; the parameter 4 is the storage location of the read result, and it is noted that the user needs to allocate enough memory to store the result in the storage location of the parameter 4; for example, to read the current rainfall value, look up the equipment manual, the rainfall value register address is 0x1, so it is only necessary to read the register by using the interface;
(9) writing data: when a user needs to write a designated register, if the current internet of things sensing equipment of the internet of things sensing equipment needs to be cleared, an interface modbus _ write _ registers () needs to be called, and a parameter 2 value is written into the address of the parameter 1 register;
(10) when the application program is ended, the created resources need to be recycled, the connection is closed by using an interface modbus _ close (), and then libmodbus environment release is carried out by using modbus _ free ().
Finally, it should be noted that: the above embodiments are only used to illustrate the technical solution of the present invention, and not to limit the same; while the invention has been described in detail and with reference to the foregoing embodiments, it will be understood by those skilled in the art that: the technical solutions described in the foregoing embodiments may still be modified, or some or all of the technical features may be equivalently replaced; and the modifications or the substitutions do not make the essence of the corresponding technical solutions depart from the scope of the technical solutions of the embodiments of the present invention.
Claims (10)
1. A data acquisition method of a rain gauge based on Modbus communication is characterized in that a LibModbus driving library is installed in a Linux environment, an industrial personal computer is inserted into a USB (universal serial bus) to 485 module, Modbus A and Modbus B interfaces of a tipping bucket rain gauge and a radar flowmeter are correctly connected with a serial port to 485 module, a compiled bottom application program calls an interface Modbus _ connect (), connection of the tipping bucket rain gauge and the radar flowmeter with the industrial personal computer is established, control and parameter acquisition of the tipping bucket rain gauge and the radar flowmeter are achieved by reading and writing corresponding function codes of the tipping bucket rain gauge and the radar flowmeter, and hydrological monitoring is achieved through the tipping bucket rain gauge and the radar flowmeter; the hydrologic monitoring content comprises parameters of rainfall, water level, flow rate and water quality monitoring.
2. The data acquisition method of the Modbus communication-based rain gauge according to claim 1, wherein the method comprises the following steps:
setting Modbus serial port parameters;
acquiring the information of the tipping bucket type rain gauge device;
acquiring radar flowmeter information;
and releasing the allocated resources, and further realizing data acquisition and equipment control on the Internet of things sensing equipment through an application program.
3. The data acquisition method of the Modbus communication-based rain gauge according to claim 2, wherein the Modbus serial port parameter setting is as follows:
initializing a Modbus environment pointer by using an interface Modbus _ new _ rtu;
setting a slave station ID by using an interface modbus _ set _ slave, wherein a parameter 1 is an environment pointer initialized by modbus _ new _ rtu; the parameter 2 is the tipping bucket type rain gauge equipment address provided by a manufacturer;
and establishing connection between the industrial personal computer and the tipping bucket rain gauge and the radar end by using the interface modbus _ connect, and starting serial port communication.
4. The data acquisition method of the Modbus communication-based rain gauge according to claim 2, wherein the obtaining of the tipping-bucket rain gauge device information is as follows:
by checking a dump-bucket rain gauge user manual provided by a manufacturer, register address values of 0x0000H, 0x07D0 and 0x07D1 are a rain value, an equipment address and an equipment baud rate respectively;
in the equipment starting-up stage, acquiring the information of the tipping bucket rain gauge equipment, and respectively reading the values of registers with the addresses of 0x0000H, 0x07D0 and 0x07D1 by using an interface modbus _ read _ registers (), so as to acquire corresponding equipment information;
performing multiple processing except 10;
if the user wants to clear the current rainfall value, the user operates according to the prompt command, the bottom layer code calls an interface modbus _ write _ register, and a specified clearing command 0x5A is written into the rainfall value address 0x0000H, so that the rainfall value data clearing can be realized.
5. The data acquisition method of the Modbus communication-based rain gauge according to claim 2, wherein the radar flow gauge information is obtained as follows:
reading the rainfall value by using an interface modbus _ read _ registers (), and performing multiple processing operation;
unlike interface getRainDeviceInfo (), the radar interface is placed in the main loop, performing long traversal operations.
6. The data acquisition method of the Modbus communication-based rain gauge according to any one of claims 2-5, wherein the releasing allocation resources specifically are: and the Modbus environment pointer of the Modbus _ new _ rtu initialization is utilized to close and recover resources, so that resource waste is avoided.
7. A data acquisition system of a rain gauge for Modbus communication is characterized by comprising,
the setting unit is used for setting Modbus serial port parameters;
the acquiring unit I is used for acquiring the information of the tipping bucket type rain gauge device;
the acquisition unit II is used for acquiring information of the radar flowmeter;
and the release unit is used for releasing the allocated resources so as to realize data acquisition and equipment control on the Internet of things sensing equipment through an application program.
8. The data acquisition system of a Modbus communication-based rain gauge according to claim 7, wherein the setting unit comprises,
the configuration module is used for configuring relevant parameters of a Modbus-RTU (485) protocol;
the connection module is used for connecting the industrial personal computer with the Internet of things sensing equipment; the sensing equipment of the Internet of things comprises a tipping bucket type rain gauge and a radar.
9. The data acquisition method of the Modbus communication-based rain gauge according to claim 8, wherein the configuration module specifically comprises the following working processes:
(1) and line connection: correctly connecting Modbus A and Modbus B interfaces of the Internet of things sensing equipment with a serial port 485 conversion module;
(2) downloading the latest LibModbus library in a Linux environment, entering a download directory, and decompressing and installing;
(3) running make and make install to generate folders of include and lib for calling by a main program; after a new static library is generated, the dynamic reference library needs to be reconfigured, specifically as follows: so. conf, open file ld, add "include/usr/local/lib" using a generation editing tool; saving and exiting, inputting Ldconfig in the command line, and re-reading the cache, namely correctly calling the new dynamic library file;
(4) and aiming at the equipment interface condition, establishing a modbus RTU environment: a modbus _ new _ RTU () interface in a LibModbus standard library function is utilized to generate and initialize a modbus structure body to carry out communication in a serial line by using an RTU mode; wherein, the parameter 1 is the name of the serial port processed by the designated OS; parameter 2 is the serial port baud rate, parameter 3 is the parity check bit, parameter 4 is the serial port data digit, and parameter 5 is the stop bit digit;
firstly, if the building is successful, the modbus _ new _ rtu () function returns a pointer pointing to the modbus _ t structure;
if the establishment fails, returning an error code;
(5) and setting a serial port mode: setting a serial port mode by using a modbus _ rtu _ set _ serial _ mode () interface in a LibModbus standard library function, wherein a parameter 1 is a serial port mode variable;
(6) and setting a slave station ID: setting the ID of expected operating equipment, and realizing the setting of the slave station ID by using a modbus _ set _ slave () interface, wherein the parameter 1 is a returned modbus _ t structure pointer, and the parameter 2 is a slave station ID value; the method comprises the following specific steps:
controlling the designated equipment, setting the ID of the expected operating equipment, and realizing the ID setting of the slave station by utilizing a modbus _ set _ slave () interface; parameter 1 is the returned modbus _ t structure pointer; the parameter 2 is the slave ID value.
10. The data acquisition system of the Modbus communication-based rain gauge according to claim 8 or 9, wherein the connection module specifically works as follows:
(1) and establishing connection: completing the setting of serial port parameters, Modbus equipment pointers and Modbus equipment slave addresses, establishing connection by using an interface Modbus _ connect (), successfully returning 0 by using the returned Modbus _ t structure pointer as the parameter 1, and returning error codes-1 by mistake;
(2) reading a holding register: when a user needs to read the holding register of the Internet of things sensing equipment, the parameter value of the holding register can be obtained by using an interface modbus _ read _ registers (); wherein, the parameter 1 is a returned modbus _ t structure pointer; parameter 2 is the holding register address value to be read; the parameter 3 is the number of registers to be read; the parameter 4 is the storage position of the reading result;
(3) writing data: when a user needs to write a designated register, if the current internet of things sensing equipment of the internet of things sensing equipment needs to be cleared, an interface modbus _ write _ registers () needs to be called, and a parameter 2 value is written into the address of the parameter 1 register;
(4) when the application program is ended, the created resources need to be recycled, the connection is closed by using an interface modbus _ close (), and then libmodbus environment release is carried out by using modbus _ free ().
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202011519035.8A CN112615771A (en) | 2020-12-21 | 2020-12-21 | Data acquisition method and system of rain gauge based on Modbus communication |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202011519035.8A CN112615771A (en) | 2020-12-21 | 2020-12-21 | Data acquisition method and system of rain gauge based on Modbus communication |
Publications (1)
Publication Number | Publication Date |
---|---|
CN112615771A true CN112615771A (en) | 2021-04-06 |
Family
ID=75243827
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202011519035.8A Pending CN112615771A (en) | 2020-12-21 | 2020-12-21 | Data acquisition method and system of rain gauge based on Modbus communication |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN112615771A (en) |
Cited By (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN116578037A (en) * | 2023-07-10 | 2023-08-11 | 杭州鄂达精密机电科技有限公司 | Full inspection machine PLC control system and full inspection machine system |
Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US20110307221A1 (en) * | 2010-06-10 | 2011-12-15 | Hach Company | Blind logger dynamic caller |
US20160154100A1 (en) * | 2013-07-24 | 2016-06-02 | Romano Giovannini | Aid system and method for visually impaired or blind people |
CN205607429U (en) * | 2016-02-05 | 2016-09-28 | 北京圣世信通科技发展有限公司 | Be applied to intelligent sensor module of hydrology water resource |
CN110706456A (en) * | 2019-10-19 | 2020-01-17 | 中国科学院、水利部成都山地灾害与环境研究所 | Rapid early warning system for debris flow |
-
2020
- 2020-12-21 CN CN202011519035.8A patent/CN112615771A/en active Pending
Patent Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US20110307221A1 (en) * | 2010-06-10 | 2011-12-15 | Hach Company | Blind logger dynamic caller |
US20160154100A1 (en) * | 2013-07-24 | 2016-06-02 | Romano Giovannini | Aid system and method for visually impaired or blind people |
CN205607429U (en) * | 2016-02-05 | 2016-09-28 | 北京圣世信通科技发展有限公司 | Be applied to intelligent sensor module of hydrology water resource |
CN110706456A (en) * | 2019-10-19 | 2020-01-17 | 中国科学院、水利部成都山地灾害与环境研究所 | Rapid early warning system for debris flow |
Non-Patent Citations (9)
Title |
---|
丁杰等: "都江堰渠首水资源监控及调度***", 《中国水利》 * |
周宜军等: "GPRS技术在水情信息传输中的应用", 《水利水文自动化》 * |
孙超作等: "丹江口水库水情测报***改造及应用", 《水利信息化》 * |
张乐等: "基于MODBUS总线的流量计在线检定", 《煤矿机械》 * |
徐敏等: "城市道路水情自动监测***的设计与实现", 《电子科技》 * |
惠楠: "串口通信技术在渠道水情监测***中的应用", 《陕西水利》 * |
朱红五: "江苏省大运河监测调度***工程设计及实施", 《人民长江》 * |
杨跃等: "基于AVR的水联网智能遥测终端的设计与实现", 《电子测试》 * |
胡功第: "江苏省太湖地区水质自动监测***的研发和实现", 《水利水文自动化》 * |
Cited By (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN116578037A (en) * | 2023-07-10 | 2023-08-11 | 杭州鄂达精密机电科技有限公司 | Full inspection machine PLC control system and full inspection machine system |
CN116578037B (en) * | 2023-07-10 | 2023-09-29 | 杭州鄂达精密机电科技有限公司 | Full inspection machine PLC control system and full inspection machine system |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN102662785B (en) | Method and device for acquiring kernel error information of Android system | |
KR20170129702A (en) | Manage previous versions of data for logical addresses of storage devices | |
CN114153779B (en) | I2C communication method, system, equipment and storage medium | |
CN101454746A (en) | Method for communication with a multi-function memory card | |
CN105183523A (en) | Method for remote upgrade of digital signal processor (DSP) program | |
CN110825647A (en) | Test method for automatically testing logical equipment interface | |
CN109240870A (en) | Solid state disk fault positioning method and related device | |
CN101699403B (en) | Method for graphically installing distributed system | |
CN112615771A (en) | Data acquisition method and system of rain gauge based on Modbus communication | |
CN103092648B (en) | A kind of image upgrade method, system and subscriber equipment and personal computer | |
CN104021089A (en) | Flash memory control chip, storage device and flash memory control method | |
CN111897485A (en) | Data storage method and device, electronic equipment and storage medium | |
WO2000036380A1 (en) | Internet enabled network flow computer system | |
CN109684152B (en) | RISC-V processor instruction downloading method and device | |
JPH11272459A (en) | Rewriting method for rewritable non-volatile memory and method/system for restoring fault of application program | |
CN105117237A (en) | Flash based program hierarchical storage, running and upgrading method and apparatus | |
CN110209605A (en) | The register reading/writing method and calculating equipment of PCIE Cardbus NIC Cardbus | |
CN116450184B (en) | System upgrading method and device, electronic equipment and storage medium | |
CN106844206B (en) | Method and device for debugging multiple systems in mobile terminal | |
CN111580888A (en) | Method, device and equipment for batch creation of server RAID (redundant array of independent disks) and storage medium | |
CN110765060A (en) | Method, device, equipment and medium for converting MDIO bus into parallel bus | |
CN103391537A (en) | Method and device for writing international mobile equipment identify (IMEI) number through mobile terminal | |
CN206058176U (en) | A kind of automobile-used BootLoader commissioning devices and test automobile | |
CN102736922A (en) | Method for updating application programs of embedded system and terminal of embedded system | |
CN106033398A (en) | Data processing system, external device starting method, and data processing method |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
RJ01 | Rejection of invention patent application after publication | ||
RJ01 | Rejection of invention patent application after publication |
Application publication date: 20210406 |