A master-slave device communication method and device, electronic device and readable storage medium

By combining data acquisition requests and online status confirmation requests in the communication between the master and slave devices, the problems of excessive refresh time caused by polling and limited information interaction in on-demand mode are solved, enabling faster online status confirmation and data acquisition for slave devices.

CN116938632BActive Publication Date: 2026-05-05GREE ELECTRIC APPLIANCE INC OF ZHUHAI
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
GREE ELECTRIC APPLIANCE INC OF ZHUHAI
Filing Date
2023-07-12
Publication Date
2026-05-05

AI Technical Summary

Technical Problem

In existing communication systems, when the master device communicates with multiple slave devices, the polling method results in an excessively long refresh time, which cannot meet the real-time requirements; the traditional on-demand method cannot effectively carry out information exchange between multiple devices, affecting information processing and control output.

Method used

The master device sends a data acquisition request to the first slave device and an online status confirmation request to the second slave device with an adjacent address. If no response is received within a preset time, the master device waits for data information or takes the slave device offline, updates the online status information pool, and reduces the polling time.

Benefits of technology

By acquiring data and confirming online status for two adjacent addresses in the address pool, the polling time of the master device is reduced, the online status of the slave device is quickly confirmed, and the system response speed is improved.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116938632B_ABST
    Figure CN116938632B_ABST
Patent Text Reader

Abstract

This invention provides a master-slave device communication method, apparatus, electronic device, and readable storage medium. The method includes: sending a first data acquisition request to a first slave device and a first online status confirmation request to a second slave device; if a response from the second slave device to the first online status confirmation request is received within a preset first time period, then recording that the second slave device is online; if no response from the second slave device to the first online status confirmation request is received within the preset first time period, then waiting for data information from the first slave device to return for the first data acquisition request within a preset second time period; if no data information from the first slave device to the first data acquisition request is received within the preset second time period, then taking the first slave device offline and recording that the first slave device is offline. By adopting the above method, the polling time of the master device can be reduced, and the online status of the slave device can be confirmed more quickly.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of communication technology, 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 Technology

[0002] In existing communication systems, multi-device interaction is commonplace, and communication between devices typically uses a bus approach. Master-slave communication achieves efficient information transfer through the interaction between a master device and several slave devices, and the master device can connect to multiple slave devices via a bus.

[0003] Master devices often use a polling method to communicate with slave devices. This means the master device continuously sends query signals to each slave device corresponding to its address. Even if only one slave device is online, all slave devices still need to be polled, wasting the master device's refresh time. Users cannot obtain timely status information from the master device. In this communication mode, the polling time increases with the number of slave devices, making the response time too slow in real-time applications, failing to meet the requirements of the entire system.

[0004] In addition to the communication modes mentioned above, the master device can also obtain the status information of a single slave device using the traditional on-demand method. This involves manually selecting a slave device corresponding to a specific address and sending a query signal to it to obtain its status information. However, this communication mode is not conducive to information exchange between multiple devices, as it only obtains partial information, which affects the master device's ability to comprehensively process and control the output. Summary of the Invention

[0005] In view of the above problems, embodiments of the present invention are proposed to provide a master-slave device communication method and a corresponding master-slave device communication apparatus, an electronic device, and a computer-readable storage medium to overcome or at least partially solve the above problems.

[0006] This invention discloses a master-slave device communication method applied to a master device, wherein the master device is connected to a plurality of slave devices via a bus, the plurality of slave devices including a first slave device and a second slave device, the first slave device and the second slave device having adjacent addresses, and the method comprising:

[0007] Send a first data acquisition request to the first slave device and a first online status confirmation request to the second slave device;

[0008] If a response is received from the second slave device in response to the first online status confirmation request within a preset first time period, then the second slave device is recorded as being in an online state.

[0009] If no response information is received from the second slave device in response to the first online status confirmation request within the preset first time period, then wait for the data information returned by the first slave device in response to the first data acquisition request within the preset second time period;

[0010] If no data information is received from the first slave device in response to the first data acquisition request within the preset second time period, the first slave device is taken offline and recorded as being in an offline state.

[0011] Optionally, after waiting for the data information returned by the first slave device in response to the first data acquisition request within a preset second time period, the method further includes:

[0012] Continue to wait for the response information returned by the second slave device in response to the first online status confirmation request within the preset third time period;

[0013] If a response is received from the second slave device in response to the first online status confirmation request within the preset third time period, then the second slave device is recorded as being in an online state.

[0014] If no response is received from the second slave device in response to the first online status confirmation request within the preset third time period, the second slave device is recorded as being in an offline state.

[0015] Optionally, the plurality of slave devices includes a third slave device, which is another slave device adjacent to the second slave device. The plurality of slave devices also includes a fourth slave device and a fifth slave device, wherein the addresses of the fourth slave device and the fifth slave device are adjacent. The method further includes:

[0016] If the second slave device is online, a second data acquisition request is sent to the second slave device, and a second online status confirmation request is sent to the third slave device;

[0017] If the second slave device is offline, a third data acquisition request is sent to the fourth slave device, and a third online status confirmation request is sent to the fifth slave device.

[0018] Optionally, the method further includes:

[0019] After updating the online status of each of the plurality of slave devices, a target slave device that is recorded as being online is identified, a fourth data acquisition request is sent to the target slave device, and no fourth online status confirmation request is sent to the adjacent slave devices adjacent to the target slave device.

[0020] Optionally, the method further includes:

[0021] If no data information is received from the target slave device in response to the fourth data acquisition request within the preset fourth time period, the target slave device is taken offline, and the target slave device is recorded as being in an offline state.

[0022] Optionally, if the method receives a response from the second slave device in response to the first online status confirmation request within a preset first time period, the method further includes:

[0023] During the preset second time period, wait for the data information returned by the first slave device in response to the first data acquisition request.

[0024] Optionally, the master device is connected to the newly added slave device via a bus, and the method further includes:

[0025] Obtain the address information to be assigned, and assign an address to the newly added slave device according to the address information to be assigned; wherein, the address information to be assigned is the previously recorded address of an offline slave device that is in an offline state.

[0026] This invention also discloses a master-slave device communication apparatus applied to a master device, wherein the master device is connected to a plurality of slave devices via a bus, the plurality of slave devices including a first slave device and a second slave device, the first slave device and the second slave device having adjacent addresses, and the apparatus comprising:

[0027] The first data acquisition request and first online status confirmation request sending module is used to send a first data acquisition request to the first slave device and a first online status confirmation request to the second slave device;

[0028] The online status recording module is used to record that the second slave device is in an online state if it receives a response from the second slave device in response to the first online status confirmation request within a preset first time period.

[0029] The data information waiting module is used to wait for the data information returned by the first slave device in response to the first data acquisition request within a preset second time period if no response information is received from the second slave device in response to the first online status confirmation request within the preset first time period.

[0030] The offline and offline status recording module is used to take the first slave device offline and record that the first slave device is in an offline state if no data information is received from the first slave device in response to the first data acquisition request within the preset second time period.

[0031] Optionally, the device further includes:

[0032] The response information waiting module is used to continue waiting for the response information returned by the second slave device in response to the first online status confirmation request within a preset third time period;

[0033] The second online status recording module is used to record that the second slave device is in an online state if it receives a response from the second slave device in response to the first online status confirmation request within the preset third time period.

[0034] The offline status recording module is used to record that the second slave device is in an offline state if no response information is received from the second slave device in response to the first online status confirmation request within the preset third time period.

[0035] Optionally, the plurality of slave devices includes a third slave device, which is another slave device adjacent to the second slave device. The plurality of slave devices also includes a fourth slave device and a fifth slave device, wherein the fourth slave device and the fifth slave device are address-adjacent. The device further includes:

[0036] The second data acquisition request and second online status confirmation request sending module is used to send a second data acquisition request to the second slave device and a second online status confirmation request to the third slave device if the second slave device is online.

[0037] The third data acquisition request and third online status confirmation request sending module is used to send a third data acquisition request to the fourth slave device and a third online status confirmation request to the fifth slave device if the second slave device is offline.

[0038] Optionally, the device further includes:

[0039] The fourth data acquisition request sending module is used to determine the target slave device that is recorded as being online after updating the online status of each of the plurality of slave devices, send a fourth data acquisition request to the target slave device, and no longer send a fourth online status confirmation request to the adjacent slave devices adjacent to the target slave device.

[0040] Optionally, the device further includes:

[0041] The target slave device offline and offline status recording module is used to take the target slave device offline and record that the target slave device is in an offline state if no data information is received from the target slave device in response to the fourth data acquisition request within a preset fourth time period.

[0042] Optionally, if the device receives a response from the second slave device in response to the first online status confirmation request within a preset first time period, the device further includes:

[0043] The second data information waiting module is used to wait for the data information returned by the first slave device in response to the first data acquisition request within the preset second time period.

[0044] Optionally, the master device is bus-connected to the newly added slave device, and the apparatus further includes:

[0045] The module for obtaining and allocating address information to be assigned is used to obtain address information to be assigned and to assign an address to the newly added slave device based on the address information to be assigned; wherein, the address information to be assigned is the previously recorded address of an offline slave device that is in an offline state.

[0046] This invention also discloses an electronic device, including: a processor, a memory, and a computer program stored in the memory and capable of running on the processor. When the computer program is executed by the processor, it implements a master-slave device communication method as described above.

[0047] This invention also discloses a computer-readable storage medium storing a computer program, which, when executed by a processor, implements a master-slave device communication method as described above.

[0048] The embodiments of the present invention have the following advantages:

[0049] In this embodiment of the invention, while sending a data acquisition request to a first slave device to obtain data information from the first slave device, the master device simultaneously sends a first online status confirmation request to a second slave device whose address is adjacent to that of the first slave device to confirm the online status of the second slave device. If a response from the second slave device to the first online status confirmation request is received within a preset first time period, the second slave device can be confirmed to be online. If no response from the second slave device to the first online status confirmation request is received within the preset first time period, the master device waits for data information from the first slave device to return for the first data acquisition request within a preset second time period. If no data information from the first slave device to the first data acquisition request is received within the preset second time period, the first slave device can be forcibly taken offline, and the first slave device can be recorded as being offline. By adopting the above method, for two adjacent addresses in the address pool, while obtaining the device data information of the slave device corresponding to one address, the online status of the slave device corresponding to the other address can be confirmed simultaneously, which can reduce the polling time of the master device and confirm the online status of the slave device more quickly. Attached Figure Description

[0050] Figure 1 This is a flowchart illustrating the steps of a master-slave device communication method provided in an embodiment of the present invention;

[0051] Figure 2 This is a flowchart of another master-slave device communication method provided in an embodiment of the present invention;

[0052] Figure 3 This is a schematic diagram of the address pool and the slave device online status information pool according to an embodiment of the present invention;

[0053] Figure 4 This is a schematic diagram of the data packet format during the master-slave device communication process according to an embodiment of the present invention;

[0054] Figure 5 This is a timing diagram of the communication and exchange process between the master and slave devices according to an embodiment of the present invention;

[0055] Figure 6 This is a schematic diagram of the communication process according to an embodiment of the present invention;

[0056] Figure 7 This is a structural block diagram of a master-slave device communication device provided in an embodiment of the present invention. Detailed Implementation

[0057] To make the above-mentioned objects, features, and advantages of the present invention more apparent and understandable, the present invention will be further described in detail below with reference to the accompanying drawings and specific embodiments. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art are within the scope of protection of the present invention.

[0058] Master devices often use a polling method to communicate with slave devices. This means the master device continuously sends query signals to each slave device corresponding to its address. Even if only one slave device is online, all slave devices still need to be polled, wasting the master device's refresh time. Users cannot obtain timely status information from the master device. In this communication mode, the polling time increases with the number of slave devices, making the response time too slow in real-time applications, failing to meet the requirements of the entire system.

[0059] In addition to the communication modes mentioned above, the master device can also obtain the status information of a single slave device using the traditional on-demand method. This involves manually selecting a slave device corresponding to a specific address and sending a query signal to it to obtain its status information. However, this communication mode is not conducive to information exchange between multiple devices, as it only obtains partial information, which affects the master device's ability to comprehensively process and control the output.

[0060] Therefore, this invention relates to solving the problem of slow acquisition of slave device status information when the master device polls all mounted slave devices, and to solving the problem of affecting multi-device information interaction when acquiring slave device status information using traditional on-demand methods.

[0061] In this embodiment of the invention, while sending a data acquisition request to a first slave device to obtain its data information, the master device simultaneously sends a first online status confirmation request to a second slave device whose address is adjacent to the first slave device's to confirm the second slave device's online status. If a response from the second slave device to the first online status confirmation request is received within a preset first time period, the second slave device can be confirmed to be online. If no response from the second slave device to the first online status confirmation request is received within the preset first time period, the master device waits for the data information returned by the first slave device to the first data acquisition request within a preset second time period. If no data information is returned from the first slave device to the first data acquisition request within the preset second time period, the first slave device can be forcibly taken offline, and the first slave device is recorded as being offline. By adopting the above method, for two adjacent addresses in the address pool, while obtaining the device data information of the slave device corresponding to one address and confirming the online status of the slave device corresponding to the other address, the master device's polling time can be reduced, and the online status of the slave device can be confirmed more quickly.

[0062] Reference Figure 1 This diagram illustrates a flowchart of a master-slave device communication method according to an embodiment of the present invention. The method is applied to a master device, which is connected to a plurality of slave devices via a bus. The slave devices include a first slave device and a second slave device, whose addresses are adjacent. Specifically, the method may include the following steps:

[0063] Step 101: Send a first data acquisition request to the first slave device and a first online status confirmation request to the second slave device.

[0064] The master device stores an address pool, which records the addresses of each slave device that has established a communication connection with the master device, and the recorded addresses are in order.

[0065] The first data acquisition request is used to acquire data information from the first slave device; the first online status confirmation request is used to confirm the online status of the second slave device.

[0066] In this embodiment of the invention, the addresses of the first slave device and the second slave device are adjacent. While the master device sends a first data acquisition request to the first slave device, it can also send a first online status confirmation request to the second slave device.

[0067] Step 102: If a response is received from the second slave device in response to the first online status confirmation request within a preset first time period, then the second slave device is recorded as being in an online state.

[0068] If a response is received from the second slave device in response to the first online status confirmation request within a preset first time period, the second slave device can be recorded as being online. In a specific implementation, the master device stores a slave device online status information pool, which records the online status information of each slave device that has established a communication connection with the master device. The online status information may include whether the device is online or offline.

[0069] Step 103: If no response information is received from the second slave device for the first online status confirmation request within a preset first time period, then wait for the data information returned by the first slave device for the first data acquisition request within a preset second time period.

[0070] If no response is received from the second slave device for the first online status confirmation request within a preset first time period, the system can wait for the data information returned by the first slave device for the first data acquisition request within a preset second time period.

[0071] Step 104: If no data information is received from the first slave device in response to the first data acquisition request within the preset second time period, the first slave device is taken offline and recorded as being in an offline state.

[0072] If no data information is received from the first slave device in response to the first data acquisition request within the preset second time period, the first slave device can be forcibly taken offline, and the first slave device can be recorded as being in an offline state.

[0073] In summary, in this embodiment of the invention, while the master device sends a data acquisition request to the first slave device to obtain its data information, it simultaneously sends a first online status confirmation request to the second slave device whose address is adjacent to the first slave device's to confirm the online status of the second slave device. If a response from the second slave device to the first online status confirmation request is received within a preset first time period, the second slave device can be confirmed to be online. If no response from the second slave device to the first online status confirmation request is received within the preset first time period, the master device waits for the data information returned by the first slave device to the first data acquisition request within a preset second time period. If no data information returned by the first slave device to the first data acquisition request is received within the preset second time period, the first slave device can be forcibly taken offline, and the first slave device is recorded as being offline. By adopting the above method, for two adjacent addresses in the address pool, while obtaining the device data information of the slave device corresponding to one address, the online status of the slave device corresponding to the other address can be confirmed simultaneously, reducing the master device's polling time and enabling faster confirmation of the slave device's online status.

[0074] Reference Figure 2This diagram illustrates a flowchart of another master-slave device communication method provided by an embodiment of the present invention. The method is applied to a master device, which is connected to a bus of multiple slave devices. The multiple slave devices include a first slave device and a second slave device, whose addresses are adjacent. Specifically, the method may include the following steps:

[0075] Step 201: Send a first data acquisition request to the first slave device and a first online status confirmation request to the second slave device.

[0076] In practice, after the master device is powered on, it needs to update the online status information pool of the slave devices to confirm the online status information of the slave devices connected to the master device, and at the same time, obtain the data information of the online slave devices during the process of confirming the online status information.

[0077] For example, the master device can send data acquisition requests to the slave devices sequentially according to the address information in the address pool. For instance, it can send a data acquisition request to the slave device at address x, and at the same time send an online status confirmation request to the slave device at address x+1.

[0078] Step 202: If a response is received from the second slave device in response to the first online status confirmation request within a preset first time period, then the second slave device is recorded as being in an online state.

[0079] If a response is received from the slave device at address x+1 within time period T, it is confirmed that the slave device at address x+1 is online. In practice, the corresponding online status information in the slave device's online status information pool can be set to 1 to indicate that it is online.

[0080] Step 203: If no response information is received from the second slave device for the first online status confirmation request within a preset first time period, then wait for the data information returned by the first slave device for the first data acquisition request within a preset second time period.

[0081] If no response is received from the slave device at address x+1 within time period T, then wait for the slave device at address x to return its own data information within time period τ.

[0082] In an optional embodiment of the present invention, when a response from a second slave device to a first online status confirmation request is received within a preset first time period, the master-slave device communication method of the present invention may further include the following steps:

[0083] Within a preset second time period, wait for the data information returned by the first slave device in response to the first data acquisition request.

[0084] If a response is received from the slave device at address x+1 within time period T, then it is also necessary to wait for the slave device at address x to return its own data information within time period τ.

[0085] In practice, after time period T, regardless of whether the slave device at address x+1 is online, the slave device at address x needs to return its own data information to the master device within time period τ.

[0086] Step 204: If no data information is received from the first slave device in response to the first data acquisition request within the preset second time period, the first slave device is taken offline and recorded as being in an offline state.

[0087] If no data is received from the slave device at address x within the time period τ, the slave device at address x will be forced offline. The online status information of the slave device at address x will be set to 0, indicating that it is in an offline state. After that, no more data acquisition requests will be sent to the slave device at address x.

[0088] Step 205: Continue to wait for the response information returned by the second slave device in response to the first online status confirmation request within the preset third time period.

[0089] After the time period τ has elapsed, the master device can continue to wait for the time period t, during which it waits for the response information from the slave device at address x+1. In this embodiment of the invention, the response information specifically refers to the ACK response information.

[0090] Step 206: If a response is received from the second slave device in response to the first online status confirmation request within a preset third time period, then the second slave device is recorded as being in an online state.

[0091] If a response message is received from the slave device at address x+1 within the time period t, it is confirmed that the slave device at address x+1 is online, and the online status information of the slave device at address x+1 is set to 1.

[0092] Step 207: If no response information is received from the second slave device for the first online status confirmation request within the preset third time period, then the second slave device is recorded as being in an offline state.

[0093] If no response is received from the slave device at address x+1 within the time period t, it is confirmed that the slave device at address x+1 is offline. The online status information of the slave device at address x+1 is then set to 0. At this point, the master device has completed the processing of this data acquisition request and online status confirmation request.

[0094] In an optional embodiment of the present invention, the plurality of slave devices includes a third slave device, which is another slave device adjacent to the second slave device. The plurality of slave devices also includes a fourth slave device and a fifth slave device, the fourth slave device and the fifth slave device having adjacent addresses. The master-slave device communication method of the present invention may further include the following steps:

[0095] If the second slave device is online, a second data acquisition request is sent to the second slave device, and a second online status confirmation request is sent to the third slave device.

[0096] If the second slave device is offline, a third data acquisition request is sent to the fourth slave device, and a third online status confirmation request is sent to the fifth slave device.

[0097] Furthermore, if the slave device at address x+1 is online, a data acquisition request is sent to the slave device at address x+1, and an online status confirmation request is sent to the slave device at address x+2; if the slave device at address x+1 is offline, a data acquisition request is sent to the slave device at address y, and an online status confirmation request is sent to the slave device at address y+1, until all slave devices in the address pool have been traversed, and the online status information of all slave devices in the slave device online status information pool has been updated.

[0098] like Figure 3 The diagram illustrates the address pool and slave device online status information pool according to an embodiment of the present invention. Each address in the address pool corresponds to a slave device, and each online status information pool in the slave device online status information pool corresponds to a slave device. There is a one-to-one correspondence between the slave devices in the address pool and the slave devices in the slave device online status information pool. 1 indicates that the slave device corresponding to the current address is online, and 0 indicates that the slave device corresponding to the current address is offline. Figure 4 The diagram shown illustrates the data packet format during master-slave device communication according to an embodiment of the present invention. The data acquisition request data packet sent by the master device includes a start bit, slave device address bits, operation instruction code, data acquisition length bits, check bit, and stop bit; the data information data packet returned by the slave device includes a start bit, local slave device address bits, data length bits, data bits, check bit, and stop bit.

[0099] In an optional embodiment of the present invention, the master-slave device communication method of the present invention may further include the following steps:

[0100] After updating the online status of each of the multiple slave devices, the target slave device that is recorded as being online is identified, a fourth data acquisition request is sent to the target slave device, and no fourth online status confirmation request is sent to the adjacent slave devices adjacent to the target slave device.

[0101] After updating the online status information of all slave devices in the online status information pool, when sending data retrieval requests to slave devices, the request can be sent only to slave devices that are online. For example, a data retrieval request can be sent to the slave device at address z that is online to retrieve the data information of the slave device at address z. At this time, it is no longer necessary to confirm the previous status information of the slave device at address z+1, that is, no longer send an online status confirmation request to the slave device at address z+1.

[0102] In an optional embodiment of the present invention, the master-slave device communication method of the present invention may further include the following steps:

[0103] If no data information is received from the target slave device in response to the fourth data acquisition request within the preset fourth time period, the target slave device will be taken offline and recorded as being in an offline state.

[0104] If no data is received from the slave device at address z within the time period τ, the slave device at address z will be forced offline. The online status information of the slave device at address z will be set to 0, indicating that it is in an offline state. After that, no more data acquisition requests will be sent to the slave device at address z.

[0105] In an optional embodiment of the present invention, the master device is connected to the newly added slave device via a bus, and the master-slave device communication method of the present invention may further include the following steps:

[0106] Obtain the address information to be assigned, and assign an address to the new slave device based on the address information to be assigned; wherein, the address information to be assigned is the previous address of the offline slave device that is in an offline state.

[0107] In practice, after a new slave device is powered on for the first time, its address is set to the default value. The new slave device can establish a bus connection with the master device through the bus. After the master device completes a round of updating the online status information of all slave devices in the online status information pool, it can send an address allocation instruction to the new slave device, select one of the previously recorded offline slave devices and allocate it to the new slave device, and set the online status information corresponding to that address to 1.

[0108] It is understood that, for the convenience of those skilled in the art, in this embodiment of the invention, the first slave device is described as the slave device at address x, the second slave device as the slave device at address x+1, the preset first time period is described as time period T, the preset second time period as time period τ, the preset third time period as time period t, the third slave device as the slave device at address x+2, the fourth slave device as the slave device at address y, the fifth slave device as the slave device at address y+1, and the slave device at address z is specifically the target slave device that is online and recorded later. The timing diagram of the master-slave device communication exchange process can be specifically as follows: Figure 5 As shown in the diagram, the communication process described in the embodiments of the present invention can be specifically illustrated as follows: Figure 6 As shown.

[0109] In summary, in this embodiment of the invention, while the master device sends a data acquisition request to the first slave device to obtain its data information, it simultaneously sends a first online status confirmation request to the second slave device whose address is adjacent to the first slave device's to confirm the online status of the second slave device. If a response from the second slave device to the first online status confirmation request is received within a preset first time period, the second slave device can be confirmed to be online. If no response from the second slave device to the first online status confirmation request is received within the preset first time period, the master device waits for the data information returned by the first slave device to the first data acquisition request within a preset second time period. If no data information returned by the first slave device to the first data acquisition request is received within the preset second time period, the first slave device can be forcibly taken offline, and the first slave device is recorded as being offline. By adopting the above method, for two adjacent addresses in the address pool, while obtaining the device data information of the slave device corresponding to one address, the online status of the slave device corresponding to the other address can be confirmed simultaneously, reducing the master device's polling time and enabling faster confirmation of the slave device's online status.

[0110] The technical solution of this invention effectively reduces the polling of offline device data acquisition by constructing a communication timing method and updating the set slave device online status information pool, thus solving the problem of slow acquisition of master and slave device system data.

[0111] This invention targets two adjacent addresses in the address pool, acquires device data information, confirms online devices to update online status information, and reclaims addresses of unresponsive devices. Then, by acquiring data information from the updated device online status information pool, it realizes address reclamation after a device has been offline for a long time.

[0112] It should be noted that, for the sake of simplicity, the method embodiments are all described as a series of actions. However, those skilled in the art should understand that the embodiments of the present invention are not limited to the described order of actions, because according to the embodiments of the present invention, some steps can be performed in other orders or simultaneously. Furthermore, those skilled in the art should also understand that the embodiments described in the specification are preferred embodiments, and the actions involved are not necessarily essential to the embodiments of the present invention.

[0113] Reference Figure 7This diagram illustrates a structural block diagram of a master-slave device communication device according to an embodiment of the present invention. The device is applied to a master device, which is connected to a plurality of slave devices via a bus. The plurality of slave devices include a first slave device and a second slave device, whose addresses are adjacent. Specifically, the device may include the following modules:

[0114] The first data acquisition request and first online status confirmation request sending module 701 is used to send a first data acquisition request to the first slave device and a first online status confirmation request to the second slave device;

[0115] The online status recording module 702 is used to record that the second slave device is in an online state if it receives a response from the second slave device in response to the first online status confirmation request within a preset first time period.

[0116] The data information waiting module 703 is used to wait for the data information returned by the first slave device in response to the first data acquisition request within a preset second time period if no response information is received from the second slave device in response to the first online status confirmation request within the preset first time period.

[0117] The offline and offline status recording module 704 is used to take the first slave device offline and record that the first slave device is in an offline state if no data information is received from the first slave device in response to the first data acquisition request within the preset second time period.

[0118] In this embodiment of the invention, the device further includes:

[0119] The response information waiting module is used to continue waiting for the response information returned by the second slave device in response to the first online status confirmation request within a preset third time period;

[0120] The second online status recording module is used to record that the second slave device is in an online state if it receives a response from the second slave device in response to the first online status confirmation request within the preset third time period.

[0121] The offline status recording module is used to record that the second slave device is in an offline state if no response information is received from the second slave device in response to the first online status confirmation request within the preset third time period.

[0122] In this embodiment of the invention, the plurality of slave devices includes a third slave device, which is another slave device adjacent to the second slave device. The plurality of slave devices also includes a fourth slave device and a fifth slave device, wherein the fourth slave device and the fifth slave device are address-adjacent. The apparatus further includes:

[0123] The second data acquisition request and second online status confirmation request sending module is used to send a second data acquisition request to the second slave device and a second online status confirmation request to the third slave device if the second slave device is online.

[0124] The third data acquisition request and third online status confirmation request sending module is used to send a third data acquisition request to the fourth slave device and a third online status confirmation request to the fifth slave device if the second slave device is offline.

[0125] In this embodiment of the invention, the device further includes:

[0126] The fourth data acquisition request sending module is used to determine the target slave device that is recorded as being online after updating the online status of each of the plurality of slave devices, send a fourth data acquisition request to the target slave device, and no longer send a fourth online status confirmation request to the adjacent slave devices adjacent to the target slave device.

[0127] In this embodiment of the invention, the device further includes:

[0128] The target slave device offline and offline status recording module is used to take the target slave device offline and record that the target slave device is in an offline state if no data information is received from the target slave device in response to the fourth data acquisition request within a preset fourth time period.

[0129] In this embodiment of the invention, when the response information returned by the second slave device in response to the first online status confirmation request is received within a preset first time period, the device further includes:

[0130] The second data information waiting module is used to wait for the data information returned by the first slave device in response to the first data acquisition request within the preset second time period.

[0131] In this embodiment of the invention, the master device is bus-connected to the newly added slave device, and the apparatus further includes:

[0132] The module for obtaining and allocating address information to be assigned is used to obtain address information to be assigned and to assign an address to the newly added slave device based on the address information to be assigned; wherein, the address information to be assigned is the previously recorded address of an offline slave device that is in an offline state.

[0133] In summary, in this embodiment of the invention, while the master device sends a data acquisition request to the first slave device to obtain its data information, it simultaneously sends a first online status confirmation request to the second slave device whose address is adjacent to the first slave device's to confirm the online status of the second slave device. If a response from the second slave device to the first online status confirmation request is received within a preset first time period, the second slave device can be confirmed to be online. If no response from the second slave device to the first online status confirmation request is received within the preset first time period, the master device waits for the data information returned by the first slave device to the first data acquisition request within a preset second time period. If no data information returned by the first slave device to the first data acquisition request is received within the preset second time period, the first slave device can be forcibly taken offline, and the first slave device is recorded as being offline. By adopting the above method, for two adjacent addresses in the address pool, while obtaining the device data information of the slave device corresponding to one address, the online status of the slave device corresponding to the other address can be confirmed simultaneously, reducing the master device's polling time and enabling faster confirmation of the slave device's online status.

[0134] As the device embodiment is basically similar to the method embodiment, the description is relatively simple, and relevant parts can be found in the description of the method embodiment.

[0135] This invention also provides an electronic device, including: a processor, a memory, and a computer program stored in the memory and capable of running on the processor. When the computer program is executed by the processor, it implements the various processes of the above-described master-slave device communication method embodiment and achieves the same technical effect. To avoid repetition, it will not be described again here.

[0136] This invention also provides a computer-readable storage medium storing a computer program. When the computer program is executed by a processor, it implements the various processes of the above-described master-slave device communication method embodiment and achieves the same technical effect. To avoid repetition, it will not be described again here.

[0137] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on the differences from other embodiments. The same or similar parts between the various embodiments can be referred to each other.

[0138] Those skilled in the art will understand that embodiments of the present invention can be provided as methods, apparatus, or computer program products. Therefore, embodiments of the present invention can take the form of entirely hardware embodiments, entirely software embodiments, or embodiments combining software and hardware aspects. Furthermore, embodiments of the present invention can take the form of computer program products implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0139] This invention is described with reference to flowchart illustrations and / or block diagrams of methods, terminal devices (systems), and computer program products according to embodiments of the invention. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing terminal device to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing terminal device, generate instructions for implementing the flowchart illustrations and / or block diagrams. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.

[0140] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing terminal device to operate in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.

[0141] These computer program instructions can also be loaded onto a computer or other programmable data processing terminal equipment, causing a series of operational steps to be performed on the computer or other programmable terminal equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable terminal equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.

[0142] Although preferred embodiments of the present invention have been described, those skilled in the art, upon learning the basic inventive concept, can make other changes and modifications to these embodiments. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments as well as all changes and modifications falling within the scope of the embodiments of the present invention.

[0143] Finally, it should be noted that in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or terminal device that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or terminal device. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or terminal device that includes said element.

[0144] The foregoing has provided a detailed description of a master-slave device communication method, a master-slave device communication apparatus, an electronic device, and a computer-readable storage medium provided by the present invention. Specific examples have been used to illustrate the principles and implementation methods of the present invention. The descriptions of the above embodiments are only for the purpose of helping to understand the method and core ideas of the present invention. At the same time, for those skilled in the art, there will be changes in specific implementation methods and application scope based on the ideas of the present invention. Therefore, the content of this specification should not be construed as a limitation of the present invention.

Claims

1. A master-slave device communication method, characterized in that, Applied to a master device, the master device is connected to a plurality of slave devices via a bus, the plurality of slave devices including a first slave device and a second slave device, the first slave device and the second slave device having adjacent addresses, the method comprising: Send a first data acquisition request to the first slave device and a first online status confirmation request to the second slave device; If a response is received from the second slave device in response to the first online status confirmation request within a preset first time period, then the second slave device is recorded as being in an online state. If no response information is received from the second slave device in response to the first online status confirmation request within the preset first time period, then wait for the data information to be returned by the first slave device in response to the first data acquisition request within the preset second time period; If no data information is received from the first slave device in response to the first data acquisition request within the preset second time period, the first slave device is taken offline and recorded as being in an offline state. The method further includes, after waiting for the data information returned by the first slave device in response to the first data acquisition request within a preset second time period: Continue to wait for the response information returned by the second slave device in response to the first online status confirmation request within the preset third time period; If a response is received from the second slave device in response to the first online status confirmation request within the preset third time period, then the second slave device is recorded as being in an online state. If no response is received from the second slave device in response to the first online status confirmation request within the preset third time period, the second slave device is recorded as being in an offline state.

2. The method according to claim 1, characterized in that, The plurality of slave devices includes a third slave device, which is another slave device adjacent to the second slave device. The plurality of slave devices also includes a fourth slave device and a fifth slave device, wherein the fourth slave device and the fifth slave device are address-adjacent. The method further includes: If the second slave device is online, a second data acquisition request is sent to the second slave device, and a second online status confirmation request is sent to the third slave device; If the second slave device is offline, a third data acquisition request is sent to the fourth slave device, and a third online status confirmation request is sent to the fifth slave device.

3. The method according to claim 2, characterized in that, The method further includes: After updating the online status of each of the plurality of slave devices, a target slave device that is recorded as being online is identified, a fourth data acquisition request is sent to the target slave device, and no fourth online status confirmation request is sent to the adjacent slave devices adjacent to the target slave device.

4. The method according to claim 3, characterized in that, The method further includes: If no data information is received from the target slave device in response to the fourth data acquisition request within the preset fourth time period, the target slave device is taken offline, and the target slave device is recorded as being in an offline state.

5. The method according to claim 1, characterized in that, If, within a preset first time period, a response is received from the second slave device in response to the first online status confirmation request, the method further includes: During the preset second time period, wait for the data information returned by the first slave device in response to the first data acquisition request.

6. The method according to claim 1, characterized in that, The master device is connected to the newly added slave device via a bus, and the method further includes: Obtain the address information to be assigned, and assign an address to the newly added slave device according to the address information to be assigned; wherein, the address information to be assigned is the previously recorded address of an offline slave device that is in an offline state.

7. A master-slave device communication apparatus, characterized in that, Applied to a master device, the master device is connected to a plurality of slave devices via a bus, the plurality of slave devices including a first slave device and a second slave device, the first slave device and the second slave device having adjacent addresses, the device comprising: The first data acquisition request and first online status confirmation request sending module is used to send a first data acquisition request to the first slave device and a first online status confirmation request to the second slave device; The first online status recording module is used to record that the second slave device is in an online state if it receives a response from the second slave device in response to the first online status confirmation request within a preset first time period. The first data information waiting module is used to wait for the data information returned by the first slave device in response to the first data acquisition request within a preset second time period if no response information is received from the second slave device in response to the first online status confirmation request within the preset first time period. The first slave device offline and offline status recording module is used to take the first slave device offline and record that the first slave device is in an offline state if no data information is received from the first slave device in response to the first data acquisition request within the preset second time period. The response information waiting module is used to continue waiting for the response information returned by the second slave device in response to the first online status confirmation request within a preset third time period; The second online status recording module is used to record that the second slave device is in an online state if it receives a response from the second slave device in response to the first online status confirmation request within the preset third time period. The offline status recording module is used to record that the second slave device is in an offline state if no response information is received from the second slave device in response to the first online status confirmation request within the preset third time period.

8. An electronic device, characterized in that, include: A processor, a memory, and a computer program stored in the memory and capable of running on the processor, wherein the computer program, when executed by the processor, implements a master-slave device communication method as described in any one of claims 1-6.

9. A computer-readable storage medium, characterized in that, A computer program is stored on the computer-readable storage medium, which, when executed by a processor, implements a master-slave device communication method as described in any one of claims 1 to 6.

Citation Information

Patent Citations

  • Automatic addressing system of master device to slave device

    CN101482749A

  • Protocol conversion gateway state monitoring method and device

    CN110048903A