Modbus communication protocol message encoding and decoding engine, system and method

CN122933791APending Publication Date: 2026-10-16邵若忱
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411672681.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-21
Publication Date
2026-10-16

AI Technical Summary

Technical Problem

[0003]然而,现有Modbus协议的编解码过程基于C、C++、Python等编程语言编写,在嵌入式系统场景中这些编解码逻辑过程被编译、烧写、固化到系统中

Benefits of technology

[0012] Therefore, the present invention adopts the above-mentioned Modbus communication protocol message encoding and decoding engine, system and method. Compared with the traditional embedded system's fixed method for Modbus message parsing logic, the Modbus communication protocol message encoding and decoding engine technology proposed in this paper has significant improvements over the traditional method by introducing a flexible protocol definition file, dynamic parsing and generation mechanism and a reconfigurable condition triggering mechanism. It can better meet the needs of the industrial Internet of Things scenario for flexible configuration capability and maintainability of embedded systems.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122933791A_ABST
    Figure CN122933791A_ABST
Patent Text Reader

Abstract

The application provides a Modbus communication protocol message encoding and decoding engine, system and method, device information library, message protocol definition management module, decoding logic analysis and dynamic generation module, trigger logic analysis and dynamic generation module, encoding logic analysis and dynamic generation module, decoding module, conditional trigger module, action execution module and encoding module. The application adopts the above-mentioned Modbus communication protocol message encoding and decoding engine, system and method, compared with the solidification method of the Modbus message analysis logic of the traditional embedded system, the Modbus communication protocol message encoding and decoding engine technology has significant improvement compared with the traditional method, and can better meet the demand of the flexible configuration ability and maintainability of the embedded system in the industrial Internet of Things scene.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of communications, and in particular to a Modbus communication protocol message encoding / decoding engine, system, and method. Background Technology

[0002] Modbus is a widely used general-purpose communication protocol for automated electronic controllers. Controllers can communicate with other controllers via a network using this protocol. Currently, Modbus has become a unified industry standard. Over the years, Modbus has evolved from being carried by RS232 and RS485 to being able to be transmitted over the Internet using the TCP protocol. Master and slave devices communicating using the Modbus protocol express different message functions through agreed-upon function codes. The Modbus protocol allows the master device (also called the host computer) to read information from or manipulate slave devices (also called slave devices).

[0003] However, existing Modbus protocol encoding and decoding processes are written in programming languages ​​such as C, C++, and Python. In embedded system scenarios, these encoding and decoding logic processes are compiled, burned, and solidified into the system. When the master and slave devices are replaced or upgraded, requiring the Modbus protocol to be upgraded or modified, the modified encoding and decoding logic processes need to be recompiled, burned, and solidified into the system, severely limiting the functional scalability and maintainability of commercially available embedded system products. Therefore, this invention addresses the need for hot updates of communication protocols in underlying sensor networks due to device upgrades and replacements, and implements a Modbus communication protocol message encoding and decoding engine that supports hot updates of the protocol. Summary of the Invention

[0004] The purpose of this invention is to provide a Modbus communication protocol message encoding / decoding engine, system, and method. Compared with the traditional embedded system's fixed Modbus message parsing logic, the Modbus communication protocol message encoding / decoding engine technology proposed in this paper introduces a flexible protocol definition file, a dynamic parsing and generation mechanism, and a reconfigurable condition triggering mechanism, which significantly improves upon the traditional method and can better meet the needs of the Industrial Internet of Things scenario for flexible configuration capabilities and maintainability of embedded systems.

[0005] To achieve the above objectives, the present invention provides a Modbus communication protocol message encoding and decoding engine, including... The device information database contains the Modbus function codes supported by the device and the corresponding message protocol definition file index for each function code. The message protocol definition management module is used to find the corresponding message protocol definition; The decoding logic parsing and dynamic generation module takes the message protocol definition as input and dynamically generates decoding logic for reconfiguration of the decoding module. The trigger logic parsing and dynamic generation module takes the message protocol definition as input and dynamically generates condition trigger logic and response action definitions for reconfiguration of the condition trigger module and action execution module; The encoding logic parsing and dynamic generation module takes the message protocol definition as input and dynamically generates encoding logic for reconfiguration of the encoding module; After the decoding module reconfigures the process using the decoding logic, it reads the original Modbus message and performs decoding calculations according to the decoding logic to obtain the data contained in the original message. After the condition triggering module performs process reconfiguration using the condition triggering logic, it reads the decoded data and checks whether the data has triggered the relevant condition response. After the action execution module is reconfigured using the response action definition, it responds to the call from the condition triggering module. After the encoding module performs process reconfiguration using the encoding logic, it reads the instructions sent to the lower-level machine, performs encoding calculations according to the encoding logic, and encapsulates the instructions into Modbus raw messages.

[0006] Preferably, the relevant condition responses include data values ​​exceeding the preset condition value range and data values ​​being equal to the preset condition values.

[0007] Preferably, the action execution module performs data storage, text alarms, and library function calls.

[0008] Preferably, the message protocol definition management module maintains a local database containing cached message protocol definition files and corresponding indexes; the message protocol definition management module will provide the engine with message protocol definition content for processing the current Modbus function code communication encoding and decoding process.

[0009] An engine-based communication system includes a host computer, a slave computer, a Modbus communication protocol message encoding and decoding engine, and a cloud-based message protocol definition database. The lower-level device encapsulates and encodes the collected data into a Modbus raw message, which is then sent to the upper-level device through the underlying sensor network. The upper-level device will obtain the device address of the lower-level device and the content of the Modbus raw message, and complete the control of the lower-level device. The engine's device information database obtains device information from the lower-level machine; The engine's decoding module decodes the Modbus raw messages output by the lower-level machine; The engine's message protocol definition management module periodically communicates with the cloud-based message protocol definition database to download and update the local message protocol definition version.

[0010] Preferably, the host computer sends instructions to the slave computer to perform data reading, state transition, and control execution.

[0011] A communication method based on a Modbus communication protocol message encoding / decoding engine, including When the lower-level machine sends a Modbus raw message, the engine first queries the device information database for device information, and then queries the corresponding message protocol definition file in the message protocol definition management module based on the device information. The message protocol definition management module provides CRUD functions for message protocol definition files stored locally on the device, and can also communicate with the cloud message protocol definition database to download and update message protocol definitions. Once the message protocol definition is found, the definition content will be sent to the decoding logic parsing and dynamic generation module, the encoding logic parsing and dynamic generation module, and the triggering logic parsing and dynamic generation module. These three modules parse the protocol definition content and dynamically generate the decoding logic, encoding logic, and conditional triggering logic and corresponding action definitions, and load them into each module. The original message then enters the decoding module for decoding according to the dynamically generated decoding logic. The condition triggering module checks and judges according to the defined triggering conditions and executes the corresponding actions. The host computer sends instructions to the slave computer, and the encoding module processes them according to the defined encoding logic, encapsulates them into a Modbus raw message, and sends it to the slave computer.

[0012] Therefore, the present invention adopts the above-mentioned Modbus communication protocol message encoding and decoding engine, system and method. Compared with the traditional embedded system's fixed method for Modbus message parsing logic, the Modbus communication protocol message encoding and decoding engine technology proposed in this paper has significant improvements over the traditional method by introducing a flexible protocol definition file, dynamic parsing and generation mechanism and a reconfigurable condition triggering mechanism. It can better meet the needs of the industrial Internet of Things scenario for flexible configuration capability and maintainability of embedded systems. Attached Figure Description

[0013] Figure 1 This is an architecture diagram of a Modbus communication protocol message encoding and decoding engine according to the present invention. Detailed Implementation

[0014] The technical solution of the present invention will be further described below with reference to the accompanying drawings and embodiments.

[0015] Unless otherwise defined, the technical or scientific terms used in this invention shall have the ordinary meaning as understood by one of ordinary skill in the art to which this invention pertains.

[0016] Message Protocol Definition To achieve hot updates of the protocol encoding / decoding logic, it is necessary to decouple the encoding / decoding logic from the executable file compiled from the programming language. This technology uses formatted languages ​​such as XML and JSON (not specific to any particular language implementation) to describe the message encoding / decoding logic, and uses a "message protocol definition" file to store the encoding / decoding logic content.

[0017] Taking the ultrasonic ranging sensor communication protocol as an example, Figure 1 This demonstrates a message protocol definition written in JSON. The protocol first defines the sensor type name (name field) and the data acquisition name (data field). Then, it defines the encoding logic for the sending process (send field): sendlength = 1 indicates sending one valid byte, and sendvalue = 55 indicates sending one byte represented as 55 in decimal. The decoding logic for the receiving process is defined in the receive field: recvlength = 2 indicates receiving two valid bytes. The operations field defines the decoding operations after receiving the data. Assuming the cumulative result is 0, the first operation is addition. The source data uses "[0]" to represent the 0th byte in the received byte array. The operation adds the source data to the cumulative result, making the cumulative result the value of the 0th byte. The second operation is multiplication. The source data is the immediate decimal value 256. The operation multiplies the source data by the cumulative result, making the cumulative result the product of the 0th byte value and 256. The third operation is an addition operation, using "[1]" to represent byte number 1 in the received byte array. After the operation, the cumulative result is [0]*256+[1]. Then the protocol definition uses the triggerers field to define the condition triggering logic and action execution logic. The triggercondition field and triggervalue field together define that when the cumulative result is greater than 300, the action field will be executed. The action field uses the message field to indicate that a text message is printed.

[0018] In the message protocol definition of this technical design, the numerical unit of encoding and decoding operations is a single byte, the type of encoding and decoding operations is integer operations such as arithmetic operations and binary bit operations, the condition triggering logic is the common inequality judgment, and the action types include, but are not limited to, text printing and library function calls.

[0019] Example 1 like Figure 1 As shown, a Modbus communication protocol message encoding / decoding engine includes... The device information database contains the Modbus function codes supported by the device and the corresponding message protocol definition file index for each function code. The engine searches for the corresponding message protocol definition in the message protocol definition management module based on the obtained message protocol definition file index. The message protocol definition management module maintains a local database containing cached message protocol definition files and their corresponding indexes. The message protocol definition management module will provide the engine with the message protocol definition content used to process the current Modbus function code communication encoding and decoding process.

[0020] The decoding logic parsing and dynamic generation module takes the message protocol definition as input and dynamically generates decoding logic for reconfiguration of the decoding module. The trigger logic parsing and dynamic generation module takes the message protocol definition as input and dynamically generates condition trigger logic and response action definitions for reconfiguration of the condition trigger module and action execution module; The encoding logic parsing and dynamic generation module takes the message protocol definition as input and dynamically generates encoding logic for reconfiguration of the encoding module; After the decoding module reconfigures the process using the decoding logic, it reads the original Modbus message and performs decoding calculations according to the decoding logic to obtain the data contained in the original message. After the condition triggering module reconfigures the process using the condition triggering logic, it reads the decoded data and checks whether the data has triggered the relevant condition response. The relevant condition response includes data values ​​exceeding the preset condition value range and data values ​​being equal to the preset condition value.

[0021] After reconfiguration using the response action definition, the action execution module responds to the call from the condition triggering module; the action execution module performs actions such as data storage, text alarms, and library function calls.

[0022] After the encoding module performs process reconfiguration using the encoding logic, it reads the instructions sent to the lower-level machine, performs encoding calculations according to the encoding logic, and encapsulates the instructions into Modbus raw messages.

[0023] An engine-based communication system includes a host computer, a slave computer, a Modbus communication protocol message encoding and decoding engine, and a cloud-based message protocol definition database. The lower-level slave device (referring to the sensors and other slave devices in the underlying sensor network) encapsulates and encodes the collected data into Modbus raw messages (i.e., binary encoding as referred to in the Modbus protocol), and sends them to the upper-level computer (referring to the embedded IoT gateway and other host devices in the underlying sensor network) through the underlying sensor network (such as ZigBee, LoRa, serial port device number, TCP, etc.). The upper-level computer obtains the device address of the lower-level device (such as ZigBee address, LoRa address, serial port device number, TCP address, etc.) and the content of the raw message. The upper-level computer then issues commands to the lower-level device to perform data reading, state transitions, and control execution.

[0024] The engine queries the local device information database based on the obtained lower-level device address and Modbus function code. Each device information entry contains the Modbus function codes supported by the device and the corresponding message protocol definition file index for each function code. The engine will then obtain the message protocol definition file index corresponding to the original message.

[0025] The engine's decoding module decodes the Modbus raw messages output by the lower-level machine; The engine's message protocol definition management module periodically communicates with the cloud-based message protocol definition database to download and update the local message protocol definition version.

[0026] A communication method based on a Modbus communication protocol message encoding / decoding engine, including When the lower-level machine sends a Modbus raw message, the engine first queries the device information database for device information, and then queries the corresponding message protocol definition file in the message protocol definition management module based on the device information. The message protocol definition management module provides CRUD functions for message protocol definition files stored locally on the device, and can also communicate with the cloud message protocol definition database to download and update message protocol definitions. Once the message protocol definition is found, the definition content will be sent to the decoding logic parsing and dynamic generation module, the encoding logic parsing and dynamic generation module, and the triggering logic parsing and dynamic generation module. These three modules parse the protocol definition content and dynamically generate the decoding logic, encoding logic, and conditional triggering logic and corresponding action definitions, and load them into each module. The original message then enters the decoding module for decoding according to the dynamically generated decoding logic. The condition triggering module checks and judges according to the defined triggering conditions and executes the corresponding actions. The host computer sends instructions to the slave computer, and the encoding module processes them according to the defined encoding logic, encapsulates them into a Modbus raw message, and sends it to the slave computer.

[0027] Therefore, the present invention adopts the above-mentioned Modbus communication protocol message encoding and decoding engine, system and method. Compared with the traditional embedded system's fixed method for Modbus message parsing logic, the Modbus communication protocol message encoding and decoding engine technology proposed in this paper has significant improvements over the traditional method by introducing a flexible protocol definition file, dynamic parsing and generation mechanism and a reconfigurable condition triggering mechanism. It can better meet the needs of the industrial Internet of Things scenario for flexible configuration capability and maintainability of embedded systems.

[0028] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention and not to limit them. Although the present invention has been described in detail with reference to preferred embodiments, those skilled in the art should understand that modifications or equivalent substitutions can still be made to the technical solutions of the present invention, and these modifications or equivalent substitutions cannot cause the modified technical solutions to deviate from the spirit and scope of the technical solutions of the present invention.

Claims

1. A Modbus communication protocol message encoding / decoding engine, characterized in that, include The device information database contains the Modbus function codes supported by the device and the corresponding message protocol definition file index for each function code. The message protocol definition management module is used to find the corresponding message protocol definition; The decoding logic parsing and dynamic generation module takes the message protocol definition as input and dynamically generates decoding logic for reconfiguration of the decoding module. The trigger logic parsing and dynamic generation module takes the message protocol definition as input and dynamically generates condition trigger logic and response action definitions for reconfiguration of the condition trigger module and action execution module; The encoding logic parsing and dynamic generation module takes the message protocol definition as input and dynamically generates encoding logic for reconfiguration of the encoding module; After the decoding module reconfigures the process using the decoding logic, it reads the original Modbus message and performs decoding calculations according to the decoding logic to obtain the data contained in the original message. After the condition triggering module performs process reconfiguration using the condition triggering logic, it reads the decoded data and checks whether the data has triggered the relevant condition response. After the action execution module is reconfigured using the response action definition, it responds to the call from the condition triggering module. After the encoding module performs process reconfiguration using the encoding logic, it reads the instructions sent to the lower-level machine, performs encoding calculations according to the encoding logic, and encapsulates the instructions into Modbus raw messages.

2. The Modbus communication protocol message encoding / decoding engine according to claim 1, characterized in that, The relevant condition responses include data values ​​exceeding the preset condition value range and data values ​​being equal to the preset condition value.

3. The Modbus communication protocol message encoding / decoding engine according to claim 1, characterized in that, The action execution module performs data storage, text alerts, and library function calls.

4. The Modbus communication protocol message encoding / decoding engine according to claim 1, characterized in that, The message protocol definition management module maintains a local database, which contains message protocol definition files cached locally and their corresponding indexes; The message protocol definition management module will provide the engine with message protocol definition content for processing the current Modbus function code communication encoding and decoding process.

5. A communication system based on the engine according to any one of claims 1-4, characterized in that, It includes a host computer, a slave computer, a Modbus communication protocol message encoding and decoding engine, and a cloud-based message protocol definition database; The lower-level device encapsulates and encodes the collected data into a Modbus raw message, which is then sent to the upper-level device through the underlying sensor network. The upper-level device will obtain the device address of the lower-level device and the content of the Modbus raw message, and complete the control of the lower-level device. The engine's device information database obtains device information from the lower-level machine; The engine's decoding module decodes the Modbus raw messages output by the lower-level machine; The engine's message protocol definition management module periodically communicates with the cloud-based message protocol definition database to download and update the local message protocol definition version.

6. The communication system based on a Modbus communication protocol message encoding / decoding engine according to claim 5, characterized in that, The host computer sends instructions to the slave computer to perform data reading, state transitions, and control execution.

7. The communication method based on a Modbus communication protocol message encoding / decoding engine according to claim 5 or 6, characterized in that, include When the lower-level machine sends a Modbus raw message, the engine first queries the device information database for device information, and then queries the corresponding message protocol definition file in the message protocol definition management module based on the device information. The message protocol definition management module provides CRUD functions for message protocol definition files stored locally on the device, and can also communicate with the cloud message protocol definition database to download and update message protocol definitions. Once the message protocol definition is found, the definition content will be sent to the decoding logic parsing and dynamic generation module, the encoding logic parsing and dynamic generation module, and the trigger logic parsing and dynamic generation module. These three modules parse the protocol definition content and dynamically generate the decoding logic, encoding logic, and conditional trigger logic and corresponding action definitions, and load them into each module. The original message then enters the decoding module for decoding according to the dynamically generated decoding logic. The condition triggering module checks and judges according to the defined triggering conditions and executes the corresponding actions. The host computer sends instructions to the slave computer, and the encoding module processes them according to the defined encoding logic, encapsulates them into a Modbus raw message, and sends it to the slave computer.