A method for allocating addresses in a master-slave bus communication system
By using the slave's unique product identification code in the industrial bus communication system to calculate the sending interval time, and automatically adjust the sending time of the allocated address request message, solving the problem of inconvenient slave address setting and long automatic address allocation time in the prior art. , realizes fast and reliable slave address allocation and improves communication efficiency.
Patent Information
- Application Number
- CN202211600838.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-12-12
- Publication Date
- 2024-12-03
- Estimated Expiration
- 2042-12-12
AI Technical Summary
The existing industrial bus communication systems have inconvenience in manual settings of slave address settings and problems such as long automatic address allocation time and poor reliability, resulting in unstable system communication.
The slave's own unique product identification code calculates the sending interval time, automatically adjusts the sending time of the allocated address request message, realizes the rapid automatic allocation of the slave address, and resolves bus conflicts through conflict detection, and uses pure software to achieve no need to increase hardware costs .
It realizes the rapid automatic allocation of slave communication addresses, reduces the risk of bus conflict, avoids the increase in hardware costs, and improves communication efficiency and reliability.
Smart Images

Figure CN116016445B_ABST
Abstract
Description
Technical Field
[0001] The invention relates to an address allocation method for a master-slave bus communication system, belonging to the technical field of industrial communication buses. Background Art
[0002] Industrial bus communication systems such as Modbus, profibus, and HART belong to master-slave communication. The communication requires that the address of the slave must be unique and non-repetitive. Generally, the slave address is set one by one using the slave's DIP switch or the human-machine interface input method. It is generally necessary to manually set the slave's communication address, which requires the setting of the slave address on site, which brings inconvenience to the on-site installation. At the same time, after the faulty equipment is replaced, if the slave's communication address is forgotten or set incorrectly, the entire system communication will not work properly. The existing automatic address implementation solutions mainly include adding address recognition lines, dual serial ports, applying for address allocation in idle state, virtual addresses, token rings, etc., which require increased hardware costs, or lead to a long time to complete the address allocation, poor reliability, and affect communication efficiency. Summary of the invention
[0003] The technical problem to be solved by the present invention is to overcome the deficiencies of the prior art and provide an address allocation method for a master-slave bus communication system, which can quickly and automatically allocate slave communication addresses at a very low cost.
[0004] The present invention specifically adopts the following technical solutions to solve the above technical problems:
[0005] A method for allocating addresses in a master-slave bus communication system comprises the following steps:
[0006] The slave receives the first broadcast address allocation request message of the master, calculates the first transmission interval according to the first transmission interval function with the slave's own unique product identification code as an independent variable, and sends the address allocation request response message containing the slave's own product identification code to the master according to the first transmission interval;
[0007] The slave receives the address confirmation message including the slave's product identification code and the assigned address sent by the host in point-to-point communication, updates its own address with the assigned address therein and sends an address confirmation response message to the host;
[0008] The slave receives the nth broadcast address allocation request message from the master, and determines whether its own address has been allocated. If yes, it does not respond. If not, it calculates the nth sending interval time according to the nth sending interval time function with the slave's own unique product identification code as the independent variable, and sends the address allocation request response message containing the slave's own product identification code to the master according to the nth sending interval time; wherein n=2, 3, ..., N, N is the number of times the master broadcasts the address allocation request message, and the master performs conflict detection after each broadcast of the address allocation request message. If a bus conflict is detected, the master broadcasts the address allocation request message again until no bus conflict is detected.
[0009] Compared with the prior art, the technical solution of the present invention has the following beneficial effects:
[0010] The present invention calculates the sending interval time of the response information of the slave machine to the address allocation request message according to the unique product identification code of the slave machine. This scheme is not easy to cause bus conflicts. Even if conflicts occur, they can be quickly resolved by automatically adjusting the sending interval time, thereby realizing the rapid automatic allocation of the slave machine communication address. In addition, the automatic address allocation of the present invention is realized by pure software, without increasing hardware costs. BRIEF DESCRIPTION OF THE DRAWINGS
[0011] Figure 1 It is a schematic diagram of the message interaction model between the host and the slave;
[0012] Figure 2 This is a flowchart of automatically allocating addresses to hosts;
[0013] Figure 3 Schematic diagram of the process of assigning addresses to slave receivers;
[0014] Figure 4 This is an example of the host conflict detection message interaction model;
[0015] Figure 5 This is a schematic diagram of the host conflict detection process. DETAILED DESCRIPTION
[0016] Aiming at the deficiency of the existing automatic address allocation scheme of the master-slave bus communication system in solving bus conflicts, the idea of the present invention is to calculate the sending interval of the response information of the slave to the address allocation request message according to the unique product identification code of the slave.
[0017] Specifically, the address allocation method of the master-slave bus communication system proposed by the present invention comprises the following steps:
[0018] The slave receives the first broadcast address allocation request message of the master, calculates the first transmission interval according to the first transmission interval function with the slave's own unique product identification code as an independent variable, and sends the address allocation request response message containing the slave's own product identification code to the master according to the first transmission interval;
[0019] The slave receives the address confirmation message including the slave's product identification code and the assigned address sent by the host in point-to-point communication, updates its own address with the assigned address therein and sends an address confirmation response message to the host;
[0020] The slave receives the nth broadcast address allocation request message from the master, and determines whether its own address has been allocated. If yes, it does not respond. If not, it calculates the nth sending interval time according to the nth sending interval time function with the slave's own unique product identification code as the independent variable, and sends the address allocation request response message containing the slave's own product identification code to the master according to the nth sending interval time; wherein n=2, 3, ..., N, N is the number of times the master broadcasts the address allocation request message, and the master performs conflict detection after each broadcast of the address allocation request message. If a bus conflict is detected, the master broadcasts the address allocation request message again until no bus conflict is detected.
[0021] In order to facilitate public understanding, the technical solution of the present invention is described in detail below through a specific embodiment and in conjunction with the accompanying drawings:
[0022] Taking the Modbus bus communication system as an example, it adopts Figure 1 The host and slave message interaction model shown is a request-reply model.
[0023] In broadcast mode, the host sends broadcast message 1, i.e., address allocation request message request, to all n slaves.
[0024] Each slave has a unique product identification code. All slaves calculate their own transmission intervals according to their own product identification codes according to a preset transmission interval function. The slave responds to the master's allocation address request message by sending a response message reply1-replyn containing its own product identification code.
[0025] After the host receives the response messages reply1-replyn containing its own product identification code from all slaves, it collects the product identification codes of the connected slaves and establishes a management list of the slaves. Then the host assigns addresses to the slaves according to certain rules based on the collected slave product identification codes. The host sends address confirmation messages request1-requestn to the slaves for point-to-point communication to confirm the assigned addresses. After receiving the address confirmation message containing its own product identification code, the slave responds to the host address confirmation message.
[0026] The host performs bus conflict detection based on the response message received from the slave. If a bus conflict is detected, the host broadcasts the address allocation request message request again. The slave receives the address allocation request message broadcasted again by the host and determines whether its own address has been allocated. If so, it does not respond. If not, it recalculates its own sending interval according to its own product identification code according to the new sending interval time function, and responds to the host's address allocation request message according to the sending interval time, and sends a response message containing its own product identification code.
[0027] And so on, until the host does not detect a bus conflict, the address is automatically assigned.
[0028] The product identification code is a unique identification code of the product, which can be a group of representative numbers or letters or a combination of numbers and letters, such as 2208010001, BBJHJAJJJA, CK2208010001, etc., which are composed of the year / month / product code / serial number of the product. The sending interval time of the slave's response to the allocation address request message in each round is calculated based on a series of preset sending interval time functions with its own product identification code as the independent variable. The sending interval time function can be a linear function, a weighted random function, a hash function, etc. For example, the first response information sending interval time t is represented by a linear function t=reference interval time*product identification code 0th bit, the second response information sending interval time can be t=reference interval time*product identification code 1st bit, the third response information sending interval time can be t=reference interval time*product identification code 2nd bit, and so on, and the number of product identification code data bits used to calculate the sending interval time is shifted down one bit in turn. Alternatively, the sending interval time t is represented by a weighted random function t=fw(ID), where fw is a weighted random function, and the parameter ID is the product identification code. Each sending interval time is calculated by the weighted random function of the product identification code. Alternatively, the sending interval time t is represented by a hash function t=hash(ID), where hash is a hash function, and the parameter ID is the product identification code. Each time the sending interval time is adjusted, the sending interval time is calculated by the product identification code hash function, and the next calculated sending interval time is calculated by the hash function using the previous sending interval time as a parameter of the hash function; the hash function can be constructed based on the unique characteristics of the product identification code, such as: taking the last four digits of the product identification code (denoted as m), taking the time calculated by m*the reference interval time as the reference, and using the division and remainder method, and the remainder obtained is used as the current sending interval time.
[0029] The address allocation rule adopted by the host can be based on various existing address allocation rules, such as the time sequence in which the host receives the response from the slave, and the address allocation is incremented from the valid address.
[0030] The host can establish a slave management list according to actual needs, such as the slave management list shown in Table 1. The host collects the product identification code of the slave according to the response information reply1-replyn of the slave's response to the host's address request message, and then establishes a slave management list based on the slave's product identification code. The address is assigned to the slave in the order of response time, and it is marked whether it is assigned. The default address is 0, which is marked as unassigned, and a non-zero address is allocated.
[0031] Table 1 Slave management list
[0032] Product Identification Code Modbus Address Is it allocated? Product identification code 1 1 yes Product Identification Code 2 2 yes … … … Product Identification Code 0 no … … … Product Identification Code n yes
[0033] Figure 2 The workflow of automatic address allocation by the host is shown: the host is powered on and starts, sends broadcast message 1 address allocation request message to all slaves, waits for a preset time, and if an address allocation request response message is received from the slave, it is determined that the address is not allocated, and then the address allocation message is sent point-to-point to the specified slave according to the product identification code; if the address allocation request response message is not received from the slave, the address allocation request message is retried, the host waits for a preset time, receives the address allocation response message from the specified slave, and the automatic address allocation ends.
[0034] Figure 3 The flow of receiving the assigned address by the slave is shown: the slave is powered on and starts, reads the local configuration, and if it receives the assigned address request message broadcast by the host and the address is not assigned, it calculates the sending interval according to the product identification code and the sending interval function, responds to the assigned address request message of the host according to the calculated sending interval, sends a response message containing its own product identification code, and then waits for the host's assigned address message. If the product identification code in the received assigned address message is consistent with its own product identification code, it responds to the assigned address message; if it does not receive the host's assigned address message, when it receives the assigned address request message broadcast by the host again, it recalculates the sending interval according to the product identification code and the new sending interval function, and sends the assigned address request response message containing its own product identification code again according to the new sending interval, and then waits for the host's assigned address message, ... until it receives the assigned address message in which the product identification code is consistent with its own product identification code, and the slave responds to the assigned address message.
[0035] Figure 4 shows an example of the host conflict detection message interaction model, Figure 5The host conflict detection process is shown. After the slave receives the address allocation request message request broadcast by the host, the slave calculates its own transmission interval according to its own product identification code according to the transmission interval function, and sends a response message reply1-replyn containing its own product identification code according to the calculated transmission interval to respond to the host's address allocation request message. If there are multiple slave conflicts on the bus, multiple slave response messages will appear on the bus at the same time, causing the host to receive an error response message. When the host receives the slave response message, if it determines that the transmission interval has timed out or the check error or frame error occurs, it considers the response to be abnormal, and the host marks the broadcast address allocation request message request as an error. The host establishes a slave management list, records the slave product identification code that has successfully responded, and allocates the communication address according to certain rules. If reply1-replyi responds successfully, the host broadcasts address confirmation messages request1-requesti one by one. After receiving the slave, it first compares its own product identification code with the product identification code contained in the broadcast address confirmation message request1-requesti. If they match, the slave sends an address confirmation message reply_p1-reply_pi containing the product identification code. The host first assigns a communication address to the slave that successfully responds to the host's broadcast address allocation request message request, and then sends a broadcast address allocation request message request again according to the error mark of the broadcast address allocation request message request, waiting for the slave to send an address confirmation message reply_pi-1-reply_pn containing the product identification code. After receiving the message, the slave determines whether its communication address has been assigned. If it has been assigned, it will not respond. If it has not been assigned, it will recalculate its own sending interval according to the product identification code and the sending interval time function, and send a response message containing its own product identification code again until all slave addresses are assigned. If the host still has conflicting messages from the slave, the above process is repeated to perform a new round of broadcast address allocation request process. In this way, bus conflicts are resolved by multiple conflict detections and repeated broadcast address allocation request processes, and automatic allocation of Modbus addresses is achieved.
Claims
1. An address allocation method for a master-slave bus communication system, characterized in that: The following steps are involved: The slave receives the first broadcast address allocation request message of the master, calculates the first transmission interval according to the first transmission interval function with the slave's own unique product identification code as an independent variable, and sends the address allocation request response message containing the slave's own product identification code to the master according to the first transmission interval; The slave receives the address confirmation message including the slave's product identification code and the assigned address sent by the host in point-to-point communication, updates its own address with the assigned address therein and sends an address confirmation response message to the host; The slave receives the nth broadcast address allocation request message from the host, and determines whether its own address has been allocated. If yes, it does not respond. If not, it calculates the nth sending interval time according to the nth sending interval time function with the slave's own unique product identification code as the independent variable, and sends the address allocation request response message containing the slave's own product identification code to the host according to the nth sending interval time; wherein n=2, 3, ..., N, N is the number of times the host broadcasts the address allocation request message, and the host performs conflict detection after each broadcast of the address allocation request message. If a bus conflict is detected, the address allocation request message is broadcast again until no bus conflict is detected.
