Method, apparatus, electronic device and storage medium for assigning bus addresses to stations
By employing a method in Modbus networks where the master station assigns the actual bus address to the slave station based on the virtual bus address, and utilizing a consistent random number algorithm and hardware identifiers, the problem of low address allocation efficiency and frequent conflicts in existing technologies is solved, achieving efficient and conflict-free address allocation.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- SIEMENS (CHINA) CO LTD
- Filing Date
- 2023-10-31
- Publication Date
- 2026-08-04
AI Technical Summary
In existing Modbus networks, slave address allocation methods are inefficient and prone to bus access conflicts. Manual configuration is costly, while automatic allocation methods are still inefficient and prone to conflicts.
The method of assigning actual bus addresses to slave stations based on virtual bus addresses is adopted. By calculating the range of available virtual bus addresses, and using a consistent random number algorithm and the unique hardware identifier of the slave station, conflict-free actual bus addresses are gradually assigned.
It improves system efficiency, reduces bus access conflicts, avoids the need to manually set unique identifiers, and significantly improves the address allocation efficiency of Modbus networks.
Smart Images

Figure CN117812044B_ABST
Abstract
Description
Technical Field
[0001] This disclosure generally relates to the field of bus technology, and more specifically, to methods, apparatus, electronic devices, and storage media for assigning bus addresses to slave stations. Background Technology
[0002] Modbus is a serial communication protocol widely used in industrial and medical applications due to its high cost-effectiveness and reliability. A Modbus network consists of a master and slave nodes (typically, the number of slave nodes should be less than 247). In a Modbus network, one node is the master, and the other nodes are slaves. Both the master and slave nodes have a unique bus address.
[0003] In a Modbus network that communicates via polling, the master station typically initiates the communication. Each Modbus command contains the device address of the station to be executed and is broadcast to every slave station in the network. Each slave station needs to determine whether to execute the command based on the device address contained in the command. Therefore, assigning an address to each slave station in the Modbus network is particularly important.
[0004] The existing address allocation method involves manually setting the slave address one by one (e.g., setting the DIP switch for each slave), which requires professional personnel. This increases system costs and reduces efficiency.
[0005] So, how can we quickly, automatically, and intelligently assign addresses to slave stations in a Modbus network?
[0006] To automatically assign an address to each slave station, a unique ID can be preset in each slave station. The master station will request this ID from all slave stations, and then assign a bus address to each slave station. However, this method has the following disadvantages:
[0007] 1) Pre-setting a unique ID for each slave station is still inefficient. Sometimes, it is comparable to the workload of manually assigning slave station addresses.
[0008] 2) Too many bus access conflicts can occur when the slave responds to the master's ID request command. This is because the slave sends response messages to the master almost simultaneously, causing communication messages to overlap. Summary of the Invention
[0009] A brief overview of the invention is given below to provide a basic understanding of certain aspects of it. It should be understood that this overview is not an exhaustive summary of the invention. It is not intended to identify key or essential parts of the invention, nor is it intended to limit the scope of the invention. Its purpose is merely to present certain concepts in a simplified form as a prelude to the more detailed description that follows.
[0010] In view of this, this disclosure proposes a method for a master station to assign an actual bus address to a slave station based on a virtual bus address in a Modbus network.
[0011] According to one aspect of this disclosure, a method for assigning a bus address to a slave station is provided, comprising:
[0012] The number of slave stations that the master station obtains and that have bus addresses to be assigned.
[0013] The master station calculates the range of available virtual bus addresses based on the number of slave stations and a predetermined expansion factor.
[0014] The master station publishes a range of available virtual bus addresses to the slave stations;
[0015] The master station sends a virtual address request start message to the slave station;
[0016] The master station determines whether it receives a virtual bus address request message within the maximum waiting time;
[0017] If not, the master station publishes a virtual bus address synchronization message and executes the step of determining whether the virtual bus address request message has been received within the maximum waiting time again;
[0018] If so, the master station updates the virtual bus address response list;
[0019] Determine whether the master station has received all virtual bus address request messages;
[0020] If not, repeat the step of the master station determining whether a virtual bus address request message has been received within the maximum waiting time;
[0021] If so, the master station assigns an actual bus address to the slave station based on the virtual bus address response list.
[0022] According to another aspect of this disclosure, a method for assigning a bus address to a slave station is provided, comprising:
[0023] Obtain your unique hardware identifier from the station;
[0024] The slave station receives the range of available virtual bus addresses published by the master station;
[0025] The slave station uses a consistent random number algorithm to calculate the virtual bus address it wants to apply for, based on the unique hardware identifier and the range of available virtual bus addresses.
[0026] The slave station receives and parses virtual bus address request messages and / or virtual bus address synchronization messages published on the bus;
[0027] The slave station determines whether it should send its own virtual bus address request message;
[0028] If not, repeat the steps of the slave station receiving and parsing the virtual bus address request message and / or virtual bus address synchronization message published on the bus.
[0029] If so, send a virtual bus address request message;
[0030] The slave station determines whether it has received the actual bus address assigned by the master station;
[0031] If so, the slave station sends an ACK message using the actual bus address assigned by the master station.
[0032] According to another aspect of this disclosure, an apparatus for assigning bus addresses to slave stations is provided, disposed at a master station, comprising:
[0033] The slave station number determination unit is configured to determine the number of slave stations to be assigned a bus address;
[0034] The available virtual bus address range calculation unit is configured to calculate the range of available virtual bus addresses based on the number of slave stations and a predetermined expansion factor;
[0035] The available virtual bus address publishing unit is configured to publish a range of available virtual bus addresses to slave stations;
[0036] The virtual address request start message publishing unit is configured to publish a virtual address request start message to the slave station;
[0037] The virtual bus address request message listening unit is configured to determine whether a virtual bus address request message has been received within the maximum waiting time;
[0038] The synchronous message publishing unit is configured to publish virtual bus address synchronization;
[0039] The Virtual Bus Address Response List Update Unit is configured to update the Virtual Bus Address Response List.
[0040] The operation termination control unit is configured to determine whether the master station has received all virtual bus address request messages;
[0041] The actual bus address allocation unit is configured to allocate actual bus addresses to slaves based on the virtual bus address response list.
[0042] According to another aspect of this disclosure, an apparatus for assigning bus addresses to slave stations is provided, disposed at each slave station, comprising:
[0043] The hardware identifier acquisition unit is configured to acquire its own unique hardware identifier.
[0044] The available virtual bus address range receiving unit is configured to receive the range of available virtual bus addresses published by the master station.
[0045] The virtual bus address calculation unit is configured to calculate the virtual bus address to be requested by the slave station using a consistent random number algorithm based on the unique hardware identifier and the range of available virtual bus addresses.
[0046] The message listening unit is configured to receive and parse virtual bus address request messages and / or virtual bus address synchronization messages published on the bus;
[0047] The virtual bus address request message sending judgment unit is configured to determine whether to send a virtual bus address request message to the slave station;
[0048] The virtual bus address request message sending unit is configured to send virtual bus address request messages;
[0049] The actual bus address determination unit is configured to determine whether the actual bus address assigned by the master station has been received.
[0050] The ACK message sending unit is configured to send ACK messages using the actual bus address assigned by the master station.
[0051] According to another aspect of this disclosure, an electronic device is provided, comprising: at least one processor; and a memory coupled to said at least one processor, said memory for storing instructions that, when executed by said at least one processor, cause the processor to perform the method as described above.
[0052] According to another aspect of this disclosure, a non-transitory machine-readable storage medium is provided that stores executable instructions, which, when executed, cause the machine to perform the method described above.
[0053] According to another aspect of this disclosure, a computer program product is provided, which is tangibly stored on a computer-readable medium and includes computer-executable instructions that, when executed, cause at least one processor to perform the method as described above.
[0054] The method and apparatus for assigning bus addresses to slave stations according to this disclosure have at least one or more of the following advantages.
[0055] The method disclosed herein converts the virtual bus address into the actual bus address during the bus address allocation process, thereby eliminating the need to manually preset any unique identifier for each slave station, which can significantly improve system efficiency.
[0056] According to the method disclosed herein, the number of virtual bus addresses is set to be the number of slaves multiplied by an extension factor, so that the number of virtual bus addresses is much greater than the number of slaves. Furthermore, each slave uses its own unique hardware ID as the random factor in the random algorithm. This greatly reduces the probability of different slaves requesting the same virtual bus address, thereby significantly reducing the problem of bus access conflicts.
[0057] The slave station sends virtual bus address request messages in the order of the virtual bus addresses and waits during the standard interval. At the same time, the master station also keeps listening. This can reduce bus conflicts and further improve system efficiency. Attached Figure Description
[0058] The above and other objects, features, and advantages of the present invention will be more readily understood by referring to the following description of embodiments of the invention in conjunction with the accompanying drawings. The components in the drawings are merely for illustrating the principles of the invention. In the drawings, the same or similar technical features or components will be represented by the same or similar reference numerals. In the drawings:
[0059] Figure 1 This is a schematic diagram of a Modbus network architecture;
[0060] Figure 2 A flowchart illustrating an exemplary process of a method for assigning a bus address to a slave station according to an embodiment of the present invention;
[0061] Figure 3 A flowchart illustrating an exemplary process of a method for assigning a bus address to a slave station, performed on the master station side according to another embodiment of this disclosure;
[0062] Figure 4 A flowchart illustrating an exemplary process of a method 400 for assigning a bus address to a slave station, performed at a slave station according to another embodiment of this disclosure;
[0063] Figure 5 A block diagram illustrating an exemplary configuration of an apparatus for assigning a bus address to a slave station according to another embodiment of this disclosure;
[0064] Figure 6 This is a block diagram illustrating an exemplary configuration of a device 600 for assigning a bus address to a slave station according to yet another embodiment of this disclosure;
[0065] Figure 7 A block diagram of an electronic device according to an embodiment of the present disclosure is shown.
[0066] The reference numerals in the attached figures are as follows:
[0067] Detailed Implementation
[0068] The subject matter described herein will now be discussed with reference to exemplary embodiments. It should be understood that these embodiments are discussed merely to enable those skilled in the art to better understand and implement the subject matter described herein, and are not intended to limit the scope, applicability, or examples set forth in the claims. The function and arrangement of the elements discussed may be changed without departing from the scope of this disclosure. Various processes or components may be omitted, substituted, or added as needed in the various examples. For example, the described methods may be performed in a different order than described, and steps may be added, omitted, or combined. Furthermore, features described in some examples may be combined in other examples.
[0069] As used herein, the term "comprising" and its variations are open terms meaning "including but not limited to". The term "based on" means "at least partially based on". The terms "one embodiment" and "an embodiment" mean "at least one embodiment". The term "another embodiment" means "at least one other embodiment". The terms "first", "second", etc., may refer to different or the same objects. Other definitions, whether explicit or implicit, may be included below. Unless explicitly indicated by the context, the definition of a term shall remain consistent throughout the specification.
[0070] Figure 1 This is a schematic diagram of the architecture of a Modbus network 100.
[0071] As can be seen, in Figure 1 In a Modbus network, there is one master station 102 and multiple slave stations 104. Typically, the number of slave stations is less than 247. Both the master and slave stations have a globally unique (actual) bus address.
[0072] This disclosure proposes a method for a master station to assign actual bus addresses to slave stations based on virtual bus addresses in a Modbus network.
[0073] Those skilled in the art will understand that in a Modbus network, messages sent by both the master and slave stations are broadcast, and the method disclosed herein is based on this.
[0074] The method and apparatus for assigning bus addresses to slave stations according to embodiments of the present disclosure will now be described with reference to the accompanying drawings.
[0075] Figure 2 This is a flowchart illustrating an exemplary process of a method 200 for assigning a bus address to a slave station according to an embodiment of the present invention. Figure 2 The method shown is the operation steps performed by the master station and the slave station to allocate a bus address to the slave station during interactive operations.
[0076] First, step S202 is executed, and the master station obtains the number of slave stations whose bus addresses are to be assigned.
[0077] For example, the master station can read the number of slave stations that need to be assigned bus addresses from the configuration file. Here, the bus address refers to the actual bus address.
[0078] Next, step S204 is executed to determine the range of available virtual bus addresses based on the number of slave stations and a predetermined expansion factor.
[0079] Preferably, the number of available virtual bus addresses can be set to the number of slave stations multiplied by a predetermined expansion factor. The expansion factor can be set to be greater than or equal to 10.
[0080] Next, in step S206, a range of available virtual bus addresses is published to the slave station.
[0081] For example, a message including the start and end addresses of the virtual bus address can be published to each slave station.
[0082] In step S208, each slave station calculates the virtual bus address it wants to request.
[0083] Specifically, the slave device resolves a message about the range of available virtual bus addresses, using the available address range and its own unique hardware identifier (e.g., CPU identifier) as input parameters, and selects an appropriate consistent random number algorithm to calculate the virtual bus address to be requested. Optionally, the slave device's system time can also be used as one of the input parameters to calculate the virtual bus address to be requested.
[0084] In the above operation, on the one hand, the number of available virtual bus addresses is increased, and on the other hand, the slave-specific hardware identifier is used to calculate the virtual bus address to be requested. In this way, the possibility of two slaves requesting the same virtual bus address can be avoided or reduced as much as possible.
[0085] Next, in step S210, the master station sends a virtual address request start message to the slave station. This message indicates that the master station is ready to receive virtual bus address request messages from the slave station. Furthermore, the virtual address request start message includes a Standard Gap Time (SGT), which represents the interval between virtual bus address request messages sent by the two slave stations. The virtual address request start message may also include the start address of the virtual bus address.
[0086] Next, in step S212, each slave station sends a virtual bus address request message in sequence according to the order in which the slave stations request the virtual bus addresses.
[0087] The virtual bus address request message also includes an acknowledgment identifier (CID) for the slave device. This acknowledgment identifier is calculated based on the slave device's unique hardware identifier (e.g., CPU ID) using a suitable consistent random number algorithm. The unique hardware identifier and consistent random number algorithm used here can be the same as or different from those used when calculating the virtual bus address requested by the slave device.
[0088] In step S214, the master station determines whether it has received a virtual bus address request message within the maximum waiting time.
[0089] If the master station does not receive any virtual bus address request message N within the maximum waiting time, it means that no slave station has requested the current virtual bus address. Then, step S216 is executed, where the master station sends a virtual bus address synchronization message to synchronize time with the slave stations. The process then returns to step S214 to determine whether the next virtual bus address request message has been received within the maximum waiting time. The maximum waiting time is a pre-set appropriate value as needed.
[0090] If the master station receives a virtual bus address request message Y, it can execute step S218 to parse the message and perform a CRC check. If the CRC check passes, it indicates that a slave station has requested the virtual bus address in the virtual bus address request message and no other slave station has requested it simultaneously, thus avoiding a conflict. Then, step S220 is executed, and the master station updates the virtual bus address response list. Specifically, the master station adds the virtual bus address and CID included in the virtual bus address request message to the virtual bus address response list. The virtual bus address response list stores the CIDs of all slave stations that sent virtual bus address request messages and the virtual bus addresses requested by those slave stations.
[0091] If, in step S218, the master station receives a message that fails the CRC check after parsing the virtual bus address request message, it may mean that more than one slave station has encountered a conflict with that virtual bus address. In this case, step S222 is executed, and the master station abandons the current virtual bus address request message. Then, the process returns to step S214 to determine whether the next virtual bus address request message has been received within the maximum waiting time.
[0092] In step S224, other slave stations receive the current virtual bus address request message, parse it to obtain the current virtual bus address, and determine whether they should send a virtual bus address request message for the next virtual bus address after the standard interval. It should be noted that even if the received virtual bus address request message fails the CRC check (especially when multiple slave stations conflict for the same virtual bus address), the slave station still needs to calculate the current virtual bus address to determine whether it should send a virtual bus address request message for the next virtual bus address after the standard interval. It can be understood that steps S224 and S214 are not sequential; rather, they are operations performed simultaneously by the master and slave stations.
[0093] In step S226, it is determined whether the master station has received all the virtual bus address request messages.
[0094] If not, return to step S214 to determine whether the next virtual bus address request message has been received within the maximum waiting time.
[0095] If so, meaning the master station has received all virtual bus address request messages, then step S228 is executed to allocate actual bus addresses to each slave station according to the virtual bus address response list. Specifically, actual bus address sending messages can be sent sequentially, and each actual bus address sending message includes the virtual bus address, acknowledgment flag, and actual bus address.
[0096] In step S230, after the slave station determines that the virtual bus address and acknowledgment identifier in the actual bus address sending message match itself, it sends an ACK (acknowledgment) message using the actual bus address assigned to it by the master station.
[0097] In step S232, the master station determines whether it has received an ACK message. If no ACK message is received, step S234 is executed to reassign a real bus address to the slave station, and the process returns to step S228 to assign a real bus address to the next slave station. If an ACK message is received, step S236 is executed to update the list of slave stations to be assigned. The list of slave stations to be assigned stores information about slave stations that have not yet received a real bus address.
[0098] In step S238, it is determined whether an actual bus address has been assigned to all slaves in the virtual bus address response list. If not, the process returns to step S228 to assign an actual bus address to the next slave, and so on, until an actual bus address has been assigned to all slaves in the virtual bus address response list.
[0099] In step S238, if the answer is Y, then a round of operations has been completed to assign actual bus addresses to all slaves added to the virtual bus address response list.
[0100] During this process, some slave stations may fail to obtain a virtual bus address due to virtual address conflicts. Therefore, in step S240, it is determined whether all slave stations have obtained a real bus address. If there are still slave stations that have not obtained a real bus address N, the master station will recalculate the number of slave stations that have not obtained a real bus address. That is, starting from step S202, each step of method 200 will be re-executed until all slave stations have obtained their own real bus addresses. If so, that is, all slave stations have obtained a real bus address, then method 200 ends in S242.
[0101] exist Figure 2 The method for allocating a bus address to a slave station according to an embodiment of this disclosure involves both a master station and a slave station. For the master station, the operational steps performed are as follows: Figure 3 As shown. Figure 3 This is a flowchart illustrating an exemplary process of a method 300 for allocating a bus address to a slave station on the master station side according to an embodiment of this disclosure. The method specifically includes:
[0102] First, in step S302, the master station obtains the number of slave stations whose bus addresses are to be assigned.
[0103] In step S304, the master station calculates the range of available virtual bus addresses based on the number of slave stations and a predetermined expansion factor.
[0104] Next, in step S306, a range of available virtual bus addresses is published to the slave station.
[0105] Next, in step S308, the master station sends a virtual address request start message to the slave station.
[0106] In step S310, the master station determines whether it has received a virtual bus address request message within the maximum waiting time.
[0107] If the master station does not receive any virtual bus address request message within the maximum waiting time, it means that no slave station has requested the current virtual bus address. Then, step S312 is executed, and the master station publishes a virtual bus address synchronization message, which is used to synchronize time with the slave station. Then, the process returns to step S310 to determine whether the next virtual bus address request message has been received within the maximum waiting time.
[0108] If the master station receives a virtual bus address request message Y, then step S316 is executed, and the master station updates the virtual bus address response list.
[0109] Preferably, before executing step S316, step S314 is executed, in which the master station parses the received virtual bus address request message and performs CRC verification. If the CRC verification passes (Y), it means that a slave station has requested the virtual bus address in the virtual bus address request message and no other slave station has requested it at the same time, thus causing a conflict. Then, step S316 is executed, and the master station updates the virtual bus address response list.
[0110] If, in step S314, the master station fails the CRC checksum N after parsing the virtual bus address request message, it may mean that more than one slave station has encountered a conflict with that virtual bus address. In this case, step S318 is executed, and the master station abandons the current virtual bus address request message. Then, returning to step S310, the master station determines whether it has received the next virtual bus address request message within the maximum waiting time.
[0111] After updating the virtual bus address response list, step S320 is executed to determine whether the master station has received all virtual bus address request messages.
[0112] If not, return to step S310 to determine whether the next virtual bus address request message has been received within the maximum waiting time.
[0113] If the answer is Y, meaning the master station has received all virtual bus address request messages, then step S322 is executed to allocate actual bus addresses to each slave station according to the virtual bus address response list. Specifically, actual bus address sending messages can be sent sequentially, and each actual bus address sending message includes the virtual bus address, acknowledgment flag, and actual bus address.
[0114] The above process enables the master station to assign actual bus addresses to slave stations based on virtual bus addresses.
[0115] Preferably, method 300 may further include step S324, whereby the master station determines whether it has received an ACK message from the slave station. If no ACK message N is received, then step S326 is executed to reallocate an actual bus address to the slave station, and the process returns to step S322 to execute the operation of the master station allocating an actual bus address to the slave station according to the virtual bus address response list. If an ACK message Y is received, then step S328 is executed to update the list of slave stations to be allocated.
[0116] In step S330, it is determined whether an actual bus address has been assigned to all slaves in the virtual bus address response list. If not, the process returns to step S322 to assign an actual bus address to the next slave, and so on, until an actual bus address has been assigned to all slaves in the virtual bus address response list.
[0117] If the answer is Y, then one round of operations to assign actual bus addresses to all master stations added to the virtual bus address response list is completed. During this process, some slave stations may not obtain a virtual bus address due to virtual address conflicts. Therefore, in step S332, it is determined whether all slave stations have obtained actual bus addresses. If there are still slave stations that have not obtained actual bus addresses (N), the master station will recalculate the number of slave stations that have not obtained actual bus addresses, that is, it will re-execute method 300 from step S302 until actual bus addresses are assigned to all slave stations. If it is determined in step S332 that all slave stations have obtained actual bus addresses, then method 300 ends in S334.
[0118] Reference above Figure 3 This describes the operational steps performed by the master station in the process of allocating a bus address to a slave station according to the method of embodiments of this disclosure. The operational steps performed by the slave station are as follows: Figure 4 As shown. Figure 4 This is a flowchart illustrating an exemplary process of a method 400 for assigning a bus address to a slave station, performed at a slave station according to an embodiment of this disclosure. The method specifically includes:
[0119] First, execute step S402 to obtain your own unique hardware identifier from the slave station.
[0120] In step S404, the range of available virtual bus addresses published by the master station is received.
[0121] In step S406, the slave station calculates the virtual bus address it wants to apply for based on the unique hardware identifier and the range of available virtual bus addresses using a consistent random number algorithm.
[0122] Optionally, the slave station calculates the virtual bus address to be requested based on the unique hardware identifier, the range of available virtual bus addresses, and the slave station's system time.
[0123] In step S408, the slave station receives and parses the virtual bus address request message and / or virtual bus address synchronization message published on the bus.
[0124] Through this step, the slave station can parse and obtain the virtual bus address requested by the currently sent virtual bus address request message.
[0125] In step S410, the slave station determines whether it needs to send its own virtual bus address request message.
[0126] As described above, each slave station sends virtual bus address request messages sequentially according to the order in which they request virtual bus addresses. Therefore, based on the virtual bus address it requests and the currently requested virtual bus address parsed in step S408, the slave station can determine whether it should send a virtual bus address request message to request the next virtual bus address after the standard interval time.
[0127] If N is not selected, it means that it is not yet the turn of the slave station to send a virtual bus address request message. Return to step S408 to continue receiving and parsing the virtual bus address request message and / or virtual bus address synchronization message published on the bus.
[0128] If it is Y, it means that the slave station will send a virtual bus address request message to request the next virtual bus address after the standard interval time, and execute step S412 to send the virtual bus address request message.
[0129] In step S414, the slave station determines whether it has received the actual bus address assigned by the master station.
[0130] If in step S414 the slave station determines that it has received the actual bus address assigned by the master station, then step S416 is executed, and the slave station sends an ACK (acknowledgment) message using the actual bus address assigned by the master station.
[0131] Finally, the slave station can save its own actual bus address parameters, and method 400 ends at S420.
[0132] Through the above process, the slave station obtains the actual bus address assigned by the master station.
[0133] Optionally, if in step S414 the slave station determines that it has not received the actual bus address assigned by the master station, then step S418 is executed, and the slave station further determines whether it has missed its own actual bus address.
[0134] It is understandable that the master station assigns actual bus addresses to each slave station in the order of the virtual bus address response list.
[0135] Here, "missed" Y means that the master station has sent a message allocating an actual bus address for the slave station, but the slave station has not received the message. Specifically, the slave station can compare its own virtual bus address with the virtual bus address in the actual bus address message sent by the master station. If the virtual bus address in the message sent by the master station is greater than its own virtual bus address, it means that the slave station missed its actual bus address in this round of operation. In this case, the process returns to step S404, which involves the slave station receiving the range of available virtual bus addresses published by the master station, to re-execute the method 400 for allocating a bus address for the slave station.
[0136] "Not missed N" means that the master station has not yet sent a message to the slave station to allocate an actual bus address. That is, the virtual bus address in the message sent by the master station is less than its own virtual bus address. In this case, step S414 is repeated and the slave station continues to determine whether it has received the actual bus address allocated by the master station.
[0137] Figure 4 The flowchart shown illustrates the steps a slave station takes to obtain the actual bus address. It can be understood that each slave station executes the following steps: Figure 4 The steps shown are used to obtain the master's actual bus address. If a conflict occurs because two slaves have requested the same virtual bus address, the master will re-execute the steps as shown. Figure 3 The operation steps shown will be executed simultaneously, and slaves that have not obtained an actual bus address will start executing the operation of method 400 from step S404.
[0138] Figure 5 This is a block diagram illustrating an exemplary configuration of a device 500 for assigning bus addresses to slave stations according to another embodiment of this disclosure. The device 500 for assigning bus addresses to slave stations is located at the master station and is used to perform actions such as... Figure 3 The method shown is for assigning bus addresses to slave stations.
[0139] The apparatus 500 for allocating bus addresses to slave stations according to an embodiment of the present disclosure includes: a slave station number determination unit 502, an available virtual bus address range calculation unit 504, an available virtual bus address publishing unit 506, a virtual address request start message publishing unit 508, a virtual bus address request message listening unit 510, a synchronization message publishing unit 512, a virtual bus address response list update unit 516, an operation termination control unit 520, and an actual bus address allocation unit 522.
[0140] The slave number determination unit 502 is configured to obtain the number of slaves to be assigned a bus address;
[0141] The available virtual bus address range calculation unit 504 is configured to calculate the range of available virtual bus addresses based on the number of slave stations and a predetermined expansion factor.
[0142] The available virtual bus address publishing unit 506 is configured to publish a range of available virtual bus addresses to the slave station;
[0143] The virtual address request start message publishing unit 508 is configured to publish a virtual address request start message to the slave station;
[0144] The virtual bus address request message listening unit 510 is configured to determine whether a virtual bus address request message has been received within the maximum waiting time;
[0145] Synchronization message publishing unit 512 is configured to publish virtual bus address synchronization;
[0146] The virtual bus address response list update unit 516 is configured to update the virtual bus address response list;
[0147] The operation termination control unit 520 is configured to determine whether the master station has received all virtual bus address request messages;
[0148] The actual bus address allocation unit 522 is configured to allocate actual bus addresses to slaves based on the virtual bus address response list.
[0149] Figure 6 This is a block diagram illustrating an exemplary configuration of a device 600 for assigning a bus address to a slave station according to yet another embodiment of this disclosure. The device 600 for assigning a bus address to a slave station is located at the slave station and is used to perform actions such as... Figure 4 The method shown is for assigning bus addresses to slave stations.
[0150] The apparatus 600 for allocating bus addresses to slave stations according to an embodiment of the present disclosure includes: a hardware identifier acquisition unit 602, an available virtual bus address range receiving unit 604, a virtual bus address request calculation unit 606, a message listening unit 608, a virtual bus address request message judgment unit 610, a virtual bus address request message sending unit 612, an actual bus address receiving judgment unit 614, and an ACK message sending unit 616.
[0151] The hardware identifier acquisition unit 602 is configured to acquire its own unique hardware identifier.
[0152] Available virtual bus address range receiving unit 604 is configured to receive the range of available virtual bus addresses published by the master station.
[0153] The virtual bus address calculation unit 606 is configured to calculate the virtual bus address to be requested by the slave station using a consistent random number algorithm based on the unique hardware identifier and the range of available virtual bus addresses.
[0154] The message listening unit 608 is configured to receive and parse virtual bus address request messages and / or virtual bus address synchronization messages published on the bus.
[0155] The virtual bus address request message determination unit 610 is configured to determine whether to send a virtual bus address request message to the slave station.
[0156] The virtual bus address request message sending unit 612 is configured to send a virtual bus address request message.
[0157] The actual bus address receiving judgment unit 614 is configured to determine whether the actual bus address assigned by the master station has been received.
[0158] The ACK message sending unit 616 is configured to send ACK messages using the actual bus address assigned by the master station.
[0159] Details of the operation and function of the various parts of the devices 500 and 600 for assigning bus addresses to slave stations can be found in references, for example. Figure 1-4 The relevant parts of the embodiments of the method for assigning bus addresses to slave stations described in this disclosure are the same or similar, and will not be described in detail here.
[0160] It should be noted that, Figure 5 and Figure 6 The structures of the devices 500 and 600 for assigning bus addresses to slave stations and their constituent units shown are merely exemplary; those skilled in the art can modify them as needed. Figure 5 and Figure 6 The structural diagram shown is modified.
[0161] The method and apparatus for assigning bus addresses to slave stations according to this disclosure have at least one or more of the following advantages.
[0162] The method disclosed herein converts the virtual bus address into the actual bus address during the bus address allocation process, thereby eliminating the need to manually preset any unique identifier for each slave station, which can significantly improve system efficiency.
[0163] According to the method disclosed herein, the number of virtual bus addresses is set to be the number of slaves multiplied by an extension factor, so that the number of virtual bus addresses is much greater than the number of slaves. Furthermore, each slave uses its own unique hardware ID as the random factor in the random algorithm. This greatly reduces the probability of different slaves requesting the same virtual bus address, thereby significantly reducing the problem of bus access conflicts.
[0164] The slave station sends virtual bus address request messages in the order of the virtual bus addresses and remains silent during the standard interval. At the same time, the master station also remains silent. This can reduce bus conflicts and further improve system efficiency.
[0165] As per the above reference Figures 1 to 6 The methods and apparatus according to embodiments of this disclosure have been described. The various units of the apparatus 500 and 600 described above for allocating bus addresses to slave stations can be implemented in hardware, software, or a combination of hardware and software.
[0166] Figure 7A block diagram of an electronic device 700 according to an embodiment of the present disclosure is shown. According to one embodiment, the electronic device 700 may include at least one processor 702 that executes at least one computer-readable instruction stored or encoded in a computer-readable storage medium (i.e., memory 704).
[0167] It should be understood that the computer-executable instructions stored in memory 704, when executed, cause at least one processor 702 to perform the above-described combinations in the various embodiments of this disclosure. Figure 1-6 The description includes various operations and functions.
[0168] According to one embodiment, a non-transitory machine-readable medium is provided. This non-transitory machine-readable medium may have machine-executable instructions that, when executed by a machine, cause the machine to perform the above-described combinations of the various embodiments of this disclosure. Figure 1-6 The description includes various operations and functions.
[0169] According to one embodiment, a computer program is provided, including computer-executable instructions that, when executed, cause at least one processor to perform the above-described embodiments of the present disclosure. Figure 1-6 The description includes various operations and functions.
[0170] According to one embodiment, a computer program product is provided, including computer-executable instructions that, when executed, cause at least one processor to perform the above-described embodiments of the present disclosure. Figure 1-6 The description includes various operations and functions.
[0171] It should be understood that the various embodiments in this specification are described in a progressive manner, and the same or similar parts between the various embodiments can be referred to each other. Each embodiment focuses on describing the differences from other embodiments. For example, the embodiments concerning the apparatus, the electronic device, and the machine-readable storage medium described above are basically similar to the method embodiments, so the description is relatively simple, and the relevant parts can be referred to the description of the method embodiments.
[0172] The foregoing description has described specific embodiments of this specification. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recited in the claims may be performed in a different order than that shown in the embodiments and may still achieve the desired result. Furthermore, the processes depicted in the drawings do not necessarily require the specific or sequential order shown to achieve the desired result. In some embodiments, multitasking and parallel processing are possible or may be advantageous.
[0173] Not all steps and units in the above process and system structure diagrams are necessary; some steps or units can be omitted according to actual needs. The device structure described in the above embodiments can be a physical structure or a logical structure. That is, some units may be implemented by the same physical entity, or some units may be implemented by multiple physical entities, or they may be jointly implemented by certain components in multiple independent devices.
[0174] The specific embodiments described above with reference to the accompanying drawings are exemplary embodiments, but do not represent all embodiments that can be implemented or fall within the scope of the claims. The term "exemplary" as used throughout this specification means "serving as an example, instance, or illustration" and does not imply that it is "preferred" or "advantageous" compared to other embodiments. Specific details are included to provide an understanding of the described techniques. However, these techniques can be practiced without these specific details. In some instances, well-known structures and apparatuses are shown in block diagram form to avoid obscuring the concepts of the described embodiments.
[0175] The foregoing description of this disclosure is provided to enable any person skilled in the art to implement or use this disclosure. Various modifications to this disclosure will be apparent to those skilled in the art, and the general principles defined herein can be applied to other variations without departing from the scope of this disclosure. Therefore, this disclosure is not limited to the examples and designs described herein, but is consistent with the widest scope of the principles and novel features disclosed herein.
[0176] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the protection scope of the present invention.
[0177] In this patent application, nouns and pronouns relating to people are not limited to specific genders.
Claims
1. A method (300) for assigning bus addresses to slave stations, including: The number of slave stations whose bus addresses are to be assigned by the master station (S302); The master station calculates the range of available virtual bus addresses based on the number of slave stations and a predetermined expansion factor (S304); The master station publishes the range of available virtual bus addresses to the slave station (S306); The master station sends a virtual address request start message to the slave station (S308); The master station determines whether it has received the virtual bus address request message within the maximum waiting time (S310); If not (N), the master station publishes a virtual bus address synchronization message (S312), and executes again the step of the master station determining whether it has received a virtual bus address request message within the maximum waiting time (S310). If it is (Y), the master station updates the virtual bus address response list (S316); Determine whether the master station has received all virtual bus address request messages (S320); If not (N), then repeat the step (S310) of the master station determining whether the virtual bus address request message has been received within the maximum waiting time; If it is (Y), the master station assigns an actual bus address to the slave station according to the virtual bus address response list (S322).
2. The method (300) of claim 1, further comprising: The master station checks whether it has received an ACK message (S324) from the slave station. If not (N), then the slave station is reassigned an actual bus address (S326), and the step of the master station assigning an actual bus address to the slave station according to the virtual bus address response list is repeated (S322). If it is (Y), update the list of slaves to be assigned (S328).
3. The method (300) of claim 2, further comprising: Determine whether all slaves in the virtual bus address response list have been assigned actual bus addresses (S330). If not (N), then repeat the step (S322) whereby the master station assigns an actual bus address to the slave station based on the virtual bus address response list. If it is (Y), then determine whether all slave stations have obtained the actual bus address (S332); If it is (Y), then the method (300) ends (334); If not (N), then return to the step (S302) where the master station obtains the number of slave stations to be assigned bus addresses and execute the method (300).
4. The method (300) according to any one of claims 1 to 3, wherein, Before executing the master station update virtual bus address response list (S316), the method further includes: The master station parses the received virtual bus address request message and performs a CRC check. If the CRC check passes (Y), the master station updates the virtual bus address response list (S316). If the CRC check (N) fails, the master station abandons the current virtual bus address request message (S318) and repeats the step of the master station determining whether the virtual bus address request message has been received within the maximum waiting time (S310).
5. The method (300) according to any one of claims 1 to 3, wherein, The virtual bus address request message includes an acknowledgment identifier, which is calculated using a random number algorithm based on the slave's unique hardware identifier.
6. The method (300) according to any one of claims 1 to 3, wherein, Assigning actual bus addresses to each slave station according to the virtual bus address response list (S322) includes: the master station sequentially sending actual bus address sending messages according to the order of the virtual bus addresses in the virtual bus address response list, wherein the actual bus address sending message includes the virtual bus address, the slave station's acknowledgment identifier, and the actual bus address.
7. The method (300) according to any one of claims 1 to 3, wherein, The expansion factor is greater than or equal to 10.
8. The method (300) according to any one of claims 1 to 3, wherein, The virtual address request initiation message includes a standard interval, which is a predetermined time interval between two slave stations sending virtual bus address request messages.
9. A method (400) for assigning bus addresses to slave stations, including: Obtain its own unique hardware identifier from the station (S402); The slave station receives the range of available virtual bus addresses published by the master station (S404); The slave station calculates the virtual bus address it wants to apply for based on the unique hardware identifier and the range of available virtual bus addresses using a consistent random number algorithm (S406); The slave station receives and parses the virtual bus address request message and / or virtual bus address synchronization message published on the bus (S408); The slave station determines whether it should send its own virtual bus address request message (S410); If not (N), then repeat the step (S408) of the slave station receiving and parsing the virtual bus address request message and / or virtual bus address synchronization message published on the bus. If it is (Y), then send a virtual bus address request message (S412); The slave station determines whether it has received the actual bus address assigned by the master station (S414); If it is (Y), the slave station sends an ACK message (S416) using the actual bus address assigned by the master station.
10. The method (400) of claim 9, wherein in the event that the slave determines that the actual bus address assigned by the master has not been received by the slave in judging whether the actual bus address assigned by the master has been received, the method further comprises: The slave station determines whether it has missed its actual bus address (S418). If it is (Y), repeat the process of the slave station receiving the range of available virtual bus addresses published by the master station (S404); If not (N), repeat the process of the slave station determining whether it has received the actual bus address assigned by the master station (S414).
11. The method (400) of claim 9, wherein, The virtual bus address request message includes a confirmation identifier for the slave station, which is calculated based on the slave station's unique hardware identifier.
12. A device (500) for assigning bus addresses to slave stations, located at the master station, comprising: The slave number determination unit (502) is configured to obtain the number of slaves to be assigned a bus address; The available virtual bus address range calculation unit (504) is configured to calculate the range of available virtual bus addresses based on the number of slave stations and a predetermined expansion factor; The available virtual bus address publishing unit (506) is configured to publish a range of available virtual bus addresses to the slave station; The virtual address request start message publishing unit (508) is configured to publish a virtual address request start message to the slave station; The virtual bus address request message listening unit (510) is configured to determine whether a virtual bus address request message is received within the maximum waiting time; The synchronous message publishing unit (512) is configured to publish virtual bus address synchronization; The virtual bus address response list update unit (516) is configured to update the virtual bus address response list; The operation termination control unit (520) is configured to determine whether the master station has received all virtual bus address request messages; The actual bus address allocation unit (522) is configured to allocate actual bus addresses to slaves based on the virtual bus address response list.
13. A means (600) for assigning bus addresses to slave stations, provided at each slave station, comprising: The hardware identifier acquisition unit (602) is configured to acquire its own unique hardware identifier; The available virtual bus address range receiving unit (604) is configured to receive the range of available virtual bus addresses published by the master station; The virtual bus address calculation unit (606) is configured to calculate the virtual bus address to be requested by the slave station using a consistent random number algorithm based on the unique hardware identifier and the range of available virtual bus addresses. The message listening unit (608) is configured to receive and parse virtual bus address request messages and / or virtual bus address synchronization messages published on the bus; The virtual bus address request message determination unit (610) is configured to determine whether to send a virtual bus address request message to the slave station. The virtual bus address request message sending unit (612) is configured to send a virtual bus address request message; The actual bus address receiving judgment unit (614) is configured to determine whether the actual bus address allocated by the master station has been received; The ACK message sending unit (616) is configured to send ACK messages using the actual bus address assigned by the master station.
14. Electronic equipment (700), including: At least one processor (702); as well as A memory (704) coupled to the at least one processor (702), the memory being used to store instructions that, when executed by the at least one processor (702), cause the processor (702) to perform the method as described in any one of claims 1-8, 9-11.
15. A non-transitory machine-readable storage medium storing executable instructions that, when executed, cause the machine to perform the method as described in any one of claims 1-8, 9-11.
16. A computer program product tangibly stored on a computer-readable medium and comprising computer-executable instructions that, when executed, cause at least one processor to perform the method according to any one of claims 1-8, 9-11.