Gateway machine equipment Modbus data unvarnished transmission and protocol conversion method and gateway machine equipment Modbus data unvarnished transmission and protocol conversion device

By implementing downlink and uplink transparent transmission processing of Modbus data in the gateway device and supporting the reporting of multiple uplink protocol data, the problems of data transmission and multi-protocol data conversion in the existing technology are solved, and efficient and flexible data transmission and protocol conversion are achieved.

CN119544821AActive Publication Date: 2025-02-28NANJING ZHENGTU INFORMATION TECH CO LTD

Patent Information

Application Number
CN202411829294.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-12
Publication Date
2025-02-28
Estimated Expiration
2044-12-12

AI Technical Summary

Technical Problem

It is difficult to realize the transmissive transmission of Modbus equipment data and the effective conversion of multi-protocol data, especially in substations and distribution stations, where gateway equipment needs to be compatible with multiple protocols and data types.

Method used

By implementing downlink and uplink transparent transmission processing of Modbus data in the gateway device, it supports reporting of multiple uplink protocol data, combining the data buffer queue and function code identification mechanism to accurately extract and verify Modbus messages, and realize data transparent transmission and protocol conversion.

Benefits of technology

It realizes efficient transmissibility of Modbus data and flexible conversion of multi-protocol data, reduces data transmission error rate, improves system flexibility and scalability, and adapts to complex and changeable industrial automation environments.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119544821A_ABST
    Figure CN119544821A_ABST
Patent Text Reader

Abstract

The invention discloses a gateway machine equipment Modbus data unvarnished transmission and protocol conversion method and device. The gateway machine equipment Modbus data unvarnished transmission and protocol conversion device comprises a configuration module, a data common transmission module, a data unvarnished transmission module and an other protocol uplink transmission module. The configuration module is used for configuring a communication node connected with downlink equipment, the downlink equipment, an equipment data point of the downlink equipment and an uplink platform in the gateway machine; in the common data transmission mode, downlink data transmission and uplink data transmission are separately carried out through caching, and communication node configuration and uplink platform configuration are independent from each other; in the data unvarnished transmission mode, the uplink platform issues a serial port acquisition command, the gateway machine forwards the serial port acquisition command to the downlink serial port and monitors a downlink serial port response, and after the downlink serial port response is received, the downlink serial port response is written into the uplink serial port; the downlink serial port response is analyzed according to the configuration reference, and the analysis result can be packaged and transmitted according to other uplink protocol requirements. On the basis of compatibility with Modbus message acquisition, message processing of uplink and downlink unvarnished transmission of the Modbus is added, and the requirement of reporting of multiple uplink protocol data is supported at the same time.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to a gateway device Modbus data transparent transmission and distribution method and device, belonging to the data transmission technology of sensors in a smart substation room. Background Art

[0002] Modbus is a serial communication protocol widely used in the field of industrial automation. It is mainly used to achieve data transmission between devices and to monitor and control industrial processes. In substations, the use of Modbus protocol is also common.

[0003] In some application scenarios, the gateway device is required to transparently transmit data to the connected sensor devices and transparently transmit the data of the Modbus device to another system or device.

[0004] The gateway is a network device with multiple interfaces and supports multiple protocols. While supporting the Modbus protocol, it may also support other protocol data. Therefore, while transparently transmitting, it is also required to convert the data into data of other protocols for transmission to other systems and platforms. Summary of the invention

[0005] Purpose of the invention: In order to overcome the deficiencies in the prior art, the present invention provides a gateway device Modbus data transparent transmission and distribution method, which, on the basis of being compatible with Modbus message collection, adds Modbus uplink and downlink transparent transmission message processing, and simultaneously supports the needs of multiple uplink protocol data reporting.

[0006] Technical solution: To achieve the above purpose, the technical solution adopted by the present invention is:

[0007] A method for transparent transmission and distribution of Modbus data of a gateway device. In this case, the data type of the gateway is first divided into two types: downstream data and upstream data. Downstream data refers to Modbus data that the downstream device interacts with the gateway through the downstream serial port, and upstream data refers to Modbus data and other upstream protocol data that the upstream platform interacts with the gateway through the upstream serial port; then the transmission of Modbus data is divided into two types: ordinary data transmission mode and data transparent transmission mode; in the ordinary data transmission mode, the downstream data transmission and the upstream data transmission are separated by caching, and the communication node configuration and the upstream platform configuration are independent of each other; the data transparent transmission mode means that the upstream platform sends a serial port acquisition command, the gateway forwards the serial port acquisition command to the downstream serial port and monitors the downstream serial port response, and when the downstream serial port response is received, the downstream serial port response is written into the upstream serial port. In this case, the gateway machine connects to the downstream device through the downstream serial port and to the upstream platform through the upstream serial port, and configures the Modbus transparent transmission protocol for both the downstream and upstream serial ports; the gateway machine starts the data acquisition thread, monitors the read signal of the upstream serial port, appends all the monitored data to the end of the data buffer queue, first searches for the function code in the data buffer queue, and then identifies the message type based on the function code, then extracts the Modbus message according to the Modbus protocol and sends it to the downstream device, then reads the downstream serial port response according to the Modbus protocol within the timeout period and forwards it to the upstream platform; if the downstream serial port response is a query response message, and there is an uplink transmission requirement for the query response message based on other uplink protocols, the query response message is parsed to obtain the relevant parameters of the device data point, parse the data value of the device data point, refresh the data value of the device data point according to the parsing result, and finally encapsulates the data message according to the corresponding other uplink protocol requirements and transmits it uplink.

[0008] Specifically, the gateway monitors the read signal of the upstream serial port and appends all the monitored data to the end of the data buffer queue; the gateway searches for the Modbus function code from the head of the data buffer queue, and when the Modbus function code is identified, it determines whether the message type of the serial port acquisition command belongs to a Modbus query message or a Modbus control message based on the Modbus function code.

[0009] Specifically, according to the Modbus protocol, if the message type belongs to the 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 bit of the register address and the low bit of the register address, the last two bytes of the register address as the high bit of the register number and the low bit of the register number, and the last two bytes as the CRC check code; calculate whether the CRC check code is correct. If correct, extract a frame of message from the data buffer queue according to the Modbus query message format. If incorrect, continue to search for the Modbus function code in the data buffer queue and make a judgment; the extracted message frame is the Modbus query message, and the extracted message frame is written to the downstream serial port.

[0010] Specifically, according to the Modbus protocol, if the message type belongs to the Modbus control message, take the first byte of the function code as the slave address, and the last two bytes of the function code as the high bit of the register address and the low bit of the register address, and obtain other corresponding data and the CRC check code according to the function code type; calculate whether the CRC check code is correct, if it is correct, the Modbus control message format extracts a frame of message from the data buffer queue, if it is not correct, continue to search for the function code in the data buffer queue and make a judgment; the extracted message frame is the Modbus control message, and the extracted message frame is written to the downstream serial port.

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

[0012] Specifically, the communication mode and communication protocol are preset in the database dictionary table of the gateway machine, the communication mode includes serial port communication, the communication protocol includes Modbus transparent transmission protocol, the communication protocol of the downstream serial port is called the downstream Modbus transparent transmission protocol, and the communication protocol of the upstream serial port is called the upstream Modbus transparent transmission protocol; the communication node connected to the downstream device, the downstream device, the device data point of the downstream device, and the upstream 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, and the communication protocol is the downstream Modbus transparent transmission protocol; the configuration information of the downstream device 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; the configuration information of the device data point includes the device ID, the device data point ID and the device data point information parameters; the configuration information of the upstream platform includes the platform ID, the platform protocol and the platform connection information, and the platform protocol is the upstream Modbus transparent transmission protocol.

[0013] Specifically, 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 parameters include 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 serial port address, communication protocol, baud rate, parity bit, data bit and stop bit.

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

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

[0016] (11) Preset the communication mode and communication protocol in the database dictionary table of the gateway machine, the communication mode includes serial port communication, the communication protocol includes Modbus transparent transmission protocol, the communication protocol of the downstream serial port is called the downstream Modbus transparent transmission protocol, and the communication protocol of the upstream serial port is called the upstream Modbus transparent transmission protocol;

[0017] (12) Configure the communication node connected to the downstream device in the database of the gateway machine. The configuration information includes the communication node ID, communication mode, communication protocol and communication address information. The communication protocol is the downstream Modbus transparent transmission protocol. The communication address information is the combination information about the device communication parameters. For serial port communication, the communication address information includes the serial port address, communication protocol, baud rate, parity bit, data bit and stop bit.

[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 a downstream device and configure the device data point. The configuration information includes the device ID, the device data point ID, and the device data point information parameters. The device data point information parameters are the combined information about the Modbus channel. 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.

[0020] (15) Configure the uplink platform in the database of the gateway machine. The configuration information includes the 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 the serial port address, communication protocol, baud rate, parity bit, data bit and stop bit.

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

[0022] Step 3. Determine whether 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, it is processed according to the normal data reporting process; if yes, it is processed according to the data transparent transmission process, which includes the following steps:

[0023] (31) parsing the communication address information in the communication node configuration information, and opening the downstream serial port according to the serial port address, baud rate, parity bit, data bit and stop bit of the downstream serial port;

[0024] (32) parsing the platform connection information in the upstream platform configuration information, and opening the upstream serial port according to the serial port address, baud rate, parity bit, data bit, stop bit and other information of the upstream serial port;

[0025] (33) Start the data acquisition thread, monitor the read signal of the upstream serial port, and when the read signal of the upstream serial port is monitored, read all the data of the upstream serial port, and append all the read data to the end of the data buffer queue;

[0026] (34) starting from the head of the data buffer queue, searching for the Modbus function code, and when the Modbus function code is identified, first determining 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 the message according to the Modbus message format requirements;

[0027] (341) According to the Modbus protocol, if the message type belongs to the 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 bit of the register address and the low bit of the register address, the last two bytes of the register address as the high bit of the register number and the low bit of the register number, 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 not correct, 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 the 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 bit of the register address and the low bit of the register address, and other corresponding data and the CRC check code are obtained according to the function code type; calculate whether the CRC check code is correct, if it is correct, then the Modbus control message format extracts a frame of message from the data buffer queue, if it is not correct, then continue to search for the function code in the data buffer queue and make a judgment;

[0029] (35) Write the retrieved message frame into the downstream serial port, and read the downstream serial port response message within the timeout period; if the read timeout or the length of the downstream serial port response message read is shorter than the Modbus message format requirement, discard the read downstream serial port response message; if the length of the downstream serial port response message read meets the Modbus message format requirement, write the downstream serial port response message into the upstream serial port;

[0030] (36) If the downlink serial port response message is a query response message, and there is an uplink transmission requirement for the query response message based on other uplink protocols, the downlink serial port response message is parsed at the same time to obtain the slave address, register address and register length in the downlink serial port response message, match the corresponding device data point according to the slave address, register address and register length, and then parse the data value of the device data point according to the Modbus register address, function code, data type, data length, data parsing method, number of decimal places, conversion relationship and data offset information contained in the device data point information parameters, refresh the data value of the device data point according to the parsing result, encapsulate the data message according to the corresponding other uplink protocol requirements and transmit it uplink.

[0031] A gateway device Modbus data transparent transmission and distribution device for implementing the above method, comprising a configuration module, a general data transmission module, a data transparent transmission module and other protocol uplink transmission modules;

[0032] The configuration module is used to configure the communication node connected to the downlink device, the downlink device, the device data point of the downlink device, and the uplink platform in the gateway machine;

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

[0034] The data transparent transmission module, when the uplink serial port or the downlink serial port in the data acquisition thread adopts the Modbus transparent transmission protocol, 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 monitors the downlink serial port response, and when the downlink serial port response is received, the downlink serial port response is written to the uplink serial port;

[0035] The other protocol uplink transmission module adopts other protocols other than the Modbus transparent transmission protocol to upload data; if the downstream serial port response is a query response message, and there is an uplink transmission requirement for the query response message based on other uplink protocols, 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 message is encapsulated and transmitted uplink according to the corresponding other uplink protocol requirements.

[0036] Specifically, the configuration module presets the communication mode and communication protocol in the database dictionary table of the gateway machine, the communication mode includes serial port communication, the communication protocol includes Modbus transparent transmission protocol, the communication protocol of the downstream serial port is called the downstream Modbus transparent transmission protocol, and the communication protocol of the upstream serial port is called the upstream Modbus transparent transmission protocol; the communication node connected to the downstream device, the downstream device, the device data point of the downstream device, and the upstream 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, and the communication protocol is the downstream Modbus transparent transmission protocol; the configuration information of the downstream device 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; the configuration information of the device data point includes the device ID, the device data point ID and the device data point information parameters; the configuration information of the upstream platform includes the platform ID, the platform protocol and the platform connection information, and the platform protocol is the upstream Modbus transparent transmission protocol.

[0037] Beneficial effect: The gateway device Modbus data transparent transmission and protocol conversion method and device provided by the present invention have the following advantages over the prior art: 1. On the basis of being compatible with traditional Modbus message collection, the present invention innovatively adds a processing mechanism for Modbus uplink and downlink transparent transmission messages; 2. Taking full advantage of the relatively fixed characteristics of the function code of the Modbus message, the function code is used as the basis for message retrieval, and the Modbus message is accurately retrieved and verified according to the strict Modbus message format, which effectively reduces the data transmission error rate; 3. It can intelligently match device data points and retrieve data values ​​based on the register address and the number of registers in the message; 4. While meeting the Modbus data transparent transmission, it can realize multi-protocol conversion in combination with parameter configuration, encapsulate data into other uplink protocol formats, and meet the communication requirements of different systems and platforms; this makes the present invention highly flexible and scalable, and can easily adapt to complex and changeable industrial automation environments, effectively reducing the difficulty and cost of system integration. BRIEF DESCRIPTION OF THE DRAWINGS

[0038] Figure 1 It is a schematic diagram of the implementation process of the method of the present invention. DETAILED DESCRIPTION

[0039] The present invention is described in detail below with reference to the accompanying drawings and specific embodiments.

[0040] A Modbus data transparent transmission and distribution device for a gateway device includes a configuration module, a general data transmission module, a data transparent transmission module, and an uplink transmission module of other protocols. The configuration module is used to configure the communication node connected to the downlink device, the downlink device, the device data point of the downlink device, and the uplink platform in the gateway. When one or both of the uplink serial port or the downlink serial port in the data acquisition thread do not adopt the Modbus transparent transmission protocol, the general data transmission module sets the downlink data transmission and the uplink data transmission to be performed separately through the cache, and independently configures the communication node and the uplink platform. When the uplink serial port or the downlink serial port in the data acquisition thread adopts 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 monitors the downlink serial port response. After receiving the downlink serial port response, the downlink serial port response is written to the uplink serial port. The other protocol uplink transmission module adopts other protocols other than the Modbus transparent transmission protocol to upload data; if the downstream serial port response is a query response message, and there is an uplink transmission requirement for the query response message based on other uplink protocols, 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 message is encapsulated and transmitted uplink according to the corresponding other uplink protocol requirements.

[0041] In this case, the data types of the gateway are divided into two types: downstream data and upstream data. Downstream data refers to the Modbus data that the downstream device interacts with the gateway through the downstream serial port, and upstream data refers to the Modbus data and other upstream protocol data that the upstream platform interacts with the gateway through the upstream serial port. The transmission of Modbus data is divided into two types: ordinary data transmission and transparent data transmission. In the ordinary data transmission mode, the downstream data transmission and the upstream data transmission are separated by caching, and the communication node configuration and the upstream platform configuration are independent of each other. The transparent data transmission mode means that the upstream platform sends a serial port acquisition command, and the gateway forwards the serial port acquisition command to the downstream serial port and listens to the downstream serial port response. When the downstream serial port response is received, the downstream serial port response is written to the upstream serial port.

[0042] Combine the following Figure 1 The specific implementation steps of the gateway device Modbus data transparent transmission and distribution method shown in the figure take the sensor as the downlink device as an example to further illustrate the present invention.

[0043] Step 1: Configure information in the gateway machine

[0044] The gateway usually supports the input and output of multiple interfaces and multiple protocols. In the normal data transmission mode, the downlink data transmission and the uplink data transmission are separated through the cache. The gateway generates the appropriate uplink data or downlink data according to the transmission protocol as needed before transmitting the data. In the data transparent transmission mode, the gateway is mainly responsible for data forwarding. In order to distinguish the normal data transmission mode and realize the data transparent transmission mode, it is necessary to add a protocol type for data transparent transmission.

[0045] The communication mode and communication protocol are preset in the database dictionary table of the gateway machine. The communication mode includes serial port communication (as shown in Table 1), and the communication protocol includes Modbus transparent transmission protocol. The communication protocol of the downstream serial port is called the downstream Modbus transparent transmission protocol, and the communication protocol of the upstream serial port is called the upstream Modbus transparent transmission protocol (as shown in Table 2).

[0046] Table 1 Preset communication mode in the database dictionary table of the gateway machine

[0047] Dictionary code Dictionary item ID name describe commmode 1 Serial Port Serial communication

[0048] Table 2 Adding communication protocols to the database dictionary table of the gateway machine

[0049] Dictionary code Dictionary item ID name describe protocoltype 11 MODBUS transparent transmission Downlink MODBUS transparent transmission protocol agreementtype 11 MODBUS transparent transmission Uplink MODBUS transparent transmission protocol

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

[0051] Table 3 Configuration of communication nodes in the database of the gateway machine

[0052] Fields type illustrate Id Number Communication node ID, non-null, * Name String Communication node name Commaddr String Correspondence address information Commmode Number Communication Protocol type Number Communication Protocol

[0053] The communication address information is a combination of information about device communication parameters. For serial port communication, the communication address information includes information such as serial port address, communication protocol, baud rate, parity bit, data bit and stop bit; 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, the sensor ID and the sensor communication parameters, and the sensor communication parameters are the Modbus communication address of the sensor.

[0056] Table 4 Sensor configuration

[0057] Fields type illustrate 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 combined information about the Modbus channel. The sensor 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.

[0059] Table 5 Sensor data point configuration

[0060] Fields type illustrate 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 the 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 of information about the access parameters. The platform connection information includes the serial port address, communication protocol, baud rate, parity bit, data bit and stop bit.

[0062] Table 6 Uplink platform configuration

[0063] Fields type illustrate Id Number Platform ID, non-null, * Name String Platform Name type String The 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: Start the normal data transmission module and the data transparent transmission module

[0067] If one or both of the communication node and the upstream platform are not configured with the Modbus transparent transmission protocol, the normal data transmission module is used and processed according to the current normal 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, 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 downstream serial port according to the serial port address, baud rate, parity bit, data bit and stop bit information of the downstream 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 bit, stop bit and other information of the uplink serial port.

[0071] Step 33, start the data acquisition thread, monitor the read signal of the upstream serial port, when the read signal of the upstream serial port is monitored, read all the data of the upstream serial port, and append all the read data to the end 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 according to the Modbus function code, and then extract a frame of the message according to the Modbus message format requirement.

[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 belongs to the Modbus query message, combined with Table 7, determine 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, take the first byte of the function code as the slave address, the last two bytes of the function code as the high bit of the register address and the low bit of the register address, the last two bytes of the register address as the high bit of the register number and the low bit of the register number, and the last two bytes as the CRC check code; calculate whether the CRC check code is correct, if correct, extract a frame of message from the data buffer queue according to the Modbus query message format, if not correct, 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 the Modbus control message, combined with 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 bit of the register address and the low bit of the register address, and obtain other corresponding data and CRC check code according to the function code type; calculate whether the CRC check code is correct, if correct, the Modbus control message format extracts a frame of message from the data buffer queue, if not correct, continue to search for the function code in the data buffer queue and make a judgment.

[0080] Step 35, write the taken-out frame message into the downstream serial port, and read the downstream serial port response message within the timeout period; combined with Table 9 and Table 10, if the reading times out or the length of the read downstream serial port response message is shorter than the Modbus message format requirement, the read downstream serial port response message is discarded; if the length of the read downstream serial port response message meets the Modbus message format requirement, the downstream serial port response message is written into the upstream 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 is an uplink transmission requirement for the query response message based on other uplink protocols, the downlink serial port response message is parsed at the same time to obtain the slave address, register address and register length in the downlink serial port response message, match the corresponding device data point according to the slave address, register address and register length, and then parse the data value of the device data point according to the Modbus register address, function code, data type, data length, data parsing method, number of decimal places, conversion relationship and data offset information contained in the device data point information parameters, refresh the data value of the device data point according to the parsing result, encapsulate the data message according to the corresponding other uplink protocol requirements and transmit it uplink.

[0086] The above shows and describes 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 form, and any technical solution obtained by equivalent replacement or equivalent transformation falls within the protection scope of the present invention.

Claims

1. A gateway device Modbus data transparent transmission and distribution method, characterized in that: The gateway machine connects to the downstream device through the downstream serial port and to the upstream platform through the upstream serial port, and configures the Modbus transparent transmission protocol for both the downstream serial port and the upstream serial port; the gateway machine starts the data acquisition thread, monitors the read signal of the upstream serial port, appends all the monitored data to the end of the data buffer queue, first searches for the function code in the data buffer queue, and then identifies the message type based on the function code, and then extracts the Modbus message according to the Modbus protocol and sends it to the downstream device, and then reads the downstream serial port response according to the Modbus protocol within the timeout period and forwards it to the upstream platform; if the downstream serial port response is a query response message, and there is an uplink transmission requirement for the query response message based on other uplink protocols, the query response message is parsed to obtain the relevant parameters of the device data point, parse the data value of the device data point, refresh the data value of the device data point according to the parsing result, and finally encapsulates the data message according to the corresponding other uplink protocol requirements and transmits it uplink.

2. The gateway device Modbus data transparent transmission and distribution method according to claim 1, characterized in that: The gateway monitors the read signal of the upstream serial port and appends all the monitored data to the end of the data buffer queue; the gateway searches for the Modbus function code from the head of the data buffer queue. When the Modbus function code is identified, it determines whether the message type of the serial port acquisition command belongs to a Modbus query message or a Modbus control message based on the Modbus function code.

3. The gateway device Modbus data transparent transmission and distribution method according to claim 2, characterized in that: According to the Modbus protocol, if the message type belongs to the 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 bit of the register address and the low bit of the register address, the last two bytes of the register address as the high bit of the register number and the low bit of the register number, 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 not correct, continue to search for the Modbus function code in the data buffer queue and make a judgment; the extracted message frame is the Modbus query message, and the extracted message frame is written to the downstream serial port.

4. The gateway device Modbus data transparent transmission and distribution method according to claim 2, characterized in that: According to the Modbus protocol, if the message type belongs to the Modbus control message, take the first byte of the function code as the slave address, and the last two bytes of the function code as the high bit of the register address and the low bit of the register address, and 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, the Modbus control message format extracts a frame of message from the data buffer queue, if it is not correct, continue to search for the function code in the data buffer queue and make a judgment; the extracted message frame is the Modbus control message, and the extracted message frame is written to the downstream serial port.

5. The gateway device Modbus data transparent transmission and distribution method according to claim 1, characterized in that: After the gateway sends the extracted message frame to the downstream device, it reads the downstream serial port response message within the timeout period; if the reading times out or the length of the downstream serial port response message read is shorter than the Modbus message format requirement, the downstream serial port response message read is discarded; If the length of the read downstream serial port response message meets the Modbus message format requirement, the downstream serial port response message is written to the upstream serial port.

6. The gateway device Modbus data transparent transmission and distribution method according to claim 1, characterized in that: The communication mode and communication protocol are preset in the database dictionary table of the gateway machine, the communication mode includes serial port communication, the communication protocol includes Modbus transparent transmission protocol, the communication protocol of the downstream serial port is called the downstream Modbus transparent transmission protocol, and the communication protocol of the upstream serial port is called the upstream Modbus transparent transmission protocol; the communication node connected to the downstream device, the downstream device, the device data point of the downstream device, and the upstream 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, and the communication protocol is the downstream Modbus transparent transmission protocol; the configuration information of the downstream device 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; the configuration information of the device data point includes the device ID, the device data point ID and the device data point information parameters; the configuration information of the upstream platform includes the platform ID, the platform protocol and the platform connection information, and the platform protocol is the upstream Modbus transparent transmission protocol.

7. The gateway device Modbus data transparent transmission and distribution method according to claim 6 is characterized in that: 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 parameters include 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 serial port address, communication protocol, baud rate, parity bit, data bit and stop bit.

8. The gateway device Modbus data transparent transmission and distribution method according to claim 1, characterized in that: The method comprises the following steps: Step 1. Configure information in the gateway machine, including: (11) Preset the communication mode and communication protocol in the database dictionary table of the gateway machine, the communication mode includes serial port communication, the communication protocol includes Modbus transparent transmission protocol, the communication protocol of the downstream serial port is called the downstream Modbus transparent transmission protocol, and the communication protocol of the upstream serial port is called the upstream Modbus transparent transmission protocol; (12) Configure the communication node connected to the downstream device in the database of the gateway machine. The configuration information includes the communication node ID, communication mode, communication protocol and communication address information. The communication protocol is the downstream Modbus transparent transmission protocol. The communication address information is the combination information about the device communication parameters. For serial port communication, the communication address information includes the serial port address, communication protocol, baud rate, parity bit, data bit and stop bit. (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. (14) Select a downstream device and configure the device data point. The configuration information includes the device ID, the device data point ID, and the device data point information parameters. The device data point information parameters are the combined information about the Modbus channel. 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. (15) Configure the uplink platform in the database of the gateway machine. The configuration information includes the 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 the serial port address, communication protocol, baud rate, parity bit, data bit and stop bit. Step 2, load the communication node configuration, downlink device configuration, device data point configuration and uplink platform configuration; Step 3. Determine whether 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, it is processed according to the normal data reporting process; if yes, it is processed according to the data transparent transmission process, which includes the following steps: (31) parsing the communication address information in the communication node configuration information, and opening the downstream serial port according to the serial port address, baud rate, parity bit, data bit and stop bit information of the downstream serial port; (32) parsing the platform connection information in the upstream platform configuration information, and opening the upstream serial port according to the serial port address, baud rate, parity bit, data bit and stop bit information of the upstream serial port; (33) Start the data acquisition thread, monitor the read signal of the upstream serial port, and when the read signal of the upstream serial port is monitored, read all the data of the upstream serial port, and append all the read data to the end of the data buffer queue; (34) starting from the head of the data buffer queue, searching for the Modbus function code, and when the Modbus function code is identified, first determining 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 the message according to the Modbus message format requirements; (341) According to the Modbus protocol, if the message type belongs to the 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 bit of the register address and the low bit of the register address, the last two bytes of the register address as the high bit of the register number and the low bit of the register number, 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 not correct, continue to search for the Modbus function code in the data buffer queue and make a judgment; (342) According to the Modbus protocol, if the message type belongs to the 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 bit of the register address and the low bit of the register address, and other corresponding data and the CRC check code are obtained according to the function code type; calculate whether the CRC check code is correct, if it is correct, then the Modbus control message format extracts a frame of message from the data buffer queue, if it is not correct, then continue to search for the function code in the data buffer queue and make a judgment; (35) Write the retrieved message frame into the downstream serial port, and read the downstream serial port response message within the timeout period; if the read timeout or the length of the downstream serial port response message read is shorter than the Modbus message format requirement, discard the read downstream serial port response message; if the length of the downstream serial port response message read meets the Modbus message format requirement, write the downstream serial port response message into the upstream serial port; (36) If the downlink serial port response message is a query response message, and there is an uplink transmission requirement for the query response message based on other uplink protocols, the downlink serial port response message is parsed at the same time to obtain the slave address, register address and register length in the downlink serial port response message, match the corresponding device data point according to the slave address, register address and register length, and then parse the data value of the device data point according to the Modbus register address, function code, data type, data length, data parsing method, number of decimal places, conversion relationship and data offset information contained in the device data point information parameters, refresh the data value of the device data point according to the parsing result, encapsulate the data message according to the corresponding other uplink protocol requirements and transmit it uplink.

9. A gateway device Modbus data transparent transmission and distribution device, characterized in that: Including configuration module, general data transmission module, data transparent transmission module and other protocol uplink transmission modules; The configuration module is used to configure the communication node connected to the downlink device, the downlink device, the device data point of the downlink device, and the uplink platform in the gateway machine; The data common transmission module, when one or both of the uplink serial port or the downlink serial port in the data acquisition thread do not adopt the Modbus transparent transmission protocol, sets the downlink data transmission and the uplink data transmission to be performed separately through the cache, and independently configures the communication node and the uplink platform; The data transparent transmission module, when the uplink serial port or the downlink serial port in the data acquisition thread adopts the Modbus transparent transmission protocol, 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 monitors the downlink serial port response, and when the downlink serial port response is received, the downlink serial port response is written to the uplink serial port; The other protocol uplink transmission module uses other protocols other than the Modbus transparent transmission protocol to upload data; If the downstream serial port response is a query response message, and there is an uplink transmission requirement for the query response message based on other uplink protocols, 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, and the data value of the device data point is refreshed according to the parsing result. Finally, the data message is encapsulated and transmitted uplink according to the corresponding other uplink protocol requirements.

10. The gateway device Modbus data transparent transmission and distribution device according to claim 9, characterized in that: The configuration module presets the communication mode and communication protocol in the database dictionary table of the gateway machine, the communication mode includes serial port communication, the communication protocol includes Modbus transparent transmission protocol, the communication protocol of the downstream serial port is called the downstream Modbus transparent transmission protocol, and the communication protocol of the upstream serial port is called the upstream Modbus transparent transmission protocol; the communication node connected to the downstream device, the downstream device, the device data point of the downstream device, and the upstream 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, and the communication protocol is the downstream Modbus transparent transmission protocol; the configuration information of the downstream device 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; the configuration information of the device data point includes the device ID, the device data point ID and the device data point information parameters; the configuration information of the upstream platform includes the platform ID, the platform protocol and the platform connection information, and the platform protocol is the upstream 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

  • Multi-platform data unvarnished transmission 485 bus interaction method, medium, equipment and system

    CN114741349A

  • Method and device for supporting multiple users to perform data read-write and message tracking on serial port

    CN118018603A

Cited By

  • Ammeter data acquisition method and system based on DLT698.45-2017 protocol

    CN120416295A

  • A method and system for collecting electric meter data based on DLT698.45-2017 protocol

    CN120416295B