CN113162931B - Method for transmitting Modbus RTU protocol message in wide area network - Google Patents
Method for transmitting Modbus RTU protocol message in wide area network Download PDFInfo
- Publication number
- CN113162931B CN113162931B CN202110436932.0A CN202110436932A CN113162931B CN 113162931 B CN113162931 B CN 113162931B CN 202110436932 A CN202110436932 A CN 202110436932A CN 113162931 B CN113162931 B CN 113162931B
- Authority
- CN
- China
- Prior art keywords
- slave station
- communication module
- address
- message
- modbus rtu
- 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.)
- Active
Links
- 238000000034 method Methods 0.000 title claims abstract description 30
- 238000004891 communication Methods 0.000 claims abstract description 72
- 230000005540 biological transmission Effects 0.000 claims abstract description 16
- 230000004044 response Effects 0.000 claims description 39
- 230000003993 interaction Effects 0.000 claims 1
- 238000012544 monitoring process Methods 0.000 abstract description 13
- 238000006243 chemical reaction Methods 0.000 abstract description 9
- 230000008569 process Effects 0.000 abstract description 6
- 230000006870 function Effects 0.000 description 42
- 238000004364 calculation method Methods 0.000 description 3
- 230000009286 beneficial effect Effects 0.000 description 2
- 238000010586 diagram Methods 0.000 description 2
- 238000012795 verification Methods 0.000 description 2
- PEDCQBHIVMGVHV-UHFFFAOYSA-N Glycerine Chemical compound OCC(O)CO PEDCQBHIVMGVHV-UHFFFAOYSA-N 0.000 description 1
- 230000002457 bidirectional effect Effects 0.000 description 1
- 238000001514 detection method Methods 0.000 description 1
- 238000011161 development Methods 0.000 description 1
- 230000000694 effects Effects 0.000 description 1
- 238000012986 modification Methods 0.000 description 1
- 230000004048 modification Effects 0.000 description 1
- 238000012545 processing Methods 0.000 description 1
- 230000002035 prolonged effect Effects 0.000 description 1
- 239000002699 waste material Substances 0.000 description 1
Images
Classifications
-
- 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/02—Protocols based on web technology, e.g. hypertext transfer protocol [HTTP]
- H04L67/025—Protocols based on web technology, e.g. hypertext transfer protocol [HTTP] for remote control or remote monitoring of applications
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L1/00—Arrangements for detecting or preventing errors in the information received
- H04L1/004—Arrangements for detecting or preventing errors in the information received by using forward error control
- H04L1/0056—Systems characterized by the type of code used
- H04L1/0061—Error detection codes
-
- 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
-
- 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
- H04L67/00—Network arrangements or protocols for supporting network services or applications
- H04L67/14—Session management
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L69/00—Network arrangements, protocols or services independent of the application payload and not provided for in the other groups of this subclass
- H04L69/08—Protocols for interworking; Protocol conversion
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L69/00—Network arrangements, protocols or services independent of the application payload and not provided for in the other groups of this subclass
- H04L69/16—Implementation or adaptation of Internet protocol [IP], of transmission control protocol [TCP] or of user datagram protocol [UDP]
- H04L69/163—In-band adaptation of TCP data exchange; In-band control procedures
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L69/00—Network arrangements, protocols or services independent of the application payload and not provided for in the other groups of this subclass
- H04L69/22—Parsing or analysis of headers
-
- 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
-
- Y—GENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
- Y02—TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
- Y02P—CLIMATE CHANGE MITIGATION TECHNOLOGIES IN THE PRODUCTION OR PROCESSING OF GOODS
- Y02P90/00—Enabling technologies with a potential contribution to greenhouse gas [GHG] emissions mitigation
- Y02P90/02—Total factory control, e.g. smart factories, flexible manufacturing systems [FMS] or integrated manufacturing systems [IMS]
Landscapes
- Engineering & Computer Science (AREA)
- Computer Networks & Wireless Communication (AREA)
- Signal Processing (AREA)
- Computer Security & Cryptography (AREA)
- Health & Medical Sciences (AREA)
- Computing Systems (AREA)
- General Health & Medical Sciences (AREA)
- Medical Informatics (AREA)
- Communication Control (AREA)
- Small-Scale Networks (AREA)
Abstract
The invention relates to the technical field of sensing equipment communication of the Internet of things, in particular to a method for transmitting a Modbus RTU protocol in a wide area network, which is applied to a network in which slave stations are connected with a master station through a communication module; after receiving the registration message, the master station records the setting information of the communication module and the address of the slave station connected and managed by the communication module, and establishes a link; and the master station and the slave station transmit and interact the Modbus RTU protocol through the established link. The method realizes the transmission of the Modbus RTU protocol in the wide area network, is not limited by the slave station having a fixed IP address in the whole process, cancels a protocol conversion process and a conversion module, reduces the monitoring function cost of the sensing equipment of the Internet of things, and improves the monitoring efficiency.
Description
Technical Field
The invention relates to the technical field of communication of sensing equipment of the Internet of things, in particular to a method for transmitting a Modbus RTU protocol message in a wide area network.
Background
Modbus is the first bus protocol used in industrial fields worldwide. The Modbus protocol is a general language applied to control devices, and communication between controllers, controllers and other devices via a network (e.g., ethernet) can be achieved through the Modbus protocol. Currently, the Modbus protocol becomes a general industrial standard, and control devices produced by different manufacturers are connected into an industrial network through the Modbus protocol to perform centralized monitoring. The ModBus network has only one host, and all communication is initiated by the host.
The Modbus protocol comprises a Modbus TCP protocol and a Modbus RTU protocol, and the Modbus RTU protocol is generally adopted for asynchronous serial transmission. With the development of the internet of things, in the existing industrial network, remote monitoring of the controller is mainly realized through a management platform of the internet of things, and the connection between the controller (slave station) and the management platform of the internet of things (master station) needs to be communicated through a communication module (such as a network serial device) and a conversion module (such as a communication gateway). The communication module is mainly used for communicating with the controller and the Internet of things management platform at the same time, so that bidirectional conversion of serial port data and network data messages is realized. The conversion module mainly converts a Modbus RTU protocol into a Modbus TCP protocol, so that transmission can be performed in the Ethernet, because the Modbus TCP protocol needs a master station to actively establish a TCP link to a slave station, and the existing slave station generally does not have a fixed IP, the Modbus TCP protocol is only suitable for transmission in a local area network, if transmission is performed in a wide area network, namely, a Modbus TCP data packet is transmitted to an Internet of things management platform through the wide area network, VPN gateway equipment needs to be added to establish a VPN network, a fixed IP address is distributed to the slave station through the VPN gateway, so that transmission of the Modbus TCP protocol in the wide area network is realized, but the cost is increased by adding the VPN gateway equipment, the processing time is prolonged, and the monitoring efficiency is reduced.
Disclosure of Invention
The invention aims to provide a method for transmitting Modbus RTU protocol messages in a wide area network only by adopting a communication module, so that the cost of the monitoring function of sensing equipment of the Internet of things is reduced, and the monitoring efficiency is improved.
The present invention provides the following basic scheme: a method for transmitting Modbus RTU protocol messages in a wide area network is applied to a network in which slave stations are connected with a master station through a communication module, and comprises the following contents:
s1, a communication module generates a self-defined registration message and sends the self-defined registration message to a master station, wherein the registration message comprises setting information of the communication module and an address of a slave station for connection management of the communication module;
s2, after receiving the registration message, the master station records the setting information of the passing module and the address of the slave station connected and managed by the communication module, and establishes a link;
and S3, the master station and the slave station transmit and interact with the Modbus RTU protocol through the established link, wherein the communication module adds a TCP protocol header of a TCP transmission protocol to a data packet of the Modbus RTU protocol sent to the master station by the slave station.
Compared with the prior art, the scheme has the advantages that: the communication module generates a self-defined registration message and sends the self-defined registration message to the master station, wherein the registration message comprises the setting information of the communication module and the address of the slave station connected and managed by the communication module; the master station records the code of the communication module after receiving the registration message, and the slave station address of the communication module connection management, and establishes a link; the master station and the slave station transmit and interact with each other through the established link, namely the master station and the slave station transmit data packets of the Modbus RTU protocol through the established link, the communication module can add a TCP protocol head of a TCP transmission protocol to the data packets of the Modbus RTU protocol transmitted to the master station by the slave station, the realization converts serial data into network data messages, then the network data messages are transmitted to the master station through a wide area network, the master station analyzes the data packets of the Modbus RTU protocol obtained by the TCP protocol head, and the communication module analyzes the data packets of the Modbus RTU protocol obtained by the TCP protocol head in the network data messages transmitted by the master station, and then transmits the data packets to the slave station, thereby realizing the centralized monitoring of the master station on the slave station.
The method realizes the transmission of the Modbus RTU protocol in the wide area network, is not limited by the fact that the slave station must have a fixed IP address in the whole process, cancels a protocol conversion process and a conversion module, reduces the monitoring function cost of the sensing equipment of the Internet of things, and improves the monitoring efficiency.
Further, the customized registration message further includes: checking a function code and CRC;
the slave station address managed by the communication module comprises a slave station minimum address managed by the communication module and a slave station maximum address managed by the communication module;
the command format of the self-defined registration message is a Modbus RTU message, which specifically comprises the following steps: setting information of the communication module, a function code, a minimum address of the slave station managed by the communication module, a maximum address of the slave station managed by the communication module, the lower eight bits of the CRC check, and the upper eight bits of the CRC check.
Has the advantages that: the self-defined command format of the register message is a Modbus RTU message, and specifically comprises the following steps: the setting information, the function code, the minimum address of the slave station managed by the communication module, the maximum address of the slave station managed by the communication module, the low eight bits of CRC check and the high eight bits of CRC check are limited in bits in a Modbus RTU message, and the command format of the self-defined registration message specifically comprises the minimum address of the slave station managed by the communication module and the maximum address of the slave station managed by the communication module, so that the slave station addresses managed by the communication module are continuous, and the accuracy of the addresses is guaranteed.
Further, when the S3, the master station and the slave station transmit and interact with each other through the established link, the method includes:
s301, the master station sends a request message to the slave station;
s302, the slave station makes a corresponding response according to the function code contained in the request message and sends a response message to the master station;
and S303, if the master station does not receive the response message within the preset response time, sending the request message to the slave station again until the link interruption is detected, and stopping sending the request message.
Has the advantages that: the master station sends a request message to the slave station; the slave station makes a corresponding response according to the function code contained in the request message and sends a response message to the master station; and if the master station does not receive the response message within the preset response time, sending the request message to the slave station again until the link interruption is detected, and stopping sending the request message. The preset response time can be adjusted according to the specific requirements of users and the specific conditions of the network, the master station sends the request message to the slave station again when not receiving the response message in the preset response time, so that the control delay caused by stopping data transmission between the slave station and the master station is prevented from influencing the control of the industrial equipment, and the request message is stopped sending until the link interruption is detected, so that the error detection is timely carried out, the repeated retransmission is prevented, and the occupation and the waste of resources are caused.
Further, the command format of the request message is a Modbus RTU message, which includes: the slave address, the function code, the data field, and the lower eight bits of the CRC check and the upper eight bits of the CRC check.
Has the advantages that: the request message is sent to the slave station by the master station, wherein the request message passes through the communication module, the command format of the request message is Modbus RTU message, the Modbus RTU message comprises the slave station address, and the communication module can definitely forward the request message to the slave station in management connection.
Further, if the function code is 0x65, it indicates that the Modbus RTU message is a self-defined registration message; and if the function codes are 0x03, 0x06 and 0x10, the Modbus RTU message is a request message.
Has the beneficial effects that: the command formats of the customized register message and the request message are Modbus RTU messages, and the messages are the customized register message or the request message according to different function codes.
Further, the function code is 0x03, and further indicates that the master station continuously reads data from the slave station, and the data field of the request message includes eight higher bits of the start register address, eight lower bits of the start register address, eight higher bits of the read register number, and eight lower bits of the read register number;
the function code is 0x06, and further indicates that the master station writes data to the slave station, and the data field of the request message includes: the written register address is eight bits high, the written register address is eight bits low, the written data is eight bits high, and the written data is eight bits low;
the function code is 0x10, and further indicates that the master station writes data into the plurality of slave stations, and the data field of the request message includes: eight higher bits of the register start address, eight lower bits of the register start address, eight higher bits of the number of registers written, eight lower bits of the number of registers written, eight higher bits of each write data, and eight lower bits of each write data.
Has the beneficial effects that: the function codes are 0x03, 0x06 and 0x10, which all indicate that the Modbus RTU message is a request message, but the data domain of the request message contains different contents according to different function codes, so as to realize different request contents.
Further, the link interruption is that the link between the master station and the slave station is interrupted if the master station does not receive the response message sent by the slave station within the preset interruption time.
Has the advantages that: the preset terminal time can be adjusted according to the specific requirements of users and the specific conditions of the network, if the master station does not receive the response message sent by the slave station within the preset interruption time, the link between the master station and the slave station is considered to be interrupted, and the master station does not send request information to the slave station any more, so that channel blockage caused by repeated sending of the request information is prevented. Further, the preset interruption time is greater than a preset response time.
Has the advantages that: the preset interruption time is longer than the preset response time, so that the master station can send the request message to the slave station again when not receiving the response message in the preset response time, and a certain fault-tolerant time is provided for transmission between the master station and the slave station.
Drawings
FIG. 1 is a flowchart of an embodiment of a method for transmitting Modbus RTU protocol messages over a wide area network according to the present invention;
FIG. 2 is a schematic diagram of a network structure in an embodiment of a method for transmitting a Modbus RTU protocol packet over a wide area network according to the present invention;
fig. 3 is a schematic diagram of a frame structure of a Modbus RTU protocol in an embodiment of a method for transmitting a Modbus RTU protocol packet in a wide area network according to the present invention.
Detailed Description
The following is further detailed by way of specific embodiments:
the embodiment is basically as shown in the attached figure 1: a method for transmitting Modbus RTU protocol messages in a wide area network is applied to a network in which slave stations are connected with a master station through a communication module, the network in the embodiment is shown in figure 2, the master station comprises an Internet of things management platform and a TCP server (TCP Server), and the Internet of things management platform is a webpage end platform (Web) and is used for a user to input commands; the command is issued to the TCP server, the TCP server passes through a Wide Area Network (WAN), the GPRS network in the embodiment sends a data packet of the command to the communication module, the communication module in the embodiment adopts a serial port communication server (DTU), the DTU issues the command to the slave station connected by a Modbus RTU protocol serial port, and the slave station in the embodiment adopts a controller (PLC).
The method comprises the following steps:
s1, a communication module generates a self-defined registration message and sends the self-defined registration message to a master station, wherein the registration message comprises setting information of the communication module and an address of a slave station for connection management of the communication module; in this embodiment, the setting information of the communication module is the code of the DTU.
The self-defined registration message is a Modbus RTU message, and further comprises: checking a function code and CRC; the slave station address managed by the communication module comprises a slave station minimum address managed by the communication module and a slave station maximum address managed by the communication module; the self-defined command format of the register message is a Modbus RTU message, and specifically comprises the following steps: setting information of the communication module, a function code, a minimum address of a slave station managed by the communication module, a maximum address of a slave station managed by the communication module, lower eight bits of CRC check, and upper eight bits of CRC check.
The frame structure of the Modbus RTU protocol, as shown in fig. 3, includes an address field, a function code, a data field, and a CRC field; the address field only contains a child node address, namely the address of the slave station PLC, and the legal child node address is decimal 0-247. 0 is a broadcast address, each sub-device is assigned an address in the range of 1 to 247; a function code indicating a command to be executed, the function code being followed by a data field indicating parameters including a request and a response; the CRC field is an error check and is the result of a calculation that performs a "redundancy check" on the message content. The self-defined register message sent by the DTU is a Modbus RTU protocol, the Modbus RTU protocol adopts a 16-system, the function code occupies 8 bits in the Modbus RTU message, the data field is a plurality of 8 bits, in this embodiment, the function code 101 is a user-defined function code, that is, the function code is 0x65, it indicates that the Modbus RTU message is the self-defined register message, but the function code of the self-defined register message is not limited to 0x65, but can also be 0x66 or other values, that is, the function code of the self-defined register message adopts a user extension segment, and the main station and the communication module negotiate to determine, that is, the equipment terminal and the platform terminal negotiate to determine consistently, thereby increasing the application range.
The format of the self-defined registration message command sent by the DTU is as follows: [ DTU encoding ] [ command number 101] [ minimum Address of slave station managed by DTU ] [ maximum Address of slave station managed by DTU ] [ lower 8 bits of CRC check ] [ upper 8 bits of CRC check ], for example: the registration message is: 01 65 01 D1 97 (hexadecimal), where 01: DTU is encoded as 01#;65: DTU register message function code; 01: minimum address of slave station managed by DTU: 1;01: maximum address of slave station managed by DTU: 1; d1 97 (b): the CRC check code can be obtained by table lookup or calculation.
And S2, after receiving the registration message, the master station records the setting information of the communication module and the address of the slave station connected and managed by the communication module, and establishes a link. Specifically, the TCP set receives a registration message sent by the DTU, where the registration message includes a code of the DTU and an address of a slave station of the PLC connected and managed by the DTU, and the address of the slave station managed by the DTU must be continuous.
S3, the master station and the slave station transmit and interact with a Modbus RTU protocol through the established link, and the method comprises the following steps:
s301, the master station sends a request message to the slave station. Specifically, the TCP server sends a request message to the PLC. The command format of the request message is a Modbus RTU message, which includes: the slave address, the function code, the data field, and the lower eight bits of the CRC check and the upper eight bits of the CRC check. The function codes are 0x03, 0x06 and 0x10, and represent that the Modbus RTU message is a request message. And the function code is 0x03, further indicating that the master station continuously reads data from the slave station, and the data field of the request message includes the initial register address upper eight bits, the initial register address lower eight bits, the register number read upper eight bits, and the register number read lower eight bits, for example: request message: 01 03 00 00 05 85 C9
01 slave station address 01#
03 continuous reading holding register function code
00 00 read start address is: 0
00 05 read of 5 words in length
A5 CB is CRC check code, and can be obtained by table look-up or calculation
PLC response data: 01 03 0A 00 01 00 00 0C 00 00 00 00 00 00 00 9C E6
The response format is: [ 16-bit slave station address ] [03 function code ] [ byte number (= register number × 2) ] [ first 8 upper bits ] [ first 8 lower bits ] [ second 8 upper bits higher bits lower bits ] [ … [ lower 8 of CRC check ] [ 8 upper bits of CRC check ] remark CRC adopting 16-bit algorithm
Meaning of data:
01. slave station address 01#
03. Sequential read holding register function code
The byte length of the 0A read is: 10
00 01 read first register value 00 01
00 The second register value read at 0C is 00C
00 The third register value read 02 is 00
00 The fourth register value of 00 read is 00
00 00 read fifth register value 00
9C E6 is CRC check code
The function code is 0x06, and further indicates that the master station writes data to the slave station, and the data field of the request message includes: the register address written eight higher bits, the register address written eight lower bits, the data written eight higher bits, the data written eight lower bits, for example: request message: 01 06 00 03 00 B8 B8A; write the value of holding register 03 (initial address 00) to 00; the PLC will return a response after the write is successful: 01 06 00 03 00B 01 B8A.
The function code is 0x10, and further indicates that the master station writes data to the plurality of slave stations, and the data field of the request message includes: eight higher bits of the register start address, eight lower bits of the register start address, eight higher bits of the number of registers written, eight lower bits of the number of registers written, eight higher bits of each write data, and eight lower bits of each write data, for example: request message: 01 10 02 58 00A 14 01 0E 00 B2 01 09 00 AF 01 09 00 AF 13 88 00 32 C3 65
01: device address
10: function code
02 58: register head address
00 0A: number of registers
14: number of bytes
01 0E: the first data of the register is written into the upper 8 bits and the lower 8 bits
00 B2: the second data written into the register is 8 high bits, 8 low bits, and so on
……
C3 65 verification information
The PLC will return a response after the write is successful: 01 10 02 58 00A C0 65
01: device address
10: function code
02 58: register head address
00 0A: number of registers
C0 65: verification information
Taking the calibration of the PLC internal time, i.e. the write time, as an example, the request message transmission is as follows:
control word: MW 146-MW 151; communication address: 0X92- -0X97; the control word function: reading the internal time of the PLC;
description of the invention | Variable address | Modbus address | Data type | Description of the preferred embodiment |
Year of year | MW146 | 0x92 | WORD | Four digit years, e.g. 2021 being 0x07E5 |
Moon cake | MW147 | 0x93 | WORD | Month, 1-12 |
Day(s) day | MW148 | 0x94 | WORD | Date, 1-31 |
Time-piece | MW149 | 0x95 | WORD | Hour, 0-23 |
Is divided into | MW150 | 0x96 | WORD | Minute, 0-59 |
Second of | MW151 | 0x97 | WORD | Second, 0-59 |
S302, the slave station makes a corresponding response according to the function code contained in the request message and sends a response message to the master station. Specifically, the PLC makes a corresponding response according to the function code included in the request message, and sends a response message to the TCP server.
And S303, if the master station does not receive the response message within the preset response time, sending the request message to the slave station again until the link interruption is detected, and stopping sending the request message. And the link interruption is that the link between the master station and the slave station is interrupted if the master station does not receive the response message sent by the slave station within the preset interruption time. And the preset interruption time is greater than the preset response time. In this embodiment, the preset response time is 10 seconds, and the preset interrupt time is 120 seconds. Specifically, if the TCP server does not receive the response message within 10 seconds, the TCP server sends the retry request to the PLC again, and if the TCP server does not receive the response message after 102 seconds, the link is considered to be interrupted, and the request sending is stopped.
The working principle is as follows: TCP server and PLC transmit the data packet of Modbus RTU agreement through the link that establishes, DTU can add the TCP agreement head of TCP transmission agreement to the data packet of the Modbus RTU agreement that PLC sent the master station, realizes converting serial data into network data message, then transmits network data message to TCP server through the GPRS network, and master station analysis TCP agreement head obtains the data packet of Modbus RTU agreement to this data acquisition is accomplished. The user inputs the command through the internet of things management platform, the internet of things management platform issues the command to the TCP server, the TCP server transmits the command to the DTU through the GPRS network, wherein the command is a network data message, namely a data packet of a Modbus RTU protocol of a TCP protocol head of a TCP transmission protocol is added, the DTU analyzes the data packet of the Modbus RTU protocol obtained by the TCP protocol head of the network data message sent by the main station, and then transmits the data packet to the corresponding PLC, and therefore centralized monitoring of the main station on the slave stations is achieved. In addition, the Modbus RTU protocol is transmitted in the wide area network, the whole process is not limited by the fact that the slave station must have a fixed IP address, a protocol conversion process and a conversion module are omitted, the monitoring function cost of the sensing equipment of the Internet of things is reduced, and the monitoring efficiency is improved.
The foregoing are embodiments of the present invention and are not intended to limit the scope of the invention to the particular forms set forth in the specification, which are set forth in the claims below, but rather are to be construed as the full breadth and scope of the claims, as defined by the appended claims, as defined in the appended claims, in order to provide a thorough understanding of the present invention. It should be noted that, for those skilled in the art, without departing from the structure of the present invention, several changes and modifications can be made, which should also be regarded as the protection scope of the present invention, and these will not affect the effect of the implementation of the present invention and the practicability of the patent. The scope of the claims of the present application shall be determined by the contents of the claims, and the description of the embodiments and the like in the specification shall be used to explain the contents of the claims.
Claims (7)
1. A method for transmitting Modbus RTU protocol message in wide area network is applied to the network that the slave station is connected with the master station through a communication module, and is characterized in that: the method comprises the following steps:
s1, a communication module generates a self-defined registration message and sends the self-defined registration message to a master station, wherein the registration message comprises setting information of the communication module and an address of a slave station for connection management of the communication module; the command format of the self-defined register message is a Modbus RTU message, and the method comprises the following steps: setting information of the communication module, a function code, a minimum address of a slave station managed by the communication module, a maximum address of the slave station managed by the communication module, the lower eight bits of CRC check and the upper eight bits of CRC check; the user-defined function code of the registration message adopts a user extension segment and is determined by negotiation of the master station and the communication module;
s2, after receiving the registration message, the master station records the setting information of the communication module and the address of the slave station connected and managed by the communication module, and establishes a link; wherein the registration message contains the code of the communication module and the slave station address of the slave station managed by the communication module, and the slave station addresses managed by the communication module must be continuous;
s3, the master station and the slave station transmit and interact with a Modbus RTU protocol through the established link;
the S3 comprises the following steps: s301, the master station sends a request message to the slave station; the command format of the request message is a Modbus RTU message, which includes: the slave station address, the function code, the data field and the lower eight bits of CRC check and the upper eight bits of CRC check;
s302, the slave station makes a corresponding response according to the function code contained in the request message and sends a response message to the master station;
the master station and the slave station transmit data packets of a Modbus RTU protocol through the established link, the communication module can add a TCP protocol head of a TCP transmission protocol to the data packets of the Modbus RTU protocol transmitted to the master station by the slave station, serial port data are converted into network data messages, then the network data messages are transmitted to the master station through a GPRS network, and the master station analyzes the TCP protocol head to obtain the data packets of the Modbus RTU protocol, so that data acquisition is completed.
2. The method for transmitting Modbus RTU protocol messages on a wide area network according to claim 1, wherein: the slave station address managed by the communication module comprises a slave station minimum address managed by the communication module and a slave station maximum address managed by the communication module.
3. The method for transmitting Modbus RTU protocol messages on a wide area network according to claim 1, wherein: s3, when master station and slave station carry out the transmission and the interaction of Modbus RTU agreement through the link that establishes, still include:
and S303, if the master station does not receive the response message within the preset response time, sending the request message to the slave station again until the link interruption is detected, and stopping sending the request message.
4. The method for transmitting Modbus RTU protocol messages on a wide area network according to claim 3, wherein: if the function code is 0x65, the Modbus RTU message is represented as a self-defined registration message; and if the function codes are 0x03, 0x06 and 0x10, the Modbus RTU message is a request message.
5. The method for transmitting Modbus RTU protocol messages on a wide area network according to claim 4, wherein: the function code is 0x03, and further indicates that the master station continuously reads data from the slave station, and the data field of the request message comprises an upper eight bit of the initial register address, a lower eight bit of the initial register address, an upper eight bit of the read register number and a lower eight bit of the read register number;
the function code is 0x06, and further indicates that the master station writes data into the slave station, and the data field of the request message includes: the written register address is eight bits high, the written register address is eight bits low, the written data is eight bits high, and the written data is eight bits low;
the function code is 0x10, and further indicates that the master station writes data into the plurality of slave stations, and the data field of the request message includes: eight higher bits of the register start address, eight lower bits of the register start address, eight higher bits of the number of registers written, eight lower bits of the number of registers written, eight higher bits of each write data, and eight lower bits of each write data.
6. The method for transmitting Modbus RTU protocol messages on a wide area network according to claim 3, wherein: and the link interruption is that the link between the master station and the slave station is interrupted if the master station does not receive the response message sent by the slave station within the preset interruption time.
7. The method for transmitting Modbus RTU protocol messages on a wide area network according to claim 6, wherein: the preset interruption time is greater than the preset response time.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202110436932.0A CN113162931B (en) | 2021-04-22 | 2021-04-22 | Method for transmitting Modbus RTU protocol message in wide area network |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202110436932.0A CN113162931B (en) | 2021-04-22 | 2021-04-22 | Method for transmitting Modbus RTU protocol message in wide area network |
Publications (2)
Publication Number | Publication Date |
---|---|
CN113162931A CN113162931A (en) | 2021-07-23 |
CN113162931B true CN113162931B (en) | 2023-04-07 |
Family
ID=76869453
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202110436932.0A Active CN113162931B (en) | 2021-04-22 | 2021-04-22 | Method for transmitting Modbus RTU protocol message in wide area network |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN113162931B (en) |
Families Citing this family (7)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN113572782B (en) * | 2021-07-30 | 2023-03-10 | 广东机电职业技术学院 | Internet of things gateway supporting multiple sensor networks and implementation method thereof |
CN114126036A (en) * | 2021-10-14 | 2022-03-01 | 南方电网深圳数字电网研究院有限公司 | Data communication method and device based on Modbus RTU protocol |
CN115278571A (en) * | 2022-07-06 | 2022-11-01 | 明阳智慧能源集团股份公司 | Data wireless communication method between wind generating set and remote equipment |
CN116566762B (en) * | 2023-07-07 | 2023-10-20 | 武汉亚为电子科技有限公司 | Cascading equipment based on Modbus-RTU protocol and application method thereof |
CN117405239A (en) * | 2023-12-14 | 2024-01-16 | 武汉亚为电子科技有限公司 | Modbus protocol-based thermal infrared imager and system imaging method thereof |
CN117579423B (en) * | 2024-01-16 | 2024-03-29 | 南京德克威尔自动化有限公司 | Bus extension module and communication method using same |
CN117792831A (en) * | 2024-02-27 | 2024-03-29 | 天津大学四川创新研究院 | Multi-protocol Modbus gateway control system and method |
Citations (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN205945786U (en) * | 2016-08-22 | 2017-02-08 | 南京南瑞集团公司 | Serial port two -way modbus communication gateway of ethernet |
Family Cites Families (6)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US7574512B2 (en) * | 2004-04-15 | 2009-08-11 | Schneider Automation Sas | MODBUS encapsulated transport interface |
CN101945088B (en) * | 2010-01-08 | 2013-02-20 | 广州中浩控制技术有限公司 | Communication processing method of wide area data collection |
CN103546467B (en) * | 2013-10-23 | 2016-08-17 | 上海爱控自动化设备有限公司 | The method applying Modbus rtu protocol on TCP/IP network |
CN103561032B (en) * | 2013-11-08 | 2016-08-17 | 山东大学 | The method of Modbus device network communication under ICP/IP protocol |
CN103746783A (en) * | 2013-11-29 | 2014-04-23 | 国电南瑞科技股份有限公司 | Extended communication method based on Modbus communication protocol |
DE102018125894B4 (en) * | 2018-10-18 | 2021-01-28 | Bender Gmbh & Co. Kg | Method for resolving an address conflict in the Modbus RTU standard protocol |
-
2021
- 2021-04-22 CN CN202110436932.0A patent/CN113162931B/en active Active
Patent Citations (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN205945786U (en) * | 2016-08-22 | 2017-02-08 | 南京南瑞集团公司 | Serial port two -way modbus communication gateway of ethernet |
Also Published As
Publication number | Publication date |
---|---|
CN113162931A (en) | 2021-07-23 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN113162931B (en) | Method for transmitting Modbus RTU protocol message in wide area network | |
CN107919947B (en) | Coding method for long message transmission of CAN bus | |
CN101719922B (en) | Device and method of protocol conversion between PROFIBUS-DP industrial fieldbus and wireless ZIGBEE | |
CN106506347B (en) | A kind of multi-protocol data communication gate equipment for air traffic control system | |
CN112929367B (en) | Protocol conversion method for Profinet network and industrial IPv6 backbone network | |
CN103546354A (en) | Communicating method being based on Internet of Things electric temperature measurement equipment and enabling RS485 bus and CAN bus to be compatible | |
US20210392011A1 (en) | User station for a serial bus system and method for communication in a serial bus system | |
CN102546217A (en) | Message filtering method | |
Urrea et al. | Design and implementation of an error detection and correction method compatible with MODBUS-RTU by means of systematic codes | |
CN106027686B (en) | Enhanced MODBUS communication method based on MPEG-2 | |
CN105515925A (en) | UART multi-master real-time communication system | |
CN112105008B (en) | LoRaWAN gateway node data interaction method based on data unit | |
CN204145528U (en) | The how main real-time communication system of a kind of UART | |
CN112398780B (en) | Equipment self-identification communication method suitable for multiple networks | |
CN110719218B (en) | Multi-node interconnection protocol standard method based on CAN bus | |
Kuang et al. | A Modbus Protocol Stack Compatible with RTU/TCP Frames and Embedded Application | |
CN102566484A (en) | Multifunctional analog quantity acquisition module and information transmission method thereof | |
Alves et al. | On the adaptation of broadcast transactions in token-passing fieldbus networks with heterogeneous transmission media | |
CN105739377B (en) | Using the circuit and control method of the common I/O transmitting-receivings CAN data messages of single-chip microcomputer | |
CN111365830B (en) | Fan networking system based on RS-485 enhanced Modbus communication protocol | |
Yang et al. | The design of the CAN bus interface controller based on Verilog HDL | |
Vitturi et al. | Hybrid Ethernet/IEEE 802.11 networks for real-time industrial communications | |
CN110120987A (en) | A kind of WiFi connection method and device | |
KR102081996B1 (en) | System for Controlling Intelligence Motor Protection and Controller(IMPC) based on LoRa Communication | |
Alves et al. | Engineering PROFIBUS networks with heterogeneous transmission media |
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 | ||
GR01 | Patent grant | ||
GR01 | Patent grant |