Interaction system and method based on UDP and Modbus-TCP

By combining the UDP mode and transaction identifier confirmation mechanism under the Modbus-TCP protocol framework, the problem of limited number of access devices and loss of UDP protocol packets is solved, and the effect of unrestricted access and reliable transmission of packets is achieved.

CN116781802BActive Publication Date: 2025-08-29GUANGDONG KEREAD ELECTRIC TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202310855695.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-07-12
Publication Date
2025-08-29
Estimated Expiration
2043-07-12

AI Technical Summary

Technical Problem

In the prior art, the Modbus-TCP protocol has a limited number of access devices in industrial field communication, and the UDP protocol has problems of packet loss or duplication, so it is impossible to simultaneously exert the advantage of unlimited number of UDP connections and the reliability of the Modbus-TCP protocol.

Method used

Using an interactive system based on UDP and Modbus-TCP, the Modbus-TCP protocol framework and UDP mode link layer communication between the communication server and the terminal device is used to confirm whether the packet is lost and retransmit it to ensure that the packet is not lost.

Benefits of technology

It realizes that the number of equipment access is not limited, and the reliable transmission of packets is ensured in UDP mode, solves the problem of insufficient number of TCP connection ports, and improves communication efficiency and reliability.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116781802B_ABST
    Figure CN116781802B_ABST
Patent Text Reader

Abstract

The present invention discloses an interactive system and method based on UDP and Modbus-TCP, relating to the field of communications technology. The communication network link layer between a communication server and each terminal device uses the UDP mode, and the communication message format between the communication server and each terminal device adopts the Modbus-TCP protocol framework. The system utilizes the transaction processing identifier of the Modbus-TCP protocol message, determines whether a message is lost by incrementing the transaction processing identifier by 1, and determines whether the message is lost by retransmitting the request message or sending a request message with the transaction processing identifier incremented by 1. This invention can achieve an unlimited number of connected devices, utilize the Modbus-TCP protocol framework, and ensure that messages are not lost.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of communication technology, and in particular to an interactive system and method based on UDP and Modbus-TCP. Background Art

[0002] As an industrial field communication bus technology, the Modbus-TCP communication protocol has been widely used in actual production. The Modbus-TCP protocol uses TCP / IP as the lower layer protocol and therefore has all the characteristics of TCP / IP communication, namely: network transmission is based on reliable connections, transmission speed is fast, and the message has a confirmation and retransmission mechanism to ensure that the communication message transmission process is not lost or repeated. In order to be able to use the Modbus-TCP communication method, in addition to having an Ethernet interface, the network device must also have a corresponding number of TCP ports to establish a TCP connection for normal use.

[0003] When using the MCU + Ethernet chip mode to implement Ethernet communication, the number of TCP connections that can be established is limited in many cases (that is, the number of ports for establishing TCP connections is limited due to resource design issues). When the client initiates the establishment of TCP connections with the server, the number is also limited. If Modbus-TCP is used as the data interaction protocol, the number of devices that can be connected is also limited, which cannot meet the needs of actual on-site applications.

[0004] The Ethernet UDP protocol is an Ethernet communication method that is not based on reliable connections. While it allows for unlimited network access, UDP itself is not based on reliable connections, and message loss and duplication are possible. Therefore, how to leverage the unlimited number of UDP connections while utilizing the Modbus-TCP protocol architecture and ensuring message loss prevention has become a pressing challenge for those skilled in the art. Summary of the Invention

[0005] The purpose of the present invention is to provide an interactive system and method based on UDP and Modbus-TCP, so as to achieve unlimited number of devices that can be connected, utilize the Modbus-TCP protocol architecture, and ensure that messages are not lost.

[0006] To achieve the above object, the present invention provides the following solutions:

[0007] An interactive system based on UDP and Modbus-TCP, the system comprising a communication server and a plurality of terminal devices connected to the communication server;

[0008] The communication message format between the communication server and each of the terminal devices adopts the Modbus-TCP protocol framework; the communication network link layer between the communication server and each of the terminal devices adopts the UDP mode;

[0009] After the communication server is started, it sends a request message with a transaction identifier of zero to the terminal device in UDP mode;

[0010] After the terminal device starts running, the terminal device clears the cache, and after the terminal device receives the request message with the transaction identifier of zero in the UDP mode, it enters the normal communication process and returns a status message with the transaction identifier of zero to the communication server in the UDP mode;

[0011] After the communication server receives a status message with a transaction processing identifier of zero using the UDP mode, the communication server enters a normal communication process, and the communication server sends a request message with a non-zero transaction processing identifier to the terminal device using the UDP mode; if the communication server receives a response message with the non-zero transaction processing identifier returned by the terminal device using the UDP mode using the UDP mode, the communication server determines that the message is not lost, and when the communication server sends a request message to the terminal device again using the UDP mode, the request message sent again is a request message with the non-zero transaction processing identifier plus 1; if the communication server does not receive a response message with the non-zero transaction processing identifier returned by the terminal device using the UDP mode using the UDP mode, the communication server determines that the message is lost, and when the communication server sends a request message to the terminal device again using the UDP mode, the request message sent again is the request message with the non-zero transaction processing identifier sent by the communication server to the terminal device last time using the UDP mode.

[0012] Optionally, the terminal device is a collection device actually installed on site; the terminal device is used to complete the collection, calculation and processing of raw data of the monitoring location under its jurisdiction.

[0013] Optionally, the communication server is the initiator of communication interaction and the center of data collection; the communication server is used to collect various types of data from on-site terminal devices.

[0014] The present invention also provides the following solution:

[0015] A method for interacting based on UDP and Modbus-TCP, the method being applied to the interactive system based on UDP and Modbus-TCP, the method comprising:

[0016] Step S1: The communication server starts running and sends a request message with a transaction identifier of zero to the terminal device in UDP mode;

[0017] Step S2: The terminal device starts running, clears the cache, and after receiving the request message with the transaction identifier of zero in UDP mode, the terminal device enters the normal communication process and returns a status message with the transaction identifier of zero to the communication server in UDP mode;

[0018] Step S3: After the communication server receives the status message with the transaction identifier of zero in the UDP mode, the communication server enters the normal communication process;

[0019] Step S4: The communication server uses the UDP mode to send a request message with a non-zero transaction processing identifier to the terminal device; if the communication server uses the UDP mode to receive a response message with the non-zero transaction processing identifier returned by the terminal device using the UDP mode, the communication server determines that the message is not lost, and when the communication server uses the UDP mode to send a request message to the terminal device again, the request message sent again is a request message with the non-zero transaction processing identifier plus 1; if the communication server uses the UDP mode to not receive a response message with the non-zero transaction processing identifier returned by the terminal device using the UDP mode, the communication server determines that the message is lost, and when the communication server uses the UDP mode to send a request message to the terminal device again, the request message sent again is the request message with the non-zero transaction processing identifier sent by the communication server to the terminal device last time using the UDP mode.

[0020] Optionally, step S4 specifically includes:

[0021] Step S41: The communication server sends a request message with a transaction identifier of i to the terminal device in UDP mode; i is a positive integer, 1≤i≤65535; the initial value of i is 1;

[0022] Step S42: The terminal device determines whether a request message with a transaction identifier of i is received in UDP mode;

[0023] If the terminal device receives the request message with the transaction identifier i in the UDP mode, step S43 is executed: the terminal device sends a response message with the transaction identifier i to the communication server in the UDP mode;

[0024] Step S44: The communication server determines whether a response message with a transaction identifier of i is received in UDP mode;

[0025] If the communication server receives a response message with a transaction identifier of i in UDP mode, step S45 is executed: determining whether i reaches 65535;

[0026] If i does not reach 65535, the communication server sets i=i+1 and returns to step S41;

[0027] If i reaches 65535, the communication server sets i=1 and returns to step S41;

[0028] If the communication server does not receive a response message with the transaction identifier i in UDP mode, it returns to step S41;

[0029] If the terminal device does not receive the request message with the transaction identifier i in UDP mode, it returns to step S41.

[0030] Optionally, after the communication server sends a request message with a transaction processing identifier of i to the terminal device using the UDP mode, if the terminal device receives the request message with a transaction processing identifier of i using the UDP mode, the terminal device sends a response message with a transaction processing identifier of i to the communication server using the UDP mode, and at the same time, the terminal device caches the response message with a transaction processing identifier of i sent to the communication server this time. If the communication server does not receive the response message with a transaction processing identifier of i using the UDP mode, the request message with a transaction processing identifier of i is sent to the terminal device again. If the terminal device receives the same request message with a transaction processing identifier of i as the last time again using the UDP mode, the cached response message with a transaction processing identifier of i sent to the communication server last time is copied, and the copied response message with a transaction processing identifier of i sent to the communication server last time is sent to the communication server.

[0031] Optionally, after the communication server sends a request message with a transaction processing identifier of i to the terminal device using the UDP mode, if the communication server does not receive a response message with a transaction processing identifier of i for more than three consecutive times using the UDP mode, the communication server sends a request message with a transaction processing identifier of zero to the terminal device using the UDP mode. After the terminal device receives the request message with a transaction processing identifier of zero using the UDP mode, the terminal device clears the cache, enters the normal communication process, and returns a status message with a transaction processing identifier of zero to the communication server using the UDP mode. After the communication server receives the status message with a transaction processing identifier of zero using the UDP mode, the communication server enters the normal communication process.

[0032] Optionally, after the communication server starts running, it sends a request message with a transaction processing identifier of zero to the terminal device in UDP mode, and also sends a terminal device cache clearing instruction to the terminal device. After the terminal device receives the terminal device cache clearing instruction, the terminal device clears the cache.

[0033] According to the specific embodiments provided by the present invention, the present invention discloses the following technical effects:

[0034] The present invention discloses an interactive system and method based on UDP and Modbus-TCP. The communication network link layer between the communication server and each terminal device adopts the UDP mode. Since the Ethernet UDP protocol is an Ethernet communication method not based on reliable connections, the access network devices are not restricted. Therefore, the communication network link layer between the communication server and each terminal device adopts the UDP mode to achieve unlimited number of devices that can be connected. The communication message format between the communication server and each terminal device adopts the Modbus-TCP protocol framework, utilizes the Modbus-TCP protocol architecture and the transaction processing identifier of the Modbus-TCP protocol message, and determines whether the message is lost by whether the transaction processing identifier is increased by 1, thereby ensuring that the message is not lost during the communication (interaction) process between the communication server and the terminal device using the UDP mode. BRIEF DESCRIPTION OF THE DRAWINGS

[0035] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.

[0036] Figure 1 This is the overall architecture diagram of the interactive system based on UDP and Modbus-TCP of the present invention;

[0037] Figure 2 Flowchart of the interactive method based on UDP and Modbus-TCP of the present invention;

[0038] Figure 3 This is a design diagram of the interaction process between the terminal device side and the communication server of the present invention. DETAILED DESCRIPTION

[0039] The following will clearly and completely describe the technical solutions in the embodiments of the present invention in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of the present invention.

[0040] The purpose of the present invention is to provide an interactive system and method based on UDP and Modbus-TCP, so as to achieve unlimited number of devices that can be connected, utilize the Modbus-TCP protocol architecture, and ensure that messages are not lost.

[0041] In order to make the above-mentioned objects, features and advantages of the present invention more obvious and easy to understand, the present invention is further described in detail below with reference to the accompanying drawings and specific embodiments.

[0042] Figure 1 This is the overall architecture diagram of the interactive system based on UDP and Modbus-TCP of the present invention. Figure 1 The interactive system based on UDP and Modbus-TCP includes a communication server 101 and multiple terminal devices 102 connected to the communication server 101.

[0043] The communication message format between the communication server 101 and each terminal device 102 adopts the Modbus-TCP protocol framework; the communication network link layer between the communication server 101 and each terminal device 102 adopts the UDP mode.

[0044] For each terminal device 102:

[0045] After the communication server 101 is started, it sends a request message with a transaction identifier of zero to the terminal device 102 in UDP mode.

[0046] After the terminal device 102 starts running, the terminal device 102 clears the cache. After the terminal device 102 receives the request message with the transaction processing identifier of zero in UDP mode, it enters the normal communication process and returns the status message with the transaction processing identifier of zero to the communication server 101 in UDP mode.

[0047] After the communication server 101 receives a status message with a transaction processing identifier of zero using the UDP mode, the communication server 101 enters a normal communication process, and the communication server 101 sends a request message with a non-zero transaction processing identifier to the terminal device 102 using the UDP mode; if the communication server 101 receives a response message with the non-zero transaction processing identifier returned by the terminal device 102 using the UDP mode using the UDP mode, the communication server 101 determines that the message is not lost, and when the communication server 101 sends a request message to the terminal device 102 again using the UDP mode, the request message sent again is a request message with the non-zero transaction processing identifier plus 1; if the communication server 101 does not receive a response message with the non-zero transaction processing identifier returned by the terminal device 102 using the UDP mode using the UDP mode, the communication server 101 determines that the message is lost, and when the communication server 101 sends a request message to the terminal device 102 again using the UDP mode, the request message sent again is the request message with the non-zero transaction processing identifier sent by the communication server 101 to the terminal device 102 last time using the UDP mode.

[0048] Communication server 101 is the initiator of communication interactions and the center of data collection. Communication server 101 is used to collect various data from on-site terminal devices. Terminal devices 102 are the actual collection devices installed on-site. Terminal devices 102 are used to complete the raw data collection, calculation, and processing of the monitoring locations under their jurisdiction.

[0049] Figure 2 The flowchart of the interactive method based on UDP and Modbus-TCP of the present invention is shown. Based on the interactive system based on UDP and Modbus-TCP, the present invention also provides an interactive method based on UDP and Modbus-TCP, such as Figure 2 As shown, the interactive method based on UDP and Modbus-TCP is applied to the interactive system based on UDP and Modbus-TCP; the interactive method based on UDP and Modbus-TCP includes the following steps:

[0050] Step S1: The communication server starts running and uses UDP mode to send a request message with a transaction identifier of zero to the terminal device.

[0051] Step S2: The terminal device starts running, clears the cache, and enters the normal communication process after receiving the request message with the transaction processing identifier of zero in UDP mode, and returns the status message with the transaction processing identifier of zero to the communication server in UDP mode.

[0052] Step S3: After the communication server receives the status message with the transaction identifier being zero in UDP mode, the communication server enters the normal communication process.

[0053] Step S4: The communication server uses the UDP mode to send a request message with a non-zero transaction processing identifier to the terminal device; if the communication server uses the UDP mode to receive a response message with the non-zero transaction processing identifier returned by the terminal device using the UDP mode, the communication server determines that the message is not lost, and when the communication server uses the UDP mode to send a request message to the terminal device again, the request message sent again is a request message with the non-zero transaction processing identifier plus 1; if the communication server uses the UDP mode to not receive a response message with the non-zero transaction processing identifier returned by the terminal device using the UDP mode, the communication server determines that the message is lost, and when the communication server uses the UDP mode to send a request message to the terminal device again, the request message sent again is the request message with the non-zero transaction processing identifier sent by the communication server to the terminal device last time using the UDP mode.

[0054] Specifically, step S4 includes:

[0055] Step S41: The communication server sends a request message with a transaction identifier of i to the terminal device in UDP mode; i is a positive integer, 1≤i≤65535; the initial value of i is 1;

[0056] Step S42: The terminal device determines whether a request message with a transaction identifier of i is received in UDP mode;

[0057] If the terminal device receives the request message with the transaction identifier i in the UDP mode, step S43 is executed: the terminal device sends a response message with the transaction identifier i to the communication server in the UDP mode;

[0058] Step S44: The communication server determines whether a response message with a transaction identifier of i is received in UDP mode;

[0059] If the communication server receives a response message with a transaction identifier of i in UDP mode, step S45 is executed: determining whether i reaches 65535;

[0060] If i does not reach 65535, the communication server sets i=i+1 and returns to step S41;

[0061] If i reaches 65535, the communication server sets i=1 and returns to step S41;

[0062] If the communication server does not receive a response message with the transaction identifier i in UDP mode, it returns to step S41;

[0063] If the terminal device does not receive the request message with the transaction identifier i in UDP mode, it returns to step S41.

[0064] After the communication server sends a request message with a transaction processing identifier of i to the terminal device using the UDP mode, if the terminal device receives the request message with a transaction processing identifier of i using the UDP mode, the terminal device sends a response message with a transaction processing identifier of i to the communication server using the UDP mode, and at the same time, the terminal device caches the response message with a transaction processing identifier of i sent to the communication server this time. If the communication server does not receive the response message with a transaction processing identifier of i using the UDP mode, the request message with a transaction processing identifier of i is sent to the terminal device again. If the terminal device receives the same request message with a transaction processing identifier of i as the last time again using the UDP mode, the cached response message with a transaction processing identifier of i sent to the communication server last time is copied, and the copied response message with a transaction processing identifier of i sent to the communication server last time is sent to the communication server.

[0065] After the communication server sends a request message with a transaction processing identifier of i to the terminal device using the UDP mode, if the communication server does not receive a response message with a transaction processing identifier of i for more than three consecutive times using the UDP mode, the communication server sends a request message with a transaction processing identifier of zero to the terminal device using the UDP mode. After the terminal device receives the request message with a transaction processing identifier of zero using the UDP mode, the terminal device clears the cache and enters the normal communication process, and returns a status message with a transaction processing identifier of zero to the communication server using the UDP mode. After the communication server receives the status message with a transaction processing identifier of zero using the UDP mode, the communication server enters the normal communication process.

[0066] After the communication server starts running, it uses UDP mode to send a request message with a transaction processing identifier of zero to the terminal device, and also sends a terminal device cache clearing instruction to the terminal device. After the terminal device receives the terminal device cache clearing instruction, the terminal device clears the cache.

[0067] For each terminal device in the interactive system based on UDP and Modbus-TCP of the present invention, the above-mentioned interactive method based on UDP and Modbus-TCP is used to implement interaction with the communication server.

[0068] The technical solution of the present invention is described below with a specific embodiment:

[0069] Figure 3The interactive process design diagram of the terminal device side and the communication server of the present invention is as follows: Figure 3 As shown, the present invention is based on the UDP mode Modbus-TCP protocol to prevent message loss interaction method solution is as follows:

[0070] Terminal equipment side (terminal equipment refers to the collection equipment actually installed on site, responsible for completing the original data collection, calculation and processing of the monitoring locations under its jurisdiction):

[0071] Step 1: Start the software, clear the cache command identifier, and proceed to step 2.

[0072] Step 2: Check whether a valid request command message is received. If yes, proceed to step 3. If no, proceed to step 2.

[0073] Step 3: Check whether the terminal device has entered the normal communication process. If yes, proceed to step 4; if no, proceed to step 8.

[0074] Step 4: Is the identifier value equal to 0? If yes, go to step 9; if no, go to step 5.

[0075] Step 5: Check whether the command identifier is consistent with the command identifier of the last interactive message. If not, proceed to step 6. If yes, proceed to step 7.

[0076] Step 6: Generate a response message according to the command request, copy the backup response message, copy and save the command identifier, send the command message, and go to step 2.

[0077] Step 7: Send the copy message and go to step 2.

[0078] Step 8: Is the command identifier of the received request message 0? If yes, go to step 9; if no, go to step 2.

[0079] Step 9: Respond to the command message, clear the cached command identifier, and go to step 2.

[0080] Communication server (communication server refers to the initiator of communication interaction and the center of data collection. The communication server collects various data from on-site terminal devices):

[0081] Step 1: Start the software, clear the command identifier, and proceed to step 2.

[0082] Step 2: Send a command message with a command identifier of 0, wait for the terminal to respond, and go to step 3.

[0083] Step 3: Check whether the terminal responds correctly. If yes, proceed to step 4. If no, proceed to step 2.

[0084] Step 4: Add 1 to the command identifier (if 1 plus 1 equals 0, add 1 again), send the command message, and go to step 5.

[0085] Step 5: Check whether the terminal device responds correctly. If yes, proceed to step 4; if no, proceed to step 6.

[0086] Step 6: Send the command message without changing the command identifier and proceed to step 7.

[0087] Step 7: Check whether the terminal device responds correctly. If yes, proceed to step 4. If no, proceed to step 8.

[0088] Step 8: If the terminal device fails to answer correctly more than 3 times, go to step 2 if it is yes, or go to step 6 if it is no.

[0089] The following describes the design of the interaction process between the terminal device side and the communication server of the present invention:

[0090] Figure 3 The interaction process design shown mainly hopes to solve three problems: the first is the problem of loss and retransmission during the message interaction process, the second is to simplify the confirmation steps during the message interaction process, and the third is to solve the problem of insufficient number of TCP connection ports in the Ethernet chip used.

[0091] The communication message format adopts the Modus-TCP protocol framework, and the communication network link layer adopts the UDP mode to solve the problem of insufficient number of TCP connection ports of the Ethernet chip used.

[0092] The above problem is solved by using the transaction identifier (identifier for short, the first two bytes of the message) count value, and the agreement is as follows:

[0093] When the terminal device starts running, the identifier is cleared. When the identifier contained in the received request message is zero, it enters the normal communication process (i.e., resets the link function and responds to the corresponding status information). If it does not enter the normal communication process, it will not respond to other identifier situations.

[0094] The terminal device needs to store the received identifier value. When the identifier contained in the received request command is consistent with the identifier value stored in itself, it means that the message is lost and the last response message is resent. Otherwise, a new response message is organized and sent.

[0095] When the communication server starts running, it performs a link reset (a request message with an identifier of zero) on each terminal device. After the terminal device responds correctly, the communication server begins the normal communication process.

[0096] After the communication server enters the normal communication process, the identifier of each new request message is automatically increased by one (the identifier is automatically skipped if it is equal to zero). If an error is found in the response message or no response message is received, the identifier is unchanged and another request is made.

[0097] After the communication server enters the normal communication process, if the terminal device does not respond normally for more than 3 times, the communication server starts to send link resets until it responds correctly.

[0098] Among them, automatic skipping when the identifier is equal to zero means that when the identifier (the first two bytes of the message) is 65535, the identifier plus 1 equals 0, and at this time 0 is skipped and the cycle starts directly from 1 and then the identifier is 1 to 65535.

[0099] Compared with the prior art, the advantages of the present invention are as follows:

[0100] 1. Use UDP to implement the Modbus-TCP protocol and achieve the effect of no loss or duplication of messages based on TCP reliable connection.

[0101] 2. It solves the limitation of insufficient number of TCP communication ports that makes it impossible to use conventional devices to implement Modbus-TCP communication, and gives full play to the advantages of Ethernet and Modbus-TCP technology.

[0102] 3. The message index information in the Modbus-TCP protocol is used to implement the confirmation and retransmission mechanism of UDP communication messages, which improves the communication interaction efficiency and ensures the reliability of data interaction.

[0103] 4. Solved the problem of how to make use of the unlimited number of connections, utilize the Modbus-TCP protocol architecture and ensure that messages are not lost.

[0104] For example, one possible alternative to the present invention is to use hardware devices such as Ethernet chipsets with more TCP connection port capabilities. Another alternative is to use UDP mode for data communication and add a message reception confirmation mechanism to the application layer message exchange. This means that regardless of which party initiates the communication, the communication is considered complete only when the other party receives the confirmation message. If the other party does not receive the confirmation message, multiple retries are performed. This increases the number of confirmation messages sent and received in both communication directions, reducing communication efficiency.

[0105] The various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the various embodiments can be referenced to each other.

[0106] This document uses specific examples to illustrate the principles and implementation methods of the present invention. The above examples are only intended to help understand the method and core concept of the present invention. At the same time, those skilled in the art will find that the specific implementation methods and application scopes may vary based on the concept of the present invention. In summary, the contents of this specification should not be construed as limiting the present invention.

Claims

1. An interactive system based on UDP and Modbus-TCP, characterized in that: The system includes a communication server and a plurality of terminal devices connected to the communication server; The communication message format between the communication server and each of the terminal devices adopts the Modbus-TCP protocol framework; the communication network link layer between the communication server and each of the terminal devices adopts the UDP mode; After the communication server is started, it sends a request message with a transaction identifier of zero to the terminal device in UDP mode; After the terminal device starts running, the terminal device clears the cache, and after the terminal device receives the request message with the transaction identifier of zero in the UDP mode, it enters the normal communication process and returns a status message with the transaction identifier of zero to the communication server in the UDP mode; After the communication server receives a status message with a transaction identifier of zero in UDP mode, the communication server enters a normal communication process, and sends a request message with a non-zero transaction identifier to the terminal device in UDP mode; If the communication server receives a response message with the non-zero transaction identifier returned by the terminal device in UDP mode in UDP mode, the communication server determines that the message is not lost, and when the communication server sends a request message to the terminal device again in UDP mode, the request message sent again is a request message with the non-zero transaction identifier plus 1; If the communication server adopts UDP mode but does not receive the response message with the non-zero transaction processing identifier returned by the terminal device adopting UDP mode, the communication server determines that the message is lost. When the communication server adopts UDP mode to send a request message to the terminal device again, the request message sent again is the request message with the non-zero transaction processing identifier sent by the communication server to the terminal device last time adopting UDP mode.

2. The interactive system based on UDP and Modbus-TCP according to claim 1, characterized in that: The terminal device is a collection device actually installed on site; the terminal device is used to complete the original data collection, calculation and processing of the monitoring location under its jurisdiction.

3. The interactive system based on UDP and Modbus-TCP according to claim 1, characterized in that: The communication server is the initiator of communication interaction and the center of data collection; the communication server is used to collect various types of data from on-site terminal devices.

4. An interactive method based on UDP and Modbus-TCP, characterized in that, The method is applied to the system according to any one of claims 1 to 3, and the method comprises: Step S1: The communication server starts running and sends a request message with a transaction identifier of zero to the terminal device in UDP mode; Step S2: The terminal device starts running, clears the cache, and after receiving the request message with the transaction identifier of zero in UDP mode, the terminal device enters the normal communication process and returns a status message with the transaction identifier of zero to the communication server in UDP mode; Step S3: After the communication server receives the status message with the transaction identifier of zero in the UDP mode, the communication server enters the normal communication process; Step S4: The communication server uses the UDP mode to send a request message with a non-zero transaction processing identifier to the terminal device; if the communication server uses the UDP mode to receive a response message with the non-zero transaction processing identifier returned by the terminal device using the UDP mode, the communication server determines that the message is not lost, and when the communication server uses the UDP mode to send a request message to the terminal device again, the request message sent again is a request message with the non-zero transaction processing identifier plus 1; if the communication server uses the UDP mode to not receive a response message with the non-zero transaction processing identifier returned by the terminal device using the UDP mode, the communication server determines that the message is lost, and when the communication server uses the UDP mode to send a request message to the terminal device again, the request message sent again is the request message with the non-zero transaction processing identifier sent by the communication server to the terminal device last time using the UDP mode.

5. The interactive method based on UDP and Modbus-TCP according to claim 4, characterized in that: The step S4 specifically includes: Step S41: The communication server sends a request message with a transaction identifier of i to the terminal device in UDP mode; i is a positive integer, 1≤i≤65535; the initial value of i is 1; Step S42: The terminal device determines whether a request message with a transaction identifier of i is received in UDP mode; If the terminal device receives the request message with the transaction identifier i in the UDP mode, step S43 is executed: the terminal device sends a response message with the transaction identifier i to the communication server in the UDP mode; Step S44: The communication server determines whether a response message with a transaction identifier of i is received in UDP mode; If the communication server receives a response message with a transaction identifier of i in UDP mode, step S45 is executed: determining whether i reaches 65535; If i does not reach 65535, the communication server sets i=i+1 and returns to step S41; If i reaches 65535, the communication server sets i=1 and returns to step S41; If the communication server does not receive a response message with the transaction identifier i in UDP mode, it returns to step S41; If the terminal device does not receive the request message with the transaction identifier i in UDP mode, it returns to step S41.

6. The interactive method based on UDP and Modbus-TCP according to claim 5, characterized in that: After the communication server sends a request message with a transaction processing identifier of i to the terminal device using the UDP mode, if the terminal device receives the request message with a transaction processing identifier of i using the UDP mode, the terminal device sends a response message with a transaction processing identifier of i to the communication server using the UDP mode, and at the same time, the terminal device caches the response message with a transaction processing identifier of i sent to the communication server this time. If the communication server does not receive the response message with a transaction processing identifier of i using the UDP mode, the request message with a transaction processing identifier of i is sent to the terminal device again. If the terminal device receives the same request message with a transaction processing identifier of i as the last time again using the UDP mode, the cached response message with a transaction processing identifier of i sent to the communication server last time is copied, and the copied response message with a transaction processing identifier of i sent to the communication server last time is sent to the communication server.

7. The interactive method based on UDP and Modbus-TCP according to claim 6, characterized in that: After the communication server sends a request message with a transaction processing identifier of i to the terminal device using the UDP mode, if the communication server does not receive a response message with a transaction processing identifier of i for more than three consecutive times using the UDP mode, the communication server sends a request message with a transaction processing identifier of zero to the terminal device using the UDP mode. After the terminal device receives the request message with a transaction processing identifier of zero using the UDP mode, the terminal device clears the cache and enters the normal communication process, and returns a status message with a transaction processing identifier of zero to the communication server using the UDP mode. After the communication server receives the status message with a transaction processing identifier of zero using the UDP mode, the communication server enters the normal communication process.

8. The interactive method based on UDP and Modbus-TCP according to claim 4, characterized in that: After the communication server starts running, it uses UDP mode to send a request message with a transaction processing identifier of zero to the terminal device, and also sends a terminal device cache clearing instruction to the terminal device. After the terminal device receives the terminal device cache clearing instruction, the terminal device clears the cache.

Citation Information

Patent Citations

  • Modbus TCP protocol safety enhancement method and system

    CN113472520A

  • Smart modbus protocol device.

    IN3303MUM2015A