Slave address allocation method, system and equipment in master-slave communication system

By determining the number of slave devices and generating random temporary addresses by the host, and then confirming uniqueness by polling the address database, the problem of low efficiency and poor stability in slave address allocation in existing technologies is solved, and automated, conflict-free address allocation is achieved.

CN121864754APending Publication Date: 2026-04-14GUANGDONG WANHE THERMAL ENERGY TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-12-26
Publication Date
2026-04-14

AI Technical Summary

Technical Problem

In existing master-slave communication systems, the slave address allocation method relies on manual adjustment, which leads to low efficiency, unstable communication, and easy slave address conflicts.

Method used

When a slave device connects, the host determines the number of slave devices, sends a temporary address allocation command, the target slave device generates a random temporary address, and confirms the uniqueness of the address by polling. Two address databases are used to ensure that there are no duplicates, and a unique address is automatically allocated.

Benefits of technology

It improves the efficiency of slave address allocation and communication stability, avoids manual intervention and address conflicts, and ensures that each slave obtains a unique communication address.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121864754A_ABST
    Figure CN121864754A_ABST
Patent Text Reader

Abstract

The invention discloses a slave address allocation method, system and equipment in a master-slave communication system, when a plurality of target slaves access the master-slave communication system, a host sends a temporary address allocation instruction to the target slaves, the target slaves generate random temporary addresses to temporarily communicate with the host, and the host allocates final communication addresses to the target slaves. Manual allocation is not needed, the situation that the communication addresses allocated to two or more slave machines are the same does not occur, and the address allocation efficiency and the communication stability are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to communication technology, and more particularly to a slave address allocation method, system, and device in a master-slave communication system. Background Technology

[0002] Master-slave communication systems are common communication systems widely used in communication protocols such as RS-485 and SPI. A master-slave communication system consists of one master and one or more slaves. The master is connected to a bus, and each slave is connected to the bus. The master is responsible for initiating communication and controlling the timing of data transmission, while the slaves passively respond to the master's commands.

[0003] To enable communication between the master and slave devices, each slave device needs to be assigned a unique address identifier. The master selects the target slave device for communication based on its address. Currently, most slave address allocation methods rely on manual allocation by users or after-sales personnel. If two or more slave devices are assigned the same address, they cannot communicate with the master, requiring repeated adjustments by users or after-sales personnel, resulting in low allocation efficiency. Summary of the Invention

[0004] The first technical problem solved by this invention is to provide a slave address allocation method in a master-slave communication system, which can improve address allocation efficiency and communication stability.

[0005] The second technical problem solved by this invention is to provide a master-slave communication system for executing the slave address allocation method in the master-slave communication system described in this invention, which can improve address allocation efficiency and communication stability.

[0006] The third technical problem solved by this invention is to provide an electronic device that can improve address allocation efficiency and communication stability.

[0007] The first technical problem mentioned above was solved in the following way:

[0008] A slave address allocation method in a master-slave communication system includes:

[0009] When a target slave device connects to the master-slave communication system, the master device determines whether the number of the target slave devices is greater than 1.

[0010] If the number of target slave devices is greater than 1, the host sends a temporary address allocation instruction to the target slave devices;

[0011] In response to the temporary address allocation instruction, the target slave device generates a random temporary address, which belongs to the first address library;

[0012] The host polls the target slave in the first address database to determine whether there is a target slave with the same temporary address;

[0013] If so, the target slave with the same temporary address is designated as the first target slave, and the remaining target slaves are designated as the second target slaves. The host selects an unallocated address from the second address database as the communication address of the second target slave, assigns it to the second target slave, sends a temporary address allocation instruction to the first target slave, and returns to the step of executing the target slave in response to the temporary address allocation instruction to generate a random temporary address.

[0014] If not, the host selects an unassigned address from the second address database as the communication address of the target slave and assigns it to the target slave; wherein the first address database and the second address database have no overlap.

[0015] The slave address allocation method in the master-slave communication system provided by this invention involves the master determining whether the number of target slaves is greater than one when a target slave connects to the system. If the number of target slaves is greater than one, the master sends a temporary address allocation instruction to the target slave. The target slave responds to the temporary address allocation instruction by generating a random temporary address. Since duplicate temporary addresses can exist, the master polls all target slaves in the first address database to determine if any target slave has the same temporary address. If duplicate random temporary addresses are found, the target slave with the same temporary address is selected as the first slave. The target slave device is designated as the first target slave device, and the remaining target slave devices are designated as the second target slave devices. The host selects an unassigned address from the second address database as the communication address for the second target slave device and assigns it to the second target slave device to ensure that no two or more slave devices are assigned the same communication address. The host then sends a temporary address allocation instruction to the first target slave device and enters the temporary address reassignment step again. If the generated random temporary addresses are all different, the host selects an unassigned address from the second address database as the communication address for the target slave device and assigns it to the target slave device to ensure that no two or more slave devices are assigned the same communication address. When multiple target slave devices access the master-slave communication system, the master sends a temporary address allocation instruction to the target slave device. The target slave device generates a random temporary address and communicates temporarily with the master. The master confirms the slave device corresponding to each temporary address through polling, and selects slave devices with the same temporary address to re-enter the temporary address re-allocation step. This ensures that the master establishes a communication link only with target slave devices with different temporary addresses each time. The master allocates the final communication address to target slave devices with different temporary addresses without manual allocation. Furthermore, the first address database and the second address database have no overlap, and a successfully matched target slave device will not occupy an address in the first address database. In this way, when a target slave device that has not yet been matched or a slave device that joins midway enters the temporary address re-allocation step, the probability of randomly generating the same temporary address is reduced. At the same time, it will not result in two or more slave devices being allocated the same communication address, thus improving address allocation efficiency and communication stability.

[0016] In some embodiments of the present invention, when a target slave device accesses the master-slave communication system, the master device determines whether the number of the target slave devices is greater than 1, including:

[0017] When the target slave device accesses the master-slave communication system, the master device sends a first verification command to the target slave device based on the agreed initial address of the target slave device, wherein the initial address does not belong to the second address database;

[0018] The target slave device responds to the first verification command and returns a first verification response to the host;

[0019] The host verifies the first verification response;

[0020] If the verification fails, the host determines that the number of target slave devices is greater than 1;

[0021] When the verification passes, the host determines that the number of target slave devices is 1.

[0022] In some embodiments of the present invention, the slave address allocation method in the master-slave communication system further includes:

[0023] If the number of target slave devices is 1, the host selects an unassigned address from the second address database as the communication address of the target slave device and assigns it to the target slave device.

[0024] In some embodiments of the present invention, the target slave device, in response to the temporary address allocation instruction, generates a random temporary address, the temporary address belonging to a first address library, including:

[0025] The target slave device acquires the discrete parameters of the hardware and / or sampled analog quantities at the current moment;

[0026] The target slave device generates a random temporary address based on the discrete parameters and / or the sampled analog quantity, and the temporary address belongs to the first address library.

[0027] In some embodiments of the present invention, the discrete parameters and the sampled analog quantity include hexadecimal values ​​and floating-point fractional values, and the target slave device generates a random temporary address based on the discrete parameters and / or the sampled analog quantity, including:

[0028] Take the lower seven digits of the hexadecimal value and convert them to decimal value to obtain the first value;

[0029] Remove the decimal places from the floating-point number to obtain the second value;

[0030] Calculate the average of the first value;

[0031] The third value is obtained by summing the average value and the second value.

[0032] Convert the third value into a fourth value in hexadecimal;

[0033] Determine whether the fourth value belongs to the first address library;

[0034] If so, then the fourth value will be used as a temporary address;

[0035] If not, return to the step of obtaining the discrete parameters of the hardware and / or sampled analog quantities of the target slave at the current moment.

[0036] In some embodiments of the present invention, the host polls the target slave in the first address database to determine whether there is a target slave with the same temporary address, including:

[0037] The host polls the target slave in the first address database and sends a second verification command to each target slave in turn.

[0038] The target slave device responds to the second verification command and returns a second verification response to the host;

[0039] The host verifies the second verification response;

[0040] If the verification fails, the host determines that there is a target slave with the same temporary address;

[0041] If the verification passes, the host determines that there is no target slave with the same temporary address.

[0042] In some embodiments of the present invention, the slave address allocation method in the master-slave communication system further includes:

[0043] The host polls the target slave in the first address database at predetermined time intervals;

[0044] If the host does not receive a second verification response from the target slave during a polling process, it determines that all the target slaves have been assigned a communication address and ends the polling.

[0045] In some embodiments of the present invention, the target slave device responds to the second verification command by returning a second verification response to the host device, including:

[0046] The target slave device responds to the second verification command by performing digital processing on the response data to be sent and generating a first verification code;

[0047] The target slave device sends the response data and the first checksum together as the second check response to the host;

[0048] The host verifies the second verification response, including:

[0049] The host performs the same digital processing on the received response data to obtain a second check code;

[0050] Determine whether the first check code and the second check code are consistent;

[0051] If so, the verification is considered successful;

[0052] If not, the verification is deemed unsuccessful.

[0053] The second technical problem mentioned above is solved in the following way:

[0054] A master-slave communication system is provided for executing the slave address allocation method in the master-slave communication system described in this invention. The master-slave communication system includes a master and at least one slave, the master and the slave are connected via a bus, and the slave is a hot water device.

[0055] The third technical problem mentioned above is solved in the following way:

[0056] An electronic device, comprising:

[0057] One or more processors;

[0058] Storage device for storing one or more programs;

[0059] When the one or more programs are executed by the one or more processors, the one or more processors implement the slave address allocation method in the master-slave communication system as described in this invention.

[0060] It should be understood that the description in this section is not intended to identify key or essential features of the embodiments of the present invention, nor is it intended to limit the scope of the invention. Other features of the invention will become readily apparent from the following description. Attached Figure Description

[0061] To more clearly illustrate the technical solutions in the embodiments of the present invention, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying 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.

[0062] Figure 1 A flowchart of a slave address allocation method in a master-slave communication system provided by the present invention;

[0063] Figure 2 A schematic diagram of a master-slave communication system provided by the present invention;

[0064] Figure 3 This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present invention.

[0065] The accompanying drawings have illustrated specific embodiments of this application, which will be described in more detail below. These drawings and descriptions are not intended to limit the scope of the concept in any way, but rather to illustrate the concept of this application to those skilled in the art through reference to specific embodiments. Detailed Implementation

[0066] To enable those skilled in the art to better understand the present invention, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings of the embodiments of the present invention. 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 should fall within the scope of protection of the present invention.

[0067] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this invention are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of the invention described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover a non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.

[0068] Figure 1 This invention provides a flowchart of a slave address allocation method in a master-slave communication system. This embodiment is applicable to situations where communication addresses are automatically allocated to slave devices in a master-slave communication system, such as... Figure 1 As shown, the slave address allocation method in this master-slave communication system includes the following steps:

[0069] S101. When the target slave device connects to the master-slave communication system, the master device determines whether the number of target slave devices is greater than 1.

[0070] In this embodiment of the invention, the host in the master-slave communication system continuously monitors whether any slave devices are connected to the master-slave communication system, and determines whether the number of target slave devices connected to the master-slave communication system is greater than 1. If yes, then step S102 is executed; otherwise, step S106 is executed.

[0071] In some embodiments of the present invention, the process by which the host determines whether the number of target slave devices is greater than 1 is as follows:

[0072] S1011. When the target slave device accesses the master-slave communication system, the master device sends a first verification command to the target slave device based on the agreed initial address of the target slave device.

[0073] The host continuously monitors for slave devices connecting to the master-slave communication system. When a target slave device is detected connecting, the host sends a verification command to the target slave device based on the agreed-upon initial address; this is called the first verification command. The initial address is a pre-agreed, fixed address assigned to newly connected slave devices, and all newly connected target slave devices use this initial address. For example, the initial address can be 0x64 (hexadecimal).

[0074] S1012. The target slave device responds to the first verification command and returns the first verification response to the host.

[0075] In this embodiment of the invention, the target slave device responds to the first verification command and returns a first verification response to the host.

[0076] In some embodiments of the present invention, the target slave device responds to the first verification command by performing digital processing on the response data to be sent to generate a first verification code. For example, the process of generating the first verification code is as follows:

[0077] 1. The target slave device has a built-in Cyclic Redundancy Check (CRC) register. The target slave device performs an XOR operation on the first byte of the response data (slave address) and the lower 8 bits of the CRC register, and stores the result back into the CRC register.

[0078] 2. Shift the CRC register one bit to the right, fill the most significant bit with 0, and check the least significant bit that was shifted out.

[0079] 3. If the least bit shifted out is 0, repeat step 3; if it is 1, XOR it with the polynomial 0xA001 (1010 00000000 0001).

[0080] 4. Repeat steps 2 and 3 until 8 shifts are completed, thus processing one byte.

[0081] 5. Repeat steps 1 to 4 to process the next byte until all bytes have been processed.

[0082] 6. The final value of the CRC register is the CRC checksum, which serves as the first checksum.

[0083] After generating the first checksum, the target slave device sends the response data and the first checksum together as the first checksum response to the host.

[0084] S1013. The host verifies the first verification response.

[0085] After receiving the first verification response, the host verifies it. In this embodiment of the invention, after receiving the first verification response, the host performs the same digital processing on the response data in the first verification response as in the aforementioned embodiments to obtain a second verification code. Then, it determines whether the first verification code and the second verification code are consistent. If they are, the verification is deemed successful; otherwise, the verification is deemed unsuccessful.

[0086] S1014. When the verification fails, the host determines that the number of target slave devices is greater than 1.

[0087] In step S1013 above, if the verification fails, it means that there are two or more target slaves with the same initial address. Since the two or more target slaves with the same initial address simultaneously return the first verification response to the host, the channel is blocked. The response data of the first verification response received by the host is incorrect, and the calculated second verification code is different from the first verification code. Therefore, the verification cannot pass.

[0088] S1015. When the verification passes, the host determines that the number of target slave devices is 1.

[0089] In step S1013 above, if the verification passes, it means that there is no channel congestion, and the host determines that the number of target slaves is 1, that is, only one target slave is currently connected.

[0090] S102, The host sends a temporary address allocation instruction to the target slave.

[0091] In step S101 above, if the host determines that the number of target slave devices is greater than 1, the host can send a temporary address allocation instruction to all target slave devices by broadcasting.

[0092] S103. The target slave device responds to the temporary address allocation instruction and generates a random temporary address.

[0093] In this embodiment of the invention, the target slave device responds to the temporary address allocation instruction and generates a random temporary address, which belongs to the first address library (e.g., 0x64 – 0xc8).

[0094] In some embodiments of the present invention, the process by which the target slave device generates a random temporary address in response to a temporary address allocation instruction is as follows:

[0095] S1031, The target slave device acquires the discrete parameters of the hardware and / or sampled analog quantities at the current moment.

[0096] In response to a temporary address allocation instruction, the target slave device obtains the discrete parameters and / or sampled analog quantities of the hardware at the current moment. For example, taking a hot water device as the target slave device, the discrete parameters of the target slave device's hardware may include timer timing, buffered data in the serial communication buffer, external interrupt time, etc., and the sampled analog quantities may be temperature sample values, current sample values, voltage sample values, water flow sample values, water pressure sample values, wind pressure sample values, etc., which are not limited in this invention.

[0097] S1032. The target slave device generates a random temporary address based on discrete parameters and / or sampled analog quantities. The temporary address belongs to the first address library.

[0098] Since the discrete parameters and / or sampled analog quantities of the hardware of different target slave devices at the same time are almost impossible to be exactly the same, the random temporary addresses generated based on the discrete parameters and / or sampled analog quantities are also different, ensuring that the temporary addresses generated by each target slave device are different.

[0099] In some embodiments of the present invention, the discrete parameters and sampled analog quantities include hexadecimal values ​​and floating-point fractional values. The process by which the target slave device generates a random temporary address based on the discrete parameters and / or sampled analog quantities is as follows:

[0100] 1. Take the lower seven digits of the hexadecimal value and convert them to decimal value to obtain the first value.

[0101] 2. Remove the decimal places from the floating-point number to obtain the second value.

[0102] 3. Calculate the average of the first value.

[0103] 4. Calculate the sum of the average value and the second value to obtain the third value.

[0104] 5. Convert the third value to the fourth value in hexadecimal.

[0105] 6. Determine whether the fourth value belongs to the first address library.

[0106] 7. If so, the fourth value will be used as a temporary address.

[0107] 8. If not, return to the step of obtaining the discrete parameters of the hardware and / or sampled analog quantities of the target slave device at the current time.

[0108] For example, at a certain moment, the value obtained from the timer counter of the target slave device is: 0xD5C8, the value of the serial communication buffer is: 0xE3, the external interrupt time is: 24ms, the value of the heating temperature probe is: 0x2A8, the water pressure is: 3.2pa, and the wind pressure is: 89bar. If the above hexadecimal data is greater than 127, the lower 7 bits are taken: 0xD5C8 takes the lower 7 bits as 72 (decimal number), 0xE3 takes the lower 7 bits as 99 (decimal number), and 0x2A8 takes the lower 7 bits as 40 (decimal number). For decimal values ​​with decimals, the decimal places are cleared: 3.2pa is rounded to 3. Then, the processed values ​​are calculated as follows: (72+99+40) / 3 +3+89=162, and then it is determined whether 162 is within the range of the first address library (e.g., 0x64-0xc8). Clearly, 162 falls within the range of 0x64-0xc8, and can therefore be used as a temporary address generated by the slave device. If the calculated fourth value is not in the first address library, the process returns to the step of obtaining the discrete parameters and / or sampled analog quantities of the hardware at the current moment from the target slave device, and recalculates the fourth value until it is found in the first address library. Since the re-obtained discrete parameters and / or sampled analog quantities cannot be exactly the same as the previous discrete parameters and / or sampled analog quantities, the calculated fourth value will also be different, and there will be no infinite loop.

[0109] S104. The host polls the target slave in the first address database to determine if there is a target slave with the same temporary address.

[0110] After sending the temporary address allocation instruction, the host immediately or after a preset delay polls the target slave devices in the first address database to determine if a target slave device with the same temporary address exists. For example, if a target slave device with the same temporary address exists, the response data sent by the target slave device with the same temporary address to the host will fail verification due to channel congestion. Therefore, this can be used to determine if a target slave device with the same temporary address exists. If yes, proceed to step S105; otherwise, proceed to step S106.

[0111] In some embodiments of the present invention, step S104 above includes the following sub-steps:

[0112] S1041. The host polls the target slaves in the first address database and sends the second verification command to each target slave in turn.

[0113] For example, the host polls the target slave in the first address database and sends verification instructions to each target slave in turn, which are called the second verification instructions.

[0114] S1042. The target slave device responds to the second verification command and returns a second verification response to the host.

[0115] In this embodiment of the invention, the target slave device responds to the second verification command and returns a verification response to the host, referred to as the second verification response. If a target slave device exists at a certain temporary address in the first address database, the target slave device will respond to the second verification command and return the second verification response.

[0116] In some embodiments of the present invention, the target slave device responds to the second verification command by performing digital processing on the response data to be sent to generate a first verification code. For example, the process of generating the first verification code is as follows:

[0117] 1. The target slave device has a built-in Cyclic Redundancy Check (CRC) register. The target slave device performs an XOR operation on the first byte of the response data (slave address) and the lower 8 bits of the CRC register, and stores the result back into the CRC register.

[0118] 2. Shift the CRC register one bit to the right, fill the most significant bit with 0, and check the least significant bit that was shifted out.

[0119] 3. If the least bit shifted out is 0, repeat step 3; if it is 1, XOR it with the polynomial 0xA001 (1010 00000000 0001).

[0120] 4. Repeat steps 2 and 3 until 8 shifts are completed, thus processing one byte.

[0121] 5. Repeat steps 1 to 4 to process the next byte until all bytes have been processed.

[0122] 6. The final value of the CRC register is the CRC checksum, which serves as the first checksum.

[0123] After generating the first checksum, the target slave device sends the response data and the first checksum together as the second checksum response to the host.

[0124] S1043. The host verifies the second verification response.

[0125] After receiving the second verification response, the host verifies it. In this embodiment of the invention, after receiving the second verification response, the host performs the same digital processing on the response data in the second verification response as in the previous embodiment to obtain a second verification code. Then, it determines whether the first verification code and the second verification code are consistent. If they are, the verification passes; otherwise, the verification fails.

[0126] S1044. When the verification fails, the host determines that there is a target slave with the same temporary address.

[0127] In step S1043 above, if the verification fails, it indicates that there are target slave devices with the same temporary address. Because two or more target slave devices with the same temporary address simultaneously return the second verification response to the host, the channel is congested, the response data of the second verification response received by the host is incorrect, and the calculated second check code is different from the first check code. Therefore, the verification fails.

[0128] S1045. When the verification passes, the host determines that there is no target slave with the same temporary address.

[0129] In step S1043 above, if the verification passes, it indicates that there is no channel congestion, and the host determines that there are no target slaves with the same temporary address, meaning that the temporary addresses of all target slaves are unique. Since the host sends verification commands sequentially through polling, if the temporary addresses of each target slave are different, the time when each target slave returns the second verification response will also be different, meaning that channel congestion will not occur.

[0130] In some embodiments of the present invention, the host polls the target slave in the first address database at predetermined time intervals, that is, at each predetermined time interval, a second verification instruction is sent to one of the temporary addresses. During a polling process, if the host does not receive the second verification response from the target slave, it determines that all target slaves have been assigned communication addresses and ends the polling.

[0131] S105. The target slave with the same temporary address is designated as the first target slave, and the remaining target slaves are designated as the second target slaves. The host selects an unallocated address from the second address database as the communication address of the second target slave, assigns it to the second target slave, and sends a temporary address allocation instruction to the first target slave.

[0132] In this embodiment of the invention, if it is determined in step S104 that there are target slaves with the same temporary address, then the target slave with the same temporary address is designated as the first target slave, and the remaining target slaves are designated as the second target slaves. The host selects an unallocated address from the second address database as the communication address of the second target slave, allocates it to the second target slave, and sends a temporary address allocation instruction to the first target slave. Then, the process returns to the step of the target slave responding to the temporary address allocation instruction and generating a random temporary address. Temporary addresses are generated again for the target slaves with the same temporary address until all target slaves have different temporary addresses and are allocated a final communication address. In this embodiment of the invention, even if at least two target slaves are allocated the same temporary address, the target host with the same temporary address can be determined through verification, and a temporary address allocation instruction is sent to the target slave with the same temporary address. The target slave regenerates a temporary address and is finally allocated a communication address, improving the address allocation success rate.

[0133] It should be noted that, in this embodiment of the invention, if all target slaves have the same temporary address, then all target slaves are considered as first target slaves, and the number of second target slaves is zero.

[0134] S106. The host selects an unassigned address from the second address library as the communication address of the target slave and assigns it to the target slave.

[0135] In step S101, if the host determines that the number of target slave devices is 1, that is, only one target slave device is currently connected, the host selects an unassigned address from the second address library as the communication address of the target slave device and assigns it to the target slave device.

[0136] In step S104, if the host determines that there is no target slave with the same temporary address, that is, the temporary address of all target slaves is unique, the host selects an unassigned address from the second address database as the communication address of the target slave and assigns it to the target slave.

[0137] For example, after each successful allocation of a communication address, the host records the allocated communication addresses. Before each allocation, it determines the unallocated addresses from the second address database, selects one of the unallocated addresses as the communication address of the target slave, and allocates it to the target slave.

[0138] In this embodiment of the invention, the first address database and the second address database have no overlap, and the initial address does not belong to the second address database. This avoids the problem that the already allocated communication address is the same as the initial address and the temporary address, which could lead to misjudgment when the host verifies the second verification response and the first verification response.

[0139] The slave address allocation method in the master-slave communication system provided by this invention involves the master determining whether the number of target slaves is greater than one when a target slave connects to the system. If the number of target slaves is greater than one, the master sends a temporary address allocation instruction to the target slave. The target slave responds to the temporary address allocation instruction by generating a random temporary address. Since duplicate temporary addresses can exist, the master polls all target slaves in the first address database to determine if any target slave has the same temporary address. If duplicate random temporary addresses are found, the target slave with the same temporary address is selected as the first slave. The target slave device is designated as the first target slave device, and the remaining target slave devices are designated as the second target slave devices. The host selects an unassigned address from the second address database as the communication address for the second target slave device and assigns it to the second target slave device to ensure that no two or more slave devices are assigned the same communication address. The host then sends a temporary address allocation instruction to the first target slave device and enters the temporary address reassignment step again. If the generated random temporary addresses are all different, the host selects an unassigned address from the second address database as the communication address for the target slave device and assigns it to the target slave device to ensure that no two or more slave devices are assigned the same communication address. When multiple target slave devices access the master-slave communication system, the master sends a temporary address allocation instruction to the target slave device. The target slave device generates a random temporary address and communicates temporarily with the master. The master confirms the slave device corresponding to each temporary address through polling, and selects slave devices with the same temporary address to re-enter the temporary address re-allocation step. This ensures that the master establishes a communication link only with target slave devices with different temporary addresses each time. The master allocates the final communication address to target slave devices with different temporary addresses without manual allocation. Furthermore, the first address database and the second address database have no overlap, and a successfully matched target slave device will not occupy an address in the first address database. In this way, when a target slave device that has not yet been matched or a slave device that joins midway enters the temporary address re-allocation step, the probability of randomly generating the same temporary address is reduced. At the same time, it will not result in two or more slave devices being allocated the same communication address, thus improving address allocation efficiency and communication stability.

[0140] Figure 2 A schematic diagram of a master-slave communication system provided by the present invention is shown below. Figure 2 As shown, the master-slave communication system is used to execute the slave address allocation method in the master-slave communication system provided in any of the foregoing embodiments of the present invention. The master-slave communication system includes a master 110 and at least one slave 120. In this embodiment of the present invention, the master-slave communication system includes multiple slaves 120 as an example. The master 110 and the slaves 120 are connected via a bus 130. For example, in a specific embodiment of the present invention, the slave 120 can be a hot water device.

[0141] Figure 3This is a schematic diagram of an electronic device provided for an embodiment of the present invention. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processors, cellular phones, smartphones, wearable devices (such as helmets, glasses, watches, etc.), and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely illustrative and are not intended to limit the implementation of the invention described and / or claimed herein.

[0142] like Figure 3 As shown, the electronic device includes at least one processor 11 and a memory, such as a read-only memory (ROM) 12 or a random access memory (RAM) 13, communicatively connected to the at least one processor 11. The memory stores computer programs executable by the at least one processor. The processor 11 can perform various appropriate actions and processes based on the computer programs stored in the ROM 12 or loaded from storage unit 18 into the RAM 13. The RAM 13 can also store various programs and data required for the operation of the electronic device. The processor 11, ROM 12, and RAM 13 are interconnected via a bus 14. An input / output (I / O) interface 15 is also connected to the bus 14.

[0143] Multiple components in the electronic device are connected to the I / O interface 15, including: an input unit 16, such as a keyboard, mouse, etc.; an output unit 17, such as various types of displays, speakers, etc.; a storage unit 18, such as a disk, optical disk, etc.; and a communication unit 19, such as a network card, modem, wireless transceiver, etc. The communication unit 19 allows the electronic device to exchange information / data with other devices through computer networks such as the Internet and / or various telecommunications networks.

[0144] Processor 11 can be a variety of general-purpose and / or special-purpose processing components with processing and computing capabilities. Some examples of processor 11 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special-purpose artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, a digital signal processor (DSP), and any suitable processor, controller, microcontroller, etc. Processor 11 performs the various methods and processes described above, such as slave address allocation methods in a master-slave communication system.

[0145] In some embodiments, the slave address allocation method in a master-slave communication system may be implemented as a computer program tangibly contained in a computer-readable storage medium, such as storage unit 18. In some embodiments, part or all of the computer program may be loaded and / or installed on an electronic device via ROM 12 and / or communication unit 19. When the computer program is loaded into RAM 13 and executed by processor 11, one or more steps of the slave address allocation method in a master-slave communication system described above may be performed. Alternatively, in other embodiments, processor 11 may be configured to execute the slave address allocation method in a master-slave communication system by any other suitable means (e.g., by means of firmware).

[0146] Various embodiments of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field-programmable gate arrays (FPGAs), application-specific integrated circuits (ASICs), application-specific standard products (ASSPs), systems-on-a-chip (SoCs), payload-programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various embodiments may include implementations in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which may be a dedicated or general-purpose programmable processor, capable of receiving data and instructions from a storage system, at least one input device, and at least one output device, and transmitting data and instructions to the storage system, the at least one input device, and the at least one output device.

[0147] Computer programs used to implement the methods of the present invention may be written in any combination of one or more programming languages. These computer programs may be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, such that when executed by the processor, the computer programs cause the functions / operations specified in the flowcharts and / or block diagrams to be performed. The computer programs may be executed entirely on a machine, partially on a machine, or as a standalone software package, partially on a machine and partially on a remote machine, or entirely on a remote machine or server.

[0148] In the context of this invention, a computer-readable storage medium can be a tangible medium that may contain or store a computer program for use by or in conjunction with an instruction execution system, apparatus, or device. A computer-readable storage medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination thereof. Alternatively, a computer-readable storage medium may be a machine-readable signal medium. More specific examples of machine-readable storage media include electrical connections based on one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fibers, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination thereof.

[0149] To provide interaction with a user, the systems and techniques described herein can be implemented on an electronic device having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user provides input to the electronic device. Other types of devices can also be used to provide interaction with the user; for example, feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including sound input, voice input, or tactile input).

[0150] The systems and technologies described herein can be implemented in computing systems that include backend components (e.g., as data servers), or middleware components (e.g., application servers), or frontend components (e.g., user computers with graphical user interfaces or web browsers through which users can interact with implementations of the systems and technologies described herein), or any combination of such backend, middleware, or frontend components. The components of the system can be interconnected via digital data communication of any form or medium (e.g., communication networks). Examples of communication networks include local area networks (LANs), wide area networks (WANs), blockchain networks, and the Internet.

[0151] A computing system can include clients and servers. Clients and servers are generally located far apart and typically interact through communication networks. The client-server relationship is created by computer programs running on the respective computers and having a client-server relationship with each other. The server can be a cloud server, also known as a cloud computing server or cloud host, which is a hosting product within the cloud computing service system to address the shortcomings of traditional physical hosts and VPS services, such as high management difficulty and weak business scalability.

[0152] This invention also provides a computer program product, including a computer program that, when executed by a processor, implements the slave address allocation method in a master-slave communication system as provided in any embodiment of this application.

[0153] In implementing the computer program product, computer program code for performing the operations of this invention can be written in one or more programming languages ​​or a combination thereof. Programming languages ​​include object-oriented programming languages ​​such as Java, Smalltalk, and C++, as well as conventional procedural programming languages ​​such as C or similar languages. The program code can be executed entirely on the user's computer, partially on the user's computer, as a standalone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving remote computers, the remote computer can be connected to the user's computer via any type of network—including a local area network (LAN) or a wide area network (WAN)—or can be connected to an external computer (e.g., via the Internet using an Internet service provider).

[0154] It should be understood that the various forms of processes shown above can be used, with steps reordered, added, or deleted. For example, the steps described in this invention can be executed in parallel, sequentially, or in different orders, as long as the desired result of the technical solution of this invention can be achieved, and this is not limited herein.

[0155] The specific embodiments described above do not constitute a limitation on the scope of protection of this invention. Those skilled in the art should understand that various modifications, combinations, sub-combinations, and substitutions can be made according to design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of this invention should be included within the scope of protection of this invention.

Claims

1. A method for slave address allocation in a master-slave communication system, characterized in that, include: When a target slave device connects to the master-slave communication system, the master device determines whether the number of the target slave devices is greater than 1. If the number of target slave devices is greater than 1, the host sends a temporary address allocation instruction to the target slave devices; In response to the temporary address allocation instruction, the target slave device generates a random temporary address, which belongs to the first address library; The host polls the target slave in the first address database to determine whether there is a target slave with the same temporary address; If so, the target slave with the same temporary address is designated as the first target slave, and the remaining target slaves are designated as the second target slaves. The host selects an unallocated address from the second address database as the communication address of the second target slave, assigns it to the second target slave, sends a temporary address allocation instruction to the first target slave, and returns to the step of executing the target slave in response to the temporary address allocation instruction to generate a random temporary address. If not, the host selects an unassigned address from the second address database as the communication address of the target slave and assigns it to the target slave; wherein the first address database and the second address database have no overlap.

2. The slave address allocation method in the master-slave communication system according to claim 1, characterized in that, When a target slave device connects to the master-slave communication system, the master determines whether the number of target slave devices is greater than one, including: When the target slave device accesses the master-slave communication system, the master device sends a first verification command to the target slave device based on the agreed initial address of the target slave device, wherein the initial address does not belong to the second address database; The target slave device responds to the first verification command and returns a first verification response to the host; The host verifies the first verification response; If the verification fails, the host determines that the number of target slave devices is greater than 1; When the verification passes, the host determines that the number of target slave devices is 1.

3. The slave address allocation method in the master-slave communication system according to claim 1, characterized in that, Also includes: If the number of target slave devices is 1, the host selects an unassigned address from the second address database as the communication address of the target slave device and assigns it to the target slave device.

4. The slave address allocation method in the master-slave communication system according to any one of claims 1-3, characterized in that, The target slave device responds to the temporary address allocation instruction by generating a random temporary address, which belongs to a first address library and includes: The target slave device acquires the discrete parameters of the hardware and / or sampled analog quantities at the current moment; The target slave device generates a random temporary address based on the discrete parameters and / or the sampled analog quantity, and the temporary address belongs to the first address library.

5. The slave address allocation method in the master-slave communication system according to claim 4, characterized in that, The discrete parameters and the sampled analog values ​​include hexadecimal values ​​and floating-point numbers. The target slave device generates a random temporary address based on the discrete parameters and / or the sampled analog values, including: Take the lower seven digits of the hexadecimal value and convert them to decimal value to obtain the first value; Remove the decimal places from the floating-point number to obtain the second value; Calculate the average of the first value; The third value is obtained by summing the average value and the second value. Convert the third value into a fourth value in hexadecimal; Determine whether the fourth value belongs to the first address library; If so, then the fourth value will be used as a temporary address; If not, return to the step of obtaining the discrete parameters of the hardware and / or sampled analog quantities of the target slave at the current moment.

6. The slave address allocation method in the master-slave communication system according to any one of claims 1-3 and 5, characterized in that, The host polls the target slave in the first address database to determine if a target slave with the same temporary address exists, including: The host polls the target slave in the first address database and sends a second verification command to each target slave in turn. The target slave device responds to the second verification command and returns a second verification response to the host; The host verifies the second verification response; If the verification fails, the host determines that there is a target slave with the same temporary address; If the verification passes, the host determines that there is no target slave with the same temporary address.

7. The slave address allocation method in the master-slave communication system according to claim 6, characterized in that, Also includes: The host polls the target slave in the first address database at predetermined time intervals; If the host does not receive a second verification response from the target slave during a polling process, it determines that all the target slaves have been assigned a communication address and ends the polling.

8. The slave address allocation method in the master-slave communication system according to claim 6, characterized in that: The target slave device responds to the second verification command by returning a second verification response to the host, including: The target slave device responds to the second verification command by performing digital processing on the response data to be sent and generating a first verification code; The target slave device sends the response data and the first checksum together as the second check response to the host; The host verifies the second verification response, including: The host performs the same digital processing on the received response data to obtain a second check code; Determine whether the first check code and the second check code are consistent; If so, the verification is considered successful; If not, the verification is deemed unsuccessful.

9. A master-slave communication system, characterized in that, This method is used to execute the slave address allocation method in the master-slave communication system according to any one of claims 1-8. The master-slave communication system includes a master and at least one slave, the master and the slave are connected by a bus, and the slave is a hot water device.

10. An electronic device, characterized in that, include: One or more processors; Storage device for storing one or more programs; When the one or more programs are executed by the one or more processors, the one or more processors implement the slave address allocation method in the master-slave communication system as described in any one of claims 1-8.