Master-slave communication method, electronic equipment and storage medium

By using the interaction of host broadcast probe frames and acknowledgment frames, the physical location of slave devices is automatically identified and sorted, solving the configuration complexity problem of the mapping relationship between slave logical addresses and physical locations in RS485 daisy chain systems, and achieving efficient slave hierarchy allocation and sorting.

CN122027466AActive Publication Date: 2026-05-12DELIXI GROUP INSTRUMENT CO LTD
View PDF 5 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
DELIXI GROUP INSTRUMENT CO LTD
Filing Date
2026-04-16
Publication Date
2026-05-12

AI Technical Summary

Technical Problem

In existing technologies, the mapping relationship between the logical address and physical location of the slave device in the RS485 daisy chain system needs to be manually configured, which leads to complex, time-consuming and error-prone construction, especially when there are many slave devices, resulting in low efficiency.

Method used

The host automatically identifies and sorts the physical locations of slave devices through the interaction of broadcast probe frames and acknowledgment frames. It utilizes a preset time window and an incrementing identifier value mechanism to achieve automatic allocation and sorting of slave device levels, reducing manual intervention.

Benefits of technology

It enables automatic identification and hierarchical sorting of the physical location of slave devices in a daisy chain topology, reducing installation difficulty and maintenance costs, and improving installation efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122027466A_ABST
    Figure CN122027466A_ABST
Patent Text Reader

Abstract

The invention provides a master-slave communication method, electronic equipment and a storage medium, and relates to the technical field of communication. In the method, a host broadcasts a first detection frame containing a first identification value and a second identification value, and when a slave determines that a third identification value of the slave is consistent with the first identification value, the slave updates a fourth identification value of the slave to be the second identification value and sends a first response frame to the host. And the host receives a first first response frame as a target response frame in a preset time window, records a mapping relation between the slave address and the fourth identification value according to the target response frame, and sends a confirmation frame to the slave. The slave receiving the acknowledgement frame broadcasts the notification frame, so that the slave receiving the notification frame and not receiving the acknowledgement frame updates the third identification value to a fifth identification value, and the fifth identification value is equal to the sum of the first identification value and 1. And the host updates the first identification value and the second identification value plus 1 and repeats the steps until no response exists. Therefore, automatic distribution of slave levels in the daisy chain can be realized without manual intervention.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of communication technology, and in particular to a master-slave communication method, electronic device, and storage medium. Background Technology

[0002] Multi-user electricity meters are widely used in centralized electricity metering scenarios such as residential communities. To simplify wiring and reduce system costs, existing technologies often use an RS485 daisy-chain topology to connect multiple slave devices in series with a master device, enabling centralized data acquisition and control.

[0003] In traditional RS485 daisy-chain systems, slave devices typically rely on pre-defined logical addresses for communication. However, logical addresses only identify the device and do not reflect the actual connection order of the slave devices on the physical link. Therefore, during field installation or maintenance, each slave device needs to be manually assigned a hierarchy, which refers to the physical position of the slave device in the daisy chain. This establishes a mapping relationship between the slave device's logical address and its physical position in the daisy chain, determining the sequential order of each slave device in the link. This manual operation not only requires a high level of technical expertise from field personnel but also becomes cumbersome and time-consuming when there are a large number of slave devices. It is also prone to errors or address duplication, increasing the complexity of field installation and reducing efficiency. Summary of the Invention

[0004] This application provides a master-slave communication method to solve the problems that manual operation not only requires high professional skills from on-site construction personnel, but also involves a cumbersome and time-consuming configuration process when there are many slave devices, which is prone to errors or address duplication, increasing the complexity and inefficiency of on-site installation. The method realizes automatic identification and hierarchical sorting of the physical location of slave devices in a daisy chain topology without manual intervention, reducing installation difficulty and maintenance costs, and improving installation efficiency.

[0005] In a first aspect, this application provides a master-slave communication method applied to a master in a master-slave communication system. The master-slave communication system includes a master and multiple slaves, which are connected in series via a daisy chain. The master is connected in series with the head slave of the chain among the multiple slaves. The method includes: The host broadcasts a first probe frame; the first probe frame includes a first identifier value and a second identifier value, the first identifier value is used to indicate the slave device to be assigned a level, and the second identifier value is used to indicate the level to be assigned to the slave device; The host receives the target response frame; the target response frame is the first first response frame received by the host within a preset time window after broadcasting the first probe frame; the first response frame is sent by the slave device to the host after updating its fourth identifier to the second identifier when it determines that its third identifier value is consistent with the first identifier value; the first response frame includes the slave device address and the fourth identifier value; initially, the third identifier value of all slave devices is the same as the first identifier value. The host records the hierarchical sorting information based on the target response frame; the hierarchical sorting information includes the mapping relationship between the slave address and the fourth identifier value in the target response frame; The host sends an acknowledgment frame to the slave corresponding to the target response frame; the acknowledgment frame is used to instruct the slave corresponding to the target response frame to broadcast a notification frame. The notification frame includes a fifth identifier value, which is equal to the first identifier value plus 1. The notification frame is used to instruct the slave that has received the notification frame but has not received the acknowledgment frame sent by the host to update its own third identifier value to the fifth identifier value, and to instruct the host to send the first probe frame for the next round. When the host receives a notification frame, it updates the first identifier value by 1 and the second identifier value by 1, and repeats the steps of sending the first probe frame, receiving the target response frame, recording the hierarchical sorting information, sending an acknowledgment frame, and updating the first identifier value and the second identifier value until no first response frame is received after the first probe frame has been sent in a preset number of rounds.

[0006] Using the method provided in the first aspect, the host broadcasts a first probe frame, which includes a first identifier value and a second identifier value. The first identifier value indicates the slave device to be assigned a hierarchy, and the second identifier value indicates the hierarchy to which the slave device needs to be assigned. Thus, the host can automatically initiate hierarchy allocation for the slave device via broadcast, based on the first and second identifier values, without manual intervention or prior knowledge of the slave device's address. When the slave device determines that its third identifier value matches its first identifier value, it participates in the response to the first probe frame. The slave device updates its fourth identifier value to the second identifier value and sends a first response frame to the host. The host receives the target response frame; the target response frame is the first first response frame received by the host within a preset time window after broadcasting the first probe frame. By controlling the preset time window, the host ensures that only one response frame from a slave device requiring hierarchy allocation is received in each round, enabling host-side control of response frame reception, eliminating the need for slave devices to participate in any reception decisions, and simplifying the design and implementation complexity on the slave side. The host records hierarchical sorting information based on the target response frame. This sorting information includes the mapping relationship between the slave addresses and the fourth identifier value in the target response frame. The host gradually establishes the correspondence between slave addresses and the fourth identifier value (i.e., the hierarchy) to complete the hierarchy allocation for multiple slaves, facilitating subsequent master-slave communication. The host sends an acknowledgment frame to the slave corresponding to the target response frame. Upon receiving the acknowledgment frame from the host, the slave broadcasts a notification frame. This notification frame instructs slaves that received the notification frame but did not receive the acknowledgment frame from the host to update their third identifier value to the fifth identifier value, and also instructs the host to send the first probe frame for the next round. Based on this, slaves that have been assigned a hierarchy lock their state upon receiving the acknowledgment frame and no longer participate in subsequent hierarchy allocation, ensuring the uniqueness of the hierarchy allocation. Simultaneously, by broadcasting the notification frame, the third identifier value of all remaining slaves is updated at once, forming a relay transmission, reducing the overhead of individual communication between the host and each slave, and improving the efficiency of hierarchy allocation. Furthermore, by progressively incrementing the first and fifth identifier values ​​in rounds, and in conjunction with the interaction of acknowledgment and notification frames, the host can lock the physical location of each slave device level by level, ensuring the orderly allocation of the hierarchy. When the host receives a notification frame, it updates the first identifier value by 1 and the second identifier value by 1, and repeats the steps of sending the first probe frame, receiving the target response frame, recording the hierarchy sorting information, sending the acknowledgment frame, and updating the first and second identifier values, until no first response frame is received after sending the first probe frame in a preset number of rounds. This completes the hierarchical allocation of all slave devices, realizing the automatic identification and orderly sorting of the physical locations of slave devices in the daisy chain topology without manual intervention, reducing installation difficulty and maintenance costs, and improving installation efficiency.

[0007] In one possible design, the preset time window satisfies Formula 1; Formula 1 is: ; in, This represents the time after the first probe frame is sent in the Nth broadcast and the first response frame is received, where N is an integer and K is the number of slave devices. The first preset duration, This is the second preset duration, where ms stands for milliseconds.

[0008] In one possible design, after no first response frame is received after the first probe frame has been sent in a preset round, the method further includes: The host sends an identification frame to the end slave; the end slave is the slave corresponding to the last target response frame received by the host. The identification frame includes the fourth identification value of the end slave and the end identifier. The end identifier is used to notify the end slave that the end slave is the last slave among multiple slaves connected in series in a daisy chain.

[0009] In one possible design, after recording the hierarchical ordering information of all slave devices, the method also includes: The host sends a second probe frame to the head slave at a preset period. The second probe frame includes a sixth identifier value and a counter. The second probe frame is used to instruct each slave to forward the message sequentially, and increment the sixth identifier value and the counter value by 1 when forwarding to the next slave, until the end slave is reached. Initially, the sixth identifier value is equal to the fourth identifier value of the head slave, and the counter value is 1. The end slave is the last slave among multiple slaves connected in series in a daisy chain. If the host does not receive the second response frame sent by the end slave within the first timeout period, it determines that one of the multiple slaves has been unplugged and re-determines the hierarchical ordering information of all slaves; wherein, the second response frame is sent by the end slave to the host after receiving the second probe frame forwarded by each level of slaves in sequence, and the second response frame includes the sixth identifier value and counter received by the end slave; When the host receives the second response frame sent by the end slave within the first timeout period, it re-executes the step of broadcasting the first probe frame. If the host receives the first response frame within the second timeout period, it determines that a new slave has been added to the multiple slaves and redetermines the hierarchical ordering information of all slaves. Initially, the third identifier value of the new slave is the same as the first identifier value.

[0010] Secondly, this application provides a master-slave communication method applied to a slave device in a master-slave communication system. The master-slave communication system includes a master and multiple slave devices, which are connected in series via a daisy chain. The master is connected in series with the head slave device among the multiple slave devices. The method includes: The slave device receives a first probe frame broadcast by the master device; the first probe frame includes a first identifier value and a second identifier value, the first identifier value is used to indicate the slave device to be assigned a level, and the second identifier value is used to indicate the level to be assigned to the slave device; When a slave device determines that its third identifier value matches its first identifier value, it updates its fourth identifier value to its second identifier value and sends a first response frame to the master device, so that the master device can record the hierarchical sorting information according to the target response frame. Initially, the third identifier value of all slave devices is the same as the first identifier value. The first response frame includes the slave device address and the fourth identifier value. The target response frame is the first first response frame received by the master device within a preset time window after broadcasting the first probe frame. The hierarchical sorting information includes the mapping relationship between the slave device address and the fourth identifier value in the target response frame. When a slave device receives an acknowledgment frame from a master device, it broadcasts a notification frame. The acknowledgment frame is sent by the master device to the slave device corresponding to the target response frame. The acknowledgment frame is used to instruct the slave device corresponding to the target response frame to broadcast a notification frame. The notification frame includes a fifth identifier value, which is equal to the first identifier value plus 1. The notification frame is used to instruct the slave device that has received the notification frame but has not received an acknowledgment frame from the master device to update its third identifier value to the fifth identifier value. When a slave device receives a notification frame broadcast by another slave device but has not received an acknowledgment frame from the master device, it updates its third identifier value to its fifth identifier value.

[0011] In one possible design, the first response frame also includes type information indicating the function type of the slave device, which includes at least one of the following: energy metering, temperature detection, digital input / output, residual current detection, leakage current detection, non-intrusive load identification, load control, and electrical parameter measurement.

[0012] In one possible design, after the host records the hierarchical ordering information of all slave devices, the method further includes: The slave device at the chain head receives the second probe frame sent by the master device at a preset period; the second probe frame includes a sixth identifier value and a counter. If the slave determines that it is not the end slave, it increments the sixth identifier value by 1, increments the counter value by 1, and forwards the updated second probe frame to the next level slave. If the slave device determines that it is the end slave device and receives the second probe frame from the upper-level slave device, it sends a second response frame to the master device; the second response frame includes the sixth identification value and counter received by the end slave device.

[0013] The beneficial effects of the methods provided in the second aspect and the various possible designs of the second aspect can be found in the first aspect and the various possible designs of the first aspect, and will not be repeated here.

[0014] Thirdly, this application provides a master-slave communication device, comprising: a module for performing the methods described in the first aspect and any possible design of the first aspect.

[0015] Fourthly, this application provides a master-slave communication device, comprising: a module for performing the methods described in the second aspect and any possible design of the second aspect.

[0016] Fifthly, this application provides an electronic device including a first processor, which, when executing a computer-executable program or instructions in a memory, implements a master-slave communication method as described in the first and second aspects and any of the possible designs of the first and second aspects.

[0017] In a sixth aspect, this application provides an electronic device including at least one memory and at least one second processor. The memory stores a computer-executable program or instructions, and the second processor, when executing the computer-executable program or instructions, implements a master-slave communication method as described in the first and second aspects and any of the possible designs of the first and second aspects.

[0018] In a seventh aspect, this application provides a computer-readable storage medium storing a computer-executable program or instructions, which, when executed by a processor, implement a master-slave communication method as described in the first and second aspects and any of the possible designs of the first and second aspects.

[0019] Eighthly, this application provides a computer program product comprising: execution instructions stored in a readable storage medium, at least one processor of an electronic device being able to read the execution instructions from the readable storage medium, and the at least one processor executing the execution instructions causing the electronic device to implement a master-slave communication method as described in the first to second aspects and any of the possible designs of the first to second aspects. Attached Figure Description

[0020] Figure 1 This is a schematic diagram of a master-slave communication system provided in an embodiment of this application.

[0021] Figure 2 Signaling interaction of a master-slave communication method provided in an embodiment of this application Figure 1 .

[0022] Figure 3 Signaling interaction of a master-slave communication method provided in an embodiment of this application Figure 2 .

[0023] Figure 4 A schematic diagram of the structure of a master-slave communication device provided in an embodiment of this application. Figure 1 .

[0024] Figure 5 A schematic diagram of the structure of a master-slave communication device provided in an embodiment of this application. Figure 2 .

[0025] Figure 6 A schematic diagram of the structure of an electronic device provided in an embodiment of this application. Figure 1 .

[0026] Figure 7 A schematic diagram of the structure of an electronic device provided in an embodiment of this application. Figure 2 . Detailed Implementation

[0027] 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. 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, or c alone can mean: a alone, b alone, c alone, a combination of a and b, a combination of a and c, a combination of b and c, or a, b, and c, where a, b, and c can be single or multiple. Furthermore, the terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance.

[0028] The terms “center,” “longitudinal,” “lateral,” “up,” “down,” “left,” “right,” “front,” and “rear,” etc., indicate the orientation or positional relationship based on the orientation or positional relationship shown in the accompanying drawings. They are used only for the convenience of describing this application and simplifying the description, and do not indicate or imply that the device or element referred to must have a specific orientation, or be constructed and operated in a specific orientation. Therefore, they should not be construed as limitations on this application.

[0029] The terms "connected" and "connected" should be interpreted broadly. For example, in circuit structures, "connected" or "connected" can refer not only to physical connections but also to electrical or signal connections. This could be a direct connection (physical connection) or an indirect connection via at least one intermediate component, as long as the circuit is connected. It could also refer to the internal connection between two components. Similarly, a signal connection can refer to a connection via a circuit or a medium, such as radio waves. Those skilled in the art will understand the specific meaning of these terms in this application based on the specific circumstances.

[0030] For example, this application provides a master-slave communication method, electronic device, and storage medium. The master broadcasts a probe frame carrying a hierarchy identifier and, utilizing the response time difference caused by physical distance differences, locks the first responding slave as the head slave within a preset time window after broadcasting the first probe frame. Subsequently, the master sends an acknowledgment frame to the slave, triggering a broadcast notification frame, causing downstream slaves to update their status to prepare for the next round of probing. Through a step-by-step, iterative approach, the master can automatically identify the physical location and connection order of all slaves in a daisy-chain topology without manual intervention, establishing a mapping relationship between addresses and hierarchy. This achieves automatic sorting of slave physical locations, reducing installation difficulty and maintenance costs, and improving installation efficiency.

[0031] The master-slave communication method provided in this application is executed by an electronic device, or by a master-slave communication device in an electronic device.

[0032] Electronic devices can be the master or slave in a master-slave communication system. The master or slave can be an electricity meter, capacitor, or circuit breaker, etc.

[0033] Electronic devices can also include servers, desktop computers, mobile phones, tablets, laptops, wearable devices, in-vehicle devices, augmented reality (AR) / virtual reality (VR) devices, etc.

[0034] The master-slave communication device can be implemented through a combination of software and / or hardware. For example, the master-slave communication device can be a transceiver chip. Alternatively, the master-slave communication device can be an application (APP), a webpage, or a public account, etc.

[0035] To simplify the explanation, the embodiments of this application are illustrated using the example of a host and a slave device.

[0036] Below, in conjunction with Figure 1 The master-slave communication system provided in the embodiments of this application will be described.

[0037] Please see Figure 1 , Figure 1 This is a schematic diagram of a master-slave communication system provided in one embodiment of this application. Figure 1 As shown, the master-slave communication system of this application includes: a master 11 and multiple slaves 12.

[0038] Multiple slave devices 12 are connected in series in a daisy chain manner, and the master device 11 is connected in series with the first slave device in the daisy chain (i.e., the first slave device in the daisy chain).

[0039] The host 11 can communicate directly with the head slave. After receiving the instruction from the host 11, the head slave triggers the corresponding forwarding or broadcasting operation according to the instruction type, thereby communicating with the next-level slave (i.e., the second slave in the daisy chain). This process continues, with each slave forwarding the host's instructions to the subsequent slaves in a hierarchical manner, and returning the response information from each slave to the host 11, thus enabling indirect communication between the host 11 and all slaves 12 in the entire daisy chain.

[0040] The communication methods between the master and slave devices, and between slave devices, can be wired or wireless.

[0041] Wired communication methods can include coaxial cable, fiber optic cable, and digital subscriber line (DSL). Wireless communication methods can include Bluetooth, infrared, Wi-Fi, and microwave.

[0042] In the RS485 protocol, the maximum number of slave devices 12 can be 32. Figure 1 This is illustrated with the number of slave devices 12 being 3, but this application does not impose any limitation on this.

[0043] The host 11 can be a device such as an electricity meter or a capacitor, and the slave 12 can also be a device such as an electricity meter or a capacitor.

[0044] The following embodiments of this application will be used to illustrate the concept of having Figure 1 Taking the master-slave communication system with the structure shown as an example, combined with Figures 2 to 3 This application provides a detailed description of the master-slave communication method.

[0045] Please see Figure 2 , Figure 2 Signaling interaction of a master-slave communication method provided in an embodiment of this application Figure 1 .like Figure 2 As shown, the method includes: S101, The host broadcasts and sends the first probe frame.

[0046] Correspondingly, the slave device receives the first probe frame broadcast by the master device.

[0047] The first probe frame includes a first identifier value and a second identifier value. The first identifier value indicates the slave device to be assigned a hierarchy, and the second identifier value indicates the hierarchy to which the slave device needs to be assigned. One first probe frame is used only for hierarchy allocation of one slave device. When the master device is performing hierarchy allocation for multiple slave devices, it needs to send multiple rounds of first probe frames. In each round of first probe frames, the first identifier value and the second identifier value will increase sequentially, thereby achieving hierarchical allocation.

[0048] Each slave device maintains a third identifier value and a fourth identifier value. The third identifier value is used to match the corresponding first probe frame to determine whether hierarchical allocation is needed based on the first probe frame. The fourth identifier value is used to identify the slave device's hierarchy; the fourth identifier value can be understood as the physical position number of the slave device in the daisy chain.

[0049] Initially, the first identifier value can be set to 0x01, the second identifier value can be set to 0x01, the third identifier value can be set to 0x01, and the fourth identifier value can be set to 0x00. That is, initially, the third identifier value of all slave devices is the same as the first identifier value.

[0050] In some examples, the first probe frame includes a frame header, a first identifier value, a second identifier value, and a checksum bit in sequence. The frame header in the first probe frame can be set to 0xAA, and the slave device is required to perform corresponding operations and respond when it receives a data frame with a frame header of 0xAA.

[0051] When the slave device receives the first probe frame, it can parse the first identifier value and the second identifier value in the first probe frame to determine whether a level allocation is required based on the first identifier value. If a level allocation is required, the slave device can update its own fourth identifier value based on the second identifier value to achieve the level allocation.

[0052] Based on this, the host can automatically initiate the hierarchical allocation of the slave through broadcast, based on the first and second identifier values, without manual intervention or prior knowledge of the slave address.

[0053] S102. The slave device determines whether its third identifier value is consistent with its first identifier value.

[0054] If the slave device determines that its third identifier value is consistent with its first identifier value, then the slave device needs to participate in the response to the first probe frame and executes S103; if the slave device determines that its third identifier value is inconsistent with its first identifier value, the slave device does not participate in the response to the first probe frame.

[0055] S103. The slave device updates its fourth identifier value to the second identifier value and sends the first response frame to the master device.

[0056] Correspondingly, the host receives the target response frame; the target response frame is the first first response frame received by the host within a preset time window after broadcasting the first probe frame.

[0057] The slave device updates its fourth identifier value to the second identifier value in the first probe frame. Initially, the fourth identifier value is 0x00, and after the update, it becomes the second identifier value in the first probe frame, which is the level that needs to be assigned to the slave device, indicating that the slave device has completed the assignment at the current level.

[0058] For example, initially, all slave devices have the same third identifier value as their first identifier value. In the first round of probing, the second identifier value is 0x01, and all slave devices update their fourth identifier value to 0x01, indicating that they have been assigned as slave devices at level 1 in the daisy chain.

[0059] After the update is completed, the slave device sends the first response frame to the master device.

[0060] The first response frame includes the slave address and the fourth identifier value. The slave address is the logical address of the slave device.

[0061] In some examples, the first response frame includes, in sequence, a frame header, the slave address, a fourth identifier value, and a checksum. The frame header in the first response frame can be set to 0xBB, which configures the master and slave devices to only receive data frames with a 0xBB header, while the other slave devices remain silent.

[0062] The first response frame is used to notify the host that the slave has updated its fourth identifier value to the second identifier value, so that the host can record the mapping relationship between the slave address and the fourth identifier value based on the first response frame.

[0063] Considering that during hierarchical allocation, a first probe frame carries only one second identifier value, which only needs to be assigned to one corresponding slave device. Each slave device, upon receiving the first probe frame, determines whether it needs to participate in the response based on whether its third identifier value matches its first identifier value. In a daisy-chain configuration of multiple slave devices (e.g., one master and three slaves), the first slave is directly connected to the master and can communicate directly. The second slave communicates with the master through the first slave, and the third slave communicates through both the second and first slaves. Therefore, the farther the slave's physical location is from the master in the daisy chain, or the later its position in the chain, the longer the data transmission path and the longer the first response frame from the slave takes to reach the master.

[0064] Based on the aforementioned physical characteristics, after broadcasting the first probe frame, the host opens a receiving window and listens for the first response frame returned by the slave within a preset time window after broadcasting the first probe frame. The host determines the first first response frame received within the preset time window as the target response frame and immediately stops receiving subsequent first response frames.

[0065] In some examples, the preset time window satisfies the following formula: Formula 1; in, This represents the time after the first probe frame is sent in the Nth broadcast and the first response frame is received, where N is an integer and K is the number of slave devices. The first preset duration, This is the second preset duration, where ms stands for milliseconds.

[0066] Where N represents the round in which the host sends the first probe frame. For example, when the host sends the first probe frame in the first round, N is 1; when the host sends the first probe frame in the second round, N is 2, and so on.

[0067] Since the second identifier value in the first probe frame of a round only needs to be assigned to one corresponding slave in the daisy chain. It can also be understood as the time to receive the first response frame sent by the Nth slave device among multiple slave devices connected in series in a daisy chain.

[0068] As a feasible implementation method, It can be 5ms. It can be 3ms.

[0069] For example, after sending the first probe frame in the first round, the host can set the preset time window as follows: That is, after sending the first probe frame in the first round, the host only... The host receives the first response frame, thus enabling it to receive the first response frame sent by the first slave among multiple slaves connected in a daisy chain, and stops receiving subsequent first response frames sent by other slaves.

[0070] For example, after sending the first probe frame in the second round, the host can set the preset time window as follows: ,Right now That is, after sending the first probe frame in the second round, the host only... The host receives the first response frame, thus enabling it to receive the first response frame sent by the second slave among multiple slaves connected in a daisy chain, and stops receiving subsequent first response frames sent by other slaves.

[0071] For example, after sending the first probe frame in the third round, the host can set the preset time window as follows: ,Right now That is, after sending the first probe frame in the third round, the host only... The host receives the first response frame, thus enabling it to receive the first response frame sent by the third slave among multiple slaves connected in a daisy chain, and stops receiving subsequent first response frames sent by other slaves.

[0072] Similarly, all eligible slave devices will send a first response frame upon receiving the first probe frame. However, the master only receives the first arriving first response frame within a preset time window; subsequent first response frames are actively ignored by the master. By progressively increasing the preset time window, the master ensures that it receives only one response frame from a slave device requiring hierarchical allocation in each round. This allows the master to control the reception of response frames, eliminating the need for slave devices to participate in any reception decisions and simplifying the design and implementation complexity on the slave side.

[0073] S104. The host records the hierarchical sorting information based on the target response frame.

[0074] The hierarchical sorting information includes the mapping relationship between the slave address and the fourth identifier value in the target response frame.

[0075] After determining the target response frame, the host parses the slave address and fourth identifier value contained in the frame and records the hierarchical sorting information accordingly.

[0076] For example, after sending the first probe frame in the first round, the host receives the target response frame, parses it to obtain the slave address as Addr_1, and the fourth identifier value as 0x01, then records the mapping relationship: 0x01 → Addr_1. After sending the first probe frame in the second round, the host receives the target response frame, parses it to obtain the slave address as Addr_2, and the fourth identifier value as 0x02, then records the mapping relationship: 0x02 → Addr_2. This process continues until the hierarchical information of all slaves has been recorded.

[0077] Based on this, the host gradually establishes a correspondence between the slave addresses and the fourth identifier value, i.e., the level, in order to complete the level allocation of multiple slaves, so as to facilitate subsequent master-slave communication.

[0078] S105. The host sends an acknowledgment frame to the slave device corresponding to the target response frame.

[0079] Correspondingly, the slave device receives the acknowledgment frame sent by the master device corresponding to the target response frame.

[0080] The acknowledgment frame is used to indicate the slave device broadcasting the notification frame corresponding to the target response frame.

[0081] After recording the hierarchical sorting information based on the target response frame, the host sends an acknowledgment frame to the slave corresponding to that target response frame—that is, the slave that has completed hierarchical allocation in the current round. This allows the slave corresponding to the target response frame to know that its second identifier value has taken effect, indicating that hierarchical allocation has been completed. The slave corresponding to the target response frame will no longer participate in subsequent hierarchical matching and responses. The slave corresponding to the target response frame can broadcast a notification frame to update the third identifier value of other slaves that have not yet undergone hierarchical allocation, in order to prepare for receiving the first probe frame in the next round.

[0082] In some examples, the acknowledgment frame includes a frame header, the target slave address, and a checksum in sequence. The frame header in the acknowledgment frame can be set to 0xFF, and the target slave address is the slave address of the slave device corresponding to the target response frame.

[0083] S106. When the slave device receives the acknowledgment frame sent by the master device, it broadcasts a notification frame.

[0084] S107. When a slave device receives a notification frame broadcast by another slave device and has not received an acknowledgment frame sent by the master device, it updates its own third identifier value to the fifth identifier value.

[0085] The notification frame includes a fifth identifier value, which is equal to the first identifier value plus 1. The notification frame is used to instruct a slave device that has received the notification frame but has not yet received an acknowledgment frame from the master to update its third identifier value to the fifth identifier value, and to instruct the master to send the first probe frame for the next round.

[0086] In some examples, the notification frame includes a frame header, a fifth identifier value, and a checksum in sequence. The frame header in the notification frame can be set to 0xCC, which enables both the master and slave to receive and respond when a data frame with a frame header of 0xCC is received.

[0087] For example, taking the first round of probing as an example, after sending the first probe frame in the first round, both the first and second identifier values ​​are 0x01, and the third identifier value of all slave devices is 0x01. The host receives the first response frame sent by the head slave device within a preset time window after broadcasting the first probe frame, identifies it as the target response frame, and records the hierarchical sorting information. The host sends an acknowledgment frame to the head slave device. After receiving the acknowledgment frame, the head slave device broadcasts a notification frame, in which the fifth identifier value is 0x02. All other slave devices that have not received an acknowledgment frame (i.e., all slave devices except the head slave device) update their own third identifier value from 0x01 to 0x02 upon receiving this notification frame.

[0088] At this point, the third identifier value of all slave devices that have not received an acknowledgment frame has been updated to 0x02, consistent with the first identifier value (0x02) in the first probe frame of the next round. When the master receives the notification frame, it begins the second round of probes, and these slave devices become eligible to participate in the response, thus ensuring that the master can accurately record the hierarchical order information of the second slave device in the next round of probes.

[0089] Based on this, slave devices that have already been assigned a hierarchy lock their own state upon receiving an acknowledgment frame and no longer participate in subsequent hierarchy allocations, ensuring the uniqueness of the hierarchy allocation. Simultaneously, a broadcast notification frame updates the third identifier value of all remaining slave devices at once, forming a relay transmission and reducing the overhead of individual communication between the master and each slave device, thus improving the efficiency of hierarchy allocation. Furthermore, by incrementally incrementing the first and fifth identifier values ​​round by round, and in conjunction with the interaction of acknowledgment and notification frames, the master can lock the physical location of each slave device level by level, ensuring the orderly nature of the hierarchy allocation.

[0090] S108. When the host receives the notification frame, it updates the first identifier value by 1 and the second identifier value by 1.

[0091] The host repeats steps S101 to S108 until no first response frame is received after the first probe frame is sent in the preset round.

[0092] It should be noted that the master needs to send the first probe frame of the next round after the slave updates its third identifier value to the fifth identifier value.

[0093] When the host receives the notification frame, it determines that it has completed one round of probing (S101 to S107). The host increments the first and second identifier values ​​by 1 to indicate the next level to be assigned. Subsequently, the host begins broadcasting the first probe frame for a new round, repeating the process from S101 to S108. Each round proceeds according to the following logic: the first identifier value of the current round is used to filter slaves with the corresponding third identifier value; the second identifier value of the current round is used to update the fourth identifier value for slaves that have successfully matched in this round; the host ensures that the first response frame of the selected slave at the current level is selected through a dynamically adjusted preset time window, records the corresponding level sorting information, and sends an acknowledgment frame; after receiving the acknowledgment frame, the selected slave broadcasts a notification frame, causing the remaining slaves to update their third identifier values ​​according to the notification frame, and causing the host to update its first and second identifier values, in preparation for starting the next round of probing.

[0094] Once all slave devices have been assigned a hierarchy, they will not update their third identifier value after receiving a notification frame. Therefore, when a new round of first probe frames arrives at the slave devices, none of their third identifier values ​​will match the first identifier value in the new round of first probe frames. Consequently, the master will not receive any first response frames. If the master fails to receive a first response frame after sending first probe frames for a preset number of consecutive rounds, it determines that all slave devices have completed hierarchy assignment, and the process ends. The master and all slave devices can then communicate according to the assigned hierarchy.

[0095] The preset number of rounds can be 3, meaning that the process ends when the host fails to receive the first response frame after sending the first probe frame 3 times consecutively.

[0096] The following will illustrate this with specific examples.

[0097] The master-slave communication system consists of a master, slave A, slave B, and slave C connected in series in a daisy chain. Initially, the third identifier value of each slave is 0x01, and the fourth identifier value is 0x00. The slave address of slave A is Addr_A, the slave address of slave B is Addr_B, and the slave address of slave C is Addr_C. It takes 5ms. It takes 3ms.

[0098] First round of exploration: The host broadcasts a first probe frame, in which the first identifier value is 0x01 and the second identifier value is 0x01.

[0099] Slave A receives the first probe frame, determines that its third identifier value (0x01) is consistent with the first identifier value (0x01), and updates its fourth identifier value to the second identifier value (0x01).

[0100] Slave B receives the first probe frame, determines that its third identifier value (0x01) is consistent with the first identifier value (0x01), and updates its fourth identifier value to the second identifier value (0x01).

[0101] Slave C receives the first probe frame, determines that its third identifier value (0x01) is consistent with the first identifier value (0x01), and updates its fourth identifier value to the second identifier value (0x01).

[0102] At this time, the third identifier value of slave A is 0x01 and the fourth identifier value is 0x01; the third identifier value of slave B is 0x01 and the fourth identifier value is 0x01; the third identifier value of slave C is 0x01 and the fourth identifier value is 0x01.

[0103] Slave A sends a first response frame to the master. The slave address in the first response frame is Addr_A and the fourth identifier value is 0x01.

[0104] Slave B sends a first response frame to the master. The slave address in the first response frame is Addr_B, and the fourth identifier value is 0x01.

[0105] Slave C sends a first response frame to master. The slave address in the first response frame is Addr_C and the fourth identifier value is 0x01.

[0106] Within [0, 5] ms after the host broadcasts the first probe frame, it receives the first response frame sent by slave A. This first response frame is the target response frame.

[0107] The host records hierarchical sorting information, which includes the mapping relationship between Addr_A and 0x01.

[0108] The host sends an acknowledgment frame to slave A, with the target slave address in the acknowledgment frame being Addr_A.

[0109] When slave device A receives the acknowledgment frame sent by the master device, it broadcasts a notification frame. The fifth identifier value in the notification frame is equal to the first identifier value (0x01) plus 1, that is, the fifth identifier value is 0x02.

[0110] The master, slave B, and slave C received a notification frame. Neither slave B nor slave C received an acknowledgment frame from the master.

[0111] Slave B updates its third identifier value to its fifth identifier value (0x02).

[0112] Slave C updates its third identifier value to its fifth identifier value (0x02).

[0113] At this time, the third identifier value of slave A is 0x01 and the fourth identifier value is 0x01; the third identifier value of slave B is 0x02 and the fourth identifier value is 0x01; the third identifier value of slave C is 0x02 and the fourth identifier value is 0x01.

[0114] The host updates the first identifier value by 1 and the second identifier value by 1.

[0115] At this point, the first identifier value is 0x02, the second identifier value is 0x02, and the next round of detection begins.

[0116] Second round of exploration: The host broadcasts a first probe frame, in which the first identifier value is 0x02 and the second identifier value is 0x02.

[0117] Slave A receives the first probe frame and determines that its third identifier value (0x01) is inconsistent with its first identifier value (0x02). Slave A does not participate in the response to the first probe frame.

[0118] Slave B receives the first probe frame, determines that its third identifier value (0x02) is consistent with the first identifier value (0x02), and updates its fourth identifier value to the second identifier value (0x02).

[0119] Slave C receives the first probe frame, determines that its third identifier value (0x02) is consistent with the first identifier value (0x02), and updates its fourth identifier value to the second identifier value (0x02).

[0120] At this time, the third identifier value of slave A is 0x01 and the fourth identifier value is 0x01; the third identifier value of slave B is 0x02 and the fourth identifier value is 0x02; the third identifier value of slave C is 0x02 and the fourth identifier value is 0x02.

[0121] Slave B sends a first response frame to the master. The slave address in the first response frame is Addr_B, and the fourth identifier value is 0x02.

[0122] Slave C sends a first response frame to master. The slave address in the first response frame is Addr_C and the fourth identifier value is 0x02.

[0123] Within (5, 8] seconds after the host broadcasts the first probe frame, it receives the first response frame sent by slave B, which is the target response frame.

[0124] The host records hierarchical sorting information, which includes the mapping relationship between Addr_B and 0x02.

[0125] The master sends an acknowledgment frame to slave B, with the target slave address in the acknowledgment frame being Addr_B.

[0126] When slave device B receives the acknowledgment frame sent by the master device, it broadcasts a notification frame. The fifth identifier value in the notification frame is equal to the first identifier value (0x02) plus 1, that is, the fifth identifier value is 0x03.

[0127] The master, slave A, and slave C receive notification frames. Slave A received an acknowledgment frame from the master during the first round of probing, while slave C did not receive an acknowledgment frame from the master.

[0128] Slave C updates its third identifier value to its fifth identifier value (0x03).

[0129] At this time, the third identifier value of slave A is 0x01 and the fourth identifier value is 0x01; the third identifier value of slave B is 0x02 and the fourth identifier value is 0x02; the third identifier value of slave C is 0x03 and the fourth identifier value is 0x02.

[0130] The host updates the first identifier value by 1 and the second identifier value by 1.

[0131] At this time, the first identifier value is 0x03, and the second identifier value is 0x03.

[0132] Third round of exploration: The host broadcasts a first probe frame, in which the first identifier value is 0x03 and the second identifier value is 0x03.

[0133] Slave A receives the first probe frame and determines that its third identifier value (0x01) is inconsistent with its first identifier value (0x03). Slave A does not participate in the response to the first probe frame.

[0134] Slave B receives the first probe frame and determines that its third identifier value (0x02) is inconsistent with its first identifier value (0x03). Slave B does not participate in the response to the first probe frame.

[0135] Slave C receives the first probe frame, determines that its third identifier value (0x03) is consistent with the first identifier value (0x03), and updates its fourth identifier value to the second identifier value (0x03).

[0136] At this time, the third identifier value of slave A is 0x01 and the fourth identifier value is 0x01; the third identifier value of slave B is 0x02 and the fourth identifier value is 0x02; the third identifier value of slave C is 0x03 and the fourth identifier value is 0x03.

[0137] Slave C sends a first response frame to master. The slave address in the first response frame is Addr_C and the fourth identifier value is 0x03.

[0138] Within (8, 11] seconds after the host broadcasts the first probe frame, it receives the first response frame sent by the slave C, which is the target response frame.

[0139] The host records hierarchical sorting information, which includes the mapping relationship between Addr_C and 0x03.

[0140] The master sends an acknowledgment frame to slave C, with the target slave address in the acknowledgment frame being Addr_C.

[0141] When slave C receives the acknowledgment frame sent by the master, it broadcasts a notification frame. The fifth identifier value in the notification frame is equal to the first identifier value (0x03) plus 1, that is, the fifth identifier value is 0x04.

[0142] The master, slave A, and slave B receive notification frames. Slave A received an acknowledgment frame from the master during the first round of probing, and slave B received an acknowledgment frame from the master during the second round of probing.

[0143] At this time, the third identifier value of slave A is 0x01 and the fourth identifier value is 0x01; the third identifier value of slave B is 0x02 and the fourth identifier value is 0x02; the third identifier value of slave C is 0x03 and the fourth identifier value is 0x03.

[0144] The host updates the first identifier value by 1 and the second identifier value by 1.

[0145] At this time, the first identifier value is 0x04, and the second identifier value is 0x04.

[0146] Fourth round of exploration: The host broadcasts a first probe frame, in which the first identifier value is 0x04 and the second identifier value is 0x04.

[0147] Slave A receives the first probe frame and determines that its third identifier value (0x01) is inconsistent with its first identifier value (0x04). Slave A does not participate in the response to the first probe frame.

[0148] Slave B receives the first probe frame and determines that its third identifier value (0x02) is inconsistent with its first identifier value (0x04). Slave B does not participate in the response to the first probe frame.

[0149] Slave C receives the first probe frame and determines that its third identifier value (0x03) is inconsistent with its first identifier value (0x04). Slave C does not participate in the response to the first probe frame.

[0150] No slave device responded; the master did not receive the first response frame.

[0151] The host then broadcasts the first probe frame twice more. The first identifier value in the first probe frame is 0x04, and the second identifier value is 0x04.

[0152] There was no response from any of the slave devices, and the master did not receive the first response frame.

[0153] The process is complete.

[0154] At this time, the third identifier value of slave A is 0x01 and the fourth identifier value is 0x01; the third identifier value of slave B is 0x02 and the fourth identifier value is 0x02; the third identifier value of slave C is 0x03 and the fourth identifier value is 0x03.

[0155] The hierarchical sorting information of the host records is shown in Table 1 below: Table 1

[0156] Thus, the host completes the hierarchical allocation of slave A, slave B, and slave C.

[0157] In this embodiment, the host broadcasts a first probe frame, which includes a first identifier value and a second identifier value. The first identifier value indicates the slave device to be assigned a hierarchy, and the second identifier value indicates the hierarchy to which the slave device needs to be assigned. Thus, the host can automatically initiate hierarchy allocation for the slave device via broadcast, based on the first and second identifier values, without manual intervention or prior knowledge of the slave device's address. When the slave device determines that its third identifier value matches its first identifier value, it participates in the response to the first probe frame. The slave device updates its fourth identifier value to the second identifier value and sends a first response frame to the host. The host receives the target response frame; the target response frame is the first first response frame received by the host within a preset time window after broadcasting the first probe frame. By controlling the preset time window, the host ensures that only one response frame from a slave device requiring hierarchy allocation is received in each round, enabling host-side control of response frame reception. The slave device does not need to participate in any reception decisions, simplifying the design and implementation complexity on the slave side. The host records hierarchical sorting information based on the target response frame. This sorting information includes the mapping relationship between the slave addresses and the fourth identifier value in the target response frame. The host gradually establishes the correspondence between slave addresses and the fourth identifier value (i.e., the hierarchy) to complete the hierarchy allocation for multiple slaves, facilitating subsequent master-slave communication. The host sends an acknowledgment frame to the slave corresponding to the target response frame. Upon receiving the acknowledgment frame from the host, the slave broadcasts a notification frame. This notification frame instructs slaves that received the notification frame but did not receive the acknowledgment frame from the host to update their third identifier value to the fifth identifier value, and also instructs the host to send the first probe frame for the next round. Based on this, slaves that have been assigned a hierarchy lock their state upon receiving the acknowledgment frame and no longer participate in subsequent hierarchy allocation, ensuring the uniqueness of the hierarchy allocation. Simultaneously, by broadcasting the notification frame, the third identifier value of all remaining slaves is updated at once, forming a relay transmission, reducing the overhead of individual communication between the host and each slave, and improving the efficiency of hierarchy allocation. Furthermore, by progressively incrementing the first and fifth identifier values ​​in rounds, and in conjunction with the interaction of acknowledgment and notification frames, the host can lock the physical location of each slave device level by level, ensuring the orderly allocation of the hierarchy. When the host receives a notification frame, it updates the first identifier value by 1 and the second identifier value by 1, and repeats the steps of sending the first probe frame, receiving the target response frame, recording the hierarchy sorting information, sending the acknowledgment frame, and updating the first and second identifier values, until no first response frame is received after sending the first probe frame in a preset number of rounds. This completes the hierarchical allocation of all slave devices, realizing the automatic identification and orderly sorting of the physical locations of slave devices in the daisy chain topology without manual intervention, reducing installation difficulty and maintenance costs, and improving installation efficiency.

[0158] Based on the above exemplary description, the first response frame also includes type information, which is used to indicate the function type of the slave device. The function type includes at least one of the following: energy metering, temperature detection, digital input / output, residual current detection, leakage current detection, non-intrusive load identification, load control, and electrical parameter measurement.

[0159] By carrying type information in the first response frame, the host can record the mapping relationship between slave addresses and levels, and also learn the specific functions of each slave, eliminating the need for manual configuration and further reducing the complexity of on-site installation and maintenance.

[0160] As a feasible implementation method, the function type can be set using the values ​​shown in Table 2 below: Table 2

[0161] It should be noted that the above values ​​are merely illustrative examples. In actual applications, more types or custom values ​​can be set according to system requirements, and this application does not impose any restrictions on this.

[0162] After receiving the first response frame, the host parses the type information in it and records the type information, along with the slave address and the fourth identifier value, into the hierarchical sorting information.

[0163] For example, based on Table 1, the hierarchical sorting information of the host records can be shown in Table 3 below: Table 3

[0164] In Table 3, the host can know that slave A is the first slave in the daisy chain, and its function is power metering; slave B is the second slave in the daisy chain, and its function is temperature detection and residual current detection; slave C is the third slave in the daisy chain, and its function is digital input and output.

[0165] Based on the above exemplary description, if no first response frame is received after the first probe frame is sent in the preset round, the host can send an identification frame to the end slave.

[0166] Among them, the end slave is the slave corresponding to the last target response frame received by the master.

[0167] The identification frame includes the fourth identification value of the end slave and the end identifier. The end identifier is used to notify the end slave that it is the last slave among multiple slaves connected in series in a daisy chain.

[0168] In some examples, the identification frame includes, in sequence, a frame header, a fourth identification value for the end slave, an end identifier, and a checksum. The frame header in the identification frame can be set to 0xDD. The end identifier can be set to a specific value.

[0169] After receiving the identification frame, the end slave device parses the end identifier in it and marks itself as an end slave device.

[0170] By sending identification frames to the end slave devices, the master and end slave devices can clearly define the physical boundaries of the daisy chain topology, which facilitates subsequent master-slave communication, link monitoring, fault location, and device addition and deletion detection, further improving the completeness of the automatic hierarchical allocation function.

[0171] Based on the above exemplary description, after the host records the hierarchical sorting information of all slave devices, considering that slave devices are frequently added or deleted in master-slave communication systems, the host can also, as follows: Figure 3 The method shown is used to detect the addition and deletion of devices.

[0172] Please see Figure 3 , Figure 3 Signaling interaction of a master-slave communication method provided in an embodiment of this application Figure 2 .like Figure 3 As shown, the method includes: S201. The host sends the second probe frame to the slave device at the chain head according to the preset cycle.

[0173] Correspondingly, the slave device at the chain head receives the second probe frame sent by the master device at a preset period.

[0174] The preset period can be set according to system requirements, such as 1 minute.

[0175] Among them, the chain head slave is the first slave among multiple slaves connected in series in a daisy chain manner.

[0176] The second probe frame includes a sixth identifier value and a counter. The second probe frame is used to instruct each slave to forward the message sequentially, and to increment the sixth identifier value and the counter value by 1 when forwarding to the next slave, until the last slave is reached. The last slave is the last slave among multiple slaves connected in series in a daisy chain.

[0177] Initially, the sixth identifier value is equal to the fourth identifier value of the chain head slave, and the counter count value is 1.

[0178] In some examples, the second probe frame includes, in sequence, a frame header, a sixth identifier value, a counter, and a checksum. The frame header of the second probe frame can be set to 0xEF.

[0179] S202. The slave device determines whether it is a terminal slave device.

[0180] If the slave device determines that it is not the final slave device, then execute S203; if the slave device determines that it is the final slave device, then execute S204.

[0181] Among them, the slave device can determine whether it is a terminal slave device by checking whether it stores a terminal identifier.

[0182] S203, the slave device increments the sixth identifier value by 1, increments the counter value by 1, and forwards the updated second probe frame to the next slave device.

[0183] For non-end slave devices, after receiving the second probe frame, the sixth identifier value is incremented by 1, the counter value is incremented by 1, and the updated second probe frame is forwarded to the next level slave device.

[0184] Through this step-by-step forwarding and incrementing method, as the second probe frame is passed down the daisy chain, the sixth identifier value always remains consistent with the level of the current forwarding slave, while the counter records the number of levels that have been forwarded.

[0185] As a feasible implementation, the number of attempts for the host to send the second probe frame and the slave to forward the updated second probe frame to the next slave can be 3, to ensure that the head slave and the next slave can stably receive the second probe frame.

[0186] S204. When the end slave receives the second probe frame from the upper-level slave, it sends a second response frame to the master.

[0187] Correspondingly, the host determines whether it has received the second response frame sent by the end slave within the first timeout period.

[0188] If the host does not receive the second response frame sent by the end slave within the first timeout period, the host executes S205; if the host receives the second response frame sent by the end slave within the first timeout period, the host executes S206.

[0189] The second response frame includes the sixth identifier value and counter received by the end slave device.

[0190] For the end slave device, after receiving the second probe frame forwarded by slave devices at each level, it stops forwarding the frame and instead returns the second response frame to the master device.

[0191] In some examples, the second response frame includes, in sequence, a frame header, a sixth identifier value, a counter, and a checksum. The sixth identifier value and the counter have been updated by each slave device at each level.

[0192] The first timeout duration can be set to 10 seconds.

[0193] S205. The host determines that one of the multiple slave devices has been unplugged and re-determines the hierarchical order information of all slave devices.

[0194] If the host does not receive a second response frame from the end slave within the first timeout period, it indicates that the second probe frame transmission was interrupted, meaning that a slave in the daisy chain has been disconnected or is malfunctioning, preventing the relay from being completed. At this point, the host determines that the link status has changed, triggers the reordering process, and re-executes the aforementioned methods S101 to S108.

[0195] S206. The host re-executes the step of broadcasting and sending the first probe frame.

[0196] If the host successfully receives the second response frame from the end slave within the first timeout period, it indicates that the current link is intact and all assigned slaves are online. At this point, to further detect whether any new slaves have joined, the host restarts an initial probe: broadcasting the first probe frame and setting both the first and second identifier values ​​to their initial values, such as 0x01.

[0197] S207. The host determines whether the first response frame has been received within the second timeout period.

[0198] If the first response frame is received within the second timeout period, the host executes S208; if the first response frame is not received within the second timeout period, the host executes S209.

[0199] The second timeout duration can be set to the maximum system response time of the master-slave communication system. The maximum system response time can be determined based on the maximum number of slave devices supported by the master-slave communication system, ensuring that it can cover the response of all possible newly added slave devices. For example, if the maximum number of slave devices supported by the master-slave communication system is 32, then the second timeout duration can be (32×3+5) ms.

[0200] S208. The host determines that a new slave has been added to the multiple slaves and redetermines the hierarchical ordering information of all slaves.

[0201] Initially, the third identifier value of the new slave device is the same as the first identifier value (e.g., initial value 0x01). The host receives the first response frame within the second timeout period, indicating that a new slave device has joined the daisy chain. Regardless of whether the joining position is at the head, middle, or end of the chain, the new slave device will respond to the first probe frame because its third identifier value is the same as its first identifier value. At this point, the host determines that a new slave device has been added to the multiple slave devices, triggering a reordering process and re-executing methods S101 to S108.

[0202] As a feasible implementation, the host can attempt to broadcast the first probe frame three times. If the first response frame is received within the second timeout period in one of the three attempts, it is determined that a new slave has been added to the multiple slaves.

[0203] S209. The master unit confirms that no new slave unit has been added and no slave unit has been removed.

[0204] If the host receives the second response frame from the end slave normally within the first timeout period, and does not receive any first response frame in subsequent probes, it is determined that the current link is stable and there are no additions or removals of devices. The host can continue to send the second probe frame in the next preset period to maintain the probe for additions or removals of devices.

[0205] In the above embodiments, through periodic probing and dynamic detection, the host can monitor the integrity of the daisy chain topology in real time, automatically detect the removal and addition of slave devices, and re-trigger hierarchical sorting when necessary, thereby realizing adaptive maintenance of the system during operation and further improving the reliability and scalability of the master-slave communication system.

[0206] For example, this application also provides a master-slave communication device.

[0207] Please see Figure 4 , Figure 4 A schematic diagram of the structure of a master-slave communication device provided in an embodiment of this application. Figure 1 .

[0208] like Figure 4 As shown, the first master-slave communication device 100 can exist independently or be integrated into other devices. It can communicate with the slave device mentioned above to implement the operation corresponding to the master in any of the above method embodiments.

[0209] The first master-slave communication device 100 may include a first transceiver unit 101 and a first processing unit 102. The first transceiver unit 101 may also be referred to as a communication interface or a communication unit. The first transceiver unit 101 can implement the corresponding communication functions in the aforementioned method embodiments. The first processing unit 102 can read instructions and / or data from the storage unit. The first processing unit 102 is used to perform data processing so that the first master-slave communication device 100 can implement the aforementioned method embodiments.

[0210] Optionally, the first master-slave communication device 100 may further include a storage unit, which can be used to store instructions and / or data.

[0211] The first master-slave communication device 100 can be used to perform the actions performed by the host in the method embodiments described above. The first master-slave communication device 100 can be a host or a component configurable on the host.

[0212] Optionally, the first transceiver unit 101 may include a sending unit and a receiving unit. The sending unit is used to perform the sending operation in the foregoing method embodiments. The receiving unit is used to perform the receiving operation in the foregoing method embodiments.

[0213] It should be noted that the first master-slave communication device 100 may include a transmitting unit but not a receiving unit. Alternatively, the first master-slave communication device 100 may include a receiving unit but not a transmitting unit. Specifically, it depends on whether the above-described scheme executed by the first master-slave communication device 100 includes both transmitting and receiving actions.

[0214] As an example, the first master-slave communication device 100 is used to perform the foregoing. Figures 2 to 3 The actions performed by the host in the illustrated embodiment.

[0215] The first master-slave communication device 100 may include a first transceiver unit 101 and a first processing unit 102.

[0216] The first transceiver unit 101 is used to broadcast and send a first probe frame; the first probe frame includes a first identifier value and a second identifier value, the first identifier value is used to indicate the slave device to be assigned a level, and the second identifier value is used to indicate the level to be assigned to the slave device; Receive target response frame; the target response frame is the first first response frame received by the first transceiver unit 101 within a preset time window after broadcasting the first probe frame; the first response frame is sent by the slave device to the first transceiver unit 101 after updating its fourth identifier value to the second identifier value when it determines that its third identifier value is consistent with the first identifier value; the first response frame includes the slave device address and the fourth identifier value; initially, the third identifier value of all slave devices is the same as the first identifier value; The first processing unit 102 is used to record hierarchical sorting information according to the target response frame; the hierarchical sorting information includes the mapping relationship between the slave address and the fourth identifier value in the target response frame; The first transceiver unit 101 is used to send an acknowledgment frame to the slave device corresponding to the target response frame. The acknowledgment frame is used to instruct the slave device corresponding to the target response frame to broadcast a notification frame. The notification frame includes a fifth identifier value, which is equal to the first identifier value plus 1. The notification frame is used to instruct the slave device that receives the notification frame but has not received the acknowledgment frame sent by the first transceiver unit 101 to update its own third identifier value to the fifth identifier value. It is also used to instruct the first transceiver unit 101 to send the first probe frame for the next round. The first processing unit 102 is used to update the first identifier value by 1 and the second identifier value by 1 when a notification frame is received. The first transceiver unit 101 and the first processing unit 102 are used to repeatedly execute the steps of sending the first probe frame, receiving the target response frame, recording the hierarchical sorting information, sending the acknowledgment frame, and updating the first identifier value and the second identifier value until no first response frame is received after the first probe frame has been sent in a preset number of rounds.

[0217] It should be understood that the corresponding processes performed by each unit have been described in detail in the above method embodiments, and will not be repeated here for the sake of brevity.

[0218] In some examples, the preset time window satisfies Formula 1; Formula 1 is: ; in, This represents the time after the first probe frame is sent in the Nth broadcast and the first response frame is received, where N is an integer and K is the number of slave devices. The first preset duration, This is the second preset duration, where ms stands for milliseconds.

[0219] In some examples, after the first detection frame is not received after a preset number of rounds, the first transceiver unit 101 is also used to send an identification frame to the end slave. The end slave is the slave corresponding to the last target response frame received by the master. The identification frame includes the fourth identification value of the end slave and the end identifier. The end identifier is used to notify the end slave that the end slave is the last slave among multiple slaves connected in series in a daisy chain.

[0220] In some examples, after recording the hierarchical ordering information of all slave devices, the first transceiver unit 101 is also used to send a second probe frame to the head slave device at a preset period. The second probe frame includes a sixth identifier value and a counter. The second probe frame is used to instruct each slave device to forward the message sequentially, and to increment the sixth identifier value and the counter value by 1 when forwarding to the next slave device, until the end slave device is reached. Initially, the sixth identifier value is equal to the fourth identifier value of the head slave device, and the counter value is 1. The end slave device is the last slave device among multiple slave devices connected in series in a daisy chain manner. The first transceiver unit 101 and the first processing unit 102 are further configured to determine that a slave device among the multiple slave devices has been unplugged when no second response frame sent by the end slave device is received within the first timeout period, and to re-determine the hierarchical ordering information of all slave devices; wherein, the second response frame is sent by the end slave device to the master device after receiving the second probe frame forwarded by each level of slave devices in sequence, and the second response frame includes the sixth identification value and counter received by the end slave device; The first transceiver unit 101 is further configured to re-execute the step of broadcasting the first probe frame when it receives the second response frame sent by the end slave within the first timeout period. If the first response frame is received within the second timeout period, the first transceiver unit 101 and the first processing unit 102 are further configured to determine that a new slave has been added to the multiple slaves and to redetermine the hierarchical sorting information of all slaves. Initially, the third identifier value of the new slave is the same as the first identifier value.

[0221] For example, this application also provides a master-slave communication device.

[0222] Please see Figure 5 , Figure 5 A schematic diagram of the structure of a master-slave communication device provided in an embodiment of this application. Figure 2 .

[0223] like Figure 5 As shown, the second master-slave communication device 200 can exist independently or be integrated into other devices. It can communicate with the master mentioned above to implement the operation corresponding to the slave device in any of the above method embodiments.

[0224] The second master-slave communication device 200 may include a second transceiver unit 201 and a second processing unit 202. The second transceiver unit 201 may also be referred to as a communication interface or communication unit. The second processing unit 202 may read instructions and / or data from the storage unit so that the second master-slave communication device 200 can implement the aforementioned method embodiment, the second transceiver unit 201 can implement the corresponding communication function, and the second processing unit 202 is used for data processing.

[0225] Optionally, the second master-slave communication device 200 may further include a storage unit, which can be used to store instructions and / or data.

[0226] The second master-slave communication device 200 can be used to execute the actions performed by the slave device in the aforementioned method embodiments. The second master-slave communication device 200 can be a slave device or a component configurable on the slave device.

[0227] Optionally, the second transceiver unit 201 may include a sending unit and a receiving unit. The sending unit is used to perform the sending operation in the foregoing method embodiments. The receiving unit is used to perform the receiving operation in the foregoing method embodiments.

[0228] It should be noted that the second master-slave communication device 200 may include a transmitting unit but not a receiving unit. Alternatively, the second master-slave communication device 200 may include a receiving unit but not a transmitting unit. Specifically, it depends on whether the above-described scheme executed by the second master-slave communication device 200 includes both transmitting and receiving actions.

[0229] As an example, the second master-slave communication device 200 is used to perform the aforementioned... Figures 2 to 3 The actions performed by the slave device in the illustrated embodiment.

[0230] The second master-slave communication device 200 may include: a second transceiver unit 201 and a second processing unit 202.

[0231] The second transceiver unit 201 is used to receive a first probe frame broadcast by the host; the first probe frame includes a first identifier value and a second identifier value, the first identifier value is used to indicate the slave device to be assigned a level, and the second identifier value is used to indicate the level to be assigned to the slave device; The second processing unit 202 is used to update its fourth identifier value to the second identifier value when it determines that its third identifier value is consistent with the first identifier value. The second transceiver unit 201 is used to send a first response frame to the host so that the host records the hierarchical sorting information according to the target response frame. Initially, the third identifier value of all slaves is the same as the first identifier value. The first response frame includes the slave address and the fourth identifier value. The target response frame is the first first response frame received by the host within a preset time window after broadcasting the first probe frame. The hierarchical sorting information includes the mapping relationship between the slave address and the fourth identifier value in the target response frame. The second transceiver unit 201 is used to broadcast a notification frame when it receives an acknowledgment frame sent by the host. The acknowledgment frame is sent by the host to the slave corresponding to the target response frame. The acknowledgment frame is used to instruct the slave corresponding to the target response frame to broadcast a notification frame. The notification frame includes a fifth identifier value, which is equal to the first identifier value plus 1. The notification frame is used to instruct the slave that has received the notification frame but has not received an acknowledgment frame sent by the host to update its own third identifier value to the fifth identifier value. The second processing unit 202 is used to update its own third identifier value to the fifth identifier value when it receives a notification frame broadcast by another slave device and has not received an acknowledgment frame sent by the master device.

[0232] In some examples, the first response frame also includes type information indicating the function type of the slave device, which includes at least one of the following: energy metering, temperature detection, digital input / output, residual current detection, leakage current detection, non-intrusive load identification, load control, and electrical parameter measurement.

[0233] In some examples, after the host records the hierarchical ordering information of all slaves, the method also includes: The second transceiver unit 201 of the chain head slave is used to receive the second probe frame sent by the master according to a preset period; the second probe frame includes a sixth identifier value and a counter. If the slave device determines that it is not the end slave device, the second processing unit 202 is used to increment the sixth identifier value by 1 and the counter value by 1, and the second transceiver unit 201 is used to forward the updated second probe frame to the next level slave device. If the slave device determines that it is the end slave device and receives the second probe frame from the upper-level slave device, the second transceiver unit 201 is used to send a second response frame to the master device; the second response frame includes the sixth identification value and counter received by the end slave device.

[0234] Figure 6 A schematic diagram of the structure of an electronic device provided in an embodiment of this application. Figure 1 .like Figure 6 As shown, the electronic device may include a first processor 301, which, when executing a computer-executable program or instruction in the memory, implements the master-slave communication method in the above method embodiment.

[0235] The electronic device can be used to perform the various steps and / or processes corresponding to the electronic devices in the above method embodiments.

[0236] Figure 7 A schematic diagram of the structure of an electronic device provided in an embodiment of this application. Figure 2 .like Figure 7 As shown, the electronic device may include a second processor 401 and a memory 402. The memory 402 stores a computer program. When the second processor 401 executes the computer program, it implements the master-slave communication method in the above method embodiment.

[0237] The electronic device can be used to perform the various steps and / or processes corresponding to the electronic devices in the above method embodiments.

[0238] The electronic device of this application can be used to execute the technical solutions of the method embodiments described above. Its implementation principle and technical effects are similar. The operations implemented by each module can be further referred to the relevant descriptions of the method embodiments, which will not be repeated here. The modules here can also be replaced by components or circuits.

[0239] Another embodiment of this application also provides a computer-readable storage medium storing a computer program. When the computer program is executed by a processor, it can implement the master-slave communication method described in the above method embodiments.

[0240] This application also provides a program product including executable instructions stored in a computer-readable storage medium. At least one processor of an electronic device can read the executable instructions from the computer-readable storage medium, and the execution of the executable instructions by the at least one processor causes the electronic device to implement the master-slave communication method described in the above method embodiments.

[0241] This application also provides a chip that is connected to a memory, or a chip that integrates a memory, wherein when a software program stored in the memory is executed, the master-slave communication method described in the above method embodiments is implemented.

[0242] In the 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 modules or 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 modules may be electrical, mechanical, or other forms.

[0243] Those skilled in the art will understand that although some embodiments herein include certain features included in other embodiments, combinations of features from different embodiments are intended to be within the scope of this application and form different embodiments. For example, in the claims, any of the claimed embodiments can be used in any combination.

[0244] The above-described embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this application.

Claims

1. A master-slave communication method, characterized in that, A host is applied to a master-slave communication system, the master-slave communication system including a master and multiple slaves, the multiple slaves being connected in series in a daisy chain, the master being connected in series with the head slave of the multiple slaves, the method including: The host broadcasts a first probe frame; the first probe frame includes a first identifier value and a second identifier value, the first identifier value is used to indicate the slave device to be assigned a level, and the second identifier value is used to indicate the level to be assigned to the slave device; The host receives a target response frame; the target response frame is the first first response frame received by the host within a preset time window after broadcasting the first probe frame; the first response frame is sent by the slave device to the host after updating its fourth identifier to the second identifier when it determines that its third identifier value is consistent with the first identifier value, and the first response frame includes the slave device address and the fourth identifier value; initially, the third identifier value of all slave devices is the same as the first identifier value; The host records hierarchical sorting information based on the target response frame; the hierarchical sorting information includes the mapping relationship between the slave address and the fourth identifier value in the target response frame; The host sends an acknowledgment frame to the slave corresponding to the target response frame; the acknowledgment frame is used to instruct the slave corresponding to the target response frame to broadcast a notification frame, the notification frame includes a fifth identifier value, the fifth identifier value is equal to the first identifier value plus 1, the notification frame is used to instruct the slave that receives the notification frame but has not received the acknowledgment frame sent by the host to update its own third identifier value to the fifth identifier value, and is used to instruct the host to send the first probe frame for the next round; When the host receives the notification frame, it updates the first identifier value by 1 and the second identifier value by 1, and repeatedly executes the steps of sending the first probe frame, receiving the target response frame, recording the hierarchical sorting information, sending the confirmation frame, and updating the first identifier value and the second identifier value, until no first response frame is received after the first probe frame has been sent in a preset number of rounds.

2. The method according to claim 1, characterized in that, The preset time window satisfies Formula 1; Formula 1 is: ; in, This represents the time after the first probe frame is sent in the Nth broadcast and the first response frame is received, where N is an integer and K is the number of slave devices. The first preset duration, This is the second preset duration, where ms stands for milliseconds.

3. The method according to claim 1, characterized in that, After no first response frame is received after the first probe frame has been sent in the preset round, the method further includes: The host sends an identification frame to the end slave; the end slave is the slave corresponding to the last target response frame received by the host, and the identification frame includes the fourth identification value of the end slave and the end identifier. The end identifier is used to notify the end slave that the end slave is the last slave among multiple slaves connected in series in a daisy chain.

4. The method according to any one of claims 1 to 3, characterized in that, After recording the hierarchical sorting information of all slave devices, the method further includes: The host sends a second probe frame to the head slave at a preset period. The second probe frame includes a sixth identifier value and a counter. The second probe frame is used to instruct each slave to forward the message sequentially, and to increment the sixth identifier value and the counter value by 1 when forwarding to the next slave, until the end slave is reached. Initially, the sixth identifier value is equal to the fourth identifier value of the head slave, and the counter value is 1. The end slave is the last slave among multiple slaves connected in series in a daisy chain. If the host does not receive the second response frame sent by the end slave within the first timeout period, it determines that one of the multiple slaves has been unplugged and re-determines the hierarchical ordering information of all slaves; wherein, the second response frame is sent by the end slave to the host after receiving the second probe frame forwarded by each level of slaves in sequence, and the second response frame includes the sixth identifier value and counter received by the end slave; When the host receives the second response frame sent by the end slave within the first timeout period, it re-executes the step of broadcasting the first probe frame. If the first response frame is received within the second timeout period, the host determines that a new slave has been added to the multiple slaves and redetermines the hierarchical sorting information of all slaves. Initially, the third identifier value of the new slave is the same as the first identifier value.

5. A master-slave communication method, characterized in that, A slave device applied in a master-slave communication system, wherein the master-slave communication system includes a master and multiple slave devices, the multiple slave devices are connected in series in a daisy chain, and the master is connected in series with the head slave device in the chain among the multiple slave devices, the method includes: The slave device receives a first probe frame broadcast by the master device; the first probe frame includes a first identifier value and a second identifier value, the first identifier value is used to indicate the slave device to be assigned a level, and the second identifier value is used to indicate the level to be assigned to the slave device; When a slave device determines that its third identifier value matches its first identifier value, it updates its fourth identifier value to the second identifier value and sends a first response frame to the host, so that the host records the hierarchical sorting information according to the target response frame. Initially, the third identifier value of all slave devices is the same as the first identifier value. The first response frame includes the slave device address and the fourth identifier value. The target response frame is the first first response frame received by the host within a preset time window after broadcasting the first probe frame. The hierarchical sorting information includes the mapping relationship between the slave device address and the fourth identifier value in the target response frame. When the slave device receives the acknowledgment frame sent by the master device, it broadcasts a notification frame. The acknowledgment frame is sent by the master device to the slave device corresponding to the target response frame. The acknowledgment frame is used to instruct the slave device corresponding to the target response frame to broadcast a notification frame. The notification frame includes a fifth identifier value, which is equal to the first identifier value plus 1. The notification frame is used to instruct the slave device that receives the notification frame but has not received the acknowledgment frame sent by the master device to update its third identifier value to the fifth identifier value. When a slave device receives a notification frame broadcast by another slave device but has not received an acknowledgment frame sent by the master device, it updates its third identifier value to the fifth identifier value.

6. The method according to claim 5, characterized in that, The first response frame also includes type information, which is used to indicate the function type of the slave device. The function type includes at least one of the following: energy metering, temperature detection, digital input / output, residual current detection, leakage current detection, non-intrusive load identification, load control, and electrical parameter measurement.

7. The method according to claim 5, characterized in that, After the host records the hierarchical sorting information of all slave devices, the method further includes: The chain head slave receives a second probe frame sent by the host at a preset period; the second probe frame includes a sixth identifier value and a counter. If the slave determines that it is not a terminal slave, it increments the sixth identifier value by 1, increments the counter value by 1, and forwards the updated second probe frame to the next level slave. If the slave device determines that it is a terminal slave device and receives a second probe frame from the upstream slave device, it sends a second response frame to the host device; the second response frame includes the sixth identification value and counter received by the terminal slave device.

8. An electronic device, characterized in that, include: First processor; The first processor is configured to execute a computer-executable program or instructions in the memory, causing the electronic device to perform the master-slave communication method according to any one of claims 1-4 or 5-7.

9. An electronic device, characterized in that, include: At least one memory and at least one second processor; The memory is used to store computer-executable programs or instructions; The second processor is used to invoke a computer-executable program or instruction in the memory, causing the electronic device to perform the master-slave communication method according to any one of claims 1-4 or 5-7.

10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer-executable program or instructions, which are configured to perform the master-slave communication method according to any one of claims 1-4 or 5-7.