A plug-and-play network access method and system for an intelligent gateway based on RS485 bus

By combining Nonce codes and N-frame collision avoidance algorithms, the problems of complex address configuration and long initialization time before device access in traditional RS485 bus systems are solved, realizing plug-and-play functionality for devices and improving system compatibility and scalability.

CN120710816BActive Publication Date: 2026-01-06GUANGZHOU DONGKE ELECTRIC CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202510864845.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-06-26
Publication Date
2026-01-06
Estimated Expiration
2045-06-26

AI Technical Summary

Technical Problem

In traditional RS485 bus systems, devices need to be pre-configured with addresses before being connected, which leads to compatibility difficulties and excessively long initialization times. This also prevents the dynamic acceptance of new devices, affecting system efficiency and flexibility.

Method used

A two-way handshake protocol based on Nonce codes and an N-frame collision avoidance algorithm are adopted to enable plug-and-play network access for devices. The host generates Nonce codes for device identification and network ID allocation, and the N-frame collision avoidance algorithm is used to resolve bus conflicts.

Benefits of technology

It enables rapid device identification and network access without the need for pre-configured addresses, reduces system complexity, improves the convenience of device integration and system scalability, and meets the dynamic changing needs of modern automation systems.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120710816B_ABST
    Figure CN120710816B_ABST
Patent Text Reader

Abstract

The application provides a plug-and-play network access method and system of an intelligent gateway based on an RS485 bus, relates to the field of industrial bus communication, and through an N-frame collision avoidance algorithm, the method can effectively deal with bus conflict conditions through a random backoff mechanism; a Nonce identification system is established, a 4-byte random number identification domain is set in a communication frame, a temporary session channel is established, precise device identification without address pre-configuration is realized; a bidirectional handshake protocol is set; through the interaction of a network access request frame and a network access response frame, a network ID is dynamically allocated, and device identity binding is completed. Through the use of the method, a sub-device can actively initiate a network access application, plug-and-play and plug-and-network access are realized, and due to the existence of the Nonce code, all sub-devices do not need to perform address configuration operations before network access, thereby greatly simplifying the configuration process.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of industrial bus communication, and more particularly to a plug-and-play network access method for an intelligent gateway based on an RS485 bus. Background Technology

[0002] In traditional RS485 bus systems, a preset address polling mechanism is commonly used to achieve device communication and management. However, this traditional mechanism has many significant drawbacks, causing numerous inconveniences for practical system applications and device integration.

[0003] First, each sub-device must be pre-configured with a unique address before connecting to the system. In practice, this often leads to compatibility issues, especially when the system involves devices from multiple different manufacturers. Different manufacturers may use different address configuration rules and encoding methods, requiring a significant amount of time and effort to coordinate and adapt the addresses of each device during the integration process, greatly increasing the complexity and cost of system integration.

[0004] Secondly, the polling cycle increases linearly with the number of devices, leading to excessively long network initialization times. As the number of devices in the system increases, the time required for polling also increases accordingly, which is particularly evident in large systems with a large number of devices. The lengthy network initialization process not only reduces system efficiency but may also affect the overall system performance and response speed in some application scenarios with high real-time requirements, failing to meet the needs of practical applications.

[0005] Third, existing network systems cannot dynamically accept new devices; they must be interrupted and rescanned. This means that if new devices need to be added to expand system functionality or for device updates during system operation, the entire system must be paused, which is unacceptable for systems requiring continuous operation. This inflexible networking approach limits the system's scalability and adaptability, failing to meet the requirements of modern automation systems for dynamic changes and flexible configuration.

[0006] To address the aforementioned problems of traditional RS485 bus systems, this invention proposes a bus access system based on dynamic identifiers, aiming to enable plug-and-play network access for smart gateways and improve the performance and application flexibility of RS485 bus systems. Summary of the Invention

[0007] To address the aforementioned issues, this invention provides a plug-and-play network access method and system for smart gateways based on the RS485 bus. By using this method, sub-devices can proactively initiate network access requests, achieving plug-and-play functionality and immediate network access. Furthermore, due to the presence of the Nonce code, all sub-devices do not need to perform address configuration operations before network access, greatly simplifying the configuration process.

[0008] To achieve the above objectives, the technical solution adopted by the present invention is as follows:

[0009] In a first aspect of the present invention, a plug-and-play network access method for a smart gateway based on an RS485 bus is provided, comprising the following steps:

[0010] If the sub-device has not yet joined the network, the sub-device will send a network joining application to the host at preset time intervals;

[0011] The host generates a corresponding network access response frame based on the network access application and sends the network access response frame to the sub-device;

[0012] The sub-device completes the network access operation based on the network access response frame;

[0013] The host assigns a network ID to the sub-device, and the sub-device communicates with the host in the network through the network ID;

[0014] Once the sub-device successfully joins the network, the host actively polls for the sub-device's data information.

[0015] Preferably, after receiving the network access application frame from the sub-device, the host uses the same Nonce as the network access application frame to respond when generating the network access response frame, and attaches the network access ID information assigned by the host to the sub-device in the response frame.

[0016] Preferably, the network access application frame and the network access response frame include the following frame structure: frame header, frame length, nonce, data, and checksum;

[0017] The frame header is used to identify the beginning of a message frame; the frame length is used to indicate the total length from the frame header to the checksum; the Nonce is a one-time random number identifier used to establish a temporary session channel; the data typically includes function words and corresponding data; and the checksum is used to verify the correctness of the message.

[0018] As a preferred option, an N-frame collision avoidance algorithm is also included. For non-broadcast messages, the N-frame collision avoidance algorithm is used for transmission. Specifically, if no response frame is received within a fixed time after the message is sent (i.e., within the timeout period), the message is retransmitted after n maximum transmission times, where n is an integer ranging from 0 to N, and N is the maximum number of retransmissions.

[0019] More preferably, the timeout period is determined based on the communication time measured under normal communication conditions.

[0020] More preferably, the maximum transmission time is the time required to transmit the longest frame message.

[0021] In a second aspect of the present invention, a plug-and-play network access system based on an RS485 bus is provided, comprising a host and at least one sub-device. The host is configured to receive a network access request frame sent by the sub-device, generate a corresponding network access response frame according to the network access request frame, and send the network access response frame to the sub-device. The sub-device is configured to complete the network access operation according to the network access response frame.

[0022] Preferably, the sub-device includes a sending module and a receiving module. The sending module is used to actively send a network access application frame to the host at preset time intervals, and the receiving module is used to receive a network access response frame sent by the host.

[0023] The plug-and-play network access method and system for a smart gateway based on the RS485 bus proposed in this invention have the following significant advantages:

[0024] Firstly, by employing an N-frame collision avoidance algorithm, which utilizes a random backoff mechanism, bus collisions can be effectively addressed. In complex environments where multiple devices simultaneously access and communicate, this algorithm significantly reduces the probability of data transmission conflicts, ensuring reliable data transmission and improving system stability and communication efficiency.

[0025] Secondly, the constructed Nonce identifier system cleverly sets a 4-byte random number identifier field in the communication frame, thereby establishing a temporary session channel. This innovation enables accurate device identification without the need for pre-configured addresses, allowing devices from different manufacturers to quickly and easily access the system without complex adaptations, greatly enhancing system compatibility and the convenience of device integration.

[0026] Thirdly, the introduced two-way handshake protocol, through the interaction of network access request frames and network access response frames, can dynamically allocate network IDs and complete device identity binding. This gives the system a powerful dynamic admission capability, allowing new devices to be added at any time without affecting the normal operation of the system, achieving true plug-and-play functionality. This greatly improves the system's scalability and flexibility, meeting the needs of modern automation systems for dynamic changes and real-time expansion, and has broad market application prospects and practical application value. Attached Figure Description

[0027] Figure 1 This is a flowchart of a plug-and-play network access method for devices based on an RS485 bus according to the present invention.

[0028] Figure 2 This is a framework diagram of a plug-and-play network access system based on RS485 bus according to the present invention.

[0029] Figure 3 This is a flowchart of an N-frame collision avoidance algorithm according to a preferred embodiment of the present invention. Detailed Implementation

[0030] The hardware connection physically connects the main controller to each sub-device via an RS485 bus. Ensure proper bus wiring and avoid interference sources, such as keeping it away from power lines. Each sub-device has an RS485 communication interface, which connects to the main controller's interface.

[0031] The software initialization involves installing and configuring the dynamic identifier-based bus access system software of this invention on the main controller. Communication parameters for each sub-device are initialized to enable basic communication capabilities, but pre-configuration of device addresses is not required.

[0032] Taking a typical industrial automation workshop as an example, this workshop deploys various sensors, actuators, and other devices from different manufacturers, all of which communicate via RS485 bus. A central controller is located in the workshop for centralized management and control of all the sub-devices. The original system used a preset address polling mechanism. Whenever a new device needed to be connected, a unique address had to be manually configured for the device, and the entire system had to be interrupted for a rescan when adding a new device, severely impacting production efficiency.

[0033] Please see Figure 1 As shown, in a first aspect of the present invention, a plug-and-play network access method for a smart gateway based on an RS485 bus is provided, comprising the following steps:

[0034] If the sub-device has not yet joined the network, the sub-device will send a network joining application to the host at preset time intervals;

[0035] Determine the timeout time and maximum transmission time based on the actual communication environment and requirements.

[0036] When a sub-device needs to send a non-broadcast message, it constructs the message according to the set frame structure and sends it to the bus. During the timeout period after message transmission, the sub-device listens to the bus to see if it receives an acknowledgment frame. If no acknowledgment frame is received, it randomly selects an integer n between 0 and N according to the N-frame collision avoidance algorithm, and then waits for n maximum transmission times before retransmitting the message. For example, assuming N is set to 3, if the sub-device does not receive an acknowledgment the first time it sends a message, it randomly generates an integer between 0 and 3, such as 2, waits for 2 maximum transmission times, and then retransmits the message until it successfully receives an acknowledgment or reaches the maximum number of retransmissions.

[0037] The host generates a corresponding network access response frame based on the network access application and sends the network access response frame to the sub-device;

[0038] A nonce code generation module is integrated into the communication software between the main controller and the sub-devices. Whenever a communication frame needs to be constructed, whether it is a network access request frame sent by the sub-device, other messages, or a response frame sent by the main controller, this module randomly generates a 4-byte nonce code and embeds it into the corresponding position in the frame structure.

[0039] When the main controller receives a network access request frame from a sub-device, it first extracts the Nonce code and uses the same Nonce code in its generated network access response frame. Upon receiving the response frame, the sub-device compares the Nonce code in the response frame with the Nonce code in its own network access request frame. If they match, the sub-device considers the response frame a correct response to its network access request, thus establishing a temporary session channel and completing the initial identification and matching of the device during the network access process.

[0040] The network access application frame and network access response frame include the following frame structure: frame header, frame length, nonce, data, and checksum;

[0041] The structures of the network access application frame and the network access response frame are shown in Table 1 below:

[0042] Table 1. Structure of Network Access Request Frame and Network Access Response Frame

[0043]

[0044] The frame header is used to identify the beginning of a message frame; the frame length is used to indicate the total length from the frame header to the checksum; the Nonce is a one-time random number identifier used to establish a temporary session channel; the data typically includes function words and corresponding data; and the checksum is used to verify the correctness of the message.

[0045] Two-way handshake protocol execution:

[0046] Network access application initiation: After a newly purchased sub-device is connected to the RS485 bus, since it has not yet joined the network, its internal communication program will actively send a network access application frame to the main controller at preset time intervals (such as every 30 seconds). The network access application frame is constructed according to the prescribed frame structure and includes fields such as frame header, frame length, Nonce, and FUNC. The FUNC field is set to the function code of the network access request (such as 0x01).

[0047] Network Access Response and ID Allocation: After receiving a network access request frame, the main controller parses the information in the request frame through the protocol processing module in the software and assigns a unique network ID to the sub-device according to preset rules. Then, it constructs a network access response frame, in which the frame header, frame length, and other fields are set according to regulations, the Nonce field uses the same value as the network access request frame, the FUNC field is set to the function code for network access request response (such as 0x02), and the assigned network ID information is appended to the data part. The main controller then sends this network access response frame back to the sub-device.

[0048] The sub-device completes the network access operation based on the network access response frame;

[0049] After receiving the network access response frame, the sub-device verifies whether the Nonce code matches. If it matches, it extracts the assigned network ID and stores it in the device's non-volatile memory. After this, the sub-device officially becomes a member of the network.

[0050] In multi-device communication scenarios, bus collisions are difficult to avoid. When a collision occurs, the device randomly backs off using an N-frame collision avoidance algorithm and retransmits the message. During retransmission, the device generates a new Nonce code and embeds it into the frame. The receiving end receives the retransmitted message, identifies the retransmission attempt through the Nonce code, distinguishes messages sent by different devices, and ensures correct processing and response to each device's retransmitted message. Even if multiple devices retransmit almost simultaneously, their unique Nonce codes allow the receiving end to accurately match messages with devices, maintain communication order, and improve bus utilization and system reliability.

[0051] Nonce codes, combined with the N-frame collision avoidance algorithm, optimize the bus communication process. When a collision occurs, the device randomly backs off based on the N-frame collision avoidance algorithm and retransmits the message. The newly generated nonce code enables the receiver to quickly identify the retransmitted frame and respond accurately. Nonce codes ensure that the receiver can quickly distinguish and process messages from different devices, reducing waiting and processing time and improving bus turnaround speed. In polling communication, nonce codes help the host accurately identify device response frames, promptly extract data, and initiate the next round of polling, shortening the polling cycle and improving system response speed and real-time performance. This is of great significance for efficient monitoring and management of the production process.

[0052] The host assigns a network ID to the sub-device, and the sub-device communicates with the host in the network through the network ID;

[0053] Once the sub-device successfully joins the network, the host actively polls for the sub-device's data information.

[0054] After a sub-device joins the host network, the main controller can actively poll the sub-device's data information according to the set polling strategy, thereby enabling monitoring and management of the sub-device.

[0055] For example, the main controller can periodically poll the sensor data collected by the sub-devices, such as temperature and pressure, for centralized display and analysis. It can also send control commands to the sub-devices to achieve automated control of the production process.

[0056] Please see Figure 2 As shown, in a second aspect of the present invention, a plug-and-play network access system based on an RS485 bus is provided, comprising a host and at least one sub-device. The host is configured to receive a network access request frame sent by the sub-device, generate a corresponding network access response frame according to the network access request frame, and send the network access response frame to the sub-device. The sub-device is configured to complete the network access operation according to the network access response frame.

[0057] Preferably, the sub-device includes a sending module and a receiving module. The sending module is used to actively send a network access request frame to the host at preset time intervals, and the receiving module is used to receive a network access response frame sent by the host.

[0058] During system operation, simulating a normal production scenario, a new sub-device is suddenly connected. Traditional RS485 bus systems cannot dynamically accept new devices, requiring a shutdown and rescanning, leading to production interruptions. However, the system of this invention can automatically detect the new device's network access request. Without affecting the normal operation of existing equipment, it successfully completes the new device's network access process through an N-frame collision avoidance algorithm, a nonce identifier system, and a two-way handshake protocol. Furthermore, the new device can immediately participate in data communication after network access, achieving true plug-and-play functionality and greatly improving the system's dynamic adaptability and flexibility.

[0059] The N-frame collision avoidance algorithm is one of the core innovations of this invention, aiming to effectively solve the bus collision problem and ensure the stability and reliability of device communication in the RS485 bus system. The following is a detailed explanation of the specific working principle of the N-frame collision avoidance algorithm and its application in the implementation of this invention:

[0060] Working principle

[0061] Please see Figure 3 As shown, the initial parameter settings must be configured before the system runs, and the key parameters of the N-frame collision avoidance algorithm need to be set in advance:

[0062] Timeout (Tout): Determined based on the average time from message transmission to response under normal communication conditions. For example, by calculating the average time for message transmission and response through multiple actual communication tests, the timeout is set to 1.5 times that average time.

[0063] Maximum transmission time (Tmax): This refers to the time required to send the longest possible message frame. It is calculated based on the maximum message length and communication rate that may occur in the actual communication scenario, with a certain margin, such as setting it to twice the longest message transmission time.

[0064] Maximum number of retransmissions (N): This is determined based on a comprehensive consideration of the system's communication reliability and efficiency. For example, it can be set to 5 times in demanding systems and 3 times in general scenarios. When N is set to 0, the message is sent only once without retransmission.

[0065] Message transmission process: When a sub-device or host needs to send a non-broadcast message, it first constructs a complete communication frame, including fields such as frame header, frame length, nonce, data, and checksum. Then, it sends the message according to the following steps:

[0066] S01: The transmitting device sends a message to the bus and starts a timer;

[0067] S02: If the timer has not expired (the instantaneous time is less than or equal to Tout), the transmitting device continues to listen to the bus and waits to receive an acknowledgment frame.

[0068] S03: If an acknowledgment frame is received within the timeout period, the communication is considered successful. The sending device stops timing and clears the timer, waiting for the next communication task.

[0069] S04: If no acknowledgment frame is received after the timeout period Tout, it is determined that a collision may have occurred during the message transmission or the receiver has not received the message correctly. The sending device generates a random integer n according to the preset N-frame collision avoidance algorithm, where 0 ≤ n ≤ N. Then it waits for n Tmax time intervals.

[0070] Message retransmission process: After waiting for n Tmax time intervals, the sending device will retry sending the previous message. The process for each retransmission is the same as the initial message sending process, including constructing a communication frame, sending the message, starting a timer, and listening for acknowledgments. The number of retransmissions will decrease with each retransmission until the maximum number of retransmissions N is reached.

[0071] By including a unique nonce code in each transmitted message, accurate matching of transmitted and acknowledgment messages is ensured during retransmission. The presence of the nonce code allows the device to distinguish between different communication sessions, guaranteeing the accuracy and consistency of communication even in the event of multiple retransmissions and collisions.

[0072] During the network access process, the sub-device and the host perform identity binding and network ID allocation through a two-way handshake protocol. The N-frame collision avoidance algorithm provides reliable communication guarantees for this process, ensuring that network access request frames and response frames can be successfully transmitted, thereby improving the success rate and efficiency of device network access.

[0073] If an acknowledgment frame is received during the retransmission process, the communication is considered successful. Retransmission stops, and the timer restarts to wait for the next communication task. If no acknowledgment frame is received after reaching the maximum number of retransmissions N, the communication is considered a failure. The sending device will discard the message and report the communication failure to the application, awaiting further processing or re-initiating the communication request.

[0074] The N-frame collision avoidance algorithm in this invention effectively solves the bus collision problem in RS485 bus systems through a carefully designed random backoff and retransmission mechanism, providing a solid foundation for achieving plug-and-play and stable, reliable communication. In practical industrial applications, this algorithm, in conjunction with other innovative technologies, significantly improves the system's performance and adaptability.

[0075] This embodiment, applied in an industrial automation workshop, verifies the feasibility and effectiveness of the proposed plug-and-play network access method for an intelligent gateway based on the RS485 bus. This method effectively avoids bus conflicts using an N-frame collision avoidance algorithm, achieves accurate device identification without address pre-configuration through a Nonce identifier system, and completes dynamic network access and identity binding of devices using a bidirectional handshake protocol. In practical applications, it solves many problems of traditional RS485 bus systems, improves system compatibility, initialization efficiency, and dynamic acceptance capabilities, and provides a more efficient, flexible, and reliable solution for device communication and management systems in the industrial automation field, possessing broad application prospects and promotional value.

[0076] The above embodiments are merely descriptions of preferred embodiments of the present invention and are not intended to limit the scope of the present invention. Various modifications and improvements made by those skilled in the art to the technical solutions of the present invention without departing from the spirit of the present invention should fall within the protection scope defined by the claims of the present invention.

Claims

1. A plug and play method for an intelligent gateway based on RS485 bus, characterized in that, The method comprises the following steps: If the current sub-device has not been networked, the sub-device sends a network entry application to the host through a preset time interval; The host generates a corresponding network entry response frame according to the network entry application and sends the network entry response frame to the sub-device; The sub-device completes the network entry operation according to the network entry response frame; The host allocates a network ID to the sub-device, and the sub-device communicates with the host in the network through the network ID; After the sub-device is successfully networked, the host actively polls the data information of the sub-device; After the host receives the network entry application frame of the sub-device, the same Nonce as the network entry application frame is used for response when generating the network entry response frame, and the network entry ID information allocated by the host to the sub-device is attached in the response frame; The network entry application frame and the network entry response frame comprise the following frame structure: frame header, frame length, Nonce, data and check; The frame header is used to identify the start of a frame message; the frame length is used to represent the total length from the frame header to the check; the Nonce is a one-time random number identifier, which is used to establish a temporary session channel; the data usually contains a function word and corresponding data; the check is used to check the correctness of the message.

2. The plug-and-play network access method of the intelligent gateway based on the RS485 bus according to claim 1, characterized in that, An N-frame collision avoidance algorithm is further included, and for non-broadcast messages, the N-frame collision avoidance algorithm is used for sending, specifically: within a fixed time, i.e. a timeout time, after the message is sent, if no response frame of the message is received, the message is re-sent after a random n maximum sending time, wherein n is an integer and the value range is 0 to N, and N is the maximum number of retransmissions.

3. The plug-and-play network access method of the intelligent gateway based on the RS485 bus according to claim 2, characterized in that, The timeout time is determined according to the communication time under the actual measured normal communication condition.

4. The plug-and-play network access method of the intelligent gateway based on the RS485 bus according to claim 2, characterized in that, The maximum sending time is the time required for sending the longest frame of message.

5. A plug and play system for RS485 bus based devices, characterized in that, The host and at least one sub-device, the host is used for receiving the network entry application frame sent by the sub-device, and generating a corresponding network entry response frame according to the network entry application frame, and sending the network entry response frame to the sub-device, the sub-device is used for completing the network entry operation according to the network entry response frame; The host allocates a network ID to the sub-device, and the sub-device communicates with the host in the network through the network ID; After the sub-device is successfully networked, the host actively polls the data information of the sub-device; After the host receives the network entry application frame of the sub-device, the same Nonce as the network entry application frame is used for response when generating the network entry response frame, and the network entry ID information allocated by the host to the sub-device is attached in the response frame; The network entry application frame and the network entry response frame comprise the following frame structure: frame header, frame length, Nonce, data and check; The frame header is used to identify the start of a frame message; the frame length is used to represent the total length from the frame header to the check; the Nonce is a one-time random number identifier, which is used to establish a temporary session channel; the data usually contains a function word and corresponding data; the check is used to check the correctness of the message.

6. A plug and play system for RS485 bus-based devices according to claim 5, characterized in that, The sub-device comprises a sending module and a receiving module, the sending module is used to actively send a network entry application frame to the host every preset time interval, and the receiving module is used to receive the network entry response frame sent by the host.

Citation Information

Patent Citations

  • Mesh network-based node discovery method, apparatus and device, and storage medium

    CN117014993A

  • Duplicate address detecting method, slave and master in field bus system, and field bus

    JP2004274395A