A self-identification method and system based on serial port MODBUS communication protocol

By using the self-identification method of the serial MODBUS communication protocol, the master station sends broadcast addressing, random address encoding, and unaddressed commands to the slave station, which solves the configuration errors and communication anomalies caused by manual configuration in the existing technology, and realizes slave station self-identification and system interconnection.

CN117527762BActive Publication Date: 2026-04-17NANJING ZHIRUI ENERGY INTERNET RES INST CO LTD
View PDF 4 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
NANJING ZHIRUI ENERGY INTERNET RES INST CO LTD
Filing Date
2023-11-27
Publication Date
2026-04-17

AI Technical Summary

Technical Problem

In intelligent power monitoring systems, the existing MODBUS communication protocol self-identification method requires manual configuration by technicians, which can easily lead to configuration errors and communication anomalies, and is not suitable for all types of application scenarios.

Method used

A self-identification method based on the serial port MODBUS communication protocol is adopted. The master station sends broadcast addressing, random address encoding and no addressing command to the slave station to realize the slave station's self-identification, reduce manual configuration work and prevent errors.

Benefits of technology

It enables self-identification of slave stations, reduces the configuration work for technical personnel, prevents communication anomalies caused by configuration errors, and improves the interconnectivity of the system.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117527762B_ABST
    Figure CN117527762B_ABST
Patent Text Reader

Abstract

This invention relates to the field of power equipment technology, specifically to a self-identification method and system based on the MODBUS serial communication protocol. The method includes: a numbering module for sequentially numbering all slave addresses; a broadcast addressing module for sending broadcast addressing commands from the master station to the corresponding slave stations connected to the bus; an unaddressed module for sending unaddressed commands from the master station to the corresponding slave stations not connected to the bus; a random address encoding module for sending random address encoding commands to multiple slave stations with the same address number; and a slave station response module for enabling the slave stations to respond according to the corresponding commands received from the broadcast addressing module, the unaddressed module, and the random address module. This invention transforms the process of manually configuring master and slave information, which previously required technicians, into a self-identifying process for both master and slave stations, reducing the configuration work for technicians and preventing communication anomalies caused by configuration errors.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of power equipment technology, and specifically to a self-identification method and system based on the serial port MODBUS communication protocol. Background Technology

[0002] The rapid development of the national economy is inseparable from the strong support of the power industry. A safe, stable, and sufficient power supply is a prerequisite for the healthy development of the national economy. Intelligent power monitoring systems serve as the most important support for the stable, safe, reliable, and long-term operation of the power system. Intelligent power monitoring systems are a product of the digital and information age, and their development has greatly improved the convenience and reliability of electricity use. Especially with the vigorous development of many new energy sources, the powerful support provided by intelligent power monitoring systems is indispensable.

[0003] In intelligent power monitoring systems, in addition to ensuring organic coordination among internal systems, standard interfaces should also be provided for external systems and equipment to enable data exchange with other subsystems or equipment, ensuring continuous expansion and optimization of the system, giving the system a high degree of openness and compatibility, and enabling good interconnection and interoperability between systems.

[0004] In existing intelligent power monitoring systems, interface development and configuration often require a significant amount of manpower. Different devices in different projects require configuration and testing based on their installation types and addresses, which consumes considerable time configuring devices from different manufacturers to achieve interoperability within the intelligent power monitoring system. If the self-identification technology of the MODBUS serial communication protocol could be implemented, it would greatly reduce operator configuration time and communication anomalies caused by operator misconfiguration.

[0005] In the prior art, Chinese patent CN105323328A discloses a method for automatically identifying addresses using the MODBUS communication protocol on RS-485. This method requires the controller to have its own ID address, which cannot meet the needs of adapting to all types of application scenarios, and it requires optimization processing at the controller communication layer, making it inconvenient to implement.

[0006] Chinese patent CN 111786941 A discloses an automatic communication protocol identification method and a communication method. This method requires a separate controller configuration, which is clearly unsuitable for applications with high cost constraints. Installing the controller is also relatively inconvenient in renovation projects or projects where construction is difficult. Summary of the Invention

[0007] To address the aforementioned technical shortcomings, the present invention aims to provide a self-identification method and system based on the serial port MODBUS communication protocol. This addresses the inconvenience of operating the serial port MODBUS protocol, where technicians are required to repeatedly check and modify settings between the master and slave stations; and even where address duplication leads to communication failures, requiring technicians to configure and check each slave station individually, then modify and re-check the master station to ensure the error is resolved.

[0008] To solve the above technical problems, the present invention adopts the following technical solution: The present invention provides a self-identification method based on the serial port MODBUS communication protocol, characterized by comprising the following steps:

[0009] All slave addresses are numbered sequentially. The address range of slaves connected to the bus is 1-32, and the address range of unconnected slaves is 33-254. The master station sends different commands to the corresponding slaves in three phases: broadcast addressing, random address encoding, and no addressing. In the broadcast addressing phase, the master station sends a broadcast addressing command to the corresponding slaves with address numbers ranging from 1 to 32. The corresponding slaves send a response message with their own address to the master station based on the received broadcast addressing command. The master station receives the response messages with their own address from the corresponding slaves until all slaves have sent their responses. In the no addressing phase, the master station sends a no addressing command to the corresponding slaves with address numbers ranging from 33 to 254. The corresponding slaves receive the no addressing command and, based on their own address number, send a response message with their own address to the master station after a corresponding delay.

[0010] If multiple slave stations have the same address number during the broadcast addressing phase / non-addressing phase, the system enters the random address encoding phase. During the random address encoding phase, the master station sends a random address encoding command to multiple slave stations with the same address number. Each slave station with the same address randomly assigns an address number between 33 and 254 and modifies its own address number based on whether or not all generated random code addresses are duplicated until no random code addresses are duplicated.

[0011] Furthermore, after the initial power-on, the master station sends a broadcast addressing command and starts timing according to the current communication parameters. The broadcast addressing command is an address request message. When the slave station address number ranges from 1 to 32, the corresponding slave station immediately or waits for a corresponding time to send a response message of its own address to the master station and other slave stations with the same address number according to the received broadcast addressing command. When the master station receives the response message of the corresponding slave station's own address, it immediately clears the waiting time and starts the next timing cycle until all slave stations have finished sending.

[0012] Furthermore, when the slave station address number ranges from 1 to 32, the corresponding slave station immediately sends a response message with its own address to the master station and other slave stations with the same address number, based on the received broadcast addressing command.

[0013] If all address numbers in the range of 1-32 have slave stations, then all slave stations in that address number range will immediately send their respective response messages to the master station in ascending order of their address numbers.

[0014] Furthermore, when the slave station address number ranges from 1 to 32, the corresponding slave station waits for the appropriate time after receiving the broadcast addressing command and then sends a response message containing its own address to the master station and the slave station with the same address number.

[0015] If the address number of any corresponding slave station is N, then it waits for N cycles to send a response message of its own address to the master station;

[0016] If the corresponding slave station receives a response message from a slave station with a smaller address number M, it will wait for NM cycles to send a response message for its own address to the master station.

[0017] Furthermore, the period refers to the time from when the master station sends a broadcast addressing command to when it receives a response message from the slave station with address number 1, and the maximum waiting time for the master station is 32 periods.

[0018] Furthermore, the delay response time is the corresponding waiting period that exceeds the maximum waiting time of the main station.

[0019] Furthermore, based on whether any of the generated random code addresses have repeatedly modified their own address numbers, the following is considered:

[0020] If all generated random code addresses are unique, the corresponding slave station that receives the random address encoding command will generate a sequence code based on the order of the random code addresses and the number of slave stations added in the first random address encoding command. It will then modify its own address to the largest address number of the corresponding slave station during the master station's broadcast addressing phase, plus the sequence code generated by the corresponding slave station based on the random address encoding command.

[0021] If the generated random code address is duplicated, the master station receives garbled information, and multiple corresponding slave stations with the same address number re-enter the random address encoding stage for random encoding until all random code addresses are no longer duplicated.

[0022] A self-identification system based on the serial port MODBUS communication protocol includes:

[0023] The numbering module is used to sequentially number all slave addresses. The address numbering range of slaves connected to the bus is 1-32, and the address numbering range of unconnected slaves is 33-254.

[0024] The broadcast addressing module is used by the master station to send broadcast addressing commands to the corresponding slave stations with address numbers ranging from 1 to 32.

[0025] The Unaddressed module is used by the master station to send an Unaddressed command to the corresponding slave station with an address number range of 33-254;

[0026] The random address encoding module is used when multiple slave stations have the same address number, the master station sends a random address encoding command to multiple slave stations with the same address number;

[0027] The slave response module is used to enable the slave to respond to the corresponding commands sent by the broadcast addressing module, the unaddressed module, and the random address module.

[0028] The beneficial effects of this invention are as follows: This invention changes the process of manually configuring the master station and slave station information by technicians to automatic identification of the master station and slave station, thereby reducing the configuration work of technicians and preventing communication abnormalities caused by configuration errors by technicians. Attached Figure Description

[0029] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0030] Figure 1 This is a logic diagram of Embodiment 1 of the present invention.

[0031] Figure 2 This is a flowchart illustrating the broadcast addressing stage of Embodiment 1 of the present invention.

[0032] Figure 3 This is a flowchart illustrating the random address encoding stage of Embodiment 1 of the present invention.

[0033] Figure 4 This is a flowchart illustrating the unaddressed stage of Embodiment 1 of the present invention. Detailed Implementation

[0034] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0035] This invention provides a self-identification method based on the serial port MODBUS communication protocol, comprising the following steps:

[0036] All slave addresses are numbered sequentially. The address range for slaves connected to the bus is 1-32, and the address range for unconnected slaves is 33-254. Figure 1 As shown, the master station sends different commands to the corresponding slave stations in three stages: broadcast addressing stage, random address encoding stage, and no addressing stage. In the broadcast addressing stage, the master station sends broadcast addressing commands to the corresponding slave stations with address numbers ranging from 1 to 32. The corresponding slave stations send response messages of their own addresses to the master station according to the received broadcast addressing commands. The master station receives the response messages of their own addresses sent by the corresponding slave stations until all slave stations have sent their responses.

[0037] like Figure 4 As shown, during the unaddressed phase, the master station sends an unaddressed command to the corresponding slave station with an address number range of 33-254. Upon receiving the unaddressed command, the corresponding slave station sends a response message for its own address to the master station after a delay of a corresponding time based on its own address number. The delay time is the corresponding waiting period that exceeds the master station's maximum waiting time.

[0038] If multiple slave stations have the same address number during the broadcast addressing phase / unaddressing phase, the system enters the random address encoding phase. During the random address encoding phase, the master station sends a random address encoding command to multiple slave stations with the same address number. Each slave station with the same address randomly assigns an address number between 33 and 254 and modifies its own address number based on whether or not all generated random code addresses are duplicated until no random code addresses are duplicated.

[0039] It should be noted that there is one master device and multiple slave devices on a bus, and the master needs to poll the slave devices to request data. The usual practice is for the commissioning personnel to change the address information of each slave device on-site, but the approach here is to complete automatic identification. Therefore, after the initial power-on, the master station scans the slave devices on the bus.

[0040] Specifically, during the broadcast addressing phase, after the initial power-on, the master station sends a broadcast addressing command and starts timing based on the current communication parameters. The broadcast addressing command is an address request message. When the slave station address number ranges from 1 to 32, the corresponding slave station immediately or waits for a corresponding time to send a response message of its own address to the master station and other slave stations with the same address number, based on the received broadcast addressing command. When the master station receives the response message of the corresponding slave station's own address, it immediately clears the waiting time and starts the next timing cycle, until all slave stations have finished sending.

[0041] For example, if slave devices with addresses 1, 4, and 7 are connected to a certain bus, the master station will first receive the response message from slave device 1. Then, the master station will wait for 3 time slices before receiving the response message from slave device 4. Simultaneously, slave device 4 will immediately clear its waiting time after receiving the response message from slave device 1, and then wait 4-1 time slices before sending its own response message. The advantage of this is that it ensures the time difference between the master and slave devices, preventing misalignment in the interaction between them due to time discrepancies, which could lead to identification failure.

[0042] like Figure 2 As shown, when the slave station address number ranges from 1 to 32, the corresponding slave station immediately sends a response message with its own address to the master station and other slave stations with the same address number, based on the received broadcast addressing command.

[0043] If all address numbers in the range of 1-32 have slave stations, then all slave stations in that address number range will immediately send their respective response messages to the master station in ascending order of their address numbers.

[0044] When the slave station address number ranges from 1 to 32, the corresponding slave station waits for the appropriate time after receiving the broadcast addressing command and then sends a response message containing its own address to the master station and the slave station with the same address number.

[0045] Let the address number of any corresponding slave station be N. It waits N cycles to send a response message for its own address to the master station. If the corresponding slave station receives a response message for its own address from a neighboring slave station with a smaller address number M, it waits NM cycles to send a response message for its own address to the master station. The cycle refers to the time from when the master station sends the broadcast addressing command to when it receives the response message from slave station number 1, and the master station's maximum waiting time is 32 cycles. For example, slave station 2 initially waits for 2 cycles. However, if slave station 2 detects that slave station 1 has responded to the master station by sending a response message for its own address, its timing cycle changes to 1 cycle. After the cycle expires, slave station 2 responds to the master station. As another example, slave station 5 detects the response from slave station 1, its waiting cycle changes from 5 to 4 cycles. If it receives no response message from any slave station within 4 cycles, it assumes that no slave station exists between 2 and 4, and after waiting for 4 cycles, slave station 5 responds.

[0046] like Figure 3 As shown, the modification of its own address number based on whether all generated random code addresses are duplicated includes: If all generated random code addresses are not duplicated, the corresponding slave station receiving the random address encoding command generates a sequence code based on the order of the random code addresses and the number of slave stations added in the first random address encoding command, and modifies its own address to the largest address number of the corresponding slave station in the master station's broadcast addressing phase plus the sequence code generated by the corresponding slave station according to the random address encoding command based on the largest address number; for example, in the broadcast addressing phase, if the master station detects multiple slave devices with address 1, 2, 3, and 4, then in the random address encoding phase, addresses 1, 3, and 4 are excluded, and only the multiple slave devices with address 2 are processed. Then, after receiving the random address encoding command sent by the master station, the multiple slave devices with address 2 change their own addresses to a random code between 33 and 354. Suppose there are two slave devices with address 2 whose addresses are randomly generated as 55 and 67. In order, the master station recognizes these two slave devices with addresses 2 and sorts them into 1 and 2, which are the original slave devices with duplicate addresses 2. Since the address number of the last slave device is 4, there are 2 devices in the random code encoding stage, in the order of 1 (55) and 2 (67). Thus, the original multiple addresses of 2 will become addresses of 4+1 and 4+2. That is, two devices with addresses 5 and 6 are added at the end of the original broadcast addressing stage. The original multiple devices with duplicate addresses of 2 are now changed to addresses of 5 and 6. That is, to change the address, it is necessary to judge the last address plus the offset address of the random code, and then add the unaddressed sequence. The broadcast address is 4. Then the actual slave device address generated by the duplicate address 2 is offset by 2 devices. Finally, the unaddressed slave device sequence number is added, which is 4+2+1.

[0047] If the generated random code address is duplicated, the master station receives garbled information, and multiple corresponding slave stations with the same address number re-enter the random address encoding stage for random encoding until all random code addresses are no longer duplicated.

[0048] Example 2

[0049] Based on the method provided in Embodiment 1, this embodiment also provides a system as follows:

[0050] The numbering module is used to sequentially number all slave addresses. The address numbering range of slaves connected to the bus is 1-32, and the address numbering range of unconnected slaves is 33-254.

[0051] The broadcast addressing module is used by the master station to send broadcast addressing commands to the corresponding slave stations with address numbers ranging from 1 to 32.

[0052] The Unaddressed module is used by the master station to send an Unaddressed command to the corresponding slave station with an address number range of 33-254;

[0053] The random address encoding module is used when multiple slave stations have the same address number, the master station sends a random address encoding command to multiple slave stations with the same address number;

[0054] The slave response module is used to enable the slave to respond to the corresponding commands sent by the broadcast addressing module, the unaddressed module, and the random address module.

[0055] The above description is merely a preferred embodiment of the present invention and is not intended to limit the present invention. Although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art can still modify the technical solutions described in the foregoing embodiments or make equivalent substitutions for some of the technical features. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the protection scope of the present invention.

Claims

1. A self-identification method based on serial port MODBUS communication protocol, characterized in that, Includes the following steps: All slave addresses are numbered sequentially. The address range of slaves connected to the bus is 1-32, and the address range of unconnected slaves is 33-254. The master station sends different commands to the corresponding slaves in three stages: broadcast addressing, random address encoding, and no addressing. In the broadcast addressing stage, the master station sends a broadcast addressing command to the corresponding slave with address numbers ranging from 1 to 32. The corresponding slave sends a response message with its own address to the master station according to the received broadcast addressing command. The master station receives the response messages with its own address from the corresponding slaves until all slaves have sent their responses. During the unaddressed phase, the master station sends an unaddressed command to the corresponding slave station with an address number range of 33-254. Upon receiving the unaddressed command, the corresponding slave station sends a response message for its own address to the master station after a delay based on its own address number. If multiple slave stations have the same address number during the broadcast addressing phase / non-addressing phase, the system enters the random address encoding phase. During the random address encoding phase, the master station sends a random address encoding command to multiple slave stations with the same address number. Each slave station with the same address randomly assigns an address number between 33 and 254 and modifies its own address number based on whether or not all generated random code addresses are duplicated until no random code addresses are duplicated.

2. The self-identification method based on the serial port MODBUS communication protocol as described in claim 1, characterized in that, After the initial power-on, the master station sends a broadcast addressing command and starts timing according to the current communication parameters. The broadcast addressing command is an address request message. When the slave station address number ranges from 1 to 32, the corresponding slave station immediately or waits for a corresponding time to send a response message of its own address to the master station and other slave stations with the same address number. When the master station receives the response message of the corresponding slave station's own address, it immediately clears the waiting time and starts the next timing cycle until all slave stations have sent their responses.

3. The self-identification method based on the serial port MODBUS communication protocol as described in claim 2, characterized in that, When the slave station address number ranges from 1 to 32, the corresponding slave station immediately sends a response message with its own address to the master station and other slave stations with the same address number, based on the received broadcast addressing command. This response message includes: If all address numbers in the range of 1-32 have slave stations, then all slave stations in that address number range will immediately send their respective response messages to the master station in ascending order of their address numbers.

4. The self-identification method based on the serial port MODBUS communication protocol as described in claim 2, characterized in that, When the slave station address number ranges from 1 to 32, the corresponding slave station waits for the appropriate time after receiving the broadcast addressing command and then sends a response message containing its own address to the master station and the slave station with the same address number. If the address number of any corresponding slave station is N, then it waits for N cycles to send a response message of its own address to the master station; If the corresponding slave station receives a response message from a slave station with a smaller address number M, it will wait for NM cycles to send a response message for its own address to the master station.

5. The self-identification method based on the serial port MODBUS communication protocol as described in claim 4, characterized in that, The cycle is the time from when the master station sends a broadcast addressing command to when it receives a response message from the slave station with address number 1, and the maximum waiting time for the master station is 32 cycles.

6. A self-identification method based on the serial port MODBUS communication protocol as described in claim 1 or 5, characterized in that, The delay response time is the corresponding waiting period that exceeds the maximum waiting time of the main station.

7. The self-identification method based on the serial port MODBUS communication protocol as described in claim 1, characterized in that, Based on whether any of the generated random code addresses have been repeatedly modified to change their own address number, including: If all generated random code addresses are unique, the corresponding slave station that receives the random address encoding command will generate a sequence code based on the order of the random code addresses and the number of slave stations added in the first random address encoding command. It will then modify its own address to the largest address number of the corresponding slave station during the master station's broadcast addressing phase, plus the sequence code generated by the corresponding slave station based on the random address encoding command. If the generated random code address is duplicated, the master station receives garbled information, and multiple corresponding slave stations with the same address number re-enter the random address encoding stage for random encoding until all random code addresses are no longer duplicated.

8. A self-identification system based on the self-identification method according to any one of claims 1 to 7 using the serial port MODBUS communication protocol, characterized in that, include: The numbering module is used to sequentially number all slave addresses. The address numbering range of slaves connected to the bus is 1-32, and the address numbering range of unconnected slaves is 33-254. The broadcast addressing module is used by the master station to send broadcast addressing commands to the corresponding slave stations with address numbers ranging from 1 to 32. The Unaddressed module is used by the master station to send an Unaddressed command to the corresponding slave station with an address number range of 33-254; The random address encoding module is used when multiple slave stations have the same address number, the master station sends a random address encoding command to multiple slave stations with the same address number; The slave response module is used to enable the slave to respond to the corresponding commands sent by the broadcast addressing module, the unaddressed module, and the random address module.

Citation Information

Patent Citations

  • Automatic address identification method by utilizing MODBUS communication protocol on RS-485

    CN105323328A

  • Communication protocol automatic identification method and communication method

    CN111786941A

  • Method for address configuration of master / slave system

    CN116636198A

  • Automatic distributing and setting up address method based on master-slave communication mode

    CN1674593A