A communication method, device and electronic equipment based on Modbus protocol

By introducing map registers and synchronous message mechanisms into the communication system of the Modbus protocol, the complexity and delay problems in the discontinuous parameter processing of register addresses are solved, data processing efficiency and bandwidth utilization are improved, and the master and slave stations are realized. Efficient communication.

CN118631606BActive Publication Date: 2024-12-24BEIJING NIMOTIONCONTROL TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410892324.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-07-04
Publication Date
2024-12-24
Estimated Expiration
2044-07-04

AI Technical Summary

Technical Problem

When the existing communication method based on the Modbus protocol processes parameters with discontinuous register addresses, there are problems such as high communication complexity and long data processing time, and the lack of synchronization mechanism between master and slave stations leads to high data processing delay and high bandwidth usage.

Method used

By introducing a mapping register mechanism in the communication system, discontinuous register addresses are mapped into continuous addresses, and the synchronous message mechanism is used to enable all slave stations to synchronize the time processing operation instructions during event triggering, improving data processing efficiency and bandwidth utilization .

Benefits of technology

It reduces the communication complexity between master and slave stations, improves data processing efficiency, reduces communication delay and bandwidth usage, and achieves more efficient multi-slave coordination and bus bandwidth utilization.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118631606B_ABST
    Figure CN118631606B_ABST
Patent Text Reader

Abstract

The present invention discloses a communication method, device and electronic device based on Modbus protocol. The method provided by the embodiment of the present invention can map the addresses of multiple parameters with discontinuous register addresses into a group of continuous addresses, thereby realizing the modification or reading of multiple parameters with discontinuous register addresses in the same frame message, which can greatly reduce the complexity of communication between the master station and the slave station compared with the prior art, thereby improving the data processing efficiency of the communication system. In addition, the method provided by the embodiment of the present invention also provides a synchronization message for controlling the effective timing of the instruction, so that the communication between multiple slave stations is more coordinated; and achieves efficient and synchronous multi-slave station control, and more effectively improves the utilization of the bus bandwidth.
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 a communication method, device and electronic equipment based on the Modbus protocol. Background Art

[0002] Industrial communication system bus protocol (Modbus) communication is widely used in the field of industrial communication and is a simple and reliable communication protocol. However, the inventors found that the existing communication method based on the Modbus protocol has the following problems:

[0003] 1. When modifying or reading parameters, only the parameter values ​​of multiple continuous parameters can be modified or read at the same time in the same frame message. That is, although the existing communication method based on the Modbus protocol supports modifying or reading the parameter values ​​of multiple parameters at the same time, the prerequisite is that these parameters are continuous in the register address. Only then can the values ​​of multiple parameters be modified or read at the same time in the same frame message. For two parameters that are not continuous in the register address, the prior art usually has two processing methods. Method 1: Send multiple frame messages, one frame message contains a parameter to be modified or read, and then modify or read one parameter at a time; Method 2: All parameters between the two parameters with discontinuous register addresses are simultaneously used as parameters to be modified or read, and placed in the same frame message. While modifying or reading the two parameters with discontinuous register addresses, all parameters between the two parameters are synchronously updated. Obviously, method 1, in which one parameter to be modified or read corresponds to one frame message, has problems such as complex modification or reading process and long data processing time. Method 2, which synchronously updates all parameters between these two parameters, will greatly increase the complexity of communication and data processing time.

[0004] 2. The structure of the communication system of the Modbus protocol is a master-slave structure, that is, one master station and multiple slave stations. In the prior art, the communication process between the master station and the slave stations is: the master station communicates with the slave stations one by one in a polling manner, and only one slave station responds to the communication request of the master station at a time. In other words, the prior art lacks a synchronization mechanism, and it is impossible to make all or multiple slave stations respond to the communication request of the master station at the same time, which leads to the problems of high latency in data processing and high bandwidth occupied by communication between the master station and the slave stations in the prior art. Summary of the invention

[0005] The embodiment of the present invention provides a communication method, device and electronic device based on the Modbus protocol to solve the problems of high communication complexity and long data processing time when multiple discontinuous parameters in a register address are placed in the same frame message for modification or reading in the prior art, and the problems of high data processing delay and high bandwidth occupied by communication between the master and slave stations caused by the lack of a synchronization mechanism between the master and slave stations.

[0006] The specific technical solutions are as follows:

[0007] In a first aspect, an embodiment of the present invention provides a communication method based on the Modbus protocol, which is applied to a master station in a communication system, wherein the communication system includes a master station and at least one slave station, and the method includes:

[0008] Receive operation instructions;

[0009] Determining the address of each register to be operated in the operation instruction;

[0010] According to a preset mapping rule, a mapping register is configured for each register to be operated, and a frame of process data configuration mapping parameter message is generated, wherein the addresses of all the mapping registers can form a continuous address, and the process data configuration mapping parameter message stores a mapping relationship between the register to be operated and the mapping register;

[0011] Generate a frame of process data request message according to the operation instruction and the mapping register corresponding to the register to be operated;

[0012] The process data configuration mapping parameter message and the process data request message are sent to the target slave station, so that the target slave station performs corresponding operations on the register to be operated according to the process data configuration mapping parameter message and the process data request message, and returns a corresponding response message to the master station.

[0013] Optionally, the step of configuring a mapping register for each register to be operated according to a preset mapping rule and generating a frame of process data configuration mapping parameter message includes:

[0014] Allocate a register for each of the registers to be operated as a mapping register;

[0015] Parameter values ​​are configured for the mapping parameter slave address, function code, register address, number of registers, number of bytes, register value and check value of the check code respectively, so that a mapping relationship is established between the register to be operated and the mapping register corresponding to the register to be operated; and a frame of process data configuration mapping parameter message is generated; wherein the parameter value corresponding to the slave address parameter item is the address range of the target slave station; the parameter value corresponding to the function code parameter item is the function code corresponding to the write operation or the read operation; the parameter value corresponding to the register address parameter item is the starting address of the mapping register corresponding to the first register to be operated in the operation instruction; the parameter value corresponding to the register number parameter item is the number of registers occupied by all the mapping registers; the parameter value corresponding to the byte number parameter item is the number of bytes occupied by all the mapping registers; the parameter value corresponding to one register value parameter item is the address and number of registers of one register to be operated; the content corresponding to the check value item of the check code is the check value of the check code.

[0016] Optionally, the step of generating a frame of process data request message according to the operation instruction and the mapping register corresponding to the register to be operated includes:

[0017] When the operation instruction is a write operation, a frame of process data write request message is generated according to the operation instruction and the mapping register corresponding to the register to be operated, in accordance with the structure of the address field, function code, message mode, number of registers, number of bytes, slave address, register value and check value of the check code in sequence; wherein the content corresponding to the address field item is the address of the target slave station; the content corresponding to the function code item is the function code corresponding to the write operation; the content corresponding to the message mode item is the identification information of the process data write request message; the content corresponding to the register quantity item is the number of mapping registers; the content corresponding to the byte number item is the number of bytes occupied by all the mapping registers; the content corresponding to the slave address item is the address of the target slave station; the content corresponding to one of the register value items is the parameter value of a parameter to be written; the content corresponding to the check value item of the check code is the check value of the check code;

[0018] When the operation instruction is a read operation, a frame of process data read request message is generated according to the operation instruction and the mapping register corresponding to the register to be operated, in sequence according to the structure of the address field, function code, message mode, number of registers and check value of the check code; wherein, the content corresponding to the address field item is the address of the target slave station; the content corresponding to the function code item is the function code corresponding to the read operation; the content corresponding to the message mode item is the identification information of the process data read request message; the content corresponding to the register number item is the number of mapping registers; and the content corresponding to the check value item of the check code is the check value of the check code.

[0019] Optionally, the method further includes:

[0020] A synchronization message is sent to the target slave station, so that after receiving the synchronization message, all the target slave stations start to perform corresponding operations on the register to be operated according to the process data request message at the same time according to the event trigger time configured in the synchronization message.

[0021] In a second aspect, an embodiment of the present invention provides a communication method based on the Modbus protocol, which is applied to a master station in a communication system, wherein the communication system includes a master station and at least one slave station, and the method includes:

[0022] Receiving a process data configuration mapping parameter message and a process data request message sent by the master station; wherein the process data configuration mapping parameter message stores a mapping relationship between a register to be operated and a mapping register;

[0023] Parsing the process data configuration mapping parameter message and the process data request message, and confirming the type of the process data request message according to the content corresponding to the message mode item in the process data request message;

[0024] When the type of the process data request message is a process data write request message, confirming the address of the target mapping register according to the contents corresponding to the register quantity item and the byte quantity item in the process data write request message;

[0025] According to the address of the target mapping register and the mapping relationship between the register to be operated and the mapping register in the process data write configuration mapping parameter message, the address, number and number of bytes of the target register to be operated are confirmed;

[0026] According to the content corresponding to the register value item in the process data write request message, confirm the to-be-written parameter corresponding to each target register to be operated;

[0027] Writing the to-be-written parameter into the corresponding target to-be-operated register, and returning a corresponding response message to the master station;

[0028] When the type of the process data request message is a process data read request message, confirming the address, number and number of bytes of the target register to be operated according to the content corresponding to the register quantity item in the process data read request message and the content corresponding to the register address item, the register quantity item, the byte number item and the register value item in the process data read configuration mapping parameter message;

[0029] According to the address, number and number of bytes of the target register to be operated, the parameter value of the parameter to be read is obtained from the target register to be operated, and a response message including the parameter value is returned to the master station.

[0030] Optionally, the method further includes:

[0031] Receiving a synchronization message sent by the master station;

[0032] The synchronization message is parsed, and according to the event trigger time configured in the synchronization message and the process data request message, a corresponding operation is performed on the register to be operated.

[0033] In a third aspect, an embodiment of the present invention provides a communication device based on the Modbus protocol, the device comprising:

[0034] A receiving module, used for receiving an operation instruction;

[0035] A determination module, used to determine the address of each register to be operated in the operation instruction;

[0036] A configuration module, configured to configure a mapping register for each of the registers to be operated according to a preset mapping rule, and generate a frame of process data configuration mapping parameter message, wherein the addresses of all the mapping registers can form a continuous address, and the process data configuration mapping parameter message stores a mapping relationship between the registers to be operated and the mapping registers;

[0037] A generating module, used for generating a frame of process data request message according to the operation instruction and the mapping register corresponding to the register to be operated;

[0038] A sending module is used to send the process data configuration mapping parameter message and the process data request message to the target slave station, so that the target slave station performs corresponding operations on the register to be operated according to the process data configuration mapping parameter message and the process data request message, and returns a corresponding response message to the master station.

[0039] Optional, configuration module, specifically for:

[0040] Allocate a register for each of the registers to be operated as a mapping register;

[0041] Parameter values ​​are configured for the mapping parameter slave address, function code, register address, number of registers, number of bytes, register value and check value of the check code respectively, so that a mapping relationship is established between the register to be operated and the mapping register corresponding to the register to be operated; and a frame of process data configuration mapping parameter message is generated; wherein the parameter value corresponding to the slave address parameter item is the address range of the target slave station; the parameter value corresponding to the function code parameter item is the function code corresponding to the write operation or the read operation; the parameter value corresponding to the register address parameter item is the starting address of the mapping register corresponding to the first register to be operated in the operation instruction; the parameter value corresponding to the register number parameter item is the number of registers occupied by all the mapping registers; the parameter value corresponding to the byte number parameter item is the number of bytes occupied by all the mapping registers; the parameter value corresponding to one register value parameter item is the address and number of registers of one register to be operated; the content corresponding to the check value item of the check code is the check value of the check code.

[0042] Optionally, generate modules, specifically for:

[0043] When the operation instruction is a write operation, a frame of process data write request message is generated according to the operation instruction and the mapping register corresponding to the register to be operated, in accordance with the structure of the address field, function code, message mode, number of registers, number of bytes, slave address, register value and check value of the check code in sequence; wherein the content corresponding to the address field item is the address of the target slave station; the content corresponding to the function code item is the function code corresponding to the write operation; the content corresponding to the message mode item is the identification information of the process data write request message; the content corresponding to the register quantity item is the number of mapping registers; the content corresponding to the byte number item is the number of bytes occupied by all the mapping registers; the content corresponding to the slave address item is the address of the target slave station; the content corresponding to one of the register value items is the parameter value of a parameter to be written; the content corresponding to the check value item of the check code is the check value of the check code;

[0044] When the operation instruction is a read operation, a frame of process data read request message is generated according to the operation instruction and the mapping register corresponding to the register to be operated, in sequence according to the structure of the address field, function code, message mode, number of registers and check value of the check code; wherein, the content corresponding to the address field item is the address of the target slave station; the content corresponding to the function code item is the function code corresponding to the read operation; the content corresponding to the message mode item is the identification information of the process data read request message; the content corresponding to the register number item is the number of mapping registers; and the content corresponding to the check value item of the check code is the check value of the check code.

[0045] Optionally, the device further includes:

[0046] The synchronization module is used to send a synchronization message to the target slave station, so that all the target slave stations, after receiving the synchronization message, start to perform corresponding operations on the register to be operated according to the process data request message at the same time according to the event trigger time configured in the synchronization message.

[0047] In a fourth aspect, an embodiment of the present invention provides a communication device based on the Modbus protocol, the device comprising:

[0048] A receiving module, used for receiving a process data configuration mapping parameter message and a process data request message sent by the master station; wherein the process data configuration mapping parameter message stores a mapping relationship between a register to be operated and a mapping register;

[0049] A confirmation module, used to parse the process data configuration mapping parameter message and the process data request message, and confirm the type of the process data request message according to the content corresponding to the message mode item in the process data request message; when the type of the process data request message is a process data write request message, start the write module; when the type of the process data request message is a process data read request message, start the read module;

[0050] The writing module is used for:

[0051] Confirming the address of the target mapping register according to the contents corresponding to the register quantity item and the byte quantity item in the process data write request message;

[0052] According to the address of the target mapping register and the mapping relationship between the register to be operated and the mapping register in the process data write configuration mapping parameter message, the address, number and byte number, number and byte number of the target register to be operated are confirmed;

[0053] According to the content corresponding to the register value item in the process data write request message, confirm the to-be-written parameter corresponding to each target register to be operated;

[0054] Writing the to-be-written parameter into the corresponding target to-be-operated register, and returning a corresponding response message to the master station;

[0055] The reading module is used for:

[0056] Confirm the address, number and number of bytes of the target register to be operated according to the content corresponding to the register quantity item in the process data read request message and the content corresponding to the register address item, register quantity item, byte number item and register value item in the process data read configuration mapping parameter message;

[0057] According to the address, number and number of bytes of the target register to be operated, the parameter value of the parameter to be read is obtained from the target register to be operated, and a response message including the parameter value is returned to the master station.

[0058] Optionally, the device further includes: a synchronization module, configured to:

[0059] Receiving a synchronization message sent by the master station;

[0060] The synchronization message is parsed, and according to the event trigger time configured in the synchronization message and the process data request message, a corresponding operation is performed on the register to be operated.

[0061] In a fifth aspect, an embodiment of the present invention further provides an electronic device, comprising a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other through the communication bus;

[0062] The memory is used to store computer programs;

[0063] The processor is used to execute the program stored in the memory to implement the communication method steps based on the Modbus protocol applied to the master station in the communication system as described in the first aspect above.

[0064] In a sixth aspect, an embodiment of the present invention further provides an electronic device, comprising a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other via the communication bus;

[0065] The memory is used to store computer programs;

[0066] The processor is used to execute the program stored in the memory to implement the communication method steps based on the Modbus protocol applied to the slave station in the communication system as described in the second aspect above.

[0067] In the seventh aspect, an embodiment of the present invention further provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the communication method based on the Modbus protocol applied to a master station in a communication system as described in the first aspect above are implemented.

[0068] In an eighth aspect, an embodiment of the present invention further provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the communication method based on the Modbus protocol applied to a slave station in a communication system as described in the second aspect above are implemented.

[0069] In summary, it can be seen that the method provided by the embodiment of the present invention and applied to the master station in the communication system can realize the modification or reading of multiple parameters with discontinuous register addresses in the same frame message. Compared with the prior art, it can greatly reduce the complexity of communication between the master station and the slave station, thereby improving the data processing efficiency of the communication system.

[0070] The method provided by the embodiment of the present invention for a slave station in a communication system can realize the solution of continuous mapping addresses into actual registers to be operated in the operation instruction, and perform corresponding operations on the registers to be operated according to the process data request message. Therefore, the method provided by the embodiment of the present invention can realize the modification or reading of multiple parameters with discontinuous register addresses in the same frame message, which can greatly reduce the complexity of communication between the master station and the slave station compared with the prior art, thereby improving the data processing efficiency of the communication system.

[0071] Other features and advantages of the present invention will be described in the following description, and partly become apparent from the description, or understood by practicing the present invention. The purpose and other advantages of the present invention can be realized and obtained by the structures particularly pointed out in the written description, claims, and drawings.

[0072] The technical solution of the present invention is further described in detail below through the accompanying drawings and embodiments. BRIEF DESCRIPTION OF THE DRAWINGS

[0073] The accompanying drawings are used to provide a further understanding of the present invention and constitute a part of the specification. Together with the embodiments of the present invention, they are used to explain the present invention and do not constitute a limitation of the present invention. In the accompanying drawings:

[0074] Figure 1 A flow chart of a communication method based on the Modbus protocol provided in an embodiment of the present invention applied to a master station;

[0075] Figure 2 A schematic diagram of the interaction between the master station and the slave station after the introduction of the synchronization message provided by the embodiment of the present invention;

[0076] Figure 3 A flow chart of a communication method based on the Modbus protocol provided in an embodiment of the present invention applied to a slave station;

[0077] Figure 4 A schematic diagram of a structure of a process data write request message, a process data write configuration mapping parameter message, and a response message corresponding to the process data write request message provided by an embodiment of the present invention;

[0078] Figure 5A schematic diagram of a structure of a process data read request message, a process data write configuration mapping parameter message, and a response message corresponding to the process data read request message provided by an embodiment of the present invention;

[0079] Figure 6 A schematic diagram of the structure of a communication device based on the Modbus protocol provided by an embodiment of the present invention;

[0080] Figure 7 Another structural schematic diagram of a communication device based on the Modbus protocol provided by an embodiment of the present invention;

[0081] Figure 8 A schematic diagram of the internal structure of an electronic device applied to a master station in a communication system provided by an embodiment of the present invention;

[0082] Fig. 9 A schematic diagram of the internal structure of an electronic device of a slave station in a communication system provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0083] The preferred embodiments of the present invention are described below in conjunction with the accompanying drawings. It should be understood that the preferred embodiments described herein are only used to illustrate and explain the present invention, and are not used to limit the present invention.

[0084] Figure 1 A flow chart of a communication method based on the Modbus protocol provided by an embodiment of the present invention. The method is applied to a master station in a communication system, wherein the communication system includes a master station and at least one slave station. The structure of the communication system based on the Modbus protocol is a master-slave structure, that is, one master station and multiple slave stations.

[0085] The master station of the communication system is the core and control center of the entire communication system. The master station is mainly responsible for processing and distributing communication information, managing system resources, and coordinating the communication between the slave stations. The master station usually has more powerful processing capabilities and higher data transmission speeds, and can support communication and coordination between multiple slave stations. In a wired communication system, the master station is usually implemented by a switch or a dispatch center; in a wireless communication system, the master station is usually implemented by a base station or a control station.

[0086] The slave station is usually a device or module in the communication system that receives instructions sent by the master station and performs corresponding operations. The function and performance of the slave station directly affect the stability and reliability of the entire communication system. After the master station and the slave station establish a connection, the master station can send instructions or data to the slave station, the slave station receives the instructions sent by the master station and performs corresponding operations, and then returns the execution results to the master station.

[0087] like Figure 1 As shown, the method includes:

[0088] S101: receiving an operation instruction;

[0089] In a specific embodiment, the operation instruction may be a write operation instruction for writing data to a register, or a read operation instruction for reading data from a register.

[0090] S102: Determine the address of each register to be operated in the operation instruction;

[0091] In a specific embodiment, when the operation instruction is a write operation, the register to be written corresponding to each parameter to be written in the operation instruction is determined as the register to be operated; when the operation instruction is a read operation, the register of each register value to be read in the operation instruction is determined as the register to be operated.

[0092] S103: According to a preset mapping rule, a mapping register is configured for each register to be operated, and a frame of process data configuration mapping parameter message is generated, wherein the addresses of all mapping registers can form a continuous address, and the process data configuration mapping parameter message stores a mapping relationship between the register to be operated and the mapping register;

[0093] Specifically, the steps of configuring a mapping register for each register to be operated according to a preset mapping rule and generating a frame of process data configuration mapping parameter message may include:

[0094] Allocate a register for each register to be operated as a mapping register;

[0095] Parameter values ​​are configured for the mapping parameter slave address, function code, register address, number of registers, number of bytes, register value and check value of the check code respectively, so as to establish a mapping relationship between the register to be operated and the mapping register corresponding to the register to be operated; and a frame of process data configuration mapping parameter message is generated; wherein, the parameter value corresponding to the slave address parameter item is the address range of the target slave station; the parameter value corresponding to the function code parameter item is the function code corresponding to the write operation or the read operation; the parameter value corresponding to the register address parameter item is the starting address of the mapping register corresponding to the first register to be operated in the operation instruction; the parameter value corresponding to the register number parameter item is the number of registers occupied by all mapping registers; the parameter value corresponding to the byte number parameter item is the number of bytes occupied by all mapping registers; the parameter value corresponding to a register value parameter item is the address and number of registers of a register to be operated; the content corresponding to the check value item of the check code is the check value of the check code.

[0096] S104: Generate a frame of process data request message according to the operation instruction and the mapping register corresponding to the register to be operated;

[0097] Specifically, the step of generating a frame of process data request message according to the operation instruction and the mapping register corresponding to the register to be operated may include:

[0098] When the operation instruction is a write operation, a frame of process data write request message is generated according to the operation instruction and the mapping register corresponding to the register to be operated, in accordance with the structure of address field, function code, message mode, number of registers, number of bytes, slave address, register value and check value of check code in sequence; wherein, the content corresponding to the address field item is the address of the target slave; the content corresponding to the function code item is the function code corresponding to the write operation; the content corresponding to the message mode item is the identification information of the process data write request message; the content corresponding to the register number item is the number of mapping registers; the content corresponding to the byte number item is the number of bytes occupied by all mapping registers; the content corresponding to the slave address item is the address of the target slave; the content corresponding to a register value item is the parameter value of a parameter to be written; the content corresponding to the check value item of the check code is the check value of the check code;

[0099] When the operation instruction is a read operation, a frame of process data read request message is generated according to the operation instruction and the mapping register corresponding to the register to be operated, in sequence according to the structure of the address field, function code, message mode, number of registers and check value of the check code; wherein, the content corresponding to the address field item is the address of the target slave station; the content corresponding to the function code item is the function code corresponding to the read operation; the content corresponding to the message mode item is the identification information of the process data read request message; the content corresponding to the register number item is the number of mapping registers; and the content corresponding to the check value item of the check code is the check value of the check code.

[0100] S105: Send the process data configuration mapping parameter message and the process data request message to the target slave station, so that the target slave station performs corresponding operations on the register to be operated according to the process data configuration mapping parameter message and the process data request message, and returns a corresponding response message to the master station.

[0101] In a specific embodiment, the method provided by the embodiment of the present invention may further include:

[0102] Send a synchronization message to the target slave station, so that all the target slave stations, after receiving the synchronization message, will start to perform corresponding operations on the registers to be operated according to the process data request message at the same time according to the event trigger time configured in the synchronization message.

[0103] Due to the lack of synchronization mechanism between the master and slave stations in the existing communication system based on the Modbus protocol, the communication system has the problem of high latency in data processing and high bandwidth occupied by communication between the master and slave stations. In view of this problem, the method provided in the embodiment of the present invention also designs a synchronization message for controlling the timing of the effectiveness of the instruction, so that the communication between multiple slave stations is more coordinated. In the embodiment of the present invention, the master station in the communication system can send a synchronization message to the slave station by broadcasting a message. After receiving the synchronization message, the slave station does not need to reply to the master station, but directly starts to process data when the event trigger time arrives. Such a design method can not only achieve the purpose of efficient and synchronous multi-slave station control, but also more effectively improve the utilization rate of the bus bandwidth.

[0104] For example, in a specific embodiment, the structure of the synchronization message provided by the embodiment of the present invention may be as shown in Table 1 below:

[0105] Table 1

[0106]

[0107] See also Figure 2 After the introduction of synchronization messages, the interaction process between the master station and the slave station can be:

[0108] The master station sends a process data write request message to all slave stations in the communication system in a broadcast manner. After receiving the message, all slave stations in the communication system do not process the process data write request message first, but cache the message first and wait for the master station to broadcast a synchronization message for the process data write request message; after receiving the synchronization message broadcast by the master station, according to the event trigger time configured in the synchronization message, when the event trigger time arrives, all slave stations in the communication system synchronously start to process the previously cached process data write request message.

[0109] In other embodiments, the method provided by the embodiment of the present invention may further include the following steps after receiving the operation instruction:

[0110] Determine the address of each register to be operated in the operation instruction;

[0111] Determine whether the addresses of all registers to be operated in the operation instruction can form a continuous address;

[0112] If yes, a frame of process data request message is generated according to the operation instruction and sent to the target slave station, so that the target slave station performs corresponding operations on the register to be operated according to the process data request message and returns a corresponding response message to the master station;

[0113] If not, then according to a preset mapping rule, a mapping register is configured for each register to be operated, wherein the addresses of all mapping registers can form a continuous address;

[0114] According to the operation instruction and the mapping register corresponding to the register to be operated, a frame of process data request message is generated and sent to the target slave station, so that the target slave station performs corresponding operations on the register to be operated according to the process data configuration mapping parameter message and the process data request message, and returns the corresponding response message to the master station.

[0115] It can be seen that in this embodiment, after receiving the operation instruction, the master station will first determine whether the addresses of all the registers to be operated in the operation instruction can form a continuous address. If so, it will directly generate a frame of process data request message according to the operation instruction and send it to the target slave station; if not, it is necessary to configure a mapping register for each register to be operated according to the preset mapping rules, wherein the addresses of all mapping registers can form a continuous address; then, according to the operation instruction and the mapping register corresponding to the register to be operated, a frame of process data request message is generated and sent to the target slave station.

[0116] Depend on Figure 1 It can be seen from the illustrated embodiment that the method provided by the embodiment of the present invention can realize the modification or reading of multiple parameters with discontinuous register addresses in the same frame message. Compared with the prior art, it can greatly reduce the complexity of communication between the master station and the slave station, thereby improving the data processing efficiency of the communication system.

[0117] Figure 3 A flow chart of a communication method based on the Modbus protocol provided by an embodiment of the present invention is provided, wherein the method is applied to a slave station in a communication system, such as Figure 3 As shown, the method includes:

[0118] S301: receiving a process data configuration mapping parameter message and a process data request message sent by a master station; wherein the process data configuration mapping parameter message stores a mapping relationship between a register to be operated and a mapping register;

[0119] S302: parsing the process data configuration mapping parameter message and the process data request message, and confirming the type of the process data request message according to the content corresponding to the message mode item in the process data request message; when the type of the process data request message is a process data write request message, executing step S303; when the type of the process data request message is a process data read request message, executing step S307;

[0120] S303: confirming the address of the target mapping register according to the contents corresponding to the register quantity item and the byte quantity item in the process data write request message;

[0121] S304: confirming the address, number and number of bytes of the target register to be operated according to the address of the target mapping register and the mapping relationship between the register to be operated and the mapping register in the process data write configuration mapping parameter message;

[0122] S305: confirming the to-be-written parameter corresponding to each target register to be operated according to the content corresponding to the register value item in the process data write request message;

[0123] S306: Write the parameter to be written into the corresponding target register to be operated, and return a corresponding response message to the master station;

[0124] S307: confirming the address, number and byte number of the target register to be operated according to the content corresponding to the register quantity item in the process data read request message and the content corresponding to the register address item, register quantity item, byte number item and register value item in the process data read configuration mapping parameter message;

[0125] S308: Obtain the parameter value of the parameter to be read from the target register to be operated according to the address, number and byte number of the target register to be operated, and return a response message including the parameter value to the master station.

[0126] In addition, the method provided in the embodiment of the present invention may further include the following steps:

[0127] Receive synchronization messages sent by the master station;

[0128] Parse the synchronization message, and perform corresponding operations on the register to be operated according to the process data request message according to the event trigger time configured in the synchronization message.

[0129] Therefore, the method provided in the embodiment of the present invention can also enable the slave stations in the communication system to synchronously start processing the cached process data request messages according to the event trigger time in the synchronization message. Therefore, the purpose of efficient and synchronous multi-slave station control can be achieved, and the utilization rate of the bus bandwidth can be more effectively improved.

[0130] Depend on Figure 3 As can be seen from the embodiments shown, the method provided by the embodiments of the present invention for a slave station in a communication system can realize the solution of continuous mapping addresses into actual registers to be operated in the operation instructions, and perform corresponding operations on the registers to be operated according to the process data request message. Therefore, the method provided by the embodiments of the present invention can realize the modification or reading of multiple parameters with discontinuous register addresses in the same frame message, which can greatly reduce the complexity of communication between the master station and the slave station compared to the prior art, thereby improving the data processing efficiency of the communication system.

[0131] The following is a practical example for a write operation instruction and a read operation instruction to further illustrate the method provided in the embodiment of the present invention in more detail.

[0132] Example 1: In this embodiment, the structure of the process data write request message may be as shown in Table 2:

[0133] Table 2

[0134]

[0135]

[0136] The process data write request message is a write operation, that is, writing data to the register in the slave station. Therefore, the function code corresponding to the process data write request message is 0x10.

[0137] In this embodiment, in order to formulate a specific process data write request message, the register address is set to the identifier of the process data write request message, that is, 0x8300.

[0138] In this embodiment, it is assumed that a frame message can contain at most 16 parameters to be modified at the same time, that is, it contains 16 data to be written into registers at the same time, and each parameter corresponds to at most two registers. Then, 16 parameters to be modified correspond to at most 32 registers, plus one slave address occupies one register, so the number of registers corresponding to a frame message ranges from 1 to 33. Since each register occupies two bytes, the number of bytes corresponding to a frame message ranges from 2 to 66.

[0139] According to the method provided in the embodiment of the present invention, the master station can send the message to all slave stations in the communication system in a broadcast mode, or can send the message to a certain slave station in the communication system in a unicast mode. Specifically, when the contents of sequence numbers 8 and 9 in Table 2 are both 0x00, it means that the master station sends the message to all slave stations in the communication system in a broadcast mode. When the contents of sequence numbers 8 and 9 are a certain slave address, the master station sends the message to the slave station in the communication system in a unicast mode. For example, when the contents of sequence numbers 8 and 9 are 0x00 and 0x01 respectively, it indicates that the target slave station is slave station 1, then the master station will send the message to slave station 1 in a unicast mode.

[0140] In this embodiment 1, the operation instruction is to write three parameters: parameter A: 0x1111, parameter F: 0x5566 and parameter M: 0x6666, respectively, into the registers with Modbus addresses of 0x0231, 0x038B and 0x03D7 in slave station 1. Since the addresses corresponding to the registers to be operated are discontinuous, it is necessary to map the discontinuous addresses to continuous addresses according to the mapping rules. Specifically, Figure 4As shown, first configure mapping parameters for these three parameters, map discontinuous addresses to continuous mapping addresses, namely 0x5002, 0x5004, and 0x5006. The register values ​​corresponding to these three mapping registers are the register addresses of the registers to be operated, namely 0x0231, 0x038B, and 0x03D7.

[0141] According to the operation instruction and the mapping register corresponding to the register to be operated, the master station generates a frame of process data write request message in accordance with the structure of address field, function code, message mode, number of registers, number of bytes, slave station address, register value and check value of check code, and sends it to the target slave station, that is, slave station 1. And a frame of message is generated for process data write configuration mapping parameter, the structure of which is: slave station address, function code, register address, number of registers, number of bytes, register value and check value of check code; and the process data write configuration mapping parameter message is sent to the target slave station, so that the target slave station can solve the register to be operated corresponding to the mapping register according to the process data write configuration mapping parameter message. After receiving the process data write configuration mapping parameter message, the target slave station will return a frame of process data write configuration mapping parameter response message to the master station to inform the master station that it has successfully received the process data write configuration mapping parameter message.

[0142] In some embodiments, if the slave station fails to successfully receive the process data request message or the process data configuration mapping parameter message, it can also feedback a reception failure message to the master station to prompt the master station to resend the message. Of course, in some embodiments, the master station can also start monitoring whether it has received a response message or a feedback reception failure message returned by the slave station after sending the message to the slave station. If it does not receive a response message or a feedback reception failure message returned by the slave station within a preset time, the master station will actively resend the message.

[0143] After receiving the process data request message and the process data write configuration mapping parameter message sent by the master station, slave station 1 first parses the two messages and confirms that the message is a process data write request message according to the content corresponding to the message mode item in the process data request message. According to the corresponding contents of the register quantity item and the byte number item in the process data write request message, the modbus addresses of the mapping registers are confirmed to be 0x5002, 0x5004, and 0x5006 respectively. According to the register values ​​corresponding to the three mapping registers in the process data write configuration mapping parameter message, the addresses of the registers to be operated are confirmed to be 0x0231, 0x038B, and 0x03D7 respectively. Then, the parameters to be written 0x1111, 0x5566, and 0x6666 obtained from the register value item of the process data write request message are written into the registers of the Modbus addresses of 0x0231, 0x038B, and 0x03D7 in slave station 1 respectively; and the response message corresponding to the process write request message is returned to the master station. The message structure of the response message may be: slave address, function code, message mode, register quantity and CRC check value.

[0144] Example 2: In this embodiment, the structure of the process data read request message may be as shown in Table 3:

[0145] Table 3

[0146]

[0147] The process data read request message is a read operation, that is, reading data from the register in the slave station, so the function code corresponding to the process data read request message is 0x04. Among them, the process data read request message reads the data in the slave station buffer area, so the address of the register to be operated is also the address of the buffer area.

[0148] In this embodiment, it is assumed that a frame message can contain at most 16 parameters to be read at the same time, that is, it contains 16 register data to be read at the same time, and each parameter corresponds to at most two registers. Then, the 16 parameters to be read correspond to at most 32 registers. Therefore, the number of registers corresponding to a frame message ranges from 1 to 32.

[0149] In this embodiment 2, the operation instruction is to read data from the three registers with Modbus addresses of 0x03C6, 0x03D0, and 0x0446 in slave station 1. Since the addresses corresponding to the registers to be operated are discontinuous, it is necessary to map the discontinuous addresses to continuous addresses according to the mapping rules, specifically, Figure 5As shown, first configure mapping parameters for these three registers, map discontinuous addresses to continuous mapping addresses, i.e., 0x6002, 0x6004, and 0x6006. The register values ​​corresponding to these three mapping registers are the starting addresses of the registers to be operated and the number of registers occupied by the registers to be operated, i.e., 0x02310002, 0x038B0002, and 0x03D70001.

[0150] According to the operation instruction, the master station generates a frame of process data read request message in accordance with the structure of address field, function code, message mode, number of registers and CRC check value, and sends it to the target slave station, that is, slave station 1. And generate a frame of message for process data read configuration mapping parameters, the structure of which is: slave station address, function code, register address, number of registers, number of bytes, register value and CRC check value; and send the process data read configuration mapping parameter message to the target slave station, so that the target slave station can solve the register to be operated corresponding to the mapping register according to the process data read configuration mapping parameter message. After receiving the process data read configuration mapping parameter message, the target slave station will return a frame of process data read configuration mapping parameter response message to the master station to inform the master station that it has successfully received the process data read configuration mapping parameter message.

[0151] After receiving the process data request message and process data read configuration mapping parameter message sent by the master station, slave station 1 will first parse the two messages and confirm that the message is a process data read request message according to the content corresponding to the message mode item in the process data request message. According to the content corresponding to the register address item, register quantity item, byte number item and register value item in the process data read configuration mapping parameter message, the modbus addresses of the mapping registers are confirmed to be: 0x6002, 0x6004, 0x6006, and the first address of the register to be operated and the number of registers occupied by the register to be operated are confirmed to be: 0x0231 occupies 2 registers, 0x038B occupies 2 registers, 0x03D7 occupies 1 register, and read data from the registers with Modbus addresses of 0x0231, 0x038B, and 0x03D7 in slave station 1 respectively: 0x00004455, 0x11226666, 0x7788; and return a response message to the master station. The message structure of the response message may be: slave address, function code, number of bytes, register value and CRC check value.

[0152] It can be seen from the above Examples 1 and 2 that the method provided in the embodiment of the present invention can realize the modification or reading of multiple parameters with discontinuous register addresses in the same frame message. Compared with the prior art, it can greatly reduce the complexity of communication between the master station and the slave station, thereby improving the data processing efficiency of the communication system.

[0153] and Figure 1 Corresponding to the embodiment shown in FIG. 1 , the embodiment of the present invention further provides a communication device based on the Modbus protocol, such as Figure 6 As shown, the device includes: a receiving module 601, a determining module 602, a configuring module 603, a generating module 604, and a sending module 605, wherein:

[0154] Receiving module 601, used for receiving operation instructions;

[0155] A determination module 602 is used to determine the address of each register to be operated in the operation instruction;

[0156] Configuration module 603, configured to configure a mapping register for each register to be operated according to a preset mapping rule, and generate a frame of process data configuration mapping parameter message, wherein the addresses of all mapping registers can form a continuous address, and the process data configuration mapping parameter message stores the mapping relationship between the register to be operated and the mapping register;

[0157] The generating module 604 is used to generate a frame of process data request message according to the operation instruction and the mapping register corresponding to the register to be operated.

[0158] The sending module 605 is used to send the process data configuration mapping parameter message and the process data request message to the target slave station, so that the target slave station performs corresponding operations on the register to be operated according to the process data configuration mapping parameter message and the process data request message, and returns a corresponding response message to the master station.

[0159] Optionally, the configuration module 603 is specifically used to:

[0160] Allocate a register for each register to be operated as a mapping register;

[0161] Parameter values ​​are configured for the mapping parameter slave address, function code, register address, number of registers, number of bytes, register value and check value of the check code respectively, so as to establish a mapping relationship between the register to be operated and the mapping register corresponding to the register to be operated; and a frame of process data configuration mapping parameter message is generated; wherein, the parameter value corresponding to the slave address parameter item is the address range of the target slave station; the parameter value corresponding to the function code parameter item is the function code corresponding to the write operation or the read operation; the parameter value corresponding to the register address parameter item is the starting address of the mapping register corresponding to the first register to be operated in the operation instruction; the parameter value corresponding to the register number parameter item is the number of registers occupied by all mapping registers; the parameter value corresponding to the byte number parameter item is the number of bytes occupied by all mapping registers; the parameter value corresponding to a register value parameter item is the address and number of registers of a register to be operated; the content corresponding to the check value item of the check code is the check value of the check code.

[0162] Optionally, the generating module 604 is specifically used for:

[0163] When the operation instruction is a write operation, a frame of process data write request message is generated according to the operation instruction and the mapping register corresponding to the register to be operated, in accordance with the structure of address field, function code, message mode, number of registers, number of bytes, slave address, register value and check value of check code in sequence; wherein, the content corresponding to the address field item is the address of the target slave; the content corresponding to the function code item is the function code corresponding to the write operation; the content corresponding to the message mode item is the identification information of the process data write request message; the content corresponding to the register number item is the number of mapping registers; the content corresponding to the byte number item is the number of bytes occupied by all mapping registers; the content corresponding to the slave address item is the address of the target slave; the content corresponding to a register value item is the parameter value of a parameter to be written; the content corresponding to the check value item of the check code is the check value of the check code;

[0164] When the operation instruction is a read operation, a frame of process data read request message is generated according to the operation instruction and the mapping register corresponding to the register to be operated, in sequence according to the structure of the address field, function code, message mode, number of registers and check value of the check code; wherein, the content corresponding to the address field item is the address of the target slave station; the content corresponding to the function code item is the function code corresponding to the read operation; the content corresponding to the message mode item is the identification information of the process data read request message; the content corresponding to the register number item is the number of mapping registers; and the content corresponding to the check value item of the check code is the check value of the check code.

[0165] Optionally, the device also includes: a synchronization module, which is used to send a synchronization message to the target slave station, so that all target slave stations, after receiving the synchronization message, will start to perform corresponding operations on the operation register according to the process data request message at the same time according to the event trigger time configured in the synchronization message.

[0166] It can be seen that the device provided by the embodiment of the present invention can modify or read multiple parameters with discontinuous register addresses in the same frame message, which can greatly reduce the complexity of communication between the master station and the slave station compared to the prior art, thereby improving the data processing efficiency of the communication system. In addition, the device provided by the embodiment of the present invention can also use the synchronization message to control the timing of the effectiveness of the instruction, so that the communication between multiple slave stations is more coordinated; and achieve efficient and synchronous multi-slave station control, and more effectively improve the utilization of the bus bandwidth.

[0167] and Figure 3 Corresponding to the embodiment shown in FIG. 1 , the embodiment of the present invention further provides a communication device based on the Modbus protocol, such as Figure 7As shown, the device includes: a receiving module 701, a confirmation module 702, a writing module 703, and a reading module 704, wherein:

[0168] The receiving module 701 is used to receive the process data configuration mapping parameter message and the process data request message sent by the master station; wherein the process data configuration mapping parameter message stores the mapping relationship between the register to be operated and the mapping register;

[0169] The confirmation module 702 is used to parse the process data configuration mapping parameter message and the process data request message, and confirm the type of the process data request message according to the content corresponding to the message mode item in the process data request message; when the type of the process data request message is a process data write request message, start the write module; when the type of the process data request message is a process data read request message, start the read module;

[0170] The writing module 703 is used for:

[0171] Confirm the address of the target mapping register according to the contents corresponding to the register quantity item and the byte quantity item in the process data write request message;

[0172] According to the address of the target mapping register and the mapping relationship between the register to be operated and the mapping register in the process data write configuration mapping parameter message, the address, number and number of bytes of the target register to be operated are confirmed;

[0173] According to the content corresponding to the register value item in the process data write request message, confirm the parameters to be written corresponding to each target register to be operated;

[0174] Write the parameters to be written into the corresponding target register to be operated, and return the corresponding response message to the master station;

[0175] The reading module 704 is used to:

[0176] According to the content corresponding to the register quantity item in the process data read request message and the content corresponding to the register address item, register quantity item, byte number item and register value item in the process data read configuration mapping parameter message, confirm the address, number and byte number of the target register to be operated;

[0177] According to the address, number and byte number of the target register to be operated, the parameter value of the parameter to be read is obtained from the target register to be operated, and a response message including the parameter value is returned to the master station.

[0178] Optionally, the device further includes: a synchronization module, configured to:

[0179] Receive synchronization messages sent by the master station;

[0180] Parse the synchronization message, and perform corresponding operations on the register to be operated according to the process data request message according to the event trigger time configured in the synchronization message.

[0181] It can be seen that the device provided by the embodiment of the present invention can realize the solution of continuous mapping addresses into actual registers to be operated in the operation instructions, and perform corresponding operations on the registers to be operated according to the process data request message. Therefore, the device provided by the embodiment of the present invention can realize the modification or reading of multiple parameters with discontinuous register addresses in the same frame message, which can greatly reduce the complexity of communication between the master station and the slave station compared to the prior art, thereby improving the data processing efficiency of the communication system. In addition, the device provided by the embodiment of the present invention can also realize the use of synchronous messages to control the timing of the effectiveness of instructions, so that the communication between multiple slave stations is more coordinated; and achieve efficient and synchronous multi-slave station control, and more effectively improve the utilization of bus bandwidth.

[0182] and Figure 1 Corresponding to the embodiment shown, the embodiment of the present invention further provides an electronic device, see Figure 8 , including a processor 801, a communication interface 802, a memory 803 and a communication bus 804, wherein the processor 801, the communication interface 802, and the memory 803 communicate with each other through the communication bus 804;

[0183] Memory 803, used for storing computer programs;

[0184] The processor 801 is used to implement the steps of the communication method based on the Modbus protocol and applied to a master station in a communication system as described in any of the above embodiments when executing the program stored in the memory.

[0185] The electronic device provided by the embodiment of the present invention can modify or read multiple parameters with discontinuous register addresses in the same frame message, which can greatly reduce the complexity of communication between the master station and the slave station compared to the prior art, thereby improving the data processing efficiency of the communication system. In addition, the electronic device provided by the embodiment of the present invention can also use the synchronization message to control the timing of the effectiveness of the instruction, so that the communication between multiple slave stations is more coordinated; and achieve efficient and synchronous multi-slave station control, and more effectively improve the utilization of the bus bandwidth.

[0186] and Figure 3 Corresponding to the embodiment shown, the embodiment of the present invention further provides an electronic device, see Fig. 9 , including a processor 901, a communication interface 902, a memory 903 and a communication bus 904, wherein the processor 901, the communication interface 902, and the memory 903 communicate with each other through the communication bus 904;

[0187] Memory 903, used for storing computer programs;

[0188] The processor 901 is used to implement the steps of the communication method based on the Modbus protocol and applied to a slave station in a communication system as described in any of the above embodiments when executing the program stored in the memory.

[0189] The electronic device provided by the embodiment of the present invention can realize the solution of continuous mapping addresses into actual registers to be operated in the operation instructions, and perform corresponding operations on the registers to be operated according to the process data request message. Therefore, the electronic device provided by the embodiment of the present invention can realize the modification or reading of multiple parameters with discontinuous register addresses in the same frame message, which can greatly reduce the complexity of communication between the master station and the slave station compared with the prior art, thereby improving the data processing efficiency of the communication system. In addition, the electronic device provided by the embodiment of the present invention can also realize the use of synchronization messages to control the timing of the effectiveness of instructions, so that the communication between multiple slave stations is more coordinated; and achieve efficient and synchronous multi-slave station control, and more effectively improve the utilization of bus bandwidth.

[0190] and Figure 1 Corresponding to the embodiment shown, an embodiment of the present invention further provides a computer-readable storage medium, in which a computer program is stored. When the computer program is executed by a processor, the steps of the communication method based on the Modbus protocol for a master station in a communication system described in any of the above embodiments are implemented.

[0191] The storage medium provided in the embodiment of the present invention can realize the modification or reading of multiple parameters with discontinuous register addresses in the same frame message, which can greatly reduce the complexity of communication between the master station and the slave station compared with the prior art, thereby improving the data processing efficiency of the communication system. In addition, the storage medium provided in the embodiment of the present invention can also realize the use of synchronization messages to control the timing of the effectiveness of instructions, so that the communication between multiple slave stations is more coordinated; and achieve efficient and synchronous multi-slave station control, and more effectively improve the utilization of bus bandwidth.

[0192] and Figure 3 Corresponding to the embodiment shown, an embodiment of the present invention further provides a computer-readable storage medium, in which a computer program is stored. When the computer program is executed by a processor, the steps of the communication method based on the Modbus protocol for any slave station in the communication system described in the above embodiments are implemented.

[0193] The storage medium provided in the embodiment of the present invention can realize the modification or reading of multiple parameters with discontinuous register addresses in the same frame message, which can greatly reduce the complexity of communication between the master station and the slave station compared with the prior art, thereby improving the data processing efficiency of the communication system. In addition, the storage medium provided in the embodiment of the present invention can also realize the use of synchronization messages to control the timing of the effectiveness of instructions, so that the communication between multiple slave stations is more coordinated; and achieve efficient and synchronous multi-slave station control, and more effectively improve the utilization of bus bandwidth.

[0194] Those skilled in the art will appreciate that embodiments of the present invention may be provided as methods, systems, or computer program products. Therefore, the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage and optical storage, etc.) containing computer-usable program code.

[0195] The present invention is described with reference to flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0196] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.

[0197] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.

[0198] Obviously, those skilled in the art can make various changes and modifications to the present invention without departing from the spirit and scope of the present invention. Thus, if these modifications or readings and variations of the present invention fall within the scope of the claims of the present invention and their equivalents, the present invention is also intended to include these changes and variations.

Claims

1. A communication method based on Modbus protocol, characterized in that, A master station applied to a communication system, wherein the communication system includes a master station and at least one slave station, and the method includes: Receive operation instructions; Determining the address of each register to be operated in the operation instruction; According to a preset mapping rule, a mapping register is configured for each register to be operated, and a frame of process data configuration mapping parameter message is generated, wherein the addresses of all the mapping registers can form a continuous address, and the process data configuration mapping parameter message stores a mapping relationship between the register to be operated and the mapping register; Generate a frame of process data request message according to the operation instruction and the mapping register corresponding to the register to be operated; Sending the process data configuration mapping parameter message and the process data request message to the target slave station, so that the target slave station performs corresponding operations on the register to be operated according to the process data configuration mapping parameter message and the process data request message, and returns a corresponding response message to the master station; The step of configuring a mapping register for each register to be operated according to a preset mapping rule and generating a frame of process data configuration mapping parameter message comprises: Allocating a register for each of the registers to be operated as a mapping register; respectively configuring parameter values ​​for the slave station address, function code, register address, number of registers, number of bytes, register value and check value of the check code, so as to establish a mapping relationship between the register to be operated and the mapping register corresponding to the register to be operated; and generating a frame of process data configuration mapping parameter message; The step of generating a frame of process data request message according to the operation instruction and the mapping register corresponding to the register to be operated includes: When the operation instruction is a write operation, according to the operation instruction and the mapping register corresponding to the register to be operated, a frame of process data write request message is generated in accordance with the structure of the address field, function code, message mode, number of registers, number of bytes, slave station address, register value and check value of the check code; When the operation instruction is a read operation, a frame of process data read request message is generated according to the operation instruction and the mapping register corresponding to the register to be operated, in accordance with the structure of the address field, function code, message mode, number of registers and check value of the check code.

2. The method according to claim 1, characterized in that: The parameter value corresponding to the slave address parameter item is the address range of the target slave station; the parameter value corresponding to the function code parameter item is the function code corresponding to the write operation or the read operation; the parameter value corresponding to the register address parameter item is the starting address of the mapping register corresponding to the first register to be operated in the operation instruction; the parameter value corresponding to the register quantity parameter item is the number of registers occupied by all the mapping registers; the parameter value corresponding to the byte number parameter item is the number of bytes occupied by all the mapping registers; the parameter value corresponding to one of the register value parameter items is the address and number of registers of one of the registers to be operated; the content corresponding to the check value item of the check code is the check value of the check code.

3. The method according to claim 1, characterized in that The content corresponding to the address domain item is the address of the target slave station; the content corresponding to the function code item is the function code corresponding to the write operation; the content corresponding to the message mode item is the identification information of the process data write request message; the content corresponding to the register quantity item is the number of mapping registers; the content corresponding to the byte number item is the number of bytes occupied by all the mapping registers; the content corresponding to the slave station address item is the address of the target slave station; the content corresponding to one of the register value items is the parameter value of a parameter to be written; the content corresponding to the check value item of the check code is the check value of the check code; The content corresponding to the address domain item is the address of the target slave station; the content corresponding to the function code item is the function code corresponding to the read operation; the content corresponding to the message mode item is the identification information of the process data read request message; the content corresponding to the register quantity item is the number of mapping registers; the content corresponding to the check value item of the check code is the check value of the check code.

4. The method according to claim 1, characterized in that The method further comprises: A synchronization message is sent to the target slave station, so that after receiving the synchronization message, all the target slave stations start to perform corresponding operations on the register to be operated according to the process data request message at the same time according to the event trigger time configured in the synchronization message.

5. A communication method based on Modbus protocol, characterized in that: A slave station applied to a communication system, wherein the communication system includes a master station and at least one slave station, and the method includes: Receiving a process data configuration mapping parameter message and a process data request message sent by the master station; wherein the process data configuration mapping parameter message stores a mapping relationship between a register to be operated and a mapping register; Parsing the process data configuration mapping parameter message and the process data request message, and confirming the type of the process data request message according to the content corresponding to the message mode item in the process data request message; When the type of the process data request message is a process data write request message, confirming the address of the target mapping register according to the contents corresponding to the register quantity item and the byte quantity item in the process data write request message; According to the address of the target mapping register and the mapping relationship between the register to be operated and the mapping register in the process data write configuration mapping parameter message, the address, number and number of bytes of the target register to be operated are confirmed; According to the content corresponding to the register value item in the process data write request message, confirm the to-be-written parameter corresponding to each target register to be operated; Writing the to-be-written parameter into the corresponding target to-be-operated register, and returning a corresponding response message to the master station; When the type of the process data request message is a process data read request message, confirming the address, number and number of bytes of the target register to be operated according to the content corresponding to the register quantity item in the process data read request message and the content corresponding to the register address item, the register quantity item, the byte number item and the register value item in the process data read configuration mapping parameter message; According to the address, number and number of bytes of the target register to be operated, the parameter value of the parameter to be read is obtained from the target register to be operated, and a response message including the parameter value is returned to the master station.

6. The method according to claim 5, characterized in that The method further comprises: Receiving a synchronization message sent by the master station; The synchronization message is parsed, and according to the event trigger time configured in the synchronization message and the process data request message, a corresponding operation is performed on the register to be operated.

7. A communication device based on Modbus protocol, characterized in that: The device comprises: A receiving module, used for receiving an operation instruction; A determination module, used to determine the address of each register to be operated in the operation instruction; A configuration module, configured to configure a mapping register for each register to be operated according to a preset mapping rule, and generate a frame of process data configuration mapping parameter message, wherein the addresses of all the mapping registers can form a continuous address, and the process data configuration mapping parameter message stores a mapping relationship between the register to be operated and the mapping register; the step of configuring a mapping register for each register to be operated according to the preset mapping rule, and generating a frame of process data configuration mapping parameter message, comprises: Allocating a register for each of the registers to be operated as a mapping register; respectively configuring parameter values ​​for the slave station address, function code, register address, number of registers, number of bytes, register value and check value of the check code, so as to establish a mapping relationship between the register to be operated and the mapping register corresponding to the register to be operated; and generating a frame of process data configuration mapping parameter message; A generating module, used for generating a frame of process data request message according to the operation instruction and the mapping register corresponding to the register to be operated; The step of generating a frame of process data request message according to the operation instruction and the mapping register corresponding to the register to be operated includes: When the operation instruction is a write operation, according to the operation instruction and the mapping register corresponding to the register to be operated, a frame of process data write request message is generated in accordance with the structure of the address field, function code, message mode, number of registers, number of bytes, slave station address, register value and check value of the check code; When the operation instruction is a read operation, a frame of process data read request message is generated according to the operation instruction and the mapping register corresponding to the register to be operated, in sequence according to the structure of the address field, function code, message mode, number of registers and check value of the check code; The sending module is used to send the process data configuration mapping parameter message and the process data request message to the target slave station, so that the target slave station performs corresponding operations on the register to be operated according to the process data configuration mapping parameter message and the process data request message, and returns a corresponding response message to the master station.

8. A communication device based on the Modbus protocol, the device comprising: A receiving module, used for receiving a process data configuration mapping parameter message and a process data request message sent by a master station; wherein the process data configuration mapping parameter message stores a mapping relationship between a register to be operated and a mapping register; A confirmation module, used to parse the process data configuration mapping parameter message and the process data request message, and confirm the type of the process data request message according to the content corresponding to the message mode item in the process data request message; when the type of the process data request message is a process data write request message, start the write module; when the type of the process data request message is a process data read request message, start the read module; The writing module is used for: Confirming the address of the target mapping register according to the contents corresponding to the register quantity item and the byte quantity item in the process data write request message; According to the address of the target mapping register and the mapping relationship between the register to be operated and the mapping register in the process data write configuration mapping parameter message, the address, number and number of bytes of the target register to be operated are confirmed; According to the content corresponding to the register value item in the process data write request message, confirm the to-be-written parameter corresponding to each target register to be operated; Writing the to-be-written parameter into the corresponding target to-be-operated register, and returning a corresponding response message to the master station; The reading module is used for: Confirm the address, number and number of bytes of the target register to be operated according to the content corresponding to the register quantity item in the process data read request message and the content corresponding to the register address item, register quantity item, byte number item and register value item in the process data read configuration mapping parameter message; According to the address, number and number of bytes of the target register to be operated, the parameter value of the parameter to be read is obtained from the target register to be operated, and a response message including the parameter value is returned to the master station.

9. An electronic device, characterized in that: It includes a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other through the communication bus; The memory is used to store computer programs; The processor, when used to execute the program stored in the memory, implements the method steps described in any one of claims 1-4 or 5-6.

10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method steps described in any one of claims 1-4 or 5-6 are implemented.