A device communication method, apparatus, device, and storage medium

CN117376052BActive Publication Date: 2026-09-11HANGZHOU HOLLYSYS AUTOMATION
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202311312579.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-10-10
Publication Date
2026-09-11
Estimated Expiration
2043-10-10

AI Technical Summary

Benefits of technology

[0039] As described above, when performing device communication, this application first collects the communication status of the first host and the second host at least once according to a preset period to obtain the first communication status corresponding to the first host and the second communication status corresponding to the second host. Based on the first and second communication statuses, the current master host among the first host and the second host is determined. A transport layer communication protocol connection is established using the current master host. After the transport layer communication protocol connection is successful, a communication request is constructed using the current master host. The communication request is sent to the slave device through the current master host, and the response data returned by the slave device is received to complete the communication. Therefore, this application determines the master host based on the communication status to handle host switching under different circumstances, ultimately enabling the master host to send requests, thereby completing communication with the slave device. In this way, conflict management of redundant master stations under link conflict mode can be achieved, successfully completing communication between redundant master stations and serial bus slave stations.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117376052B_ABST
    Figure CN117376052B_ABST
Patent Text Reader

Abstract

The application discloses a device communication method and device, equipment and storage medium, and relates to the field of industrial communication, and comprises the following steps: collecting the communication states of a first host and a second host at least once according to a preset period to obtain a first communication state corresponding to the first host and a second communication state corresponding to the second host; determining a current host among the first host and the second host based on the first communication state and the second communication state; using the current host to perform a transmission layer communication protocol connection, using the current host to build a communication request after the transmission layer communication protocol connection succeeds; sending the communication request to a slave device through the current host, and receiving response data returned by the slave device to complete communication. Thus, the application completes communication between a redundant master station and a serial bus slave station.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of industrial communication, and in particular to a device communication method, apparatus, device, and storage medium. Background Technology

[0002] In the field of industrial automation, to improve system reliability, the host computer communication master station is widely configured as a redundant master station, consisting of a primary master station (redundant host) and a backup master station (redundant standby). Industrial networks mainly include industrial Ethernet and fieldbus. Fieldbus widely uses RS485 / RS422 serial ports. With the cloudification of industrial interconnection, many local devices using serial ports (slave devices, slave devices, devices) need to be converted to Ethernet for cloud access, while the application layer communication protocol remains unchanged. Besides requiring a gateway adapter, the redundant master station also needs to make corresponding adaptive adjustments. Therefore, how to achieve master-slave management of the redundant master station and smoothly complete communication between the redundant master station and the serial bus slave stations is an urgent problem to be solved. Summary of the Invention

[0003] In view of this, the purpose of this invention is to provide a device communication method, apparatus, device, and storage medium that can realize conflict management of redundant master stations under link conflict mode and successfully complete communication between redundant master stations and serial bus slave stations. The specific solution is as follows:

[0004] In a first aspect, this application discloses a device communication method, comprising:

[0005] The communication status of the first host and the second host is collected at least once according to a preset period to obtain the first communication status corresponding to the first host and the second communication status corresponding to the second host.

[0006] Based on the first communication state and the second communication state, determine the current primary host among the first host and the second host;

[0007] Establish a transport layer communication protocol connection using the current primary host. After the transport layer communication protocol connection is successful, construct a communication request using the current primary host.

[0008] The primary host sends the communication request to the slave device and receives the response data returned by the slave device to complete the communication.

[0009] Optionally, the step of collecting the communication status of the first host and the second host at least once according to a preset period to obtain the first communication status corresponding to the first host and the second communication status corresponding to the second host includes:

[0010] The communication status of the first host and the second host is collected at least once according to a preset period, so as to obtain a first status value corresponding to the communication status of at least one first host and a second status value corresponding to the communication status of at least one second host.

[0011] If all the first state values ​​are the same, then the communication state corresponding to the first state value is determined as the first communication state;

[0012] If all the second state values ​​are the same, then the communication state corresponding to the second state value is determined as the second communication state.

[0013] Optionally, before determining the current primary host among the first host and the second host based on the first communication state and the second communication state, the method further includes:

[0014] Determine whether a historical switchover between the primary and backup hosts has been performed.

[0015] Optionally, the first communication state and the second communication state determine the current primary host among the first host and the second host, including:

[0016] If no historical switch between primary and backup hosts has been performed, then determine whether the first communication state and the second communication state are online.

[0017] If the first communication status is online, then the first host is determined as the current primary host;

[0018] If the second communication status is online, then the second host is determined as the current primary host;

[0019] Otherwise, the host that is currently online will be designated as the primary host.

[0020] Optionally, determining the current primary host among the first host and the second host based on the first communication state and the second communication state includes:

[0021] If a historical switch between the primary host and the backup host has been performed, then determine whether the first communication state and the second communication state are online.

[0022] If all are online or all are offline, the current primary host is determined based on the pre-default primary / standby relationship;

[0023] If the first communication state of the first host is online and the second communication state of the second host is offline, then the first host is determined as the current primary host.

[0024] If the first communication state of the first host is offline and the second communication state of the second host is online, then the second host is determined as the current primary host.

[0025] Optionally, the process of establishing a transport layer communication protocol connection using the current primary host, after the transport layer communication protocol connection is successfully established, further includes:

[0026] If the transport layer communication protocol connection fails, the current primary host will be used to repeatedly attempt to connect to the transport layer communication protocol until the connection is successfully established.

[0027] Optionally, the step of sending the communication request to the slave device through the current master host and receiving the response data returned by the slave device to complete the communication further includes:

[0028] The primary host sends the communication request to the slave device, receives the response data returned by the slave device, processes the response data accordingly, and sends the next communication request based on a preset rest time.

[0029] Alternatively, the current master host can send the communication request to the slave device, and if no response data is received from the slave device, a preset timeout operation can be performed, and the next communication request can be sent based on the preset timeout period.

[0030] Secondly, this application discloses a device communication apparatus, comprising:

[0031] The communication status determination module is used to collect the communication status of the first host and the second host at least once according to a preset period, so as to obtain the first communication status corresponding to the first host and the second communication status corresponding to the second host.

[0032] A primary host determination module is used to determine the current primary host between the first host and the second host based on the first communication state and the second communication state.

[0033] The communication protocol connection module is used to establish a transport layer communication protocol connection using the current primary host, and to construct a communication request using the current primary host after the transport layer communication protocol connection is successful.

[0034] The communication request sending module is used to send the communication request to the slave device through the current master host, and receive the response data returned by the slave device to complete the communication.

[0035] Thirdly, this application discloses an electronic device, including:

[0036] Memory, used to store computer programs;

[0037] A processor for executing the computer program to implement the aforementioned device communication method.

[0038] Fourthly, this application discloses a computer-readable storage medium for storing a computer program, which, when executed by a processor, implements the aforementioned device communication method.

[0039] As described above, when performing device communication, this application first collects the communication status of the first host and the second host at least once according to a preset period to obtain the first communication status corresponding to the first host and the second communication status corresponding to the second host. Based on the first and second communication statuses, the current master host among the first host and the second host is determined. A transport layer communication protocol connection is established using the current master host. After the transport layer communication protocol connection is successful, a communication request is constructed using the current master host. The communication request is sent to the slave device through the current master host, and the response data returned by the slave device is received to complete the communication. Therefore, this application determines the master host based on the communication status to handle host switching under different circumstances, ultimately enabling the master host to send requests, thereby completing communication with the slave device. In this way, conflict management of redundant master stations under link conflict mode can be achieved, successfully completing communication between redundant master stations and serial bus slave stations. Attached Figure Description

[0040] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on the provided drawings without creative effort.

[0041] Figure 1 This is a flowchart of a device communication method disclosed in this application;

[0042] Figure 2 This is a classic communication diagram disclosed in this application;

[0043] Figure 3 This is a flowchart of a specific device communication method disclosed in this application;

[0044] Figure 4 This is a schematic diagram of the structure of a device communication apparatus disclosed in this application;

[0045] Figure 5 This is a structural diagram of an electronic device disclosed in this application. Detailed Implementation

[0046] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. 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 without creative effort are within the scope of protection of the present invention.

[0047] In the field of industrial automation, to improve system reliability, the host computer communication master station is widely configured as a redundant master station, consisting of a primary master station (redundant host) and a backup master station (redundant standby). Industrial networks mainly include industrial Ethernet and fieldbus. Fieldbus widely uses RS485 / RS422 serial ports. With the cloudification of industrial interconnection, many local devices (slave devices, slave devices, devices) using serial ports need to be converted to Ethernet for cloud access, while the application layer communication protocol remains unchanged. Besides requiring a gateway adapter, the redundant master station also needs to make corresponding adaptive adjustments. To solve the above technical problems, this application provides a device communication method that can achieve conflict management of the redundant master station under link conflict mode, successfully completing communication between the redundant master station and the serial bus slave station.

[0048] See Figure 1 As shown, an embodiment of the present invention discloses a device communication method, including:

[0049] Step S11: Collect the communication status of the first host and the second host at least once according to a preset period to obtain the first communication status corresponding to the first host and the second communication status corresponding to the second host.

[0050] In this embodiment, a redundant FEP (Front-End Processor, or front-end machine) typically contains multiple pairs of master stations. Each pair of master stations operates independently, performing independent master / standby management and switching, a process known as link redundancy or channel redundancy. Currently, the actual primary and backup hosts in a pair of master stations cannot be determined; only default primary and default backup hosts exist. To determine the default relationships and obtain the true primary and backup hosts, it is first necessary to determine the status of each host. Therefore, the communication status of the first host and the second host is collected at least once according to a preset period to obtain at least one first status value corresponding to the communication status of the first host and at least one second status value corresponding to the communication status of the second host. If all first status values ​​are the same, the communication status corresponding to the first status value is determined as the first communication status; if all second status values ​​are the same, the communication status corresponding to the second status value is determined as the second communication status. For example, let any pair of master stations in the redundant FEP be machine A (i.e., the first host) and machine B (i.e., the second host). Let FEPACurrentState and FEPBCurrentState be the current actual primary / standby states of machines A and B, respectively. Let FEPADefaultState and FEPBDefaultState be the default primary / standby states of machines A and B, respectively. Assume that FEPADefaultState is the default primary host and FEPBDefaultState is the default standby host. The communication states FEPAState and FEPBState of the redundant master stations (machines A and B) are continuously collected N times (N≥1, where 1 indicates that the data is collected only once). Communication state 1 indicates online and 0 indicates offline. The states of FEPAState and FEPBState from the 1st to the Nth time are saved as follows: FEPAState[1], FEPAState[2], ..., FEPAState[N], FEPBState[1], FEPBState[2], ..., FEPBState[N]. If the communication states FEPAState[1] = FEPAState[2] = ... = FEPAState[N] are consecutively N, they are denoted as FEPAStateStable, and FEPBState[1] = FEPBState[2] = ... = FEPBState[N] are denoted as FEPBStateStable. This only requires checking whether FEPAStateStable and FEPBStateStable correspond to 1 or 0, and determining the final online or offline status based on their respective state values.

[0051] Step S12: Determine the current primary host among the first host and the second host based on the first communication state and the second communication state.

[0052] In this embodiment, before determining the current primary host among the first host and the second host based on the first communication state and the second communication state, the method further includes: determining whether a historical switch between the primary host and the standby host has been performed. It is necessary to confirm whether this is the first switch. One scenario is that when it is the first switch, that is, if no historical switch between the primary host and the standby host has been performed, then it is determined whether the first communication state and the second communication state are online; if the first communication state is online, then the first host is determined as the current primary host; if the second communication state is online, then the second host is determined as the current primary host; otherwise, the host currently online is determined as the current primary host. According to the above embodiment, when it is the first switch: if FEPAStateStable is online, then host A is set to Hot (i.e., host A is set as the primary host), and host B is set to Standby (i.e., host B is set as the standby host); if FEPAStateStable is online, then host B is set to Hot, and host A is set to Standby; if neither of the above conditions is met, host A is set to Hot, and host B is set to Standby. Another scenario will be described in detail in the next embodiment.

[0053] Step S13: Establish a transport layer communication protocol connection using the current primary host. After the transport layer communication protocol connection is successful, construct a communication request using the current primary host.

[0054] In this embodiment, the above steps demonstrate that the primary and backup hosts have been identified based on their respective communication states under different circumstances. The process of establishing a communication request using the current primary host after a successful transport layer communication protocol connection includes: if the transport layer communication protocol connection fails, the primary host repeatedly attempts to establish a transport layer communication protocol connection until a successful connection is established. Specifically, when a TCP (Transmission Control Protocol) connection fails, TCP connections are repeatedly established, and no request is established until a successful connection is established. After a successful TCP connection, the primary host establishes a communication request. Since redundant master stations need to manage TCP / IP connections, such as reconnection, this technology does not send requests during reconnection, avoiding unnecessary resource scheduling. Furthermore, the communication in this application is conducted over Ethernet with TCP / IP (Internet Protocol) at the transport layer, which obviously does not present a channel conflict mode. Therefore, redundant master stations can independently establish and manage Ethernet connections.

[0055] Step S14: Send the communication request to the slave device through the current master host, and receive the response data returned by the slave device to complete the communication.

[0056] In this embodiment, as Figure 2As shown, the current master host sends the communication request to the slave device by executing the BuildRequest() request in the connection success callback function (which can be called SessionSuccess()) after the TCP connection is successfully established. Thereafter, the BuildRequest() request is executed periodically. The communication is completed by the current master host sending the communication request to the slave device and receiving the response data returned by the slave device. This also includes: sending the communication request to the slave device through the current master host, receiving the response data returned by the slave device, performing corresponding processing based on the response data, and sending the next communication request based on a preset rest time; or, sending the communication request to the slave device through the current master host, performing a preset timeout processing operation if no response data is received from the slave device, and sending the next communication request based on the preset timeout period. There are two execution modes: After receiving and processing the device's response (ProcessRcvdPacket()), the primary host pauses briefly before sending the next request; or, if the primary host does not receive a correct response from the device, it enters a timeout process (TimeOut()), and sends another request when the timeout expires. It should be noted that if a backup host is used to send the request, there are two scenarios: First, if the other host is online, the backup host actively constructs the request and waits for a heartbeat notification from the other host before sending the request to the slave device. Second, if the other host is offline, the backup host directly sends the request and receives the response data returned by the slave device to complete the communication.

[0057] As described above, when performing device communication, this application first collects the communication status of the first host and the second host at least once according to a preset period to obtain the first communication status corresponding to the first host and the second communication status corresponding to the second host. Based on the first and second communication statuses, the current master host among the first host and the second host is determined. A transport layer communication protocol connection is established using the current master host. After the transport layer communication protocol connection is successful, a communication request is constructed using the current master host. The communication request is sent to the slave device through the current master host, and the response data returned by the slave device is received to complete the communication. Therefore, this application determines the master host based on the communication status to handle host switching under different circumstances, ultimately enabling the master host to send requests, thereby completing communication with the slave device. In this way, conflict management of redundant master stations under link conflict mode can be achieved, successfully completing communication between redundant master stations and serial bus slave stations.

[0058] As can be seen from the above embodiments, this application can determine the current primary host among the first host and the second host based on the first communication state and the second communication state. Next, a method for determining the current primary host among the first host and the second host based on the first communication state and the second communication state will be described in detail. See [link to documentation]. Figure 3 As shown in the figure, this application discloses a specific device communication method, including:

[0059] Step S21: If a historical switch between the primary host and the backup host has been performed, determine whether the first communication state and the second communication state are online.

[0060] In this embodiment, if a historical switch between the primary host and the backup host has already been performed, meaning that this is not the first time the primary station has switched between the primary host and the backup host, then it is necessary to determine whether the first communication state and the second communication state are online.

[0061] Step S22: If all are online or all are offline, then determine the current primary host based on the pre-default primary / backup relationship.

[0062] In this embodiment, if both the first and second communication states are online or both are offline, no switching is required, and the current primary host is determined based on the pre-default primary / standby relationship. For example, let any pair of primary stations in the redundant FEP be machine A and machine B. Let the current actual primary / standby states of machine A and machine B be FEPACurrentState and FEPBCurrentState, and let the default primary / standby states of machine A and machine B be FEPADefaultState and FEPBDefaultState. Assume that FEPADefaultState is the default primary host, FEPBDefaultState is the default standby host, FEPAStateStable represents the communication state of machine A, and FEPBStateStable represents the communication state of machine B. If FEPAStateStable is online and FEPBStateStable is online, or if FEPAStateStable is offline and FEPBStateStable is offline, no switching is required, and A remains the primary host and B remains the standby host.

[0063] Step S23: If the first communication state of the first host is online and the second communication state of the second host is offline, then the first host is determined as the current primary host.

[0064] In this embodiment, if the first communication state of the first host is online and the second communication state of the second host is offline, then the first host is determined to be the primary host and the second host is determined to be the standby host. For example, if FEPAStateStable is online and FEPBStateStable is offline, then host A is determined to be Hot (i.e., the primary host) and host B is determined to be Standby (i.e., the backup host).

[0065] Step S24: If the first communication state of the first host is offline and the second communication state of the second host is online, then the second host is determined as the current primary host.

[0066] In this embodiment, if the first communication state of the first host is offline and the second communication state of the second host is online, then the second host is determined as the primary host and the second host is determined as the standby host. For example, if FEPBStateStable is online and FEPAStateStable is offline, then host B is determined as Hot (i.e., the primary host) and host A is determined as Standby (i.e., the backup host).

[0067] As can be seen from the above, this application determines the primary host and the backup host based on the communication status of each host, so as to realize the primary and backup management of the corresponding redundant master station, which improves the communication reliability and stability of the redundant master station. At the same time, at the data link layer, serial bus technologies such as RS485 / RS422 are used to realize the management of channel conflict mode by the redundant master station.

[0068] See Figure 4 As shown, an embodiment of the present invention discloses a device communication apparatus, comprising:

[0069] The communication status determination module 11 is used to collect the communication status of the first host and the second host at least once according to a preset period, so as to obtain the first communication status corresponding to the first host and the second communication status corresponding to the second host.

[0070] The primary host determination module 12 is used to determine the current primary host between the first host and the second host based on the first communication state and the second communication state.

[0071] The communication protocol connection module 13 is used to establish a transport layer communication protocol connection using the current primary host, and to construct a communication request using the current primary host after the transport layer communication protocol connection is successful.

[0072] The communication request sending module 14 is used to send the communication request to the slave device through the current master host, and receive the response data returned by the slave device to complete the communication.

[0073] As described above, when performing device communication, this application first collects the communication status of the first host and the second host at least once according to a preset period to obtain the first communication status corresponding to the first host and the second communication status corresponding to the second host. Based on the first and second communication statuses, the current master host among the first host and the second host is determined. A transport layer communication protocol connection is established using the current master host. After the transport layer communication protocol connection is successful, a communication request is constructed using the current master host. The communication request is sent to the slave device through the current master host, and the response data returned by the slave device is received to complete the communication. Therefore, this application determines the master host based on the communication status to handle host switching under different circumstances, ultimately enabling the master host to send requests, thereby completing communication with the slave device. In this way, conflict management of redundant master stations under link conflict mode can be achieved, successfully completing communication between redundant master stations and serial bus slave stations.

[0074] In some specific embodiments, the communication status determination module 11 may specifically include:

[0075] The status value determination unit is used to collect the communication status of the first host and the second host at least once according to a preset period, so as to obtain a first status value corresponding to the communication status of at least one first host and a second status value corresponding to the communication status of at least one second host.

[0076] The first communication state determination unit is used to determine the communication state corresponding to the first state value as the first communication state if all the first state values ​​are the same.

[0077] The second communication state determination unit is used to determine the communication state corresponding to the second state value as the second communication state if all the second state values ​​are the same.

[0078] In some specific embodiments, the primary host determination module 12 may further include:

[0079] The historical switchover determination module is used to determine whether a historical switchover between the primary host and the backup host has already been performed.

[0080] In some specific embodiments, the primary host determination module 12 may specifically include:

[0081] The first online status determination unit is used to determine whether the first communication status and the second communication status are online if no historical switch between the primary host and the backup host has been performed.

[0082] The first primary host determination unit is used to determine the first host as the current primary host if the first communication state is online.

[0083] The second primary host determination unit is used to determine the second host as the current primary host if the second communication state is online.

[0084] The third primary host determination unit is used to determine the currently online host as the current primary host if otherwise.

[0085] In some specific embodiments, the primary host determination module 12 may specifically include:

[0086] The second online status determination unit is used to determine whether the first communication status and the second communication status are online if a historical switch between the primary host and the backup host has been performed.

[0087] The fourth primary host determination unit is used to determine the current primary host based on the pre-default primary / standby relationship if all hosts are online or all hosts are offline.

[0088] The fifth primary host determination unit is used to determine the first host as the current primary host if the first communication state of the first host is online and the second communication state of the second host is offline.

[0089] The sixth primary host determination unit is used to determine the second host as the current primary host if the first communication state of the first host is offline and the second communication state of the second host is online.

[0090] In some specific embodiments, the communication protocol connection module 13 may further include:

[0091] The communication protocol connection unit is used to repeatedly attempt to connect to the transport layer communication protocol using the current primary host if the connection fails, until the connection to the transport layer communication protocol is successfully established.

[0092] In some specific embodiments, the communication request sending module 14 may specifically include:

[0093] The first communication request sending unit is used to send the communication request to the slave device through the current master host, receive the response data returned by the slave device, perform corresponding processing based on the response data, and send the next communication request based on a preset rest time.

[0094] The second communication request sending unit is used to send the communication request to the slave device via the current master host, and when no response data is received from the slave device, perform a preset timeout processing operation and send the next communication request based on the preset timeout period.

[0095] Furthermore, embodiments of this application also disclose an electronic device, Figure 5 This is a structural diagram of an electronic device 20 according to an exemplary embodiment. The content of the diagram should not be construed as limiting the scope of this application.

[0096] Figure 5 This is a schematic diagram of the structure of an electronic device 20 provided in an embodiment of this application. Specifically, the electronic device 20 may include: at least one processor 21, at least one memory 22, a power supply 23, a communication interface 24, an input / output interface 25, and a communication bus 26. The memory 22 stores a computer program, which is loaded and executed by the processor 21 to implement the relevant steps in the device communication method disclosed in any of the foregoing embodiments. Furthermore, the electronic device 20 in this embodiment may specifically be an electronic computer.

[0097] In this embodiment, the power supply 23 is used to provide operating voltage for each hardware device on the electronic device 20; the communication interface 24 can create a data transmission channel between the electronic device 20 and external devices, and the communication protocol it follows can be any communication protocol applicable to the technical solution of this application, and is not specifically limited here; the input / output interface 25 is used to acquire external input data or output data to the outside world, and its specific interface type can be selected according to specific application needs, and is not specifically limited here.

[0098] In addition, the memory 22, as a carrier for resource storage, can be a read-only memory, random access memory, disk or optical disk, etc. The resources stored thereon can include operating system 221, computer program 222, etc., and the storage method can be temporary storage or permanent storage.

[0099] The operating system 221 is used to manage and control the various hardware devices on the electronic device 20 and the computer program 222, which may be Windows Server, Netware, Unix, Linux, etc. In addition to including computer programs capable of performing the device communication methods executed by the electronic device 20 as disclosed in any of the foregoing embodiments, the computer program 222 may further include computer programs capable of performing other specific tasks.

[0100] Furthermore, this application also discloses a computer-readable storage medium for storing a computer program; wherein, when the computer program is executed by a processor, it implements the aforementioned disclosed device communication method. Specific steps of this method can be found in the corresponding content disclosed in the foregoing embodiments, and will not be repeated here.

[0101] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on its differences from other embodiments. Similar or identical parts between embodiments can be referred to interchangeably. For the apparatus disclosed in the embodiments, since it corresponds to the method disclosed in the embodiments, the description is relatively simple; relevant parts can be referred to in the method section.

[0102] Those skilled in the art will further recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the components and steps of the various examples have been generally described in terms of functionality in the foregoing description. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.

[0103] The steps of the methods or algorithms described in conjunction with the embodiments disclosed herein can be implemented directly by hardware, a software module executed by a processor, or a combination of both. The software module can be located in random access memory (RAM), main memory, read-only memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, hard disk, removable disk, CD-ROM, or any other form of storage medium known in the art.

[0104] 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 apparatus 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 apparatus. 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 apparatus that includes said element.

[0105] The technical solutions provided in this application have been described in detail above. Specific examples have been used to illustrate the principles and implementation methods of this application. The descriptions of the above embodiments are only for the purpose of helping to understand the methods and core ideas of this application. At the same time, for those skilled in the art, there will be changes in the specific implementation methods and application scope based on the ideas of this application. Therefore, the content of this specification should not be construed as a limitation of this application.

Claims

1. A device communication method characterized by, include: The communication status of the first host and the second host is collected at least once according to a preset period to obtain the first communication status corresponding to the first host and the second communication status corresponding to the second host. Based on the first communication state and the second communication state, determine the current primary host among the first host and the second host; Establish a transport layer communication protocol connection using the current primary host. After the transport layer communication protocol connection is successful, construct a communication request using the current primary host. The primary host sends the communication request to the slave device and receives the response data returned by the slave device to complete the communication. Before determining the current primary host among the first host and the second host based on the first communication state and the second communication state, the method further includes: Determine whether a historical switchover between the primary and backup hosts has been performed; Determining the current primary host among the first host and the second host based on the first communication state and the second communication state includes: If no historical switch between primary and backup hosts has been performed, then determine whether the first communication state and the second communication state are online. If the first communication status is online, then the first host is determined as the current primary host; If the second communication status is online, then the second host is determined as the current primary host; Otherwise, the host that is currently online will be designated as the primary host. If a historical switch between the primary host and the backup host has been performed, then determine whether the first communication state and the second communication state are online. If all are online or all are offline, the current primary host is determined based on the pre-default primary / standby relationship; If the first communication state of the first host is online and the second communication state of the second host is offline, then the first host is determined as the current primary host. If the first communication state of the first host is offline and the second communication state of the second host is online, then the second host is determined as the current primary host.

2. The device communication method of claim 1, wherein, The step of collecting the communication status of the first host and the second host at least once according to a preset period to obtain the first communication status corresponding to the first host and the second communication status corresponding to the second host includes: The communication status of the first host and the second host is collected at least once according to a preset period, so as to obtain a first status value corresponding to the communication status of at least one first host and a second status value corresponding to the communication status of at least one second host. If all the first state values ​​are the same, then the communication state corresponding to the first state value is determined as the first communication state; If all the second state values ​​are the same, then the communication state corresponding to the second state value is determined as the second communication state.

3. The device communication method according to claim 1, characterized in that, The process of establishing a transport layer communication protocol connection using the current primary host, after the transport layer communication protocol connection is successfully established, further includes: If the transport layer communication protocol connection fails, the current primary host will be used to repeatedly attempt to connect to the transport layer communication protocol until the connection is successfully established.

4. The device communication method according to any one of claims 1 to 3, characterized in that, The step of sending the communication request to the slave device through the current master host and receiving the response data returned by the slave device to complete the communication also includes: The primary host sends the communication request to the slave device, receives the response data returned by the slave device, processes the response data accordingly, and sends the next communication request based on a preset rest time. Alternatively, the current master host can send the communication request to the slave device, and if no response data is received from the slave device, a preset timeout operation can be performed, and the next communication request can be sent based on the preset timeout period.

5. A device communication apparatus, characterized in that, include: The communication status determination module is used to collect the communication status of the first host and the second host at least once according to a preset period, so as to obtain the first communication status corresponding to the first host and the second communication status corresponding to the second host. A primary host determination module is used to determine the current primary host between the first host and the second host based on the first communication state and the second communication state. The communication protocol connection module is used to establish a transport layer communication protocol connection using the current primary host, and to construct a communication request using the current primary host after the transport layer communication protocol connection is successful. The communication request sending module is used to send the communication request to the slave device through the current master host, and receive the response data returned by the slave device to complete the communication; The device is also used to determine whether a historical switch between the primary host and the backup host has been performed. The primary host determination module is used to determine whether the first communication state and the second communication state are online if no historical switch between the primary host and the backup host has been performed. If the first communication status is online, then the first host is determined as the current primary host; If the second communication status is online, then the second host is determined as the current primary host; otherwise, the host currently online is determined as the current primary host. If a historical switch between the primary host and the backup host has been performed, then determine whether the first communication state and the second communication state are online. If all are online or all are offline, the current primary host is determined based on the pre-default primary / standby relationship; If the first communication state of the first host is online and the second communication state of the second host is offline, then the first host is determined as the current primary host. If the first communication state of the first host is offline and the second communication state of the second host is online, then the second host is determined as the current primary host.

6. An electronic device, comprising: include: Memory, used to store computer programs; A processor for executing the computer program to implement the steps of the device communication method as described in any one of claims 1 to 4.

7. A computer-readable storage medium, characterized in that, A computer program product for storing a computer program; wherein the computer program, when executed by a processor, implements the steps of the device communication method according to any one of claims 1 to 4.

Citation Information

Patent Citations

  • Double-host 485 bus system and working host fault redundancy protection method

    CN110347536A

  • Communication control method, device and system

    CN110677302A