An addressing method, apparatus, device, and readable storage medium
By automatically determining the waiting time and sending addressing messages on a shared communication medium, the problem of slave device automatic addressing relying on dedicated hardware and protocols in the prior art is solved, and orderly and stable automatic addressing without additional hardware is achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- SHENZHEN KEXIN COMM TECH
- Filing Date
- 2026-07-02
- Publication Date
- 2026-07-31
AI Technical Summary
In communication systems where the host device and multiple slave devices are connected to the same shared communication medium, existing technologies require additional hardware or dedicated communication protocols to achieve automatic addressing of slave devices, resulting in high costs, poor flexibility, and a tendency for address conflicts to occur.
The first device listens to addressing messages on the shared communication medium, determines the waiting time, and sends addressing messages. It uses preset step size and historical address values to achieve automatic addressing without dedicated communication protocols and hardware, ensuring that devices participate in addressing in the order of their addresses.
It achieves the orderliness and stability of the automatic addressing process for multiple slave devices without the need for dedicated communication protocols and hardware, reducing address conflicts and the need for manual configuration, and lowering system costs.
Smart Images

Figure CN122496492A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and in particular to an addressing method, apparatus, device and readable storage medium. Background Technology
[0002] In a communication system where a master device and multiple slave devices are connected to the same shared communication medium, it is necessary to assign different communication addresses to each slave device so that the master device or other slave devices can communicate through the communication addresses. For example, in a scenario with a serial bus or similar bus network sharing a communication medium, multiple slave devices are connected to the same communication bus. The master device sends communication messages based on the slave device's address, and the slave device with the corresponding address responds to the communication message, while other slave devices do not respond.
[0003] Currently, slave device addresses are typically set manually via DIP switches, or written as fixed addresses before network setup, or allocated using other communication networks with automatic addressing capabilities. DIP switch methods require additional hardware, occupying slave device space and involving significant on-site configuration work, and are prone to address conflicts due to manual settings errors. Fixed address methods require pre-configuration, offering limited flexibility when adding or removing slave devices or changing network relationships. While using additional communication networks for automatic addressing reduces manual configuration, it usually relies on dedicated communication protocols and hardware, resulting in high system costs.
[0004] Therefore, how to achieve automatic addressing without the need for dedicated communication protocols and hardware is a technical problem that urgently needs to be solved. Summary of the Invention
[0005] This application provides an addressing method, apparatus, device, and readable storage medium that can achieve automatic addressing without the need for dedicated communication protocols and communication hardware.
[0006] In a first aspect, this application provides an addressing method, the method comprising: if a first device receives a first addressing message before the end of a first waiting time, the first device determines a second waiting time based on the first addressing message, the first addressing message including a first address value of the second device; after the first device determines the second waiting time, if the first device does not receive an addressing message sent by another device before the end of the second waiting time, the first device sends a second addressing message, the second addressing message including a second address value of the first device, the second address value being determined based on the first address value and a preset step size; if the first device does not receive an addressing message sent by another device before the end of the first waiting time, the first device sends a second addressing message, the second addressing message including a second address value of the first device, the second address value being an initial address value.
[0007] In this application, when the second address value is the initial address value, if the first device does not receive an addressing message sent by another device before the end of the first waiting time, the first device sends a second addressing message, which includes the initial address value.
[0008] When the second address value is determined based on the first address value and a preset step size, if the first device receives the first addressing message before the end of the first waiting time, the first device determines the second waiting time based on the first addressing message, which includes the address values of other devices. If the first device does not receive an addressing message from another device before the end of the second waiting time, the first device sends a second addressing message, which includes the second address value of the first device.
[0009] Therefore, the first device can automatically complete the addressing process by listening to addressing messages on the same shared communication medium, exchanging addressing messages between devices, and determining the waiting time of each device. This allows for automatic addressing without the need for dedicated communication protocols and hardware.
[0010] It should be noted that, in this embodiment, the electronic device can be a device connected to the same shared communication medium. The electronic device may include a host device and a slave device. The host device can be used to send normal communication messages based on the address value of the slave device, and the slave device can be used to receive normal communication messages sent by the host device.
[0011] The first device in this application embodiment refers to a slave device that executes the addressing method provided in this application embodiment. That is, the first device can be any slave device accessing the same shared communication medium, and does not specifically refer to a particular fixed slave device. For example, the first device can be slave device A, slave device B, slave device C, or other slave devices. The second device, third device, etc., can be other slave devices that are different from the first device.
[0012] Therefore, unless otherwise stated, the operations such as "the first device sends an addressing message", "the first device receives an addressing message", and "the first device determines a waiting time" in the embodiments of this application can all be understood as being performed by the slave device.
[0013] In conjunction with the first aspect, in one possible implementation, the first address value is the initial address value.
[0014] In conjunction with the first aspect, in one possible implementation, the first address value is an initial address value, the first device obtains the historical address value of the first device, and the first device determines the first waiting time based on the historical address value.
[0015] In conjunction with the first aspect, in one possible implementation, the first waiting time satisfies: T1 = (n-1)×TS; where T1 represents the first waiting time, n represents the historical address value, TS = M×TI, M is a positive integer, and TI represents the time from when the addressing message is sent to when it is received, thus ensuring that the device at address n will not send an addressing message before receiving the message.
[0016] In this application, the first device can determine different first waiting times based on its own historical address values, so that the first device with a smaller historical address value sends the addressing message earlier, and the first device with a larger historical address value sends the addressing message later. Therefore, multiple slave devices can participate in addressing sequentially according to their historical address order, thereby reducing the probability of multiple slave devices sending addressing messages simultaneously and improving the orderliness of the automatic addressing process.
[0017] In conjunction with the first aspect, in one possible implementation, the first device determines the next sequential address value based on the first address value and a preset step size; the first device determines the second waiting time based on the first device's historical address values and the next sequential address value or the first address value.
[0018] In conjunction with the first aspect, in one possible implementation, if the historical address value is equal to the next sequential address value, then the first type of waiting time is determined as the second waiting time; if the historical address value is greater than the next sequential address value, then the second type of waiting time is determined as the second waiting time; if the historical address value is less than the first address value, then the third type of waiting time is determined as the second waiting time; wherein, the first type of waiting time is less than the second type of waiting time, and the second type of waiting time is less than or equal to the third type of waiting time.
[0019] In conjunction with the first aspect, in one possible implementation, the first type of waiting time satisfies: 0 ≤ Tr ≤ TR, where Tr represents the first type of waiting time and TR represents the upper limit of the first type of waiting time; the second type of waiting time satisfies: Tc = n×TI+TC, where Tc represents the second type of waiting time; the third type of waiting time satisfies: Ta = n×TI+TA, where TA=TC+N×TI+TI, N represents the total number of supported access devices, and Ta represents the third type of waiting time; where TC=TR+TI, TR=R×TI, R is a positive integer, n represents the historical address value, and TI represents the time from when the addressing message is sent to when it is received.
[0020] In this application, devices with historical address values equal to the next sequential address value use a first type of waiting time to prioritize transmission. Devices with historical address values greater than the next sequential address value use a second type of waiting time to delay transmission. Devices with historical address values less than the first address value use a third type of waiting time to further delay transmission. This allows multiple slave devices to participate in addressing sequentially according to their address order when their corresponding waiting times arrive, improving the orderliness of the automatic addressing process.
[0021] In conjunction with the first aspect, in one possible implementation, when the first device receives an addressing message sent by another device within a first time after the sending time of the second addressing message, or when the first device receives a third addressing message and the address value carried by the third addressing message is the same as the second address value of the first device, the first device determines a third waiting time, which is less than a third type of waiting time.
[0022] In conjunction with the first aspect, in one possible implementation, the third waiting time satisfies: Tx = TC + Te, where TC = TR + TI, TR = R × TI, R is a positive integer, TI represents the time from when the addressed message is sent to when it is received, and Te represents the time within the first time after the sending time when the addressed message is received from another device.
[0023] In this application, a transmission conflict is determined when multiple slave devices send addressing messages at the same or near time and a conflict occurs, or when a slave device receives an addressing message from another slave device containing the same address value as its own. The conflicting slave devices no longer preempt the current address value; instead, they recalculate the conflict waiting time Tx (i.e., the third waiting time) based on the conflict detection time Te, and re-participate in addressing after Tx expires. This method allows conflicting slave devices to stagger their transmission times and adjusts the conflicted address to a subsequent address sequence, thereby reducing the probability of repeated conflicts and improving the stability and orderliness of the automatic addressing process.
[0024] In conjunction with the first aspect, in one possible implementation, after the first device sends the second addressing message, the first device determines a fourth waiting time, which satisfies: TD = TA + N × TI + TI, where TA = TC + N × TI + TI, TC = TR + TI, TR = R × TI, R is a positive integer, N represents the total number of devices supported for access, TI represents the time from when the addressing message is sent to when it is received, and TD represents the fourth waiting time, which is greater than the third type of waiting time.
[0025] In this application, if the first device has already sent a second addressing message carrying its own address value, the first device can determine its corresponding waiting time as a fourth waiting time TD. Since the fourth waiting time TD is greater than the third waiting time Ta, the first device will not immediately participate in the competition for subsequent address values after sending the second addressing message, but will re-participate in the addressing process after a longer waiting period. Therefore, slave devices that have already completed their current address declaration can actively avoid subsequent addressing processes, ensuring that other slave devices that have not yet completed addressing can continue to send addressing messages in address order, thereby improving the orderliness and stability of the automatic addressing process.
[0026] In conjunction with the first aspect, in one possible implementation, if the first device detects a communication message sent by the host and determines that at least one round of addressing process has been completed, then the first device stops addressing.
[0027] In conjunction with the first aspect, in one possible implementation, if the first device receives an addressing message carrying the initial address value again, the first device determines that at least one round of addressing process has been completed.
[0028] In this application, the first device can exit the addressing process after the host device is online and has completed at least one round of addressing. This ensures that each slave device has completed the necessary address allocation and avoids addressing messages continuously occupying the shared communication medium, thereby improving the coordination and stability between the automatic addressing process of the slave devices and the normal communication process of the host device.
[0029] Secondly, this application provides an addressing device, the device comprising: The determining unit is configured to determine a second waiting time based on the first addressing message when the first device receives the first addressing message before the first waiting time ends, wherein the first addressing message includes a first address value of the second device. The sending unit is configured to send a second addressing message after the determining unit determines the second waiting time, and before the end of the second waiting time, if no addressing message is received from other devices, the second addressing message includes a second address value of the first device, the second address value being determined based on the first address value and the preset step size; The sending unit is further configured to send a second addressing message when the first device has not received an addressing message from another device before the first waiting time ends. The second addressing message includes a second address value of the first device, which is an initial address value.
[0030] In conjunction with the second aspect, in one possible implementation, the first address value is the initial address value.
[0031] In conjunction with the second aspect, in one possible implementation, the first address value is the initial address value. The device also includes an acquisition unit for acquiring the historical address values of the first device; The determining unit is also used to determine the first waiting time based on the historical address value.
[0032] In conjunction with the second aspect, in one possible implementation, the first waiting time satisfies: T1 = (n-1)×TS; where T1 represents the first waiting time, n represents the historical address value, TS = M×TI, M is a positive integer, and TI represents the time from when the addressing message is sent to when it is received. This ensures that the device at address n will not send an addressing message before receiving the message.
[0033] In conjunction with the second aspect, in one possible implementation, the determining unit is specifically configured to determine the next sequential address value based on the first address value and a preset step size; the determining unit is specifically configured to determine the second waiting time based on the historical address value of the first device and the next sequential address value or the first address value.
[0034] In conjunction with the second aspect, in one possible implementation, the determining unit is specifically configured to determine the first type of waiting time as the second waiting time when the historical address value is equal to the next sequential address value; the determining unit is specifically configured to determine the second type of waiting time as the second waiting time when the historical address value is greater than the next sequential address value; the determining unit is specifically configured to determine the third type of waiting time as the second waiting time when the historical address value is less than the first address value; wherein the first type of waiting time is less than the second type of waiting time, and the second type of waiting time is less than or equal to the third type of waiting time.
[0035] In conjunction with the second aspect, in one possible implementation, the first type of waiting time satisfies: 0 ≤ Tr ≤ TR, where Tr represents the first type of waiting time and TR represents the upper limit of the first type of waiting time; the second type of waiting time satisfies: Tc = n×TI+TC, where Tc represents the second type of waiting time; the third type of waiting time satisfies: Ta = n×TI+TA, where TA=TC+N×TI+TI, N represents the total number of supported access devices, and Ta represents the third type of waiting time; where TC=TR+TI, TR=R×TI, R is a positive integer, n represents the historical address value, and TI represents the time from when the addressing message is sent to when it is received.
[0036] In conjunction with the second aspect, in one possible implementation, the determining unit is further configured to determine a third waiting time when the first device receives an addressing message sent by another device within a first time after the sending time of the second addressing message, or when the first device receives a third addressing message and the address value carried by the third addressing message is the same as the second address value of the first device, wherein the third waiting time is less than the third type of waiting time.
[0037] In conjunction with the second aspect, in one possible implementation, the third waiting time satisfies: Tx = TC + Te, where TC = TR + TI, TR = R × TI, R is a positive integer, TI represents the time from when the addressed message is sent to when it is received, and Te represents the time within the first time after the sending time when the addressed message is received from another device.
[0038] In conjunction with the second aspect, in one possible implementation, the determining unit is further configured to determine a fourth waiting time after the first device sends the second addressing message. The fourth waiting time satisfies: TD = TA + N × TI + TI, where TA = TC + N × TI + TI, TC = TR + TI, TR = R × TI, R is a positive integer, N represents the total number of devices supported for access, TI represents the time from when the addressing message is sent to when it is received, and TD represents the fourth waiting time, which is greater than the third type of waiting time.
[0039] In conjunction with the second aspect, in one possible implementation, the device further includes a status control unit for stopping addressing when the first device detects a communication message sent by the host and determines that at least one round of addressing process has been completed.
[0040] In conjunction with the second aspect, in one possible implementation, the state control unit is further configured to determine that at least one round of addressing process has been completed if the first device receives an addressing message carrying the initial address value again.
[0041] Thirdly, this application provides an electronic device including a processor and an interface circuit coupled together. The interface circuit is used for transmitting, receiving, or inputting / outputting information or data. The processor is used to execute program instructions, causing the electronic device to perform the methods described in the first aspect or any possible implementation thereof.
[0042] Fourthly, this application provides a computer-readable storage medium storing a computer program or instructions that, when run on a computer, cause the computer to perform the method described in the first aspect or any possible implementation thereof.
[0043] Fifthly, this application provides a computer program product containing program instructions that, when run, causes the method described in the first aspect or any possible implementation of the first aspect to be executed.
[0044] Sixthly, this application provides a communication system including a shared communication medium and a plurality of electronic devices connected to the shared communication medium. At least one of the plurality of electronic devices is used to perform the method described in the first aspect or any possible implementation thereof.
[0045] The technical effects achieved in the above aspects can be referred to each other or to the beneficial effects in the method embodiments shown below, which will not be repeated here. Attached Figure Description
[0046] Figure 1 This is a schematic diagram of the architecture of a communication system provided in an embodiment of this application; Figure 2 This is a flowchart illustrating an addressing method provided in an embodiment of this application; Figure 3 This is a flowchart illustrating a complete addressing method provided in an embodiment of this application; Figure 4 This is a timing diagram of a complete addressing method provided in an embodiment of this application; Figure 5 This is a timing diagram of an addressing conflict provided in an embodiment of this application; Figure 6 This is a timing diagram illustrating an addressing method for a slave device after it goes offline, as provided in an embodiment of this application. Figure 7 This is a schematic diagram of an addressing device provided in an embodiment of this application; Figure 8 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation
[0047] The technical solutions in the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. The specific operation methods and functional descriptions in the method embodiments can also be applied to the device embodiments or system embodiments.
[0048] In the various embodiments of this application, unless otherwise specified or in case of logical conflict, the terminology and / or descriptions of different embodiments are consistent and can be referenced by each other. The technical features of different embodiments can be combined to form new embodiments according to their inherent logical relationship.
[0049] In this application, "at least one" means one or more, and "more than one" means two or more. "And / or" describes the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can mean: A alone, A and B simultaneously, or B alone, where A and B can be singular or plural. In the textual description of this application, the character " / " generally indicates that the preceding and following related objects are in an "or" relationship. "At least one of the following" or similar expressions refer to any combination of these items, including any combination of single or plural items. For example, at least one of a, b, and c can mean: a, or, b, or, c, or, a and b, or, a and c, or, b and c, or, a, b, and c. Here, a, b, and c can each be single or multiple.
[0050] In this application, terms such as "first" and "second" are merely for descriptive convenience and are not intended to limit the scope of the embodiments of this application. For example, they distinguish different instruction information, rather than describing a specific order or sequence. Such descriptions can be interchanged where appropriate to describe solutions other than those in the embodiments of this application.
[0051] In this application, "send" and "receive" indicate the direction of signal transmission. "Send information to XX (device)" can be understood as the destination of the information being that device. This can include sending information directly or indirectly to that device. "Receive information from XX (device)" can be understood as the source of the information being that device, and can include receiving information directly or indirectly from that device. Information may undergo necessary processing between the source and destination, such as format changes, but the destination can understand the valid information from the source. Similar expressions in this application can be understood in a similar way, and will not be elaborated further here. Additionally, "send" can also be understood as the "output" of a chip interface, and "receive" can also be understood as the "input" of a chip interface. In other words, "send" or "receive" can occur between devices, for example, between network devices and terminal devices via an air interface; "send" or "receive" can also occur within a device, for example, between components, modules, chips, software modules, or hardware modules within a device via a bus, wiring, or interface.
[0052] It is understandable that information may undergo necessary processing, such as encoding and modulation, between the source and destination, but the destination can understand the valid information from the source. Similar statements in this application can be interpreted in a similar way and will not be elaborated further.
[0053] In this application, the words "exemplary," "for example," "such as," etc., are used to indicate examples, illustrations, or descriptions. Any embodiment or design described as an "example" in this application should not be construed as being more preferred or advantageous than other embodiments or designs. Specifically, the term "example" is used to present concepts in a concrete manner.
[0054] In this application, expressions such as "B corresponding to A" can indicate that there is a correspondence / mapping relationship between A and B, and that B can be determined based on A. Determining B based on A includes determining B based solely on A, as well as determining B based on A and other information.
[0055] The following describes the communication system involved in this application.
[0056] The technical solutions of this application can be applied to communication systems where multiple slave devices share the same communication medium. This shared communication medium may include a serial bus, a single bus, a multi-point bus, or other wired shared communication media capable of enabling network communication among multiple slave devices. This application does not limit the specific type of communication medium; as long as multiple slave devices can send and receive addressed messages through this communication medium, the technical solutions provided in this application can be applied.
[0057] In one possible implementation, the communication system may include a master device and multiple slave devices, with the slave devices connected to the same shared communication medium. The master device can send a communication message to a target slave device based on the address value of the slave device. The target slave device corresponding to the address value responds to the communication message, while other slave devices do not respond. In cases where the master device is offline, has not yet sent a communication message, or the communication system requires readdressing, the multiple slave devices can send and receive addressing messages through the communication medium and complete automatic addressing based on the address value carried in the addressing message and the waiting time rules.
[0058] In another possible implementation, the communication system may not include a master device, or the master device may be offline for a period of time. Multiple slave devices connected to the communication medium can each execute the addressing method provided in this application embodiment to achieve automatic and ordered addressing of the multiple slave devices.
[0059] The electronic device in this application embodiment can be a device that accesses the same shared communication medium and is capable of sending or receiving addressed messages. For example, the electronic device can be a serial bus device, slave device, node device, industrial control device, sensing device, data acquisition device, execution device, display device, or other device that needs to distinguish addresses within the same shared communication medium. This application embodiment does not limit the specific product form of the electronic device.
[0060] See Figure 1 , Figure 1 This is a schematic diagram of the architecture of a communication system provided in an embodiment of this application. Figure 1 As shown, the communication system may include a shared communication medium 110 and multiple slave devices connected to the shared communication medium 110, such as... Figure 1 The slave devices are A, B, C, D, E, F, and G. This is understandable. Figure 1 Taking seven slave devices as an example, in practical applications, the number of devices connected to the shared communication medium 110 can be more or less, without limitation. For example, the shared communication medium 110 can be a serial bus, a single bus, a multi-point bus, or other communication medium that enables multiple slave devices to network and communicate.
[0061] In one possible implementation, the communication system may further include a master device 120. The master device 120 can communicate with multiple slave devices via a shared communication medium 110. For example, the master device 120 can send a communication message to a slave device based on its address value, and the slave device corresponding to that address value responds to the communication message. When the master device 120 is offline, or does not detect a communication message sent by the master device 120, or when the communication system requires readdressing, multiple slave devices can send and receive addressing messages via the shared communication medium 110 to perform an automatic addressing process.
[0062] Serial communication is a common device communication method. In a serial bus communication scenario, multiple devices can be connected to the same bus for network communication, which can include one master device and multiple slave devices. The master device can send a request signal based on the slave device's address. The slave device with the corresponding address responds to the request signal, while other slave devices do not respond. Therefore, in order for the master device to distinguish between different slave devices, different addresses need to be assigned to each slave device at the communication protocol layer.
[0063] The existing methods for assigning slave device addresses include the following: First, manually setting the slave device address via a DIP switch; second, pre-setting a fixed address before networking the slave devices, for example, by storing the address in a read-only memory; and third, using a Controller Area Network (CAN) communication network to achieve automatic address assignment.
[0064] However, manually assigning addresses via DIP switches requires additional switches, increasing hardware costs and occupying space on the slave device's panel, affecting its appearance. Furthermore, manual DIP switching during installation or maintenance is prone to errors, leading to duplicate or conflicting addresses and increasing the difficulty and workload of on-site debugging. Setting fixed addresses before networking also requires manual pre-configuration, which becomes inflexible when the number of devices, installation locations, or network relationships change, further increasing configuration difficulty and maintenance workload. While CAN communication networking enables automatic address assignment, it requires additional CAN communication networks and related interfaces, wiring, and terminating resistors, resulting in higher system costs and increased wiring complexity. Therefore, how to achieve automatic addressing of multiple slave devices based on existing serial buses is a pressing technical problem that needs to be solved.
[0065] The addressing method of this application embodiment will be described by way of example below.
[0066] The addressing method in this embodiment can be executed by a first device connected to a shared communication medium. The first device can be any slave device in the communication system. The second device can be any slave device different from the first device. Both the first and second devices can be connected to the shared communication medium.
[0067] See Figure 2 , Figure 2 This is a flowchart illustrating an addressing method provided in an embodiment of this application. Figure 2 As shown, this addressing method may include, but is not limited to, the following steps: S101, if the first device receives the first addressing message before the first waiting time ends, the first device determines the second waiting time based on the first addressing message.
[0068] The first addressing message includes the first address value of the second device. After the first device determines the second waiting time, if the first device does not receive an addressing message from another device before the end of the second waiting time, the first device sends a second addressing message, which includes the second address value of the first device, and the second address value is determined based on the first address value and the preset step size.
[0069] S102, if the first device does not receive an addressing message from another device before the first waiting time ends, the first device sends a second addressing message.
[0070] The second addressing message includes a second address value for the first device, which is the initial address value.
[0071] In one possible implementation, the addressing method further includes: S100, the first device determines a first waiting time.
[0072] The first waiting time can be an initial waiting time, or it can be a waiting time re-determined based on the address value carried by the most recently received addressing message (i.e., a second waiting time).
[0073] It should be noted that the first address value can be understood as the address value in the addressing message most recently received by the first device.
[0074] In one possible implementation, when the second address value is the initial address value, if the first device does not receive an addressing message from another device before the end of the first waiting time, the first device sends a second addressing message, which includes the second address value (i.e., the initial address value) of the first device.
[0075] At this point, the first device can serve as the starting device in this round of addressing process. For example, the first device can be slave device A, and other slave devices can include slave device B and slave device C. After slave device A enters the addressing process, slave device A can acquire a first waiting time and listen for addressing messages sent by other devices on the shared communication medium 110 during this first waiting time.
[0076] If slave device A does not receive an addressing message from another device before the end of the first waiting time, it indicates that no other device has declared or sent an addressing message through the shared communication medium 110 during the current waiting period. In this case, slave device A can determine the second address value as the initial address value and use this second address value as its own address value. For example, the initial address value can be the starting address value in the address sequence or a preset minimum address value, such as 1.
[0077] After the first device determines its own address value, slave device A can send a second addressing message through the shared communication medium 110. This second addressing message carries the second address value. Since this second address value is the initial address value, the second addressing message can be used to indicate that the current addressing process has started from this initial address value. After receiving the second addressing message, slave devices B, C, and other slave devices can redetermine their respective waiting times based on the initial address value carried in the second addressing message, in order to participate in the determination of subsequent address values and the sending of addressing messages. In this implementation, since the second address value carried in the second addressing message is the initial address value, the second addressing message can also be understood as the initial addressing message.
[0078] For example, if the initial address value is 1, and slave device A does not receive an addressing message from another slave device before the first waiting time ends, slave device A can set its own address value to 1 and send a second addressing message carrying the address value 1. After receiving the second addressing message carrying the address value 1, other slave devices can determine that the current addressing process has completed the declaration of address value 1, and can determine the next sequential address value, such as address value 2, based on address value 1 and a preset step size. Thus, without relying on the master device to allocate addresses, multiple slave devices can be triggered to continue the subsequent automatic addressing process based on the shared communication medium 110 by sending an addressing message carrying the initial address value.
[0079] In this way, if the first device (i.e., slave device A) does not receive an addressing message from other slave devices, slave device A can automatically occupy the initial address value and send an addressing message, thereby avoiding the need to manually specify the starting slave device or manually configure the initial address, which is beneficial for realizing automatic addressing of multiple slave devices in a shared communication medium.
[0080] In one possible implementation, when the second address value is the initial address value, the first device obtains the historical address value of the first device, and the first device determines the first waiting time based on the historical address value.
[0081] When the second address value is the initial address value, the first waiting time is the initial waiting time, which is determined by the first device based on the acquired historical address value. It should be noted that the historical address value can be the address value determined by the first device in the previous addressing process, or the address value stored by the first device after the previous network addressing was completed.
[0082] The first device can determine the first waiting time based on the historical address value. Specifically, the first device can determine the first waiting time based on the position of the historical address value in the address sequence. The earlier the historical address value appears in the address sequence, the shorter the first waiting time. The later the historical address value appears in the address sequence, the longer the first waiting time. Therefore, when re-entering the addressing process, devices with smaller historical address values can send addressing messages earlier, and devices with larger historical address values can send addressing messages later, thus enabling multiple slave devices to participate in addressing sequentially according to the address sequence formed in the previous round of addressing as much as possible.
[0083] For example, such as Figure 1As shown, if the historical address values of slave devices A, B, and C in the previous addressing process are 1, 2, and 3 respectively, then when the master device goes offline or re-enters the addressing process, slave device A can determine a shorter first waiting time based on historical address value 1, slave device B can determine a longer first waiting time based on historical address value 2, and slave device C can determine a longer first waiting time based on historical address value 3. In this way, without receiving addressing messages from other devices, slave devices A, B, and C can send addressing messages sequentially according to the order corresponding to their historical address values, thus achieving automatic and ordered addressing.
[0084] It should be noted that, in this embodiment of the application, to facilitate the description of the relationship between various waiting times, uppercase letters can be used to represent preset constants, and lowercase letters can be used to represent variables related to specific slave devices. For example, TI, TS, TR, TC, TA, TD, and N can be preset constants. Wherein, TI represents the time required for an addressed message to be sent and received by other devices in the shared communication medium; TS represents the basic waiting interval; TR represents the upper limit of random waiting; TC represents the second type of baseline waiting time; TA represents the third type of baseline waiting time; TD represents the waiting time after transmission; and N represents the total number of devices supported by the communication system or the maximum number of devices. For example, if the shared communication medium supports a maximum of 64 devices, then N can be 64.
[0085] 'n' can represent the historical address value of the first device or its order in the address sequence, and the value of 'n' is no greater than N. Therefore, the global time boundary for each waiting time can be determined based on N, and the waiting time corresponding to a specific device can be determined based on 'n'.
[0086] In one possible implementation, the first waiting time can satisfy the following relationship: T1 = (n-1) × TS. Here, T1 represents the first waiting time, n represents the historical address value of the first device (i.e., the address sequence value corresponding to the historical address value of the first device), TS represents the basic waiting interval, TS = M × TI, where M is a positive integer, and TI represents the time it takes for an addressed message to be sent from one device to another and received. In other words, TI represents the time required for an addressed message to be sent and received by another device in a shared communication medium.
[0087] For example, when the address values increment in the order of 1, 2, 3, 4, n can be the same as the historical address value of the first device. TS can be determined based on TI, for example, TS = M × TI, where M is a positive integer. In one possible example, M can be 2, i.e., TS = 2 × TI.
[0088] It should be noted that, when the shared communication medium is a bus, an addressing message sent by one slave device on the bus can be received by other slave devices on the bus at the same or substantially the same time. This application embodiment can utilize this characteristic to define the time from the sending of a byte on the bus to its reception by another slave device as TI, and determine the waiting time corresponding to each slave device based on TI, thereby achieving addressing timing control among multiple slave devices.
[0089] For example, when the master device is offline and each slave device has historical address values, the slave device whose historical address value appears earlier in the address sequence has a shorter initial waiting time. Conversely, the slave device whose historical address value appears later in the address sequence has a longer initial waiting time. Figure 1 As shown, slave device A has a historical address value of 1, so its first waiting time can be 0 milliseconds. Therefore, slave device A can first send an addressing message carrying address value 1. Slave device B with a historical address value of 2 has a first waiting time of TS. When TS = 2 × TI, slave device B can send an addressing message carrying address value 2 after a delay of 2 × TI. Therefore, the first waiting time for a slave device with a historical address value of n can be (n-1) × TS, which means the first waiting time can be (n-1) × 2 × TI.
[0090] For example, if TI is 1 millisecond, then TS is 2 milliseconds. In this case, the first waiting time for slave device A with a historical address value of 1 is 0 milliseconds, and slave device A can first send an addressing message carrying address value 1. The first waiting time for slave device B with a historical address value of 2 is 2 milliseconds. The first waiting time for slave device C with a historical address value of 3 is 4 milliseconds. The first waiting time for slave device D with a historical address value of 4 is 6 milliseconds. The first waiting time for slave device E with a historical address value of 5 is 8 milliseconds. The first waiting time for slave device F with a historical address value of 6 is 10 milliseconds. And so on, the first waiting time for a device with a historical address value of n is (n-1) × 2 milliseconds. As shown in Table 1: Table 1:
[0091] By employing the above method, each slave device can determine a different first waiting time based on its own historical address value. This allows devices with smaller historical address values to send addressing messages earlier, while devices with larger historical address values send them later. Consequently, when the host goes offline or re-enters the addressing process, multiple slave devices can participate in addressing sequentially according to their historical address order, thereby reducing the probability of multiple slave devices sending addressing messages simultaneously and improving the orderliness of the automatic addressing process.
[0092] In one possible implementation, after the first device sends the second addressing message, the first device determines a fourth waiting time, which is greater than the third type of waiting time.
[0093] In one possible implementation, the fourth waiting time satisfies: TD = TA + N × TI + TI, where TA = TC + N × TI + TI, TC = TR + TI, TR = R × TI, R is a positive integer, N represents the total number of devices supported for access, TI represents the time from when the addressing message is sent to when it is received, and TD represents the fourth waiting time, which is greater than the third type of waiting time.
[0094] It should be noted that TD can be a preset constant, and TD is greater than the third type of waiting time Ta. In order for TD to be greater than the third type of waiting time corresponding to any device, TD can be determined according to the total number of devices N that the system supports for access.
[0095] After the first device sends the second addressing message, it can determine a fourth waiting time. This fourth waiting time can be understood as the waiting time determined by the first device after sending the addressing message. By setting the fourth waiting time, devices that have already sent addressing messages can postpone their participation in the addressing process for a period of time, avoiding the device from immediately sending an addressing message again after completing the address declaration, thereby reducing interference with the addressing process of subsequent devices.
[0096] The fourth waiting time can be denoted as TD. The fourth waiting time TD can be greater than the third type of waiting time Ta, that is: TD > Ta. The third type of waiting time Ta can be determined based on the third type of baseline waiting time TA, the historical address value n, and TI.
[0097] For example, the third type of waiting time Ta can satisfy: Ta = TA + n × TI, where n can represent the historical address value of the first device, or the order value of the historical address value in the address sequence.
[0098] The third type of baseline waiting time TA can be determined based on the second type of baseline waiting time TC, the total number of devices N, and TI, for example: TA = TC + N × TI + TI. Here, N can represent the total number of devices supported by the communication system or the maximum number of devices. The second type of baseline waiting time TC can be determined based on the random waiting limit TR and TI, for example: TC = TR + TI. TR represents the upper limit of the first type of waiting time, and TR can be determined based on TI, for example: TR = R × TI, where R is a positive integer, and TI represents the time required for an addressed message to be sent and received by other devices in the shared communication medium. For example, when the addressed message is a single-byte message, TI can represent the time required for one byte to be sent and received by other devices in the shared communication medium.
[0099] Based on the above relationships, the third type of waiting time Ta can be derived and combined. Since TR = R × TI, therefore: TC = TR + TI = R × TI + TI = (R + 1) × TI. Since TA = TC + N × TI + TI, substituting TC = (R + 1) × TI, we get: TA = (R + 1) × TI + N × TI + TI. Further combining, we get: TA = (R + N + 2) × TI. Substituting TA = (R + N + 2) × TI into Ta = TA + n × TI, we get: Ta = (R + N + 2) × TI + n × TI. Further combining, we get: Ta = (R + N + n + 2) × TI. Therefore, the third type of waiting time Ta satisfies: Ta = (R + N + n + 2) × TI.
[0100] Therefore, the fourth waiting time TD can satisfy: TD = TA + N × TI + TI, where TA = TC + N × TI + TI, TC = TR + TI, TR = R × TI, R is a positive integer, N represents the total number of supported access devices, TI represents the time from sending to receiving the addressing message, and TD represents the fourth waiting time, which is greater than the third type of waiting time. Therefore, the fourth waiting time TD is greater than the third type of waiting time Ta.
[0101] For example, if the first device has already sent a second addressing message carrying its own address value, the first device can determine its corresponding waiting time as a fourth waiting time TD. Since the fourth waiting time TD is greater than the third waiting time Ta, the first device will not immediately participate in the competition for subsequent address values after sending the second addressing message, but will re-participate in the addressing process after a longer waiting time.
[0102] This allows devices that have already completed their current address declaration to proactively avoid subsequent addressing processes, ensuring that other devices that have not yet completed addressing can continue to send addressing messages in address order, thereby improving the orderliness and stability of the automatic addressing process.
[0103] In one possible implementation, when the second address value is determined based on the address value in the most recently received addressing message of the first device and a preset step size, and the first device receives the first addressing message before the end of the first waiting time, the first device determines a second waiting time based on the first addressing message, which includes the first address value of the second device. Then, if the first device does not receive any addressing message from other devices before the end of the second waiting time, the first device sends a second addressing message, which includes the second address value of the first device, determined based on the first address value and the preset step size.
[0104] It should be noted that, in this embodiment of the application, the first addressing message can be an addressing message received by the first device during the current addressing process, used to trigger the determination of the second waiting time. The first address value can be the address value carried in the first addressing message. Therefore, after the first device determines the second waiting time, if the first device does not receive any addressing message sent by other devices before the end of the second waiting time, the first addressing message can be regarded as the most recently received addressing message by the first device, and the first address value can be understood as the address value in the most recently received addressing message by the first device.
[0105] In the embodiments of this application, the terms "first" and "second" are used only to distinguish different objects and are not used to limit the number, order, or fixed correspondence of objects. In different execution processes or different addressing cycles, the addressing message used to trigger the first device to determine the second waiting time can be called the first addressing message, and the address value carried by the addressing message can be called the first address value.
[0106] like Figure 1 As shown, if the first device is any of slave devices B, C, or D, and receives the first addressing message before the first waiting time ends, the first device determines the second waiting time based on the first addressing message, which includes the address values of other slave devices. If the first device does not receive an addressing message from another device before the second waiting time ends, the first device sends a second addressing message, which includes the second address value of the first device. In this case, the first device is not the starting device in this round of addressing, but participates in addressing as a device continuing the addressing process. The second device is any other slave device that sent an addressing message before the first device.
[0107] For example, taking slave device B as the first device and slave device A as the second device, slave device B can listen for addressing messages sent by other slave devices on the shared communication medium 110 during a first waiting period. If slave device B receives a first addressing message sent by slave device A before the end of the first waiting period, it indicates that slave device A has sent an addressing message before slave device B. The first addressing message may include a first address value of slave device A, which may represent an address value that slave device A has declared or occupied.
[0108] If the first address value carried in the first addressing message is 1, it indicates that slave device A has declared or occupied address value 1. After receiving the first addressing message, slave device B can determine that the current addressing process has progressed to address value 1 based on the first address value, and then re-determine the second waiting time based on the first addressing message. By re-determining the second waiting time, slave device B can prevent itself from continuing to send addressing messages according to the original first waiting time, thereby avoiding address order disorder or sending timing conflicts caused by multiple devices sending addressing messages based on expired waiting times.
[0109] If the most recently received valid addressing message by slave device B is the first addressing message sent by slave device A, and the address value carried by the first addressing message is 1 with a preset step size of 1, then slave device B can determine the second address value as 2 based on the address value 1 and the preset step size. If slave device B does not receive any addressing message sent by other devices before the end of the second waiting time, then slave device B can determine the second address value as its own address value and send the second addressing message through the shared communication medium 110. This second addressing message includes the second address value of slave device B. That is, slave device A first sends the first addressing message carrying the address value 1, and slave device B, after receiving the first addressing message, re-determines the second waiting time. Before the end of the second waiting time, if slave device B does not receive any new addressing message sent by other devices, then slave device B determines the address value 2 as its own address value and sends the second addressing message carrying the address value 2. After receiving the second addressing message sent by slave device B, slave devices C, D, and other slave devices can continue to determine subsequent address values, such as address value 3, based on the address value 2 carried in the second addressing message, so that multiple slave devices can complete the addressing in the order of addresses.
[0110] In one possible implementation, when the second address value is determined based on the address value in the addressing message recently received by the first device and a preset step size, the first waiting time can be a waiting time (i.e., the second waiting time) that is re-determined based on the address value carried in the recently received addressing message.
[0111] In one possible implementation, the first device determines the next sequential address value based on the first address value and a preset step size. The first device then determines a second waiting time based on its historical address values and either the next sequential address value or the first address value.
[0112] In one possible implementation, if the historical address value is equal to the next sequential address value, the first device determines the first type of waiting time as the second waiting time; if the historical address value is greater than the next sequential address value, the first device determines the second type of waiting time as the second waiting time; if the historical address value is less than the first address value, the first device determines the third type of waiting time as the second waiting time; wherein the first type of waiting time is less than the second type of waiting time, and the second type of waiting time is less than or equal to the third type of waiting time.
[0113] It should be noted that the first type of waiting time, the second type of waiting time, and the third type of waiting time can be determined based on TI and preset constants.
[0114] In one possible implementation, the first type of waiting time satisfies: 0 ≤ Tr ≤ TR, where Tr represents the first type of waiting time and TR represents the upper limit of the first type of waiting time. It should be noted that TR is the upper limit or maximum value of the random waiting time (i.e., Tr), which can be determined based on TI, for example: TR = R × TI. In one possible implementation, R can be 4, i.e., TR = 4 × TI. Therefore, the first type of waiting time Tr can satisfy: 0 ≤ Tr ≤ R × TI.
[0115] By setting the first type of waiting time Tr to a random waiting time, devices whose historical address value is equal to the next sequential address value can randomly send addressing messages within a short period of time, thereby reducing the probability of multiple slave devices sending addressing messages at the same time.
[0116] In one possible implementation, the second type of latency satisfies: Tc = n×TI+TC, where Tc represents the second type of latency. It should be noted that the second type of latency Tc can be determined based on the second type of baseline latency TC, the historical address value n, and TI.
[0117] For example, the second type of waiting time Tc can satisfy: Tc = TC + n × TI, where n can represent the historical address value of the first device, or the order of that historical address value in the address sequence. The second type of baseline waiting time TC can be determined based on the upper limit of the random waiting time TR and TI, for example: TC = TR + TI. Since TR = R × TI, we can obtain: TC = R × TI + TI = (R + 1) × TI. Substituting TC = (R + 1) × TI into Tc = TC + n × TI, we can obtain: Tc = (R + 1) × TI + n × TI. After further merging, we can obtain: Tc = (R + n + 1) × TI. That is, the second type of waiting time Tc can satisfy: Tc = (R + n + 1) × TI. When n is a positive integer, Tc is greater than Tr.
[0118] Therefore, after a slave device using the first type of waiting time sends an addressing message, the addressing message can be received by other slave devices before the slave device using the second type of waiting time times out, thus enabling the slave device whose historical address value is equal to the next sequential address value to send the addressing message first.
[0119] In one possible implementation, the third type of waiting time satisfies: Ta = n×TI+TA, where TA=TC+N×TI+TI, N represents the total number of devices supporting access (or the total number of devices supporting access to the shared communication medium), Ta represents the third type of waiting time, and TI represents the time from when the address message is sent to when it is received.
[0120] It should be noted that the third type of waiting time Ta can be determined based on the third type of baseline waiting time TA, the historical address value n, and TI. For example, the third type of waiting time Ta can satisfy: Ta = n × TI + TA. The third type of baseline waiting time TA can be determined based on the second type of baseline waiting time TC, the total number of devices N, and TI, for example: TA = TC + N × TI + TI, where TC = TR + TI, TR = R × TI, R is a positive integer, n represents the historical address value, and TI represents the time from sending to receiving the addressing message. When N and n are positive integers, Ta is greater than Tc.
[0121] Therefore, it can be ensured that the third type of waiting time is not less than the second type of waiting time, so that slave devices with historical address values less than the currently received first address value can further delay their participation in the addressing process, reducing their interference with the subsequent address order recursion process.
[0122] For example, such as Figure 1 As shown, slave devices A, B, C, D, E, F, and G are all connected to the shared communication medium 110, and their historical address values are 1, 2, 3, 4, 5, 6, and 7, respectively.
[0123] If the first address value carried in the first addressing message received by the first device is 4, and the preset step size is 1, then the next sequential address value is 5. In this case, the second waiting time corresponding to each device can be obtained according to the above rules, as shown in Table 2.
[0124] Table 2:
[0125] As shown in Table 2 above, when the first address value is 4 and the preset step size is 1, the next sequential address value is 5. The historical address value of slave device E is 5, which is equal to the next sequential address value. Therefore, slave device E can determine the second waiting time as the first type of waiting time so that device E can send the addressing message carrying the address value 5 first.
[0126] The historical address values of slave devices F and G are 6 and 7 respectively, both greater than the next sequential address value 5. This indicates that slave devices F and G are located after slave device E in the historical address sequence and should not send the addressing message carrying address value 5 before slave device E. Therefore, slave devices F and G can define the second waiting time as the second type of waiting time to postpone their participation in the addressing process corresponding to the current next sequential address value.
[0127] The historical address values of slave devices A, B, and C are 1, 2, and 3, respectively, all less than the first address value 4. This indicates that slave devices A, B, and C are located before the currently received address value in the historical address sequence and should not participate in the transmission contention corresponding to the next sequential address value. Therefore, slave devices A, B, and C can determine the second waiting time as the third type of waiting time to further avoid the current addressing process.
[0128] For slave device D, its historical address value is equal to the first address value 4. In one possible implementation, slave device D can be a device that has already sent an addressing message carrying address value 4, in which case slave device D can enter the post-transmission wait process. In another possible implementation, if slave device D receives an addressing message from another device that also carries address value 4, it can trigger the address conflict judgment process. Therefore, the case where the historical address value is equal to the first address value does not fall under the aforementioned first, second, or third type of waiting time, but can be handled through the post-transmission wait or conflict handling process.
[0129] Using the above method, slave devices with historical address values equal to the next sequential address value use a first-type waiting time to prioritize transmission. Slave devices with historical address values greater than the next sequential address value use a second-type waiting time to delay transmission. Slave devices with historical address values less than the first address value use a third-type waiting time to further avoid transmission. This allows multiple slave devices to participate in addressing sequentially according to their address order, improving the orderliness of the automatic addressing process.
[0130] Please see Figure 3 , Figure 3 This is a flowchart illustrating a complete addressing method provided in an embodiment of this application.
[0131] In one possible implementation, when the first address value can be an initial address value, and the second address value can be determined based on the address value in the most recently received addressing message from the first device and a preset step size, such as... Figure 3 As shown, slave devices A, B, C, D, E, F, and G are all connected to the shared communication medium and automatically addressed according to the addressing method provided in this embodiment. Device A can serve as the initial device in this round of addressing, while slave devices B, C, D, E, F, and G can participate sequentially in subsequent addressing processes as devices for subsequent addressing.
[0132] Figure 3 The diagram illustrates the timing process of automatic addressing performed by slave devices A, B, C, D, E, F, and G based on addressing messages and waiting time rules, with a preset step size of 1. Slave device A corresponds to n=1, slave device B to n=2, slave device C to n=3, slave device D to n=4, slave device E to n=5, slave device F to n=6, and slave device G to n=7. n represents the historical address value corresponding to each slave device. This historical address value can be the address value determined by the first device in the previous addressing process, or the address value stored by the first device after the previous network addressing was completed. For a description of this historical address value, please refer to the description in the previous embodiment.
[0133] In the diagram, "T1" represents the first waiting time, "Tr" represents the first type of waiting time, "Tc" represents the second type of waiting time, "Ta" represents the third type of waiting time, and "TD" represents the waiting time after transmission (i.e., the fourth waiting time). The numbers "1", "2", "3", "4", etc., on the arrows in the diagram represent the address values carried by the corresponding addressing messages.
[0134] For example, with a preset step size of 1, the first time interval TI can be 1ms, and the basic waiting interval TS can be 2×TI, i.e., TS=2ms. Each slave device can determine the first waiting time T1 based on the historical address value n, and the first waiting time T1 can satisfy: T1=(n-1)×TS. Therefore: If n=1 for slave device A, then T1=(1-1)×2ms=0ms; If n=2 for slave device B, then T1=(2-1)×2ms=2ms; If n=3 for slave device C, then T1=(3-1)×2ms=4ms; If n=4 for slave device D, then T1=(4-1)×2ms=6ms; If n=5 for slave device E, then T1=(5-1)×2ms=8ms; If n=6 for slave device F, then T1=(6-1)×2ms=10ms; If n=7 for slave device G, then T1=(7-1)×2ms=12ms.
[0135] therefore, Figure 3 The values "T1=0ms", "T1=2ms", "T1=4ms", "T1=6ms", "T1=8ms", "T1=10ms" and "T1=12ms" are displayed respectively.
[0136] At the start of the "first round of addressing", slave device A meets the transmission condition first because its first waiting time T1 = 0ms. If slave device A does not receive an addressing message from another slave device before its first waiting time ends, it sets its initial address value to its own address value. Since the preset step size is 1 and the initial address value is 1, slave device A sets its own address value to "address value = 1" and sends an addressing message carrying the address value 1. Figure 3 In the diagram, multiple arrows sent by slave device A to slave devices B, C, D, E, F, and G are all marked with "1", indicating that the addressing message sent by slave device A carries the address value 1, and that the addressing message can be received by other slave devices.
[0137] After receiving the addressing message carrying address value 1 from slave device A, other slave devices determine the next sequential address value to be 2 based on the received address value 1 and the preset step size 1. For slave device B, its historical address value n=2, which is equal to the next sequential address value 2. Therefore, slave device B determines the second waiting time as the first type of waiting time Tr. Figure 3 In the example, slave device B is marked as "Tr=1ms", which means that after receiving the addressing message carrying the address value 1, slave device B re-determines the waiting time as the first type of waiting time Tr, and in this example, Tr=1ms.
[0138] For slave devices C, D, E, F, and G, their historical address values are 3, 4, 5, 6, and 7 respectively, all greater than the next sequential address value of 2. Therefore, these slave devices determine the second waiting time as the second type of waiting time Tc. The second type of waiting time Tc can satisfy: Tc = TC + n × TI. If TC = 5ms and TI = 1ms, then: The slave device C has a Tc of 5ms + 3 × 1ms = 8ms, which corresponds to "Tc = 8ms" in the figure. The slave device D has a Tc of 5ms + 4 × 1ms = 9ms, which corresponds to "Tc = 9ms" in the figure. For slave device E, Tc = 5ms + 5 × 1ms = 10ms, corresponding to "Tc = 10ms" in the figure; The slave device F has a Tc of 5ms + 6 × 1ms = 11ms, which corresponds to "Tc = 11ms" in the figure. The slave device G has a Tc of 5ms + 7 × 1ms = 12ms, which corresponds to "Tc = 12ms" in the figure.
[0139] Since the slave device B, whose Tr=1ms arrives first, sends an addressing message carrying address value 2. Figure 3 In the diagram, the arrow marked with "2" sent by slave device B to other slave devices indicates that the addressing message sent by slave device B carries the address value 2. Simultaneously, slave device B sets its own address value to "address value = 2". After slave device A sends the addressing message carrying the address value 1, it enters the post-transmission waiting time TD. Figure 3 The corresponding annotation is "TD=21ms", indicating that slave device A enters a longer waiting period after sending the message to avoid immediately participating in subsequent address contention.
[0140] After slave device B sends an addressing message carrying address value 2, other slave devices receive the addressing message and determine the next sequential address value as 3 based on address value 2 and a preset step size of 1. For slave device C, its historical address value n=3, which is equal to the next sequential address value 3. Therefore, slave device C determines the second waiting time as the first type of waiting time Tr. Figure 3 The corresponding annotation is "Tr=1ms". For slave devices D, E, F, and G, their historical address values are 4, 5, 6, and 7 respectively, all greater than the next sequential address value 3. Therefore, they are determined to have a second type of waiting time Tc. Among them, slave device D corresponds to "Tc=9ms", slave device E corresponds to "Tc=10ms", slave device F corresponds to "Tc=11ms", and slave device G corresponds to "Tc=12ms". For slave device A, its historical address value n=1, which is less than the currently received address value 2. Therefore, slave device A determines its waiting time as a third type of waiting time Ta. The third type of waiting time Ta can satisfy: Ta=TA+n×TI. If TA=13ms and TI=1ms, then slave device A's Ta=13ms+1×1ms=14ms, corresponding to "Ta=14ms" in the figure. After slave device B sends the addressing message carrying address value 2, it enters the post-transmission waiting time TD. Figure 3 The corresponding annotation is "TD=21ms".
[0141] Since the slave device C, whose Tr=1ms arrives first, sends an addressing message carrying address value 3. Figure 3 In the diagram, the arrow sent by slave device C to other slave devices is marked with "3", indicating that the addressing message sent by slave device C carries the address value 3. At the same time, slave device C determines its own address value as "address value = 3".
[0142] After slave device C sends an addressing message carrying address value 3, other slave devices receive the addressing message and determine the next sequential address value as 4 based on address value 3 and a preset step size of 1. For slave device D, its historical address value n=4, which is equal to the next sequential address value 4. Therefore, slave device D determines the second waiting time as the first type of waiting time Tr. Figure 3 The corresponding annotation is "Tr=1ms". For slave devices E, F, and G, their historical address values are 5, 6, and 7 respectively, all greater than the next sequential address value 4. Therefore, they are assigned a second type of waiting time Tc. Specifically, slave device E corresponds to "Tc=10ms", slave device F corresponds to "Tc=11ms", and slave device G corresponds to "Tc=12ms". For slave devices A and B, their historical address values are 1 and 2 respectively, both less than the currently received address value 3. Therefore, slave devices A and B are assigned a third type of waiting time Ta. Specifically, slave device A's Ta = 13ms + 1 × 1ms = 14ms, corresponding to "Ta=14ms" in the diagram; slave device B's Ta = 13ms + 2 × 1ms = 15ms, corresponding to "Ta=15ms" in the diagram. After slave device C sends the addressing message carrying address value 3, it enters the post-transmission waiting time TD. Figure 3 The corresponding annotation is "TD=21ms".
[0143] Since the slave device D, whose Tr=1ms arrives first, sends an addressing message carrying address value 4. Figure 3 In the diagram, the arrow sent by slave device D to other slave devices is marked with "4", indicating that the addressing message sent by slave device D carries the address value 4. At the same time, slave device D determines its own address value as "address value = 4".
[0144] The subsequent process can continue to be executed according to the same rules. Figure 3 The text box in Chinese indicates that "Slave device E sends address value 5, slave device F sends address value 6, and slave device G sends address value 7". Specifically: After receiving the addressing message carrying the address value 4, slave device E sends an addressing message carrying the address value 5 after the first type of waiting time Tr arrives, since its historical address value n=5 is equal to the next sequential address value 5, and determines its own address value as "address value=5".
[0145] After receiving the addressing message carrying the address value 5, slave device F, since its historical address value n=6 is equal to the next sequential address value 6, sends the addressing message carrying the address value 6 after the first type of waiting time Tr arrives, and determines its own address value as "address value=6".
[0146] After receiving the addressing message carrying the address value 6, slave device G sends the addressing message carrying the address value 7 after the first type of waiting time Tr arrives, since its historical address value n=7 is equal to the next sequential address value 7, and determines its own address value as "address value=7".
[0147] Thus, after the first round of addressing is completed, slave devices A, B, C, D, E, F, and G will respectively form "address value=1", "address value=2", "address value=3", "address value=4", "address value=5", "address value=6", and "address value=7". Figure 3 The corresponding addresses below each slave device are also displayed: "Address value=1", "Address value=2", "Address value=3", "Address value=4", "Address value=5", "Address value=6", and "Address value=7".
[0148] In the "second round of addressing", each slave device can continue to determine the first waiting time T1 based on its own address value or historical address value. Figure 3 The code again shows that slave device A corresponds to "T1=0ms", slave device B corresponds to "T1=2ms", slave device C corresponds to "T1=4ms", slave device D corresponds to "T1=6ms", slave device E corresponds to "T1=8ms", slave device F corresponds to "T1=10ms", and slave device G corresponds to "T1=12ms". Since slave device A's T1=0ms arrived first, slave device A can resend the addressing message carrying the address value 1. Figure 3 The diagram shows multiple arrows marked "1". Subsequently, each slave device can "repeat the first round of addressing process..." and continue to enter the next round of addressing loop by receiving addressing messages, resetting the waiting time, and sending the next address value addressing message.
[0149] pass Figure 3As shown in the process, with a preset step size of 1, slave device A, as the starting device, first sends an addressing message carrying an address value of 1. Slave devices B, C, D, E, F, and G then sequentially determine their own waiting time based on the received addressing messages, and send an addressing message carrying the next address value when their respective waiting time arrives first. Therefore, in scenarios where the host is offline or needs re-addressing, multiple slave devices can automatically complete the addressing process according to address order.
[0150] See Figure 4 , Figure 4 This is a timing diagram illustrating a complete addressing method provided in an embodiment of this application. For example... Figure 4 As shown, Figure 4 This illustrates the process of automatic addressing of multiple devices based on addressing messages and delay rules in a host-offline scenario. Figure 4 The solid diagonal arrows with numbers indicate that the device is sending an addressing message; the numbers on the arrows represent the address value carried in the addressing message. The horizontal arrows labeled Tr, Tc, Ta, and TD indicate the waiting time determined by the corresponding device: Tr for Type I waiting time, Tc for Type II waiting time, Ta for Type III waiting time, and TD for Type IV waiting time. Solid dots indicate the time or node at which the device sends the addressing message. Gray dots indicate that the corresponding device receives the addressing message at the corresponding time or is at the corresponding time node. The horizontal axis represents time, and the vertical axis represents the device address or historical address sequence value.
[0151] exist Figure 4 As shown in the process, after the host goes offline, each device enters the addressing process. The device with address value 1 first sends an addressing message carrying address value 1, as shown by the diagonal solid arrow "1" in the diagram. After receiving this addressing message, other devices re-determine their waiting time based on address value 1 and their own historical address values. Among them, the waiting time for the device with historical address value 2 is reached first, so this device sends an addressing message carrying address value 2, as shown by the diagonal solid arrow "2" in the diagram.
[0152] Similarly, after receiving the addressing message carrying address value 2, other devices recalculate their waiting time based on the address value carried in the addressing message and their own historical address values. The device whose waiting time expires first continues to send an addressing message carrying the next address value. Thus, Figure 4 The diagonal solid arrows in the diagram represent the addressing messages corresponding to address values 1, 2, 3, ..., n being sent sequentially, thus enabling each device to complete automatic addressing according to the address order.
[0153] Figure 4The horizontal dashed arrows indicate the different waiting times determined by each device after receiving the addressing message. For example, a device corresponding to the next sequential address value can use a shorter first-type waiting time Tr to prioritize sending the next addressing message; a device whose historical address value is after the next sequential address value can use a second-type waiting time Tc to delay sending; and a device whose historical address value is before the currently received address value can use a third-type waiting time Ta to further avoid conflict. After sending the addressing message, a device can also enter a fourth-type waiting time TD to avoid immediately participating in subsequent address contention.
[0154] therefore, Figure 4 The essence lies in this: each diagonal solid arrow represents the transmission of an addressing message. After this addressing message is received by other devices, it triggers the other devices to recalculate the waiting time. The device whose waiting time arrives first continues to send the addressing message for the next address value. Through this recursive process of "receiving an addressing message - recalculating the waiting time - the first to arrive sends the next addressing message", automatic and orderly addressing of multiple devices can be achieved when the host is offline.
[0155] In one possible implementation, during the entire addressing process, an addressing conflict may occur when the first device receives an addressing message from another device within a first time after the transmission time of the second addressing message, or when the first device receives a third addressing message and the address value carried by the third addressing message is the same as the second address value of the first device. When an addressing conflict occurs, the first device determines a third waiting time, which is less than a third type of waiting time.
[0156] In one possible implementation, the third waiting time satisfies: Tx = TC + Te, where TC = TR + TI, TR = R × TI, R is a positive integer, TI represents the time from when the addressed message is sent to when it is received, and Te represents the time when the addressed message sent by another device is received within the first time after the sending time. In other words, Te can represent the time interval between when the first device sends the addressed message and when it receives the conflict message.
[0157] When multiple devices are connected in parallel to a shared communication medium, it is possible for two or more devices to send addressing messages at the same time or close to the same time, or for multiple devices to send addressing messages carrying the same address value. When the first device detects the above situation, it can determine that an addressing conflict has occurred.
[0158] When the first device determines that an addressing conflict has occurred, it can recalculate the conflict waiting time Tx and rejoin the addressing process after the conflict waiting time Tx has expired. Tx can be determined based on the second-type baseline waiting time TC and the conflict detection time Te.
[0159] For example, Tx = TC + Te. Since TC = TR + TI and TR = R × TI, TC = (R + 1) × TI. Substituting TC = (R + 1) × TI into Tx = TC + Te, we get Tx = (R + 1) × TI + Te.
[0160] In one possible implementation, if the first device receives a conflict message within TI after sending the addressing message, then Te ≤ TI. Therefore, Tx ≤ (R+2)×TI. On the other hand, the third type of waiting time Ta is determined based on TA, and TA = TC + N×TI + TI, making Ta greater than Tx. Thus, the conflicting device can re-participate in the addressing process at a time less than the third type of waiting time, avoiding continuing to occupy the original conflicting address and allowing it to be arranged in the subsequent address positions.
[0161] See Figure 5 , Figure 5 This is a timing diagram of an addressing conflict provided in an embodiment of this application.
[0162] like Figure 5 As shown, Figure 5 The process of handling address message conflicts when multiple devices are connected in parallel to a shared communication medium is shown. Figure 5 The horizontal axis represents time, and the vertical axis represents the device address or the device's historical address sequence value. Solid dots indicate the time or node when the device sends an addressing message, while gray dots indicate when the corresponding device receives the addressing message at that time or is at that time node. Diagonal solid arrows indicate that the device sends an addressing message, and the number on the diagonal solid arrow represents the address value carried in that addressing message. Horizontal dashed arrows indicate the waiting time determined by the device after receiving the addressing message. Horizontal solid arrows indicate the earliest waiting time among multiple waiting times.
[0163] exist Figure 5 In the process illustrated, when multiple devices are connected in parallel to a shared communication medium, it is possible for two devices to send addressing messages at the same or near the same time. For example, two devices may send addressing messages carrying the same address value simultaneously or nearly simultaneously, or one device may send an addressing message shortly after another device sends one. In this case, the device sending the addressing message can receive the addressing message sent by the other device within the first moment after sending it, or receive an addressing message carrying the same address value, thus determining that a transmission conflict or address conflict has occurred.
[0164] After a conflict is determined, the device that has a conflict can re-determine the conflict waiting time Tx. Exemplarily, Tx can satisfy: Tx = TC + Te, where TC is a preset reference waiting time, and Te is the time interval between the device sending an addressing message and receiving a conflict message. That is to say, Te can be used to represent the time difference between two conflicting addressing messages. By introducing Te into the conflict waiting time Tx, the device that has a conflict can re-adjust the subsequent sending opportunity according to the actual conflict occurrence time.
[0165] As Figure 5 shown, the conflict waiting time Tx is less than the third type of waiting time Ta, that is: Tx < Ta. By setting Tx < Ta, the device that has a conflict can stop competing for the current address value according to the original sending opportunity, but re-participate in the subsequent addressing process after the conflict waiting time Tx. In this way, the device that has a conflict can avoid the sending opportunity corresponding to the current conflict address and re-send an addressing message at a subsequent address position. For example, Figure 5 the diagonal solid arrow located after the end of the conflict waiting time Tx and marked with the address value n + 1 beside the arrow can indicate that the device after the conflict re-participates in the addressing and sends a new addressing message, so that the address corresponding to the device with a conflict is adjusted to a subsequent address position. For example, the new addressing message carries the address value n + 1.
[0166] Therefore, Figure 5 the essence is that when multiple devices in a parallel operation scenario send addressing messages at the same or close time and a conflict occurs, the device with a conflict no longer continues to preempt the current address value, but recalculates the conflict waiting time Tx according to the conflict detection time Te and re-participates in the addressing after Tx ends. By this means, the conflicting devices can stagger the sending opportunities and adjust the conflicting addresses to the subsequent address sequence, thereby reducing the probability of repeated conflicts and improving the stability and orderliness of the parallel operation automatic addressing process.
[0167] See Figure 6 , Figure 6 is a timing schematic diagram of an addressing method after a slave device goes offline provided by an embodiment of the present application. As Figure 6 shown, Figure 6 shows the process of the device realizing automatic address rearrangement based on the addressing message and the delay rule in the case where some devices do not participate in the addressing or some addresses are vacant. Figure 6The horizontal axis represents time, and the vertical axis represents the device's historical address values or address order. Solid dots indicate the time or node when a device sends an addressing message, while gray dots indicate when the corresponding device receives the addressing message or is at the corresponding time node. Diagonal solid arrows indicate when a device sends an addressing message, and the number on the arrow indicates the address value carried in that message. Horizontal dashed arrows indicate the waiting time determined by the device after receiving the addressing message. Horizontal solid arrows indicate the earliest waiting time among multiple waiting times.
[0168] exist Figure 6 In the process shown, the device sequentially receives addressing messages sent by the preceding device and re-determines the waiting time based on the received address values. When the device receives an addressing message carrying address value 3, it can determine the next sequential address value based on address value 3 and a preset step size. For example, when the preset step size is 1, the next sequential address value is 4.
[0169] If the device originally corresponding to address value 4 is not participating in the current addressing process, or if address value 4 is vacant, no device will send an addressing message carrying address value 4 within the corresponding waiting time. In this case, the device with historical address value 6, upon receiving an addressing message carrying address value 3, can re-determine its waiting time according to a preset delay rule. If, before the end of this waiting time, the device with historical address value 6 has not received an addressing message carrying address value 4 from another device, then the device with historical address value 6 can update its own address value to address value 4 and send an addressing message carrying address value 4. Figure 6 The diagonal solid arrow "4" in the image represents the addressing message sent by device 6 after it changed its local address to 4.
[0170] Figure 6 The following example illustrates the situation where the device corresponding to address value 1 (1 offline) and the device corresponding to address value 4 (4 offline) are both offline. Figure 6 The address values 1, 2, 3, and n-2 can represent the address result of the remaining devices after readdressing, that is, devices located after offline devices can be filled in forward according to the address order.
[0171] Therefore, Figure 6 The essence of this is that when there is a missing address in the address sequence, the device following that missing address can automatically move forward after the waiting time ends, update its own address to the next missing address value, and send the corresponding addressing message. Subsequent devices, upon receiving this addressing message, can continue to determine the waiting time and update their address values according to the same rules, thus making the address sequence more compact.
[0172] pass Figure 6The process shown demonstrates that in scenarios where the host is offline, some devices are removed, or multiple networks are reconnected, there is no need for manual address reconfiguration. The remaining devices can automatically rearrange their addresses based on the addressing messages on the shared communication medium, keeping the preceding addresses stable and filling in the gaps with subsequent addresses in sequence, thereby improving address resource utilization and network stability.
[0173] In one possible implementation, if the first device detects a communication message sent by the host and determines that at least one round of addressing process has been completed, the first device stops addressing.
[0174] In one possible implementation, if the first device receives an addressing message carrying the initial address value again, the first device determines that it has completed at least one round of addressing process.
[0175] The first device can determine whether to stop addressing based on the host's communication status and the completion status of the addressing process. Specifically, if the first device detects a communication message sent by the host and determines that at least one round of addressing has been completed, the first device can stop sending addressing messages and enter normal communication mode. This avoids the first device continuing to send addressing messages after the host has already participated in communication, thereby reducing interference from addressing messages on the host's normal communication process.
[0176] The communication messages sent by the host can be normal communication messages sent by the host based on the device address, such as request messages, control messages, or query messages sent by the host to the target device. When the first device detects a communication message sent by the host, it can assume that the host is online or has started participating in communication. However, to avoid prematurely exiting the addressing process before the device has completed address arrangement, the first device also needs to determine whether at least one round of the addressing process has been completed.
[0177] In one possible implementation, the first device can determine whether at least one round of addressing has been completed by detecting whether the addressing message carrying the initial address value reappears. Specifically, in one round of addressing, the initial device can first send an addressing message carrying the initial address value, and subsequent devices can sequentially determine subsequent address values based on the received addressing messages and send corresponding addressing messages. After all devices have completed sending the addressing messages in address order, the addressing message carrying the initial address value can reappear to indicate the start of a new addressing cycle. Therefore, if the first device receives the addressing message carrying the initial address value again, the first device can determine that at least one round of addressing has been completed.
[0178] For example, the initial address value can be 1. Device A first sends an addressing message carrying address value 1. After receiving this addressing message, device B sends an addressing message carrying address value 2. After receiving the addressing message sent by device B, device C sends an addressing message carrying address value 3, and so on for subsequent devices. When one round of addressing is completed, if the first device receives an addressing message carrying address value 1 again, it indicates that the previous round of address value recursion has been completed, and it enters the next round of addressing loop. At this time, if the first device also detects communication messages sent by the host, the first device can stop sending addressing messages and enter normal communication state.
[0179] In this way, the first device can exit the addressing process after the host is online and at least one round of addressing process has been completed. This ensures that each device has completed the necessary address allocation and avoids addressing messages from continuously occupying the shared communication medium, thereby improving the coordination and stability between the automatic addressing process and the normal communication process of the host.
[0180] In one possible implementation, each slave device in the communication system can switch between an addressing state and a normal communication state based on the host's communication status. When a slave device does not detect a normal communication message sent by the host, it can be determined that the host is offline or not participating in communication, and the slave device enters the addressing state. A slave device in the addressing state can determine its waiting time according to preset timing rules, and if it does not receive an addressing message from another device before the corresponding waiting time expires, it sends an addressing message carrying its own address value to participate in the automatic addressing process.
[0181] When a slave device detects a normal communication message sent by the host and determines that at least one round of addressing has been completed, the slave device can exit the addressing state, stop sending addressing messages, and enter the normal communication state. In the normal communication state, the slave device can determine whether to respond to communication messages sent by the host based on its own address value. This avoids the slave device continuing to send addressing messages during the host's normal communication process, thereby reducing interference from addressing messages to normal communication.
[0182] In another possible implementation, when one or more new devices access the shared communication medium, the slave devices in the communication system can re-enter the addressing state. For example, existing slave devices can, upon receiving an addressing message from a newly accessed device, pause responding to the host's normal communication messages and re-determine their corresponding waiting time to participate in the re-addressing process. After the re-addressing is complete, each slave device stops sending addressing messages and resumes responding to the host's normal communication messages.
[0183] It is understood that in this embodiment, the first device listens to addressing messages on the shared communication medium and receives a first addressing message before the end of a first waiting time. Then, it determines a second waiting time based on the address value carried in the first addressing message. The address carried in the first addressing message is the first address value of the second device. If the first device does not receive an addressing message from another device before the end of the first waiting time, the first device sends a second addressing message to the other device. This second addressing message includes the second address value of the first device. When the first device is the initial first device, the second address value is the initial address value. When the first device is another device besides the first device, the second address value is determined based on the address value in the most recently received addressing message and a preset step size. Therefore, the first device can automatically complete the address determination and address recursion process based on the interaction of addressing messages on the shared communication medium and local waiting time control, achieving automatic addressing without the need for dedicated communication protocols and hardware.
[0184] It is understood that the embodiments of this application can transmit addressing messages on a shared communication medium and combine the waiting time determined by each device itself, so that each device can automatically determine the address value in scenarios such as host online, host offline, device access, device removal or multiple network merging, thereby reducing the hardware cost of the devices and the workload of on-site configuration.
[0185] The addressing method provided in this application enables multiple devices to be addressed sequentially when connected in parallel networking. For example, when multiple devices access the same shared communication medium, each device can sequentially send an addressing message carrying its own address value according to the received addressing message and waiting time rules, so that the address values of each device are arranged in a preset ascending order. This reduces the problem of address duplication or address conflicts caused by manual address configuration.
[0186] When the host is offline, a single device connected to the shared communication medium can automatically restore its address to a preset minimum address value, such as address value 1. When the host is offline and multiple devices are connected to the shared communication medium simultaneously, the multiple devices can automatically complete address allocation through addressing messages and waiting time rules. When multiple networked devices are further connected to the same shared communication medium, each device can also re-participate in the addressing process and automatically form a new address order.
[0187] When a device connects to an existing host bus network, it can participate in the readdressing process along with existing slave devices to obtain the corresponding address value. When multiple devices are first connected in parallel and then connected to an existing host bus network, they can also re-participate in the addressing process within a shared communication medium, thus automatically completing address allocation. This improves the addressing flexibility during hot-swapping, expansion access, and field maintenance.
[0188] When a host is offline and some devices are removed from the network, the remaining devices can re-execute the addressing process. During the re-addressing process, the addresses of preceding devices can remain unchanged, and the addresses of subsequent devices can be arranged compactly forward according to the address order, thereby reducing address gaps and improving address resource utilization.
[0189] When a device is powered on after being connected to an existing host network, or when both the host and the device are powered on simultaneously, each device can automatically enter the addressing process or the normal communication process based on whether it detects host communication messages, receives addressing messages, and its own waiting time. This enables automatic addressing under different power-on sequences, different network states, and different host online states, improving the adaptability and stability of the communication system.
[0190] Through the above methods, the embodiments of this application can realize automatic addressing of multiple devices in a serial bus or similar shared communication medium without relying on manual dialing, preset fixed addresses or additional CAN communication networks, thereby reducing system costs and wiring complexity.
[0191] It is understood that, in order to achieve the functions in the above embodiments, each slave device includes hardware structures and / or software modules corresponding to perform each function. Those skilled in the art should readily recognize that, based on the units and method steps described in conjunction with the embodiments disclosed in this application, this application can be implemented in hardware or a combination of hardware and computer software. Whether a function is executed in hardware or by computer software driving hardware depends on the specific application scenario and design constraints of the technical solution.
[0192] See Figure 7 , Figure 7 This is a schematic diagram of an addressing device provided in an embodiment of this application.
[0193] like Figure 7 As shown, the addressing device 700 includes: The determining unit 710 is configured to determine a second waiting time based on the first addressing message when the first device receives the first addressing message before the first waiting time ends, wherein the first addressing message includes a first address value of the second device. The sending unit 720 is configured to send a second addressing message after the determining unit determines the second waiting time, and if no addressing message is received from other devices before the end of the second waiting time. The second addressing message includes a second address value of the first device, and the second address value is determined based on the first address value and the preset step size. The sending unit 720 is further configured to send a second addressing message when the first device does not receive an addressing message from another device before the first waiting time ends. The second addressing message includes a second address value of the first device, which is an initial address value.
[0194] In one possible implementation, the first address value is the initial address value.
[0195] In one possible implementation, the first address value is the initial address value. The addressing device 700 further includes an acquisition unit 730, which is used to acquire the historical address values of the first device; The determining unit 710 is also used to determine the first waiting time based on the historical address value.
[0196] In one possible implementation, the first waiting time satisfies: T1 = (n-1) × TS; where T1 represents the first waiting time, n represents the historical address value, TS = M × TI, M is a positive integer, and TI represents the time from when the address message is sent to when it is received.
[0197] In one possible implementation, the determining unit 710 is specifically used to determine the next sequential address value based on the first address value and a preset step size; the determining unit 710 is specifically used to determine the second waiting time based on the historical address value of the first device and the next sequential address value or the first address value.
[0198] In one possible implementation, the determining unit 710 is specifically used to determine the first type of waiting time as the second waiting time when the historical address value is equal to the next sequential address value; the determining unit 710 is specifically used to determine the second type of waiting time as the second waiting time when the historical address value is greater than the next sequential address value; the determining unit 710 is specifically used to determine the third type of waiting time as the second waiting time when the historical address value is less than the first address value; wherein the first type of waiting time is less than the second type of waiting time, and the second type of waiting time is less than or equal to the third type of waiting time.
[0199] In one possible implementation, the first type of waiting time satisfies 0 ≤ Tr ≤ TR, where Tr represents the first type of waiting time and TR represents the upper limit of the first type of waiting time; the second type of waiting time satisfies: Tc = n×TI+TC, where Tc represents the second type of waiting time; the third type of waiting time satisfies: Ta =n×TI+TA, where TA=TC+N×TI+TI, N represents the total number of supported access devices, and Ta represents the third type of waiting time; where TC=TR+TI, TR=R×TI, R is a positive integer, n represents the historical address value, and TI represents the time from when the addressing message is sent to when it is received.
[0200] In one possible implementation, the determining unit 710 is further configured to determine a third waiting time when the first device receives an addressing message sent by another device within a first time after the sending time of the second addressing message, or when the first device receives a third addressing message and the address value carried by the third addressing message is the same as the second address value of the first device, wherein the third waiting time is less than the third type of waiting time.
[0201] In one possible implementation, the third waiting time satisfies: Tx = TC + Te, where TC = TR + TI, TR = R × TI, R is a positive integer, TI represents the time from when the addressed message is sent to when it is received, and Te represents the time when the addressed message sent by another device is received within the first time after the sending time.
[0202] In one possible implementation, the determining unit 710 is further configured to determine a fourth waiting time after the first device sends the second addressing message, the fourth waiting time being greater than the third type of waiting time.
[0203] In one possible implementation, the fourth waiting time satisfies: TD = TA + N × TI + TI, where TA = TC + N × TI + TI, TC = TR + TI, TR = R × TI, R is a positive integer, N represents the total number of devices supported for access, TI represents the time from when the addressing message is sent to when it is received, and TD represents the fourth waiting time, which is greater than the third type of waiting time.
[0204] In one possible implementation, the device further includes a status control unit 740 for stopping addressing when the first device detects a communication message sent by the host and determines that at least one round of addressing process has been completed.
[0205] In one possible implementation, the state control unit 740 is further configured to determine that at least one round of addressing process has been completed if the first device receives an addressing message carrying the initial address value again.
[0206] See Figure 8 , Figure 8 This is a schematic diagram of an electronic device provided in an embodiment of this application. The electronic device 800 may include a processor 810, an interface circuit 820, and a memory 830, with the processor 810 and the interface circuit 820 coupled to each other. The interface circuit 820 can be used to access a shared communication medium and receive information from other electronic devices or send information to other electronic devices through the shared communication medium. Exemplarily, the shared communication medium can be a serial bus, a single bus, a multi-point bus, or other communication medium capable of enabling network communication among multiple electronic devices. The interface circuit 820 may include a serial port interface circuit, a bus transceiver circuit, an input / output interface circuit, or other interface circuits capable of data transmission and reception.
[0207] The memory 830 can be used to store instructions executed by the processor 810, data required by the processor 810 to execute instructions, or data generated after the processor 810 executes instructions. For example, the memory 830 can be used to store historical address values, current address values, initial address values, wait times, preset step sizes, random wait times, addressing message handlers, or other data related to automatic addressing. In one possible implementation, the memory 830 can be set independently of the processor 810; in another possible implementation, the memory 830 can be integrated into the processor 810.
[0208] When the electronic device 800 is used to implement the addressing method in any of the aforementioned method embodiments, the processor 810 can be used to perform processing operations such as determining the waiting time, determining the address value, reading the historical address value, generating a random waiting time, judging conflicts, and judging the completion of addressing; the interface circuit 820 can be used to receive addressing messages sent by other electronic devices or communication messages sent by the host through the shared communication medium, and can also be used to send addressing messages carrying its own address value through the shared communication medium.
[0209] For example, processor 810 can be used to determine whether electronic device 800 has received a first addressing message before the first waiting time ends. Processor 810 can also be used to determine a second address value for electronic device 800 and send a second addressing message including the second address value through interface circuit 820 if no addressing message from another device is received before the first waiting time ends. As another example, processor 810 can be used to obtain historical address values of electronic device 800 and determine the first waiting time based on the historical address values.
[0210] In one possible implementation, the electronic device 800 can be a slave device, node device, serial port device, industrial control device, sensing device, data acquisition device, execution device, display device, or other device that needs to distinguish addresses in the shared communication medium and access the shared communication medium. This application does not limit the specific product form of the electronic device 800.
[0211] In another possible implementation, the electronic device 800 can also be implemented as a chip, a chip system, a control circuit, a processing module, an interface module, or a device formed by combining hardware circuitry and software programs. When the electronic device 800 is implemented as a chip or a chip system, the chip or chip system can receive information from a shared communication medium through an external interface circuit and output information to be sent to the external interface circuit to implement the addressing method in any of the aforementioned method embodiments. In this case, the interface circuit 820 can be understood as the chip's input / output interface, or as an external bus transceiver circuit connected to the chip.
[0212] In one possible implementation, processor 810 may include one or more processing units. Processor 810 may be a central processing unit, microcontroller, digital signal processor, application-specific integrated circuit, programmable logic device, system-on-a-chip, or other circuit with data processing capabilities. Processor 810 can execute computer programs or instructions stored in memory 830 to enable electronic device 800 to implement the addressing method in any of the foregoing method embodiments.
[0213] The processor 810, interface circuit 820, and memory 830 in this application embodiment can be implemented by hardware circuits or by a combination of software programs and hardware circuits. This application embodiment does not limit the specific structure, model, or implementation method of the processor 810, interface circuit 820, and memory 830, as long as they enable the electronic device 800 to implement the addressing method in any of the aforementioned method embodiments.
[0214] This application also provides a communication system, which includes a shared communication medium and a plurality of electronic devices connected to the shared communication medium. At least one of the plurality of electronic devices is used to perform the method in any of the foregoing method embodiments.
[0215] In addition, this application also provides a computer program for implementing the operations and / or processes performed by a computer in the method provided in this application.
[0216] This application also provides a computer-readable storage medium storing computer code that, when executed on a computer, causes the computer to perform the operations and / or processes described in the method provided in this application.
[0217] This application also provides a computer program product comprising a computer program or instructions that, when executed on a computer, cause the operations and / or processes performed by the computer in the method provided in this application to be performed.
[0218] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working processes of the systems, devices, and modules described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be described again here.
[0219] In the several embodiments provided in this application, it should be understood that the disclosed systems, apparatuses, and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between apparatuses or units may be electrical, mechanical, or other forms.
[0220] The unit described as a separate component may or may not be physically separate. The component shown as a unit may or may not be a physical unit; that is, it may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0221] In addition, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit.
[0222] If this function is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to existing solutions, or a portion of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, ROM, RAM, magnetic disks, or optical disks.
[0223] The above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.
Claims
1. An addressing method, characterized by, include: If the first device receives the first addressing message before the first waiting time ends, the first device determines the next sequential address value based on the first address value and a preset step size; the first device determines the second waiting time based on the first device's historical address value and the next sequential address value or the first address value, wherein the first addressing message includes the first address value of the second device; After the first device determines the second waiting time, if the first device does not receive an addressing message from another device before the end of the second waiting time, the first device sends a second addressing message. The second addressing message includes the second address value of the first device, and the second address value is determined based on the first address value and the preset step size. If the first device does not receive an addressing message from another device before the first waiting time ends, the first device sends a second addressing message, which includes the second address value of the first device, and the second address value is the initial address value.
2. The method of claim 1, wherein, The first address value is the initial address value.
3. The method according to claim 1 or 2, characterized in that, The first address value is the initial address value, and the method further includes: The first device obtains the historical address value of the first device; The first device determines the first waiting time based on the historical address value.
4. The method according to claim 3, characterized in that, The first waiting time satisfies: T1 = (n-1) × TS; Where T1 represents the first waiting time, n represents the historical address value, TS=M×TI, M is a positive integer, and TI represents the time from when the addressing message is sent to when it is received.
5. The method according to claim 1, characterized in that, The first device determines a second waiting time based on its historical address value and the next sequential address value or the first address value, including: If the historical address value is equal to the next sequential address value, then the first type of waiting time is determined as the second waiting time; If the historical address value is greater than the next sequential address value, then the second type of waiting time is determined as the second waiting time; If the historical address value is less than the first address value, then the third type of waiting time is determined as the second waiting time; Wherein, the first type of waiting time is less than the second type of waiting time, and the second type of waiting time is less than or equal to the third type of waiting time.
6. The method according to claim 5, characterized in that, The first type of waiting time satisfies: 0 ≤ Tr ≤ TR, where Tr represents the first type of waiting time and TR represents the upper limit of the first type of waiting time; The second type of waiting time satisfies: Tc = n×TI+TC, where Tc represents the second type of waiting time; The third type of waiting time satisfies: Ta = n×TI+TA, where TA=TC+N×TI+TI, N represents the total number of devices that support access, and Ta represents the third type of waiting time; Where TC = TR + TI, TR = R × TI, R is a positive integer, n represents the historical address value, and TI represents the time from when the addressing message was sent to when it was received.
7. The method according to any one of claims 1-2 or 5-6, characterized in that, The method further includes: When the first device receives an addressing message sent by another device within a first time after the sending time of the second addressing message, or when the first device receives a third addressing message and the address value carried by the third addressing message is the same as the second address value of the first device, the first device determines a third waiting time, the third waiting time being less than a third type of waiting time.
8. The method according to claim 7, characterized in that, The third waiting time satisfies: Tx = TC + Te, where TC = TR + TI, TR = R × TI, R is a positive integer, TI represents the time from when the addressed message is sent to when it is received, and Te represents the time when the addressed message sent by another device is received within the first time after the sending time.
9. The method according to any one of claims 1-2 or 5-6, characterized in that, After the first device sends the second addressing message, the method further includes: The first device determines a fourth waiting time, which satisfies: TD=TA+N×TI+TI, where TA=TC+N×TI+TI, TC=TR+TI, TR=R×TI, R is a positive integer, N represents the total number of devices that support access, TI represents the time from when the addressing message is sent to when it is received, and TD represents the fourth waiting time, which is greater than the third type of waiting time.
10. The method according to any one of claims 1-2 or 5-6, characterized in that, The method further includes: If the first device detects a communication message sent by the host and determines that at least one round of addressing process has been completed, the first device stops addressing.
11. The method according to claim 10, characterized in that, The determination that at least one round of addressing has been completed includes: If the first device receives an addressing message carrying the initial address value again, the first device determines that at least one round of addressing process has been completed.
12. An addressing device, characterized in that, include: The determining unit is configured to, upon receiving a first addressing message before the end of the first waiting time, determine the next sequential address value based on the first address value and a preset step size; and determine a second waiting time based on the historical address value of the first device and the next sequential address value or the first address value, wherein the first addressing message includes the first address value of the second device. The sending unit is configured to send a second addressing message after the determining unit determines the second waiting time, and when no addressing message is received from other devices before the end of the second waiting time. The second addressing message includes a second address value of the first device, and the second address value is determined based on the first address value and the preset step size. The sending unit is further configured to send a second addressing message if no addressing message is received from another device before the first waiting time ends. The second addressing message includes a second address value of the first device, and the second address value is an initial address value.
13. An electronic device, characterized in that, The device includes a processor and an interface circuit, wherein the interface circuit is used to receive information from other devices via a shared communication medium and transmit it to the processor, or to send information from the processor to other devices via the shared communication medium; the processor enables the electronic device to implement the method as described in any one of claims 1-11 via the interface circuit or by executing code instructions.
14. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program or instructions that, when executed by a computer, cause the computer to perform the method as described in any one of claims 1-11.
15. A computer program product, characterized in that, It includes a computer program or instructions that, when executed by a computer, cause the computer to perform the method as described in any one of claims 1-11.