CN-122027466-A - Master-slave communication method, electronic device, and storage medium
Abstract
The application provides a master-slave communication method, electronic equipment and a storage medium, and relates to the technical field of communication. The method includes that a first detection frame containing a first identification value and a second identification value is broadcast by a host, when the slave determines that a third identification value of the slave is consistent with the first identification value, a fourth identification value of the slave is updated to be the second identification value, and a first response frame is sent to the host. The host receives a first response frame as a target response frame in a preset time window, records the mapping relation between the address of the slave and a fourth identification value according to the target response frame, and sends a confirmation frame to the slave. The slave which receives the acknowledgement frame broadcasts the notification frame such that the slave which received the notification frame and did not receive the acknowledgement frame updates the third identification value to a fifth identification value, the fifth identification value being equal to the first identification value plus 1. The host updates the first and second identification values by adding 1 and repeats the above steps until no response occurs. Therefore, the automatic distribution of slave machine levels in the daisy chain can be realized without manual intervention.
Inventors
- WANG YANGLONG
- FENG QIANG
- HUANG ZHENG
- PING JUNXIANG
- TANG BEILEI
- ZHOU ENZE
Assignees
- 德力西集团仪器仪表有限公司
Dates
- Publication Date
- 20260512
- Application Date
- 20260416
Claims (10)
- 1. A master-slave communication method, applied to a master in a master-slave communication system including a master and a plurality of slaves connected in series by a daisy-chain, the master being connected in series with a link head slave among the plurality of slaves, the method comprising: The method comprises the steps that a host broadcasts and sends a first detection frame, wherein the first detection frame comprises a first identification value and a second identification value, the first identification value is used for indicating a slave machine of a hierarchy to be allocated, and the second identification value is used for indicating the hierarchy to be allocated to the slave machine; The method comprises the steps that a host receives a target response frame, wherein the target response frame is a first response frame received by the host in a preset time window after a first detection frame is broadcast and sent, the first response frame is sent to the host after the third identification value of the host is updated to the second identification value when the third identification value of the host is consistent with the first identification value, and the first response frame comprises a slave address and the fourth identification value; The host records hierarchical ordering information according to the target response frame, wherein the hierarchical ordering information comprises a mapping relation between a slave address and a fourth identification value in the target response frame; The host sends a confirmation frame to the slave corresponding to the target response frame, wherein the confirmation frame is used for indicating the slave corresponding to the target response frame to broadcast and send a notification frame, the notification frame comprises a fifth identification value which is equal to the first identification value plus 1, the notification frame is used for indicating the slave which receives the notification frame and does not receive the confirmation frame sent by the host to update the third identification value of the slave to the fifth identification value, and the notification frame is used for indicating the host to send a first detection frame of the next round; And when the host receives the notification frame, updating the first identification value by 1 and the second identification value by 1, and repeating the steps of sending the first detection frame, receiving the target response frame, recording the hierarchical ordering information, sending the confirmation frame and updating the first identification value and the second identification value until the first response frame is not received after the first detection frame of the preset round is sent.
- 2. The method of claim 1, wherein the predetermined time window satisfies equation one; The first formula is: ; Wherein, the Indicating the time of receiving the first response frame after the nth broadcast transmission of the first probe frame, N being an integer, K being the number of slaves, For a first predetermined period of time, For a second preset duration, ms is milliseconds.
- 3. The method of claim 1, wherein after no first response frame is received after the transmission of the first probe frame for the preset round, the method further comprises: The method comprises the steps that a master computer sends an identification frame to a terminal slave computer, wherein the terminal slave computer is a slave computer corresponding to a target response frame received by the master computer last time, the identification frame comprises a fourth identification value of the terminal slave computer and a terminal identification, and the terminal identification is used for informing the terminal slave computer that the terminal slave computer is the last slave computer in a plurality of slave computers connected in series in a daisy chain mode.
- 4. A method according to any one of claims 1 to 3, wherein after recording the hierarchical ordering information of all slaves, the method further comprises: The method comprises the steps that a master machine sends a second detection frame to a chain head slave machine according to a preset period, wherein the second detection frame comprises a sixth identification value and a counter, the second detection frame is used for indicating each level of slave machines to forward in sequence, the sixth identification value is increased by 1 when the second detection frame is forwarded to the next level of slave machines, the count value of the counter is increased by 1 until reaching a tail end slave machine, the sixth identification value is equal to the fourth identification value of the chain head slave machine, the count value of the counter is 1, and the tail end slave machine is the last slave machine in a plurality of slave machines which are connected in series in a daisy chain mode; When the host computer does not receive a second response frame sent by the end slave computer within a first timeout period, determining that the slave computers in the plurality of slave computers are pulled out, and redefining hierarchical ordering information of all the slave computers, wherein the second response frame is sent to the host computer by the end slave computer after the second detection frames forwarded by the slave computers at all levels are sequentially received, and the second response frame comprises a sixth identification value and a counter which are received by the end slave computer; And when the host receives the second response frame sent by the end slave machine within the first timeout period, re-executing the step of broadcasting and sending the first detection frame, and if the first response frame is received within the second timeout period, determining that a plurality of slave machines are added with new slave machines and re-determining the hierarchical ordering information of all the slave machines by the host, wherein the third identification value of the new slave machine is the same as the first identification value initially.
- 5. A master-slave communication method, applied to a slave in a master-slave communication system, the master-slave communication system including a master and a plurality of slaves, the plurality of slaves being connected in series by means of a daisy chain, the master being connected in series with a link head slave among the plurality of slaves, the method comprising: the method comprises the steps that a slave receives a first detection frame sent by a host in a broadcasting mode, wherein the first detection frame comprises a first identification value and a second identification value, the first identification value is used for indicating the slave of a hierarchy to be allocated, and the second identification value is used for indicating the hierarchy to be allocated to the slave; When the slave determines that the third identification value of the slave is consistent with the first identification value, updating the fourth identification value of the slave to the second identification value, and sending a first response frame to the host so that the host records hierarchical ordering information according to a target response frame, wherein the third identification values of all the slaves are the same as the first identification value in the initial stage, the first response frame comprises a slave address and the fourth identification value, the target response frame is a first response frame received by the host in a preset time window after the first detection frame is broadcast and sent by the host, and the hierarchical ordering information comprises a mapping relation between the slave address and the fourth identification value in the target response frame; The method comprises the steps that when a slave receives an acknowledgement frame sent by a host, the slave broadcasts and sends a notification frame, wherein the acknowledgement frame is sent by the host to the slave corresponding to a target response frame, the acknowledgement frame is used for indicating the slave corresponding to the target response frame to broadcast and send the notification frame, the notification frame comprises a fifth identification value, the fifth identification value is equal to the first identification value plus 1, and the notification frame is used for indicating the slave which receives the notification frame and does not receive the acknowledgement frame sent by the host to update the third identification value of the slave to the fifth identification value; and when the slave receives the notification frame broadcast by other slaves and does not receive the acknowledgement frame sent by the host, the slave updates the third identification value of the slave to the fifth identification value.
- 6. The method of claim 5, wherein the first response frame further includes type information indicating a function type of the slave, the function type including at least one of a power metering class, a temperature detection class, a digital input output class, a residual current detection class, a leakage detection class, a non-invasive load identification class, a load control class, and an electrical parameter measurement class.
- 7. The method of claim 5, wherein after the master records the hierarchical ordering information of all slaves, the method further comprises: the chain head slave receives a second detection frame sent by the host according to a preset period, wherein the second detection frame comprises a sixth identification value and a counter; If the slave determines that the slave is not the terminal slave, adding 1 to the sixth identification value, adding 1 to the count value of the counter, and forwarding the updated second detection frame to the next-stage slave; And if the slave determines that the slave is the tail end slave and receives a second detection frame from the last-stage slave, sending a second response frame to the host, wherein the second response frame comprises a sixth identification value and a counter which are received by the tail end slave.
- 8. An electronic device is characterized by comprising a first processor; The first processor is configured to execute a computer executable program or instructions in a memory to cause the electronic device to perform the master-slave communication method of any one of claims 1-4 or 5-7.
- 9. An electronic device comprising at least one memory and at least one second processor; The memory is used for storing computer executable programs or instructions; The second processor is configured to invoke a computer executable program or instructions in the memory to cause the electronic device to perform the master-slave communication method of any 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 arranged to perform the master-slave communication method of any of claims 1-4 or 5-7.
Description
Master-slave communication method, electronic device, and storage medium Technical Field The present application relates to the field of communications technologies, and in particular, to a master-slave communication method, an electronic device, and a storage medium. Background The multi-user electric energy meter is widely applied to centralized electricity metering scenes such as residential communities. In order to simplify wiring and reduce system cost, the prior art commonly adopts an RS485 daisy chain topology structure to connect a plurality of slaves with one master in series, so as to realize centralized data acquisition and control. In a conventional RS485 daisy chain system, slaves typically rely on preset logical addresses for communication. However, the logical address can only identify the device identity, and cannot reflect the actual connection order of the slaves on the physical link. Thus, during field installation or maintenance, each slave needs to be manually allocated in a hierarchy, where the hierarchy refers to the physical position of the slave in the daisy chain, so as to establish a mapping relationship between the logical address of the slave and the physical position of the slave in the daisy chain, so as to determine the front-to-back order of each slave in the link. The manual operation mode has higher professional technical requirements on site constructors, and when the number of the secondary equipment is more, the configuration process is tedious and time-consuming, the problems of errors or repeated addresses and the like are easy to occur, the complexity of site installation is increased, and the efficiency is low. Disclosure of Invention The application provides a master-slave communication method, which solves the problems that a manual operation mode has higher professional technical requirements on site constructors, and when the number of slave devices is large, the configuration process is tedious and time-consuming, errors or address repetition are easy to occur, the complexity of site installation is increased, the efficiency is low, the automatic identification and hierarchical ordering of the physical positions of the slave devices under the daisy chain topology are realized, the manual intervention is not needed, the installation difficulty and maintenance cost are reduced, and the installation efficiency is improved. In a first aspect, the present application provides a master-slave communication method applied to a master in a master-slave communication system, the master-slave communication system including a master and a plurality of slaves, the plurality of slaves being connected in series by means of a daisy chain, the master being connected in series with a link head slave of the plurality of slaves, the method comprising: The method comprises the steps that a host broadcasts and sends a first detection frame, wherein the first detection frame comprises a first identification value and a second identification value, the first identification value is used for indicating a slave machine of a hierarchy to be allocated, and the second identification value is used for indicating the hierarchy to be allocated to the slave machine; The method comprises the steps that a host receives a target response frame, wherein the target response frame is a first response frame received by the host in a preset time window after broadcasting and transmitting a first detection frame, and the first response frame is transmitted to the host after updating a fourth identification value of the host into a second identification value when determining that a third identification value of the host is consistent with the first identification value; the host records hierarchical ordering information according to the target response frame, wherein the hierarchical ordering information comprises a mapping relation between a slave address and a fourth identification value in the target response frame; The host sends a confirmation frame to the slave corresponding to the target response frame, wherein the confirmation frame is used for indicating the slave corresponding to the target response frame to broadcast and send a notification frame, the notification frame comprises a fifth identification value which is equal to the first identification value plus 1, the notification frame is used for indicating the slave which receives the notification frame and does not receive the confirmation frame sent by the host to update the third identification value of the slave to the fifth identification value, and the notification frame is used for indicating the host to send a first detection frame of the next round; When the host receives the notification frame, the first identification value is increased by 1, the second identification value is increased by 1, and the steps of transmitting the first detection frame, receiving the target response frame, recording the hierarchical ordering informa