Modbus communication method and system based on HMI
By using an HMI-based Modbus communication method, address mapping and automatic address relationship generation are achieved through configuration files. This solves the problems of complex address calculation and low usability in traditional Modbus systems, enabling rapid system adaptation and efficient communication, and improving device compatibility and maintainability.
Patent Information
- Application Number
- CN202510493111.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-18
- Publication Date
- 2026-02-10
- Estimated Expiration
- 2045-04-18
AI Technical Summary
Traditional Modbus communication systems involve complex and error-prone calculations of address relationships between different devices, leading to reduced system reliability and ease of use, and making it difficult to adapt to complex device network structures.
By using the HMI-based Modbus communication method and implementing address mapping through configuration files, communication functions supporting different devices are generated. Serial port and Ethernet connection methods are provided. Users do not need to manually calculate addresses; the system automatically generates address mapping relationships and supports rapid adaptation to device types.
It improved the system's development efficiency and reliability, simplified the operation process, enhanced the system's adaptability and maintainability, and improved its compatibility with different devices and the overall simplification of the system.
Smart Images

Figure CN120415943B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of industrial control technology, and in particular to a communication system based on the industrial standard Modbus protocol generated by HMI. Background Technology
[0002] Modbus is a serial communication protocol widely used in industrial control. With its advantages of openness, high reliability, high efficiency, simplicity, and free availability, it has become the industry standard for communication protocols in the industrial field and is a commonly used communication format between electronic devices in industrial settings. While the content of communication messages and commonly used function codes are relatively fixed, the specific data segments specified for different device models vary.
[0003] Traditional Modbus communication systems provide identical one-to-one address relationships for different devices, requiring users to manually calculate addresses, reducing software usability, and introducing hard-to-detect errors during the calculation process, thus lowering system reliability. Conversely, providing various customizations for address relationships across different devices within the same system increases software complexity and reduces system maintainability. Summary of the Invention
[0004] This invention provides a method and system based on HMI-based Modbus communication. Without modifying the encapsulated system, it utilizes independent configuration files to quickly generate communication functions that meet different needs, while maintaining consistency in addressing rules with the device side. Users do not need to concern themselves with the specific implementation; they only need to input the address relationships specified by different devices to enable normal communication functionality. For different interfaces provided by the same type of devices, the system offers two commonly used connection methods: serial port and Ethernet, which users can freely choose according to their needs. By using configuration files, the address relationships of various devices are decoupled from the system, allowing the entire system to function without modifying the software engineering.
[0005] To solve the above-mentioned technical problems, one technical solution adopted by the present invention is: a Modbus communication method based on HMI, which includes the following steps:
[0006] Step 1: Parse the address requirement table of the lower-level Modbus device, establish the supported Modbus protocol address mapping relationship, and generate the configuration file;
[0007] Step 2: Read and parse the configuration file to provide external access channel addresses for the registers or relays of the lower-level Modbus device;
[0008] Step 3: According to the configuration file, display the modifiable lower-level Modbus device attribute options, as well as the lower-level Modbus devices that distinguish between serial port and Ethernet interfaces, and configure different communication device attributes, including serial port number or IP address.
[0009] Step 4: Based on the channel address and communication device attributes of the lower-level Modbus device, realize the communication between the upper-level computer and the lower-level Modbus device based on the Modbus protocol.
[0010] Preferably, in step 1, a configuration file is generated for each lower-level Modbus device. The configuration file includes the logical address and physical address of each register or relay of the lower-level Modbus device, forming an address mapping relationship between logical address and physical address.
[0011] Preferably, the configuration file includes: register or relay name, logical address, physical address, maximum block length, main address format, bit address format, read function code, and write function code.
[0012] Preferably, in step 1, the address requirement table of the lower-level Modbus device is parsed, and the offset and coefficient relationship are calculated based on the logical address and physical address range in the address requirement table. Then, the function code is used to distinguish between bit relays, word relays, bit registers, or word registers, and a configuration file with address mapping relationship is generated.
[0013] Preferably, in step 3, the communication attributes of the lower-level Modbus device of the serial port include: initial working state, serial port number, communication baud rate, data bit length, stop bit length, and data verification method.
[0014] Preferably, in step 4, the status of the protocol data is checked before the communication packet is sent, and then the data in the buffer is taken out and sent to the lower-level Modbus device; after receiving the packet, the parsing logic is triggered first, and then the data is sent to the upper-level computer screen for display.
[0015] To solve the above-mentioned technical problems, another technical solution adopted by the present invention is: a Modbus communication system based on HMI, which includes: a communication device attribute module, a protocol parser, a communication address module, and a communication device channel;
[0016] The communication device attribute module is used to statically configure the attribute options of the lower-level Modbus device during operation;
[0017] The protocol parser interacts with the communication address module and is used to assemble, parse, and verify data packets transmitted between the lower-level Modbus device network interface or serial port during communication.
[0018] The communication address module is used to manage configuration files. Each lower-level Modbus device generates its own configuration file, which includes the name of each register or relay of the lower-level Modbus device, logical address, physical address, maximum block length, main address format, bit address format, read function code, and write function code, forming an address mapping relationship between logical address and physical address.
[0019] The communication address module is also used to provide an external access channel address for the registers or relays of the lower-level Modbus device;
[0020] The communication device channel provides a device channel with a channel address for data exchange.
[0021] Preferably, the HMI-based Modbus communication system further includes: a communication device streaming module; the communication device streaming module is used to realize the storage and restoration of internal data, including the storage and restoration of device attributes, device channels, and address mapping information, and provides them to the communication address module.
[0022] Preferably, the HMI-based Modbus communication system further includes: a communication device instruction module; the communication device instruction module is used to write control logic to realize device communication and screen display.
[0023] Preferably, the Modbus communication system based on HMI further includes: a data acquisition block unit; the data acquisition block unit is used to merge the continuous addresses of multiple device channels when there are many channel addresses and a large amount of data acquisition, merge multiple channels into one acquisition block, and then organize multiple blocks together according to the dispersion, block size and address gap between multiple acquisition blocks, so as to realize the simultaneous refresh of several channels through one communication data transmission and reception.
[0024] The present invention has the following beneficial effects:
[0025] This invention, based on address mapping, converts between logical addresses and physical communication addresses, eliminating the need for manual calculations. Users no longer need to concern themselves with the actual address relationships and can quickly build business logic using the same addressing method as the device, thus improving development efficiency. The system verifies the validity of user addresses based on the established mappings, enhancing system reliability.
[0026] This invention improves the system's adaptability and reliability; eliminates unnecessary manual calculations during user operation, solving the usability problem; and enhances the system's maintainability through the reuse of functions.
[0027] Based on the device type and functional requirements, this invention selects an appropriate configuration template and automatically generates predefined device attributes and related default parameters based on the input file. It provides attribute alternatives, enabling the system to quickly adapt to the device's general extended functions. While ensuring user-defined functions, it simplifies the operation process.
[0028] This invention encapsulates the underlying communication interface, supporting both serial and Ethernet communication methods, thus improving compatibility with different device connections. Compared to the single connection method of traditional communication systems, it is easier to adapt to the complex device network structure in the user's field; interface reuse reduces the overall complexity of the system. Attached Figure Description
[0029] Figure 1 This is a flowchart of an embodiment of the communication method of the present invention.
[0030] Figure 2 This is a schematic diagram of an embodiment of the communication system of the present invention. Detailed Implementation
[0031] The detailed description and technical content of the present invention are explained below with reference to the accompanying drawings. However, the drawings are provided for reference and illustration only and are not intended to limit the present invention.
[0032] The principle of this invention is as follows: Unlike traditional communication systems, this invention uses the mapping relationship between logical addresses and physical addresses abstracted from the address requirement table as the system input, which simplifies user operation steps and reuses the entire communication process. It does not require modification of the system software source code or the underlying communication protocol logic, nor does it involve hardware modification. It uses configuration files to generate a Modbus communication system, which can quickly adapt to various types of Ethernet / serial port lower-level devices that support standard protocols, improve the system's adaptability, and reduce maintenance costs.
[0033] like Figure 1 As shown, an embodiment of the Modbus communication method based on HMI according to the present invention includes the following steps:
[0034] Step 1: Parse the address requirement table of the lower-level Modbus device, establish the supported Modbus protocol address mapping relationship, and generate the configuration file;
[0035] Step 2: Read and parse the configuration file to provide external access channel addresses for the registers or relays of the lower-level Modbus device;
[0036] Step 3: According to the configuration file, display the modifiable lower-level Modbus device attribute options, as well as the lower-level Modbus devices that distinguish between serial port and Ethernet interfaces, and configure different communication device attributes, including serial port number or IP address.
[0037] Step 4: Based on the channel address and communication device attributes of the lower-level Modbus device, realize the communication between the upper-level computer and the lower-level Modbus device based on the Modbus protocol.
[0038] In step 1, the address requirement table refers to the list of address relationships that are usually defined by the lower-level machine (e.g., PLC). Relevant information can usually be found in the product manual.
[0039] A specific address requirement table is shown below:
[0040]
[0041] The configuration file is a file with a fixed format used to store address mapping relationships within the communication system.
[0042] In step 1, a configuration file is generated for each lower-level Modbus device. The configuration file includes the logical address and physical address of each register or relay of the lower-level Modbus device, forming an address mapping relationship between logical address and physical address.
[0043] A specific configuration file is shown in the table below. The configuration file includes: register or relay name, logical address, physical address, maximum block size, main address format, bit address format, read function code, and write function code.
[0044]
[0045] This process involves parsing the address requirement table of the lower-level Modbus device, calculating the offset and coefficient relationship based on the logical and physical address ranges in the address requirement table, and then distinguishing between bit relays, word relays, bit registers, or word registers according to the function code to generate a configuration file with address mapping relationships.
[0046] Taking 'Register C' as an example:
[0047]
[0048] Type: Bit; Range: 0~511; Modbus Address: 061441~061952; Communication Address: F000~F1FF;
[0049] Mapping relationship;
[0050] Register addresses: 0 to 511;
[0051] Communication address: 0xF000~0xF1FF;
[0052] Function codes: Read function code -0x01, Write function code -0x0F (Modbus address 0xxxxx, representing 'Modbus 0 zone', relay);
[0053] Internal mapping of the communication system: y = k*x + b (where k = 1; b = 61440; y represents the communication address; x represents the register address).
[0054] Type: Word; Range: 0~511; Modbus address: 461441~461952; Communication address: F000~F1FF;
[0055] Mapping relationship;
[0056] Register addresses: 0 to 511;
[0057] Communication address: 0xF000~0xF1FF;
[0058] Function codes: Read function code -0x03, Write function code -0x10 (Modbus address 4xxxxx, representing 'Modbus 4 zone', register);
[0059] Internal mapping of the communication system: y = k*x + b (where k = 1; b = 61440; y represents the communication address; x represents the register address).
[0060] In step 3, the communication attributes of the lower-level Modbus device of the serial port include: initial working state, serial port number, communication baud rate, data bit length, stop bit length, and data verification method.
[0061] In step 4, the status of the protocol data is checked before the communication packet is sent, and then the data in the buffer is taken out and sent to the lower-level Modbus device; after receiving the packet, the parsing logic is triggered first, and then the data is sent to the upper-level computer screen for display.
[0062] like Figure 2 As shown, another embodiment of the present invention provides a Modbus communication system based on HMI, comprising: a communication device attribute module, a communication device streaming module, a protocol parser, a communication device instruction module, a communication address module, and a communication device channel.
[0063] The communication device properties module is used to statically configure the runtime property options of the communication device (lower-level Modbus device).
[0064] Users can adjust attribute values according to their needs to ensure normal interaction with the actual devices used, thereby enhancing the system's adaptability to different devices. Communication device attributes include: acquisition cycle, initial working status, communication wait time, byte order, string encoding, verification options, etc.
[0065] The communication device attributes of the lower-level Modbus device via serial port also include: serial port number, communication baud rate, data bit width, and stop bit width.
[0066] The streaming module of the communication device is used to save and restore internal data, including saving and restoring device attributes, device channels, address mapping information, etc.
[0067] Streaming is a crucial method for saving and restoring system data, involving the processing of logic such as device attributes, device channels, and address mapping information. The streaming module's data processing ensures that HMI configuration information is correctly saved as a byte stream during operations such as project downloads, providing it for communication transmission or file management. During reverse streaming, the raw data is parsed into system memory data and passed to other modules for subsequent processing such as screen variable association or frame assembly.
[0068] Device streaming converts user-configured data into binary files for easier network transmission or storage. For example, if the user displays "Register SR address 0000", it is recorded internally as "SR.0000". When saving user data, it is converted into binary (53 52 2E 30 3030 30) by the streaming module and finally saved to a file.
[0069] The protocol parser interacts with the communication address module to assemble, parse, and verify data packets transmitted between the lower-level Modbus device's network interface or serial port during communication. Its interaction with the underlying communication system data involves calling the address module to parse network byte streams, caching communication layer data through references to the address module, and encapsulating common methods for parsing data packets, including framing, deframing, and verification.
[0070] After parsing the various fields of the data packet, the protocol parser sends the results back to the communication address module. The protocol parser includes two main categories of functions: reading and writing, involving command codes such as coil read, register read, single coil write, single register write, multiple coil write, and multiple register write.
[0071] The main function of a protocol parser is to parse and assemble communication packets.
[0072] For example, if the HMI screen needs to display the relevant data at addresses 0000 and 0001 of register SR, it needs to send a request to the lower-level machine via serial port and receive a response.
[0073] The protocol parser assembles a request frame according to the Modbus standard protocol: 01 03C0 00 00 02F8 0B;
[0074] 0x01: Device address (device attributes are specified by the user during configuration);
[0075] 0x03: Function code (read function code of register SR, provided by the communication address module);
[0076] 0xC0 0x00: Starting address (provided by the communication address module);
[0077] 0x00 0x02: Number of addresses (provided by the communication address module);
[0078] 0xF8 0x0B: Verification (implemented by the protocol parser).
[0079] The protocol parser parses the lower-level machine's response frame: 01 03 04 43 56BF 7D BF B6;
[0080] 0x01: Device address (consistent with the request);
[0081] 0x03: Function code (consistent with the request);
[0082] 0x04: Data segment length;
[0083] 0x43 0x56 0xBF 0x7D: Data segment;
[0084] BF B6: Verification.
[0085] After the parser verifies that the lower-level machine's response is normal, it decodes the frame and obtains the data at address C000 as 0x4356 and the data at address C001 as 0xBF7D. Then, it returns the data to the communication address module.
[0086] The communication address module is used to manage configuration files. It generates a configuration file for each lower-level Modbus device. Each configuration file includes the register or relay name, logical address, physical address, maximum block length, main address format, bit address format, read function code, and write function code of the lower-level Modbus device, forming an address mapping relationship between logical address and physical address.
[0087] The communication address module also provides runtime device attribute modification and custom address data reading and writing. During runtime, it controls device attributes and calls the protocol parser to perform specific address data reading and writing. It serves as the address logic data source for the protocol parser. It parses command string text and, through references to the device attribute module and the protocol parser, enables runtime adjustments to device attributes and custom address data reading and writing, providing an external device access interface.
[0088] The communication address module is the main implementation module for the runtime functionality of the configuration file. It implements the logic for converting between physical addresses and logical addresses within the system.
[0089] For example, the HMI screen needs to display 32-bit floating-point data at register address 0000.
[0090] The communication address module retrieves information from the configuration file based on the specified register:
[0091] Function code: 0x03 (read function code for register SR);
[0092] Starting address: 0xC000 (Register SR address 0000 is mapped to actual communication address C000);
[0093] Number of addresses: 2 (32-bit floating-point data types occupy 2 Modbus address lengths);
[0094] The retrieved address information is passed to the protocol parser, a request frame is assembled, and the system waits for the lower-level machine to respond.
[0095] The protocol parser returns addresses 0xC000-0x4356 and 0xC001-0xBF7D, and the communication address module processes them according to the required data type.
[0096] Floating-point 32-bit data uses two communication addresses. The data at addresses 0xC000 and 0xC001 are combined. The reading result represents the floating-point number 214.748 (0x4356BF7D). The data is then returned to other modules for display on the screen.
[0097] Communication Equipment Command Module: The HMI configuration software supports scripting languages. Users can use the communication equipment command module to write control logic according to business function requirements, and realize device communication and screen display, etc. In addition to public functions, the communication equipment command module also includes script function functions, such as network port parameter setting, serial port parameter setting, reading and writing specified protocol addresses, and rewriting registration IDs, which can control the device interaction process during the runtime.
[0098] The communication address module is also used to provide external access channel addresses for the registers or relays of the lower-level Modbus devices, parse the address mapping from the configuration file, and deliver the content to the communication streaming module for use in the runtime phase; at the same time, it parses the user interface input and provides feedback information based on the checking logic such as address continuity, address out-of-bounds, address segmentation, and address uniqueness.
[0099] Communication device channel: The device channel is the path for data exchange. The channel address corresponds to an address on the lower-level device. Depending on the selected data type, there may be multiple addresses. Users associate the channel with the controls on the HMI configuration screen. When the screen is active, the channel data is collected in real time.
[0100] Device communication status: Status values are updated in real time. The range of status values varies depending on the type of device, but the system defines commonly used error status codes. When communication is normal, the system sets the status to 0; when the communication system itself fails to load, the runtime framework sets the error code to -1; when the system fails to open a serial port or network port, the status value is set to -2. Users can manage communication connection status, troubleshoot hardware cables, or trigger abnormal alarms by associating with default device status channels.
[0101] This embodiment also includes a data acquisition block unit. The data acquisition block unit addresses the issue that, since protocol addresses and device channels are typically in a one-to-one relationship, data refresh can be slow or even cause screen stuttering when there are many channel addresses and a large amount of data to be acquired. The standard protocol provides a read address length field, and communication system acquisition optimization strategies can merge consecutive addresses from multiple channels into a single acquisition block. Then, based on the dispersion, block size, and address gaps between multiple acquisition blocks, these blocks are organized together. Finally, several channels can be refreshed simultaneously with a single communication data transmission, reducing the number of frames sent and the time overhead on the communication link, thus improving acquisition efficiency.
[0102] This embodiment also includes a mapping table tool. The mapping table tool addresses the issue that lower-level devices typically provide the relationship between physical and logical address segments. When users input address relationships into the communication system, they need to fill in the configuration fields according to address information, bit word registers, function codes, etc. Incorrect configuration files can also lead to communication errors. The mapping table tool simplifies the address configuration file generation process; users only need to fill in the original range mapping, without specifying the type or other information, and the configuration can be automatically exported and used as the address relationship table configuration for the communication system.
[0103] When configuring the configuration file, reasonable offsets and coefficient relationships are calculated based on specific addresses, and function codes are used to distinguish between bits and words. The communication system uses the information in the configuration file to convert the addresses on the channel into physical addresses for device access, determine address continuity, perform data packet verification, and provide runtime data read / write services.
[0104] When users fill in the requirement form address to generate the configuration file and fill in the channel address, the system provides address checking logic to prompt whether the mapping relationship can be created, address out of bounds, etc.; to avoid problems such as incorrect address relationships and unauthorized access to device addresses caused by improper human input.
[0105] The Modbus communication system provided by this invention is highly versatile. It transforms original user requirements into protocol address mapping relationships, eliminating the need for users to focus on specific communication addresses during HMI configuration. Users can utilize the same logical addresses as the devices to perform normal communication processes. During system operation, communication addresses are sorted and valid contiguous segments are merged, improving data acquisition efficiency.
[0106] This invention provides an automatically generated communication system that supports both serial and Ethernet communication. Different communication methods can share the same configuration file; only the communication type field needs to be adjusted to reuse it in the automatic communication system generation tool, generating both types of communication system files. During the configuration phase, both serial and Ethernet devices need to be created and mounted to different types of parent communication devices. After the configuration program is downloaded to the HMI, provided the hardware interface supports it, both devices can be started simultaneously, and communication data can be executed alternately between the different devices.
[0107] The embodiments described above are merely preferred embodiments for fully illustrating the present invention, and the scope of protection of the present invention is not limited thereto. Equivalent substitutions or modifications made by those skilled in the art based on the present invention are all within the scope of protection of the present invention.
Claims
1. A Modbus communication method based on HMI, characterized in that, It includes the following steps: Step 1: Parse the address requirement table of the lower-level Modbus device, establish the supported Modbus protocol address mapping relationship, and generate the configuration file; Step 2: Read and parse the configuration file to provide external access channel addresses for the registers or relays of the lower-level Modbus device; Step 3: According to the configuration file, display the modifiable lower-level Modbus device attribute options, as well as the lower-level Modbus devices that distinguish between serial port and Ethernet interfaces, and configure different communication device attributes, including serial port number or IP address. Step 4: Based on the channel address and communication device attributes of the lower-level Modbus device, realize communication between the upper-level computer and the lower-level Modbus device based on the Modbus protocol; In step 1, a configuration file is generated for each lower-level Modbus device. The configuration file includes the logical address and physical address of each register or relay of the lower-level Modbus device, forming an address mapping relationship between logical address and physical address. The channel address corresponds to the register or relay logic address of the lower-level Modbus device.
2. The Modbus communication method based on HMI as described in claim 1, characterized in that, The configuration file includes: register or relay name, logical address, physical address, maximum block length, main address format, bit address format, read function code, and write function code.
3. The Modbus communication method based on HMI as described in claim 1, characterized in that, In step 1, the address requirement table of the lower-level Modbus device is parsed. Based on the logical address and physical address range in the address requirement table, the offset and coefficient relationship are calculated. Then, based on the function code, the bit relay, word relay, bit register or word register are distinguished to generate a configuration file with address mapping relationship. The formula for calculating the offset and coefficient relationship is: y = k * x + b, where y represents the physical address, x represents the logical address, b is the offset, and k is the coefficient relationship.
4. The Modbus communication method based on HMI as described in claim 1, characterized in that, In step 3, the communication attributes of the lower-level Modbus device of the serial port include: initial working state, serial port number, communication baud rate, data bit length, stop bit length, and data verification method.
5. The Modbus communication method based on HMI as described in claim 1, characterized in that, In step 4, the status of the protocol data is checked before the communication packet is sent, and then the data in the buffer is taken out and sent to the lower-level Modbus device; after receiving the packet, the parsing logic is triggered first, and then the data is sent to the upper-level computer screen for display.
6. A Modbus communication system based on HMI, characterized in that, It includes: Communication device attribute module, protocol parser, communication address module, communication device channel; The communication device attribute module is used to statically configure the attribute options of the lower-level Modbus device during operation; The protocol parser interacts with the communication address module and is used to assemble, parse, and verify data packets transmitted between the lower-level Modbus device network interface or serial port during communication. The communication address module is used to manage configuration files. Each lower-level Modbus device generates its own configuration file, which includes the name of each register or relay of the lower-level Modbus device, logical address, physical address, maximum block length, main address format, bit address format, read function code, and write function code, forming an address mapping relationship between logical address and physical address. The communication address module is also used to provide an external access channel address for the registers or relays of the lower-level Modbus device; The communication device channel provides a device channel with a channel address for data exchange, and the channel address corresponds to the register or relay logic address of the lower-level Modbus device.
7. The HMI-based Modbus communication system as described in claim 6, characterized in that, It also includes: a streaming module for communication equipment; The communication device streaming module is used to save and restore internal data, including saving and restoring device attributes, device channels, and address mapping information, and providing them to the communication address module.
8. The HMI-based Modbus communication system as described in claim 6, characterized in that, It also includes: a communication equipment instruction module; The communication device instruction module is used to write control logic to realize device communication and screen display.
9. The HMI-based Modbus communication system as described in claim 6, characterized in that, It also includes: a data acquisition block unit; The acquisition block unit is used to merge the continuous addresses of multiple device channels when there are many channel addresses and a large amount of data to be acquired. Multiple channels are merged into one acquisition block. Then, based on the dispersion, block size, and address gap between multiple acquisition blocks, multiple blocks are organized together to achieve simultaneous refresh of several channels through a single communication data transmission and reception.
Citation Information
Patent Citations
Method and device for binding PLC (Programmable Logic Controller) address of upper computer and electronic equipment
CN115567481A
Smart Functionality for Discrete Field Devices and Signals
US20200103946A1