Data sending method, data response method, device and storage medium
By grouping and arranging access data messages, the problem of low data transmission performance in the Modbus protocol is solved, and more efficient data transmission and processing are achieved.
Patent Information
- Application Number
- CN202211526184.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-11-28
- Publication Date
- 2024-10-22
- Estimated Expiration
- 2042-11-28
AI Technical Summary
The existing Modbus protocol has the problem of low data transmission performance in data transmission between industrial equipment, mainly because it can only send continuous access addresses, resulting in the existence of invalid access addresses and reducing data transmission efficiency.
By obtaining several sets of variable access data, the data is packaged into a request data message, and the stored data is arranged according to the order of the access addresses during the transmission process to avoid invalid access addresses, and the stored data is directly extracted from the response data message to obtain the access result.
It improves data transmission performance, reduces redundant calculation processes, and improves the timely reception and processing capabilities of control information between industrial equipment.
Smart Images

Figure CN115883461B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of data exchange, and in particular to a data sending method, a data response method, a device and a storage medium. Background Art
[0002] With the rapid development of industrial equipment, the demand for industrial protocols used to interconnect to form industrial communication systems is also increasing. The existing mainstream industrial protocol is to establish communication connections between multiple industrial devices through the Modbus protocol to obtain control information between industrial devices.
[0003] However, as the amount of control information that needs to be transmitted between industrial equipment increases, users have found in the process of using the Modbus protocol to send control information between industrial equipment and receive reply information based on the control information that because the Modbus protocol can only send request data messages with continuous access addresses for the access addresses of the variables to be accessed during the packetization of request data messages based on control signals, which results in that in the process of unpacking the request data messages, the corresponding access addresses and register quantities can only be calculated based on the addresses of the variables to be accessed, so as to eliminate invalid access addresses that do not appear in the control signal but are required to ensure the continuity of the access addresses. The inconvenience in this process has seriously reduced the data transmission performance in the current situation where the amount of control information is increasing, and is very unfavorable for users to receive and process the control information between industrial equipment in a timely manner. Summary of the invention
[0004] The main purpose of the present invention is to provide a data sending method, a data response method, a device and a storage medium, aiming to solve the technical problem of low data transmission performance when communicating between industrial devices through the existing Modbus protocol.
[0005] To achieve the above object, the present invention provides a data sending method, which is applied to a request initiator, and comprises the following steps:
[0006] Acquire several groups of variable access data, wherein one group of the variable access data includes an access address of a variable to be accessed;
[0007] Packaging the variable access data to obtain a request data message;
[0008] The request data message is sent to a request responding end that establishes a communication connection with the request initiating end, so that the request responding end reads the storage area indicated by the access address, and obtains a response data message according to each stored data group packet read, wherein in the response data message, each of the stored data read is arranged according to the order of the access addresses corresponding to each other in the request data message;
[0009] After receiving the response data message, the stored data are combined according to the arrangement order of the stored data in the response data message to obtain access results corresponding to the variables to be accessed.
[0010] Optionally, the variable access data further includes a write variable value of the variable to be accessed, and the step of sending the request data message to the request responding end that establishes a communication connection with the request initiating end includes:
[0011] The request data message is sent to the request response end that establishes a communication connection with the request initiator, so that the request response end uses the write variable value to write the storage area indicated by the corresponding access address, and then the request response end reads the storage area indicated by the access address, and obtains the response data message according to each of the stored data packets read.
[0012] Optionally, before the step of sending the request data message to the request responding end that establishes a communication connection with the request initiating end, the method further includes:
[0013] Sending a verification message including a first data version to the request response end, so that the request response end compares the first data version with the second data version in the request response end, and returning a verification reply message indicating that the verification has passed when the comparison is consistent, wherein the first data version and the second data version are used to indicate the access address corresponding to the variable to be accessed;
[0014] If the verification reply message indicating that the verification has passed is received, the step of sending the request data message to the request responding end that has established a communication connection with the request initiating end is performed.
[0015] Optionally, the step of packaging the variable access data to obtain a request data message includes:
[0016] Arranging the variable access data in the order of the size of the access address, and grouping the arranged variable access data to obtain the request data message;
[0017] The step of combining the stored data according to the arrangement order of the stored data in the response data message to obtain the access result corresponding to each access variable comprises:
[0018] The variables to be accessed are sorted in order of the size of the corresponding access addresses, and the stored data combinations are obtained from the response data message in the sorted order according to the length of each variable to be accessed to obtain the access results corresponding to each variable to be accessed.
[0019] The present invention also provides a data response method, which is applied to a request response end and comprises the following steps:
[0020] Receiving a request data message sent by a request initiator, wherein the request data message is obtained by the request initiator by packaging a plurality of groups of variable access data, wherein a group of the variable access data includes an access address of a variable to be accessed;
[0021] Reading the storage area indicated by the access address in the request data message, and obtaining a response data message according to each stored data group packet read, wherein in the response data message, each of the stored data read is arranged according to the order of the corresponding access addresses in the request data message;
[0022] The response data message is sent to the request initiator that establishes a communication connection with the request responder.
[0023] Optionally, the variable access data further includes a write variable value of the variable to be accessed, and before the step of reading the storage area indicated by the access address in the request data message, the step further includes:
[0024] The write variable value is used to write into the storage area indicated by the corresponding access address.
[0025] Optionally, before the step of receiving the request data message sent by the request initiator, the step further includes:
[0026] Receiving a verification message including a first data version sent by the request initiator;
[0027] The first data version is compared with the second data version in the request response end, and when the comparison is consistent, a verification reply message representing the passed verification is returned to the request initiating end, so that the request initiating end can send the request data message to the request response end according to the verification reply message representing the passed verification, wherein the first data version and the second data version are used to indicate the access address corresponding to the variable to be accessed.
[0028] Optionally, the step of obtaining a response data message according to each stored data group package read includes:
[0029] Obtaining a data packet header according to the request data message;
[0030] The data packet header and a plurality of the stored data arranged in the order of the access addresses in the request data message are grouped together to obtain the response data message.
[0031] In addition, to achieve the above-mentioned purpose, the present invention also provides a data exchange device, including a memory, a processor, and a data exchange program stored in the memory and executable on the processor, wherein the processor implements the steps of the above-mentioned data sending method and data response method when executing the data exchange program.
[0032] In addition, to achieve the above-mentioned purpose, the present invention also provides a computer-readable storage medium, on which a data exchange program is stored, and when the data exchange program is executed by a processor, the steps of the above-mentioned data sending method and data response method are implemented.
[0033] The present invention obtains several groups of variable access data, wherein one group of variable access data includes an access address of a variable to be accessed; groups the variable access data into packets to obtain a request data message, wherein the access address in the obtained variable access data is the access address of the variable to be accessed, and there is no access address that is not the variable to be accessed, that is, there is no access address that is not the access address to be accessed by the variable to be accessed, thereby avoiding the existing situation that multiple invalid access addresses exist only based on continuous access addresses and thus causing low data transmission performance, and at the same time, sends the request data message to the request response end that establishes a communication connection with the request initiator end, and by synchronizing the data sent between the request initiator end and the request response end. According to the limitation of the data order in the message, unnecessary calculation process is avoided. After receiving the response data message returned by the request response end based on the request data message, the stored data are combined according to the arrangement order of the stored data in the response data message to obtain the access results corresponding to the variables to be accessed. Because the stored data in the response data message are arranged according to the order of their corresponding access addresses in the request data message, as long as the stored data are extracted in sequence according to the order in the response data message, according to the variables to be accessed corresponding to the access addresses corresponding to the stored data, the stored data corresponding to the variables to be accessed can be directly obtained without going through the calculation process, thereby further improving the data transmission performance. BRIEF DESCRIPTION OF THE DRAWINGS
[0034] Figure 1 It is a schematic diagram of the terminal structure of the hardware operating environment involved in the embodiment of the present invention;
[0035] Figure 2 This is a flow chart of a first embodiment of a data sending method of the present invention;
[0036] Figure 3 It is a flow chart of the second embodiment of the data response method of the present invention;
[0037] Figure 4 Schematic diagram of the assumed correspondence between the second variable and the access address.
[0038] The purpose, features and advantages of the present invention will be further described with reference to the accompanying drawings in conjunction with the embodiments. DETAILED DESCRIPTION
[0039] It should be understood that the specific embodiments described herein are only used to explain the present invention, and are not used to limit the present invention.
[0040] like Figure 1 As shown, Figure 1 It is a schematic diagram of the terminal structure of the hardware operating environment involved in the embodiment of the present invention.
[0041] The application carrier of the data sending method and the data response method of the embodiment of the present invention is a data exchange device, such as Figure 1 As shown, the data exchange device may include: a processor 1001, such as a CPU, a network interface 1004, a user interface 1003, a memory 1005, and a communication bus 1002. Among them, the communication bus 1002 is used to realize the connection and communication between these components. The user interface 1003 may include a display area (Display), an input unit such as a keyboard (Keyboard), and the optional user interface 1003 may also include a standard wired interface and a wireless interface. The network interface 1004 may optionally include a standard wired interface and a wireless interface (such as a WI-FI interface). The memory 1005 may be a high-speed RAM memory, or a stable memory (non-volatile memory), such as a disk memory. The memory 1005 may also be a storage device independent of the aforementioned processor 1001.
[0042] Optionally, the data exchange device may also include a camera, an RF (Radio Frequency) circuit, a sensor, an audio circuit, a WiFi module, and the like. Among them, sensors include light sensors, motion sensors, and other sensors. Specifically, the light sensor may include an ambient light sensor and a proximity sensor, wherein the ambient light sensor may adjust the brightness of the display screen according to the brightness of the ambient light, and the proximity sensor may turn off the display screen and / or backlight when the mobile terminal is moved to the ear. As a type of motion sensor, the gravity acceleration sensor can detect the magnitude of acceleration in each direction (generally three axes), and can detect the magnitude and direction of gravity when stationary. It can be used for applications that identify the posture of the mobile terminal (such as horizontal and vertical screen switching, related games, magnetometer posture calibration), vibration recognition related functions (such as pedometer, tapping), etc.; of course, the mobile terminal can also be equipped with other sensors such as gyroscopes, barometers, hygrometers, thermometers, infrared sensors, etc., which will not be repeated here.
[0043] Those skilled in the art will understand that Figure 1 The data exchange device structure shown in the figure does not constitute a limitation on the data exchange device, and may include more or less components than shown in the figure, or combine certain components, or arrange the components differently.
[0044] like Figure 1 As shown, the memory 1005 as a computer storage medium may include an operating system, a network communication module, a user interface module, and a data exchange program.
[0045] exist Figure 1 In the terminal shown, the network interface 1004 is mainly used to connect to the backend server and perform data communication with the backend server; the user interface 1003 is mainly used to connect to the client (user end) and perform data communication with the client; and the processor 1001 can be used to call the data exchange program stored in the memory 1005 and perform the following operations:
[0046] Acquire several groups of variable access data, wherein one group of variable access data includes an access address of a variable to be accessed;
[0047] Packaging the variable access data to obtain a request data message;
[0048] Sending the request data message to the request responding end that establishes a communication connection with the request initiating end;
[0049] After receiving the response data message returned by the request response end based on the request data message, the storage data are combined according to the arrangement order of the storage data in the response data message to obtain access results corresponding to the variables to be accessed.
[0050] Further, the processor 1001 may call the data exchange program stored in the memory 1005, and further perform the following operations:
[0051] The variable access data also includes a write variable value of the variable to be accessed, and the step of sending the request data message to the request response end that establishes a communication connection with the request initiator includes: sending the request data message to the request response end that establishes a communication connection with the request initiator, so that the request response end uses the write variable value to write the storage area indicated by the corresponding access address, and then the request response end reads the storage area indicated by the access address, and obtains the response data message according to each of the read storage data packets.
[0052] Further, the processor 1001 may call the data exchange program stored in the memory 1005, and further perform the following operations:
[0053] Before the step of sending the request data message to the request responder end that has established a communication connection with the request initiator end, sending a verification message including a first data version to the request responder end, so that the request responder end compares the first data version with the second data version in the request responder end, and returns a verification reply message indicating that the verification has passed when the comparison is consistent, wherein the first data version and the second data version are used to indicate the access address corresponding to the variable to be accessed;
[0054] If the verification reply message indicating that the verification has passed is received, the step of sending the request data message to the request responding end that has established a communication connection with the request initiating end is performed.
[0055] Further, the processor 1001 may call the data exchange program stored in the memory 1005, and further perform the following operations:
[0056] The step of packaging the variable access data to obtain the request data message includes: arranging the variable access data in the order of the size of the access address, and packaging the arranged variable access data to obtain the request data message;
[0057] The step of combining the stored data according to the arrangement order of the stored data in the response data message to obtain the access result corresponding to each access variable comprises:
[0058] The variables to be accessed are sorted in order of the size of the corresponding access addresses, and the stored data combinations are obtained from the response data message in the sorted order according to the length of each variable to be accessed to obtain the access results corresponding to each variable to be accessed.
[0059] Further, the processor 1001 may call the data exchange program stored in the memory 1005, and further perform the following operations:
[0060] Receiving a request data message sent by a request initiator, wherein the request data message is obtained by the request initiator by packaging a plurality of groups of variable access data, wherein a group of the variable access data includes an access address of a variable to be accessed;
[0061] Reading the storage area indicated by the access address in the request data message, and obtaining a response data message according to each stored data group packet read, wherein in the response data message, each of the stored data read is arranged according to the order of the corresponding access addresses in the request data message;
[0062] The response data message is sent to the request initiator that establishes a communication connection with the request responder.
[0063] Further, the processor 1001 may call the data exchange program stored in the memory 1005, and further perform the following operations:
[0064] The variable access data also includes a write variable value of the variable to be accessed. Before the step of reading the storage area indicated by the access address in the request data message, the write variable value is used to write the storage area indicated by the corresponding access address.
[0065] Further, the processor 1001 may call the data exchange program stored in the memory 1005, and further perform the following operations:
[0066] Before the step of receiving the request data message sent by the request initiator, receiving a verification message including the first data version sent by the request initiator;
[0067] The first data version is compared with the second data version in the request response end, and when the comparison is consistent, a verification reply message representing the passed verification is returned to the request initiating end, so that the request initiating end can send the request data message to the request response end according to the verification reply message representing the passed verification, wherein the first data version and the second data version are used to indicate the access address corresponding to the variable to be accessed.
[0068] Further, the processor 1001 may call the data exchange program stored in the memory 1005, and further perform the following operations:
[0069] The step of obtaining a response data message according to each stored data packet read includes: obtaining a data packet header according to the request data message;
[0070] The data packet header and a plurality of the stored data arranged in the order of the access addresses in the request data message are grouped together to obtain the response data message.
[0071] like Figure 2 As shown, Figure 2 1 is a flow chart of a first embodiment of a data sending method of the present invention. In this embodiment, the data sending method is applied to a request initiator, and the data sending method includes the following steps:
[0072] Step S10, obtaining several groups of variable access data, wherein a group of the variable access data includes an access address of a variable to be accessed.
[0073] Step S20, packaging the variable access data to obtain a request data message.
[0074] Step S30: sending the request data message to the request responding end that has established a communication connection with the request initiating end.
[0075] Specifically, the conventional industrial protocol, that is, the step flow of the request initiator in the Modbus protocol is first explained. In the Modbus protocol, when the request initiator receives the input request access command, it obtains and packages the access address and the number of access bytes of the variable to be accessed in the request access command. The Modbus protocol package has a characteristic, that is, the access address in the request data message composed by the Modbus protocol must be continuous, because the Modbus protocol has a verification process to verify whether the data corresponding to the access address has continuity. Therefore, if you only want to form a request data message, the access address in the request data message must be continuous. If you do not want it to be continuous, you can only divide it into multiple request data messages. For example, at this time, the access addresses corresponding to the two variables to be accessed in the request access command are access address 0 and access address 99 respectively. ① If the request initiator based on the Modbus protocol wants to form a request data message, the access address of the request data message composed at this time is 0, and the corresponding number of access bytes is 20. 0, which seems to contain the storage data corresponding to 100 access addresses, but because the access request command only requests access addresses 0 and 99, in this request data message, the truly valid access addresses are only the access addresses 0 and 99, and the remaining access addresses are invalid data. Therefore, the data transmission efficiency of this request data message is only 2%. The transmission of invalid data will waste a lot of communication resources and the data transmission performance is low; ② If the request initiator based on the Modbus protocol does not need to be continuous, then based on the two discontinuous access addresses of 0 and 99, the request initiator at this time will form a request data message with an access address of 0 and an access byte number of 2, and another request data message with an access address of 99 and an access byte number of 2. Although it avoids the problem of multiple invalid data when sending a data message, dividing a request access command into two request data messages for transmission still has the problem of low data transmission performance. Therefore, this situation obviously cannot meet the existing situation of increasing data transmission quantity.
[0076] Based on the above situation, this embodiment proposes a data transmission method, which is mainly used for SCADA (Supervisory Control And Data Acquisition) software and industrial equipment to formulate a unified data frame format when variable data is accessed at high speed. The variables to be accessed at the request response end adopt an absolute address access mode, that is, the variables to be accessed at the request response end can directly correspond to the access address of the request initiator. In addition, the request initiator and the request response end in this embodiment are arranged at the application layer, and the transmission of the request data message and the response data message is realized through the transport layer, wherein the transport layer can use TCP (Transmission Control Protocol) or a shared memory method.
[0077] Specifically, when the request initiator in this embodiment receives the request access command uploaded by the user, it directly extracts the access address corresponding to each variable to be accessed and the access byte number corresponding to each variable to be accessed in the request access command, and then forms a group of variable access data according to the combination relationship of the access address corresponding to the variable to be accessed + the access byte number corresponding to the variable to be accessed. After the combination is completed, several groups of variable access data will be obtained, and the several groups of variable access data are directly packaged to obtain request data messages. For example, at this time, the request initiator receives the access request command, and the access address 0 and the access byte number corresponding to the variable to be accessed are 0 and 99, respectively. Then, after receiving the access request command, the request initiator directly extracts the access address 0 and the access byte number corresponding to it as 2, and the access address 99 and the access byte number corresponding to it as 2 in the access request command (in this embodiment, one variable to be accessed corresponds to one access address). , and the variable to be accessed occupies only one register, the number of bytes of which is 2 for illustration), therefore, at this time, the request data message is composed of variable access data (0) + variable access data (99), wherein variable access data (0) is access address (0) + number of access bytes (2), and variable access data (99) is access address (99) + number of access bytes (2), so that when the request access command contains discontinuous access addresses, this embodiment can generate and send a single request data message corresponding to the request access command without adding any invalid access addresses and without splitting it into multiple request data messages, and because the access addresses contained in the request data message are all valid data (i.e., the access addresses of the variables to be accessed in the request access command), there is no invalid data (i.e., not the access addresses of the variables to be accessed in the request access command) in the request data message, which wastes a lot of communication resources and causes low data transmission performance.
[0078] It should be noted that the reason why the present embodiment can place discontinuous access addresses directly in a request data message is that the variable to be accessed in the request response end that unpacks the request data message adopts an absolute address access mode, that is, the variable to be accessed on the request response end has a corresponding access address to be accessed, and the access address is consistent with the access address corresponding to the variable to be accessed on the request initiating end contained in the request data message. In other words, based on the same access address, the variable to be accessed on the request response end can directly correspond to the address to be accessed in the request data message. Therefore, the present embodiment can realize that all discontinuous access addresses are placed in the same request data message.
[0079] Among them, after the access addresses in the request data message are exchanged to the request response end, their order does not change at all, that is, the order of the access addresses on the request initiator is the same as that on the request response end, so that when the subsequent request response end reads each storage data in the storage area indicated by the access address and assembles the response data message, each storage data can be arranged according to the order of its corresponding access address, so that after the request initiator receives the response data message and extracts its storage data, it can directly determine the corresponding access address according to the sequential position of the storage data in the response data message, and then determine the corresponding variable to be accessed. By combining the extracted storage data, the access results corresponding to each variable to be accessed can be obtained, avoiding unnecessary calculation or conversion processes and improving data communication efficiency.
[0080] Specifically, after obtaining the request data message through packet assembly, the request initiator sends the request data message to the request responder with which a communication connection has been established through the transport layer, so that the request responder responds to the request data message and obtains a response result.
[0081] Optionally, before the step of sending the request data message to the request responding end that establishes a communication connection with the request initiating end in step S30, the method further includes:
[0082] Step S301, sending a verification message including a first data version to the request response end, so that the request response end compares the first data version with the second data version in the request response end, and returns a verification reply message indicating that the verification has passed when the comparison is consistent, wherein the first data version and the second data version are used to indicate the access address corresponding to the variable to be accessed;
[0083] Step S302: If the verification reply message indicating that the verification has passed is received, the step of sending the request data message to the request responding end that has established a communication connection with the request initiating end is executed.
[0084] Specifically, before the request initiator composes a request data message and sends the request data message to the request responder, the request initiator will send a verification message to the request responder to determine whether the variable to be accessed on the request responseer and the access address of the variable to be accessed are consistent with the access address of the variable to be accessed contained in the request data message, thereby ensuring the absolute correspondence between the variable to be accessed on the request responseer and the access address on the request initiator.
[0085] The check message includes the data packet header in the request data message + the total length of the number of access bytes in the request data message + the data version. After receiving the check message, the request response end mainly checks the data version in the check message to determine whether the data version in the check message is consistent with the data version of the request response end. If they are consistent, it means that the access address to be accessed by the variable to be accessed on the request response end is consistent with the access address of the variable to be accessed in the request data message. At this time, the request response end will generate a check reply message indicating that the check has passed based on the consistent judgment result, for example, generate a check reply message of the data packet header + the total length in the check message + 1 (check data indicating that the check has passed), and send the check reply message to the request initiator, so that the request initiator performs the step of sending the request data message after receiving the check reply message indicating that the check has passed.
[0086] It should be noted that the first data version sent by the request initiator and the second data version on the request responder are the variable to be accessed and the access address to which the variable to be accessed corresponds, for example, refer to Table 1:
[0087] First data version Second data version A(2), B(4), C(6), D(8) A(2), B(4), C(6), D(8) A(2), B(4), C(6), D(8) A(1), B(3), C(5), D(7)
[0088] Assume that the first line in Table 1 is the first verification message initiated by the request initiator. According to the first data version and the second data version on the first line, the access address corresponding to the variable to be accessed and the variable to be accessed on the first data version sent by the request initiator is exactly the same as the access address corresponding to the variable to be accessed and the variable to be accessed on the second data version on the request responder, which means that the verification is passed; the second line is another verification message initiated by the request initiator. According to the first data version and the second data version on the second line, the access address corresponding to the variable to be accessed and the variable to be accessed on the first data version sent by the request initiator is inconsistent with the access address corresponding to the variable to be accessed and the variable to be accessed on the second data version on the request responder, which means that the verification fails. At this time, the request responder will generate a verification reply message indicating that the verification fails, or will not generate any verification reply message, so as to inform the request initiator that the variable to be accessed and the access address of the variable to be accessed included in the request initiator are inconsistent with the variable to be accessed and the address to be accessed on the request responder, so as to stop the request initiator from sending the request data message, and avoid the need for additional calculation and conversion processes because the access address is not the access address corresponding to the variable to be assigned.
[0089] Optionally, the variable access data in step S30 also includes a write variable value of the variable to be accessed, and the step of sending the request data message to the request responding end that establishes a communication connection with the request initiating end includes:
[0090] Step S303, sending the request data message to the request response end that establishes a communication connection with the request initiator, so that the request response end uses the write variable value to write the storage area indicated by the corresponding access address, and then the request response end reads the storage area indicated by the access address, and obtains the response data message according to each of the stored data packets read.
[0091] Specifically, the conventional industrial protocol, namely, the step flow of the request response end in the Modbus protocol is first explained. In the Modbus protocol, when the request response end receives the request data message sent by the request initiator and unpacks the request data message, it calculates the access address and the number of registers in the request data message based on the address of the variable on the request response end at this time, so as to screen the access address corresponding to the valid data and filter out the invalid access address and the number of registers. This results in a waste of unpacking resources and reduces the data transmission performance.
[0092] Based on this situation, it has been explained at the request initiator that in order to avoid the low data transmission performance and low communication efficiency caused by invalid access addresses or multiple request data messages, this embodiment extracts packets based on the access addresses of the variables to be accessed. Please refer to the above description for details and will not be repeated here.
[0093] In this implementation, after receiving the request data message sent by the request initiator, the request responder will unpack and assemble the request data message, specifically, obtain the variable access data in the request data message, so that the request responder can extract the access address corresponding to the variable to be accessed in the variable access data. Because it has been verified that the access address to be accessed by the variable to be accessed on the request responder can correspond to the access address of the variable to be accessed in the request data message, after obtaining the access address, the request responder will write the variable value of the variable to be accessed on the request initiator (the value on the data of the register associated with the access address) By using the write variable value to extract the value on the register corresponding to the corresponding access address, the extracted value is written into the storage area indicated by the access address to form storage data in the storage area, that is, after assigning a value to the storage area corresponding to the variable to be accessed on the request response end, the request response end reads the storage data in the assigned storage area, and can obtain the storage data sorted in the order of the access address. By directly packaging the storage data, the response data message can be obtained. Therefore, there is no additional communication resource overhead such as access to invalid data and calculation of address offset, which improves the unpacking efficiency and packaging speed of the request response end.
[0094] Specifically, assuming that the order of the addresses to be accessed on the request data message is: address to be accessed (1), address to be accessed (2), address to be accessed (3), address to be accessed (4) (where address to be accessed (1) is the address to be accessed of variable A, address to be accessed (2) is the address to be accessed of variable B, address to be accessed (3) is the address to be accessed of variable C, and address to be accessed (4) is the address to be accessed of variable D), the order of the variables to be accessed and the addresses to be accessed corresponding to the variables to be accessed on the request response end is: B (2), A (1), C (3), D (4). After receiving the request data message, because according to the request data message, The order of the variables to be accessed corresponding to the addresses to be accessed on the request response end is adjusted to: A(1), B(2), C(3), D(4), so as to correspond to the addresses to be accessed on the request initiator. After the request response end adjusts the order of the addresses to be accessed on the request response end according to the request data message, the request response end accesses the data of the register at the access address according to the corresponding access address of the variables to be accessed in the request data message, extracts the value stored in the register, and writes the extracted value into the storage indicated by its access address. In the storage area, before the storage area indicated by each access address on the request response end is written with a value, there is no storage data or old storage data on the storage area. After receiving the request response message, the value must be written or updated to the storage area to ensure the correctness of the storage data used by the subsequent request response end when assembling the package. For example, the storage data corresponding to the access address (1)(2)(3)(4) is ①, ②, ③, ④, so the storage data of the storage area indicated by the access address is ①, ②, ③, ④. At this time, the request response end reads the storage data on the storage area in sequence to obtain the storage data used to compose the response data message ①, ②, ③, ④, and the storage The data is arranged according to the order of the access addresses on the request response end, and the order of the access addresses on the request response end is arranged according to the order of the access addresses in the request data message. In this way, in the response data message, each read storage data is arranged according to the order of the corresponding access addresses in the request data message, which ensures the consistency and order of the data order exchanged between the request initiator and the request response end, so that the order of the stored data in the response data message can be directly matched with the variables to be accessed on the request initiator, so as to directly form the corresponding access result, avoid unnecessary calculation or conversion processes, and improve data communication efficiency.
[0095] In addition, if there is a variable to be accessed that occupies two registers, that is, 4 access bytes, then when the value of the register corresponding to the address to be accessed corresponding to the variable to be accessed is read according to the variable to be accessed, 2 access bytes will be read backward based on the register corresponding to the address to be accessed, that is, the value of one register will be read backward, refer to Figure 3 At this time, there are variables A to be accessed with an access byte number of 4 and variable B to be accessed with an access byte number of 2. Assuming that the access address corresponding to variable A to be accessed is 1, and the access address corresponding to variable B to be accessed is 3, after reading the value ① of the register corresponding to access address 1 corresponding to variable A to be accessed, due to the access byte number of 4 of variable A to be accessed, one more register will be read backward based on access address 1, that is, the register corresponding to access address 2 will be read with the value ②. Since variable B to be accessed only occupies 2 access bytes, it is only necessary to read the value ③ of the register corresponding to access address 3 corresponding to variable B to be accessed.
[0096] Step S40, after receiving the response data message returned by the request response end based on the request data message, combining the stored data according to the arrangement order of the stored data in the response data message to obtain access results corresponding to the variables to be accessed.
[0097] Specifically, when the request initiator receives the response data message returned by the request responder based on the request data message, it will read each stored data in sequence according to the arrangement order of each stored data in the response data message, because the access address corresponding to each stored data in the response data message corresponds to the order of the access addresses in the request data message, and the order of the access addresses in the request data message is the order of the access addresses of the variables to be accessed on the request initiator. Therefore, each stored data is read in sequence directly according to the arrangement order of the stored data in the response data message, and each stored data read can correspond to the variable to be accessed corresponding to the access address on the request initiator, so that without performing any conversion steps, the variable to be accessed on the request initiator can directly determine its corresponding stored data, so as to obtain the corresponding access result directly based on the corresponding storage receipt.
[0098] Optionally, in step S20, the step of packaging the variable access data to obtain a request data message includes:
[0099] Step S201, arranging the variable access data in the order of the size of the access address, and grouping the arranged variable access data to obtain the request data message;
[0100] The step of combining the stored data according to the arrangement order of the stored data in the response data message to obtain the access results corresponding to the access variables in step S40 includes:
[0101] Step S401, sorting the variables to be accessed according to the size of the corresponding access addresses, and obtaining the stored data combination from the response data message according to the length of each variable to be accessed in the sorted order to obtain the access result corresponding to each variable to be accessed.
[0102] Specifically, in order to further speed up the speed at which the request initiator obtains the access results corresponding to each variable to be accessed based on the received response data message unpacking, the present embodiment can also obtain several groups of variable access data by arranging each variable access data in the order of the size of the access address contained in each variable access data, and then grouping the variable access data arranged in the order of the size of the access address to obtain the request data message.
[0103] Because the access addresses included in the access data of each variable in the request data message are arranged in order of size, after receiving the request data message, the request response end arranges the access addresses of the variables to be accessed on the request response end in order of size according to the arrangement order of the addresses to be accessed on the request data message, so that each storage data in the response data message returned to the request initiator is also arranged according to the size of the corresponding access address. For example, the variables to be accessed ABCD on the request initiator correspond to access addresses 1234 respectively. If the arrangement order of the access addresses is not restricted and the order of the access addresses is set to 1324, the extracted storage data is also arranged in the order of ①③②④, but the variables to be accessed on the request initiator are ABCD. Therefore, after reading the storage data, an additional step is required to correspond the storage data with the variables to be accessed to ensure that the variables to be accessed can obtain the corresponding access results based on the corresponding storage data.
[0104] If the order of access addresses is restricted, the order of access addresses is set to 1234 in descending order of access addresses, and the extracted storage data is also arranged in the order of ①②③④. Because the access address corresponding to the variable ABCD to be accessed on the request initiator is 1234, there is no need to correspond the storage data with the variable to be accessed at this time. The storage data can be directly read in sequence, so that the variable to be accessed can obtain the corresponding storage data, thereby directly obtaining the corresponding access result. Compared with not restricting the order of access addresses constituting the request data message, restricting the order of access addresses constituting the request data message can speed up the request initiator to obtain the corresponding access result, thereby speeding up the user to obtain the access result.
[0105] In this embodiment, by obtaining several groups of variable access data, wherein one group of variable access data includes an access address of a variable to be accessed; each variable access data is packaged to obtain a request data message, wherein the access address in the obtained variable access data is the access address of the variable to be accessed, and there is no access address that is not the variable to be accessed, that is, there is no access address that is not to be accessed by the variable to be accessed, thereby avoiding the existing situation where multiple invalid access addresses exist only based on continuous access addresses and thus resulting in low data transmission performance, and at the same time, the request data message is sent to the request response end that establishes a communication connection with the request initiator end, and the request is sent between the request initiator end and the request response end. The limitation of the data order in the data message avoids unnecessary calculation process. After receiving the response data message returned by the request response end based on the request data message, the stored data are combined according to the arrangement order of the stored data in the response data message to obtain the access results corresponding to the variables to be accessed. Because the stored data in the response data message are arranged according to the order of the access addresses corresponding to them in the request data message, as long as the stored data are extracted in sequence according to the order in the response data message, according to the variables to be accessed corresponding to the access addresses corresponding to the stored data, the stored data corresponding to the variables to be accessed can be directly obtained without going through the calculation process, thereby further improving the data transmission performance.
[0106] like Figure 3 As shown, Figure 3 1 is a flow chart of a second embodiment of a data response method of the present invention. In this embodiment, the data response method is applied to a request response end, and the data response method includes the following steps:
[0107] Step S50, receiving a request data message sent by the request initiator, wherein the request data message is obtained by the request initiator by packaging a plurality of groups of variable access data, wherein a group of the variable access data includes an access address of a variable to be accessed;
[0108] Step S60, reading the storage area indicated by the access address in the request data message, and obtaining a response data message according to each stored data group packet read, wherein in the response data message, each stored data read is arranged according to the order of the corresponding access addresses in the request data message;
[0109] Step S70: sending the response data message to the request initiator that establishes a communication connection with the request responder.
[0110] The specific implementation of steps S50 to S70 may refer to the specific implementation of steps S30 to S40 described above, and will not be elaborated here.
[0111] Optionally, before the step of receiving the request data message sent by the request initiator in step S50, the method further includes:
[0112] Step S501, receiving a verification message including a first data version sent by the request initiator;
[0113] Step S502: compare the first data version with the second data version in the request response end, and when they are consistent, return a verification reply message representing the passed verification to the request initiating end, so that the request initiating end can send the request data message to the request response end according to the verification reply message representing the passed verification, wherein the first data version and the second data version are used to indicate the access address corresponding to the variable to be accessed.
[0114] The specific implementation of steps S501 to S502 may refer to the specific implementation of steps S301 to S302 described above, and will not be described in detail here.
[0115] Optionally, the variable access data in step S60 also includes a write variable value of the variable to be accessed, and before the step of reading the storage area indicated by the access address in the request data message, the step further includes:
[0116] Step S601: Use the write variable value to write into the storage area indicated by the corresponding access address.
[0117] The specific implementation of step S601 may refer to the specific implementation of step S303 above, which will not be described in detail here.
[0118] Optionally, the step of obtaining a response data message according to each stored data group package read in step S60 includes:
[0119] Step S602, obtaining a data packet header according to the request data message;
[0120] Without going to S603, the data packet header and a plurality of the stored data arranged in the order of the access addresses in the request data message are grouped to obtain the response data message.
[0121] In addition to the variable access data composed of the access address, the request data message also includes the data packet header in the request access command sent by the user, which is used to identify the request data message, similar to the number information. Therefore, when the request responder forms a response data message based on the request data message, it is necessary to extract the data packet header in the request data message to prompt the request initiator which request data message the response data message corresponds to, so as to avoid erroneous reception.
[0122] It should be noted that the data packet header includes the transmission type, industrial equipment identifier, function code and total data length, wherein the transmission type is used to identify the data transmission method, that is, whether the request data message goes through TCP or shared memory in the transport layer.
[0123] Industrial device identifiers are divided into four categories: source device type, source device identification, target device type and target device identification.
[0124] The function code identifies the function type of the requested data message, and the function types include read single / multiple coil registers (0x01); write single / multiple coil registers (0x02); read single / multiple input registers (0x03); read single / multiple holding registers (0x04); write single / multiple holding registers (0x05).
[0125] The total data length is the total length of several access addresses in the request data message.
[0126] In this embodiment, the response request end receives a request data message sent by the request initiator, wherein the request data message is obtained by the request initiator by packaging several groups of variable access data, and a group of variable access data includes an access address of a variable to be accessed, thereby avoiding the existing situation that multiple invalid access addresses exist because the package can only be based on continuous access addresses, thereby causing low data transmission performance; the storage area indicated by the access address in the request data message is read, and a response data message is obtained according to the read storage data packets, wherein in the response data message, the read storage data are arranged in the order of the corresponding access addresses in the request data message; the response data message is sent to the request initiator that establishes a communication connection with the request response end, because the storage data in the response data message is arranged in the order of the corresponding access addresses in the request data message, as long as the storage data is extracted in sequence in the order of the storage data in the response data message, according to the variables to be accessed corresponding to the access addresses corresponding to the storage data, the storage data corresponding to the variables to be accessed can be directly obtained without going through a calculation process, thereby further improving the data transmission performance.
[0127] In addition, an embodiment of the present invention also proposes a data exchange device, which includes a memory, a processor, and a data exchange program stored in the memory and executable on the processor. When the processor executes the data exchange program, the steps of the above-mentioned data sending method and data response method are implemented.
[0128] In addition, the present invention also proposes a computer-readable storage medium, on which a data exchange program is stored, and when the data exchange program is executed by a processor, the steps of the above-mentioned data sending method and data response method are implemented.
[0129] It should be noted that, in this article, the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article or system including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or system. In the absence of further restrictions, an element defined by the sentence "comprises a ..." does not exclude the existence of other identical elements in the process, method, article or system including the element.
[0130] The serial numbers of the above embodiments of the present invention are only for description and do not represent the advantages or disadvantages of the embodiments.
[0131] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present invention, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) as above, and includes a number of instructions for a terminal device (which can be a mobile phone, a computer, a server, an air conditioner, or a network device, etc.) to execute the methods of various embodiments of the present invention.
[0132] The above are only preferred embodiments of the present invention, and are not intended to limit the patent scope of the present invention. Any equivalent structure or equivalent process transformation made using the contents of the present invention specification and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present invention.
Claims
1. A data transmission method, It is characterized in that The data sending method is applied to the request initiator, and the data sending method comprises the following steps: Acquire several groups of variable access data, wherein one group of the variable access data includes an access address of a variable to be accessed; Packaging the variable access data to obtain a request data message; Sending a verification message including a first data version to the request response end, so that the request response end compares the first data version with the second data version in the request response end, and returning a verification reply message indicating that the verification has passed when the comparison is consistent, wherein the first data version and the second data version are used to indicate the access address corresponding to the variable to be accessed; If the verification reply message indicating that the verification has passed is received, the request data message is sent to the request responding end that has established a communication connection with the request initiating end; After receiving the response data message returned by the request response end based on the request data message, the storage data are combined according to the arrangement order of the storage data in the response data message to obtain the access results corresponding to the variables to be accessed.
2. The data transmission method according to claim 1, It is characterized in that The variable access data also includes a write variable value of the variable to be accessed, and the step of sending the request data message to the request responding end that establishes a communication connection with the request initiating end includes: The request data message is sent to the request responding end that establishes a communication connection with the request initiating end, so that the request responding end uses the write variable value to write the storage area indicated by the corresponding access address, and then the request responding end reads the storage area indicated by the access address, and obtains the response data message according to each of the stored data packets read.
3. The data transmission method according to claim 1, It is characterized in that The step of packaging the variable access data to obtain a request data message comprises: Arranging the variable access data in the order of the size of the access address, and packaging the arranged variable access data to obtain the request data message; The step of combining the stored data according to the arrangement order of the stored data in the response data message to obtain the access result corresponding to each access variable comprises: The variables to be accessed are sorted in order of the size of the corresponding access addresses, and the stored data combinations are obtained from the response data message in the sorted order according to the length of each variable to be accessed to obtain the access results corresponding to each variable to be accessed.
4. A data response method, It is characterized in that The data response method is applied to the request response end, and the data response method comprises the following steps: receiving a verification message including a first data version sent by a request initiator; Compare the first data version with the second data version in the request responder, and return a verification reply message indicating that the verification has passed to the request initiator when they are consistent, so that the request initiator can send a request data message to the request responder according to the verification reply message indicating that the verification has passed, wherein the first data version and the second data version are used to indicate the access address corresponding to the variable to be accessed; Receiving the request data message sent by the request initiator, wherein the request data message is obtained by the request initiator by packaging a plurality of groups of variable access data, and a group of the variable access data includes an access address of the variable to be accessed; Reading the storage area indicated by the access address in the request data message, and obtaining a response data message according to each stored data group packet read, wherein in the response data message, each of the stored data read is arranged according to the order of the corresponding access addresses in the request data message; The response data message is sent to the request initiator that establishes a communication connection with the request responder.
5. The data response method according to claim 4, It is characterized in that The variable access data also includes the write variable value of the variable to be accessed, and before the step of reading the storage area indicated by the access address in the request data message, it also includes: The write variable value is used to write into the storage area indicated by the corresponding access address.
6. The data response method according to claim 4, It is characterized in that The step of obtaining a response data message according to each stored data group package read comprises: Obtaining a data packet header according to the request data message; The data packet header and a plurality of the stored data arranged in the order of the access addresses in the request data message are grouped together to obtain the response data message.
7. A data exchange device, It is characterized in that The data exchange device includes a memory, a processor, and a data exchange program stored in the memory and executable on the processor. When the processor executes the data exchange program, the data sending method or the data response method described in any one of claims 1 to 6 is implemented.
8. A computer-readable storage medium, It is characterized in that The computer-readable storage medium stores a data exchange program, and when the data exchange program is executed by a processor, the steps of the data sending method or the data response method described in any one of claims 1 to 6 are implemented.
Citation Information
Patent Citations
Command processing method and device
CN105527881A
Data collection device and method
CN108416069A
Communication method and device of transmission control protocol
CN112422485A
Modbus equipment point table generation method and device, equipment and storage medium
CN115174373A
Systems And Methods To Interface Diverse Climate Controllers And Cooling Devices
US20090287866A1
