Master-slave device switching method, system, device, equipment and storage medium
By rotating the master and slave device switching system of the RS485 bus, the master device is solved by rotating the level signal, the problem of competition between two devices on the half-duplex bus is ensured, and the stability of data processing is achieved. The need for two master devices is achieved Communication solutions in scenarios.
Patent Information
- Application Number
- CN202411254044.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-09
- Publication Date
- 2024-11-15
- Estimated Expiration
- 2044-09-09
AI Technical Summary
In industrial control systems, in the half-duplex communication mode of the RS485 bus, there is a problem that data cannot be directly transmitted when data exchange is required between slave devices, resulting in the fact that both devices need to be processed as master devices. Bus competition leads to communication failure.
By configuring the first master-slave switching device and the second master-slave switching device to rotate into the master device in the master device using the rotation method of level signals in the master device, thereby solving the competition problem and ensuring that there is only one master on the half-duplex bus. The device performs data processing.
In the communication scenario where two main devices are required, bus competition is avoided, data transmission stability is ensured, and communication failure problem caused by competition between two devices on the half-duplex bus becomes the main device.
Smart Images

Figure CN118778530B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of communication technology, and in particular to a master-slave device switching method, system, device, equipment and storage medium. Background Art
[0002] With the development of industrial control systems, more and more industrial sites have been installed with sensor acquisition systems, so that various types of sensors can be arranged at the industrial site to collect multiple sensor data, such as temperature and humidity, vibration, noise, and light. Multiple sensors need to be arranged at the industrial site to collect data. To ensure that multiple sensor data can be accurately collected, RS485 bus is usually used to connect each sensor, so as to achieve stable transmission of sensor data.
[0003] The RS485 bus is a half-duplex bus. At any one time, only one node can be in the sending state and send data to the bus, and all other nodes must be in the receiving state. That is, when applied, RS485 is a master-slave communication mode, that is, there is a master device connected to multiple slave devices on an RS485 bus. The master device initiates communication and the slave device responds. However, data cannot be transferred directly between slave devices. If data needs to be exchanged between slave devices, it must be forwarded through the master device.
[0004] However, in some application scenarios, data collection and processing may also be required between slave devices. For example, the communication module collects data from multiple sensors, and sensor No. 1 also needs to obtain the values of other sensors as a basis for processing (such as addition, subtraction or averaging operations, etc.). In this case, both the communication module and the sensor need to act as the master device for data collection and processing. If the RS485 bus is used to transmit data, there will be two master devices on this bus, resulting in competition and making the entire bus unable to be used normally.
[0005] Currently, a technical solution is urgently needed to solve the above technical problems. Summary of the invention
[0006] In view of the above problems, the present application provides a master-slave device switching method, system, device, equipment and storage medium to solve the above technical problems.
[0007] In a first aspect, the present application provides a master-slave device switching method, which is applied to a master-slave device switching system, the master-slave device switching system comprising: a first master-slave switching device, a second master-slave switching device and at least one slave device;
[0008] The first master-slave switching device, the second master-slave switching device and at least one slave device are connected via a half-duplex bus, the first master-slave switching device and the second master-slave switching device both include an input interface and an output interface, the output interface of the first master-slave switching device is used to output a level signal to the input interface of the second master-slave switching device, and the input interface of the first master-slave switching device is used to receive a level signal output by the output interface of the second master-slave switching device;
[0009] Among them, after the master-slave device switching system is powered on, the master-slave device switching method is executed, and the master-slave device switching method includes:
[0010] Step S100: the first master-slave switching device sends a first level to the second master-slave switching device, and the second master-slave switching device sends a second level to the first master-slave switching device, so as to configure the first master-slave switching device to become the master device for data processing;
[0011] Step S200: loop through steps S210 to S220:
[0012] Step S210: After the first master-slave switching device completes data processing, the first master-slave switching device modifies the level state sent to the second master-slave switching device to configure the second master-slave switching device to become the master device for data processing;
[0013] Step S220: After the second master-slave switching device completes data processing, the second master-slave switching device modifies the level state sent to the first master-slave switching device to configure the first master-slave switching device to become the master device for data processing.
[0014] In a second aspect, the present application provides a master-slave device switching system, comprising: a first master-slave switching device, a second master-slave switching device, and at least one slave device;
[0015] The first master-slave switching device, the second master-slave switching device and at least one slave device are connected via a half-duplex bus, the first master-slave switching device and the second master-slave switching device both include an input interface and an output interface, the output interface of the first master-slave switching device is used to output a level signal to the input interface of the second master-slave switching device, and the input interface of the first master-slave switching device is used to receive a level signal output by the output interface of the second master-slave switching device;
[0016] The master-slave device switching system is configured as follows: when the first master-slave switching device and the second master-slave switching device output the same level signal, the first master-slave switching device becomes the master device, and when the first master-slave switching device and the second master-slave switching device output different level signals, the second master-slave switching device becomes the master device; or when the first master-slave switching device and the second master-slave switching device output the same level signal, the second master-slave switching device becomes the master device, and when the first master-slave switching device and the second master-slave switching device output different level signals, the first master-slave switching device becomes the master device;
[0017] After being powered on, the master-slave device switching system is used to execute the master-slave device switching method of the first aspect described above.
[0018] In a third aspect, the present application provides a master-slave device switching apparatus, which is applied to a master-slave device switching system, the master-slave device switching system comprising: a first master-slave switching device, a second master-slave switching device and at least one slave device;
[0019] The first master-slave switching device, the second master-slave switching device and at least one slave device are connected via a half-duplex bus, the first master-slave switching device and the second master-slave switching device both include an input interface and an output interface, the output interface of the first master-slave switching device is used to output a level signal to the input interface of the second master-slave switching device, and the input interface of the first master-slave switching device is used to receive a level signal output by the output interface of the second master-slave switching device;
[0020] Among them, after the master-slave device switching system is powered on, the master-slave device switching device is executed, and the master-slave device switching device includes:
[0021] A first master-slave switching module, configured to execute: the first master-slave switching device sends a first level to the second master-slave switching device, and the second master-slave switching device sends a second level to the first master-slave switching device, so as to configure the first master-slave switching device to become a master device for data processing;
[0022] The second master-slave switching module is used for cyclic execution:
[0023] When the first master-slave switching device completes data processing, the first master-slave switching device modifies the level state sent to the second master-slave switching device to configure the second master-slave switching device to become the master device for data processing;
[0024] When the second master-slave switching device completes data processing, the second master-slave switching device modifies the level state sent to the first master-slave switching device to configure the first master-slave switching device to become the master device for data processing.
[0025] In a fourth aspect, the present application provides an electronic device, including a memory and a processor, wherein:
[0026] The memory is used to store computer programs;
[0027] The processor is used to read the program in the memory and execute the steps of the master-slave device switching method provided in the first aspect above.
[0028] In a fifth aspect, the present application provides a computer-readable storage medium having a readable computer program stored thereon, which, when executed by a processor, implements the steps of the master-slave device switching method provided in the first aspect above.
[0029] The master-slave device switching method, system, device, equipment and storage medium provided by the present application, after power-on, the first master-slave switching device sends a first level to the second master-slave switching device, and the second master-slave switching device sends a second level to the first master-slave switching device, so as to configure the first master-slave switching device to become the master device for data processing; then the loop is executed: when the first master-slave switching device completes data processing, the first master-slave switching device modifies the level state sent to the second master-slave switching device so that the second master-slave switching device becomes the master device for data processing; step S220: when the second master-slave switching device completes data processing, the second master-slave switching device modifies the level state sent to the first master-slave switching device so that the first master-slave switching device becomes the master device for data processing. The master-slave device switching method provided by the present application realizes that the first master-slave switching device and the second master-slave switching device are rotated to become the master device by modifying the level state between the first master-slave switching device and the second master-slave switching device, which is suitable for master-slave communication scenarios requiring two master devices, and solves the technical problem that in a master-slave communication system using a half-duplex bus, when two devices are required to process data, two devices on the half-duplex bus compete to become the master device, causing the entire bus to fail.
[0030] These and other aspects of the present application will become more clearly understood in the description of the following embodiments. BRIEF DESCRIPTION OF THE DRAWINGS
[0031] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0032] Figure 1 A schematic diagram of a master-slave device switching system provided in an embodiment of the present application is shown.
[0033] Figure 2 A flow chart of a master-slave device switching method provided in an embodiment of the present application is shown.
[0034] Figure 3 Another flow chart of the master-slave switching method provided in an embodiment of the present application is shown.
[0035] Figure 4 Another flow chart of the master-slave switching method provided in an embodiment of the present application is shown.
[0036] Figure 5 Another flow chart of the master-slave switching method provided in an embodiment of the present application is shown.
[0037] Figure 6 A schematic diagram of a master-slave device switching apparatus provided in an embodiment of the present application is shown.
[0038] Figure 7 A schematic diagram of an electronic device provided in an embodiment of the present application is shown.
[0039] Figure 8 A schematic diagram of a computer storage medium provided in an embodiment of the present application is shown. DETAILED DESCRIPTION
[0040] In order to enable those skilled in the art to better understand the solutions of the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, rather than all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without making creative work are within the scope of protection of the present application.
[0041] In the embodiments of the present application, it should be noted that, in this article, relational terms such as first and second, etc. are merely used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any actual relationship or order between these entities or operations.
[0042] Moreover, the terms "comprises," "comprising," or any other variation thereof are intended to encompass non-exclusive inclusion, such that a process, method, article, or apparatus that includes a list of elements includes not only those elements, but also other elements not explicitly listed, or elements inherent to such process, method, article, or apparatus. In the absence of further limitations, an element defined by the phrase "comprising a ..." does not exclude the presence of additional identical elements in the process, method, article, or apparatus that includes the element.
[0043] In addition, the "plurality" in the embodiments of the present application refers to two or more than two. In view of this, in the embodiments of the present application, "plurality" can also be understood as "at least two". "At least one" can be understood as one or more, for example, one, two or more. For example, including at least one means including one, two or more, and there is no limit on which ones are included. For example, including at least one of A, B and C, then A, B, C, A and B, A and C, B and C, or A, B and C can be included.
[0044] It should be noted that in the embodiments of the present application, "connection" can be understood as electrical connection, and the connection between two electrical components can be a direct or indirect connection between the two electrical components. For example, the connection between A and B can be either a direct connection between A and B or an indirect connection between A and B through one or more other electrical components.
[0045] The present application embodiment provides a master-slave device switching method, which is applied to a master-slave device switching system. Figure 1 A schematic diagram of a master-slave device switching system provided in an embodiment of the present application is shown. Figure 1 As shown, the master-slave device switching system includes: a first master-slave switching device, a second master-slave switching device and at least one slave device;
[0046] The first master-slave switching device, the second master-slave switching device and at least one slave device are connected via a half-duplex bus (e.g., an RS 485 bus). The first master-slave switching device and the second master-slave switching device both include an input interface and an output interface. The output interface of the first master-slave switching device is used to output a level signal to the input interface of the second master-slave switching device, and the input interface of the first master-slave switching device is used to receive the level signal output by the output interface of the second master-slave switching device.
[0047] After the master-slave device switching system is powered on, the master-slave device switching method provided in the embodiment of the present application is executed. Figure 2 A flow chart of a master-slave device switching method provided in an embodiment of the present application is shown. Figure 2 As shown, the master-slave device switching method provided in the embodiment of the present application includes:
[0048] Step S100: the first master-slave switching device sends a first level to the second master-slave switching device, and the second master-slave switching device sends a second level to the first master-slave switching device, so as to configure the first master-slave switching device to become the master device for data processing.
[0049] Step S200: loop through steps S210 to S220:
[0050] Step S210: After the first master-slave switching device completes data processing, the first master-slave switching device modifies the level state sent to the second master-slave switching device to configure the second master-slave switching device to become the master device for data processing.
[0051] Step S220: After the second master-slave switching device completes data processing, the second master-slave switching device modifies the level state sent to the first master-slave switching device to configure the first master-slave switching device to become the master device for data processing.
[0052] The master-slave device switching method provided in the embodiment of the present application determines the master device of the master-slave device switching system through the level signals of the input interface and the output interface of the first master-slave switching device and the second master-slave switching device. Next, taking the first level and the second level both being low levels as an example, the master-slave device switching method provided in the embodiment of the present application is explained, see Table 1 below.
[0053] Table 1:
[0054]
[0055] The master-slave device switching method provided in the embodiment of the present application executes step S100 after power-on: the first master-slave switching device outputs a low level, and the second master-slave switching device outputs a low level. At this time, the first master-slave switching device will be configured as the master device, and the first master-slave switching device will be used as the master device to collect and process data.
[0056] Next, steps S210 to S220 are executed in a loop:
[0057] Step S210: When the first master-slave switching device completes data processing and the second master-slave switching device is required to process data, the first master-slave switching device will actively exit the master device mode to make the second master-slave switching device the master device. Specifically, the first master-slave switching device modifies the low level sent by its output port to a high level, and the input port of the second master-slave switching device detects that the low level changes to a high level, and the second master-slave switching device will become the master device. For step S210, when the second master-slave switching device becomes the master device, the level signals output by the first master-slave switching device and the second master-slave switching device are always different level signals.
[0058] Step S220: When the second master-slave switching device completes data processing and needs to switch back to the first master-slave switching device for data processing, the second master-slave switching device will actively exit the master device mode so that the first master-slave switching device becomes the master device again. Specifically, the second master-slave switching device modifies the low level sent by its output port to a high level, and the input port of the first master-slave switching device detects that the low level changes to a high level, and the first master-slave switching device becomes the master device again. For step S220, when the second master-slave switching device becomes the master device, the level signals output by the first master-slave switching device and the second master-slave switching device are always the same level signals.
[0059] The master-slave device switching method provided in the embodiment of the present application realizes that the first master-slave switching device and the second master-slave switching device take turns to become the master device by modifying the level state between the first master-slave switching device and the second master-slave switching device. It is suitable for master-slave communication scenarios that require two master devices, and solves the technical problem that in a master-slave communication system using a half-duplex bus, when two devices are required to process data, the two devices on the half-duplex bus compete to become the master device, causing the entire bus to fail.
[0060] In some embodiments, Figure 3 Another flow chart of the master-slave switching method provided in the embodiment of the present application is shown. Figure 3 As shown, in the master-slave device switching method provided in the embodiment of the present application, after step S100 and before step S200, it also includes:
[0061] Step S180: The second master-slave switching device modifies the level state sent to the first master-slave switching device, and delays the first time to configure the second master-slave switching device to become the master device for data processing. Optionally, after power-on, the first master-slave switching device in the master-slave switching system is the master device. At this time, when the second master-slave switching device encounters an emergency and needs to communicate, it needs to seize to become the master device. During the seizure process, the second master-slave switching device will actively modify the state of the level signal it outputs so that the current master device (the first master-slave switching device) knows the information. The purpose of the second master-slave switching device delaying the first time to become the master device is to enable the current master device (the first master-slave switching device) to complete the processing of the current data, that is, the first time T>T1+T2, where T1 is the time for the master device to send a frame of command / data, and T2 is the time for the slave device to reply a frame of command / data.
[0062] Step S190: When the second master-slave switching device completes data processing, the second master-slave switching device modifies the level state sent to the first master-slave switching device to configure the first master-slave switching device to become the master device for data processing. Optionally, the second master-slave switching device is forced to seize the master device, so after completing data processing, it should actively exit the master device and make the first master-slave switching device the master device again.
[0063] In some embodiments, Figure 4 Another flow chart of step S200 of the master-slave switching method provided in an embodiment of the present application is shown. Figure 4 As shown, in step S200 of the master-slave device switching method provided in the embodiment of the present application, after step S210 and before step S220, the following further includes:
[0064] Step S218: The first master-slave switching device modifies the level state sent to the second master-slave switching device, and delays the second time to configure the first master-slave switching device to become the master device for data processing. Optionally, in step S210, the second master-slave switching device is used as the master device. At this time, when the first master-slave switching device encounters an emergency and needs to communicate, it also needs to seize the master device. During the seizure process, the first master-slave switching device will actively modify the state of the level signal it outputs so that the current master device (the second master-slave switching device) knows the information. The purpose of the first master-slave switching device delaying the second time to become the master device is to enable the current master device (the second master-slave switching device) to complete the processing of the current data, that is, the second time T>T1+T2, where T1 is the time for the master device to send a frame of command / data, and T2 is the time for the slave device to reply a frame of command / data.
[0065] Step S219: When the first master-slave switching device completes data processing, the first master-slave switching device modifies the level state sent to the second master-slave switching device to configure the second master-slave switching device to become the master device for data processing. Optionally, the first master-slave switching device is forced to seize the master device, so after completing data processing, it should actively exit the master device and make the second master-slave switching device the master device again.
[0066] In some embodiments, Figure 5 Another flow chart of step S200 of the master-slave switching method provided in an embodiment of the present application is shown. Figure 5 As shown, in step S200 of the master-slave device switching method provided in the embodiment of the present application, after step S220, the following further includes:
[0067] Step S221: The second master-slave switching device modifies the level state sent to the first master-slave switching device, and delays the third time to configure the second master-slave switching device to become the master device for data processing. Optionally, in step S220, the first master-slave switching device is used as the master device. At this time, when the second master-slave switching device encounters an emergency and needs to communicate, it also needs to seize the master device. During the seizure process, the second master-slave switching device will actively modify the state of the level signal it outputs so that the current master device (the first master-slave switching device) knows the information. The purpose of the second master-slave switching device delaying the third time to become the master device is to enable the current master device (the first master-slave switching device) to complete the processing of the current data, that is, the third time T>T1+T2, where T1 is the time for the master device to send a frame of command / data, and T2 is the time for the slave device to reply a frame of command / data.
[0068] Step S222: When the second master-slave switching device completes data processing, the second master-slave switching device modifies the level state sent to the first master-slave switching device to configure the first master-slave switching device to become the master device for data processing. Optionally, the second master-slave switching device is forced to seize the master device, so after completing data processing, it should actively exit the master device and make the first master-slave switching device the master device again.
[0069] In some embodiments, in the master-slave device switching method provided in the embodiments of the present application, the first time, the second time, and the third time can be set to the same time or to different times, as long as they can satisfy T>T1+T2, where T1 is the time for the master device to send a frame of command / data, and T2 is the time for the slave device to reply a frame of command / data.
[0070] In some embodiments, in the master-slave device switching method provided in the embodiments of the present application, the first level and the second level are the same level signal, that is, the first level and the second level are both high level or both low level. Or the first level and the second level are different level signals, that is, the first level is one of the high level and the low level, and the second level is the other of the high level and the low level.
[0071] Specifically, as shown in Table 1 above, when the first level and the second level are the same level signal, if the level signals output by the first master-slave switching device and the second master-slave switching device are the same, then the first master-slave switching device is the master device; if the level signals output by the first master-slave switching device and the second master-slave switching device are different, then the second master-slave switching device is the master device.
[0072] Similarly, when the first level and the second level are different level signals, the second master-slave switching device is the master device if the level signals output by the first master-slave switching device and the second master-slave switching device are the same, and the first master-slave switching device is the master device if the level signals output by the second master-slave switching device are different.
[0073] As an implementation manner, in the master-slave device switching method provided in the embodiment of the present application, the first level and the second level are the same level signals, and after power-on, the first level and the second level are low level signals.
[0074] In some embodiments, in the master-slave device switching method of the embodiment of the present application, the second master-slave switching device includes a first sensor device, and the first sensor device includes at least an input interface, an output interface, and a half-duplex bus communication interface.
[0075] The at least one slave device includes at least one second sensor device, the second sensor device including at least a half-duplex bus communication interface.
[0076] In some embodiments, the half-duplex communication interface is an RS 485 communication interface, and the input interface and the output interface are two IO interfaces for receiving and outputting high level and low level.
[0077] In some embodiments, the first master-slave switching device generally includes a host computer, a middle computer, and the like, which are commonly used hosts of a master-slave communication method based on an RS 485 bus.
[0078] It should be clear that in the master-slave device switching method provided in the embodiment of the present application, the first sensor and the at least one second sensor may include sensors of the same type or sensors of different types.
[0079] The master-slave device switching method provided in the embodiment of the present application realizes that the first master-slave switching device and the second master-slave switching device take turns to become the master device by modifying the level state between the first master-slave switching device and the second master-slave switching device. It is suitable for master-slave communication scenarios that require two master devices, and solves the technical problem that in a master-slave communication system using a half-duplex bus, when two devices are required to process data, the two devices on the half-duplex bus compete to become the master device, causing the entire bus to fail.
[0080] The present application also provides a master-slave device switching system. Figure 1 As shown, the master-slave device switching system provided by the embodiment of the present application includes: a first master-slave switching device, a second master-slave switching device and at least one slave device;
[0081] The first master-slave switching device, the second master-slave switching device and at least one slave device are connected via a half-duplex bus. The first master-slave switching device and the second master-slave switching device both include an input interface and an output interface. The output interface of the first master-slave switching device is used to output a level signal to the input interface of the second master-slave switching device, and the input interface of the first master-slave switching device is used to receive the level signal output by the output interface of the second master-slave switching device.
[0082] Specifically, the master-slave device switching system provided by the embodiment of the present application is configured as follows: when the first master-slave switching device and the second master-slave switching device output different level signals, the first master-slave switching device is the master device; when the first master-slave switching device and the second master-slave switching device output the same level signal, the second active switching device is the master device. Or when the first master-slave switching device and the second master-slave switching device output the same level signal, the second master-slave switching device is the master device; when the first master-slave switching device and the second master-slave switching device output the same level signal, the first master-slave switching device is the master device.
[0083] Wherein, the master-slave device switching system is used to execute the master-slave device switching method provided above after being powered on.
[0084] The master-slave device switching system provided in the embodiment of the present application realizes that the first master-slave switching device and the second master-slave switching device take turns to become the master device by modifying the level state between the first master-slave switching device and the second master-slave switching device. It is suitable for master-slave communication scenarios that require two master devices, and solves the technical problem that in a master-slave communication system using a half-duplex bus, when two devices are required to process data, the two devices on the half-duplex bus compete to become the master device, causing the entire bus to fail.
[0085] Based on the above master-slave device switching method, the embodiment of the present application further provides a master-slave device switching device, which is applied to the above-provided master-slave device switching system. Figure 6 A schematic diagram of a master-slave device switching device provided in an embodiment of the present application is shown. Figure 6 As shown, the master-slave device switching device provided in the embodiment of the present application includes:
[0086] A first master-slave switching module, configured to execute: the first master-slave switching device sends a first level to the second master-slave switching device, and the second master-slave switching device sends a second level to the first master-slave switching device, so that the first master-slave switching device becomes a master device for data processing;
[0087] The second master-slave switching module is used for cyclic execution:
[0088] When the first master-slave switching device completes data processing, the first master-slave switching device modifies the level state sent to the second master-slave switching device to configure the second master-slave switching device to become the master device for data processing;
[0089] When the second master-slave switching device completes data processing, the second master-slave switching device modifies the level state sent to the first master-slave switching device to configure the first master-slave switching device to become the master device for data processing.
[0090] For other details about how the modules in the master-slave device switching apparatus implement the above technical solution, please refer to the description of the master-slave device switching method provided in the above invention embodiment, which will not be repeated here.
[0091] Based on the above master-slave device switching method, the embodiment of the present application further provides an electronic device, Figure 7 A schematic diagram of an electronic device provided by an embodiment of the present application is shown, Figure 7 As shown, the electronic device provided in the embodiment of the present application includes a processor 71 and a memory 72 coupled to the processor 71. The memory 72 stores a computer program, and when the computer program is executed by the processor 71, the processor 71 executes the steps of the master-slave device switching method in the above embodiment.
[0092] For other details about how the processor 71 in the electronic device implements the above technical solution, please refer to the description of the master-slave device switching method provided in the above invention embodiment, which will not be repeated here.
[0093] Among them, the processor 71 can also be called a CPU (Central Processing Unit), and the processor 71 may be an integrated circuit chip with signal processing capabilities; the processor 71 can also be a general-purpose processor, DSP (Digital Signal Process), ASIC (Application Specific Integrated Circuit), FPGA (Field Programmable Gate Array) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, among which the general-purpose processor can be a microprocessor or the processor 71 can also be any conventional processor, etc.
[0094] Based on the above master-slave device switching method, the embodiment of the present application also provides a computer-readable storage medium, Figure 8 A schematic diagram of a computer storage medium provided in an embodiment of the present application is shown, Figure 8As shown, the embodiment of the present application also provides a computer-readable storage medium, on which a readable computer program 81 is stored; wherein the computer program 81 can be stored in the above storage medium in the form of a software product, including a number of instructions for enabling a computer device (which can be a personal computer, server, or network device, etc.) or a processor to execute all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, magnetic disk or optical disk, ROM (Read-Only Memory), RAM (Random Access Memory) and other media that can store program codes, or terminal devices such as computers, servers, mobile phones, and tablets.
[0095] The above contents are further detailed descriptions of the present application in combination with specific implementation methods, and it cannot be determined that the specific implementation of the present application is limited to these descriptions. For ordinary technicians in the technical field to which the present application belongs, several simple deductions or substitutions can be made without departing from the concept of the present application, which should be regarded as the protection scope of the present application.
Claims
1. A method for switching between a master and a slave device, characterized in that: Applied to a master-slave device switching system, the master-slave device switching system comprises: a first master-slave switching device, a second master-slave switching device and at least one slave device; The first master-slave switching device, the second master-slave switching device and the at least one slave device are connected via a half-duplex bus, the first master-slave switching device and the second master-slave switching device each include an input interface and an output interface, the output interface of the first master-slave switching device is used to output a level signal to the input interface of the second master-slave switching device, and the input interface of the first master-slave switching device is used to receive a level signal output by the output interface of the second master-slave switching device; Wherein, the master-slave device switching system executes the master-slave device switching method after being powered on, and the master-slave device switching method includes: Step S100: the first master-slave switching device sends a first level to the second master-slave switching device, and the second master-slave switching device sends a second level to the first master-slave switching device, so as to configure the first master-slave switching device to become a master device for data processing; Step S200: loop through steps S210 to S220: Step S210: when the first master-slave switching device completes data processing, the first master-slave switching device modifies the level state sent to the second master-slave switching device to configure the second master-slave switching device to become the master device for data processing; Step S220: After the second master-slave switching device completes data processing, the second master-slave switching device modifies the level state sent to the first master-slave switching device to configure the first master-slave switching device to become the master device for data processing.
2. The master-slave device switching method according to claim 1, characterized in that: After step S100 and before step S200, the method further includes: The second master-slave switching device modifies the level state sent to the first master-slave switching device, and delays the first time to configure the second master-slave switching device to become the master device for data processing; When the second master-slave switching device completes data processing, the second master-slave switching device modifies the level state sent to the first master-slave switching device to configure the first master-slave switching device to become the master device for data processing.
3. The master-slave device switching method according to claim 1, characterized in that: After step S210 and before step S220, the following steps are further included: The first master-slave switching device modifies the level state sent to the second master-slave switching device, and delays a second time to configure the first master-slave switching device to become the master device for data processing; When the first master-slave switching device completes data processing, the first master-slave switching device modifies the level state sent to the second master-slave switching device to configure the second master-slave switching device to become the master device for data processing.
4. The master-slave device switching method according to claim 1, characterized in that: After step S220, the method further includes: The second master-slave switching device modifies the level state sent to the first master-slave switching device, and delays for a third time to configure the second master-slave switching device to become the master device for data processing; When the second master-slave switching device completes data processing, the second master-slave switching device modifies the level state sent to the first master-slave switching device to configure the first master-slave switching device to become the master device for data processing.
5. The master-slave device switching method according to claim 1, characterized in that: The first level and the second level are the same level signal, or the first level and the second level are different level signals.
6. The master-slave device switching method according to claim 1, characterized in that: The second master-slave switching device comprises a first sensor device, wherein the first sensor device comprises at least the input interface, the output interface and a half-duplex bus communication interface; The at least one slave device comprises at least one second sensor device, wherein the second sensor device comprises at least the half-duplex bus communication interface.
7. A master-slave device switching system, characterized in that: include: a first master-slave switching device, a second master-slave switching device, and at least one slave device; The first master-slave switching device, the second master-slave switching device and the at least one slave device are connected via a half-duplex bus, the first master-slave switching device and the second master-slave switching device each include an input interface and an output interface, the output interface of the first master-slave switching device is used to output a level signal to the input interface of the second master-slave switching device, and the input interface of the first master-slave switching device is used to receive a level signal output by the output interface of the second master-slave switching device; The master-slave device switching system is configured such that: when the first master-slave switching device and the second master-slave switching device output the same level signal, the first master-slave switching device becomes the master device; when the first master-slave switching device and the second master-slave switching device output different level signals, the second master-slave switching device becomes the master device; Or when the first master-slave switching device and the second master-slave switching device output the same level signal, the second master-slave switching device becomes the master device, and when the first master-slave switching device and the second master-slave switching device output different level signals, the first master-slave switching device becomes the master device; After being powered on, the master-slave device switching system is used to execute the master-slave device switching method according to any one of claims 1 to 6.
8. A master-slave device switching device, characterized in that: Applied to a master-slave device switching system, the master-slave device switching system comprises: a first master-slave switching device, a second master-slave switching device and at least one slave device; The first master-slave switching device, the second master-slave switching device and the at least one slave device are connected via a half-duplex bus, the first master-slave switching device and the second master-slave switching device each include an input interface and an output interface, the output interface of the first master-slave switching device is used to output a level signal to the input interface of the second master-slave switching device, and the input interface of the first master-slave switching device is used to receive a level signal output by the output interface of the second master-slave switching device; Wherein, the master-slave device switching system executes the master-slave device switching device after power-on, and the master-slave device switching device includes: A first master-slave switching module, configured to execute: the first master-slave switching device sends a first level to the second master-slave switching device, and the second master-slave switching device sends a second level to the first master-slave switching device, so that the first master-slave switching device becomes a master device for data processing; The second master-slave switching module is used for cyclic execution: When the first master-slave switching device completes data processing, the first master-slave switching device modifies the level state sent to the second master-slave switching device to configure the second master-slave switching device to become the master device for data processing; When the second master-slave switching device completes data processing, the second master-slave switching device modifies the level state sent to the first master-slave switching device to configure the first master-slave switching device to become the master device for data processing.
9. An electronic device, characterized in that: comprising a memory and a processor, wherein: The memory is used to store computer programs; The processor is used to read the computer program in the memory and execute the steps of the master-slave device switching method according to any one of claims 1 to 6.
10. A computer-readable storage medium, characterized in that: A readable computer program is stored thereon, and when the program is executed by a processor, the steps of the master-slave device switching method as described in any one of claims 1 to 6 are implemented.
