Multi-node serial port cascade networking method, device, equipment and medium
By automatically determining the roles and numbers of multiple node devices through serial port cascading, the flexibility and data coverage issues of multi-node communication in existing technologies are solved, realizing automatic networking and bidirectional data transmission of multi-node devices, and improving networking efficiency and data integrity.
Patent Information
- Application Number
- CN202511540437.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-10-27
- Publication Date
- 2026-01-13
AI Technical Summary
In existing technologies, single-machine serial port detection communication only supports one-to-one communication and cannot be extended to multi-node cascading. Furthermore, the fixed master-slave interface networking communication method has poor flexibility, requires manual configuration and resetting of DIP switches, and cannot achieve full-link data coverage and bidirectional transmission.
The network topology is built by serial port cascading. The host and slave devices are automatically identified by role detection frames. Numbering frames are sent level by level for recursive numbering. The number of slave devices is determined by quantity reporting frames. This enables data encapsulation and forwarding of intermediate slave devices and supports bidirectional data synchronization.
It enables automatic networking of multi-node devices without manual intervention or programming configuration, improving application flexibility and data coverage, adapting to different scenario requirements, and automatically updating the number when a slave device fails.
Smart Images

Figure CN121333907A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of communication technology, specifically to a network communication method, apparatus, device, and medium for multi-node serial port cascading. Background Technology
[0002] In the field of communications, standalone serial port probing communication only supports communication between one master device and one slave device, and cannot be extended to communication with multiple cascaded nodes. This communication method lacks intermediate nodes for data forwarding, thus failing to achieve full-link data coverage. Furthermore, in standalone serial port probing communication systems, data transmission is unidirectional; slave devices can only receive data and cannot upload data to the master device, meaning the master device cannot obtain data from the slave devices. Therefore, to overcome the shortcomings of standalone serial port probing communication technology, multi-node device networking communication technology has emerged with the development of communication technology.
[0003] Currently, multi-node network communication typically uses fixed master-slave interfaces. This requires pre-programming the roles of each node in the network, designating one node as the master and the rest as slaves. In a fixed master-slave interface system, the slave device numbers are written into the master device's memory via DIP switches. When one slave device fails and needs replacement, the DIP switches must be reset to reassign the slave device numbers and adjust the master device configuration. This fixed master-slave interface networking method is only suitable for scenarios where the number of nodes is fixed and there is no need for dynamic adjustments. It lacks flexibility, requires manual pre-setting of node roles and numbers, and necessitates renting a programming program for multi-node networking, resulting in time-consuming configuration. Summary of the Invention
[0004] In view of this, the present invention provides a networking communication method, apparatus, device and medium for multi-node serial port cascading, which realizes automatic networking of multiple node devices based on serial port cascading, and automatically determines the role and number of each node device in the network, without manual intervention and programming configuration, reducing device configuration time and improving application flexibility.
[0005] On one hand, embodiments of the present invention provide a networking communication method for multi-node serial port cascading, including:
[0006] Multiple node devices are connected in a serial port cascade manner to form a network topology; wherein, the node devices include a first In the network topology, the first serial port is used to receive instructions from the upper level and respond to the upper level, while the second serial port is used to send instructions to the lower level and receive responses from the lower level. Based on the transmission of role detection frames, the host and slave devices in the network topology are determined, so as to transmit the first string of... The node device that does not receive the role detection frame is determined as the master device, the node device that does not receive the response frame corresponding to the role detection frame is determined as the last-level slave device, and the node device that receives the role detection frame on the first serial port and the response frame on the second serial port is determined as the intermediate-level slave device. By sending numbered frames to the next level until reaching the last level slave device, the intermediate level slave devices and the aforementioned... The last-level slave devices are numbered recursively according to the physical connection order; each slave device sets its own number based on the received number frame, updates the data segment information representing the next level's number in the number frame, and sends the updated number frame to the next level.
[0007] In some embodiments, the networking communication method further includes: By sending quantity reporting frames to the previous level until the report is submitted to the host device, the host device determines the number of slave devices in the network topology. The last-level slave device determines the number of slave devices reported in the quantity reporting frame based on its own number. After receiving the quantity reporting frame through the second serial port, the intermediate-level node device updates the number of slave devices stored locally according to the number of slave devices reported in the quantity reporting frame, and forwards the quantity reporting frame to the previous level through the first serial port.
[0008] In some embodiments, the networking communication method further includes: When sending a data frame containing local data to the previous or next level, the intermediate slave device encapsulates the data contained in the data frame received from the previous level and its own local data into a new data frame and sends it to the next level, and sends its own local data and the local data of each slave device in the next level to the previous level.
[0009] In some embodiments, the intermediate slave device encapsulates the data contained in the data frame received from the previous level and its own local data into a new data frame and sends it to the next level, and sends its own local data and the local data of each slave device in the next level to the previous level, including: Based on the currently received data frame, extract the sending device number and timestamp corresponding to the currently received data frame; Based on the extracted sending device number, it traverses its own data queue to determine whether there is historical data in its own data queue that is from the same sending device as the currently received data frame; When it is determined that the historical data exists, it is determined whether the extracted timestamp is greater than the timestamp corresponding to the historical data; If so, delete the historical data, insert the data contained in the currently received data frame into the data queue, and mark the inserted data as data to be forwarded; When data needs to be forwarded, the data to be forwarded is retrieved and sent together with its own local data to the previous or next level.
[0010] In some embodiments, the intermediate slave device encapsulates the data contained in the data frame received from the previous stage and its own local data into a new data frame and sends it to the next stage, and sends its own local data and the local data of each slave device in the next stage to the previous stage, further comprising: After data forwarding is completed, the data to be forwarded in the data queue is marked as forwarded data, and the forwarded data is removed from the data queue.
[0011] In some embodiments, the intermediate slave device encapsulates the data contained in the data frame received from the previous stage and its own local data into a new data frame and sends it to the next stage, and sends its own local data and the local data of each slave device in the next stage to the previous stage, further comprising: If the determination result of whether there is historical data from the same sending device as the currently received data frame in its own data queue is no, the data contained in the currently received data frame is inserted into the data queue, and the inserted data is marked as data to be forwarded; and / or, If the determination result of whether the extracted timestamp is greater than the timestamp corresponding to the historical data is negative, the data contained in the currently received data frame is discarded, and the historical data is retained.
[0012] In some embodiments, when the determination result of whether there is historical data from the same transmitting device as the currently received data frame in its own data queue is negative, inserting the data contained in the currently received data frame into the data queue includes: If the determination result of whether there is historical data from the same sending device as the currently received data frame in its own data queue is no, if it is determined that the data queue is not full, the data contained in the currently received data frame is inserted into the data queue; if it is determined that the data queue is full, the data with the smallest timestamp in the data queue is deleted first, and then the data contained in the currently received data frame is inserted into the data queue.
[0013] In a second aspect, embodiments of the present invention provide a networking communication device, comprising: A link building module is used to build a network topology by connecting multiple node devices in a serial port cascading manner; wherein, the node device includes a first serial port and a second serial port, in the network topology, the first serial port is used to receive instructions from the upper level and respond to the upper level, and the second serial port is used to send instructions to the lower level and receive responses from the lower level. The role determination module is used to determine the host device and slave device in the network topology based on the transmission of the role detection frame, so as to determine the node device that does not receive the role detection frame on the first serial port as the host device, the node device that does not receive the response frame corresponding to the role detection frame as the last-level slave device, and the node device that receives the role detection frame on the first serial port and receives the response frame on the second serial port as the intermediate-level slave device. The slave device number allocation module is used to recursively number intermediate slave devices and the last slave device according to the physical connection order by sending number frames to the next level until the last slave device. Each slave device sets its own number based on the received number frame, updates the data segment information representing the number of the next level in the number frame, and sends the number frame with updated data segment information to the next level.
[0014] Thirdly, embodiments of the present invention provide a networking communication device, including a processor and a memory, wherein the memory is used to store programs, instructions or code, and the processor is used to execute the programs, instructions or code in the memory to complete the networking communication method as described in any of the foregoing.
[0015] Fourthly, embodiments of the present invention provide a computer-readable storage medium storing a computer program, which is loaded by a processor to execute the networking communication method as described in any of the foregoing claims.
[0016] In several embodiments provided by this invention, multiple node devices are networked using a serial port cascading method. By sending role detection frames from each node device, the serial port detection and response status of each node device is determined, thereby automatically determining the role of each node device based on its serial port detection and response status, eliminating the need for manual pre-setting. Furthermore, by sending numbering frames level by level from each node device, the slave devices are recursively numbered according to their physical connection order, thus eliminating the need for programming configuration of the slave device numbers. Therefore, the networking communication method provided by this invention can automatically determine the role and number of each node device in the network without manual intervention or programming configuration, reducing device configuration time and improving application flexibility. Attached Figure Description
[0017] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on the provided drawings without creative effort.
[0018] Figure 1 This is a flowchart illustrating the method for a multi-node serial port cascaded networking communication method provided according to some embodiments of the present invention.
[0019] Figure 2 This is a schematic diagram of the structure of a communication system used in a networking communication method provided according to some embodiments of the present invention.
[0020] Figure 3 This is a flowchart illustrating the method for a multi-node serial port cascaded networking communication method provided according to some embodiments of the present invention.
[0021] Figure 4 This is a schematic diagram illustrating the data forwarding process of an intermediate slave device in a networking communication method provided according to some embodiments of the present invention.
[0022] Figure 5 This is a schematic diagram illustrating the process of inserting data contained in a data frame into the data queue for intermediate-level slave devices.
[0023] Figure 6 This is a schematic diagram of the frame structure used in the communication networking method provided in some embodiments of the present invention.
[0024] Figure 7 This is a schematic diagram of a networking communication device provided according to some embodiments of the present invention.
[0025] Figure 8 This is a schematic diagram of the structure of a networking communication device provided according to some embodiments of the present invention. Detailed Implementation
[0026] The technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings of the embodiments of the present invention. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments.
[0027] Please see Figure 1 The diagram shown is a flowchart illustrating a multi-node serial port cascading network communication method provided according to some embodiments of the present invention. In some embodiments, the network communication method provided by the present invention can be applied to, but is not limited to, [various applications]. Figure 2The multi-node cascaded communication system 200 shown is a network communication system formed by connecting multiple node devices in series step by step based on serial port cascading. It includes S2, S4 and S6, and the description of each step is as follows.
[0028] S2: Construct a network topology by cascading multiple node devices via serial ports.
[0029] The network topology consists of three or more node devices, connected hierarchically via serial ports to form physical links that define the network topology. There are no fixed master or slave devices in the network; any node device can act as either a master or a slave. Each node device includes a first serial port and a second serial port. In the network topology, the first serial port receives commands from the higher-level node and responds to the higher-level node, while the second serial port sends commands to the lower-level node and receives responses from the lower-level node. Here, "higher-level" refers to the node device at the next higher level, or the node preceding the command, which is physically adjacent to and upstream of the command receiving node. Similarly, "lower-level" refers to the node device at the next lower level, or the node following the command, which is physically adjacent to and downstream of the command receiving node.
[0030] Figure 2 The communication system 200 shown is a system composed of multiple node devices connected in a serial port cascade network. In this embodiment, the communication system 200 is composed of four node devices. In other embodiments, the number of node devices in the communication system 200 is not limited to four. The four node devices in the communication system 200 are the first node device 202, the second node device 204, the third node device 206, and the fourth node device 208. Although in Figure 2In this configuration, the first node device 202 has no superior, but its first serial port 2021 can be used to receive instructions sent by its superior. The second serial port 2022 of the first node device is used to send instructions to the first serial port 2041 of the second node device and to receive response frames returned from the first serial port 2041 of the second node device. After receiving the instructions sent by the first node device 202, the second node device 204 sends a response back to the first node device 202 through its first serial port 2041, and sends instructions to the first serial port 2061 of the third node device 206 through its second serial port 2042. After receiving the instructions sent by the second node device 204, the third node device 206 sends a response back to the second node device 204 through its first serial port 2061, and sends instructions to the first serial port 2081 of the fourth node device 208 through its second serial port 2062. After receiving the instruction sent by the third node device 206, the fourth node device 208 sends a response back to the third node device 206 via its first serial port 2081. If the fourth node device 208 has subordinates, its second serial port 2082 can continue to send instructions to its subordinates and receive responses from them.
[0031] The networking communication method provided in this embodiment of the invention does not have a fixed master-slave role when multiple networked node devices are networked. An upper level (pre-level) and / or a lower level (rear level) can be added based on the needs, thereby automatically changing the master-slave role of each node device.
[0032] S4: Based on the transmission of role detection frames, determine the host and slave devices in the network topology.
[0033] During network communication in a communication system, the network communication device using the network communication method provided in this embodiment of the invention triggers each node device to send a role detection frame. Based on the reception of the role detection frame and the return response frame via the first and second serial ports of each node device, the device determines the master and slave devices in the network topology. Specifically, after triggering each node device to send a role detection frame via its corresponding second serial port, the network communication device determines whether each node device receives the role detection frame via its first serial port and whether it receives the response frame via its second serial port. Node devices that do not receive a role detection frame via their first serial port are identified as master devices; node devices that do not receive the response frame corresponding to the role detection frame are identified as last-level slave devices; and node devices that receive a role detection frame via their first serial port and a response frame via their second serial port are identified as intermediate-level slave devices. This automatically determines the role of each node device in the current network communication process.
[0034] by Figure 2Taking the communication system 200 as an example, after triggering each node device to send a role detection frame, if the first serial port 2021 of the first node device does not receive a role detection frame sent by the superior, then when the time for which the first interface has not received a role detection frame reaches a first preset time, the node device corresponding to the first interface that has not received a role detection frame can be determined as the master node device. For example, in the communication system 200, the first node device 202 can be determined as the master device, and the other node devices as slave devices.
[0035] Furthermore, in the network topology, if it is determined that a certain second interface never receives a response frame from the lower level, then after a second preset time, the node device corresponding to that second interface is determined to be the last-level slave device. For example, if the second serial port 2082 of the fourth node device in communication system 200 never receives a response frame, then the fourth node device 208 can be determined to be the last-level slave device in the multi-level slave device system. If the first serial ports of the second node device 204 and the third node device 206 can receive role detection frames sent by the upper level, and their second serial ports can also receive response frames returned by the lower level, then the second node device 204 and the third node device 206 are determined to be intermediate-level node devices.
[0036] In the networking communication method provided in the embodiments of the present invention, the roles of the host device, the last-level slave device, and the intermediate-level slave device can be automatically determined based on the role detection frames sent by each node device and the interface detection and response of each node device, without the need for manual preset or programming configuration.
[0037] S6: By sending numbered frames to the next level, up to the last level slave device, to coordinate the intermediate level slave devices and... The last-level slave devices are numbered sequentially according to their physical connection order.
[0038] Each slave device sets its own number based on the received number frame, updates the data segment information representing the number of the next level in the number frame, and sends the number frame with the updated data segment information to the next level, so that the next level can determine its own number based on the data segment information in the received number frame.
[0039] The network communication equipment automatically numbers each slave device by triggering each node device to send a number frame to the next level, up to the last slave device. The slave devices include intermediate-level slave devices and the last-level slave device; the number of intermediate-level slave devices can be one or more.
[0040] The physical connection order of slave devices refers to the connection order of each slave device in the physical link, i.e., the front-to-back relationship. Recursive numbering means that the code of the next-level slave device is increased by a preset value based on the code of the previous-level slave device according to a preset numbering increment strategy. In some embodiments, the code of the next-level slave device may, but is not limited to, be one higher than the code of the previous-level slave device. For example, in communication system 200, the first node device 202, acting as the master device, sends a number frame containing slave device number information to the second node device 204 through its second serial port. After receiving the number frame, the second node device 204 determines its own code as 1 based on the data segment information in the received number frame, and sends a number frame with updated data segment information to the third node device 206 through its second serial port. The third node device 206 determines its own code as 2 based on the received number frame, and sends a number frame with further updated data segment information to the fourth node device 208 through its second serial port. The fourth node device 208 determines its own code as 3 based on the received number frame and stops sending number frames to lower levels, thus completing the numbering of each slave device. In this embodiment, the slave devices are numbered 1, 2, and 3 from the top to the bottom.
[0041] Based on the physical connection order of each slave device, the slave device number is determined using a recursive slave device numbering algorithm. The master device initiates the initial numbering, the intermediate slave devices recursively number the slave devices, and the last slave device terminates the numbering frame distribution. This achieves automatic allocation of numbers for multiple slave devices, thus adapting to different application scenarios. Furthermore, the slave device encoding allocation is time-efficient, the network communication efficiency is high, and the slave device numbers can be automatically updated after a slave device malfunctions, without the need for programming and re-burning for configuration.
[0042] The networking communication method provided in this invention determines the serial port detection and response status of each node device by sending role detection frames, thereby automatically determining the role of each node device based on its serial port detection and response status, eliminating the need for manual pre-setting. Furthermore, it assigns a numbering frame to each slave device in a recursive manner according to the physical connection order of each slave device, eliminating the need for programming configuration of slave device numbers. Therefore, the networking communication method provided in this invention can automatically determine the role and number of each node device in the network without manual intervention or programming configuration, reducing device configuration time and improving application flexibility. In addition, the networking communication method provided in this invention has relatively low requirements for determining master and slave devices among multiple node devices and assigning slave device numbers. Compared with fixed master and slave device networking communication schemes, it improves efficiency and eliminates the need for reconfiguration when replacing slave devices, offering plug-and-play functionality and reducing maintenance costs.
[0043] Please see Figure 3As shown, in some embodiments, the networking communication method provided by the present invention includes S8 in addition to S2 to S6, which is described below.
[0044] S8: By sending quantity reporting frames to the previous level until the report is sent to the host device, the host device determines the number of slave devices in the network topology. Among them, the last-level slave device determines the number of slave devices reported in the quantity reporting frame based on its own number. After receiving the quantity reporting frame through the second serial port, the intermediate-level node device updates the number of slave devices stored locally according to the number of slave devices reported in the quantity reporting frame, and forwards the quantity reporting frame to the previous level through the first serial port.
[0045] The network communication equipment triggers each node device to send quantity reporting frames sequentially from the downstream to the upstream. The last-level node device is the first to send a quantity reporting frame to the upstream, and the next level after the host device is the last to report a quantity reporting frame. Each level of node device reports the quantity reporting frames directly to the host device from the downstream to the upstream, so as to provide the host device with an accurate network scale, avoid the host device to traverse and query, and the quantity reporting accuracy of the slave devices is relatively high.
[0046] The networking communication method provided in this invention employs a reverse reporting logic for the number of slave devices. Starting with the last-level slave device as the reporting starting point, intermediate-level slave devices forward quantity reporting frames to the next higher level sequentially. This ensures that each slave device forwards quantity information sequentially from the next higher level, allowing the master device to accurately obtain the number of slave devices and determine data integrity during networking communication based on the number of slave devices. Furthermore, after receiving the quantity reporting frame from the next higher level, each slave device updates its locally stored slave device count based on the reported number in the received frame and forwards the frame to the previous level. This ensures that each level accurately obtains the number of slave devices currently in the network.
[0047] Taking communication system 200 as an example, the fourth node device 208 sends a quantity reporting frame containing the number of slave devices to the third node device through its first serial port. Upon receiving the quantity reporting frame, the third node device 206 updates its local slave device count based on the information in the digital segment representing the number of slave devices in the frame, and forwards the received quantity reporting frame to the second node device 204 through its own first serial port. Upon receiving the data reporting frame, the second node device 204 also updates its local slave device count based on the reported slave device count information in the quantity reporting frame, and then forwards the received quantity reporting frame to the first node device 202 through its own first serial port, thus forwarding it to the host device. Upon receiving the quantity reporting frame, the host device updates its local slave device count based on the slave device count information in the frame, thus completing the slave device count. The host device can then use this count to determine the completeness of the communication data, thereby improving the integrity of the link data coverage.
[0048] Please continue reading. Figure 3 As shown, in some embodiments, the networking communication method provided by the present invention may include S8 in addition to S2 to S6, and may further include S10. S10 may be executed after S8, but is not limited to this. Its description is as follows.
[0049] S10: When sending a data frame containing local data to the previous or next level, the intermediate slave device encapsulates the data contained in the data frame received from the previous level and its own local data into a new data frame and sends it to the next level, and sends its own local data and the local data of each slave device in the next level to the previous level.
[0050] The networking device triggers each node device to send data frames to the previous or next level. In the networking communication method provided in this embodiment, intermediate slave devices can forward received data to both their previous and next levels. Simultaneously, while forwarding data, they can also send their own data to the previous or next level, ensuring that each node device can obtain the number of all nodes. Therefore, based on the networking communication method provided in this embodiment, a bidirectional full data synchronization link can be achieved, constructing a bidirectional data stream. This allows any node device in the network to obtain all data from all node devices, effectively improving data coverage during networking communication—almost full link coverage, i.e., 100% quantity coverage. Based on the networking communication method provided in this embodiment, the collaborative capability of multiple node devices in the network can be improved by 100%. Even if a node device experiences a brief failure, it can recover and replenish missing data through a queue, improving link fault tolerance.
[0051] Taking the communication system 200 as an example, the first node device 202, acting as the host device, first sends a data frame containing its own local data to the second node device 204. Each node device's data frame also includes its own identification information, allowing the preceding or succeeding node device to know the source of the received data. After receiving the data frame, the second node device 204 compares the data in the data frame against a queue to determine whether to retain the received data. It then encapsulates the data received from the first node device 202 and its own data together and forwards them to the third node device 206. Simultaneously, it also sends a data frame containing its own data and data sent from its successor node devices back to the first node device 202 via its first serial port. Similarly, the third node device 206 sends its own data and data from the received data frame to the fourth node device 208, and simultaneously sends its own data and data received from the fourth node device 208 to the second node device 204. Each node device compares the data in the received data frames through a queue and retains it. Ultimately, the data queues of all node devices contain all the data from the four node devices, achieving full synchronization with a data coverage rate of up to 100%. Please see Figure 4 As shown, it is a schematic diagram of the data forwarding process of intermediate-level slave devices in a networking communication method provided according to some embodiments of the present invention. In some embodiments, the intermediate-level slave devices in SO1O encapsulate the data contained in the data frame received from the previous level and their own local data into a new data frame and send it to the next level, and send their own local data and the local data of each slave device in the next level to the previous level. That is, the steps of intermediate-level slave devices forwarding data include S101, S103, S105, S107 and S109. Among them, S101 to S109 can be executed by intermediate-level node devices, and the description of each step is as follows.
[0052] S101: Based on the currently received data frame, extract the sending device number and timestamp corresponding to the currently received data frame.
[0053] S103: Based on the extracted sending device number, traverse its own data queue to determine whether there is historical data in its own data queue that is from the same sending device as the currently received data frame.
[0054] S105: If historical data is confirmed to exist, determine whether the extracted timestamp is greater than the timestamp corresponding to the historical data. If so, proceed to S107.
[0055] S107: Delete historical data, insert the data contained in the currently received data frame into the data queue, and mark the inserted data as data to be forwarded.
[0056] S109: When data needs to be forwarded, the data to be forwarded is retrieved and sent together with its own local data to the previous or next level.
[0057] Steps S101 to S109 can be executed by intermediate-level slave devices. After receiving a data frame, the intermediate-level slave device first extracts the "sender ID" and "timestamp T_new" from the data frame. Then, it iterates through its own data queue (data_queue) to check if there is historical data with the same sender ID (whose corresponding timestamp is T_old). Here, the sender ID is the number of the sending device corresponding to the received data frame. If the intermediate-level slave device determines that there is historical data with the same sender ID as the currently received data frame in its own data queue, then: it compares the currently extracted time T_new with the historical timestamp T_old corresponding to the historical data with the same sender ID. If T_new > T_old, the intermediate-level slave device deletes the historical data from its own data queue and inserts the data from the currently received data frame as new data into its own data queue, marking the inserted new data as "to be forwarded." If T_new ≤ T_old, the intermediate-level slave device discards the new data contained in the received data frame, retains the historical data, and only forwards the historical data in its own queue to the previous or next level. If the intermediate slave device determines that there is no historical data with the same sender ID as the currently received data frame in its data queue, then: the intermediate slave device will directly insert the data contained in the received data frame as new data into its own data queue, and will also mark the inserted new data as "to be forwarded". Marking the inserted new data as "to be forwarded" makes it easier to retrieve it from the queue for forwarding later.
[0058] Based on the networking communication method provided in this embodiment of the invention, the intermediate slave device uses a data queue and timestamp comparison algorithm to determine that only the latest data is forwarded by using queue caching and timestamp priority judgment. The old data discard rate can be as high as 100%, which effectively improves the real-time performance of data. The timestamp comparison mechanism of the intermediate slave device reduces the forwarding rate of old data. Compared with the queueless scheme, the data accuracy is improved. The checksum and retransmission mechanism makes the data error rate low.
[0059] Please continue reading. Figure 4 As shown, the intermediate slave device forwarding data also includes S110: after the data forwarding is completed, the data to be forwarded in the data queue is marked as forwarded data, and the forwarded data is removed from the data queue.
[0060] After forwarding data to the previous or next level, intermediate slave devices mark the forwarded data in their own data queue as "forwarded" to facilitate removing it from the data queue, thereby avoiding unnecessary data occupying the storage space of their own data queue.
[0061] In some embodiments, when the determination result of SO1O3 that there is no historical data of the same sending device as the currently received data frame in its own data queue is no, the step of the intermediate slave device forwarding data further includes: inserting the data contained in the currently received data frame into the data queue and marking the inserted data as data to be forwarded.
[0062] When an intermediate slave device determines that there is no historical data with the same sender ID as the currently received data frame in its own data queue, it does not need to perform a timestamp comparison algorithm. Instead, it directly inserts the data in the received data frame into its own queue as data to be forwarded. This ensures that all data forwarded is new data, thus improving the old data discard rate.
[0063] In some embodiments, the step of forwarding data by the intermediate slave device further includes: if the determination result of whether the extracted timestamp is greater than the timestamp corresponding to the historical data is negative, discarding the data contained in the currently received data frame and retaining the historical data. When the intermediate slave device determines that the currently extracted timestamp is less than the timestamp corresponding to the historical data, it directly discards the data contained in the currently received data frame and chooses to retain the historical data, thereby further improving the old data discard rate and improving network communication efficiency.
[0064] Please see Figure 5 As shown, it is a flowchart illustrating the process of inserting data contained in the currently received data frame into the data queue in a network communication method provided according to some embodiments of the present invention. In some embodiments, the insertion of data contained in the currently received data frame into the data queue in S107 includes S1071, S1073 and S1075, and the description of each step is as follows.
[0065] S1071: If the determination result for whether there is historical data from the same sending device as the currently received data frame in its own data queue is negative, determine whether the data queue is full. If yes, execute S1073; otherwise, execute S1075.
[0066] S1073: Insert the data contained in the currently received data frame into the data queue.
[0067] S1075: Delete the data with the smallest timestamp in the data queue, and then insert the data contained in the currently received data frame into the data queue.
[0068] When an intermediate slave device inserts data from a received data frame into its own data queue, it first determines whether its own data queue is full. It only inserts new data if its own data queue is not full; otherwise, it deletes the historical data with the smallest timestamp before inserting it to ensure the data update rate in the data queue.
[0069] In some embodiments, the networking communication method provided by the present invention is applied to Figure 2 The communication system shown mainly includes the following steps: master / slave determination, slave number allocation, reverse reporting of slave quantity, comparison of intermediate slave device data queues, and full synchronization. The following will describe the networking communication method provided by this embodiment of the invention through these steps.
[0070] Before determining the master / slave relationship, each node device is connected step-by-step through its first and second serial ports to form a physical link with a chain-like network topology. In this physical link, the connection order of each node device is as follows: the second serial port of the first node device 202 is connected to the first serial port of the second node device 204; the second serial port of the second node device 204 is connected to the first serial port of the third node device 206; the second serial port of the third node device 206 is connected to the first serial port of the fourth node device 208; the first serial port of the first node device 202 is not connected to the preceding node device; and the second serial port of the fourth node device 208 is not connected to the following node device.
[0071] After establishing a communication system 200 by connecting multiple node devices in a cascaded physical link, the system is first powered on and initialized so that the role scalar of all node devices in the system is equal to 0. Then, each node device is triggered to send a role detection frame 0x01 sequentially from the previous stage to the next stage via its own second serial port. Each second serial port can continuously send a preset number of role detection frames 0x01 at a certain transmission frequency to reduce errors in master-slave device role determination caused by false triggers or unsuccessful transmissions. Specifically, each second serial port can continuously send three role detection frames 0x01 at a transmission frequency of 100ms / time. After each second serial port sends the role detection frame 0x01, if the first node device 202 neither responds to the superior nor receives the role detection frame 0x01 sent by the superior, then after a first preset time (e.g., 500ms), the role scalar value of the first node device 202 is set to 1, indicating that the first node device 202 is the master device. If the fourth node device 208 does not receive a response from the subordinate, then after a second preset time (e.g., 500ms), the role scalar value of the fourth node device 208 is set to 3, indicating that the fourth node device 208 is the last-level slave device. If the first serial ports of the second node device 204 and the third node device 206 can receive the role detection frame 0x01 sent by the superior and the response returned by the subordinate, then after a third preset time (e.g., 500ms), the role scalar value of the second node device 202 and the third node device 206 is set to 2, indicating that the second node device 204 and the third node device 206 are both intermediate-level slave devices. That is, in the networking communication method provided in the embodiments of the present invention, different role scalars are used to represent the host device, intermediate slave device and the last slave device, so as to facilitate the subsequent slave device numbering and full synchronization.
[0072] After automatically determining the role of each node device, the first node device 202, acting as the master device, sends a number frame 0x03 containing data 0x01 to the second node device 204. The second node device 202, based on the received number frame, sets its own ID to 1, updates the data in the number frame to data 0x02 representing the next-level node device number, and sends the updated number frame 0x03 (data 0x02) to the third node device 206. The third node device 206, based on the received number frame, sets its own ID to 2, updates the data in the number frame to data 0x03 representing the next-level node device number, and sends the updated number frame 0x03 (data 0x03) to the fourth node device 208. The fourth node device 208, based on the received number frame, sets its own ID to 3. Furthermore, the master device sets its own ID to 0. This hierarchical automatic numbering of slave devices through the sequential sending of number frames is simple to implement and flexible in application.
[0073] The steps for reverse reporting of slave device counts include: based on automatic role determination and slave device number, the last-level slave device can determine the number of slave devices based on its own number. For example, the fourth node device 208, as the last-level slave device, determines the number of slave devices (slave_count) to be 3 based on its own number 3, and sends a count reporting frame 0x04 (data 0x03) containing the number of slave devices it has determined to be 3 to the third node device 206 through its first serial port; after receiving the count reporting frame 0x04, the third node device 206 updates its local slave count value (slave_count) to 3 based on the data in the count reporting frame 0x04, and forwards the received data reporting frame 0x04 to the second node device 20; after receiving the count reporting frame, the second node device 204 also updates its own slave count value based on this, and forwards the count reporting frame 0x0 to the first node device 202, so that each node device can obtain the number of slave devices.
[0074] If each node device is configured with local data, such as A for the first node device 202, B for the second node device 204, C for the third node device 206, and D for the fourth node device 208, then the networking communication method provided in this embodiment of the invention includes: the first node device 202 periodically sending a data frame 0x05 (T=t1) containing a timestamp T and its own data A to the second node device 204; after receiving the data, the second node device 204 inserts {0, A, t1} into its data queue, and encapsulates its own data B and the received data into a new data frame 0x05 (T=t2, data B+A) and sends it to the third node device 206, while simultaneously sending data B and subsequently received data C and data D to the first node device 202; after receiving the data frame 0x05, the third node device 206 inserts {1, B+A, t2} into its own queue, and encapsulates it with its own data C into a new data frame 0x05. After (T=t3, data C+B+A), it is sent to the fourth node device 208, and at the same time, it sends its own data C and the data D of the fourth node device 208 to the second node device 204; the fourth node device 208 periodically sends data frame 0x05 (T=t4, data D) to the third node device 206. In this way, all four node devices can obtain data A, B, C, and D, realizing that all node devices can store the data of all node devices, and there is no old data residue, and the data integrity can reach 100%.
[0075] The multi-node serial port cascading-based networking communication method provided in this embodiment of the invention automatically determines the master / slave status based on the role detection frame sent by the second serial port and the response received by the first serial port. It distinguishes between the master device and the last-level slave device through a logic of no upper-level / no lower-level hierarchy, eliminating the need for manual role presets. The master device initiates an initial numbering frame, and the slave devices recursively set their own IDs, achieving automatic allocation of slave device numbers 1 to 3, adapting to fixed multi-node cascading scenarios. Using the last-level slave device as the starting point for reporting the number of slave devices, it reports the number of slave devices upwards level by level, providing the master device with an accurate network scale and avoiding host traversal queries. Intermediate-level slave devices use a data queue and timestamp comparison algorithm to implement data queue caching and timestamp priority judgment, ensuring that only the latest data is forwarded, with an old data discard rate of up to 100%. A bidirectional full-data synchronization physical link is built through serial port cascading, enabling bidirectional data flow. Any node setting can obtain data from all node devices, achieving 100% link data coverage.
[0076] The networking communication method provided in this embodiment of the invention can achieve at least the following effects: 1. Improved networking efficiency: The time for multi-node master-slave determination and number allocation is less than 500ms. Compared with the fixed master-slave networking communication method, the networking efficiency is improved. Moreover, no reconfiguration is required when replacing slave devices. It is plug-and-play, reduces maintenance costs, and is standardized and modular.
[0077] 2. High data real-time performance: The timestamp comparison mechanism of intermediate slave devices reduces the forwarding rate of old data. Compared with networking communication methods without data queue management, the data accuracy is improved, and the checksum and retransmission mechanism makes the data error rate lower.
[0078] 3. Complete and comprehensive data: Any node device can obtain the full data of all node devices, with 100% data coverage. The collaboration capability between multiple node devices is strong. Even if a node device in the middle experiences a brief failure, the missing data can be supplemented through the queue after recovery, thus improving the fault tolerance of the link.
[0079] 4. Strong scenario adaptability: It can be directly applied to scenarios such as small industrial data acquisition (e.g., 4 sensor nodes) and laboratory equipment collaboration (e.g., data aggregation of 4 test boards). Only the local data acquisition logic needs to be adjusted, without modifying the core communication mechanism, thus reducing the adaptation cost.
[0080] Experimental results show that, with a baud rate of 460800bps, the four nodes in the communication system 200 operated continuously for 24 hours, with the following results: the success rate of master-slave device identification reached 100% (no role misjudgment); the accuracy rate of slave number reporting reached 100% (the master always obtained slave_count=3); the full data acquisition rate of any node reached 100%; and the average data transmission latency was less than or equal to 25ms (meeting the requirements of real-time communication).
[0081] The networking communication method provided in this embodiment of the invention requires sending or receiving various types of data frames. The frame structure of each type of data frame can be referred to... Figure 6 As shown. In some embodiments, the frame structure of various types of data uniformly adopts the format of "frame header (2 bytes: 0XEEB6) + type (1 byte) + data length (1 byte) + data segment (N bytes) + checksum (1 byte) + frame trailer (2 bytes: 0X0D0A)", and the functions of each frame type are as follows [frame type + function description + data length + data segment content]: 0x01 + Detection command frame + 0 + None [For character detection only]; 0x02 + Probe Response Frame + 0 + None [Only used for responding character probe frames]; 0x03 + number allocation frame + 1 + slave number; 0x04 + number of slave devices reported in frames + 1 + total number of slave devices; 0x05 + data synchronization frame + N + data [sender ID + data + timestamp] (assuming length is N); 0x06 + verification failure frame + 1 + error frame type; 0x07 + Length mismatch frame + 0 + None [Used only to detect whether the length of the frame data segment is the same as the length of the frame data]; 0x09 + Command mismatch + 0 + None [Used only to detect whether the corresponding frame type has been received]; Checksum: Each byte is XORed sequentially to obtain a 1-byte checksum. Usually, only the data part is checked (excluding the frame header and frame tail).
[0082] Please see Figure 7 The diagram shows a network communication device 700 provided according to some embodiments of the present invention. The network communication device 700 includes a link establishment module 702, a role determination module 704, and a slave device number allocation module 706. The link establishment module 702 is used to build a network topology structure by connecting multiple node devices in a serial port cascade manner. Each node device includes a first serial port and a second serial port. In the network topology structure, the first serial port is used to receive instructions from the upper level and respond to the upper level, while the second serial port is used to send instructions to the lower level and receive responses from the lower level. The role determination module 704 is used to determine the host device and slave device in the network topology structure based on the transmission of role detection frames. Specifically, the role determination module 704 determines the host device and slave device in the network topology structure based on the transmission of role detection frames by: determining a node device that has not received a role detection frame on its first serial port as a host device; determining a node device that has not received a response frame corresponding to the role detection frame as the last-level slave device; and determining a node device that has received a role detection frame on its first serial port and a response frame on its second serial port as an intermediate-level slave device. The slave device number allocation module 706 is used to recursively number intermediate and final slave devices according to their physical connection order by sending number frames to the next level until the last level slave device. Each slave device sets its own number based on the received number frame, updates the data segment information representing the next level's number in the number frame, and sends the updated number frame to the next level.
[0083] The networking communication device 700 provided in this embodiment of the invention and the networking communication method provided in this embodiment of the invention can achieve essentially the same technical effects, and will not be described in detail here.
[0084] Please continue reading. Figure 7As shown, in some embodiments, the network communication device 700 further includes a quantity reporting module 708. The quantity reporting module 707 is used to send quantity reporting frames to the previous level until the data is reported to the host device, so that the host device can determine the number of slave devices in the network topology. That is, the data reporting module 708 is used to execute S8.
[0085] Please continue reading. Figure 7 As shown, in some embodiments, the networking communication device 700 further includes a data transmission module 7010, which is used to perform S10.
[0086] Please see Figure 8 The diagram shows a structural schematic of a network communication device 800 provided according to some embodiments of the present invention. The network communication device 800 provided in the embodiments of the present invention includes a processor 802 and a memory 804. The memory 804 is used to store programs, instructions, or code, and the processor is used to execute the programs, instructions, or code in the memory to complete the network communication method described in the foregoing embodiments. The memory 804 may be random access memory (RAM), flash memory, read-only memory (ROM), EPROM, non-volatile read-only memory (Electronic Programmable ROM), registers, hard disk, removable disk, etc.
[0087] The networking communication device 800 provided in this embodiment of the invention and the networking communication method provided in this embodiment of the invention can achieve essentially the same technical effects, and will not be described in detail here.
[0088] In the above embodiments, implementation can be achieved, in whole or in part, through software, hardware, firmware, or any combination thereof. When implemented in software, it can be implemented, in whole or in part, as a computer program product. A computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, all or part of the flow or function according to the embodiments of the present invention is generated. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, computer instructions can be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via wired (e.g., coaxial cable, fiber optic, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that integrates one or more available media. The available medium can be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape) or a semiconductor medium (e.g., solid-state disk (SSD)).
[0089] This invention also provides a readable storage medium for storing the networking communication method provided in the above embodiments. Examples include random access memory (RAM), flash memory, read-only memory (ROM), EPROM, non-volatile read-only memory (EPROM), registers, hard disks, removable disks, or any other form of storage medium in the art.
[0090] It is understood that the term "connection" in the embodiments of the present invention can be interpreted as "electrical connection," "communication connection," etc., if the connected circuits, units, etc. can transmit electrical signals or data to each other.
[0091] It is understood that the specific examples in this document are only intended to help those skilled in the art better understand the embodiments of the present invention, and are not intended to limit the scope of the present invention.
[0092] It is understood that in the various embodiments of the present invention, the sequence number of each process does not imply the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present invention.
[0093] It is understood that the various embodiments described in this invention can be implemented individually or in combination, and the embodiments of this invention are not limited in this respect.
[0094] Unless otherwise stated, all technical and scientific terms used in the embodiments of this invention have the same meaning as commonly understood by one of ordinary skill in the art. The terminology used in this invention is for the purpose of describing particular embodiments only and is not intended to limit the scope of the invention. The term "and / or" as used in this invention includes any and all combinations of one or more of the associated listed items. The singular forms "a," "the," and "the" as used in the embodiments of this invention and the appended claims are also intended to include the plural forms unless the context clearly indicates otherwise.
[0095] Those skilled in the art will recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementations should not be considered beyond the scope of this invention.
[0096] The above are merely specific embodiments of the present invention, but the scope of protection of the present invention is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the technical scope disclosed in the present invention should be included within the scope of protection of the present invention. Therefore, the scope of protection of the present invention should be determined by the scope of the claims.
Claims
1. A network communication method for multi-node serial port cascading, characterized in that, include: Multiple node devices are connected in a serial port cascade manner to form a network topology; wherein, the node devices include a first In the network topology, the first serial port is used to receive instructions from the upper level and respond to the upper level, while the second serial port is used to send instructions to the lower level and receive responses from the lower level. Based on the transmission of role detection frames, the host and slave devices in the network topology are determined, so as to transmit the first string of... The node device that does not receive the role detection frame is determined as the master device, the node device that does not receive the response frame corresponding to the role detection frame is determined as the last-level slave device, and the node device that receives the role detection frame on the first serial port and the response frame on the second serial port is determined as the intermediate-level slave device. By sending numbered frames to the next level, until reaching the last level slave device, the intermediate level slave devices and the aforementioned... The last-level slave devices are numbered recursively according to the physical connection order; each slave device sets its own number based on the received number frame, updates the data segment information representing the next level's number in the number frame, and sends the updated number frame to the next level.
2. The networking communication method according to claim 1, characterized in that, Also includes: By sending quantity reporting frames to the previous level until the report is submitted to the host device, the host device determines the number of slave devices in the network topology. The last-level slave device determines the number of slave devices reported in the quantity reporting frame based on its own number. After receiving the quantity reporting frame through the second serial port, the intermediate-level node device updates the number of slave devices stored locally according to the number of slave devices reported in the quantity reporting frame, and forwards the quantity reporting frame to the previous level through the first serial port.
3. The networking communication method according to claim 1, characterized in that, Also includes: When sending a data frame containing local data to the previous or next level, the intermediate slave device encapsulates the data contained in the data frame received from the previous level and its own local data into a new data frame and sends it to the next level, and sends its own local data and the local data of each slave device in the next level to the previous level.
4. The networking communication method according to claim 3, characterized in that, The intermediate-level slave device encapsulates the data contained in the data frame received from the previous level and its own local data into a new data frame and sends it to the next level, and sends its own local data and the local data of each slave device in the next level to the previous level, including: Based on the currently received data frame, extract the sending device number and timestamp corresponding to the currently received data frame; Based on the extracted sending device number, it traverses its own data queue to determine whether there is historical data in its own data queue that is from the same sending device as the currently received data frame; When it is determined that the historical data exists, it is determined whether the extracted timestamp is greater than the timestamp corresponding to the historical data; If so, delete the historical data, insert the data contained in the currently received data frame into the data queue, and mark the inserted data as data to be forwarded; When data needs to be forwarded, the data to be forwarded is retrieved and sent together with its own local data to the previous or next level.
5. The networking communication method according to claim 4, characterized in that, The intermediate-level slave device encapsulates the data contained in the data frame received from the previous level and its own local data into a new data frame and sends it to the next level, and also sends its own local data and the local data of each slave device in the next level to the previous level, further including: After data forwarding is completed, the data to be forwarded in the data queue is marked as forwarded data, and the forwarded data is removed from the data queue.
6. The networking communication method according to claim 4, characterized in that, The intermediate-level slave device encapsulates the data contained in the data frame received from the previous level and its own local data into a new data frame and sends it to the next level, and also sends its own local data and the local data of each slave device in the next level to the previous level, further including: If the determination result of whether there is historical data from the same sending device as the currently received data frame in its own data queue is no, the data contained in the currently received data frame is inserted into the data queue, and the inserted data is marked as data to be forwarded; and / or, If the determination result of whether the extracted timestamp is greater than the timestamp corresponding to the historical data is negative, the data contained in the currently received data frame is discarded, and the historical data is retained.
7. The networking communication method according to claim 6, characterized in that, When the determination result of whether there is historical data from the same sending device as the currently received data frame in its own data queue is no, inserting the data contained in the currently received data frame into the data queue includes: If the determination result of whether there is historical data from the same sending device as the currently received data frame in its own data queue is no, if it is determined that the data queue is not full, the data contained in the currently received data frame is inserted into the data queue; if it is determined that the data queue is full, the data with the smallest timestamp in the data queue is deleted first, and then the data contained in the currently received data frame is inserted into the data queue.
8. A networking communication device, characterized in that, include: A link building module is used to build a network topology by connecting multiple node devices in a serial port cascading manner; wherein, the node device includes a first serial port and a second serial port, in the network topology, the first serial port is used to receive instructions from the upper level and respond to the upper level, and the second serial port is used to send instructions to the lower level and receive responses from the lower level. The role determination module is used to determine the host device and slave device in the network topology based on the transmission of the role detection frame, so as to determine the node device that does not receive the role detection frame on the first serial port as the host device, the node device that does not receive the response frame corresponding to the role detection frame as the last-level slave device, and the node device that receives the role detection frame on the first serial port and receives the response frame on the second serial port as the intermediate-level slave device. The slave device number allocation module is used to recursively number intermediate slave devices and the last slave device according to the physical connection order by sending number frames to the next level until the last slave device. Each slave device sets its own number based on the received number frame, updates the data segment information representing the number of the next level in the number frame, and sends the number frame with updated data segment information to the next level.
9. A networking communication device, characterized in that, It includes a processor and a memory, the memory being used to store programs, instructions, or code, and the processor being used to execute the programs, instructions, or code in the memory to complete the networking communication method as described in any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that, The device contains a computer program that is loaded by a processor to execute the networking communication method as described in any one of claims 1 to 7.