CN-116938632-B - Master-slave device communication method and device, electronic device and readable storage medium
Abstract
The invention provides a master-slave device communication method, a device, an electronic device and a readable storage medium, wherein the method comprises the steps of sending a first data acquisition request to a first slave device and sending a first online state confirmation request to a second slave device; recording that the second slave device is in an online state if response information returned by the second slave device for the first online state confirmation request is received within a preset first time period, waiting for data information returned by the first slave device for the first data acquisition request within the preset second time period if response information returned by the second slave device for the first online state confirmation request is not received within the preset first time period, and downloading the first slave device and recording that the first slave device is in an offline state if data information returned by the first slave device for the first data acquisition request is not received within the preset second time period. By adopting the method, the polling time of the master device can be reduced, and the online state of the slave device can be confirmed more quickly.
Inventors
- YANG SICHENG
- LI YINLONG
- LIAO KUN
Assignees
- 珠海格力电器股份有限公司
Dates
- Publication Date
- 20260505
- Application Date
- 20230712
Claims (9)
- 1. A master-slave communication method, applied to a master device, the master device being respectively bus-connected to a plurality of slave devices, the plurality of slave devices including a first slave device and a second slave device, addresses of the first slave device and the second slave device being adjacent, the method comprising: Transmitting a first data acquisition request to the first slave device and a first presence confirmation request to the second slave device; if the response information returned by the second slave device for the first online state confirmation request is received within a preset first time period, recording that the second slave device is in an online state; If the response information returned by the second slave device for the first online state confirmation request is not received within the preset first time period, waiting for the data information returned by the first slave device for the first data acquisition request within a preset second time period; if the data information returned by the first slave device for the first data acquisition request is not received within the preset second time period, the first slave device is disconnected and the first slave device is recorded to be in an offline state; After the first slave device waits for the data information returned by the first slave device for the first data acquisition request in a preset second time period, the method further comprises: Continuously waiting for response information returned by the second slave device for the first online state confirmation request within a preset third time period; if the response information returned by the second slave device for the first online state confirmation request is received in the preset third time period, recording that the second slave device is in an online state; and if the response information returned by the second slave device for the first online state confirmation request is not received within the preset third time period, recording that the second slave device is in an offline state.
- 2. The method of claim 1, wherein the plurality of slave devices includes a third slave device that is another slave device adjacent to the second slave device, the plurality of slave devices further including a fourth slave device and a fifth slave device, the fourth slave device and the fifth slave device being adjacent to an address of the fifth slave device, the method further comprising: If the second slave device is in an online state, a second data acquisition request is sent to the second slave device, and a second online state confirmation request is sent to the third slave device; and if the second slave device is in an offline state, sending a third data acquisition request to the fourth slave device and sending a third online state confirmation request to the fifth slave device.
- 3. The method according to claim 2, wherein the method further comprises: After the presence status is updated for each of the plurality of slaves, determining a target slave that is logged in to the presence status, sending a fourth data acquisition request to the target slave and no longer sending a fourth presence status confirmation request to an adjacent slave adjacent to the target slave.
- 4. A method according to claim 3, characterized in that the method further comprises: And if the data information returned by the target slave device for the fourth data acquisition request is not received in a preset fourth time period, the target slave device is disconnected, and the target slave device is recorded to be in an offline state.
- 5. The method of claim 1, wherein in a case where response information returned by the second slave device for the first presence confirmation request is received within a preset first period of time, the method further comprises: And waiting for data information returned by the first slave device for the first data acquisition request in the preset second time period.
- 6. The method of claim 1, wherein the master device is bus-connected with an added slave device, the method further comprising: And obtaining address information to be allocated, and allocating an address for the newly added slave device according to the address information to be allocated, wherein the address information to be allocated is a recorded prior address of the offline slave device in an offline state.
- 7. A master-slave communication apparatus, applied to a master device, the master device being respectively bus-connected to a plurality of slave devices, the plurality of slave devices including a first slave device and a second slave device, addresses of the first slave device and the second slave device being adjacent, the apparatus comprising: The first data acquisition request and first online state confirmation request sending module is used for sending a first data acquisition request to the first slave device and sending a first online state confirmation request to the second slave device; the first online state recording module is used for recording that the second slave equipment is in an online state if response information returned by the second slave equipment for the first online state confirmation request is received within a preset first time period; the first data information waiting module is used for waiting for the data information returned by the first slave device for the first data acquisition request in a preset second time period if the response information returned by the second slave device for the first online state confirmation request is not received in the preset first time period; The first slave device offline and offline state recording module is configured to, if data information returned by the first slave device for the first data acquisition request is not received within the preset second time period, offline the first slave device, and record that the first slave device is in an offline state; the response information waiting module is used for continuously waiting for response information returned by the second slave device for the first online state confirmation request in a preset third time period; The second online state recording module is used for recording that the second slave equipment is in an online state if response information returned by the second slave equipment for the first online state confirmation request is received within the preset third time period; And the offline state recording module is used for recording that the second slave device is in an offline state if the response information returned by the second slave device for the first online state confirmation request is not received within the preset third time period.
- 8. An electronic device comprising a processor, a memory and a computer program stored on the memory and capable of running on the processor, which computer program, when executed by the processor, implements a master-slave device communication method according to any one of claims 1-6.
- 9. A computer readable storage medium, characterized in that it stores thereon a computer program, which when executed by a processor implements a master-slave device communication method according to any of claims 1 to 6.
Description
Master-slave device communication method and device, electronic device and readable storage medium Technical Field The present invention relates to the field of communications technologies, and in particular, to a master-slave device communication method, a master-slave device communication apparatus, an electronic device, and a computer readable storage medium. Background In the existing communication system, multi-device interaction is normal, and a bus mode is generally adopted as a communication mode between devices. The master-slave communication realizes effective information transfer through interaction of one master device and a plurality of slave devices, and the master device can be connected with a plurality of slave devices through a bus. The master device often adopts a polling mode to realize communication with the slave devices, namely, the master device continuously transmits a query signal to the slave devices corresponding to each address in sequence, and even if only one slave device is in an on-line state, all the slave devices need to be polled, so that the refreshing time of the master device is wasted, and a user cannot acquire the state information of the slave devices in time through the master device. In the communication mode, when the master device polls for one circle, the more the number of slave devices is, the longer the time is, and in the occasion with higher real-time requirement, the response time is too slow to meet the requirement of the whole system. Besides the communication mode, the master device can acquire the state information of the single slave device in a traditional on-demand mode, namely, the slave device corresponding to a certain address is selected manually, a query signal is sent to the slave device, and the state information of the slave device is acquired. However, in the communication mode, information interaction among multiple devices is not facilitated, only one-sided information is obtained, and control output is affected after comprehensive information arrangement of the main device. Disclosure of Invention In view of the above, embodiments of the present invention have been made to provide a master-slave device communication method and corresponding a master-slave device communication apparatus, an electronic device, and a computer-readable storage medium that overcome or at least partially solve the above problems. The embodiment of the invention discloses a master-slave device communication method, which is applied to master devices, wherein the master devices are respectively connected with a plurality of slave device buses, the plurality of slave devices comprise a first slave device and a second slave device, the addresses of the first slave device and the second slave device are adjacent, and the method comprises the following steps: Transmitting a first data acquisition request to the first slave device and a first presence confirmation request to the second slave device; if the response information returned by the second slave device for the first online state confirmation request is received within a preset first time period, recording that the second slave device is in an online state; If the response information returned by the second slave device for the first online state confirmation request is not received within the preset first time period, waiting for the data information returned by the first slave device for the first data acquisition request within a preset second time period; And if the data information returned by the first slave device for the first data acquisition request is not received within the preset second time period, the first slave device is disconnected, and the first slave device is recorded to be in an offline state. Optionally, after the waiting for the data information returned by the first slave device for the first data acquisition request in the preset second period of time, the method further includes: Continuously waiting for response information returned by the second slave device for the first online state confirmation request within a preset third time period; if the response information returned by the second slave device for the first online state confirmation request is received in the preset third time period, recording that the second slave device is in an online state; and if the response information returned by the second slave device for the first online state confirmation request is not received within the preset third time period, recording that the second slave device is in an offline state. Optionally, the plurality of slave devices includes a third slave device, the third slave device being another slave device adjacent to the second slave device, the plurality of slave devices further including a fourth slave device and a fifth slave device, the fourth slave device and the fifth slave device being adjacent to an address, the method further including: If the second slave device is in a