Gateway machine equipment Modbus data transparent transmission and protocol conversion method and device

By separating downlink and uplink data in the gateway device, identifying and verifying Modbus function codes, the problem of data pass-through and multi-protocol conversion in gateway devices when compatible with the Modbus protocol is solved, achieving efficient data transmission and system adaptability.

CN119544821BActive Publication Date: 2026-03-10NANJING ZHENGTU INFORMATION TECH CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-12-12
Publication Date
2026-03-10

AI Technical Summary

Technical Problem

While existing gateway devices are compatible with the Modbus protocol, they struggle to effectively achieve data pass-through and multi-protocol conversion, failing to meet the communication needs of different systems and platforms.

Method used

The gateway device categorizes data types into downlink and uplink data, identifies Modbus function codes through a data buffer queue, extracts and verifies messages using the Modbus protocol, and enables Modbus pass-through and multi-protocol conversion. It supports independent configuration and pass-through processes for downlink and uplink data.

Benefits of technology

It achieves accurate transmission of Modbus data and multi-protocol conversion, reduces data transmission error rate, improves system flexibility and scalability, adapts to complex industrial environments, and reduces system integration difficulty and cost.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119544821B_ABST
    Figure CN119544821B_ABST
Patent Text Reader

Abstract

The application discloses a gateway device Modbus data transparent transmission and protocol conversion method and device, comprising a configuration module, a data ordinary transmission module, a data transparent transmission module and other protocol uplink transmission modules; the configuration module is used for configuring a communication node connected with a downlink device, the downlink device, device data points of the downlink device and an uplink platform in the gateway device; in the data ordinary transmission mode, downlink data transmission and uplink data transmission are separately carried out through buffering, and the communication node configuration and the uplink platform configuration are independent of each other; in the data transparent transmission mode, the uplink platform issues a serial port acquisition command, the gateway device forwards the serial port acquisition command to a downlink serial port and listens to a downlink serial port response, writes the downlink serial port response into an uplink serial port after receiving the downlink serial port response, and analyzes the downlink serial port response according to the configuration reference; the analysis result can be encapsulated and transmitted according to other uplink protocol requirements. On the basis of compatible Modbus message acquisition, the application increases message processing of Modbus uplink and downlink transparent transmission, and simultaneously supports the demand of multiple uplink protocol data reporting.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The application relates to a gateway machine Modbus data transparent transmission and distribution method and device, and belongs to the technical field of data transmission of sensors in intelligent transformer substation. BACKGROUND

[0002] Modbus is a serial communication protocol widely used in industrial automation field, mainly used for realizing data transmission between devices, monitoring and control of industrial processes. In the transformer substation, the use of Modbus protocol is also common.

[0003] In some application scenarios, the gateway machine device is required to realize data transparent transmission on the accessed sensor device, and to transparently transmit the Modbus device data to another system or device.

[0004] The gateway machine is a multi-interface network device supporting multiple protocols. While supporting the Modbus protocol, it may also support other protocol data. Therefore, while transparently transmitting the data, the data is required to be converted into other protocol data for transmission to other systems and platforms. SUMMARY

[0005] The application aims to overcome the deficiencies in the prior art, and provides a gateway machine Modbus data transparent transmission and distribution method. On the basis of compatible Modbus message collection, the method increases the processing of uplink and downlink transparent transmission messages of Modbus, and simultaneously supports the demand of multiple uplink protocol data reporting.

[0006] Technical scheme: In order to achieve the above-mentioned purpose, the technical scheme adopted by the application is as follows:

[0007] The application discloses a gateway device Modbus data transparent transmission and distribution method, which comprises the following steps: first, the data types of the gateway device are divided into downlink data and uplink data, the downlink data refers to Modbus data exchanged between downlink equipment and the gateway device through a downlink serial port, and the uplink data refers to Modbus data and other uplink protocol data exchanged between an uplink platform and the gateway device through an uplink serial port; second, the transmission of the Modbus data is divided into a data normal transmission mode and a data transparent transmission mode; in the data normal transmission mode, the transmission of the downlink data and the transmission of the uplink data are separately performed through a cache, and the communication node configuration and the uplink platform configuration are independent of each other; the data transparent transmission mode refers to that the uplink platform issues a serial port collection command, the gateway device forwards the serial port collection command to the downlink serial port and listens to a downlink serial port response, and after receiving the downlink serial port response, the downlink serial port response is written into the uplink serial port. In the application, the gateway device is connected with downlink equipment through a downlink serial port and connected with an uplink platform through an uplink serial port, and the downlink serial port and the uplink serial port are both configured with a Modbus transparent transmission protocol; the gateway device starts a data collection thread, listens to a read signal of the uplink serial port, appends all the listened data to the tail of a data buffer queue, searches for a function code in the data buffer queue first, identifies a message type based on the function code, extracts a Modbus message according to the Modbus protocol and issues the Modbus message to the downlink equipment, then reads a downlink serial port response according to the Modbus protocol within a timeout time and forwards the downlink serial port response to the uplink platform; if the downlink serial port response is a query response message and there is an uplink transmission requirement of other uplink protocols about the query response message, the query response message is analyzed, device data point related parameters are acquired, a data value of the device data point is analyzed, the data value of the device data point is refreshed according to the analysis result, and finally, a data message is packaged according to the corresponding other uplink protocol requirement and is transmitted upwards.

[0008] Specifically, the gateway device listens to a read signal of the uplink serial port, appends all the listened data to the tail of the data buffer queue; the gateway device searches for a Modbus function code from the head of the data buffer queue, and when the Modbus function code is identified, judges whether the message type of the serial port collection command belongs to a Modbus query message or a Modbus control message according to the Modbus function code.

[0009] Specifically, according to the Modbus protocol, if the message type is a Modbus query message, it is determined whether the length of the received message in the data buffer queue is greater than or equal to 6. If it is greater than or equal to 6, the first byte of the function code is taken as the slave address, the last two bytes of the function code are taken as the high and low bytes of the register address, the last two bytes of the register address are taken as the high and low bytes of the register quantity, and the last two bytes are taken as the CRC checksum. The CRC checksum is calculated to see if it is correct. If it is correct, a message frame is extracted from the data buffer queue according to the Modbus query message format. If it is incorrect, the Modbus function code is searched for and judged in the data buffer queue. The extracted message frame is the Modbus query message, and the extracted message frame is written to the downlink serial port.

[0010] Specifically, according to the Modbus protocol, if the message type is a Modbus control message, the first byte of the function code is taken as the slave address, and the last two bytes of the function code are taken as the high and low bits of the register address. Other corresponding data and CRC check codes are obtained according to the function code type. The CRC check code is calculated to see if it is correct. If it is correct, a frame of the Modbus control message is extracted from the data buffer queue. If it is incorrect, the function code is searched for and judged in the data buffer queue. The extracted message frame is the Modbus control message, and the extracted message frame is written to the downlink serial port.

[0011] Specifically, after the gateway sends the extracted message frame to the downlink device, it reads the downlink serial port response message within the timeout period. If the reading times out or the length of the read downlink serial port response message is shorter than the Modbus message format requirement, the read downlink serial port response message is discarded. If the length of the read downlink serial port response message meets the Modbus message format requirement, the downlink serial port response message is written to the uplink serial port.

[0012] Specifically, the gateway's database dictionary table presets communication methods and protocols. Communication methods include serial communication, and communication protocols include the Modbus transparent protocol. The downlink serial communication protocol is called the downlink Modbus transparent protocol, and the uplink serial communication protocol is called the uplink Modbus transparent protocol. The gateway configures communication nodes connecting to downlink devices, downlink devices, device data points of downlink devices, and uplink platforms. The configuration information of the communication nodes includes communication node ID, communication method, communication protocol, and communication address information; the communication protocol is the downlink Modbus transparent protocol. The configuration information of the downlink devices includes communication node ID, device ID, and device communication parameters; the device communication parameters are the device's Modbus communication address. The configuration information of the device data points includes device ID, device data point ID, and device data point information parameters. The configuration information of the uplink platforms includes platform ID, platform protocol, and platform connection information; the platform protocol is the uplink Modbus transparent protocol.

[0013] Specifically, for serial communication, the communication address information includes the serial port address, communication protocol, baud rate, parity bit, data bits, and stop bits; the device data point information parameters include the Modbus register address, function code, data type, data length, data parsing method, number of decimal places, conversion relationship, and data offset; the platform connection information includes the serial port address, communication protocol, baud rate, parity bit, data bits, and stop bits.

[0014] Specifically, the method includes the following steps:

[0015] Step 1: Configure information in the gateway device, including:

[0016] (11) Preset the communication mode and communication protocol in the database dictionary table of the gateway machine. The communication mode includes serial communication and the communication protocol includes Modbus transparent transmission protocol. The communication protocol of the downlink serial port is called the downlink Modbus transparent transmission protocol and the communication protocol of the uplink serial port is called the uplink Modbus transparent transmission protocol.

[0017] (12) Configure the communication node for connecting the downlink device in the database of the gateway machine. The configuration information includes the communication node ID, communication method, communication protocol and communication address information. The communication protocol is the downlink Modbus transparent transmission protocol. The communication address information is a combination of device communication parameters. For serial communication, the communication address information includes the serial port address, communication protocol, baud rate, parity bit, data bits and stop bits.

[0018] (13) Select a communication node and configure the downlink device. The configuration information includes the communication node ID, device ID and device communication parameters. The device communication parameters are the Modbus communication address of the device.

[0019] (14) Select the downlink device and configure the device data point. The configuration information includes the device ID, device data point ID and device data point information parameters. The device data point information parameters are combined information about the Modbus channel. The device data point information parameters include Modbus register address, function code, data type, data length, data parsing method, number of decimal places, conversion relationship and data offset.

[0020] (15) Configure the uplink platform in the database of the gateway machine. The configuration information includes platform ID, platform protocol and platform connection information. The platform protocol is the uplink Modbus transparent transmission protocol. The platform connection information is the combination information about the access parameters. The platform connection information includes serial port address, communication protocol, baud rate, parity bit, data bits and stop bits.

[0021] Step 2: Load communication node configuration, downlink device configuration, device data point configuration, and uplink platform configuration;

[0022] Step 3: Determine if the communication node is configured with the downlink Modbus transparent transmission protocol and the uplink platform is configured with the uplink Modbus transparent transmission protocol. If not, proceed according to the normal data reporting process; if yes, proceed according to the data transparent transmission process, which includes the following steps:

[0023] (31) Parse the communication address information in the communication node configuration information, and open the downlink serial port according to the serial port address, baud rate, parity bit, data bits and stop bits of the downlink serial port;

[0024] (32) Parse the platform connection information in the uplink platform configuration information, and open the uplink serial port according to the serial port address, baud rate, parity bit, data bits and stop bits of the uplink serial port;

[0025] (33) Start the data acquisition thread, listen for the read signal of the uplink serial port, and when the read signal of the uplink serial port is heard, read all the data of the uplink serial port and append all the read data to the tail of the data buffer queue.

[0026] (34) Start searching for the Modbus function code from the head of the data buffer queue. When the Modbus function code is identified, first determine whether the message type belongs to the Modbus query message or the Modbus control message according to the Modbus function code, and then extract a frame of message according to the Modbus message format requirements.

[0027] (341) According to the Modbus protocol, if the message type is a Modbus query message, determine whether the length of the received message in the data buffer queue is greater than or equal to 6. If it is greater than or equal to 6, take the first byte of the function code as the slave address, the last two bytes of the function code as the high byte and low byte of the register address, the last two bytes of the register address as the high byte and low byte of the register quantity, and the last two bytes as the CRC check code. Calculate whether the CRC check code is correct. If it is correct, extract a frame of message from the data buffer queue according to the Modbus query message format. If it is incorrect, continue to search for the Modbus function code in the data buffer queue and make a judgment.

[0028] (342) According to the Modbus protocol, if the message type belongs to Modbus control message, the first byte of the function code is taken as the slave address, and the last two bytes of the function code are taken as the high and low bits of the register address. Other corresponding data and CRC check code are obtained according to the function code type. The CRC check code is calculated to see if it is correct. If it is correct, a frame of message is extracted from the data buffer queue in the Modbus control message format. If it is incorrect, the function code is searched for and judged in the data buffer queue.

[0029] (35) Write the extracted frame of message to the downlink serial port and read the downlink serial port response message within the timeout period; if the reading timeout occurs or the length of the read downlink serial port response message is shorter than the Modbus message format requirement, discard the read downlink serial port response message; if the length of the read downlink serial port response message meets the Modbus message format requirement, write the downlink serial port response message to the uplink serial port.

[0030] (36) If the downlink serial port response message is a query response message and there are uplink transmission requirements for the query response message based on other uplink protocols, then the downlink serial port response message is parsed simultaneously to obtain the slave address, register address and register length in the downlink serial port response message. The corresponding device data point is matched according to the slave address, register address and register length. Then, the data value of the device data point is parsed according to the Modbus register address, function code, data type, data length, data parsing method, decimal places, conversion relationship and data offset contained in the device data point information parameters. The data value of the device data point is refreshed according to the parsing result. The data packet is encapsulated and transmitted uplink according to the corresponding other uplink protocol requirements.

[0031] A Modbus data pass-through and distribution device for a gateway device used to implement the above method includes a configuration module, a normal data transmission module, a data pass-through module, and other protocol uplink transmission modules.

[0032] The configuration module is used to configure the communication nodes, downlink devices, device data points of downlink devices, and uplink platforms in the gateway device;

[0033] The data transmission module, when one or both of the uplink or downlink serial ports in the data acquisition thread do not use the Modbus transparent transmission protocol, sets the downlink data transmission and uplink data transmission to be performed separately through buffering, and independently configures the communication node and uplink platform.

[0034] When the uplink or downlink serial port in the data acquisition thread both use the Modbus transparent transmission protocol, the data transparent transmission module associates and configures the communication node and the uplink platform. For the serial port acquisition command issued by the uplink platform, the gateway forwards the serial port acquisition command to the downlink serial port and listens for the downlink serial port response. When the downlink serial port response is received, it writes the downlink serial port response to the uplink serial port.

[0035] The other protocol uplink transmission module uses protocols other than Modbus transparent transmission protocol for data upload; if the downlink serial port response is a query response message, and there are uplink transmission requirements for the query response message based on other uplink protocols, then the query response message is parsed to obtain the relevant parameters of the device data point, the data value of the device data point is parsed, the data value of the device data point is refreshed according to the parsing result, and finally the data packet is encapsulated and transmitted uplink according to the corresponding other uplink protocol requirements.

[0036] Specifically, the configuration module presets communication methods and protocols in the gateway's database dictionary. The communication methods include serial communication, and the communication protocols include the Modbus transparent protocol. The downlink serial communication protocol is referred to as the downlink Modbus transparent protocol, and the uplink serial communication protocol is referred to as the uplink Modbus transparent protocol. The gateway configures communication nodes, downlink devices, device data points of downlink devices, and uplink platforms for connecting downlink devices. The configuration information of the communication nodes includes communication node ID, communication method, communication protocol, and communication address information; the communication protocol is the downlink Modbus transparent protocol. The configuration information of the downlink devices includes communication node ID, device ID, and device communication parameters; the device communication parameters are the device's Modbus communication address. The configuration information of the device data points includes device ID, device data point ID, and device data point information parameters. The configuration information of the uplink platform includes platform ID, platform protocol, and platform connection information; the platform protocol is the uplink Modbus transparent protocol.

[0037] Beneficial Effects: The Modbus data pass-through and protocol conversion method and apparatus for gateway devices provided by this invention have the following advantages compared to existing technologies: 1. This invention innovatively adds a processing mechanism for Modbus uplink and downlink pass-through messages while maintaining compatibility with traditional Modbus message acquisition; 2. It fully utilizes the relatively fixed function code characteristic of Modbus messages, using the function code as the basis for message retrieval, and accurately extracts and verifies Modbus messages according to a strict Modbus message format, effectively reducing the data transmission error rate; 3. It can intelligently match device data points and extract data values ​​based on the register address and number of registers in the message; 4. While satisfying Modbus data pass-through, it can achieve multi-protocol conversion by combining parameter configuration, encapsulating data into other uplink protocol formats to meet the communication needs of different systems and platforms; This makes this invention highly flexible and scalable, easily adaptable to complex and ever-changing industrial automation environments, and effectively reducing the difficulty and cost of system integration. Attached Figure Description

[0038] Figure 1 This is a schematic diagram illustrating the implementation process of the method of the present invention. Detailed Implementation

[0039] The present invention will now be described in detail with reference to the accompanying drawings and specific embodiments.

[0040] A Modbus data pass-through and distribution device for a gateway includes a configuration module, a normal data transmission module, a data pass-through module, and other protocol uplink transmission modules. The configuration module is used to configure the communication nodes connecting to the downlink devices, the downlink devices, the device data points of the downlink devices, and the uplink platform within the gateway. The normal data transmission module, when one or both of the uplink or downlink serial ports in the data acquisition thread do not use the Modbus pass-through protocol, sets downlink and uplink data transmission to be performed separately through buffering, and independently configures the communication nodes and uplink platform. The data pass-through module, when both the uplink and downlink serial ports in the data acquisition thread use the Modbus pass-through protocol, associates and configures the communication nodes and uplink platform; for serial port acquisition commands issued by the uplink platform, the gateway forwards the serial port acquisition commands to the downlink serial ports and listens for downlink serial port responses; upon receiving a downlink serial port response, it writes the downlink serial port response to the uplink serial port. The other protocol uplink transmission module uses protocols other than Modbus transparent transmission protocol for data upload; if the downlink serial port response is a query response message, and there are uplink transmission requirements for the query response message based on other uplink protocols, then the query response message is parsed to obtain the relevant parameters of the device data point, the data value of the device data point is parsed, the data value of the device data point is refreshed according to the parsing result, and finally the data packet is encapsulated and transmitted uplink according to the corresponding other uplink protocol requirements.

[0041] In this case, the gateway's data types are divided into downlink data and uplink data. Downlink data refers to Modbus data exchanged between the downlink device and the gateway via the downlink serial port, while uplink data refers to Modbus data and other uplink protocol data exchanged between the uplink platform and the gateway via the uplink serial port. Modbus data transmission is divided into two modes: normal data transmission and transparent data transmission. In the normal data transmission mode, downlink and uplink data transmission are separated by buffering, and the communication node configuration and uplink platform configuration are independent of each other. In the transparent data transmission mode, the uplink platform issues a serial port acquisition command, the gateway forwards the serial port acquisition command to the downlink serial port and listens for the downlink serial port response. When the downlink serial port response is received, it is written to the uplink serial port.

[0042] The following is combined Figure 1 The specific implementation steps of the Modbus data pass-through and distribution method for the gateway device shown are illustrated below, taking a sensor as an example of a downlink device, to further explain the present invention.

[0043] Step 1: Configure information on the gateway device.

[0044] Gateways typically support multiple interfaces and protocols for input and output. In normal data transmission, downlink and uplink data transmissions are separated through buffering. The gateway generates appropriate uplink or downlink data according to the transmission protocol before transmitting the data. In data pass-through mode, the gateway is mainly responsible for data forwarding. To differentiate it from normal data transmission and implement data pass-through mode, a protocol type needs to be added for data pass-through.

[0045] The communication methods and protocols are preset in the database dictionary table of the gateway machine. The communication methods include serial communication (as shown in Table 1), and the communication protocols include Modbus transparent transmission protocol. The communication protocol of the downlink serial port is called the downlink Modbus transparent transmission protocol, and the communication protocol of the uplink serial port is called the uplink Modbus transparent transmission protocol (as shown in Table 2).

[0046] Table 1 shows the preset communication methods in the gateway's database dictionary.

[0047] Dictionary code Dictionary item ID Name Description Comm mode 1 Serial port Serial port communication

[0048] Table 2 shows the addition of communication protocols to the gateway's database dictionary.

[0049] Dictionary code Dictionary item ID Name Description Protocol type 11 MODBUS transparent transmission Downlink MODBUS transparent transmission protocol Agreement type 11 MODBUS transparent transmission Uplink MODBUS transparent transmission protocol

[0050] As shown in Table 3, the communication nodes for connecting to the downlink devices are configured in the database of the gateway machine.

[0051] Table 3 shows the configuration of communication nodes in the gateway's database.

[0052] Field Type Description Id Number Communication node ID, non-null, Name String Communication node name Commaddr String Communication address information Commmode Number Communication mode Protocoltype Number Communication protocol

[0053] The communication address information is a combination of device communication parameters. For serial communication, the communication address information includes serial port address, communication protocol, baud rate, parity bit, data bits, and stop bits. The communication protocol adopts the downlink Modbus transparent transmission protocol.

[0054] Select a communication node and connect the sensor (downlink device) to the gateway. The gateway needs to collect relevant information about the sensor and sensor data points to configure the sensor and sensor data points.

[0055] As shown in Table 4, the sensor configuration information includes the communication node ID, sensor ID, and sensor communication parameters. The sensor communication parameters are the sensor's Modbus communication address.

[0056] Table 4 Sensor Configuration

[0057] Field Type Description Id Number Sensor ID, non-null, Name String Sensor name Commnodeid Number Communication node ID Commaddr String Sensor communication parameters

[0058] As shown in Table 5, the sensor data point configuration information includes sensor ID, sensor data point ID, and sensor data point information parameters. The sensor data point information parameters are combination information about Modbus channels, including Modbus register address, function code, data type, data length, data parsing method, number of decimal places, conversion relationship, and data offset.

[0059] Table 5 Sensor Data Point Configuration

[0060] Field Type Description Id Number Sensor data point ID, non-null, Name String Sensor data point name Sensorid Number Sensor ID url String Sensor data point information parameters

[0061] As shown in Table 6, the uplink platform is configured in the database of the gateway machine. The configuration information includes platform ID, platform protocol and platform connection information. The platform protocol is the uplink Modbus transparent transmission protocol. The platform connection information is a combination of access parameters, including serial port address, communication protocol, baud rate, parity bit, data bits and stop bits.

[0062] Table 6 Uplink Platform Configuration

[0063] Field Type Description Id Number Platform ID, non-null, Name String Platform name Type String Platform protocol, non-null Url String Platform connection information

[0064] Step 2: Load configuration information

[0065] Load communication node configuration, downlink device configuration, device data point configuration, and uplink platform configuration.

[0066] Step 3: Activate the normal data transmission module and the data pass-through module.

[0067] If one or both of the communication nodes and the uplink platform are not configured with the Modbus transparent transmission protocol, the ordinary data transmission module will be used, and the data will be processed according to the existing ordinary data reporting process.

[0068] If the communication node is configured with the downlink Modbus transparent transmission protocol and the uplink platform is configured with the uplink Modbus transparent transmission protocol, then the data transparent transmission module is used for data transmission; the specific steps are as follows.

[0069] Step 31: Parse the communication address information in the communication node configuration information, and open the downlink serial port according to the serial port address, baud rate, parity bit, data bits and stop bits of the downlink serial port.

[0070] Step 32: Parse the platform connection information in the uplink platform configuration information, and open the uplink serial port according to the serial port address, baud rate, parity bit, data bits and stop bits of the uplink serial port.

[0071] Step 33: Start the data acquisition thread, listen for the read signal of the uplink serial port, and when the read signal of the uplink serial port is detected, read all the data of the uplink serial port and append all the read data to the tail of the data buffer queue.

[0072] Step 34: Start searching for the Modbus function code from the head of the data buffer queue. When the Modbus function code is identified, first determine whether the message type belongs to a Modbus query message or a Modbus control message based on the Modbus function code, and then extract a message frame according to the Modbus message format requirements.

[0073] Table 7 shows the query message format, and Table 8 shows the control message format.

[0074] Table 7 Query Message Format

[0075]

[0076] Table 8 Control Message Format

[0077]

[0078] Step 341: According to the Modbus protocol, if the message type is a Modbus query message, refer to Table 7 to determine whether the length of the received message in the data buffer queue is greater than or equal to 6. If it is greater than or equal to 6, take the first byte of the function code as the slave address, the last two bytes of the function code as the high and low bytes of the register address, the last two bytes of the register address as the high and low bytes of the register quantity, and the last two bytes as the CRC checksum. Calculate whether the CRC checksum is correct. If it is correct, extract a frame of message from the data buffer queue according to the Modbus query message format. If it is incorrect, continue to search for the Modbus function code in the data buffer queue and make a judgment.

[0079] Step 342: According to the Modbus protocol, if the message type belongs to Modbus control message, referring to Table 8, take the first byte of the function code as the slave address, and the last two bytes of the function code as the high and low bits of the register address. Obtain other corresponding data and CRC check code according to the function code type; calculate whether the CRC check code is correct. If it is correct, extract a frame of message from the data buffer queue in the Modbus control message format. If it is incorrect, continue to search for the function code in the data buffer queue and make a judgment.

[0080] Step 35: Write the extracted frame of message to the downlink serial port and read the downlink serial port response message within the timeout period; referring to Tables 9 and 10, if the reading times out or the length of the read downlink serial port response message is shorter than the Modbus message format requirement, discard the read downlink serial port response message; if the length of the read downlink serial port response message meets the Modbus message format requirement, write the downlink serial port response message to the uplink serial port.

[0081] Table 9 Query Response Message Format

[0082]

[0083] Table 10 Control Response Message Format

[0084]

[0085] Step 36: If the downlink serial port response message is a query response message, and there are uplink transmission requirements for this query response message based on other uplink protocols, then simultaneously parse the downlink serial port response message to obtain the slave address, register address, and register length from the downlink serial port response message. Match the corresponding device data point based on the slave address, register address, and register length. Then, based on the Modbus register address, function code, data type, data length, data parsing method, decimal places, conversion relationship, and data offset information contained in the device data point information parameters, parse the data value of the device data point. Refresh the data value of the device data point based on the parsing result, encapsulate the data packet according to the corresponding other uplink protocol requirements, and transmit it uplink.

[0086] The foregoing has shown and described the basic principles, main features, and advantages of the present invention. Those skilled in the art should understand that the above embodiments do not limit the present invention in any way, and all technical solutions obtained by equivalent substitution or equivalent transformation fall within the protection scope of the present invention.

Claims

1. A gateway machine device Modbus data transparent transmission and distribution method, characterized in that: The gateway machine connects the downlink device through the downlink serial port and connects the uplink platform through the uplink serial port, and Modbus transparent transmission protocol is configured for both the downlink serial port and the uplink serial port; the gateway machine starts a data collection thread, listens to the read signal of the uplink serial port, appends all the data listened to to the tail of the data buffer queue, first finds the function code in the data buffer queue, then identifies the message type based on the function code, then extracts the Modbus message according to the Modbus protocol and delivers it to the downlink device, and then reads the downlink serial port response and forwards it to the uplink platform within a timeout time according to the Modbus protocol; if the downlink serial port response is a query response message and there is an uplink transmission requirement based on other uplink protocols about the query response message, the query response message is parsed, the device data point related parameters are obtained, the data value of the device data point is parsed, the data value of the device data point is refreshed according to the parsing result, and finally the data message is encapsulated and transmitted according to the corresponding other uplink protocol requirements; The gateway machine listens to the read signal of the uplink serial port and appends all the data listened to to the tail of the data buffer queue. The gateway machine starts from the head of the data buffer queue to find the Modbus function code, and when the Modbus function code is identified, it is judged according to the Modbus function code whether the serial port collection command message type belongs to the Modbus query message or the Modbus control message. The gateway machine delivers the extracted message frame to the downlink device, and then reads the downlink serial port response message within a timeout time; If the reading is timed out or the length of the read downlink serial port response message is shorter than the Modbus message format requirement, the read downlink serial port response message is discarded; If the length of the read downlink serial port response message meets the Modbus message format requirement, the downlink serial port response message is written into the uplink serial port. The communication mode and the communication protocol are preset in the database dictionary table of the gateway machine, the communication mode includes serial communication, the communication protocol includes Modbus transparent transmission protocol, the communication protocol of the downlink serial port is referred to as downlink Modbus transparent transmission protocol, and the communication protocol of the uplink serial port is referred to as uplink Modbus transparent transmission protocol; the communication node connected with the downlink device, the downlink device, the device data point of the downlink device and the uplink platform are configured in the gateway machine; the configuration information of the communication node includes communication node ID, communication mode, communication protocol and communication address information, and the communication protocol is the downlink Modbus transparent transmission protocol; the configuration information of the downlink device includes communication node ID, device ID and device communication parameter, and the device communication parameter is the Modbus communication address of the device; the configuration information of the device data point includes device ID, device data point ID and device data point information parameter; and the configuration information of the uplink platform includes platform ID, platform protocol and platform connection information, and the platform protocol is the uplink Modbus transparent transmission protocol.

2. The gateway device Modbus data pass-through and distribution method of claim 1, wherein: According to the Modbus protocol, if the message type belongs to the Modbus query message, it is judged whether the length of the received message in the data buffer queue is greater than or equal to 6, if greater than or equal to 6, the previous byte of the function code is taken as the slave address, the last two bytes of the function code are taken as the high bit of the register address and the low bit of the register address, the last two bytes of the register address are taken as the high bit of the register quantity and the low bit of the register quantity, and the last two bytes are taken as the CRC check code; it is calculated whether the CRC check code is correct, if correct, a frame of message is extracted from the data buffer queue according to the Modbus query message format, if incorrect, the function code of Modbus is continuously searched in the data buffer queue and judged; the extracted message frame is the Modbus query message, and the extracted message frame is written into the downlink serial port.

3. The gateway device Modbus data pass-through and distribution method of claim 1, wherein: According to the Modbus protocol, if the message type belongs to the Modbus control message, the previous byte of the function code is taken as the slave address, the last two bytes of the function code are taken as the high bit of the register address and the low bit of the register address, other corresponding data and CRC check code are obtained according to the function code type; it is calculated whether the CRC check code is correct, if correct, a frame of message is extracted from the data buffer queue according to the Modbus control message format, if incorrect, the function code is continuously searched in the data buffer queue and judged; the extracted message frame is the Modbus control message, and the extracted message frame is written into the downlink serial port.

4. The gateway device Modbus data pass-through and distribution method of claim 1, wherein: For serial port communication, the communication address information includes serial port address, communication protocol, baud rate, parity bit, data bit and stop bit; the device data point information parameter includes Modbus register address, function code, data type, data length, data analysis method, decimal point bit number, conversion relationship and data offset; the platform connection information includes serial port address, communication protocol, baud rate, parity bit, data bit and stop bit.

5. The gateway device Modbus data pass-through and distribution method of claim 1, wherein: The method comprises the following steps: Step 1, information configuration in the gateway machine, including: (11) presetting the communication mode and the communication protocol in the database dictionary table of the gateway machine, the communication mode including serial port communication, and the communication protocol including the Modbus transparent transmission protocol, the communication protocol of the downlink serial port being referred to as the downlink Modbus transparent transmission protocol, and the communication protocol of the uplink serial port being referred to as the uplink Modbus transparent transmission protocol; (12) configuring the communication node connected with the downlink device in the database of the gateway machine, and the configuration information includes the communication node ID, the communication mode, the communication protocol and the communication address information; the communication protocol is the downlink Modbus transparent transmission protocol, and the communication address information is the combined information about the device communication parameters; for serial port communication, the communication address information includes serial port address, communication protocol, baud rate, parity bit, data bit and stop bit; (13) selecting the communication node, configuring the downlink device, and the configuration information includes the communication node ID, the device ID and the device communication parameters, and the device communication parameters are the Modbus communication address of the device; (14) selecting a downlink device, configuring a device data point, the configuration information including a device ID, a device data point ID and a device data point information parameter, the device data point information parameter being combined information about a Modbus channel, the device data point information parameter including a Modbus register address, a function code, a data type, a data length, a data analysis method, a decimal point bit number, a conversion relationship and a data offset; (15) configuring an uplink platform in a database of the gateway machine, the configuration information including a platform ID, a platform protocol and platform connection information; the platform protocol being an uplink Modbus transparent transmission protocol, the platform connection information being combined information about access parameters, the platform connection information including a serial port address, a communication protocol, a baud rate, a parity bit, a data bit and a stop bit; Step 2, loading the communication node configuration, the downlink device configuration, the device data point configuration and the uplink platform configuration; Step 3, judging whether the communication node configuration is a downlink Modbus transparent transmission protocol and the uplink platform configuration is an uplink Modbus transparent transmission protocol: if not, processing according to a normal data reporting process; if yes, processing according to a data transparent transmission process, the data transparent transmission process including the following steps: (31) analyzing the communication address information in the communication node configuration information, opening a downlink serial port according to the serial port address, the baud rate, the parity bit, the data bit and the stop bit information of the downlink serial port; (32) analyzing the platform connection information in the uplink platform configuration information, opening an uplink serial port according to the serial port address, the baud rate, the parity bit, the data bit and the stop bit information of the uplink serial port; (33) starting a data collection thread, listening to a read signal of the uplink serial port, when the read signal of the uplink serial port is listened to, reading all data of the uplink serial port and appending all the read data to the tail of a data buffer queue; (34) starting from the head of the data buffer queue to find a Modbus function code, when the Modbus function code is identified, first judging whether the message type belongs to a Modbus query message or a Modbus control message according to the Modbus function code, and then extracting a frame of message according to the Modbus message format requirement; (341) according to the Modbus protocol, if the message type belongs to the Modbus query message, judging whether the length of the received message in the data buffer queue is greater than or equal to 6, if yes, taking the previous byte of the function code as a slave address, the last two bytes of the function code as a high bit of a register address and a low bit of the register address, the last two bytes of the register address as a high bit of a register number and a low bit of the register number, and the last two bytes as a CRC check code; calculating whether the CRC check code is correct, if yes, extracting a frame of message from the data buffer queue according to the Modbus query message format, if not, continuing to find the Modbus function code in the data buffer queue and judging; (342) According to the Modbus protocol, if the message type belongs to the Modbus control message, the previous byte of the function code is taken as the slave address, the last two bytes of the function code are taken as the high bit of the register address and the low bit of the register address, other corresponding data is obtained according to the function code type, and the CRC check code is calculated; whether the CRC check code is correct is calculated, if correct, the Modbus control message format is extracted from the data buffer queue, if incorrect, the function code is continuously searched in the data buffer queue and judged; (35) The extracted frame message is written into the downlink serial port, and the downlink serial port response message is read within the timeout time; if the read timeout or the length of the read downlink serial port response message is shorter than the Modbus message format requirement, the read downlink serial port response message is discarded; if the length of the read downlink serial port response message meets the Modbus message format requirement, the downlink serial port response message is written into the uplink serial port; (36) If the downlink serial port response message is a query response message, and there is an uplink transmission requirement based on other uplink protocols about the query response message, the downlink serial port response message is analyzed at the same time, the slave address, register address and register length in the downlink serial port response message are obtained, the corresponding device data points are matched according to the slave address, register address and register length, then the data value of the device data point is analyzed according to the Modbus register address, function code, data type, data length, data analysis method, decimal point position, conversion relationship and data offset information contained in the device data point information parameter, the data value of the device data point is refreshed according to the analysis result, and the data message is packaged and transmitted uplink according to the corresponding other uplink protocol requirements.

6. A gateway device Modbus data transparent transmission and distribution apparatus for implementing the method of any one of claims 1-5, characterized in that: It comprises a configuration module, a data general transmission module, a data transparent transmission module and an other protocol uplink transmission module. The configuration module is used for configuring the communication node connected with the downlink device, the downlink device, the device data point of the downlink device and the uplink platform in the gateway machine. The data general transmission module is used for setting the downlink data transmission and the uplink data transmission to be carried out separately through the buffer when one or both of the uplink serial port and the downlink serial port in the data acquisition thread does not use the Modbus transparent transmission protocol. The data transparent transmission module is used for associating the configuration of the communication node and the uplink platform when the uplink serial port and the downlink serial port in the data acquisition thread both use the Modbus transparent transmission protocol; for the serial port acquisition command issued by the uplink platform, the gateway machine forwards the serial port acquisition command to the downlink serial port and listens to the downlink serial port response, and writes the downlink serial port response into the uplink serial port after receiving the downlink serial port response; The other protocol uplink transmission module is used for uploading data by using other protocols except the Modbus transparent transmission protocol. If the downlink serial port response is a query response message, and there is an uplink transmission requirement based on other uplink protocols about the query response message, the query response message is parsed, the device data point related parameters are obtained, the data value of the device data point is parsed, the data value of the device data point is refreshed according to the parsing result, and finally the data message is encapsulated and transmitted according to the corresponding other uplink protocol requirement.

7. The gateway device Modbus data pass-through and distribution apparatus of claim 6, wherein: The configuration module presets the communication mode and the communication protocol in the database dictionary table of the gateway machine, the communication mode includes serial communication, the communication protocol includes Modbus transparent transmission protocol, the communication protocol of the downlink serial port is referred to as downlink Modbus transparent transmission protocol, and the communication protocol of the uplink serial port is referred to as uplink Modbus transparent transmission protocol; the communication node connected with the downlink device, the downlink device, the device data point of the downlink device and the uplink platform are configured in the gateway machine; the configuration information of the communication node includes the communication node ID, the communication mode, the communication protocol and the communication address information, the communication protocol is the downlink Modbus transparent transmission protocol; the configuration information of the downlink device includes the communication node ID, the device ID and the device communication parameter, the device communication parameter is the Modbus communication address of the device; the configuration information of the device data point includes the device ID, the device data point ID and the device data point information parameter; and the configuration information of the uplink platform includes the platform ID, the platform protocol and the platform connection information, the platform protocol is the uplink Modbus transparent transmission protocol.

Citation Information

Patent Citations

  • Method of realizing adaptive switching between two modes of transparent transmission and Modbus protocol conversion in network serial port

    CN109587158A