Method and apparatus for allocating addresses for a host

The host broadcasts commands to the slave to generate random numbers and automatically allocate addresses, which solves the problem of time-consuming and errors in slave address allocation in Internet of Things communication, and realizes efficient and low-cost address allocation.

CN115987947BActive Publication Date: 2025-07-11GUANGZHOU ON BRIGHT ELECTRONICS
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202211548422.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-12-05
Publication Date
2025-07-11
Estimated Expiration
2042-12-05

AI Technical Summary

Technical Problem

In Internet of Things communication, when allocating addresses to a large number of slaves, the prior art is time-consuming and error-prone, and requires a more efficient and costly address allocation method.

Method used

The host broadcast starts the assignment command, causing the slave to enter the address allocation mode, and broadcast a random number to generate a command, obtain slave feedback information to determine the target slave and assign the address.

Benefits of technology

Improve the efficiency of address allocation, reduce costs, and realize the automated address allocation process.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115987947B_ABST
    Figure CN115987947B_ABST
Patent Text Reader

Abstract

The present invention provides a method and apparatus for allocating addresses for a host. The method for allocating addresses for a host includes: broadcasting a start address allocation command to cause at least one of all slaves associated with the host to enter an address allocation mode; broadcasting a random number generation command to cause the at least one slave to generate a random number; obtaining feedback information of the at least one slave in response to generating the random number to determine a target slave among the at least one slave; and allocating an address to the target slave. According to the method and apparatus for allocating addresses for a host according to an exemplary embodiment of the present invention, it is possible to cause a slave to generate a random number by the host broadcasting relevant commands to the slave, and automatically allocate an address to the slave by using the random number, thereby improving the efficiency of address allocation and saving the cost of address allocation.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of communications, and in particular, to a method and apparatus for allocating addresses for a host. Background Art

[0002] In the field of communications such as the Internet of Things, there are many cases where a large number of hosts communicate with associated slaves in a broadcast manner. For example, the case where a host communicates with a slave using an RS485 bus. In this case, when allocating addresses for the slaves, it is usually necessary to allocate them manually. However, in the case where the host has a large number of associated slaves, this allocation method is very time-consuming and very prone to errors.

[0003] Therefore, a more efficient and lower-cost address allocation method is needed. Summary of the Invention

[0004] According to one aspect of an exemplary embodiment of the present invention, there is provided a method for allocating addresses for a host, including: broadcasting a start address allocation command to cause at least one of all slaves associated with the host to enter an address allocation mode; broadcasting a random number generation command to cause the at least one slave to generate a random number; obtaining feedback information of the at least one slave in response to generating the random number to determine a target slave among the at least one slave; and allocating an address to the target slave.

[0005] According to another aspect of an exemplary embodiment of the present invention, there is provided an apparatus for allocating addresses for a host, including: a first broadcast unit configured to broadcast a start address allocation command to cause at least one of all slaves associated with the host to enter an address allocation mode; a second broadcast unit configured to broadcast a random number generation command to cause the at least one slave to generate a random number; a determination unit configured to obtain feedback information of the at least one slave in response to generating the random number to determine a target slave among the at least one slave; and an address allocation unit configured to allocate an address to the target slave.

[0006] According to another aspect of an exemplary embodiment of the present invention, there is provided a computer-readable medium storing instructions that, when executed by a processor, cause the processor to execute the method for allocating addresses for a host according to the above embodiments of the present disclosure.

[0007] The method and apparatus for allocating addresses for a host according to an exemplary embodiment of the present invention can cause a slave to generate a random number by the host broadcasting relevant commands to the slave, and automatically allocate an address to the slave using the random number, thereby improving the efficiency of address allocation and saving the cost of address allocation. Brief Description of the Drawings

[0008] The present invention can be better understood from the following description of specific embodiments in conjunction with the accompanying drawings, where:

[0009] Figure 1 FIG. shows a flowchart of a method for allocating addresses for a host according to an exemplary embodiment of the present invention.

[0010] Figure 2 FIG. shows a flowchart of a method for allocating addresses for a host according to another exemplary embodiment of the present invention.

[0011] Figure 3 FIG. shows a flowchart of a method for allocating addresses for a host according to another exemplary embodiment of the present invention.

[0012] Figure 4 FIG. shows a flowchart of a method for allocating addresses for a host according to another exemplary embodiment of the present invention.

[0013] Figure 5 FIG. shows a flowchart of a process for a host to allocate addresses to slaves according to an exemplary embodiment of the present invention.

[0014] Figure 6 FIG. shows a block diagram of an apparatus for allocating addresses for a host according to an exemplary embodiment of the present invention. Detailed Embodiments

[0015] The features and exemplary embodiments of various aspects of the present invention will be described in detail below. In the following detailed description, many specific details are set forth in order to provide a thorough understanding of the present invention. However, it will be apparent to those skilled in the art that the present invention may be practiced without some of these specific details. The following description of the embodiments is merely provided to better understand the present invention by showing examples of the present invention. The present invention is in no way limited to any specific configuration and algorithm set forth below, but covers any modification, replacement, and improvement of elements, components, and algorithms without departing from the spirit of the present invention. Well-known structures and technologies are not shown in the drawings and the following description so as to avoid unnecessarily obscuring the present invention.

[0016] Figure 1 FIG. shows a flowchart of a method for allocating addresses for a host according to an exemplary embodiment of the present invention.

[0017] In an embodiment according to the present invention, the host can be associated with each slave through an RS485 bus, or can be associated with the slave in other ways and communicate with the slave in a broadcast manner.

[0018] Refer to Figure 1, in step S110, a start address allocation command is broadcast to cause at least one of all the slaves associated with the master to enter the address allocation mode.

[0019] In one embodiment, the start address allocation command may include: a no-address-allocation command, a predetermined address allocation command, or a forced allocation command.

[0020] In one example, the no-address-allocation command can be used to cause the slaves without addresses among all the slaves to enter the address allocation mode, that is, to allocate addresses to the slaves that have not been allocated addresses. The predetermined address allocation command can be used to cause the slaves with predetermined addresses among all the slaves to enter the address allocation mode, that is, to re-allocate addresses to the slaves that have already been allocated addresses. The forced allocation command can be used to cause all the slaves to enter the address allocation mode, that is, to allocate addresses to all the slaves.

[0021] In one example, after each slave receives the start address allocation command broadcast by the master, each slave can enter the address allocation mode. Then, each slave can determine whether it is the slave indicated by the start address allocation command. If so, it remains in the address allocation mode for subsequent address allocation. If not, it exits the address allocation mode and no longer processes the commands related to address allocation broadcast by the master.

[0022] For example, if the slave determines that the start address allocation command corresponds to the no-address-allocation command, the slave judges whether it currently has an address. If it has no address, it remains in the address allocation mode. If it has an address, it exits the address allocation mode. If the slave determines that the start address allocation command corresponds to the predetermined address allocation command, the slave judges whether it currently has the predetermined address in the command. If it has the predetermined address, it remains in the address allocation mode. If it does not have the predetermined address, it exits the address allocation mode. If the slave determines that the start address allocation command corresponds to the forced allocation command, the slave remains in the address allocation mode.

[0023] In the case where the slave determines that it needs to remain in the address allocation mode, if the slave currently has an address (for example, when the start address allocation command corresponds to the predetermined address allocation command or the forced allocation command), it can clear the address to prepare for being allocated a new address.

[0024] It should be understood that the above is only an example of how the slave responds to the start address allocation command. The slave can also respond to the command in other ways. For example, the slave can first determine whether it belongs to the slave indicated by the start address allocation command. If it determines that it does not belong to the slave indicated by the command, it does not enter the address allocation mode. If it determines that it belongs to the slave indicated by the command, it enters the address allocation mode.

[0025] After or simultaneously with the host broadcasting the start address assignment command, in step S120, broadcast a random number generation command to cause at least one slave (the slaves that have entered the address assignment mode above) to generate random numbers. Here, the slaves in the above address assignment mode can generate random numbers in response to the random number generation command.

[0026] In one embodiment, the random number generation command may include a random number upper limit value and a random number lower limit value. The random number generation command may cause each of the at least one slave to generate a random number that is less than the random number upper limit value and greater than the random number lower limit value.

[0027] As an example, the random number upper limit value may be at least ten times the number of slaves for which addresses are to be assigned determined by the host, so as to avoid the possibility of different slaves generating duplicate random numbers when the slaves generate random numbers. For example, when the number of slaves for which addresses are to be assigned is 10, the random number upper limit value may be 100, the random number lower limit value may be 0, and the random numbers generated by each slave may be positive integers (n) less than 100 and greater than 0.

[0028] In step S130, obtain feedback information from at least one slave in response to generating random numbers to determine the target slave among the at least one slave.

[0029] For example, after a slave generates a random number (n), it may wait for a further command from the host and send relevant information to the host in response to the further command, so that the host can determine the target slave to which the host will currently assign an address based on this information. As an example, the target slave may be the slave that generates the smallest random number, and this smallest random number has the minimum value among the random numbers generated by at least one slave. The following will refer to Figures 2 to 5 Step S130 will be further described.

[0030] In step S140, assign an address to the target slave.

[0031] In one embodiment, step S140 may include: generating a target address based on the smallest random number; and broadcasting the target address so that the target slave has the target address. The following will refer to Figures 2 to 5 Step S140 will be further described.

[0032] In the above manner, the address assignment for one target slave among the slaves, such as the slave that generates the smallest random number, can be completed. At this time, the target slave that has been assigned an address can exit the address assignment mode and no longer process commands related to address assignment broadcast by the host subsequently.

[0033] In order to enable the host to assign addresses to slave devices one by one when the host needs to assign addresses to multiple slave devices, in one embodiment, the method for the host to assign addresses according to the present invention may further include (refer to Figure 4 ): After assigning an address to the target slave device, determine whether the number of address assignments has reached a predetermined value (S150); if the predetermined value has not been reached, repeat steps S120 (broadcast a random number generation command, where the random number generation command at this time includes a new upper limit value and a lower limit value of the random number), S130 (determine the target slave device), and S140 (assign an address to the target slave device); when the number of address assignments reaches the predetermined value, broadcast an end address assignment command (S160) so that there is no slave device in the address assignment mode. If there is still a slave device in the address assignment mode at this time, the end address assignment command can force the slave device to exit the address assignment mode; if all slave devices have exited the address assignment mode at this time, the slave device may not perform any processing on the end address assignment command.

[0034] Figure 2 FIG. shows a flowchart of a method for a host to assign addresses according to another exemplary embodiment of the present invention.

[0035] Refer to Figure 2 and Figure 1 , Figure 2 Steps S110, S120, and S140 in Figure 1 are the same as Figure 2 , except that: Figure 1 Steps S131 - S135 are shown as an example of step S130 in

[0036] Refer to Figure 2 , in step S131, a random number matching command may be broadcast, and the random number matching command may include a random number matching condition.

[0037] In one embodiment, the random number matching condition may be a random number matching value (M), and the random number matching command is used to cause the slave device that has generated a random number less than or equal to the random number matching value (n ≤ M) to enter the state of waiting for an address assignment. For example, the state of waiting for an address assignment may be a state in which the slave device sets its matching flag (flag) so that it can be assigned an address. At the same time, the slave device that has generated a random number greater than the random number matching value (n > M) will enter the state of not being able to be assigned an address. For example, the slave device may reset (clear) its matching flag so that it is in a state where it cannot be assigned an address.

[0038] In step S132, at least one response of the slave device to the random number matching command may be obtained. The following will be further described with reference to Figure 3 and Figure 4 .

[0039] In step S133, according to the response, it can be determined whether it is necessary to update the random number matching condition (e.g., the random number matching value M), so that among at least one slave (which has entered the address allocation mode), only the target slave (which has the smallest random number) can enter the to-be-allocated address state.

[0040] If it is determined in step S133 that the random number matching condition needs to be updated, the random number matching condition can be updated in step S134, and then return to step S131 to broadcast a random number matching command with the updated random number matching condition, so as to further determine whether only the target slave has entered the to-be-allocated address state under the adjusted random number matching condition.

[0041] If it is determined in step S133 that the random number matching condition does not need to be updated, it can be determined in step S135 that only the target slave has entered the to-be-allocated address state, and the random number matching condition corresponds to the smallest random number. The following will refer to Figures 3 to 5 for further description.

[0042] After that, step S140 of allocating an address to the target slave can be executed.

[0043] Figure 3 FIG. shows a flowchart of a method for allocating an address for a host according to another exemplary embodiment of the present invention.

[0044] Figure 3 Different from Figure 2 is that: Figure 3 An example of step S132 is further shown in detail, and an example of step S133 is shown in detail by steps S133-1 to S133-3.

[0045] In one embodiment, step S132 may include: determining whether indication information (sent from one or more slaves) is received within a predetermined time, and the indication information may be information indicating that a slave has entered the to-be-allocated address state sent by the slave that has entered the to-be-allocated address state. For example, a slave that has set the matching flag can send indication information to the host.

[0046] If it is determined in step S132 that the indication information is received, step S133-1 can be executed to obtain an intermediate value (M 11 ) through a first setting using the random number matching value (M). If it is determined in step S132 that the indication information is not received, step S133-2 can be executed to obtain an intermediate value (M 11 ) through a second setting using the random number matching value (M).

[0047] In step S133-3, it can be determined whether the intermediate value meets a predetermined criterion.

[0048] In the case where it is determined in step S133-3 that the intermediate value meets the predetermined criteria, it can be determined that there is no need to update the random number matching value, and it can be determined in step S135 that only the target slave has entered the address-to-be-allocated state. Thereafter, step S140 of allocating an address to the target slave can be executed.

[0049] In the case where it is determined in step S133-3 that the intermediate value does not meet the predetermined criteria, it can be determined that the random number matching value needs to be updated. In step S134, the random number matching value (M) can be updated to the intermediate value (M 11 ) obtained above through the first setting or the second setting, and return to execute step S131 to broadcast a random number matching command in which the random number matching value is updated to the current intermediate value, so as to further determine whether only the target slave has entered the address-to-be-allocated state in this case.

[0050] In one example, in steps S133-1 and S133-2, the intermediate value M 11 :

[0051] M 11 =(M1 + M2) / 2

[0052] wherein, M 11 represents the currently obtained intermediate value, and M 11 is equal to the integer part value of (M1 + M2) / 2. The initial value of M1 can be the random number upper limit value (a), and the initial value of M2 can be the random number lower limit value (b). M 11 , M1, M2, a, M can all be positive integers, and b can be 0.

[0053] In this case, the first setting in step S133-1 can be to set the current random number matching value (M) to M1, and the second setting in step S133-2 can be to set the current random number matching value (M) to M2.

[0054] Correspondingly, in one embodiment, the predetermined criteria in step S133-3 can be that the intermediate value M 11 is equal to the currently set M1 or M2. In addition, in the case where the current intermediate value M 11 meets this predetermined criteria, the currently set M1 is the minimum random number.

[0055] For example, when the currently obtained intermediate value M 11 is equal to M1 or M2 at this time, it means that M1 and M2 are adjacent integers. In addition, one of M1 and M2 is the random number matching value M at this time, so this can indicate that currently only one slave that has generated the minimum random number has entered the address-to-be-allocated state, and the minimum random number is M1.

[0056] For example, when the upper limit value of the random number is 100 and the lower limit value of the random number is 0, the initial value of M1 can be 100, and the initial value of M2 can be 0. In addition, when the first broadcast random number matching command is sent, the random number matching value therein can be set to 99. After that, when the indication information sent by the slave is received, M1 in the above equation can be set to 99 through the first setting. At this time, M2 is 0. Therefore, the currently calculated intermediate value M 11 is the integer part value of (M1 + M2) / 2, that is, 49. Since the intermediate value M 11 = 49 is different from M1 = 99 or M 12 = 0, the predetermined condition is not satisfied. At this time, the random number matching value M is updated to M = M 11 = 49, that is, M is bisected to speed up the search for the smallest random number; and so on, until M, M1, and M2 that satisfy the above predetermined condition are found. It should be understood that the above specific values are only examples, and these values can be set to any other values according to actual needs.

[0057] Figure 4 FIG. shows a flowchart of a method for allocating addresses for a host according to another exemplary embodiment of the present invention.

[0058] Figure 4 Different from Figure 3 is that: Figure 4 Steps S133-1 to S133-3 are used to detail an example of step S133, and steps S150 and S160 described in Figure 1 are shown.

[0059] In order to determine, when it is determined in step S132 that no indication information is received, whether this is the case where no indication information is received after step S131 in the current loop is first executed (that is, no slave generates a random number), so that subsequent address allocation operations do not need to be performed (because no slave can be allocated an address). In one embodiment, when it is determined in step S132 that no indication information is received, step S133-4 can be first executed to determine whether the current is the first time to broadcast a random number matching command after broadcasting a random number generation command. When it is determined in step S133-4 that it is the first time to broadcast a random number matching command, step S160 can be executed to broadcast an end address allocation command so that there is no slave in the address allocation mode. When it is determined in step S133-4 that it is not the first time to broadcast a random number matching command after broadcasting a random number generation command, step S133-2 can be executed to obtain an intermediate value using the random number matching value through a second setting.

[0060] In one example, it can be determined whether the current random number matching command is broadcast for the first time after the random number generation command is broadcast by determining whether the current M1 in the above equation is equal to the upper limit value a of the random number. For example, when M1 = a (when M1 is the initial value), it can be determined that the random number matching command is broadcast for the first time; otherwise, it can be determined that the random number matching command is not broadcast for the first time.

[0061] The following refers to Figure 5 to describe an example of the interaction process between the host and the slave during the process of the host allocating an address.

[0062] Figure 5 FIG. shows a flowchart of the process of the host allocating an address to the slave according to an exemplary embodiment of the present invention.

[0063] Referring to Figure 5 , in step S501, the host 100 broadcasts a start address allocation command to all slaves 200. Figure 5 Only one slave 200 is schematically shown in Figure 5 It should be understood that each slave 200 associated with the host 100 can execute

[0064] the process shown.

[0065] In step S502, in response to the start address allocation command, the slave 200 determines whether it is the slave indicated by the start address allocation command. If so, it enters the address allocation mode (and clears its current address if necessary), and waits for a further command from the host 100; if not, it executes step S522 to exit the address allocation mode (or does not enter the address allocation mode).

[0065] In step S503, the host 100 broadcasts a random number generation command (including the upper limit value a and the lower limit value b of the random number).

[0066] In step S504, the slave 200 (which has entered the address allocation mode) generates a random number n (b < n < a) in response to the random number generation command.

[0067] In step S505, the host 100 broadcasts a random number matching command (including the random number matching value M).

[0068] In step S506, the slave 200 determines whether the generated random number satisfies n ≤ M. If n ≤ M is not satisfied, it enters the non-addressable state (resets its matching flag) in step S507, and returns to the step of continuing to receive the next random number matching command; if n ≤ M is satisfied, it enters the pending address state (sets its matching flag) in step S508, and sends an indication message to the host in step S509.

[0069] In step S510, the host 100 determines whether it has received any indication information from the slave 200. If indication information is received, then in step S511, M1 is set as the current M value to obtain an intermediate value M in step S512 11 If no indication information is received, then in step S513, it is determined whether M1 is the random number upper limit value a. If M1 = a, it indicates that there is currently no slave that needs to be assigned an address, and thus step S521 is executed to broadcast an end address assignment command. If M1 ≠ a, it indicates that a previous slave has entered the address assignable state, and thus in step S514, M2 is set as the current M value to obtain an intermediate value M in step S512 11 .

[0070] In step S515, the host 100 determines the currently obtained intermediate value M 11 whether it is equal to the current M1 or M2. If not, then step S516 is executed to update the random number matching value in the random number matching command to the current intermediate value M 11 , and step S505 is executed again to re-broadcast the random number matching command. If M 11 is equal to the current M1 or M2, then the host 200 can determine in step S517 that the slave that has currently generated only the minimum random number is in the address assignable state, determine that the current M1 is the random number generated by this slave, obtain the address matching this random number, and broadcast this address in step S518 so that this slave 200 can save this address in step S519. After that, the slave that has been assigned an address can exit the address assignment mode in step S522

[0071] It should be understood that steps S505 - S516 may be repeatedly executed multiple times before step S518

[0072] In step S520, the host can determine whether the set value of the assignment times has been reached. If not, then step S503 is executed again to broadcast a new random number generation command to assign an address to the next slave. If the assignment times reach the set value, then step S521 is executed to broadcast an end address assignment command. After that, in step S522, any slave 200 can exit the address assignment mode

[0073] It should be understood that Figure 5 not all steps executed by the host 100 and each slave 200 are shown. For example, during the execution of any step by the slave, if it receives an end address assignment command broadcast by the host, the slave can immediately execute step S522 to exit the address assignment mode

[0074] In addition, to ensure that the host and slave do not interfere with other data transmissions on the connection bus (e.g., RS485 bus) when transmitting commands or information, the host and slave can check whether there is data transmission on the bus before each transmission operation and only start transmitting the commands or information related to the above operations when there is no data transmission.

[0075] In one example, the host can start transmitting (broadcasting) commands after detecting that there has been no data transmission on the connection bus for a time t1; the slave can start transmitting relevant information after detecting that there has been no data transmission on the connection bus for a time t2. In addition, t1 can be made greater than t2, for example, t1 can be made more than three times t2, to ensure the effectiveness of the transmission.

[0076] In addition, during the process of the host performing the above address allocation, situations may occur where, for example, although a certain slave can enter the address-to-be-allocated state, it cannot send indication information to the host, which may cause the host to repeatedly determine that the allocation count has not reached the set value in step S520 and return to execute step S530. To prevent the host from repeatedly performing the above operations due to such errors, according to one embodiment, a threshold number of times for repeatedly performing the above operations can be set. After repeatedly performing the above operations up to the threshold number of times, the host broadcasts an end address allocation command to end the address allocation process, thereby saving the host's computing resources. In addition, optionally, the host can also report the error information to further determine the cause of the error, so as to facilitate starting the next address allocation process.

[0077] The method for allocating addresses for a host according to an exemplary embodiment of the present invention can enable the host to broadcast relevant commands to slaves to generate random numbers, and use the random numbers to automatically allocate addresses to the slaves, thereby improving the efficiency of address allocation and saving the cost of address allocation.

[0078] Figure 6 FIG. shows a block diagram of an apparatus 600 for allocating addresses for a host according to an exemplary embodiment of the present invention.

[0079] Referring to Figure 6 , the apparatus 600 for allocating addresses for a host according to an exemplary embodiment of the present invention can be implemented by any processor and may include a first broadcast unit 610, a second broadcast unit 620, a determination unit 630, and an address allocation unit 640.

[0080] The first broadcast unit 610 is configured to broadcast a start address allocation command to cause at least one of all slaves associated with the host to enter an address allocation mode.

[0081] The second broadcast unit 620 is configured to broadcast a random number generation command to cause the at least one slave to generate a random number.

[0082] The determination unit 630 is configured to obtain feedback information of the at least one slave in response to generating a random number, so as to determine a target slave among the at least one slave.

[0083] The address allocation unit 640 is configured to allocate an address to the target slave.

[0084] In other words, the apparatus 600 for allocating an address for a host according to an exemplary embodiment of the present invention may perform any of the steps / operations in the method described above with reference to Figures 1 to 5 the steps / operations described.

[0085] The above has been described with reference to Figures 1 to 5 Examples of the start address allocation command, the random number generation command, the determination of the target slave, and the allocation of an address to the target slave have been described in detail above, and will not be repeated here.

[0086] The apparatus for allocating an address for a host according to an exemplary embodiment of the present invention can broadcast relevant commands from the host to the slave to cause the slave to generate a random number, and automatically allocate an address to the slave by using the random number, thereby improving the efficiency of address allocation and saving the cost of address allocation.

[0087] According to an embodiment of the present disclosure, there is also provided a computer-readable medium storing instructions, which when executed by a processor, can cause the processor to execute the method for allocating an address for a host according to the embodiment of the present disclosure above.

[0088] It should be understood that the present disclosure is not limited to the specific configurations and processes described above and shown in the figures. For the sake of brevity, detailed descriptions of known methods are omitted here. In the above embodiments, several specific steps are described and shown as examples. However, the method process of the present invention is not limited to the specific steps described and shown, and those skilled in the art can make various changes, modifications and additions, or change the order between the steps after understanding the spirit of the present invention.

[0089] The functional blocks shown in the above-described structural block diagram can be implemented as hardware, software, firmware, or a combination thereof. When implemented in hardware, it can be, for example, an electronic circuit, an application specific integrated circuit (ASIC), appropriate firmware, a plug-in, a functional card, etc. When implemented in software, the elements of the present invention are programs or code segments for performing the required tasks. The program or code segment can be stored in a machine-readable medium or transmitted over a transmission medium or communication link via a data signal carried in a carrier wave. A "machine-readable medium" can include any medium capable of storing or transmitting information. Examples of machine-readable media include electronic circuits, semiconductor memory devices, ROMs, flash memories, erasable ROMs (EROMs), floppy disks, CD-ROMs, optical disks, hard disks, fiber optic media, radio frequency (RF) links, etc. The code segment can be downloaded via a computer network such as the Internet, an intranet, etc.

[0090] The present invention can be implemented in other specific forms without departing from its spirit and essential characteristics. For example, the algorithms described in specific embodiments can be modified without the system architecture departing from the basic spirit of the present invention. Therefore, the current embodiments are to be considered in all respects as illustrative and not restrictive, and the scope of the present invention is defined by the appended claims rather than the above description, and all changes falling within the meaning and equivalents of the claims are thus included within the scope of the present invention.

Claims

1. A method for allocating addresses to a host, comprising: Broadcasting a start address allocation command to cause at least one slave among all slaves associated with the host to enter an address allocation mode; Broadcasting a random number generation command to cause the at least one slave to generate a random number; Obtaining feedback information of the at least one slave in response to generating the random number to determine a target slave among the at least one slave; And Allocating an address to the target slave, wherein obtaining feedback information of the at least one slave in response to generating the random number to determine a target slave among the at least one slave includes: broadcasting a random number matching command, the random number matching command including a random number matching condition, obtaining the response of the at least one slave to the random number matching command, determining whether the random number matching condition needs to be updated according to the response, so that only the target slave among the at least one slave can enter a state of waiting for an address allocation, in the case of determining that the random number matching condition needs to be updated, updating the random number matching condition and re - executing the steps of broadcasting the random number matching command, obtaining the response, and determining whether the random number matching condition needs to be updated, and in the case of determining that the random number matching condition does not need to be updated, determining that only the target slave has entered the state of waiting for an address allocation, wherein the random number matching condition is a random number matching value, and the random number matching command is used to cause the slave that has generated a random number less than or equal to the random number matching value to enter the state of waiting for an address allocation.

2. The method according to claim 1, wherein, The start address allocation command includes: a no - address - allocation command, a predetermined address - allocation command, or a forced - allocation command, wherein the no - address - allocation command is used to cause the slaves without addresses among all slaves to enter the address allocation mode, the predetermined address - allocation command is used to cause the slaves with predetermined addresses among all slaves to enter the address allocation mode, the forced - allocation command is used to cause all slaves to enter the address allocation mode, wherein the slaves in the address allocation mode can generate random numbers in response to the random number generation command.

3. The method according to claim 1, wherein The random number generation command includes a random number upper limit value and a random number lower limit value, wherein the random number generation command causes each slave among the at least one slave to generate a random number less than the random number upper limit value and greater than the random number lower limit value, wherein the target slave is the slave that has generated the smallest random number, the smallest random number has the minimum value among the random numbers generated by the at least one slave, and the random number matching condition corresponds to the smallest random number.

4. The method according to claim 3, wherein Obtaining the response of the at least one slave to the random number matching command includes: determining whether an indication information is received within a predetermined time, the indication information being information indicating entry into the state of waiting for an address allocation sent by the slave that has entered the state of waiting for an address allocation.

5. The method according to claim 4, wherein, Determining whether the random number matching condition needs to be updated according to the response includes: In the case of determining that the indication information is received, obtaining an intermediate value through a first setting using the random number matching value; Determining whether the intermediate value meets a predetermined standard; In the case where it is determined that the intermediate value meets the predetermined standard, it is determined that there is no need to update the random number matching value, and it is determined that only the target slave has entered the address to be assigned state; In the case where it is determined that the intermediate value does not meet the predetermined standard, it is determined that the random number matching value needs to be updated, wherein the random number matching value is updated to the intermediate value.

6. The method according to claim 5, wherein, Determining whether the random number matching condition needs to be updated according to the response further includes: In the case where it is determined that the indication information has not been received, the intermediate value is obtained by a second setting using the random number matching value; Determine whether the intermediate value meets the predetermined standard; In the case where it is determined that the intermediate value meets the predetermined standard, it is determined that there is no need to update the random number matching value, and it is determined that only the target slave has entered the address to be assigned state; In the case where it is determined that the intermediate value does not meet the predetermined standard, it is determined that the random number matching value needs to be updated, wherein the random number matching value is updated to the intermediate value.

7. The method according to claim 6, wherein, Determining whether the random number matching condition needs to be updated according to the response further includes: In the case where the indication information has not been received, determine whether the random number matching command is broadcast for the first time after the random number generation command is broadcast; In the case where the random number matching command is not broadcast for the first time, the intermediate value is obtained by a second setting using the random number matching value.

8. The method according to claim 7, wherein, In the case where the random number matching command is broadcast for the first time, broadcast an end address assignment command so that there is no slave in the address assignment mode.

9. The method according to claim 7, wherein The intermediate value is obtained by using the random number matching value through the following equation: M 11 = (M1 + M2) / 2 Among them, M 11 represents the intermediate value, and M 11 is equal to the integer part of the value of (M1 + M2) / 2 wherein the first setting is to set the random number matching value to M1, and the second setting is to set the random number matching value to M2, Among them, the initial value of M1 is the upper limit value of the random number, and the initial value of M2 is the lower limit value of the random number. Among them, M 11 , M1, M2, the random number matching value, and the upper limit value of the random number are all positive integers.

10. The method according to claim 9, wherein, The predetermined standard is the intermediate value M 11 which is equal to the currently set M1 or M2, wherein, in the case where the intermediate value meets the predetermined standard, the currently set M1 is the smallest random number.

11. The method according to claim 10, wherein, The steps of assigning an address to the target slave include: Generating a target address according to the smallest random number; and Broadcasting the target address so that the target slave has the target address.

12. The method according to any one of claims 1-11, further comprising: After assigning an address to the target slave, determine whether the number of address assignments reaches a predetermined value; In the case where the predetermined value is not reached, repeat the steps of broadcasting the random number generation command, obtaining the feedback information, and assigning an address to the target slave; In the case where the predetermined value is reached, broadcast an end address assignment command so that there is no slave in the address assignment mode.

13. The method according to any one of claims 1-11, wherein, The host is associated with each slave through an RS485 bus.

14. An apparatus for assigning an address to a host, comprising: A first broadcast unit configured to broadcast a start address assignment command to cause at least one slave among all slaves associated with the host to enter an address assignment mode; A second broadcast unit configured to broadcast a random number generation command to cause the at least one slave to generate a random number; A determination unit, configured to obtain feedback information of the at least one slave in response to generating a random number, so as to determine a target slave among the at least one slave; And An address allocation unit, configured to allocate an address to the target slave, wherein, obtaining the feedback information of the at least one slave in response to generating a random number to determine the target slave among the at least one slave includes: broadcasting a random number matching command, the random number matching command includes a random number matching condition, obtaining the response of the at least one slave to the random number matching command, determining whether it is necessary to update the random number matching condition according to the response, so that only the target slave among the at least one slave can enter the address-to-be-allocated state, in the case of determining that it is necessary to update the random number matching condition, updating the random number matching condition and re-executing the steps of broadcasting the random number matching command, obtaining the response, and determining whether it is necessary to update the random number matching condition, and in the case of determining that it is not necessary to update the random number matching condition, determining that only the target slave has entered the address-to-be-allocated state, wherein, the random number matching condition is a random number matching value, and the random number matching command is used to make the slave that generates a random number less than or equal to the random number matching value enter the address-to-be-allocated state.

15. A computer-readable medium storing instructions, which when executed by a processor cause the processor to execute the method for allocating an address for a host according to any one of claims 1-13.

Citation Information

Patent Citations

  • Method for distributing serial bus slave node address, electronic device and electronic system

    CN101631147A

  • Method for realizing automatic address allocation based on RS485

    CN112689028A