Long-distance communication bus, host, bus topology detection and relay control method

By combining soft relay and hard relay in the long-distance communication bus, and optimizing the bus topology through topology detection and relay control, the problem of time-consuming and cost balance is solved, and efficient and low-cost data transmission is achieved.

CN119316252BActive Publication Date: 2025-04-08HANGZHOU HIKVISION DIGITAL TECHNOLOGY CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202411854846.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-12-16
Publication Date
2025-04-08
Estimated Expiration
2044-12-16

AI Technical Summary

Technical Problem

During data transmission of existing long-distance communication buses, soft relays are time-consuming and hard relays are high and signal distortion is easy to cause signal distortion, which cannot effectively solve the problem of time-consuming and cost balance between data transmission.

Method used

By combining soft relay and hard relay in the relay communication module, the soft relay shares the transmission load when the data volume is large, the hard relay ensures signal quality and optimizes the bus topology through topology detection and relay control methods to reduce transmission time.

Benefits of technology

It effectively reduces the time-consuming transmission of data on the bus, while reducing costs and reducing communication failure rate, realizing the organic combination of soft relay and hard relay.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119316252B_ABST
    Figure CN119316252B_ABST
Patent Text Reader

Abstract

An embodiment of the present application provides a long-distance communication bus, a host, and a bus topology detection and relay control method, wherein the host sends a first switching message to all slaves connected to the host, and after a first preset delay, sends a first detection message indicating a first detection level to all slaves connected to the host, wherein the first detection level initially indicates the first level; each first slave responds to the first switching message by switching a switch unit to a blocking state; each slave responds to the first detection message by parsing and obtaining the first detection level indicated in the first detection message as the level of the slave; each first slave updates the level indicated by the first detection message to the next level of the first detection level, and sends the updated first detection message to all slaves connected to the downlink port; the host detects each slave in turn according to the level of each first slave to obtain the topology of the bus.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of bus circuit technology, and in particular to a long-distance communication bus, a host, a bus topology detection and a relay control method. Background Art

[0002] In the related art, the long-distance communication bus includes a bus transceiver module, a relay communication module and a 485 communication module, which are cascaded through communication. If the relay communication module only uses soft relay to forward data. When the amount of data is particularly large, forwarding data by soft relay will take a long time. If the relay communication module only uses hard relay to forward data, it will either lead to high costs or cause communication failure due to signal distortion. In order to solve the above problems, the relay communication module can be made to forward data by both soft relay and hard relay. How to generate a bus topology that can forward data by both soft relay and hard relay is a problem that needs to be solved urgently. Summary of the invention

[0003] The purpose of the embodiments of the present application is to provide a long-distance communication bus, host, bus topology detection and relay control method to reduce the time consumption of data transmission on the bus while reducing costs and communication failure rate. The specific technical solution is as follows:

[0004] In a first aspect, an embodiment of the present application provides a bus topology detection method, the method comprising:

[0005] The host sends a first switching message to all slaves connected to the host, and after a first preset delay, sends a first detection message indicating a first detection level to all slaves connected to the host, wherein the first detection level indicates the first level when it is initial; all slaves include a first slave and / or a second slave, and all slaves are cascaded to the host, the first slave includes an uplink port, a downlink port and a switch unit, the second slave includes only an uplink port, the uplink port is used to realize the connection between the first slave and the upper-level device, the downlink port is used to realize the connection between the slave and the lower-level device, when the switch unit is in the on state, the uplink port and the downlink port are conductive, when the switch unit is in the blocked state, the uplink port and the downlink port are blocked, and each of the switch units is initially in the on state;

[0006] By each of the first slaves responding to the first switching message, the switch unit is switched to the blocking state; by each of the slaves responding to the first detection message, a first detection level represented in the first detection message is parsed and obtained as the level of the slave; and by the first slave, the level represented by the first detection message is updated to the next level of the first detection level, and the updated first detection message is sent to all slaves connected to the downlink port;

[0007] The host detects each of the first slaves in turn according to the level of each of the first slaves to obtain the topology of the bus.

[0008] In a second aspect, an embodiment of the present application provides a long-distance communication bus, including a host and multiple slaves, the multiple slaves including a first slave and / or a second slave, the multiple slaves are cascaded to the host, and the first slave includes an upstream port, a downstream port and a switch unit, the second slave includes only an upstream port, the upstream port is used to realize the connection between the first slave and an upper-level device, the downstream port is used to realize the connection between the slave and a lower-level device, when the switch unit is in a conducting state, the upstream port and the downstream port are connected, when the switch unit is in a blocked state, the upstream port and the downstream port are blocked, and each of the switch units is initially in the conducting state;

[0009] The host is used to send a first switching message to all slaves connected to the host, and send a first detection message indicating a first detection level to all slaves connected to the host after a first preset delay, wherein the first detection level indicates a first level when it is initial;

[0010] Each of the first slaves is configured to switch the switch unit to the blocking state in response to the first switching message;

[0011] Each of the slave machines is configured to respond to the first detection message and parse and obtain a first detection level indicated in the first detection message as the level of the slave machine;

[0012] Each of the first slaves is configured to update the level represented by the first detection message to a level next to the first detection level, and send the updated first detection message to all slaves connected to the downlink port;

[0013] The host is further configured to detect each of the first slaves in sequence according to the level of each of the first slaves to obtain the topology of the bus.

[0014] In a third aspect, an embodiment of the present application provides a long-distance communication host, wherein the host is cascaded with multiple slaves, wherein the multiple slaves include a first slave and / or a second slave, and the first slave includes an upstream port, a downstream port and a switch unit, and the second slave includes only an upstream port, wherein the upstream port is used to realize the connection between the first slave and an upper-level device, and the downstream port is used to realize the connection between the slave and a lower-level device, when the switch unit is in a conducting state, the upstream port and the downstream port are conducted, and when the switch unit is in a blocked state, the upstream port and the downstream port are blocked, and each of the switch units is initially in the conducting state;

[0015] The host is used to send a first switching message to all slaves connected to the host, and send a first detection message indicating a first detection level to all slaves connected to the host after a first preset delay, wherein the first detection level initially indicates the first level, so that each of the first slaves responds to the first switching message and switches the switch unit to the blocking state; each of the slaves responds to the first detection message and parses the first detection level indicated in the first detection message as the level of the slave; each of the first slaves updates the level indicated by the first detection message to the next level of the first detection level, and sends the updated first detection message to all slaves connected to the downlink port;

[0016] The host is further configured to detect each of the first slaves in sequence according to the level of each of the first slaves to obtain the topology of the bus.

[0017] In a fourth aspect, an embodiment of the present application provides a bus relay control method, which is applied in a long-distance communication bus, wherein the bus includes a host and multiple slaves, wherein the multiple slaves include a first slave and / or a second slave, wherein the multiple slaves are cascaded to the host, and the first slave includes an upstream port, a downstream port, and a switch unit, wherein the second slave includes only an upstream port, wherein the upstream port is used to realize a connection between the first slave and an upper-level device, and the downstream port is used to realize a connection between the slave and a lower-level device, wherein when the switch unit is in a conducting state, the upstream port and the downstream port are conducted, and when the switch unit is in a blocked state, the upstream port and the downstream port are blocked, and each of the switch units is initially in the conducting state;

[0018] The method comprises:

[0019] For each level of slaves in the multi-level slaves, if the number of the first slaves in each level is less than a first preset value, the target number is determined to be the first target number, the target number is the number of first slaves for which the switch unit is set to the blocking state, and the first target number is the quotient of the total number of the slaves and a second preset value; if the first target number is greater than a third preset value, it is determined to set the switch unit of the first slave whose rank value is less than the product of the first target number and the second preset value and is an integer multiple of the second preset value to the blocking state; if the first target number is not greater than the third preset value, it is determined not to set the switch unit of the first slave to the blocking state;

[0020] If the number of the first slaves in each level is not less than the first preset value, the target number is determined to be the second target number, the second target number is the quotient of the cascade number of the slaves and the fourth preset value, if the first target number is greater than the third preset value, it is determined to set the switch unit of the first slave whose rank value is less than the product of the second target number and the fourth preset value and is an integer multiple of the fourth preset value to a blocking state; if the first target number is not greater than the third preset value, it is determined not to set the switch unit of the first slave to a blocking state; send a fourth switching message to all first slaves connected to the host;

[0021] Each of the first slaves switches the switch unit to the blocking state in response to the fourth switching message.

[0022] In a fifth aspect, an embodiment of the present application provides an electronic device, comprising: a memory for storing computer programs; and a processor for executing the programs stored in the memory to implement the bus topology detection method or bus relay control method described in the embodiment of the present application.

[0023] In a sixth aspect, an embodiment of the present application further provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the bus topology detection method or bus relay control method described in the present application is implemented.

[0024] The beneficial effects of the embodiments of the present application are as follows: the bus includes a host and multiple slaves, the multiple slaves include a first slave and / or a second slave, the multiple slaves are cascaded to the host, the first slave includes an upstream port, a downstream port and a switch unit, the second slave only includes an upstream port, the host sends a first switching message to all slaves connected to the host, and sends a first detection message representing a first detection level to all slaves connected to the host after a first preset delay, the first detection level initially representing the first level; each first slave switches the switch unit to a blocking state in response to the first switching message; each slave responds to the first detection message, parses and obtains the first detection level represented in the first detection message as the level of the slave; each first slave updates the level represented by the first detection message to the next level of the first detection level, and sends the updated first detection message to all slaves connected to the downstream port; the host is also used to detect each slave in turn according to the level of each first slave to obtain the topology of the bus.

[0025] Of course, implementing any product or method of the present application does not necessarily require achieving all of the advantages described above at the same time. BRIEF DESCRIPTION OF THE DRAWINGS

[0026] Figure 1 A first schematic diagram of a long-distance communication bus provided in an embodiment of the present application;

[0027] Figure 2 A schematic diagram of a slave provided in an embodiment of the present application;

[0028] Figure 3 A second schematic diagram of a long-distance communication bus provided in an embodiment of the present application;

[0029] Figure 4 A first schematic diagram of a bus topology provided in an embodiment of the present application;

[0030] Figure 5 A schematic diagram of using a routing algorithm to determine a routing strategy provided in an embodiment of the present application;

[0031] Figure 6 A second schematic diagram of a bus topology provided in an embodiment of the present application;

[0032] Figure 7 A third schematic diagram of a bus topology provided in an embodiment of the present application;

[0033] Figure 8 A schematic diagram of adding color distinction and displaying information for the type of slave provided in an embodiment of the present application;

[0034] Fig. 9 A third schematic diagram of a long-distance communication bus provided in an embodiment of the present application;

[0035] Fig.10 A fourth schematic diagram of a long-distance communication bus provided in an embodiment of the present application;

[0036] Figure 11-1 A first schematic diagram of a long-distance communication bus host polling a slave provided in an embodiment of the present application;

[0037] Figure 11-2 A second schematic diagram of a long-distance communication bus host polling a slave provided in an embodiment of the present application;

[0038] Fig.12 A fifth schematic diagram of a long-distance communication bus provided in an embodiment of the present application;

[0039] Fig.13 A schematic diagram of a bus topology detection method provided in an embodiment of the present application;

[0040] Fig.14 A schematic diagram of a bus relay control method provided in an embodiment of the present application;

[0041] Fig.15 A schematic diagram of an electronic device according to an embodiment of the present application. DETAILED DESCRIPTION

[0042] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field based on the present application belong to the scope of protection of the present application.

[0043] Below, the terms appearing in this application are explained:

[0044] 485 bus: A commonly used two-wire communication bus that uses differential signal transmission.

[0045] 485 relay: A device that receives 485 data and forwards it.

[0046] Soft relay: A 485 relay that forwards data via software.

[0047] Hard relay: 485 relay that automatically forwards through hardware design and does not require software processing.

[0048] Half-duplex: Data can only be transmitted in one direction at the same time, that is, either sending data or receiving data at the same time.

[0049] Host: The 485 bus is half-duplex. Usually, communication is initiated by the host. Generally, there can be only one host on a bus.

[0050] Slave: A device on the 485 bus that receives data messages from the host and responds accordingly.

[0051] Node: A communication entity on the 485 bus, which can be a host or a slave.

[0052] Backoff mechanism: Since the 485 bus is half-duplex, multiple slaves cannot send data at the same time, otherwise it will cause bus conflicts. The solution of the embodiment of the present application allows multiple slaves to compete to send data in the scenario without a fixed communication address. However, in order to reduce conflicts, each node will calculate its own backoff time according to a certain algorithm, and wait until the backoff time is over before sending the response data.

[0053] In the related art, the long-distance communication bus includes a bus transceiver module, a relay communication module and a 485 communication module, which are cascaded through communication. If the relay communication module only uses soft relay to forward data. When the amount of data is particularly large, forwarding data by soft relay will take a long time. If the relay communication module only uses hard relay to forward data, it will either lead to high costs or cause communication failure due to signal distortion. In order to solve the above problems, the relay communication module can be made to forward data by both soft relay and hard relay. How to generate a bus topology that can forward data by both soft relay and hard relay is a problem that needs to be solved urgently.

[0054] In order to solve the technical problems existing in the related art, the present application provides a schematic diagram of a long-distance communication bus. That is, a schematic diagram of a topology of a generated bus is provided, see Fig.10 The bus includes a host, slaves 1-1, 1-2, 2-1 and 3-1, wherein slave 2-1 is connected to slave 1-2, and slave 3-1 is connected to slave 2-1.

[0055] S1001: The host sends a switching message CMD-TYPE0 to slaves 1-1, 1-2, 2-1 and 3-1, wherein the switching message may be sent once every a first preset time length and a preset number of times.

[0056] S1002: After receiving the switching message sent by the host, slaves 1-1, 1-2, 2-1 and 3-1 set the switch units to a blocking state and forward the switching message to the next-level slave.

[0057] It should be noted that in this embodiment, the slaves 1-1, 1-2, 2-1 and 3-1 are all slaves with relay functions. The slaves may also be slaves without relay functions. The slave with relay function includes an uplink port, a downlink port and a switch unit. Setting the switch unit to a blocking state actually disconnects the physical connection between the front and rear stages of the slave. It is necessary to forward the data received at the uplink port to the downlink port, or forward the data received at the downlink port to the uplink port through software. That is, the forwarding of data at each level of slaves can only be achieved through software, and the forwarding of data at each level of slaves cannot be achieved through hardware design. This state can be called "soft relay".

[0058] It should be further explained that, by default, the switch unit in the slave is in the on state. The upstream port and the downstream port are connected through hardware, and there is no need to implement forwarding through software. The data received by the upstream port can be directly forwarded to the downstream port through hardware, and the data received by the downstream port 1022 is directly forwarded to the upstream port through hardware. That is, each slave is physically connected, and the forwarding of data in slaves at all levels can be achieved through hardware design. This state can be called "hard relay". When the switch unit is in the on state, the input data can be sent from the upstream port to the downstream port, and the input data can also be uploaded from the downstream port to the upstream port.

[0059] S1003: The host sends a rank value to slaves 1-1 and 1-2 (the rank value is Fig.10 as well as Fig.12 The node detection control command CMD-TYPE1 (CMD-TYPE is Fig.10 as well as Fig.12 -type in the command).

[0060] It should be noted that all the first slaves receiving CMD-TYPE1 start to detect the slaves below them.

[0061] S1004: Slave 1-1 and slave 1-2 mark the current position as rank 1, and forward the node detection control command CMD-TYPE1 with rank 1 downward; slave 2-1 marks the current position as rank 2, and forwards the node detection control command CMD-TYPE1 with rank 2 downward; slave 3-1 marks the current position as rank 3.

[0062] By executing S1004, each level of slaves obtains its own rank value, which represents the cascade quantity information of the slave in the bus. The rank value of the last level is the current total cascade quantity of the bus.

[0063] S1005: The host sends a node detection command CMD-TYPE2 with rank 1 to slaves 1-1 and 1-2.

[0064] S1006: Slave 1-1 and slave 1-2 respond according to the backoff mechanism.

[0065] In the response process, slaves 1-1 and 1-2 start to detect child nodes. If they receive data from other slaves during the backoff time, they will give up responding to the host, and the host needs to resend the node detection command CMD-TYPE2 with a rank value of 1.

[0066] S1007: The host sends a detection confirmation CMD-TYPE3 to the slave that first receives the response.

[0067] Among them, the detection confirmation CMD-TYPE3 is accompanied by a slave identifier, which can be the rank value of the slave. For the slave that has sent the detection confirmation CMD-TYPE3, it will no longer respond to the node detection command CMD-TYPE2 sent by the host, and the slave whose rank value does not correspond to the rank value in the node detection command CMD-TYPE2 sent by the host does not need to respond to the node detection command CMD-TYPE2 sent by the host. If the host does not receive a response from slaves 1-1 and slaves 1-2 to the node detection command CMD-TYPE2 with a rank of 1 within a certain period of time, it is determined that the detection of this level is completed. For example, a certain period of time is for the host to send the node detection command CMD-TYPE2 several times and wait for a second preset time length.

[0068] S1008: The host sends a switching message CMD-TYPE0 to slaves 1-1 and 1-2.

[0069] S1009: After receiving the switching message sent by the host, the slave 1-1 and the slave 1-2 switch the state of the switch unit to the on state.

[0070] S1010: The host sends a node detection command CMD-TYPE4 with rank 2 to slave 2-1.

[0071] In general, the host can only send the node detection command CMD-TYPE4 to the slave with relay function, and query according to the rank value.

[0072] S1011: If the detection is not completed, the status of incomplete is returned to the host; if the detection is completed, the child node information is returned to the host.

[0073] It should be noted that the subnode information is the slave information of the slave, and the slave information of the slave includes at least the number of slaves directly connected to the slave. Further, the slave information of the slave may also include information such as the device serial number of the slave. This application does not limit this.

[0074] S1012: After receiving the child node information sent by the slave 2-1, the host sends a detection confirmation CMD-TYPE5 to the slave 2-1.

[0075] S1013: The host sends a switching message CMD-TYPE0 to the slave 2-1.

[0076] S1014: After receiving the switching message sent by the host, the slave 2-1 switches the state of the switch unit to the on state.

[0077] S1015: The host sends a node detection command CMD-TYPE6 with rank 2 to slave 3-1.

[0078] For example, in the case of circular query of level N, the host sends a switching message CMD-TYPE0 to the slave N, sets the switch unit of the slave N to the on state, and queries the level N according to the above S1010-S1011. Alternatively, the host sends a switching message CMD-TYPE0 to the slave N, sets the switch unit of the slave N to the blocking state, and the slaves at all levels forward the node detection command CMD-TYPEN+3 sent by the host to the slave N. If the detection is not completed, the status forwarding is not completed based on the slaves at all levels to the host; if the detection is completed, the sub-node information is forwarded based on the slaves at all levels to the host.

[0079] The present application provides a schematic diagram of a long-distance communication bus. That is, a schematic diagram of a topology of a generated bus is provided, see Fig.12 The bus includes a host, slaves 1-1, 1-2, 2-1 and 3-1, wherein slave 2-1 is connected to slave 1-2, and slave 3-1 is connected to slave 2-1.

[0080] S1201: The host sends a switching message CMD-TYPE0 to slaves 1-1, 1-2, 2-1 and 3-1, wherein the switching message may be sent once every a first preset time length and a preset number of times.

[0081] It should be noted that the switch unit of the slave with relay function is in the on state by default, so the slave 1 - 1 , the slave 1 - 2 , the slave 2 - 1 and the slave 3 - 1 can all receive the switching message.

[0082] S1202: After receiving the switching message sent by the host, slaves 1-1, 1-2, 2-1 and 3-1 set the switch units to a blocking state and forward the switching message to the next-level slave.

[0083] S1203: The host sends a node detection control command CMD-TYPE1 with a rank of 0 to slaves 1-1 and 1-2.

[0084] S1204: Slave 1-1 and slave 1-2 mark the current position as rank 1, and forward the node detection control command CMD-TYPE1 of rank 1 downward; slave 2-1 marks the current position as rank 2, and forwards the node detection control command CMD-TYPE1 of rank 2 downward; slave 3-1 marks the current position as rank 3.

[0085] S1205: The host sends a node detection command CMD-TYPE2 with rank 1 to slaves 1-1 and 1-2.

[0086] S1206: Slave 1-1 and slave 1-2 respond according to the backoff mechanism.

[0087] In the response process, slaves 1-1 and 1-2 start to detect child nodes. If they receive data from other slaves during the backoff time, they will give up responding to the host, and the host needs to resend the node detection command CMD-TYPE2 with a rank value of 1.

[0088] S1207: The host sends a detection confirmation CMD-TYPE3 to the slave that first receives the response.

[0089] Among them, the detection confirmation CMD-TYPE3 is accompanied by a slave identifier, which can be the rank value of the slave. For the slave that has sent the detection confirmation CMD-TYPE3, it will no longer respond to the node detection command CMD-TYPE2 sent by the host, and for the slave whose rank value does not correspond to the rank value in the node detection command CMD-TYPE2 sent by the host, it is not necessary to respond to the node detection command CMD-TYPE2 sent by the host. If the host does not receive a response from slaves 1-1 and slaves 1-2 to the node detection command CMD-TYPE2 with a rank of 1 within a certain period of time, it is determined that the detection of this level is completed. For example, a certain period of time is for the host to send the node detection command CMD-TYPE2 several times and wait for a second preset time length.

[0090] S1208: The host sends a switching message CMD-TYPE0 to the slave 1-1.

[0091] S1209: After receiving the switching message sent by the host, the slave 1-1 switches the state of the switch unit to the on state.

[0092] S1210: The host sends a switching message CMD-TYPE0 to slave 1-2.

[0093] exist Fig.12 In the example, slave 1-1 does not include the slaves hanging down, so when slave 1-2 switches the switch unit to the on state, it means that the detection of slave 1-1 is completed, and then the detection of slave 1-2 can continue. Therefore, the host sends a switching message CMD-TYPE0 to slave 1-2, and then detects slave 1-2.

[0094] S1211: After receiving the switching message sent by the host, the slave 1-2 switches the state of the switch unit to the on state.

[0095] S1212: The host sends a node detection command CMD-TYPE4 with rank 2 to slave 2-1.

[0096] In general, the host can only send the node detection command CMD-TYPE4 to the slave with forwarding function, and query according to the rank value.

[0097] S1213: If the subnode detection of the slave 2-1 is not completed, the incomplete status is returned to the host; if the subnode detection of the slave 2-1 is completed, the subnode information is returned to the host.

[0098] S1214: After receiving the child node information sent by the slave 2-1, the host sends a detection confirmation CMD-TYPE5 to the slave 2-1.

[0099] S1215: The host sends a switching message CMD-TYPE0 to the slave 2-1.

[0100] S1216: After receiving the switching message sent by the host, the slave 2-1 switches the state of the switch unit to the on state.

[0101] S1217: The host sends a node detection command CMD-TYPE6 with rank 2 to slave 3-1.

[0102] Through the above two exemplary embodiments, the topology of the bus can be obtained, and then a simulated topology map can be drawn on the display screen of the host. Subsequently, the slave with problems can be quickly located according to the topology map, which facilitates on-site operation and maintenance. In addition, the topology of the bus obtained in the above manner can be compared with the engineering implementation to see whether the wiring is in accordance with the engineering requirements, etc., and risk problems can be identified in advance. Moreover, displaying the topology map of the bus on the display screen, client or web page improves the user experience.

[0103] The above two methods are only two possible exemplary solutions of the embodiments of the present application. Next, the solutions provided by the embodiments of the present application will be further described.

[0104] See also Figure 1 The bus includes a host 101 and multiple slaves 102 , the multiple slaves 102 include a first slave and / or a second slave, and the multiple slaves 102 are cascaded to the host 101 .

[0105] It should be noted that the first slave is a slave with a relay function, and the second slave is a slave without a relay function. The bus may include only the first slave, or only the second slave, or both the first slave and the second slave.

[0106] Multiple slaves 102 are cascaded to the host 101, which means that the slaves 102 are directly connected to the host 101, or the slaves 102 are connected to the host through other devices.

[0107] The multiple slaves 102 are cascaded to the master 101 to connect the multiple slaves 102 together through physical connection to form a back-to-back connection to achieve signal transmission and sharing. Figure 1 , from left to right, it includes a host 101, a first-level slave 102, a second-level slave 102, and a third-level slave 102, and the slaves 102 and the host 101, and the slaves 102 and the slaves 102 are connected through cables. Among them, the second-level slave 102 is connected to the downlink port of the second slave 102 in the first level, and the third-level slave 102 is connected to the downlink port of the first slave 102 in the second level, so it can be considered that the second-level slave 102 is a slave connected to the second slave 102 in the first level, and the third-level slave 102 is a slave connected to the first slave 102 in the second level.

[0108] See also Figure 2 The first slave includes an upstream port 1021, a downstream port 1022 and a switch unit 1023, and the second slave only includes an upstream port 1021. The upstream port 1021 is used to realize the connection between the slave 102 and the upper-level device, and the downstream port 1022 is used to realize the connection between the first slave and the lower-level device. When the switch unit 1023 is in the on state, the upstream port 1021 and the downstream port 1022 are connected. When the switch unit 1023 is in the blocked state, the upstream port 1021 and the downstream port 1022 are blocked. Each switch unit 1023 is initially in the on state.

[0109] The host 101 is used to send a first switching message to all slaves connected to the host, and send a first detection message indicating a first detection level to all slaves connected to the host after a first preset delay. The first detection level initially indicates the first level.

[0110] The first switching message is used to control the switch unit 1023 to block the upstream port 1021 and the downstream port 1022. To disconnect the physical connection between the front and rear stages of the slave 102, it is necessary to forward the data received at the upstream port 1021 to the downstream port 1022, or forward the data received at the downstream port 1022 to the upstream port 1021 through software. That is, the forwarding of data in the slaves 102 at all levels can only be achieved through software, and the forwarding of data in the slaves 102 at all levels cannot be achieved through hardware design. This state can be called "soft relay".

[0111] It should be noted that, by default, the switch unit 1023 in the first slave is in the on state. The upstream port 1021 and the downstream port 1022 are connected through hardware, and there is no need to implement forwarding through software. The data received by the upstream port 1021 can be directly forwarded to the downstream port 1022 through hardware, and the data received by the downstream port 1022 can be directly forwarded to the upstream port 1021 through hardware. That is, each first slave is physically connected, and the forwarding of data in the first slaves at each level can be achieved through hardware design. This state can be called "hard relay". When the switch unit 1023 is in the on state, the input data can be sent from the upstream port 1021 to the downstream port 1022, and the input data can also be uploaded from the downstream port 1022 to the upstream port 1021.

[0112] For example, the bus may be a 485 bus or other types of serial bus, which is not limited in the present application.

[0113] In one example, after the host 101 sends the first switching message to the slave 102, the first slave can set the switch unit 1023 to the blocking state after a first preset delay after receiving the first switching message. The first preset delay is set according to actual conditions, wherein the first preset delay is greater than the time taken by the host 101 in the bus to send the first switching message to the last slave 102 of the last level slave 102. For example, the first preset delay can be set to 0.5 seconds, 1 second, or 1.5 seconds, etc. The number of times the host 101 sends the first switching message can be set to a preset value according to actual conditions, for example, sending the first switching message 2 to 3 times.

[0114] In a possible embodiment, each first slave is further configured to send the first switching message to all slaves 102 on the bus through the downlink port 1022 of the first slave itself in response to the first switching message.

[0115] See also Figure 3 , when the switch units 1023 of all the first slaves in the bus are set to the blocking state, the bus will be disconnected from a complete bus into segments of sub-buses without interfering with each other. An example, in which the first dotted box is used to represent the first segment of the sub-bus, which can be named subnet 1, the second dotted box is used to represent the second segment of the sub-bus, which can be named subnet 2, and the third dotted box is used to represent the third segment of the sub-bus, which can be named subnet 3. It is easy to understand that data transmission and reception between sub-buses of different segments cannot be realized through hardware design. That is, the first slave that receives the first switching message sent by the host 101 sets the state of the switch unit 1023 to the blocking state, resulting in the next-level slave 102 of the slave 102 being unable to receive the first switching message sent by the host 101. Therefore, the first slave that receives the first switching message sent by the host 101 will also forward the received first switching message to its next-level slave 102 through the downlink port 1022 to avoid the above situation.

[0116] The long-distance communication bus provided in the embodiment of the present application is achieved by setting the switch units 1023 of the first slave machines in the long-distance communication bus to a blocking state, so that each level of the first slave machine only needs to detect the level of the slave machine 102 at the next level and mark the corresponding position of the slave machine 102 to complete the topology detection of each level of the slave machines 102.

[0117] Next, the level of the slave 102 is obtained by the slave 102 responding to the first detection message, specifically:

[0118] The first detection message representing the first detection level broadcast by the host 101 after the first preset delay can only be received by the first-level slave 102. The first detection level can be represented by a rank value, and the rank value can be used to represent the level of the slave 102. For example, the level of the slave 102 is represented by the rule of rank values ​​0, 1, 2, 3... For example, when the rank value is 1, the level of the slave 102 is 1; when the rank value is 2, the level of the slave 102 is 2; when the rank value is 3, the level of the slave 102 is 3, and so on.

[0119] For example, the level of the slave 102 can also be represented by the rule of rank values ​​2, 4, 6, 8... For example, when the rank value is 4, the level of the slave 102 is 1; when the rank value is 6, the level of the slave 102 is 2; when the rank value is 8, the level of the slave 102 is 3, and so on.

[0120] For the convenience of description, the following steps will be described by taking the rule that the rank values ​​are 0, 1, 2, 3, ... to represent the hierarchy of the slave 102 as an example.

[0121] Each first slave 102 is used to switch the switch unit 1023 to the blocking state in response to the first switching message; each slave 102 is used to respond to the first detection message and parse the first detection level represented in the first detection message as the level of the slave 102.

[0122] Each first slave is used to update the level represented by the first detection message to the next level of the first detection level, and send the updated first detection message to all slaves connected to the downlink port 1022 .

[0123] For example, when the host 101 broadcasts a detection frame with a rank value of 0 to the bus, in this case, only the first-level slave 102 can receive the detection frame; after receiving the detection frame, the first-level slave 102 marks its current position with a rank value of 1, and forwards the detection frame with a rank value of 1, in this case, only the second-level slave 102 can receive the detection frame, and the second-level slave 102 receives the detection frame, marks its current position with a rank value of 2, and forwards the detection frame with a rank value of 2, and so on, until all slaves 102 in the bus obtain their corresponding rank values. The rank value is used to indicate the level of the slave 102. The level of the slave 102 is used to indicate the cascade quantity information of the slave 102 in the bus, and the maximum slave level is the total cascade quantity information of the bus.

[0124] The host 101 is further used to detect each slave 102 in turn according to the level of each first slave to obtain the topology of the bus.

[0125] It should be noted that when detecting each slave 102 according to the slave level to obtain the bus topology, considering that the second slave does not have any slaves hanging below it, when detecting each slave 102, only the first slave with a relay function can be detected without detecting the second slave.

[0126] The topological structure refers to the method of studying the relationship between points and lines in topology that is independent of size and shape. The computer and communication equipment in the network are abstracted as a point, and the transmission medium is abstracted as a line. The geometric figure composed of points and lines is the topological structure of the computer network. In computer networks, topology refers to the form and method of connecting each node.

[0127] After detecting each slave 102 in turn according to the level of each first slave, the slave information of the slaves under each slave 102 can be obtained, and the slave information at least includes the number of slaves. In addition, the slave information may also include the device type of the slave, the rank value of the slave, the device serial number of the slave, and whether the slave is the first slave or the second slave, so that slave detection, slave color display, and slave distinction of the same type can be performed based on the above information.

[0128] The device type of the slave device is used to indicate the type of device. For example, the slave device may be a camera, a mobile phone, or a computer.

[0129] The topology of the bus can be obtained based on the hierarchy of the slaves 102 and the slave information of each slave connected to the first slave.

[0130] The specific process of the host 101 detecting each slave 102 in turn according to the level of each first slave is detailed in the subsequent content, and this application will not describe it in detail here.

[0131] The host 101 can draw a simulated topology on a display screen or a web server page to display the wiring scheme of the bus, for example, to obtain the cascade quantity information, the number of slaves at each level and the total number of slaves; the above parameters obtained are used as parameters of the routing algorithm; the host calls the routing algorithm to determine the routing strategy. That is, it is determined whether to set the switch unit 1023 to a blocking state, and which switch units 1023 of the slaves 102 are set to a blocking state, wherein after the switch unit 1023 is set to a blocking state, data can be forwarded through software to improve the communication signal and distance.

[0132] Different algorithms will be used to determine the routing strategy according to different parameters. An example is Figure 4 As shown, when the cascade quantity information is 8, the number of slaves at each level is 2, and the total number of slaves is 16, the following algorithm is used to determine the routing strategy.

[0133] In a possible embodiment, the host 101 is further used to: for each level of slaves 102 in the multi-level slaves 102, if the number of first slaves 102 in each level is less than a first preset value, determine the target number to be the first target number, the target number is the number of first slaves that set the switch unit 1023 to a blocking state, and the first target number is the quotient of the total number of slaves 102 and the second preset value; if the first target number is greater than a third preset value, determine to set the switch unit 1023 of the first slave whose level rank value is less than the product of the first target number and the second preset value and is an integer multiple of the second preset value to a blocking state; if the first target number is not greater than the third preset value, then Determine not to set the switch unit 1023 of the first slave to a blocking state; if the number of the first slaves 102 at each level is not less than the first preset value, determine the target number to be the second target number, the second target number being the quotient of the cascade number of the slaves 102 and the fourth preset value, and if the first target number is greater than the third preset value, determine to set the switch unit 1023 of the first slave whose rank value is less than the product of the second target number and the fourth preset value and is an integer multiple of the fourth preset value to a blocking state; if the first target number is not greater than the third preset value, determine not to set the switch unit 1023 of the first slave to a blocking state; send a fourth switching message to the first slave connected to the host 101;

[0134] Each first slave is further configured to switch the switch unit 1023 to a blocking state in response to a fourth switching message.

[0135] It should be noted that only the first slave with relay function needs to respond to the fourth switching message and switch the switch unit 1023 to the blocking state, while the second slave without relay function does not need to respond to the fourth switching message and switch the switch unit 1023 to the blocking state.

[0136] Furthermore, the host may adopt the following algorithm to determine the routing strategy, or other electronic devices may adopt the following algorithm to determine the routing strategy. This application does not limit this.

[0137] For an example, see Figure 5 , using routing algorithm to determine routing strategy includes the following steps:

[0138] S501: calling routing algorithm;

[0139] S502: Determine whether the number of first slaves at each level is less than a first preset value;

[0140] S503: If yes, determine that the number of first slaves for which the switch unit is set to a blocking state is the quotient of the total number of slaves and a second preset value;

[0141] S504: If not, determining that the number of first slaves for which the switch unit is set to a blocking state is the quotient of the cascade number of slaves and a fourth preset value;

[0142] S505: Determine whether the number of first slaves that set the switch unit to a blocking state is greater than a third preset value;

[0143] S506: If yes, setting the switch unit of the first slave whose rank value is less than the product of the first target number and the second preset value and is an integer multiple of the second preset value to a blocking state;

[0144] S507: If not, then the switch unit of the first slave is not set to a blocking state;

[0145] S508: Determine whether the number of first slaves that set the switch unit to a blocking state is greater than a third preset value;

[0146] S509: If yes, setting the switch unit of the first slave whose rank value is less than the product of the second target number and the fourth preset value and is an integer multiple of the fourth preset value to a blocking state;

[0147] S510: If not, the switch unit of the first slave is not set to the blocking state.

[0148] An example, such as Figure 6 As shown, the cascade quantity information is 16, the number of slaves in each level is 1, and the total number of slaves is 16, which belongs to the daisy chain topology, has no bifurcation, and does not need to set the switch unit 1023 to the blocking state.

[0149] An example, such as Figure 7 As shown, the cascade quantity information is 1, the number of slaves in each stage is 16, and the total number of slaves is 16, which belongs to a star topology, and there is no need to set the switch unit 1023 of the first slave to a blocking state.

[0150] In the embodiment of the present application, the topology of the bus is detected and the routing algorithm is automatically called to determine the routing strategy without user perception, and the final communication path is determined by the host or other electronic devices.

[0151] In a possible embodiment, Figure 8 As shown, after the host 101 draws the simulated topology on the display screen or the network server page, it can add color distinction and display information according to the type of the slave. For example, the information can be the slave identification of the slave 102, such as host 4851, slave 1231, slave 1232, slave 1233, slave 12311, slave 12312 and slave 12313, and the slaves with attached slaves are marked with colors.

[0152] The following is a specific embodiment of the host 101 detecting each slave 102 in turn according to the level of each first slave to obtain the topology of the bus:

[0153] In a possible embodiment, after receiving the first detection message and forwarding it to the downstream port, each first slave machine 102 can start sending a detection message for detecting the information of the downstream slave machine. The detection command and timing carried in the detection message are consistent with the sending format of the host 101, and the response format of the downstream slave machine is also consistent with the format of the first node message responding to the host 101.

[0154] Specifically, the host 101 is used to detect the first-level slaves 102, wherein the first-level slaves 102 are the slaves 102 directly connected to it.

[0155] Each first slave is further used to detect the slave 102 connected to the downlink port 1022 as a downstream slave. Each slave 102 records the number of its downstream slaves as the number of downstream slaves.

[0156] It should be noted that each slave 102 can also record the device type of the slave below, the rank value of the slave, the device serial number of the slave, and whether the slave has a relay function, so that slave detection, slave color display, and distinction of slaves of the same type can be performed based on the above information.

[0157] The host 101 is specifically configured to send a second detection message to all first slaves of the second detection level respectively, wherein the second detection level is initially the first level;

[0158] Each first slave is further configured to send a first node message to the host 101 in response to the second detection message, wherein the first node message is used to indicate a slave connected to the first slave;

[0159] The host 101 is used to send a second switching message to all first slaves of the second detection layer, so that the first slaves switch the switch unit 1023 to the on state in response to the second switching message; take the next layer of the second detection layer as the new second detection layer, return to execute the step of sending the second detection message to all first slaves of the second detection layer respectively until the second detection layer does not include the first slave; determine the topology of the bus according to the received first node message.

[0160] An example, such as Figure 11-1 and Figure 11-2As shown, in this embodiment, the slaves 102 of the first level are numbered 1.1, 1.2 and 1.3 in sequence, the slaves 102 of the second level are numbered 2.1, 2.2, 2.3 and 2.4 in sequence, and the slaves 102 of the third level are numbered 3.1, 3.2 and 3.3 in sequence. The host 101 detects the slaves numbered 1.1, 1.2 and 1.3 to obtain the slaves under the host; each first slave detects the slaves of its downstream port as its slaves under it. For example, the slave 102 under the slave 102 numbered 1.1 is the slave 102 numbered 2.1, the slave 102 under the slave 102 numbered 1.2 is the slave 102 numbered 2.2, 2.3 and 2.4, and the slave 102 under the slave 102 numbered 2.3 is the slave 102 numbered 3.1, 3.2 and 3.3. The host 101 sends a first detection message to the slaves 102 numbered 1.1 and 1.2 respectively, and the slaves 102 numbered 1.1 and 1.2 respond to the first detection message and send a first node message to the host 101, and the first node message is used to indicate the slaves hanging below. Afterwards, the host 101 sends a second switching message to the slaves 102 numbered 1.1 and 1.2 of the first level, so that the slaves 102 numbered 1.1 and 1.2 of the first level respond to the second switching message and switch the switch units of the slaves 102 numbered 1.1 and 1.2 of the first level to the on state. Afterwards, take the next level as the new detection level, and execute the step of the host 101 sending the second detection message to all the first slaves of the detection level until the detection level does not include the first slave.

[0161] It should be noted that the slave 102 without a relay function does not need to perform the above polling steps.

[0162] For an example, see Fig. 9 The first slave at the first level responds to the switching message and switches the switch unit 1023 to the on state, so that the host 101, the first slave at the first level and the slave 102 at the second level are connected, so that the bus only includes subnet 1 and subnet 2.

[0163] In a possible embodiment, each first slave is configured to send a first node message to the host 101 if the first slave has completed the detection of the downstream slaves;

[0164] Each first slave is also used to send a second node message to the host 101 if the first slave has not completed the detection of the downstream slave, so that the host 101 responds to the second node message and re-sends the second detection message to the first slave at a preset time interval.

[0165] In a possible embodiment, the host 101 is used to detect the slave 102 of the third detection level, and the third detection level is initially the first level; non-repeatedly select a first slave from the first slaves in the third detection level as the target slave; send a third switching message to the target slave, so that the target slave responds to the third switching message and switches the switch unit 1023 to the on state; send a first polling message to the slaves of the downstream port of the target slave of the fourth detection level respectively, and the fourth detection level is initially the second level;

[0166] Each slave 102 is used to send a third node message to the host in response to the first polling message, where the third node message is used to indicate the slave itself that sends the third node message;

[0167] The host 101 is used to return to the step of non-repeatedly selecting a first slave as a target slave from the first slaves in the third detection layer, until all the first slaves in the third detection layer are selected as target slaves; using the next layer of the third detection layer as a new third detection layer and the next layer of the fourth detection layer as a new fourth detection layer to return to the step of selecting a first slave as a target slave from the first slaves in the third detection layer, until the fourth detection layer does not include any slaves; and determining the topology of the bus according to the received third node message.

[0168] An example, such as Figure 11-1 and Figure 11-2 As shown, in this embodiment, the slaves 102 of the first level are numbered 1.1, 1.2 and 1.3 in sequence, the slaves 102 of the second level are numbered 2.1, 2.2, 2.3 and 2.4 in sequence, and the slaves 102 of the third level are numbered 3.1, 3.2 and 3.3 in sequence. The slaves 102 of the first level are polled first, and for each slave 102 in the first level of slaves 102, the slaves 102 under each slave 102 are polled in a preset order. For example, the slaves 102 under the slave 102 numbered 1.1 in the first level are polled first, and then the slaves 102 under the slave 102 numbered 1.2 in the first level of slaves 102 are polled, until the polling of the slaves 102 under all the slaves 102 of the first level is completed. Afterwards, the above steps are performed again to poll the slaves 102 of the second-level slaves 102 in sequence, until the polling of the slaves 102 of the second level is completed. The above operations are repeated until the polling of all slaves 102 is completed.

[0169] It should be noted that, in the embodiment of the present application, in the case of polling, the above steps may be performed only on the first slave until the polling of all first slaves is completed.

[0170] In a possible embodiment, the slave is detected in the following manner, including:

[0171] Send detection messages to each slave machine at the level to be detected;

[0172] By each slave responding to the detection message, the detection level indicated in the detection message is parsed and obtained. If the detection level is the level of the slave and the slave does not receive the confirmation message, the fourth section message is sent to the device that sent the detection message according to the backoff mechanism;

[0173] In response to the first received fourth node message, a confirmation message is sent to the slave that sent the fourth node message.

[0174] In one example, the host 101 broadcasts a detection message after a certain delay, and each slave 102 responds to the detection message. Considering that the data transmission mode of the long-distance communication bus may be half-duplex, data conflicts may occur after data transmission. Therefore, each slave 102 may use a backoff algorithm to respond to the detection message.

[0175] The backoff mechanism is specifically as follows: determine the basic backoff time t. On the bus transmission line, the one-way end-to-end transmission time can be recorded as τ, and the basic backoff time t can be determined to be 2τ. Randomly take a number from the discrete integer set containing the rank value of the slave 102 and record it as R, then the backoff time T required for retransmission is T=R+2τ. Each slave 102 sends data according to its own backoff time to avoid data conflicts caused by simultaneous transmission. Among them, the random number R is generated based on a seed, which can be the device serial number of the slave, or it can be based on the processor number in the slave, or it can be the timer count value when the machine is powered on. Among them, the range of the random number R is within a certain time interval. For example, the range of the random number R is 0-100ms.

[0176] In one example, a first slave whose slave level is the first level and has not received a confirmation message sends a node message representing the first slave itself to the host 101, and the node message includes at least information such as the device type of the slave and whether the slave is the first slave. In response to the first received node message, the host 101 sends a confirmation message to the first slave that sent the node message.

[0177] In a possible embodiment, after obtaining the topology of the bus, the switch unit 1023 of the first slave in the bus may be set to an on state.

[0178] A long-distance communication bus provided by an embodiment of the present application includes a host and multiple slaves, the multiple slaves include a first slave and / or a second slave, the multiple slaves are cascaded to the host, the first slave includes an upstream port, a downstream port and a switch unit, the second slave only includes an upstream port, the host sends a first switching message to all slaves connected to the host, and sends a first detection message representing a first detection level to all slaves connected to the host after a first preset delay, the first detection level initially representing the first level; each first slave switches the switch unit to a blocking state in response to the first switching message; each slave responds to the first detection message, parses and obtains the first detection level represented in the first detection message as the level of the slave; each first slave updates the level represented by the first detection message to the next level of the first detection level, and sends the updated first detection message to all slaves connected to the downstream port; the host is also used to detect each slave in turn according to the level of each first slave to obtain the topology of the bus.

[0179] The embodiment of the present application also provides a long-distance communication host, wherein the host is cascaded with multiple slaves, the multiple slaves include a first slave and / or a second slave, and the first slave includes an upstream port, a downstream port and a switch unit, and the second slave includes only an upstream port, the upstream port is used to realize the connection between the first slave and the upper-level device, the downstream port is used to realize the connection between the slave and the lower-level device, when the switch unit is in the on state, the upstream port and the downstream port are connected, when the switch unit is in the blocked state, the upstream port and the downstream port are blocked, and each switch unit is initially in the on state;

[0180] A host, used to send a first switching message to all slaves connected to the host, and send a first detection message indicating a first detection level to all slaves connected to the host after a first preset delay, wherein the first detection level initially indicates the first level, so that each first slave responds to the first switching message and switches the switch unit to a blocking state; each slave responds to the first detection message, parses and obtains the first detection level indicated in the first detection message as the level of the slave; each first slave updates the level indicated by the first detection message to the next level of the first detection level, and sends the updated first detection message to all slaves connected to the downlink port;

[0181] The host is further used to detect each slave in turn according to the level of each first slave to obtain the topology of the bus.

[0182] See also Fig.13 The present application also provides a bus topology detection method, which includes the following steps:

[0183] S1301: Send a first switching message to all slaves connected to the host through the host, and send a first detection message indicating a first detection level to all slaves connected to the host after a first preset delay, and the first detection level indicates the first level when it is initial; all slaves include the first slave and / or the second slave, and all slaves are cascaded to the host, the first slave includes an uplink port, a downlink port and a switch unit, the second slave includes only an uplink port, the uplink port is used to realize the connection between the first slave and the upper-level device, the downlink port is used to realize the connection between the slave and the lower-level device, when the switch unit is in the on state, the uplink port and the downlink port are connected, when the switch unit is in the blocked state, the uplink port and the downlink port are blocked, and each switch unit is initially in the on state;

[0184] S1302: each first slave responds to the first switching message, switching the switch unit to the blocking state; each slave responds to the first detection message, parsing to obtain the first detection level represented in the first detection message as the level of the slave; and updating the level represented by the first detection message to the next level of the first detection level by the first slave, and sending the updated first detection message to all slaves connected to the downlink port;

[0185] S1303: The host detects each slave in turn according to the level of each first slave to obtain the topology of the bus.

[0186] See also Fig.14 , an embodiment of the present application provides a bus relay control method, the method is applied in a long-distance communication bus, the bus includes a host and multiple slaves, the multiple slaves include a first slave and / or a second slave, the multiple slaves are cascaded to the host, and the first slave includes an upstream port, a downstream port and a switch unit, the second slave only includes an upstream port, the upstream port is used to realize the connection between the first slave and the upper-level device, the downstream port is used to realize the connection between the slave and the lower-level device, when the switch unit is in the on state, the upstream port and the downstream port are connected, when the switch unit is in the blocked state, the upstream port and the downstream port are blocked, and each switch unit is initially in the on state;

[0187] Methods include:

[0188] S1401: For each level of slaves in the multi-level slaves, if the number of first slaves in each level is less than the first preset value, the target number is determined to be the first target number, the target number is the number of first slaves whose switch units are set to the blocking state, and the first target number is the quotient of the total number of slaves and the second preset value; if the first target number is greater than the third preset value, it is determined to set the switch unit of the first slave whose rank value is less than the product of the first target number and the second preset value and is an integer multiple of the second preset value to the blocking state; if the first target number is not greater than the third preset value, it is determined not to set the first target number to the blocking state. The switch unit of the slave is set to a blocking state; if the number of first slaves in each level is not less than a first preset value, the target number is determined to be a second target number, the second target number is the quotient of the cascade number of slaves and a fourth preset value, and if the first target number is greater than a third preset value, it is determined to set the switch unit of the first slave whose rank value is less than the product of the second target number and the fourth preset value and is an integer multiple of the fourth preset value to a blocking state; if the first target number is not greater than the third preset value, it is determined not to set the switch unit of the first slave to a blocking state; a fourth switching message is sent to all first slaves connected to the host;

[0189] S1402: Switching the switch unit to a blocking state by each first slave in response to the fourth switching message.

[0190] See also Fig.15 , the present application embodiment also provides an electronic device, such as Fig.15 As shown, including:

[0191] Memory 1501, used for storing computer programs;

[0192] The processor 1502 is used to execute the program stored in the memory 1501, and implement the following steps:

[0193] The bus includes a host and multiple slaves, the multiple slaves include a first slave and / or a second slave, the multiple slaves are cascaded to the host, and the first slave includes an upstream port, a downstream port and a switch unit, the second slave includes only an upstream port, the upstream port is used to realize the connection between the first slave and the upper-level device, the downstream port is used to realize the connection between the slave and the lower-level device, when the switch unit is in the on state, the upstream port and the downstream port are connected, when the switch unit is in the blocked state, the upstream port and the downstream port are blocked, and each switch unit is initially in the on state;

[0194] Sending a first switching message to all slaves connected to the host through the host, and sending a first detection message indicating a first detection level to all slaves connected to the host after a first preset delay, wherein the first detection level indicates the first level when it is initial;

[0195] Each first slave responds to the first switching message, switching the switch unit to the blocking state; each slave responds to the first detection message, parsing to obtain the first detection level represented in the first detection message as the level of the slave; and the first slave updates the level represented by the first detection message to the next level of the first detection level, and sends the updated first detection message to all slaves connected to the downlink port;

[0196] The host detects each slave in turn according to the level of each first slave to obtain the topology of the bus.

[0197] In addition, the electronic device may further include a communication bus and / or a communication interface, and the processor 1502, the communication interface, and the memory 1501 communicate with each other via the communication bus.

Claims

1. A bus topology detection method, characterized in that: The method comprises: A first switching message is sent by the host to all slaves connected to the host, and a first detection message indicating a first detection level is sent to all slaves connected to the host after a first preset delay, wherein the detection message carries a rank value, and the first detection level initially indicates the first level, wherein the detection message is a detection command; all the slaves include a first slave and a second slave, and all the slaves are cascaded to the host, the first slave includes an uplink port, a downlink port and a switch unit, the second slave includes only an uplink port, the uplink port is used to realize the connection between the first slave and the upper-level device, the downlink port is used to realize the connection between the slave and the lower-level device, when the switch unit is in the on state, the uplink port and the downlink port are connected, when the switch unit is in the on state, the first slave is in a hard relay state, when the switch unit is in the blocked state, the uplink port and the downlink port are blocked, when the switch unit is in the blocked state, the first slave is in a soft relay state, and each of the switch units is initially in the on state; By each of the first slaves responding to the first switching message, the switch unit is switched to the blocking state; by each of the slaves responding to the first detection message, a first detection level represented by the rank value carried in the first detection message is parsed and obtained as the level of the first slave and the second slave; and by the first slave, the level represented by the first detection message is updated to the next level of the first detection level, and the updated first detection message is sent to all slaves connected to the downlink port; The host detects each of the first slaves in turn according to the level of each of the first slaves to obtain the topology of the bus; The detecting each of the slaves in turn according to the level of each of the first slaves by the host to obtain the topology of the bus includes: The host detects the slaves of the first level; each of the first slaves detects the slaves of the downstream port as the slaves hanging down; the host sends a second detection message to all the first slaves of the second detection level respectively, wherein the second detection level is the first level in the initial case; each of the first slaves responds to the second detection message, and after detecting the slave hanging down of the first slave, sends a first node message to the host, and the first node message is used to indicate the slave hanging down of the first slave; the host sends a second switching message to all the first slaves of the second detection level, so that the first slave switches the switch unit to the on state in response to the second switching message; the next level of the second detection level is used as the new second detection level, and the step of sending the second detection message to all the first slaves of the second detection level respectively by the host is returned to execute until the second detection level does not include the first slave; the host determines the topology of the bus according to the received first node message; or, The detecting each of the slaves in turn according to the level of each of the first slaves by the host to obtain the topology of the bus includes: The host detects slaves of the third detection level, and the third detection level is initially the first level; a first slave is selected from the first slaves in the third detection level without repetition as a target slave; a third switching message is sent to the target slave, so that the target slave switches the switch unit to the on state in response to the third switching message; the host sends a first polling message to the slaves of the downstream port of the target slave at the fourth detection level, and the fourth detection level is initially the second level; The host sends a first polling message to the slaves of the downstream port of the target slave at the fourth detection level respectively, including: sending a detection command to the slaves of the downstream port of the target slave at the fourth detection level respectively in a polling manner by the host; sending a third node message to the host by each of the slaves in response to the first polling message, wherein the third node message is used to represent the slave itself that sends the third node message; returning to the step of non-repeatedly selecting a first slave as the target slave from the first slaves in the third detection level until the The first slaves in the third detection level are all taken as target slaves; the next level of the third detection level is taken as a new third detection level, and the next level of the fourth detection level is taken as a new fourth detection level, and the execution is returned to select a first slave from the first slaves in the third detection level as the target slave, until the fourth detection level does not include the slave; the topology of the bus is determined according to the received third node message; the method also includes: each of the first slaves responds to the first switching message, and sends the first switching message to all slaves connected to the downlink port of the first slave itself; the slaves are detected in the following manner, including: sending a detection message to each of the slaves of the level to be detected respectively; each of the slaves responds to the detection message, and the detection level represented in the detection message is parsed, and if the detection level is the level of the slave and the slave does not receive a confirmation message, a fourth node message is sent to the device that sends the detection message according to the backoff mechanism; in response to the first received fourth node message, a confirmation message is sent to the slave that sends the fourth node message.

2. The method according to claim 1, characterized in that The sending of the first node message to the host comprises: If the first slave has completed the detection of the downstream slave, sending a first node message to the host; The method further comprises: If the first slave has not completed the detection of the downstream slave, the second node message is sent to the host, so that the host responds to the second node message and re-sends the second detection message to the first slave at a preset time interval; The method further comprises: Sending the first switching message to all slaves connected to the downlink port of the first slave by each of the first slaves in response to the first switching message; Detect slaves by: Sending detection messages to the slaves of the level to be detected respectively; By each of the slaves responding to the detection message, parsing to obtain the detection level indicated in the detection message, if the detection level is the level of the slave and the slave has not received a confirmation message, sending a fourth node message to the device that sent the detection message according to the backoff mechanism; In response to the fourth node message received first, a confirmation message is sent to the slave that sent the fourth node message.

3. A long-distance communication bus, characterized in that: The present invention comprises a host and a plurality of slaves, wherein the plurality of slaves comprises a first slave and a second slave, wherein the plurality of slaves are cascaded to the host, and the first slave comprises an upstream port, a downstream port and a switch unit, and the second slave comprises only an upstream port, wherein the upstream port is used to realize the connection between the first slave and a device at an upper level, and the downstream port is used to realize the connection between the slave and a device at a lower level, and when the switch unit is in a conducting state, the upstream port and the downstream port are conducted, when the switch unit is in a conducting state, the first slave is in a hard relay state, when the switch unit is in a blocking state, the upstream port and the downstream port are blocked, when the switch unit is in a blocking state, the first slave is in a soft relay state, and each of the switch units is initially in the conducting state; The host is used to send a first switching message to all slaves connected to the host, and send a first detection message indicating a first detection level to all slaves connected to the host after a first preset delay, wherein the detection message carries a rank value, and the first detection level initially indicates the first level, wherein the detection message is a detection command; Each of the first slaves is configured to switch the switch unit to the blocking state in response to the first switching message; Each of the slaves is configured to respond to the first detection message and parse to obtain a first detection level represented by a rank value carried in the first detection message as the level of the first slave and the second slave; Each of the first slaves is configured to update the level represented by the first detection message to a level next to the first detection level, and send the updated first detection message to all slaves connected to the downlink port; The host is further configured to detect each of the first slaves in sequence according to the level of each of the first slaves to obtain a topology of the bus; The host is used to detect slaves of the first level; each of the first slaves is also used to detect slaves connected to the downlink port as downstream slaves; the host is specifically used to send second detection messages to all the first slaves of the second detection level, wherein the second detection level is initially the first level; each of the first slaves is used to respond to the second detection message and, after detecting the downstream slave of the first slave, send a first node message to the host, wherein the first node message is used to indicate the downstream slave of the first slave; the host is used to send second detection messages to all the first slaves of the second detection level. The first slave sends a second switching message, so that the first slave switches the switch unit to the on state in response to the second switching message; taking the next level of the second detection level as the new second detection level, returning to execute the step of sending the second detection message to all the first slaves of the second detection level respectively, until the second detection level does not include the first slave; determining the topology of the bus according to the received first node message; each of the first slaves is further used to send the first switching message to all slaves connected to the downlink port of the first slave itself in response to the first switching message; or, The host is used to detect slaves of the third detection level, which is initially the first level; non-repeatedly select a first slave from the first slaves in the third detection level as a target slave; send a third switching message to the target slave, so that the target slave switches the switch unit to the on state in response to the third switching message; send a first polling message to the slaves of the downlink port of the target slave of the fourth detection level, respectively, and the fourth detection level is initially the second level; the first polling message to the target slave of the fourth detection level is respectively The method comprises: sending a detection command to the slaves of the downstream port of the target slave in the fourth detection level in a polling manner; each of the slaves is used to send a third node message to the host in response to the first polling message, and the third node message is used to represent the slave itself that sends the third node message; the host is used to return to the step of non-repeatedly selecting a first slave as the target slave from the first slaves in the third detection level until all the first slaves in the third detection level are selected as the target slaves; The step of returning to the third detection level as a new third detection level and the step of returning to the fourth detection level as a new fourth detection level to select a first slave from the first slaves in the third detection level as a target slave until the fourth detection level does not include the slave; determining the topology of the bus according to the received third node message; each of the first slaves is further configured to respond to the first switching message and send the first switching message to all slaves connected to the downlink port of the first slave; the devices in the bus are configured to send the first switching message to the first slaves respectively. Each slave of the level to be detected sends a detection message, wherein the devices in the bus are used to represent the upper names of the master and the slaves; each slave is used to respond to the detection message, parse and obtain the detection level represented in the detection message, if the detection level is the level of the slave and the slave has not received a confirmation message, send a fourth node message to the device that sent the detection message according to the backoff mechanism; the devices in the bus are used to send a confirmation message to the slave that sent the fourth node message in response to the fourth node message received first.

4. The bus according to claim 3, characterized in that: Each of the first slaves is configured to send a first node message to the host if the first slave has completed detection of the downstream slave; Each of the first slaves is further configured to send a second node message to the host if the first slave has not completed the detection of the downstream slave, so that the host responds to the second node message and re-sends the second detection message to the first slave at a preset time interval; The device in the bus is used to send a detection message to each of the slaves at the level to be detected, wherein the device in the bus is used to represent the upper name of the master and the slave; Each of the slaves is configured to respond to the detection message, parse and obtain the detection level indicated in the detection message, and if the detection level is the level of the slave and the slave has not received a confirmation message, send a fourth node message to the device that sent the detection message according to a backoff mechanism; The device in the bus is used to send a confirmation message to the slave that sends the fourth node message in response to the fourth node message received first.

5. The bus according to claim 3, characterized in that: The host is also used for: For each level of slaves in the multi-level slaves, if the number of the first slaves in each level is less than a first preset value, the target number is determined to be the first target number, the target number is the number of first slaves that set the switch unit to the blocking state, and the first target number is the quotient of the total number of the slaves and a second preset value; if the first target number is greater than a third preset value, it is determined to set the switch unit of the first slave whose level rank value is less than the product of the first target number and the second preset value and is an integer multiple of the second preset value to the blocking state; if the first target number is not greater than the third preset value, it is determined not to set the switch unit of the first slave The switch unit is set to a blocking state; if the number of the first slaves at each level is not less than a first preset value, the target number is determined to be a second target number, the second target number is the quotient of the cascade number of the slaves and a fourth preset value, and if the first target number is greater than a third preset value, it is determined to set the switch unit of the first slave whose rank value is less than the product of the second target number and the fourth preset value and is an integer multiple of the fourth preset value to a blocking state; if the first target number is not greater than the third preset value, it is determined not to set the switch unit of the first slave to a blocking state; a fourth switching message is sent to all first slaves connected to the host; Each of the first slaves is further configured to switch the switch unit to the blocking state in response to the fourth switching message.

6. A long-distance communication host, characterized in that: The host is arranged on a bus, and the host is cascaded with a plurality of slaves, the plurality of slaves include a first slave and a second slave, and the first slave includes an upstream port, a downstream port and a switch unit, the second slave includes only an upstream port, the upstream port is used to realize the connection between the first slave and a device at an upper level, the downstream port is used to realize the connection between the slave and a device at a lower level, when the switch unit is in a conducting state, the upstream port and the downstream port are conducted, when the switch unit is in a conducting state, the first slave is in a hard relay state, when the switch unit is in a blocking state, the upstream port and the downstream port are blocked, when the switch unit is in a blocking state, the first slave is in a soft relay state, and each of the switch units is initially in the conducting state; The host is used to send a first switching message to all slaves connected to the host, and send a first detection message indicating a first detection level to all slaves connected to the host after a first preset delay, wherein the detection message carries a rank value, and the first detection level initially indicates the first level, wherein the detection message is a detection command, so that each of the first slaves responds to the first switching message and switches the switch unit to the blocking state; each of the slaves responds to the first detection message and parses to obtain the first detection level indicated by the rank value carried in the first detection message as the level of the first slave and the second slave; each of the first slaves updates the level indicated by the first detection message to the next level of the first detection level, and sends the updated first detection message to all slaves connected to the downlink port; The host is further configured to detect each of the first slaves in sequence according to the level of each of the first slaves to obtain a topology of the bus; The host is specifically used to detect the slaves of the first level; send second detection messages to all the first slaves of the second detection level respectively, so that each of the first slaves responds to the second detection message, and after detecting the slaves hanging down from the first slave, sends a first node message to the host, and the first node message is used to indicate the slaves hanging down from the first slave; wherein the second detection level is initially the first level, and each of the first slaves detects the slaves of the downstream port as the slaves hanging down before responding to the second detection message and sending the first node message to the host; send a second switching message to all the first slaves of the second detection level, so that the first slave switches the switch unit to the on state in response to the second switching message; take the next level of the second detection level as the new second detection level, and return to execute the step of sending the second detection message to all the first slaves of the second detection level respectively, until the second detection level does not include the first slave; determine the topology of the bus according to the received first node message; or, The host is specifically used to detect slaves of the third detection level, and the third detection level is initially the first level; non-repeatedly select a first slave from the first slaves in the third detection level as the target slave; send a third switching message to the target slave, so that the target slave responds to the third switching message and switches the switch unit to the on state; respectively send a first polling message to the slaves of the downstream port of the target slave of the fourth detection level, so that each of the slaves responds to the first polling message and sends a third node message to the host, and the third node message is used to represent the slave itself that sends the third node message; the first polling message is sent to the slaves of the downstream port of the target slave of the fourth detection level, respectively, including: sending a detection command to the slaves of the downstream port of the target slave of the fourth detection level in a polling manner; the fourth detection level is initially the second level; returning a non-repeated command from the first slave in the third detection level. The method comprises the following steps: repeatedly selecting a first slave as a target slave until all the first slaves in the third detection level are selected as target slaves; returning to the step of non-repeatedly selecting a first slave as a target slave from the first slaves in the third detection level with the next level of the third detection level as a new third detection level and the next level of the fourth detection level as a new fourth detection level, until the fourth detection level does not include the slave; determining the topology of the bus according to the received third node message; the host is specifically used to send a detection message to each of the slaves of the level to be detected, so that each of the slaves responds to the detection message, parses and obtains the detection level represented in the detection message, and if the detection level is the level of the slave and the slave does not receive a confirmation message, sends a fourth node message to the device that sends the detection message according to the backoff mechanism; in response to the first received fourth node message, sends a confirmation message to the slave that sends the fourth node message.

7. The host according to claim 6, characterized in that: The host is also used for: For each level of slaves in the multi-level slaves, if the number of the first slaves in each level is less than a first preset value, the target number is determined to be the first target number, the target number is the number of first slaves for which the switch unit is set to the blocking state, and the first target number is the quotient of the total number of the slaves and a second preset value; if the first target number is greater than a third preset value, it is determined to set the switch unit of the first slave whose rank value is less than the product of the first target number and the second preset value and is an integer multiple of the second preset value to the blocking state; if the first target number is not greater than the third preset value, it is determined not to set the switch unit of the first slave to the blocking state; if the first target number is not greater than the third preset value, it is determined not to set the switch unit of the first slave to the blocking state; If the number of slaves is not less than a first preset value, the target number is determined to be a second target number, the second target number being the quotient of the cascade number of the slaves and a fourth preset value; if the first target number is greater than a third preset value, it is determined to set the switch unit of the first slave whose rank value is less than the product of the second target number and the fourth preset value and is an integer multiple of the fourth preset value to a blocking state; if the first target number is not greater than the third preset value, it is determined not to set the switch unit of the first slave to a blocking state; a fourth switching message is sent to all first slaves connected to the host, so that each of the first slaves switches the switch unit to the blocking state in response to the fourth switching message.

Citation Information

Patent Citations

  • CAN bus automatic coding circuit and method

    CN106647393A