Communication system based on Modbus protocol

By configuring variable information data sets and register information in the Modbus master and slave station and using two-dimensional container storage, the problem of inconsistent communication between Modbus protocol devices is solved, achieving higher universality and reducing development and testing costs.

CN120498922APending Publication Date: 2025-08-15HANGZHOU GOLD ELECTRONICS EQUIP CO LTD
View PDF 5 Cites 0 Cited by

Patent Information

Application Number
CN202510828974.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-06-20
Publication Date
2025-08-15

AI Technical Summary

Technical Problem

In the field of industrial communications, the procedures standards of different equipment developers of the Modbus protocol are different, resulting in customized development during communication, which is poor in versatility and high in development and testing costs.

Method used

It provides a communication system based on the Modbus protocol. By storing configurable information data sets and register information in the Modbus master and slave station, storing register information in a two-dimensional container, and implementing data interaction through query and sub-message, supporting flexible configuration of register number and order.

Benefits of technology

Improves the universality of the Modbus protocol, reduces development and testing costs, and achieves compatibility with different devices.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120498922A_ABST
    Figure CN120498922A_ABST
Patent Text Reader

Abstract

The invention provides a communication system based on a Modbus protocol. A master station information data set in a Modbus master station is configurable; the corresponding register information is stored in a two-dimensional container, and the number of registers in the one-dimensional container of each master station is configurable; a slave station information data set in the Modbus slave station is configurable; corresponding register information is stored in a slave station one-dimensional container; the Modbus master station sends a first message based on the master station information data set and each master station one-dimensional container; and the Modbus slave station returns a response message based on the first message, the slave station information data set and the slave station one-dimensional container. According to the system, the master station information data set corresponding to the master station structural body stored in the Modbus master station can be configured, the number of registers inquired or set at a time can be configured, the slave station information data set corresponding to the slave station structural body stored in the Modbus slave station can be configured, the universality is improved, and the development and test cost is reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of communications, and in particular to a communication system based on the Modbus protocol. Background Art

[0002] As an industrial communication system bus protocol, Modbus is widely used in the industrial communication field. It mainly adopts a master-slave architecture. In actual application, different equipment development manufacturers have different program standards. As a result, when establishing communication between devices from different manufacturers, customized development programs are required, which have poor versatility and high development and testing costs. Summary of the Invention

[0003] The purpose of the embodiments of the present application is to provide a communication system based on the Modbus protocol to improve versatility and reduce development and testing costs.

[0004] The present invention provides a communication system based on the Modbus protocol, comprising: a Modbus master station and a Modbus slave station, wherein the Modbus master station stores a master station structure, a master station information data set in the master station structure is configurable, and the master station information data set at least includes: a valid bit extraction flag bit and a byte storage order of a multi-byte register; register information of registers corresponding to the Modbus master station is stored in a two-dimensional container, each master station one-dimensional container in the two-dimensional container includes register information of at least one register, and the number of registers in each master station one-dimensional container is configurable; the Modbus slave station stores a slave station structure, the slave station information data set in the slave station structure is configurable; register information of registers corresponding to the Modbus slave station is stored in the slave station one-dimensional container; the Modbus master station sends a first message to the Modbus slave station based on the master station information data set and the register information in each master station one-dimensional container; wherein the first message is a query message or a subordinate message; and the Modbus slave station returns a response message to the Modbus master station based on the first message, the slave station information data set, and the register information in the slave station one-dimensional container.

[0005] Furthermore, the Modbus master station is used to: use the first master station one-dimensional container as the current one-dimensional container, and send a query message for each register in the current one-dimensional container to the Modbus slave station; wherein the query message carries the site address of the Modbus slave station, the query function code, the starting register address corresponding to the current one-dimensional container, and the number of registers; when the response message received from the Modbus slave station is a normal query response message, based on the first specified information in the master station information data set, the first information corresponding to each register in the current one-dimensional container is parsed from the normal query response message. The first designated information includes at least: a message structure, a byte storage order, and a valid bit extraction flag of a query normal response message; calculating the first signal physical value corresponding to each first signal original value according to the scaling factor and the offset in the master station information data set; saving each first signal original value and each first signal physical value in the master station information data set; taking the next master station one-dimensional container as the new current one-dimensional container, and repeating the step of sending a query message for each register in the current one-dimensional container to the Modbus slave station until the current one-dimensional container is the last master station one-dimensional container.

[0006] Furthermore, the Modbus master station is used to: obtain the query message sending timestamp, and save the query message sending timestamp to the master station information data set; when receiving a response message returned by the Modbus slave station, obtain the first receiving timestamp of the response message, and save the first receiving timestamp to the master station information data set; calculate the first time interval between the sending timestamp and the first receiving timestamp, and save the first time interval in the master station information data set; when the received response message is a query exception response message, obtain a preset query time interval from the master station information data set, and when the query time interval is reached, repeat the step of sending a query message for the register in the current one-dimensional container to the Modbus slave station.

[0007] Furthermore, the Modbus slave station is used to: determine whether the query message is correct after receiving the query message; if the query message is correct, traverse the one-dimensional container of the slave station; use the register corresponding to the starting register address traversed as the current register, and obtain the second signal physical value corresponding to the current register; calculate the second signal original value corresponding to the current register based on the second signal physical value, the scaling factor and the offset in the slave station information data set; use the next register as the new current register, and repeat the step of obtaining the second signal physical value corresponding to the current register until the number of traversed registers reaches the number of registers carried in the query message; extract the flag bit based on each second signal original value, the byte storage order and the valid bit in the slave station information data set, generate a query normal response message, and return the query normal response message to the Modbus master station; if the query message is erroneous, generate a query exception response message, and return the query exception response message to the Modbus master station; wherein, the query exception response message carries the error type.

[0008] Furthermore, the Modbus master station is used to: use the first master station one-dimensional container as the current one-dimensional container, obtain the sending flag corresponding to the current one-dimensional container; if the sending flag indicates sending a subordinate message for the current one-dimensional container, obtain the third signal physical value corresponding to each register in the current one-dimensional container; calculate the third signal original value corresponding to each third signal physical value according to the scaling factor and offset in the master station information data set; extract the flag and byte storage order based on each third signal original value and the valid bits in the master station information data set to obtain data area information; generate a subordinate message based on the data area information and the second specified information, and send it to the M The Modbus slave station sends a subordinate message; wherein the second specified information includes at least: a station address of the Modbus slave station, a subordinate function code, a starting register address corresponding to the current one-dimensional container, and the number of registers; when the received response message is a subordinate normal response message, it is determined that the subordinate message is sent completely, and a send flag corresponding to the current one-dimensional container is updated, wherein the updated send flag is used to indicate that the subordinate message for the current one-dimensional container is not sent; the next master station one-dimensional container is used as the new current one-dimensional container, and the step of obtaining the send flag corresponding to the current one-dimensional container is repeated until the current one-dimensional container is the last master station one-dimensional container.

[0009] Furthermore, the Modbus master station is used to: obtain the sending timestamp of the subordinate message, and save the sending timestamp of the subordinate message to the master station information data set; when receiving a response message returned by the Modbus slave station, obtain the second receiving timestamp of the response message, and save the second receiving timestamp to the master station information data set; when the received response message is a subordinate abnormal response message, obtain the preset subordinate time interval from the master station information data set, and when the subordinate time interval is reached, repeat the step of sending the subordinate message to the Modbus slave station.

[0010] Furthermore, the Modbus slave station is used to: upon receiving a subordinate message, determine whether the subordinate message is correct; if the subordinate message is correct, traverse the one-dimensional container of the slave station; use the register corresponding to the traversed starting register address as the current register, extract the flag bit according to the byte storage order and valid bit of the current register, and parse out the fourth signal original value corresponding to the current register from the subordinate message; calculate the fourth signal physical value corresponding to the fourth signal original value according to the fourth signal original value, the scaling factor and the offset in the slave station information data set; save the fourth signal original value and the fourth signal physical value to the slave station information data set; use the next register as the new current register, repeat the steps of extracting the flag bit according to the byte storage order and valid bit of the current register, and parsing out the fourth signal original value corresponding to the current register from the subordinate message, until the fourth signal original value and the fourth signal physical value corresponding to the last register in the current one-dimensional container are saved in the slave station information data set; return the subordinate success information to the Modbus master station.

[0011] Furthermore, the Modbus slave station is used to: if the subordinate message is erroneous, generate a subordinate exception response message and return the subordinate exception response message to the Modbus master station; wherein the subordinate exception response message carries the error type.

[0012] Furthermore, the target device is a Modbus master station or a Modbus slave station; the target device is used to: receive an acquisition request for a target signal to be acquired sent by the application layer through a preset first interface function; wherein the acquisition request carries: the target signal name, target channel number and target variable address of the target signal to be acquired; through the channel corresponding to the target channel number, based on the target signal name, traverse the target information data set; wherein, if the target device is a Modbus master station, the target information data set is a master station information data set; if the target device is a Modbus slave station, the target information data set is a slave station information data set; if the target signal name is traversed, obtain the target signal value corresponding to the target signal name; return the target signal value to the application layer, so that the application layer saves the target signal value to the location indicated by the target variable address.

[0013] Furthermore, the Modbus master station is also used to: receive a configuration request for the target signal to be configured, sent by the application layer through a preset second interface function; wherein the configuration request carries: the name of the signal to be configured, the channel number to be configured and the signal value to be written of the target signal to be configured; traverse the master station information data set based on the name of the signal to be configured; if the name of the signal to be configured is traversed, the signal value to be written is saved to the master station information data set through the channel corresponding to the channel number to be configured.

[0014] The present invention provides a Modbus protocol-based communication system, wherein a master information data set in a Modbus master station is configurable; corresponding register information is stored in a two-dimensional container, wherein the number of registers in each master station one-dimensional container is configurable; a slave information data set in a Modbus slave station is configurable; corresponding register information is stored in the slave station one-dimensional container; the Modbus master station sends a first message based on the master information data set and each master station one-dimensional container; and the Modbus slave station returns a response message based on the first message, the slave information data set, and the slave station one-dimensional container. The system has a configurable master information data set corresponding to a master station structure stored in the Modbus master station, a configurable number of registers that can be queried or assigned at one time, and a configurable slave information data set corresponding to a slave station structure stored in the Modbus slave station. This system improves versatility and reduces development and testing costs. BRIEF DESCRIPTION OF THE DRAWINGS

[0015] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the following is a brief introduction to the drawings required for use in the embodiments of the present application. It should be understood that the following drawings only show certain embodiments of the present application and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other relevant drawings can be obtained based on these drawings without creative work.

[0016] Figure 1 A schematic diagram of a communication system based on the Modbus protocol provided in an embodiment of the present application;

[0017] Figure 2 A schematic diagram of a communication process based on the Modbus protocol provided in an embodiment of the present application;

[0018] Figure 3 A flowchart of processing a received first message in a slave station mode provided in an embodiment of the present application;

[0019] Figure 4 A flowchart of a Modbus message encoding, sending, receiving, parsing, and storing method when a master station queries the status of a slave station in a master station mode provided in an embodiment of the present application;

[0020] Figure 5 A flow chart of a method for obtaining a signal value through an API function at the application layer provided in an embodiment of the present application;

[0021] Figure 6 The present invention provides a flowchart of a method for encoding, sending, receiving, parsing, and storing Modbus messages in master mode when the master has slave register values. DETAILED DESCRIPTION

[0022] The technical solutions in the embodiments of the present application will be described below in conjunction with the drawings in the embodiments of the present application.

[0023] Currently, Modbus is widely used in the field of industrial communications. It mainly adopts a master-slave architecture. In actual application, different equipment development manufacturers have different program standards. As a result, when establishing communication between devices from different manufacturers, customized development programs are required, which has poor universality and high development and testing costs. The details are as follows:

[0024] 1. Register query / sub-setting methods are not standardized. For example, according to the Modbus standard, when a master station queries the status of a slave station, it can query a single register or query multiple registers continuously. However, some manufacturers' devices developed as slave stations do not support any single register query and can only query multiple registers continuously at one time. In addition, the register starting address and number of continuous queries required by devices developed by different manufacturers are not unified. The same problem also exists in the register sub-setting of the master station.

[0025] 2. The function code usage is not standard. For example, according to the Modbus standard, the slave station should use the function code 0x01 to reply to the coil status query, and each register occupies 1 bit. However, some manufacturers' devices actually use the function code 0x04 to reply to the coil status query, and each register occupies 2 bytes, including the status information of 16 coils.

[0026] 3. Issues with the byte storage order of multi-byte (>2 bytes) registers. For example, for U32 type registers, the 4-byte storage order is ABCD, CDAB, DCBA, and BADC. The current solution is to rewrite a set of programs for each project, which has poor versatility.

[0027] Based on this, an embodiment of the present invention provides a communication system based on the Modbus protocol. This technology can be applied to applications that use the Modbus protocol for communication.

[0028] To facilitate understanding of this embodiment, firstly, a communication system based on the Modbus protocol disclosed in an embodiment of the present invention is introduced. Figure 1As shown, the system includes: a Modbus master station and a Modbus slave station. The Modbus master station and the Modbus slave station are two types of device roles defined in the Modbus protocol, which are used to realize data interaction between devices in the communication system; the Modbus master station stores a master station structure, and the master station information data set in the master station structure is configurable. The master station information data set at least includes: a valid bit extraction flag bit and a byte storage order of a multi-byte register; the above-mentioned master station structure can be understood as a whole composed of multiple different types of variables; the value of each variable in the master station structure can constitute a master station information data set, and the user can configure the data in the master station information data set according to actual needs; the register information of the corresponding register of the Modbus master station is stored in a two-dimensional container, and each master station one-dimensional container in the two-dimensional container includes register information of at least one register, and the number of registers in each master station one-dimensional container is configurable; For the Modbus master, the register information of all registers belonging to the same group can be stored in the same master one-dimensional container, and then each master one-dimensional container can be used as an element and stored in a two-dimensional container. The number of registers in each master one-dimensional container is configurable without modifying the code. For example, there are 10 registers numbered 1 to 10. The Modbus slave requires that registers numbered 1 to 4 must be queried at one time, and registers numbered 5 to 10 must be queried at one time. In this way, the register information of registers numbered 1 to 4 can be placed in the first master one-dimensional container, and the register information of registers numbered 5 to 10 can be placed in the second master one-dimensional container, and then these two master one-dimensional containers form a two-dimensional container. The overall idea is that each element in the two-dimensional container is a master one-dimensional container, and the registers in the same master one-dimensional container all require one frame of message to complete the setting or query of registers. In other words, the two dimensions of the two-dimensional container corresponding to the Modbus master station, the first dimension determines the number of registers that need to be queried or set in the current frame message, and the second dimension determines the register address, function code and other detailed information to be queried or set in the current frame message.

[0029] The Modbus slave station stores a slave station structure, and the slave station information data set in the slave station structure is configurable; the register information of the corresponding register of the Modbus slave station is stored in the slave station one-dimensional container; the slave station structure can also be understood as a whole composed of multiple different types of variables; the value of each variable in the slave station structure can constitute the slave station information data set, and the user can configure the data in the slave station information data set according to actual needs; for the Modbus slave station, the read register information can be directly stored in the slave station one-dimensional container.

[0030] In practical applications, a structure is usually defined first to load the configuration file information. The structure specifically includes: site mode (master / slave), send flag (valid only for master mode messages), signal name, register address, register type (query / subordinate), data type, valid bit extraction flag, scaling factor, offset, function code, initial value, byte storage order, register group, signal original value, signal physical value, query message timestamp, query response message timestamp, time interval between two adjacent queries, time interval between two adjacent responses, time interval between adjacent queries and responses, subordinate message timestamp, subordinate response message timestamp, time interval between adjacent subordinate and subordinate responses, etc. After defining the structure, you can read the pre-configured configuration file containing Modbus protocol information, obtain the required information in the above structure, and store it in different containers according to the master and slave stations. Usually, when defining the structure, the container is defined. After reading the information in the configuration file, you can directly fill the read information into the container.

[0031] The Modbus master sends a first message to the Modbus slave based on the master information data set and the register information in each master's one-dimensional container; wherein the first message is a query message or a subordinate message; and the Modbus slave returns a response message to the Modbus master based on the first message, the slave information data set, and the register information in the slave's one-dimensional container. In actual implementation, the Modbus master can send a query message or a subordinate message to the Modbus slave based on the master information data set and the register information in each master's one-dimensional container. After receiving the query message or the subordinate message, the Modbus slave can return a corresponding response message to the Modbus master based on the slave information data set and the register information in the slave's one-dimensional container. For example, for a query message, the response message returned by the Modbus slave to the Modbus master may be a normal query response message or a query exception response message; for a subordinate message, the response message returned by the Modbus slave to the Modbus master may be a normal subordinate response message or a subordinate exception response message.

[0032] In the above-mentioned communication system based on the Modbus protocol, the master station information data set corresponding to the master station structure stored in the Modbus master station is configurable, and the number of one-time queries or subordinate registers is configurable. The slave station information data set corresponding to the slave station structure stored in the Modbus slave station is configurable. This system improves versatility and reduces development and testing costs.

[0033] Furthermore, the Modbus master station is used to: use the first master station one-dimensional container as the current one-dimensional container, and send a query message for each register in the current one-dimensional container to the Modbus slave station; wherein the query message carries the site address of the Modbus slave station, the query function code, the starting register address corresponding to the current one-dimensional container, and the number of registers; in actual implementation, the first master station one-dimensional container can be used as the current one-dimensional container. Since the registers in the current one-dimensional container require a frame of message to complete the query, the query message can be encoded according to the site address of the Modbus slave station, the query function code, the starting register address corresponding to the current one-dimensional container, and the number of registers to obtain the query message, and the query message is sent to the Modbus slave station to request to query the register information of each register in the current one-dimensional container.

[0034] When the response message received from the Modbus slave station is a normal query response message, the Modbus slave station parses the normal query response message to obtain the first signal original value corresponding to each register in the current one-dimensional container based on the first specified information in the master station information data set; wherein the first specified information at least includes: the message structure, byte storage order, and valid bit extraction flag of the normal query response message. In actual implementation, if the query message response is normal, the Modbus slave station may return a normal query response message to the Modbus master station. At this time, the Modbus master station may parse the first signal original value corresponding to each register in the current one-dimensional container based on the first specified information, such as the message structure, byte storage order, and valid bit extraction flag of the normal query response message.

[0035] Based on the scaling factor and offset in the master station information data set, the first signal physical value corresponding to each first signal raw value is calculated; each first signal raw value and each first signal physical value are stored in the master station information data set; the next master station one-dimensional container is used as the new current one-dimensional container, and the step of sending a query message to the Modbus slave for each register in the current one-dimensional container is repeated until the current one-dimensional container becomes the last master station one-dimensional container. The scaling factor and offset described above can be configured according to actual needs. In actual implementation, after parsing the first signal raw value corresponding to each register in the current one-dimensional container, the Modbus master can calculate the first signal physical value corresponding to each first signal raw value based on the scaling factor and offset in the master station information data set, and store each first signal raw value and each first signal physical value in the master station information data set. The first dimension index number of the master station one-dimensional container is incremented by 1, i.e., the next master station one-dimensional container is used as the new current one-dimensional container, and the above process is repeated to send the next query message until every register in the last master station one-dimensional container is queried.

[0036] Considering that the physical value stored in the register changes all the time, the query of the message is performed periodically. Therefore, after all query messages are sent and responded correctly, the first-dimensional index number is set to 0, and it is determined whether the current time reaches the query time interval. If it reaches it, the first master station one-dimensional container is immediately used as the current one-dimensional container, and the query message for each register in the current one-dimensional container is sent to the Modbus slave station. If it does not reach it, the waiting time is reached, and then the first master station one-dimensional container is used as the current one-dimensional container, and the query message for each register in the current one-dimensional container is sent to the Modbus slave station.

[0037] Furthermore, the Modbus master is used to: obtain the query message sending timestamp and save the query message sending timestamp to the master information data set; when receiving the reply message returned by the Modbus slave, obtain the first receiving timestamp of the reply message and save the first receiving timestamp to the master information data set; calculate the first time interval between the sending timestamp and the first receiving timestamp and save the first time interval in the master information data set; in actual implementation, after the Modbus master sends a query message to the Modbus slave, it can obtain the sending time of the query message, that is, the query message sending timestamp, and store the query message sending timestamp in the query timestamp of the master structure. When monitoring the reply message returned by the Modbus slave to the query message, it can obtain the receiving time of the reply message, that is, the first receiving timestamp, and store the first receiving timestamp in the query reply timestamp of the master structure. Calculate the first time interval between the sending timestamp and the first receiving timestamp and store it in the adjacent query and reply response time interval of the master structure.

[0038] When the received response message is a query exception response message, a preset query time interval is obtained from the master station information data set. When the query time interval is reached, the step of sending a query message to the Modbus slave station for the register in the current one-dimensional container is repeated. The query time interval is the time interval between two consecutive query messages, that is, the time interval between two consecutive query messages. The query time interval can be set according to actual needs. When the response message received by the Modbus master station is a query exception response message, the Modbus master station can wait until the query time interval is reached before sending the current query message again.

[0039] Furthermore, the Modbus slave is used to: after receiving the query message, determine whether the query message is correct, for example, whether the query register is out of bounds (for example, the Modbus slave has 10 registers, numbered 1 to 10, if the Modbus master wants to query the register information of register numbered 11, it is considered out of bounds), CRC (Cyclic Redundancy The CRC check is performed to see whether it passes, etc., wherein the CRC check method can refer to the relevant technology and will not be repeated here; if the query message is correct, traverse the one-dimensional container of the slave station; take the register corresponding to the traversed starting register address as the current register, and obtain the second signal physical value corresponding to the current register; calculate the second signal original value corresponding to the current register according to the second signal physical value, the scaling factor and the offset in the slave station information data set; take the next traversed register as the new current register, and repeat the step of obtaining the second signal physical value corresponding to the current register until the number of traversed registers reaches the number of registers carried in the query message; generate a normal query response message according to each second signal original value, the byte storage order and the valid bit extraction flag in the slave station information data set, and return the normal query response message to the Modbus master station.

[0040] In actual implementation, after determining that the query message is correct, the one-dimensional container of the slave station can be traversed according to the starting register address of the query. After matching the starting register address, the register corresponding to the starting register address can be used as the current register, and the physical value of the second signal corresponding to the current register is taken out. The original value of the second signal is converted according to the scaling factor and offset in the slave station information data set. The traversal is continued according to the number of registers carried in the query message, and each traversed register is used as the new current register. The above process is repeated to obtain the original value of the second signal corresponding to each register. The flag bit is extracted according to the byte storage order and valid bit in the slave station information data set, and the normal query response message is encoded and sent to the Modbus master station.

[0041] If the query message is erroneous, a query exception response message is generated and returned to the Modbus master. The query exception response message carries the error type, which may be register out of bounds, CRC check failure, etc. In actual implementation, if a query message error is detected, a query exception response message may be generated based on the error type and sent to the Modbus master.

[0042] Furthermore, the Modbus master is configured to use the first master one-dimensional container as the current one-dimensional container and obtain a send flag corresponding to the current one-dimensional container. The send flag can be set based on actual needs. For example, if the send flag is 0, it indicates that the subordinate message for the current one-dimensional container does not need to be sent. If the send flag indicates that the subordinate message for the current one-dimensional container is not to be sent, for example, if the send flag is 0, the first-dimensional index number of the master one-dimensional container can be increased by 1, that is, the next master one-dimensional container is used as the new current one-dimensional container, and the step of obtaining the send flag corresponding to the current one-dimensional container is repeated.

[0043] If the sending flag indicates sending a subordinate message for the current one-dimensional container, obtain the third signal physical value corresponding to each register in the current one-dimensional container; calculate the third signal original value corresponding to each third signal physical value according to the scaling factor and offset in the master station information data set; extract the flag bit and byte storage order based on each third signal original value and the valid bits in the master station information data set to obtain data area information; generate a subordinate message based on the data area information and the second specified information, and send the subordinate message to the Modbus slave station; wherein the second specified information includes at least: the site address of the Modbus slave station, the subordinate function code, the starting register address corresponding to the current one-dimensional container, and the number of registers.

[0044] In actual implementation, if the send flag indicates sending a subordinate message for the current one-dimensional container, the physical value of the third signal corresponding to each register in the current one-dimensional container can be retrieved and converted to the corresponding original value of the third signal based on the scaling factor and offset in the master station information data set. The flag bit and byte storage order are then extracted based on the valid bits in the master station information data set and encoded into data area information. Based on the Modbus slave station's station address, subordinate function code, the starting register address and number of registers corresponding to the current one-dimensional container, and other information, this is further encoded into a complete subordinate message and sent to the Modbus slave station.

[0045] When the received response message is a normal response message for a subordinate, it is determined that the subordinate message has been sent, and the send flag corresponding to the current one-dimensional container is updated. The updated send flag is used to indicate that the subordinate message for the current one-dimensional container will not be sent. For example, the send flag 1 can be changed to 0. The next master station one-dimensional container is used as the new current one-dimensional container, and the step of obtaining the send flag corresponding to the current one-dimensional container is repeated until the current one-dimensional container is the last master station one-dimensional container. The first dimension index number of the master station one-dimensional container is increased by 1, that is, the next master station one-dimensional container is used as the new current one-dimensional container. The above process is repeated to send the next subordinate message until the subordinate is completed for each register in the last master station one-dimensional container.

[0046] Furthermore, the Modbus master station is used to: obtain the sending timestamp of the subordinate message, and save the sending timestamp of the subordinate message to the master station information data set; when receiving the response message returned by the Modbus slave station, obtain the second receiving timestamp of the response message, and save the second receiving timestamp to the master station information data set; in actual implementation, after the Modbus master station sends the subordinate message to the Modbus slave station, it can obtain the sending time of the subordinate message, that is, the above-mentioned sending timestamp of the subordinate message, and store the sending timestamp of the subordinate message in the subordinate timestamp of the master station structure. When monitoring the response message returned by the Modbus slave station for the subordinate message, it can obtain the receiving time of the response message, that is, the second receiving timestamp, and store the second receiving timestamp in the subordinate response timestamp of the master station structure. When the received response message is a subordinate abnormal response message, obtain the preset subordinate time interval from the master station information data set, and when the subordinate time interval is reached, repeat the step of sending the subordinate message to the Modbus slave station. The above-mentioned subordinate time interval is specifically the time interval between two adjacent subordinate messages, and the subordinate time interval can be set according to actual needs; when the response message received by the Modbus master station is a subordinate abnormal response message, it can wait until the subordinate time interval arrives and then send the current subordinate message again.

[0047] Furthermore, the Modbus slave is used to: after receiving the subordinate message, determine whether the subordinate message is correct, for example, whether the register is out of bounds (for example, the Modbus slave has 10 registers, numbered 1 to 10, if the Modbus master wants to set the register numbered 11, it is considered out of bounds), CRC (Cyclic Redundancy Check) Check, cyclic redundancy check) check is passed, etc.; if the subordinate message is correct, traverse the one-dimensional container of the slave station; the register corresponding to the traversed starting register address is used as the current register, and the flag bit is extracted according to the byte storage order and valid bit of the current register, and the fourth signal original value corresponding to the current register is parsed from the subordinate message; according to the fourth signal original value, the scaling factor and the offset in the slave information data set, the fourth signal physical value corresponding to the fourth signal original value is calculated; the fourth signal original value and the fourth signal physical value are saved in the slave information data set; in actual implementation, the Modbus slave station can traverse the one-dimensional container of the slave station according to the subordinate starting register address after determining that the subordinate message is correct. After matching the starting register address, the register corresponding to the starting register address can be used as the current register, and the flag bit is extracted according to the byte storage order and valid bit of the current register, and the fourth signal original value corresponding to the current register is parsed from the subordinate message, and the scaling factor and offset in the slave information data set are converted to obtain the fourth signal physical value, and the fourth signal original value and the fourth signal physical value are saved in the slave information data set.

[0048] Use the next register as the new current register, repeat the steps of extracting the flag bit according to the byte storage order and valid bit of the current register, and parsing the fourth signal original value corresponding to the current register from the subordinate message, until the fourth signal original value and the fourth signal physical value corresponding to the last register in the current one-dimensional container are saved in the slave information data set; return the subordinate success information to the Modbus master station.

[0049] Furthermore, the Modbus slave station is used to: if a subordinate message error occurs, generate a subordinate exception response message and return the subordinate exception response message to the Modbus master station; wherein the subordinate exception response message carries an error type; the error type may be: register out of bounds, CRC check failure, etc.; in actual application, if a subordinate message error is detected, a subordinate exception response message can be generated according to the error type and sent to the Modbus master station.

[0050] Furthermore, the target device is a Modbus master station or a Modbus slave station; the target device is used to: receive an acquisition request for a target signal to be acquired sent by the application layer through a preset first interface function; wherein the acquisition request carries: the target signal name, target channel number and target variable address of the target signal to be acquired; through the channel corresponding to the target channel number, based on the target signal name, traverse the target information data set; wherein, if the target device is a Modbus master station, the target information data set is a master station information data set; if the target device is a Modbus slave station, the target information data set is a slave station information data set; if the target signal name is traversed, obtain the target signal value corresponding to the target signal name; return the target signal value to the application layer, so that the application layer saves the target signal value to the location indicated by the target variable address.

[0051] The above-mentioned first interface function can also be called an API (Application Programming Interface) function; in actual implementation, the first interface function can be pre-encapsulated, and the application layer can send an acquisition request to the target device through the first interface function to request to obtain the target signal value corresponding to the target signal to be obtained; after the target device receives the acquisition request, it can search for the container for storing register information in the target device according to the target signal name of the target signal to be obtained through the channel corresponding to the target channel number, and after matching the target signal name, it can take out the corresponding target signal value and return the target signal value to the application layer. After receiving the target signal value, the application layer can save the target signal value to the location indicated by the target variable address.

[0052] Furthermore, the Modbus master station is also used to: receive a configuration request for the target signal to be configured, sent by the application layer through a preset second interface function; wherein the configuration request carries: the name of the signal to be configured, the channel number to be configured and the signal value to be written of the target signal to be configured; traverse the master station information data set based on the name of the signal to be configured; if the name of the signal to be configured is traversed, the signal value to be written is saved to the master station information data set through the channel corresponding to the channel number to be configured.

[0053] The above-mentioned second interface function can also be called an API function. The second interface function may be the same as or different from the first interface function. In actual implementation, the second interface function can be pre-encapsulated, and the application layer can send a subordinate request to the Modbus master station through the second interface function to request to write the signal value to be written for the target signal to be set; after the Modbus master station receives the subordinate request, it can search for the container for storing register information in the Modbus master station according to the name of the signal to be set of the target signal to be set, and after matching the name of the signal to be set, it can assign the signal value to be written to the corresponding register through the channel corresponding to the channel number to be set, and at the same time, it can also set the send flag position corresponding to the one-dimensional container of the master station where the register is located to 1 as needed, that is, it can indicate the sending of the subordinate message for the one-dimensional container of the master station.

[0054] For further understanding of the above embodiments, see Figure 2 The figure shows a schematic diagram of a communication process based on the Modbus protocol, which shows the implementation process of reading the Modbus protocol configuration file, adding necessary information, and storing it locally. It mainly includes steps S101 to S103, which are detailed as follows:

[0055] Step S101, create a new structure to store the original information of the Modbus protocol configuration file, for example, it can include SigName (signal name), RegAddr (register address), RegType (register type), DataType (data type), hardware port number, site number, signal set, etc. After analysis, it is convenient for the software to parse the subsequent message information, auxiliary judgment information for communication loss, Modbus master station to actively query the Modbus slave station status cycle, etc., to ensure that the Modbus message protocol information finally stored locally is convenient for the API function to obtain the signal value at any time and set the signal value at any time. At the same time, it can be compatible with the problems of limited number of message query / register setting, non-standard use of function code, flexible and changeable byte storage order, etc. without modifying the code. The details are as follows:

[0056] ① Define a structure type for each signal in the Modbus protocol configuration file. The specific variables and types are as follows:

[0057]

[0058]

[0059] In the above structure, most of the information is easy to understand, so I will not go into details. I will only introduce some parameters as follows:

[0060] a. "StationMode" is used to indicate the station mode information, with two options: master station and slave station;

[0061] b. "MsgSendFlag" is used to indicate the message sending flag information. Only in the master mode, when the register is set, each time the upper layer requests the register through the API function, the flag will be set to 1. After the message is sent and the slave station replies that it is received correctly, the flag will be set to 0 and will not be sent again in the next cycle. In other modes, this flag is not effective;

[0062] c. "RegType" is used to indicate whether the current register is read or written. It is only valid in master mode. If it is read, the master will periodically send query messages according to the set query time interval. If it is written, the master will send the following message according to the value of the message sending flag "MsgSendFlag";

[0063] d. "ValidBitFlag" is used to indicate the valid bit of the current signal in the register. For third-party devices developed by some manufacturers that use a multi-byte register to transmit multiple switch values, each signal can be distinguished by this flag bit. For example, if a 2-byte register is used to transmit 16 status bits, the value of the first status bit is the register value & ValidBitFlag;

[0064] e. "ByteOrder" is used to indicate the byte storage order of the current register, making the byte storage order of multi-byte registers in memory configurable, and expanding the scope of compatibility with different Modbus protocols without modifying the code;

[0065] f. "RegGroup" is used to indicate the group to which a register belongs. It is only valid in master mode. When the master sends a query or set message, it will query or set all registers in the same group at once. This allows the number of registers that can be queried or set at one time to be configurable. This is compatible with some Modbus slave devices developed by third-party manufacturers that do not support querying or setting an arbitrary number of registers at one time, thus expanding the scope of compatibility with different Modbus protocols without modifying the code.

[0066] g. "strValue" is used to store the original value of the signal, which is the value obtained by extracting the current register field from the original message and performing a bitwise AND operation with ValidBitFlag;

[0067] h. "Value" is used to store the physical value of the signal, that is, the value obtained by calculating the scaling factor and offset after the original value of the signal in step g.

[0068] The remaining multiple timestamp information is mainly used to evaluate the response speed of the Modbus slave after the Modbus master sends a query or a command, as well as to clear data and report communication loss when the Modbus slave does not reply to the message for a certain period of time.

[0069] Based on the structure (ModbusDetailParam) in ①, define the secondary structure as follows:

[0070]

[0071] The above two secondary structures are used to store register information in master mode and slave mode respectively. QString Port represents the hardware interface used for Modbus communication, such as RS485_0 (ModbusRTU) and LAN_0 (ModbusTCP); QString StationAddress represents the station address of Modbus communication; for Modbus master and Modbus slave, the contents stored in the SingalList container are different, as follows:

[0072] i. In master mode, SingalList is a two-dimensional space. The register set that needs to be read or written at once is stored in a one-dimensional container as an element of the two-dimensional space. That is, SingalList[i] is a one-dimensional space, which contains multiple register information (i.e., SingalList[i][j] - j is a positive integer ≥ 0), which needs to be written or read at once.

[0073] ii. In slave mode, SingalList is a one-dimensional space. SingalList[i] represents the signal information of a register. The Modbus master queries or writes several registers at a time, and the Modbus slave reports or stores the value information of several registers accordingly.

[0074] Step S102, read the Modbus protocol configuration file and extract key information such as site mode, SigName, RegAddr, RegType, DateType, valid bit extraction flag, Scale, Offset, FunCode, Inivalue, ByteOrder, and RegGroup.

[0075] Step S103, add necessary information based on the Modbus protocol configuration file and store it, for example, the original value of the signal, the physical value of the signal, the sending flag, the query message timestamp, the query response message timestamp, the time interval between two adjacent queries, the time interval between two adjacent responses, the time interval between adjacent queries and responses, and other information can be added and stored in the above structure.

[0076] See also Figure 3The flowchart of processing a received first message in a slave mode shown in FIG. 1 may specifically include receiving and replying to a query and a subordinate command message from a master station, and a message parsing and encoding method, mainly including steps S201 to S205, as detailed below:

[0077] Step S201: A Modbus message is received on the bus, and the integrity and correctness of the Modbus message are determined. If it is correct, it is stored in the slave station receive buffer area. If it is incorrect, the Modbus message continues to be received.

[0078] Step S202, another thread monitors that the slave station receive buffer is not empty, takes out a Modbus message and extracts the bytes representing the station address, and compares it with the QStringStationAddress in the above second structure (corresponding to the secondary structure in the above slave station mode). If they are consistent, proceed to the next step, otherwise continue to compare with the station address of the other second structure;

[0079] Step S203, take out the byte representing the function code in the received Modbus message, determine whether the current Modbus message is a register information message or a register information query message (Modbus defines the function code and the specific function of each function code, such as 0x06, which indicates a single register), and proceed to the next step;

[0080] Step S204: If it is a query message, extract the response information code from the first structure (corresponding to the structure constructed in step ① above) according to the bytes representing the read register address and the number of registers in the Modbus message and send it out;

[0081] Step S205: If it is a subordinate message, then according to the information such as the subordinate register address, the number of registers, the subordinate value, etc. represented in the Modbus message, and the message value stored in the first structure, the scaling factor, offset, data valid bits, etc. are converted to obtain the physical value and stored in the signal physical value in the first structure, and the subordinate result message of the master station is replied.

[0082] See also Figure 4 The flowchart of the Modbus message encoding, sending, receiving, parsing and storing method shown in the master station mode when the master station queries the slave station status mainly includes steps S301 to S303, which are detailed as follows:

[0083] Step S301, when the set query cycle is reached, a corresponding query message is automatically added to the master station query slave station message buffer area. It should be noted that the same group of registers in the second structure of the master station querying the slave station need to be queried at one time, and different groups of registers are queried separately; (message encoding method: the station address uses the StationAddress in the first structure, the function code uses the FunCode of the register group currently to be queried, the starting address of the register to be queried uses the starting register address of the register group currently to be queried, the number of registers to be queried uses the number of registers stored in the register group currently to be queried, and the remaining information such as CRC check is a general function and will not be repeated here. It is encoded according to the Modbus message format and sent out and the sending time is recorded).

[0084] Perform message judgment: If a message is received from the slave within the specified time interval, judge the integrity and correctness of the message. If the message is complete and correct, proceed to the next step.

[0085] Step 302: Parse the message and extract the specified bytes from the message replied by the slave station according to the queried register starting address, quantity, valid bits of the signal in the register, etc., convert them into the original value of the message, and store them in the strValue signal original value corresponding to the first structure. Then, calculate the physical value based on the scaling factor and offset, and store it in the Value signal physical value corresponding to the first structure.

[0086] See also Figure 5 The flowchart of a method for the application layer to obtain signal values through API functions is shown. By encapsulating the API function, the application layer can obtain the value corresponding to any signal by simply calling the signal acquisition API function and passing in the signal name to be obtained, the variable address to store the signal value, etc., to obtain the corresponding signal value. The details are as follows:

[0087] Step S401, obtaining data through the API function, specifically, the API function Modbus_Get_Signal(QString RS485_ChanelIndex, QString sigName, QString&sigValue) can be encapsulated, and the function parameters are the RS485 channel number, the signal name and the variable address for storing the signal value.

[0088] In step S402, the API function searches for the local Modbus protocol file storage structure according to the RS485 channel number and signal name, and traverses the "SingalList" container in the structure.

[0089] Step S403: After the corresponding signal name is found, its signal value is obtained and assigned to "sigValue".

[0090] See also Figure 6 The flowchart of the Modbus message encoding, sending, receiving, parsing, and storage method is shown in a master mode, where the master sets the value of the slave register. Specifically, in the master mode, the Modbus master sends a command to the Modbus slave, encapsulating the API function. The application layer can modify the value of any signal in the structure through the API function and trigger the message sending command. The message is sent, encoded, and parsed. The Modbus slave responds with the result and retransmits or ends the message accordingly. The method mainly includes steps S501 to S505, which are detailed as follows:

[0091] Step S501: Send data through the API function. Specifically, the API function Modbus_Set_Signal(QString RS485_ChanelIndex, QString sigName, QString sigValue) can be encapsulated, and the function parameters are the RS485 channel number, the signal name, and the signal value to be set.

[0092] Step 502: perform information search, traverse the SingalList of the two-dimensional container in the second structure of the slave register information under the master station, and if the signal name matches successfully, proceed to the next step;

[0093] Step S503: Set the signal value. Write the API function parameter signal value into the Value structure, retrieve the signal scaling factor and offset from the corresponding register information, convert the signal value to the original value, and store it in the signal original value of the local structure. At the same time, set the send flag MsgSendFlag to true.

[0094] Step S504, message encoding is performed, all signals in SingalList[i] of the information taken out from the buffer area are taken out (the same group of signals are sent together), the original value of the message is obtained according to the format conversion in step S503, and encoded into the specified byte of the message according to the register address and the valid bit of the signal. The function code corresponding to the signal in SingalList[i] and the site number and other information in the second structure are taken out, a CRC check is added, and the message is encoded into a complete Modbus message according to the Modbus encoding rules;

[0095] Step S505: Take out a frame of message in step S504, send it out through the underlying driver function, and store the current time value into the message timestamp;

[0096] Step S506: within the specified time range, receive the subordinate result reply message from the slave station and determine whether the subordinate is successful. If successful, end the current message sending. If unsuccessful, wait for the set interval time and execute step S505 again.

[0097] The above-mentioned communication system based on the Modbus protocol has developed a set of software programs with configurable Modbus message structure, byte storage order, valid data bits of signals in registers, and master-slave station modes. This can not only improve development efficiency and reduce development costs, but also reduce program bugs, reduce testing costs, and improve program stability.

[0098] This system provides a communication method based on the Modbus protocol, supporting customizable message formats within a certain range, decoupling the Modbus message format from the function code. The system also allows for configurable signal valid bits in registers, the number of registers queried or assigned (when acting as a master), and the byte storage order of multi-byte (>2-byte) registers. This allows for compatibility without code modifications for third-party programs with non-standard register query / assignment methods, non-standard function code usage, or flexible byte storage order for multi-byte (>2-byte) registers. This reduces development time, lowers development and testing costs, reduces program bugs, and improves program stability.

[0099] In summary, the system has the following beneficial effects:

[0100] 1. It can realize the reception, parsing, encoding and sending of different Modbus protocols by importing Modbus protocol files in a specified format without modifying the code. The main highlights are as follows:

[0101] a. When acting as a master station, the number of registers that can be queried at one time or set up is configurable, the function code and message structure are decoupled, the transmission signal of each bit of the same register (not a single bit) is configurable, the valid bit extraction flag is configurable, and the cycle of each query message is independent and configurable;

[0102] b. The storage order of multi-byte (>2 bytes) registers is configurable.

[0103] The above mainly solves the compatibility issues of third-party devices from different manufacturers with Modbus protocol register query / setting methods, non-standard function code usage, and flexible and changeable byte storage order.

[0104] 2. The upper-level API functions can be encapsulated separately for Modbus message sending and receiving to further improve the high cohesion and low coupling of the program.

[0105] The above description is merely an embodiment of the present application and is not intended to limit the scope of protection of the present application. For those skilled in the art, various modifications and variations of the present application are possible. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present application shall be included in the scope of protection of the present application.

Claims

1. A communication system based on the Modbus protocol, characterized in that: The system includes: a Modbus master station and a Modbus slave station, wherein the Modbus master station stores a master station structure, a master station information data set in the master station structure is configurable, and the master station information data set at least includes: a valid bit extraction flag bit and a byte storage order of a multi-byte register; register information of registers corresponding to the Modbus master station is stored in a two-dimensional container, each master station one-dimensional container in the two-dimensional container includes register information of at least one register, and the number of registers in each master station one-dimensional container is configurable; the Modbus slave station stores a slave station structure, and the slave station information data set in the slave station structure is configurable; register information of registers corresponding to the Modbus slave station is stored in the slave station one-dimensional container; The Modbus master station sends a first message to the Modbus slave station based on the master station information data set and the register information in each one-dimensional container of the master station; wherein the first message is a query message or a subordinate message; The Modbus slave returns a response message to the Modbus master based on the first message, the slave information data set, and the register information in the slave one-dimensional container.

2. The system according to claim 1, wherein: The Modbus master is used to: Taking the first master station one-dimensional container as the current one-dimensional container, sending a query message for each register in the current one-dimensional container to the Modbus slave station; wherein the query message carries the station address of the Modbus slave station, the query function code, the starting register address corresponding to the current one-dimensional container, and the number of registers; When the response message returned by the Modbus slave station is a normal query response message, the first signal original value corresponding to each register in the current one-dimensional container is parsed from the normal query response message based on the first specified information in the master station information data set; wherein the first specified information includes at least: the message structure, byte storage order, and valid bit extraction flag of the normal query response message; Calculating the first signal physical value corresponding to each of the first signal original values according to the scaling factor and the offset in the master station information data set; Saving each of the first signal original values and each of the first signal physical values into the master station information data set; The next master station one-dimensional container is used as a new current one-dimensional container, and the step of sending a query message for each register in the current one-dimensional container to the Modbus slave is repeated until the current one-dimensional container is the last master station one-dimensional container.

3. The system according to claim 2, characterized in that The Modbus master is used to: Obtaining a query message sending timestamp, and saving the query message sending timestamp to the master station information data set; When receiving a response message returned by the Modbus slave station, obtaining a first receiving timestamp of the response message, and saving the first receiving timestamp to the master station information data set; Calculating a first time interval between the sending timestamp and the first receiving timestamp, and saving the first time interval in the master station information data set; When the received response message is a query exception response message, a preset query time interval is obtained from the master station information data set. When the query time interval is reached, the step of sending a query message for the register in the current one-dimensional container to the Modbus slave station is repeated.

4. The system according to claim 2, wherein: The Modbus slave is used to: After receiving the query message, determining whether the query message is correct; If the query message is correct, traverse the one-dimensional container of the slave station; The register corresponding to the starting register address traversed is used as the current register, and the physical value of the second signal corresponding to the current register is obtained; Calculate the original value of the second signal corresponding to the current register according to the physical value of the second signal, the scaling factor and the offset in the slave station information data set; Taking the next register as the new current register, and repeatedly performing the step of obtaining the physical value of the second signal corresponding to the current register, until the number of traversed registers reaches the number of registers carried in the query message; Generate a normal query response message according to each second signal original value, the byte storage order and the valid bit extraction flag in the slave station information data set, and return the normal query response message to the Modbus master station; If the query message is erroneous, a query exception response message is generated and returned to the Modbus master station; wherein the query exception response message carries the error type.

5. The system according to claim 1, wherein: The Modbus master is used to: Taking the first master station one-dimensional container as the current one-dimensional container, and obtaining a sending flag corresponding to the current one-dimensional container; If the sending flag indicates sending a subordinate message for the current one-dimensional container, obtaining a third signal physical value corresponding to each register in the current one-dimensional container; Calculating the third signal original value corresponding to each of the third signal physical values according to the scaling factor and the offset in the master station information data set; Obtaining data area information based on each of the third signal original values, a valid bit extraction flag bit in the master station information data set, and a byte storage order; Generate a subordinate message based on the data area information and the second specified information, and send the subordinate message to the Modbus slave station; wherein the second specified information includes at least: a station address of the Modbus slave station, a subordinate function code, a starting register address corresponding to the current one-dimensional container, and the number of registers; When the received response message is a normal response message of the subordinate, determining that the subordinate message is sent completely, and updating the sending flag corresponding to the current one-dimensional container, wherein the updated sending flag is used to indicate that the subordinate message for the current one-dimensional container is not sent; The next master station one-dimensional container is used as a new current one-dimensional container, and the step of obtaining the sending flag corresponding to the current one-dimensional container is repeatedly performed until the current one-dimensional container is the last master station one-dimensional container.

6. The system according to claim 5, characterized in that The Modbus master is used to: Obtaining a timestamp of sending a subordinate message, and saving the timestamp of sending the subordinate message to the master station information data set; When receiving a response message returned by the Modbus slave station, obtaining a second receiving timestamp of the response message, and saving the second receiving timestamp to the master station information data set; When the received response message is a subordinate exception response message, a preset subordinate time interval is obtained from the master station information data set, and when the subordinate time interval is reached, the step of sending the subordinate message to the Modbus slave station is repeated.

7. The system according to claim 5, characterized in that The Modbus slave is used to: After receiving the subordinate message, determining whether the subordinate message is correct; If the subordinate message is correct, traverse the one-dimensional container of the slave station; The register corresponding to the traversed starting register address is used as the current register, and according to the byte storage order of the current register and the valid bit extraction flag bit, the original value of the fourth signal corresponding to the current register is parsed from the subordinate message; Calculating a fourth signal physical value corresponding to the fourth signal original value according to the fourth signal original value, the scaling factor and the offset in the slave station information data set; Saving the fourth signal original value and the fourth signal physical value into the slave station information data set; Taking the next register as the new current register, repeatedly performing the steps of extracting the flag bit according to the byte storage order of the current register and the valid bit, and parsing the fourth signal original value corresponding to the current register from the subordinate message, until the fourth signal original value and the fourth signal physical value corresponding to the last register in the current one-dimensional container are saved in the slave station information data set; Returns a success message to the Modbus master.

8. The system according to claim 7, characterized in that The Modbus slave is used to: If the subordinate message is erroneous, a subordinate exception response message is generated and returned to the Modbus master station; wherein the subordinate exception response message carries the error type.

9. The system according to claim 1, wherein: The target device is a Modbus master or a Modbus slave; the target device is used to: Receiving an acquisition request for a target signal to be acquired, sent by the application layer through a preset first interface function; wherein the acquisition request carries: a target signal name, a target channel number, and a target variable address of the target signal to be acquired; Traversing the target information data set through the channel corresponding to the target channel number and based on the target signal name; wherein, if the target device is a Modbus master station, the target information data set is the master station information data set; if the target device is a Modbus slave station, the target information data set is the slave station information data set; If the target signal name is found, the target signal value corresponding to the target signal name is obtained; The target signal value is returned to the application layer, so that the application layer saves the target signal value to the location indicated by the target variable address.

10. The system according to claim 1, wherein: The Modbus master is also used to: Receiving a request for a target signal to be set sent by the application layer through a preset second interface function; wherein the request carries: a name of the signal to be set, a channel number to be set, and a signal value to be written of the target signal to be set; Traversing the master station information data set based on the signal name to be set up; If the signal name to be set is traversed, the signal value to be written is saved to the master station information data set through the channel corresponding to the channel number to be set.

Citation Information

Patent Citations

  • Method for performing large data volume communication between Modbus master station and Modbus slave station

    CN102820959A

  • A depth packet detection platform based on industrial SCADA system

    CN109167796A

  • Data acquisition method, system and device and medium

    CN112487271A

  • Modbus multi-slave-station data acquisition and lower control method and system based on address mapping

    CN117544442A

  • Relay communication system, relay station and relay method

    JP2017098762A