Communication address automatic distribution system and method
In the automatic communication address allocation system, the master device querys the comparison table based on the slave device's serial number and allocates the communication address, and solves the problem of error-prone setting of the communication address by manually setting the communication address, and realizes the effect of efficiently obtaining a unique address by the slave device, improving the accuracy of address allocation and the stability of network communication.
Patent Information
- Application Number
- CN202510050963.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-13
- Publication Date
- 2025-05-09
AI Technical Summary
In the prior art, manual setting of communication addresses is prone to errors, resulting in duplication or omission of addresses, time-consuming and inaccurate.
An automatic communication address allocation system is provided, and the master device and the slave device are connected through the RS485 bus. The master device queries the comparison table based on the serial number of the slave device. If it is recorded, the corresponding address will be sent, and if it is not recorded, the idle address will be assigned.
Ensure that slave devices efficiently join the network and obtain a unique communication address, improve the accuracy and flexibility of address allocation, avoid address conflicts and waste, and improve the stability and efficiency of network communication.
Smart Images

Figure CN119966950A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of device network access, and in particular to a system and method for automatically allocating communication addresses. Background Art
[0002] Currently, serial bus communications mostly use a master-slave mode, where the host polls the information of each slave device. After the slave device is installed at the factory, the debugging personnel need to set the communication address for each slave device and ensure that the communication address is unique and cannot be repeated to ensure that the system as a whole forms a network communication. This process is not only time-consuming but also prone to errors, such as duplicate or missing addresses. Summary of the invention
[0003] In order to solve the problem that manual setting of communication addresses in the prior art is prone to errors, the present application provides a system and method for automatic allocation of communication addresses.
[0004] In the first aspect, the present application provides a communication address automatic allocation system, which adopts the following technical solutions: A communication address automatic allocation system, comprising: a master device and at least one slave device connected via an RS485 bus; the slave device sends a network access request to the master device, the network access request including the serial number and current communication address of the slave device; If the current communication address is a default value, the master device queries a comparison table based on the serial number to determine whether the communication address corresponding to the serial number is recorded in the comparison table; If the communication address corresponding to the serial number is recorded in the comparison table, the master device sends address allocation information including the communication address corresponding to the serial number to the slave device; If the communication address corresponding to the serial number is not recorded in the comparison table, the master device determines an idle communication address from the comparison table, and sends address allocation information including the idle communication address to the slave device.
[0005] By adopting the above technical solution, the slave device sends a network access request including a serial number and a current communication address to the master device. The master device queries the comparison table based on the serial number. If it has been recorded, the corresponding communication address is sent. If it has not been recorded, an idle address is allocated. This mechanism ensures that the slave device can efficiently join the network and obtain a unique communication address, while improving the accuracy and flexibility of address allocation.
[0006] In a preferred example, the present application can be further configured as follows: the master device repeatedly sends the address allocation information to the slave device until it receives the allocation success information returned by the slave device, or the number of sending times reaches a preset number of times; if the number of sending times of the master device reaches the preset number of times and the allocation success information is not received, the communication address contained in the address allocation information is cleared from the comparison table.
[0007] By adopting the above technical solution, the master device repeatedly sends address allocation information to the slave device until it receives allocation success information or reaches a preset number of transmission times. If the latter occurs, the relevant communication address is cleared from the comparison table. This mechanism ensures the reliability and effectiveness of address allocation, avoids address conflicts and waste, and improves the stability and efficiency of network communications.
[0008] In a preferred example, the present application can be further configured as follows: if the communication address corresponding to the serial number is not recorded in the comparison table, and there is no idle communication address in the comparison table, the master device returns a silence indication message including a communication address as the default value, and the slave device enters silence after receiving the silence indication message, and displays on the slave end that the communication address is not assigned.
[0009] By adopting the above technical solution, when there is neither a communication address corresponding to the slave device serial number nor an idle address in the comparison table, the master device returns a silent indication message containing a default communication address, causing the slave device to enter a silent state and locally displaying that the communication address is not allocated. This mechanism effectively handles the situation where address allocation fails and avoids confusion in network communications.
[0010] In a preferred example, the present application may be further configured as follows: the comparison table records the correspondence between the known serial number and the known communication address; If the current communication address is not a default value, determining whether the serial number of the slave device is recorded in the comparison table; if the serial number of the slave device is recorded in the comparison table, comparing the current communication address of the slave device with the known communication address of the serial number of the slave device in the comparison table to see whether they are the same; If different, the current communication address is updated based on the known communication address.
[0011] By adopting the above technical solution, a comparison table is used to manage the correspondence between known serial numbers and communication addresses. When a slave device accesses the network, if its current communication address is not the default, the comparison table is checked to confirm whether the serial number exists and whether the communication address is consistent. If they are inconsistent, it is updated to the known communication address. This mechanism ensures the accuracy and consistency of the slave device's communication address, avoiding address conflicts and network communication confusion.
[0012] In a second aspect, the present application provides a method for automatically allocating communication addresses, which adopts the following technical solution: A communication address automatic allocation method is applied to a communication address automatic allocation system, the method is executed by a master device, and the method comprises: Receiving a network access request sent by a slave device, the network access request including a serial number and a current communication address of the slave device; If the current communication address is a default value, querying a comparison table based on the serial number to determine whether the communication address corresponding to the serial number is recorded in the comparison table; If the communication address corresponding to the serial number is recorded in the comparison table, the master device sends address allocation information including the communication address corresponding to the serial number to the slave device; If the communication address corresponding to the serial number is not recorded in the comparison table, the master device determines an idle communication address from the comparison table and sends address allocation information containing the idle communication address to the slave device. In summary, this application includes the following beneficial technical effects: In this application, the slave device sends a network access request containing a serial number and a current communication address to the master device. The master device queries the comparison table based on the serial number. If it has been recorded, it sends the corresponding communication address. If it has not been recorded, it allocates an idle address. This mechanism ensures that the slave device can efficiently join the network and obtain a unique communication address, while improving the accuracy and flexibility of address allocation. BRIEF DESCRIPTION OF THE DRAWINGS
[0013] Figure 1 It is a schematic diagram of the overall structure of a communication address automatic allocation system provided in an embodiment of the present application; Figure 2 is a flow chart of communication address allocation based on network access protocol provided in an embodiment of the present application; Figure 3 It is a flow chart of a method for automatically allocating communication addresses provided in an embodiment of the present application. DETAILED DESCRIPTION
[0014] The following is combined with Figure 1 -Attached Figure 3 This application is described in further detail.
[0015] This specific embodiment is merely an explanation of the present application and is not a limitation of the present application. After reading this specification, those skilled in the art may make modifications to the present embodiment without any creative contribution as needed, but such modifications are protected by the patent law as long as they are within the scope of the claims of the present application.
[0016] In order to make the purpose, technical solution and advantages of the embodiments of the present application clearer, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0017] In addition, the term "and / or" in this article is only a description of the association relationship of associated objects, indicating that there can be three relationships. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. In addition, the character " / " in this article, unless otherwise specified, generally means that the associated objects before and after are in an "or" relationship.
[0018] It should be noted that in the optional embodiments of the present application, the object information and other related data involved, when the embodiments in the present application are applied to specific products or technologies, need to obtain the permission or consent of the object, and the collection, use and processing of the relevant data need to comply with the relevant laws, regulations and standards of the relevant countries and regions. In other words, if the embodiments of the present application involve data related to the object, it needs to be obtained with the authorization and consent of the object, the authorization and consent of the relevant departments, and in compliance with the relevant laws, regulations and standards of the country and region. If personal information is involved in the embodiments, the acquisition of all personal information needs to obtain the consent of the individual. If sensitive information is involved, the separate consent of the information subject needs to be obtained. The embodiments also need to be implemented with the authorization and consent of the object.
[0019] The present embodiment provides a system for automatically allocating communication addresses, including: a master device and at least one slave device connected via an RS485 bus. The master device uniformly summarizes the serial numbers of the slave devices, and then allocates and issues different communication addresses, waiting for replies from the slave devices. Receiving a reply from the slave device indicates that the communication address allocation is successful and an identification is made. If it is unsuccessful, it is resent until the communication address allocation is successful, thereby allocating unique communication addresses for slave devices with different serial numbers. After the slave device is powered on for the second time, it determines whether its own communication address is the default value. If it is, it proves that the communication address has not been allocated. If not, it proves that the communication address has been allocated and does not need to be reallocated. Replace or add a slave device and follow the above-mentioned network access protocol to perform the network access operation. The master device can also forcibly modify the communication address of the slave device and allocate it again.
[0020] See also Figure 1 , which shows the overall structural diagram of the communication address automatic allocation system. The master device and the slave device are powered on and self-tested respectively. The master device is initialized after powering on and self-testing, and the slave device is powered on and self-tested and checks its own communication address ( Figure 1For any slave device, if the communication address of the slave device is the default value, it means that the slave device is not currently assigned a communication address, and the master device can assign a communication address to the slave device; if the communication address of the slave device is not the default value, it means that the slave device has been assigned a communication address, and the master device can verify the communication address of the slave device. If the original communication address of the slave device is not recorded in the master device, the master device can re-assign a new communication address to the slave device, thereby completing the slave device's access to the network.
[0021] See also Figure 2 , which shows a communication address allocation flow chart based on the network access protocol, where a slave device sends a network access request to a master device, the network access request including the serial number and current communication address of the slave device; if the current communication address is a default value, the master device queries a comparison table based on the serial number to determine whether the communication address corresponding to the serial number is recorded in the comparison table; if the communication address corresponding to the serial number is recorded in the comparison table, address allocation information including the communication address corresponding to the serial number is sent to the slave device; if the communication address corresponding to the serial number is not recorded in the comparison table, an idle communication address is determined from the comparison table, and address allocation information including the idle communication address is sent to the slave device.
[0022] Specifically, after the slave device is powered on, it self-checks whether its own communication address is the default value 0xFF. If it is the default value, the slave device reports a network access request to the master device. The network access request sent by the slave device to the master device includes: Table 1 shows the frame format of the slave device's network access request. The slave device's network access request includes: network access request frame flag, the slave device's serial number length, the slave device's serial number, the current communication address (because the slave device's communication address is the default value, the current communication address in the network access request pushed at this time is the default value 0xFF) and CRC check.
[0023] After the slave device reports the network access request, it waits for the reply from the master device. If the slave device receives the address allocation information returned by the master device within the preset time, the slave device stops sending the network access request, and the communication address allocation of the slave device is completed, that is, the slave device successfully accesses the network; if the slave device does not receive the address allocation information returned by the master device within the preset time, the slave device reports the network access request again after a random delay of a period of time based on the preset time, and waits for the reply from the master device within the preset time after the second report. If there is no reply, the slave device reports the network access request for the third time after a random delay of a period of time based on the preset time after the second report, and so on, until the address allocation information replied by the master device is received. Among them, the preset time is a fixed time, and the preset time is optional, and the random delay is a time range, and the random delay is optional, and the random delay is 10% of the preset time to 3 times of the preset time. When the preset time is 1s, the random delay is 0.1s-3s.
[0024] The process of assigning a communication address from a slave device to a master device includes: if the current communication address of the slave device is a default value, the master device queries a comparison table based on the serial number in the network access request, and the comparison table is pre-set and stored in the master device, representing the correspondence between known communication addresses of registered known serial numbers. If the communication address corresponding to the serial number is recorded in the comparison table, the communication address is used as the communication address assigned to the slave device. If the communication address corresponding to the serial number is not recorded in the comparison table, the idle communication address is searched from the comparison table. If there are multiple idle communication addresses, the one with the smallest communication address is selected as the communication address assigned to the slave device, and the correspondence between the assigned idle communication address and the serial number of the slave device is updated in the comparison table. Among them, the frame format of the address allocation information sent by the master device to the slave device is shown in Table 2. The address allocation information includes: the network access setting frame flag, the serial number length of the slave device, the serial number of the slave device, the communication address assigned to the slave device, and the CRC check.
[0025] In this embodiment, the slave device sends a network access request including a serial number and a current communication address to the master device. The master device queries the comparison table based on the serial number. If it has been recorded, the corresponding communication address is sent. If it has not been recorded, an idle address is allocated. This mechanism ensures that the slave device can efficiently join the network and obtain a unique communication address, while improving the accuracy and flexibility of address allocation.
[0026] In a possible implementation method of an embodiment of the present application, the correspondence between known serial numbers and known communication addresses is recorded in a comparison table; if the current communication address is not a default value, it is determined by querying whether the serial number of the slave device is recorded in the comparison table; if the serial number of the slave device is recorded in the comparison table, the current communication address of the slave device is compared with the known communication address of the slave device in the comparison table to see if they are the same; if they are different, the current communication address is updated based on the known communication address.
[0027] Specifically, if the current communication address of the slave device is not the default value, it indicates that the communication address of the slave device has been allocated. The slave device sends a network access request including the current communication address to the master device. The network access request of the slave device includes: network access request frame flag, the serial number length of the slave device, the serial number of the slave device, the current communication address (the communication address of the slave device is not the default value) and CRC check. After receiving the network access request of the slave device, the master device searches the comparison table to determine whether there is a record in the comparison table for the correspondence between the serial number of the slave device and the current communication address. If there is no record of the corresponding relationship, it indicates that the slave device does not belong to the eligible network access device, and the information of the slave device is recorded and sent to the management personnel; if there is a record of the corresponding relationship, it indicates that the slave device has successfully accessed the network. If the communication address corresponding to the serial number of the slave device stored in the comparison table is another, the current communication address of the slave device is updated based on the other communication address recorded in the comparison table, thereby completing the network access of the slave device.
[0028] This embodiment manages the correspondence between known serial numbers and communication addresses through a comparison table. When a slave device accesses the network, if its current communication address is non-default, the comparison table is checked to confirm whether the serial number exists and whether the communication address is consistent. If they are inconsistent, it is updated to the known communication address. This mechanism ensures the accuracy and consistency of the slave device's communication address, avoiding address conflicts and network communication confusion.
[0029] In a possible implementation method of an embodiment of the present application, the master device repeatedly sends address allocation information to the slave device until it receives allocation success information returned by the slave device, or the number of transmissions reaches a preset number of times; if the number of transmissions by the master device reaches the preset number of times and no allocation success information is received, the communication address contained in the address allocation information is cleared from the comparison table.
[0030] In this embodiment, after the master device sends the address allocation information to the slave device, it waits for the slave device to reply with the allocation success information. Table 3 shows the frame format of the allocation success information replied by the slave device, including: network access confirmation frame flag, slave device serial number length, slave device serial number, slave device assigned communication address and CRC check. Among them, the preset number of times can be set according to actual needs, and this embodiment is not limited. If the subsequent master device receives data pushed by a slave device that has not been assigned a communication address, it means that there is a slave device that has not successfully accessed the network to communicate with the master device, and the master device automatically sends a silent indication message with a communication address of the default value 0xFF to make the slave device silent.
[0031] In this embodiment, the master device repeatedly sends address allocation information to the slave device until it receives allocation success information or reaches a preset number of transmission times. If the latter occurs, the relevant communication address is cleared from the comparison table. This mechanism ensures the reliability and effectiveness of address allocation, avoids address conflicts and waste, and improves the stability and efficiency of network communications.
[0032] A possible implementation method of an embodiment of the present application is that if the communication address corresponding to the serial number is not recorded in the comparison table, and there is no idle communication address in the comparison table, the master device returns a silent indication message containing the communication address as a default value, and the slave device enters silence after receiving the silent indication message, and displays on the slave end that the communication address is not assigned.
[0033] In addition, AES data encryption can be used in the network access protocol to ensure data reliability and security during subsequent protocol interactions.
[0034] In this embodiment, when there is neither a communication address corresponding to the slave device serial number nor an idle address in the comparison table, the master device returns a silent indication message containing a default communication address, causing the slave device to enter a silent state and locally displaying that the communication address is unassigned. This mechanism effectively handles the situation where address allocation fails and avoids confusion in network communications.
[0035] In the automatic communication address allocation system provided in the present application, the RS485 bus can be replaced with a CAN bus, while other technical solutions remain unchanged. The communication effect is better, but the cost is higher. The automatic communication address allocation system based on the CAN bus should also be considered as within the scope of protection of the present application.
[0036] The present application embodiment provides a method for automatically allocating communication addresses, such as Figure 3 As shown, the method is applied to a communication address automatic allocation system. The method provided in the embodiment of the present application is executed by a master device, and the method includes steps S301 to S304, wherein: S301. Receive a network access request sent by a slave device, where the network access request includes a serial number and a current communication address of the slave device.
[0037] S302: If the current communication address is a default value, query the comparison table based on the serial number to determine whether the communication address corresponding to the serial number is recorded in the comparison table.
[0038] S303: If the communication address corresponding to the serial number is recorded in the comparison table, the master device sends address allocation information including the communication address corresponding to the serial number to the slave device.
[0039] S304: If the communication address corresponding to the serial number is not recorded in the comparison table, the master device determines an idle communication address from the comparison table, and sends address allocation information including the idle communication address to the slave device.
[0040] It should be understood that, although the steps in the flowchart of the accompanying drawings are displayed in sequence as indicated by the arrows, these steps are not necessarily executed in sequence in the order indicated by the arrows. Unless otherwise specified herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least a part of the steps in the flowchart of the accompanying drawings may include multiple sub-steps or multiple stages, and these sub-steps or stages are not necessarily executed at the same time, but can be executed at different times, and their execution order is not necessarily sequential, but can be executed in turn or alternately with other steps or at least a part of the sub-steps or stages of other steps.
[0041] The above are only some implementation methods of the present application. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present application. These improvements and modifications should also be regarded as the scope of protection of the present application.
Claims
1. A communication address automatic allocation system, characterized in that: include: A master device and at least one slave device connected via an RS485 bus; The slave device sends a network access request to the master device, wherein the network access request includes a serial number and a current communication address of the slave device; If the current communication address is a default value, the master device queries a comparison table based on the serial number to determine whether the communication address corresponding to the serial number is recorded in the comparison table; If the communication address corresponding to the serial number is recorded in the comparison table, the master device sends address allocation information including the communication address corresponding to the serial number to the slave device; If the communication address corresponding to the serial number is not recorded in the comparison table, the master device determines an idle communication address from the comparison table, and sends address allocation information including the idle communication address to the slave device.
2. The communication address automatic allocation system according to claim 1, characterized in that: The master device repeatedly sends the address allocation information to the slave device until receiving allocation success information returned by the slave device, or the number of sending times reaches a preset number; If the number of times the master device sends reaches the preset number of times and the allocation success information is not received, the communication address included in the address allocation information is cleared from the comparison table.
3. The communication address automatic allocation system according to claim 1, characterized in that: If the communication address corresponding to the serial number is not recorded in the comparison table, and there is no idle communication address in the comparison table, the master device returns a silence indication message including a communication address as the default value, and the slave device enters silence after receiving the silence indication message, and displays on the slave end that the communication address is not allocated.
4. The communication address automatic allocation system according to claim 1, characterized in that: The comparison table records the correspondence between known serial numbers and known communication addresses; If the current communication address is not a default value, determining whether the serial number of the slave device is recorded in the comparison table; If the comparison table records the serial number of the slave device, comparing the current communication address of the slave device with the known communication address of the serial number of the slave device in the comparison table to see whether they are the same; If different, the current communication address is updated based on the known communication address.
5. A method for automatically allocating communication addresses, characterized in that: Applied to a communication address automatic allocation system, the method is executed by a master device, and the method comprises: Receiving a network access request sent by a slave device, the network access request including a serial number and a current communication address of the slave device; If the current communication address is a default value, querying a comparison table based on the serial number to determine whether the communication address corresponding to the serial number is recorded in the comparison table; If the communication address corresponding to the serial number is recorded in the comparison table, the master device sends address allocation information including the communication address corresponding to the serial number to the slave device; If the communication address corresponding to the serial number is not recorded in the comparison table, the master device determines an idle communication address from the comparison table, and sends address allocation information including the idle communication address to the slave device.
Citation Information
Patent Citations
Power utilization monitoring terminal equipment and installation and acquisition method thereof
CN113970893A
Master-slave device addressing method
CN114285824A
Method for automatically distributing RS485 communication address
CN114500472A
Methods, apparatus and storage media for automatic generation of serial bus device addresses
CN114936180A
Slave address automatic allocation method based on CAN bus communication
CN116527638A