CN116938632A - Master-slave device communication method and device, electronic device and readable storage medium - Google Patents

Master-slave device communication method and device, electronic device and readable storage medium Download PDF

Info

Publication number
CN116938632A
CN116938632A CN202310858778.5A CN202310858778A CN116938632A CN 116938632 A CN116938632 A CN 116938632A CN 202310858778 A CN202310858778 A CN 202310858778A CN 116938632 A CN116938632 A CN 116938632A
Authority
CN
China
Prior art keywords
slave device
slave
preset
data acquisition
online state
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202310858778.5A
Other languages
Chinese (zh)
Inventor
杨思城
李荫珑
廖坤
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Gree Electric Appliances Inc of Zhuhai
Original Assignee
Gree Electric Appliances Inc of Zhuhai
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Gree Electric Appliances Inc of Zhuhai filed Critical Gree Electric Appliances Inc of Zhuhai
Priority to CN202310858778.5A priority Critical patent/CN116938632A/en
Publication of CN116938632A publication Critical patent/CN116938632A/en
Pending legal-status Critical Current

Links

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 following steps: transmitting a first data acquisition request to a first slave device and transmitting a first presence confirmation request to a second slave device; if the response information returned by the second slave device for the first online state confirmation request is received within the 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 a 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 a preset second time period, the first slave device is disconnected, and the first slave device is recorded to be in an offline state. 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.

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 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.
Optionally, 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.
Optionally, 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.
Optionally, in a case that response information returned by the second slave device for the first presence confirmation request is received in a preset first period of time, the method further includes:
And waiting for data information returned by the first slave device for the first data acquisition request in the preset second time period.
Optionally, the master device is connected with the newly added slave device bus, and the method further comprises:
acquiring address information to be allocated, and allocating an address to the newly added slave device according to the address information to be allocated; the address information to be allocated is the recorded prior address of the offline slave device in the offline state.
The embodiment of the invention also discloses a master-slave device communication device 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 device comprises:
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 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 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;
and the offline and offline state recording module is used for downloading the first slave device and recording that the first slave device is in an offline state 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.
Optionally, the apparatus further comprises:
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.
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 apparatus further including:
the second data acquisition request and second online state confirmation request sending module is used for sending a second data acquisition request to the second slave device and sending a second online state confirmation request to the third slave device if the second slave device is in an online state;
and the third data acquisition request and third online state confirmation request sending module is used for sending a third data acquisition request to the fourth slave device and sending a third online state confirmation request to the fifth slave device if the second slave device is in an offline state.
Optionally, the apparatus further comprises:
and the fourth data acquisition request sending module is used for determining the recorded target slave equipment in the online state after updating the online state of each slave equipment in the plurality of slave equipment, sending a fourth data acquisition request to the target slave equipment, and not sending a fourth online state confirmation request to the adjacent slave equipment adjacent to the target slave equipment.
Optionally, the apparatus further comprises:
and the target slave device offline and offline state recording module is used for offline the target slave device and recording that the target slave device is in an offline state if the data information returned by the target slave device for the fourth data acquisition request is not received within a preset fourth time period.
Optionally, when receiving response information returned by the second slave device for the first presence confirmation request in a preset first period of time, the apparatus further includes:
and the second 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 the preset second time period.
Optionally, the master device is connected with the newly added slave device bus, and the apparatus further includes:
the address information acquisition and address allocation module is used for acquiring the address information to be allocated and allocating an address to the newly added slave device according to the address information to be allocated; the address information to be allocated is the recorded prior address of the offline slave device in the offline state.
The embodiment of the invention also discloses an electronic device, which comprises: a processor, a memory and a computer program stored on the memory and capable of running on the processor, which when executed by the processor implements a master-slave device communication method as described above.
The embodiment of the invention also discloses a computer readable storage medium, wherein the computer readable storage medium stores a computer program, and the computer program realizes the master-slave device communication method when being executed by a processor.
The embodiment of the invention has the following advantages:
in the embodiment of the invention, the master device sends a first online state confirmation request to a second slave device adjacent to the address of the first slave device and confirms the online state of the second slave device while sending a data acquisition request to the first slave device to acquire the data information of the first slave device. If the response information returned by the second slave device for the first online state confirmation request is received within the preset first time period, the second slave device can be confirmed to be 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 a 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 can be forced to be disconnected, and the first slave device is recorded to be in an offline state. By adopting the method, the on-line state of the slave device corresponding to one address is confirmed while the device data information of the slave device corresponding to the other address is acquired for two adjacent addresses in the address pool, so that the polling time of the master device can be reduced, and the on-line state of the slave device can be confirmed more quickly.
Drawings
FIG. 1 is a flow chart of steps of a method for communication between a master device and a slave device according to an embodiment of the present invention;
FIG. 2 is a flow chart of steps of another communication method of a master-slave device according to an embodiment of the present invention;
FIG. 3 is a schematic diagram of an address pool and slave device presence information pool in accordance with an embodiment of the present invention;
FIG. 4 is a schematic diagram of a packet format during communication between a master device and a slave device according to an embodiment of the present invention;
FIG. 5 is a timing diagram of a master-slave communication exchange process in accordance with an embodiment of the present invention;
FIG. 6 is a schematic illustration of a communication process according to an embodiment of the invention;
fig. 7 is a block diagram of a communication apparatus of a master-slave device according to an embodiment of the present invention.
Detailed Description
So that the manner in which the above recited objects, features and advantages of the present invention can be understood in detail, a more particular description of the invention, briefly summarized above, may be had by reference to the embodiments, some of which are illustrated in the appended drawings, and some, but not all of which are illustrated in the appended drawings. All other embodiments, which are derived by a person skilled in the art based on the embodiments of the invention, fall within the scope of protection of the invention.
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.
Therefore, the invention relates to the problem that the state information of the slave device is slow to acquire when the master device polls all the mounted slave devices, and the problem that the information interaction of multiple devices is affected by acquiring the state information of the slave device in a traditional on-demand mode.
According to the embodiment of the invention, the master device sends the data acquisition request to the first slave device to acquire the data information of the first slave device, and simultaneously sends the first online state confirmation request to the second slave device adjacent to the address of the first slave device to confirm the online state of the second slave device. If the response information returned by the second slave device for the first online state confirmation request is received within the preset first time period, the second slave device can be confirmed to be 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 a 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 can be forced to be disconnected, and the first slave device is recorded to be in an offline state. By adopting the method, the on-line state of the slave device corresponding to one address is confirmed while the device data information of the slave device corresponding to the other address is acquired for two adjacent addresses in the address pool, so that the polling time of the master device can be reduced, and the on-line state of the slave device can be confirmed more quickly.
Referring to fig. 1, a step flowchart of a master-slave communication method provided by an embodiment of the present invention is shown and applied to a master device, where the master device is respectively connected to a plurality of slave devices through buses, and the plurality of slave devices include a first slave device and a second slave device, and addresses of the first slave device and the second slave device are adjacent to each other, and specifically may include the following steps:
step 101, a first data acquisition request is sent to a first slave device, and a first presence confirmation request is sent to a second slave device.
The master device has stored therein an address pool in which addresses of respective slave devices that establish communication connection with the master device are recorded, and the recorded addresses are ordered.
The first data acquisition request is used for acquiring data information of the first slave device; the first presence confirmation request is for confirming the presence of the second slave device.
In the embodiment of the invention, the addresses of the first slave device and the second slave device are adjacent, and the master device can send the first online state confirmation request to the second slave device while sending the first data acquisition request to the first slave device.
Step 102, if the response information returned by the second slave device for the first online state confirmation request is received within the preset first period of time, 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 received within the preset first time period, the second slave device can be recorded to be in an online state. In a specific implementation, the master device stores a slave device presence information pool, in which presence information of each slave device that establishes a communication connection with the master device is recorded, where the presence information may include being in a presence state or being in an offline state.
Step 103, if no response information returned by the second slave device for the first online status confirmation request is received within a preset first period of time, waiting for data information returned by the first slave device for the first data acquisition request within a preset second period of time.
If the response information returned by the second slave device for the first online status confirmation request is not received within the preset first time period, the data information returned by the first slave device for the first data acquisition request can be waited for within the preset second time period.
Step 104, 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.
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 can be forced to be disconnected, and the first slave device is recorded to be in an offline state.
In summary, in the embodiment of the present invention, the master device sends a data acquisition request to the first slave device to acquire data information of the first slave device, and simultaneously sends a first presence confirmation request to the second slave device adjacent to the address of the first slave device, so as to confirm the presence of the second slave device. If the response information returned by the second slave device for the first online state confirmation request is received within the preset first time period, the second slave device can be confirmed to be 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 a 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 can be forced to be disconnected, and the first slave device is recorded to be in an offline state. By adopting the method, the on-line state of the slave device corresponding to one address is confirmed while the device data information of the slave device corresponding to the other address is acquired for two adjacent addresses in the address pool, so that the polling time of the master device can be reduced, and the on-line state of the slave device can be confirmed more quickly.
Referring to fig. 2, a step flow chart of another communication method of a master device and a slave device provided by an embodiment of the present invention is shown and applied to the master device, where the master device is respectively connected to a plurality of slave devices through buses, and the plurality of slave devices include a first slave device and a second slave device, and addresses of the first slave device and the second slave device are adjacent, and specifically may include the following steps:
step 201, a first data acquisition request is sent to a first slave device and a first presence confirmation request is sent to a second slave device.
In a specific implementation, after the master device is powered on, the slave device presence information pool needs to be updated, the presence information of the slave device mounting the master device is confirmed, and meanwhile, the data information of the online slave device is acquired in the process of confirming the presence information.
For example, the master device may sequentially send data acquisition requests to the slave devices according to the address information in the address pool, for example, may send data acquisition requests to the slave device of address x, and may send presence confirmation requests to the slave device of address x+1.
Step 202, if the response information returned by the second slave device for the first online status confirmation request is received within the preset first period of time, recording that the second slave device is in an online status.
If the response information returned by the slave device of the address x+1 is received in the T time period, the slave device of the address x+1 is confirmed to be in an on-line state. In particular implementations, the corresponding presence information in the slave device presence information pool may be set to 1, indicating that it is in presence.
In step 203, if the response information returned by the second slave device for the first online status confirmation request is not received within the preset first period of time, waiting for the data information returned by the first slave device for the first data acquisition request within the preset second period of time.
If the response information returned by the slave device of the address x+1 is not received in the T period, the slave device waiting for the address x returns the own data information in the tau period.
In an optional embodiment of the present invention, when receiving the response information returned by the second slave device for the first presence status confirmation request in a preset first period of time, the master-slave device communication method of the present invention specifically further includes the following steps:
and 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 from the slave device at address x+1 is received within the T period, it is also necessary to wait for the slave device at address x to return its own data information within the τ period.
In a specific implementation, after the T period, no matter whether the slave device of the address x+1 is in an online state or not, the slave device of the address x needs to return its own data information to the master device within the τ period.
And 204, 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.
If the data information returned by the slave device of the address x is not received within the tau time period, the slave device of the address x is forced to be in a low-line state, the on-line state information of the slave device of the address x is set to 0, the slave device is in an off-line state, and then a data acquisition request is not sent to the slave device of the address x.
And step 205, continuing to wait for response information returned by the second slave device for the first online status confirmation request within a preset third time period.
After the τ period, the master device may continue to wait for a t period, and wait for the response information of the slave device with the address x+1 in the t period.
And step 206, if the response information returned by the second slave device for the first online state confirmation request is received within the preset third time period, recording that the second slave device is in an online state.
If the response information of the slave device with the address x+1 is received in the t time period, the slave device with the address x+1 is confirmed to be in an online state, and the online state information of the slave device with the address x+1 is set to be 1.
And step 207, 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.
If the response information of the slave device with the address x+1 is not received in the t time period, the slave device with the address x+1 is confirmed to be in an offline state, the online state information of the slave device with the address x+1 is set to be 0, and the processing of the data acquisition request and the online state confirmation request of the master device is completed.
In an optional embodiment of the present invention, 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 includes a fourth slave device and a fifth slave device, addresses of the fourth slave device and the fifth slave device are adjacent, and the master-slave device communication method of the present invention may specifically further include the steps of:
and if the second slave device is in the online state, sending a second data acquisition request to the second slave device, and sending a second online state confirmation request 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.
Further, if the slave device of address x+1 is in an online state, sending a data acquisition request to the slave device of address x+1 and sending an online state confirmation request to the slave device of address x+2; if the slave device of the address x+1 is in an offline state, sending a data acquisition request to the slave device of the address y, and sending a presence state confirmation request to the slave device of the address y+1 until all slave devices in the address pool are traversed, and completing the update of the presence state information of all slave devices in the presence state information pool of the slave devices.
As shown in fig. 3, a schematic diagram of an address pool and a slave device presence information pool according to an embodiment of the present invention is shown, where each address in the address pool corresponds to a slave device, each presence information pool in the slave device presence information pool corresponds to a slave device, the slave devices in the address pool correspond to the slave devices in the slave device presence information pool one-to-one, 1 indicates that the slave device corresponding to the current address is in an online state, and 0 indicates that the slave device corresponding to the current address is in an offline state. Fig. 4 is a schematic diagram of a data packet format in a communication process of a master device and a slave device according to an embodiment of the present invention. The data acquisition request data packet sent by the master device comprises a start bit, a slave device address bit, an operation instruction code, an acquisition data length bit, a check bit and a termination bit; the data information data packet returned from the slave device includes a start bit, a present slave device address bit, a data length bit, a data bit, a check bit, and a termination bit.
In an optional embodiment of the present invention, the master-slave device communication method of the present invention may specifically further include the following steps:
after the presence status is updated for each of the plurality of slaves, the recorded target slave in the presence status is determined, a fourth data acquisition request is sent to the target slave, and a fourth presence status confirmation request is no longer sent to neighboring slaves adjacent to the target slave.
When the data acquisition request is subsequently sent to the slave device after the update of the presence information of all the slave devices in the presence information pool of the slave device is completed, the data acquisition request may be sent only to the slave device in the presence state, for example, the data acquisition request may be sent to the slave device in the presence state at the address z to acquire the data information of the slave device at the address z, and at this time, the previous state information of the slave device at the address z+1 does not need to be confirmed, that is, the presence confirmation request is not sent to the slave device at the address z+1.
In an optional embodiment of the present invention, the master-slave device communication method of the present invention may specifically further include the following steps:
if the data information returned by the target slave device for the fourth data acquisition request is not received within the preset fourth time period, the target slave device is disconnected, and the target slave device is recorded to be in an offline state.
If the data information returned by the slave device of the address z is not received within the tau time period, the slave device of the address z is forced to be in a low-line state, the on-line state information of the slave device of the address z is set to 0, the slave device of the address z is in an off-line state, and then a data acquisition request is not sent to the slave device of the address z.
In an optional embodiment of the present invention, the master device is connected to the newly added slave device bus, and the master-slave device communication method of the present invention specifically further includes the following steps:
the method comprises the steps of obtaining address information to be allocated, and allocating an address for newly added slave equipment according to the address information to be allocated; the address information to be allocated is the recorded prior address of the offline slave device in the offline state.
In a specific implementation, after the newly added slave device gets power for the first time, the address of the newly added slave device is a default value, the newly added slave device can establish bus connection with the master device through the mounting bus, after finishing updating the online state information of all slave devices in the online state information pool of one round of slave devices, the master device can send an address allocation instruction to the newly added slave device, alternatively allocate the recorded previous address of the offline slave device in an offline state to the newly added slave device, and set the online state information corresponding to the address to be 1.
It may be appreciated that, for a person skilled in the art to understand the present disclosure, the first slave device is described as a slave device of address x, the second slave device is described as a slave device of address x+1, the preset first period is described as a T period, the preset second period is described as a τ period, the preset third period is described as a T period, the third slave device is described as a slave device of x+2, the fourth slave device is described as a slave device of address y, the fifth slave device is described as a slave device of address y+1, and the slave device of address z is specifically a target slave device in an online state that is recorded later. The timing diagram of the communication exchange process of the master device and the slave device may be shown in fig. 5, and the schematic diagram of the communication process described in the embodiment of the present invention may be shown in fig. 6.
In summary, in the embodiment of the present invention, the master device sends a data acquisition request to the first slave device to acquire data information of the first slave device, and simultaneously sends a first presence confirmation request to the second slave device adjacent to the address of the first slave device, so as to confirm the presence of the second slave device. If the response information returned by the second slave device for the first online state confirmation request is received within the preset first time period, the second slave device can be confirmed to be 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 a 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 can be forced to be disconnected, and the first slave device is recorded to be in an offline state. By adopting the method, the on-line state of the slave device corresponding to one address is confirmed while the device data information of the slave device corresponding to the other address is acquired for two adjacent addresses in the address pool, so that the polling time of the master device can be reduced, and the on-line state of the slave device can be confirmed more quickly.
According to the technical scheme, the communication time sequence mode is constructed, the set slave equipment online state information pool is updated, the polling off-line equipment data acquisition is effectively reduced, and the problem of slow acquisition of master-slave equipment system data is solved.
Aiming at two adjacent addresses in an address pool, the invention confirms online equipment to update online state information while acquiring equipment data information, and recovers equipment addresses which are not responded; and then, acquiring data information from the updated equipment in the slave equipment online state information pool, so that the address recovery after the equipment is offline for a long time is realized.
It should be noted that, for simplicity of description, the method embodiments are shown as a series of acts, but it should be understood by those skilled in the art that the embodiments are not limited by the order of acts, as some steps may occur in other orders or concurrently in accordance with the embodiments. Further, those skilled in the art will appreciate that the embodiments described in the specification are presently preferred embodiments, and that the acts are not necessarily required by the embodiments of the invention.
Referring to fig. 7, a block diagram of a master-slave communication apparatus provided by an embodiment of the present invention is shown and applied to a master device, where the master device is respectively connected to a plurality of slave devices through buses, and the plurality of slave devices include a first slave device and a second slave device, where addresses of the first slave device and the second slave device are adjacent to each other, and the block may specifically include the following modules:
A first data acquisition request and first online status confirmation request sending module 701, configured to send a first data acquisition request to the first slave device, and send a first online status confirmation request to the second slave device;
the online state recording module 702 is configured to record 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 period of time;
a data information waiting module 703, configured to wait for, in a preset second period of time, data information returned by the first slave device for the first data acquisition request if no response information returned by the second slave device for the first online status confirmation request is received in the preset first period of time;
and a offline and offline state recording module 704, configured to, if data information returned by the first slave device for the first data acquisition request is not received within the preset second period of time, offline the first slave device, and record that the first slave device is in an offline state.
In an embodiment of the present invention, the apparatus further includes:
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.
In an embodiment of the present invention, 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, addresses of the fourth slave device and the fifth slave device being adjacent, the apparatus further includes:
the second data acquisition request and second online state confirmation request sending module is used for sending a second data acquisition request to the second slave device and sending a second online state confirmation request to the third slave device if the second slave device is in an online state;
and the third data acquisition request and third online state confirmation request sending module is used for sending a third data acquisition request to the fourth slave device and sending a third online state confirmation request to the fifth slave device if the second slave device is in an offline state.
In an embodiment of the present invention, the apparatus further includes:
and the fourth data acquisition request sending module is used for determining the recorded target slave equipment in the online state after updating the online state of each slave equipment in the plurality of slave equipment, sending a fourth data acquisition request to the target slave equipment, and not sending a fourth online state confirmation request to the adjacent slave equipment adjacent to the target slave equipment.
In an embodiment of the present invention, the apparatus further includes:
and the target slave device offline and offline state recording module is used for offline the target slave device and recording that the target slave device is in an offline state if the data information returned by the target slave device for the fourth data acquisition request is not received within a preset fourth time period.
In the embodiment of the present invention, when receiving, within a preset first period of time, response information returned by the second slave device for the first online status confirmation request, the apparatus further includes:
and the second 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 the preset second time period.
In the embodiment of the present invention, the master device is connected with the newly added slave device bus, and the apparatus further includes:
the address information acquisition and address allocation module is used for acquiring the address information to be allocated and allocating an address to the newly added slave device according to the address information to be allocated; the address information to be allocated is the recorded prior address of the offline slave device in the offline state.
In summary, in the embodiment of the present invention, the master device sends a data acquisition request to the first slave device to acquire data information of the first slave device, and simultaneously sends a first presence confirmation request to the second slave device adjacent to the address of the first slave device, so as to confirm the presence of the second slave device. If the response information returned by the second slave device for the first online state confirmation request is received within the preset first time period, the second slave device can be confirmed to be 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 a 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 can be forced to be disconnected, and the first slave device is recorded to be in an offline state. By adopting the method, the on-line state of the slave device corresponding to one address is confirmed while the device data information of the slave device corresponding to the other address is acquired for two adjacent addresses in the address pool, so that the polling time of the master device can be reduced, and the on-line state of the slave device can be confirmed more quickly.
For the device embodiments, since they are substantially similar to the method embodiments, the description is relatively simple, and reference is made to the description of the method embodiments for relevant points.
The embodiment of the invention also provides electronic equipment, which comprises: the system comprises a processor, a memory and a computer program stored in the memory and capable of running on the processor, wherein the computer program realizes each process of the above-mentioned master-slave device communication method embodiment when being executed by the processor, and can achieve the same technical effect, and the repetition is avoided, and the description is omitted here.
The embodiment of the invention also provides a computer readable storage medium, on which a computer program is stored, which when executed by a processor, implements each process of the above-mentioned embodiment of the master-slave device communication method, and can achieve the same technical effects, so that repetition is avoided, and no further description is provided herein.
In this specification, each embodiment is described in a progressive manner, and each embodiment is mainly described by differences from other embodiments, and identical and similar parts between the embodiments are all enough to be referred to each other.
It will be apparent to those skilled in the art that embodiments of the present invention may be provided as a method, apparatus, or computer program product. Accordingly, embodiments of the present invention may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, embodiments of the invention may take the form of a computer program product on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) having computer-usable program code embodied therein.
Embodiments of the present invention are 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 flow and/or block of the flowchart illustrations and/or block diagrams, and combinations of flows and/or blocks in the flowchart illustrations and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may 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, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
While preferred embodiments of the present invention have been described, additional variations and modifications in those embodiments may occur to those skilled in the art once they learn of the basic inventive concepts. It is therefore intended that the following claims be interpreted as including the preferred embodiment and all such alterations and modifications as fall within the scope of the embodiments of the invention.
Finally, it is further noted that relational terms such as first and second, and the like are used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Moreover, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or terminal that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or terminal. Without further limitation, an element defined by the phrase "comprising one … …" does not exclude the presence of other like elements in a process, method, article or terminal device comprising the element.
The foregoing has outlined 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, wherein specific examples are provided herein to illustrate the principles and embodiments of the present invention, and the above examples are only for the purpose of aiding in the understanding of the method and core idea of the present invention; meanwhile, as those skilled in the art will have variations in the specific embodiments and application scope in accordance with the ideas of the present invention, the present description should not be construed as limiting the present invention in view of the above.

Claims (10)

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;
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.
2. The method of claim 1, wherein after waiting for the data information returned by the first slave device for the first data acquisition request within a preset second period of time, 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.
3. The method of claim 2, wherein the plurality of slaves includes a third slave that is another slave that is adjacent to the second slave, the plurality of slaves further including a fourth slave and a fifth slave that are adjacent to an address of the fifth slave, 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.
4. A method according to claim 3, characterized in that 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.
5. The method according to claim 4, wherein 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.
6. 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.
7. The method of claim 1, wherein the master device is bus-connected with an added slave device, the method further comprising:
acquiring address information to be allocated, and allocating an address to the newly added slave device according to the address information to be allocated; the address information to be allocated is the recorded prior address of the offline slave device in the offline state.
8. 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;
and the first slave device offline and offline state recording module is used for offline the first slave device and recording that the first slave device is in an offline state 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.
9. An electronic device, comprising: a processor, a memory and a computer program stored on the memory and capable of running on the processor, which when executed by the processor implements a master-slave device communication method as claimed in any one of claims 1-7.
10. A computer readable storage medium, characterized in that it has stored thereon a computer program which, when executed by a processor, implements a master-slave communication method according to any of claims 1 to 7.
CN202310858778.5A 2023-07-12 2023-07-12 Master-slave device communication method and device, electronic device and readable storage medium Pending CN116938632A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202310858778.5A CN116938632A (en) 2023-07-12 2023-07-12 Master-slave device communication method and device, electronic device and readable storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202310858778.5A CN116938632A (en) 2023-07-12 2023-07-12 Master-slave device communication method and device, electronic device and readable storage medium

Publications (1)

Publication Number Publication Date
CN116938632A true CN116938632A (en) 2023-10-24

Family

ID=88382020

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202310858778.5A Pending CN116938632A (en) 2023-07-12 2023-07-12 Master-slave device communication method and device, electronic device and readable storage medium

Country Status (1)

Country Link
CN (1) CN116938632A (en)

Similar Documents

Publication Publication Date Title
JP5607784B2 (en) CAN open network configuration method, slave device operation method, PLC device control method, and PLC device control system
CN108733604B (en) 485 bus intelligent expansion method and device based on modbus communication protocol
US10204072B2 (en) Method for automatically allocating addresses to similar bus users
CN107786405B (en) Multi-node automatic networking method based on CAN bus
CN107395787B (en) Address allocation method, system, gateway and medium for CAN communication network
JP2003124950A (en) Bus system and method and apparatus for transmitting information thereon
JPH10503041A (en) Arbitration method for bus connection delay
JP4601888B2 (en) Elevator communication control device and communication control method
JP2008099482A (en) Battery pack block, battery pack system, and address setting method for battery pack system
CN116319683A (en) Method, system and device for distributing networking address and electronic equipment
JP5110998B2 (en) Distribution device, communication system, and communication method
JPH0652900B2 (en) Multi-master communication bus
JPH07112201B2 (en) Method and apparatus for assigning addresses to remote terminals in a LAN
CN116938632A (en) Master-slave device communication method and device, electronic device and readable storage medium
CN111371659B (en) Method for automatically allocating RS485 slave equipment address
CN113923073B (en) Method for distributing ID (identity) to CAN (controller area network) bus and CAN bus system
CN115622834A (en) Bus communication control method, device, equipment and storage medium
CN113179338B (en) Communication method, electronic device, and storage medium
US7583690B2 (en) Allocation of station addresses to communication users in a bus system
CN115208794B (en) Timer adjustment method, device, equipment and medium of Profibus-DP protocol
CN113395366A (en) Network address allocation method and device
CN108628796A (en) A kind of serial communication method and system
EP4362399A1 (en) Polling scheme in an industrial network system
US20240137247A1 (en) Polling scheme in an industrial network system
CN111371922B (en) Automatic setting algorithm for address of network node without master and slave in network

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination