A dynamic communication system and method based on RS485 bus

Through the dynamic communication system based on the RS485 bus, the problem of low efficiency of Modbus protocol in RS485 bus communication is solved, flexible network access and protocol switching of slave devices are realized, and communication efficiency and system stability are improved.

CN119966761BActive Publication Date: 2025-08-26BEIJING ACCUENERGY TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

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

AI Technical Summary

Technical Problem

The Modbus protocol combined with RS485 bus communication is not efficient in scenarios where there are many devices or require high real-time response, the bus overhead is large, the equipment is complex, and the query cycle is extended when communication failure is performed, which reduces the bus utilization rate.

Method used

The dynamic communication system based on the RS485 bus is adopted. By sending network access requests from the slave device, the master device allocates a communication address, and supports switching between push protocols, synchronization protocols and polling protocols. The master and slave devices select the most suitable protocol for communication according to their needs.

Benefits of technology

It realizes flexible expansion and reduction of the system, and the slave device does not need to fix the address in advance, reduces labor costs, improves communication efficiency and reliability, and ensures data synchronization and system stability.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119966761B_ABST
    Figure CN119966761B_ABST
Patent Text Reader

Abstract

The present application relates to the field of communication protocol technology, and in particular to a dynamic communication system and method based on an RS485 bus. The system comprises: a master device and at least one slave device connected via an RS485 bus; the slave device sends a network access request to the master device, and the master device allocates a communication address to the slave device based on the network access request; when the slave device successfully accesses the network, and the master device broadcasts a switch to a push protocol or a synchronization protocol, the slave device sends current configuration information to the master device; when the master device successfully receives and synchronizes the current configuration information, and the master device broadcasts a switch to a push protocol, the slave device pushes data to the master device based on the push protocol; when the master device broadcasts a switch to a polling protocol, the master device sequentially accesses each slave device based on the polling protocol. The present application can achieve efficient data communication.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of communication protocol technology, and in particular to a dynamic communication system and method based on RS485 bus. Background Art

[0002] In the fields of industrial automation and building control, the Modbus protocol combined with the RS485 bus communication solution has been widely adopted, but it faces multiple challenges in actual deployment and management. First, Modbus's master-slave sequential polling mechanism is inefficient in scenarios with numerous devices or requiring high real-time response times. Bus overhead is high and utilization is low, as all slaves must wait to be polled before transmitting data. Second, when adding a new slave, construction personnel must consult the existing address list, assign a new address, and set it on the new device. This process is complex and prone to errors. Finally, when a slave goes offline or experiences a communication failure, the master must wait a long time for confirmation of a timeout. This not only prolongs the query cycle for other slaves but also significantly reduces overall bus utilization, creating a "barrel effect." Clearly, the relevant technology suffers from low communication efficiency when it comes to master-slave device communication. Summary of the Invention

[0003] In order to solve the problem of low communication efficiency in the prior art, the present application provides a dynamic communication system and method based on RS485 bus.

[0004] In a first aspect, the present application provides a dynamic communication system based on an RS485 bus, which adopts the following technical solution: a dynamic communication system based on an RS485 bus, comprising: a master device and at least one slave device connected via the RS485 bus;

[0005] The slave device sends a network access request to the master device, and the master device allocates a communication address to the slave device according to the network access request;

[0006] When the slave device successfully joins the network and the master device broadcasts switching the current protocol to the push protocol or the synchronization protocol, the slave device sends the current configuration information to the master device;

[0007] When the master device successfully receives and synchronizes the current configuration information, and the master device broadcasts a message indicating that the current protocol is switched to a push protocol, the slave device pushes data to the master device based on the push protocol;

[0008] When the master device broadcasts switching the current protocol to the polling protocol, the master device sequentially accesses each slave device based on the polling protocol.

[0009] By adopting the above technical solution, the slave device joins the network by sending a network access request, and the master device allocates a communication address to the slave device based on the network access request, so that the system can flexibly expand or reduce the number of slave devices without pre-fixing the communication address of each slave device, reducing labor costs and improving communication efficiency. The system supports switching between push protocols, synchronization protocols and polling protocols, so that the system can select the most appropriate protocol according to current communication needs and data transmission characteristics, and then the master and slave devices communicate based on the corresponding protocols, realizing efficient and flexible data communication and management.

[0010] In a preferred example, the present application may be further configured as follows: when the master device broadcasts switching the current protocol to the synchronization protocol, the master device monitors the bus, and after determining that all slave devices connected to the bus have stopped pushing data, periodically performs the synchronization step;

[0011] Among them, the synchronization step includes: the master device broadcasts a synchronization beacon and starts a first timer; after the slave device receives the synchronization beacon, it starts a second timer and pushes data to the master device, and the timing difference between the first timer and the second timer is a first duration; when the first timer ends, the master device accesses each slave device in turn based on the polling protocol.

[0012] By adopting the above technical solution, when the master device switches to the synchronization protocol, it monitors the bus to ensure that all slave devices stop pushing data, and then periodically performs synchronization steps, including broadcasting a synchronization beacon and starting a timer. After the slave device receives the beacon, it also starts the timer and pushes data, and uses the time difference of the timer to ensure data synchronization. Finally, the master device checks the status of the slave device based on the polling protocol. This mechanism improves the accuracy of data synchronization and the stability of the system.

[0013] In a preferred example, the present application may be further configured as follows: the slave device reports current configuration information to the master device, the current configuration information including a function code and device configuration information;

[0014] After receiving the current configuration information, the master device synchronizes the current configuration information to the host memory of the master device and sends configuration reply information to the slave device;

[0015] If the slave device does not receive the configuration reply information within the second time period, the slave device repeatedly sends the current configuration information to the master device based on a preset random delay until the configuration reply information is received within the second time period, and the configuration reply information includes a confirmation function code.

[0016] By adopting the above technical solution, the slave device reports the current configuration information including the function code and device configuration information to the master device. After receiving it, the master device synchronizes it to the host memory and sends a configuration reply message containing a confirmation function code. If the slave device does not receive a reply within the specified time, it will repeat the message based on a random delay until a reply is received. This mechanism ensures accurate synchronization of configuration information and reliable communication between the master and slave devices.

[0017] In a preferred example, the present application may be further configured as follows: the slave device periodically performs a data pushing step; wherein the data pushing step includes: the slave device repeatedly pushing data to the master device until the number of pushes reaches a preset number of pushes, or a reply message from the master device is received;

[0018] After receiving the data pushed by the slave device, the master device determines whether the slave configuration information in the host memory is modified. If so, a reply message containing the modified slave configuration information is sent to the slave device.

[0019] By adopting the above technical solution, the slave device periodically pushes data to the master device until the preset number of pushes is reached or a reply is received from the master device. After receiving the data, the master device checks whether the slave device configuration information is updated and sends a reply containing the updated configuration information to the slave device accordingly. This mechanism ensures continuous data updates and real-time synchronization of slave device configurations, improving system data consistency.

[0020] In a preferred example, the present application may be further configured as follows: the master device periodically performs a polling step on each slave device in turn based on the comparison table;

[0021] The polling step includes: the master device sends a request frame to the current slave device and listens for a data frame returned by the current slave device; if the master device receives the data frame, or the master device does not receive the data frame within a third time period, the current polling step is ended.

[0022] By adopting the above technical solution, the master device periodically executes polling steps based on the comparison table for each slave device, sends request frames and listens for returned data frames. Regardless of whether the data frame is received, the current polling ends within the set time. This mechanism ensures that the system can check the status of each slave device or collect data in an orderly and efficient manner, thereby improving the response efficiency of the system.

[0023] In a preferred example, the present application may be further configured as follows: the master device sends multiple broadcasts so that each slave device receives the broadcasts;

[0024] The broadcast types of the master device include: control broadcast, host online broadcast and protocol switching broadcast.

[0025] By adopting the above technical solution, the master device ensures that each slave device can receive key information by sending multiple types of broadcasts, including control broadcasts, host online broadcasts, and protocol switching broadcasts. This mechanism improves the reliability of system communication and the response consistency of all slave devices.

[0026] In a second aspect, the present application provides a dynamic communication method based on an RS485 bus, which adopts the following technical solution: a dynamic communication method based on an RS485 bus, applied to a dynamic communication system based on an RS485 bus, the method being executed by a master device, the method comprising:

[0027] receiving a network access request sent by a slave device, and allocating a communication address to the slave device based on the network access request;

[0028] When the slave device successfully joins the network and the master device broadcasts switching the current protocol to the push protocol or the synchronization protocol, receiving the current configuration information sent by the slave device;

[0029] When the master device successfully receives and synchronizes the current configuration information, and the master device broadcasts a message indicating that the current protocol is switched to a push protocol, receiving data pushed by the slave device based on the push protocol;

[0030] When the master device broadcasts switching the current protocol to the polling protocol, each slave device is accessed in sequence based on the polling protocol. In summary, the present application has the following beneficial technical effects:

[0031] In this application, the slave device joins the network by sending a network access request, and the master device assigns a communication address to the slave device based on the network access request, so that the system can flexibly expand or reduce the number of slave devices without pre-fixing the communication address of each slave device, reducing labor costs and improving communication efficiency. The system supports switching between push protocols, synchronization protocols and polling protocols, so that the system can select the most appropriate protocol according to current communication needs and data transmission characteristics, and then the master and slave devices communicate based on the corresponding protocols, realizing efficient and flexible data communication and management. BRIEF DESCRIPTION OF THE DRAWINGS

[0032] Figure 1 1 is a schematic diagram of the overall structure of a dynamic communication system based on RS485 bus provided in an embodiment of the present application;

[0033] Figure 2 This is a configuration flow chart based on the configuration push protocol provided in an embodiment of the present application;

[0034] Figure 3 This is a push flow chart based on the push protocol provided in an embodiment of the present application;

[0035] Figure 4 This is a single-cycle polling flow chart provided by an embodiment of the present application;

[0036] Figure 5 This is a sub-flowchart of a data request from a single slave device provided in an embodiment of the present application;

[0037] Figure 6 This is a synchronization flow chart based on the synchronization protocol provided in an embodiment of the present application;

[0038] Figure 7 This is a flow chart of a dynamic communication method based on RS485 bus provided in an embodiment of the present application. DETAILED DESCRIPTION

[0039] The following is combined with Figure 1 -Attached Figure 7 This application is described in further detail.

[0040] This specific embodiment is merely an explanation of the present application and is not a limitation of the present application. After reading this specification, those skilled in the art may make non-creative modifications to the present embodiment as needed, but as long as they are within the scope of the claims of the present application, they are protected by the patent law.

[0041] To make the purpose, technical solutions, and advantages of the embodiments of this application more clear, the technical solutions in the embodiments of this application will be clearly and completely described below in conjunction with the drawings in the embodiments of this application. Obviously, the described embodiments are part of the embodiments of this application, not all of the embodiments. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of this application.

[0042] In this document, the term "and / or" simply describes a relationship between related objects, indicating that three possible relationships exist. For example, "A and / or B" can represent: A exists alone, A and B exist simultaneously, or B exists alone. Furthermore, the character " / " in this document, unless otherwise specified, generally indicates an "or" relationship between the related objects.

[0043] It should be noted that in the optional embodiments of the present application, the object information and other related data involved, when the embodiments in the present application are applied to specific products or technologies, need to obtain the permission or consent of the object, and the collection, use and processing of the relevant data need to comply with the relevant laws, regulations and standards of the relevant countries and regions. In other words, if the embodiments of the present application involve data related to the object, it needs to be obtained through the authorization and consent of the object, the authorization and consent of the relevant departments, and in compliance with the relevant laws, regulations and standards of the country and region. If personal information is involved in the embodiments, the acquisition of all personal information requires the consent of the individual. If sensitive information is involved, the separate consent of the information subject needs to be obtained. The embodiments also need to be implemented with the authorization and consent of the object.

[0044] The present application provides a new communication protocol for automatic networking between communication devices based on the RS485 bus. The communication protocol is applied to a dynamic communication system based on the RS485 bus. The system includes a master device and at least one slave device connected via the RS485 bus. The master device and the slave device communicate with each other via the communication protocol provided by the present application. The slave device can automatically join the network in real time, and the master device can automatically identify the slave device, thereby achieving the purpose of two-way communication based on the RS485 bus. It can reduce a large amount of manual labor costs during on-site construction and improve the reliability and efficiency of communication networking.

[0045] like Figure 1 As shown, it shows a schematic diagram of the overall structure of a dynamic communication system based on RS485 bus provided by the present application, the system includes a master device and at least one slave device. Figure 1 Slave devices are represented by slave device 1 to slave device N. The master device and the slave device are powered on and perform self-tests respectively. The master device is initialized after the power-on self-test. The slave device is powered on and performs self-tests and sends a network access request to the master device based on the network access protocol. The master device assigns a unique communication address to each slave device based on the network access request. After receiving the assigned communication address, the slave device returns an acknowledgment message ACK to the master device.

[0046] Master device broadcasts are used to synchronize the current bus protocol, switch between different protocols, and control batches of slave devices. When a slave device successfully joins the network and the master device broadcasts a switch to the push or synchronization protocol, the slave device sends its current configuration information to the master device using the configuration push protocol. After receiving the current configuration information pushed by the slave device, the master device returns an acknowledgment message (ACK) to the slave device.

[0047] When the master device successfully receives and synchronizes the current configuration information, and the master device broadcasts a message indicating that the current protocol has been switched to the push protocol, the slave device pushes data to the master device based on the push protocol. After receiving the data pushed by the slave device, the master device returns an ACK message to the slave device.

[0048] When the master device broadcasts the switch to the polling protocol, it accesses each slave device sequentially based on the polling protocol. The master device can access each slave device sequentially based on the slave device communication address, from smallest to largest. When accessing any slave device, the master device can send a data request to the slave device to obtain data from the slave device. The master device can also send a data request frame with configuration to the slave device. After receiving the data request frame, the slave device completes the data configuration and returns the data and an acknowledgment message (ACK) to the master device.

[0049] In this embodiment, the slave device joins the network by sending a network access request, and the master device assigns a communication address to the slave device based on the network access request, so that the system can flexibly expand or reduce the number of slave devices without pre-fixing the communication address of each slave device, reducing labor costs and improving communication efficiency. The system supports switching between push protocols, synchronization protocols and polling protocols, so that the system can select the most appropriate protocol according to current communication needs and data transmission characteristics, and then the master and slave devices communicate based on the corresponding protocols, realizing efficient and flexible data communication and management.

[0050] In a possible implementation of the embodiment of the present application, the master device sends multiple broadcasts so that each slave device receives the broadcast; wherein the broadcast types of the master device include: control broadcast, host online broadcast and protocol switching broadcast.

[0051] In this embodiment, the master device's broadcast frequency can be flexibly set by the administrator based on practical experience and is not limited in this embodiment. The master device can broadcast in any situation. To ensure that broadcast frames are successfully delivered to all slaves, the master device will continuously send broadcast frames, and the broadcast time is much longer than the transmission time of other messages. Table 1 shows the master device's broadcast types.

[0052]

[0053] Table 2 shows examples of the formats of the broadcast frame and the slave device reply.

[0054]

[0055] In this embodiment, the master device ensures that each slave device can receive key information by sending multiple types of broadcasts including control broadcasts, host online broadcasts and protocol switching broadcasts. This mechanism improves the reliability of system communication and the response consistency of all slave devices.

[0056] In a possible implementation of the embodiment of the present application, the slave device reports current configuration information to the master device, where the current configuration information includes a function code and device configuration information;

[0057] After receiving the current configuration information, the master device synchronizes the current configuration information to the host memory of the master device and sends a configuration reply message to the slave device;

[0058] If the slave device does not receive the configuration reply information within the second time period, the slave device repeatedly sends the current configuration information to the master device based on a preset random delay until the configuration reply information is received within the second time period, and the configuration reply information includes a confirmation function code.

[0059] See also Figure 2 , which shows a configuration flow chart based on the configuration push protocol. When the slave device successfully joins the network and the master device broadcasts the switch of the current protocol to the push protocol or the synchronization protocol, the current configuration information of the slave device is synchronized to the master device based on the configuration push protocol. Specifically, taking any slave device as an example to illustrate the configuration push process: the slave device reports the current configuration information to the master device. The frame format of the current configuration information of the slave device is shown in Table 3, including: the push protocol start identifier, the communication address, the function code, the device configuration information of the slave device, the version information, and the CRC check. Among them, the function code is used to distinguish different functions and distinguish between master and slave devices. The specific configuration of the current configuration information is customized according to different slave devices.

[0060]

[0061] Furthermore, the slave device monitors whether an acknowledgment frame of the configuration reply information of the master device is received within the second duration. Table 4 shows the acknowledgment frame format of the configuration reply information of the master device. The second duration is a preset duration, which can be 1 second, and the preset random delay can be 10% to 3 times the second duration, that is, the preset random delay can be 0.1 second to 3 seconds.

[0062]

[0063] In this embodiment, the slave device reports the current configuration information including the function code and device configuration information to the master device. After receiving it, the master device synchronizes it to the host memory and sends a configuration reply message containing a confirmation function code. If the slave device does not receive a reply within the specified time, it repeats the message based on a random delay until a reply is received. This mechanism ensures accurate synchronization of configuration information and reliable communication between the master and slave devices.

[0064] In a possible implementation of the embodiment of the present application, the slave device periodically performs the data push step;

[0065] The data pushing step includes: repeatedly pushing data from the slave device to the master device until the number of pushes reaches a preset number of pushes, or receiving a reply message from the master device;

[0066] After receiving the data pushed by the slave device, the master device determines whether the slave configuration information in the host memory has been modified. If so, it sends a reply message containing the modified slave configuration information to the slave device.

[0067] In this embodiment, when the master device successfully receives and synchronizes the current configuration information, and the master device broadcasts a message indicating a switch to the push protocol, the slave device periodically executes the data push step based on the push protocol. The period is dynamic and can be pre-set to a fixed period, with a random delay of up to 10% added to the fixed period as the data push period. The push protocol is primarily suitable for scenarios with low real-time requirements but requiring flexible networking.

[0068] See also Figure 3 , which shows a push flow chart based on the push protocol. Taking any slave device as an example in any cycle, the slave device performs data push steps including: pushing data from the slave device to the master device. The data format can be customized according to the push protocol of different slave devices. Table 5 shows the general message format of the pushed data.

[0069]

[0070] Within the fourth time period after the slave device pushes data to the master device, the slave device waits for a reply from the master device. If the master device does not reply within the fourth time period, the slave device randomly delays for a period ranging from 10% to twice the fourth time period after the end of the fourth time period, and then pushes the data again. The above process is repeated until the number of data pushes reaches the preset number of pushes, or the slave device receives a reply from the master device. If the slave device still does not receive a reply from the master device after the preset number of pushes, the slave device resets the time and waits for the next cycle to push data again. The fourth time period and the preset number of pushes can be flexibly set. The fourth time period can be 1 second, and the random delay based on the fourth time period can be 0.1 second to 1 second.

[0071] After the master device receives the push data from the slave device, it determines whether the slave configuration information in the host memory needs to be modified by the host operator. If not, the host returns a reply message. Table 6 shows the frame format of the master device receiving the push data and returning the reply message to the slave device.

[0072]

[0073] If the slave configuration information in the host memory is modified, the master device sends a reply message back to the slave device carrying the modified slave configuration information. Table 7 shows the frame format of the reply message containing the modified slave configuration information returned by the master device.

[0074]

[0075] Furthermore, after receiving the reply information including the modified slave configuration information, the slave device updates its own configuration information and returns a response to the master device. Table 8 shows the frame format of the response information.

[0076]

[0077] If the master device does not receive the response information returned by the slave device, the master device retains the modification of the slave configuration information and tries to return the reply information containing the modified slave configuration information again when the slave device pushes data next time.

[0078] In this embodiment, the slave device periodically pushes data to the master device until the preset number of pushes is reached or a reply is received from the master device. After receiving the data, the master device checks whether the slave device configuration information is updated, and accordingly sends a reply containing the updated configuration information to the slave device. This mechanism ensures continuous data updates and real-time synchronization of slave device configurations, thereby improving system data consistency.

[0079] In a possible implementation of the embodiment of the present application, the master device periodically performs a polling step on each slave device in turn based on the comparison table;

[0080] The polling step includes: the master device sends a request frame to the current slave device and monitors the data frame returned by the current slave device; if the master device receives the data frame, or the master device does not receive the data frame within the third time period, the current polling step ends.

[0081] In this embodiment, when the master device broadcasts the switch of the current protocol to the polling protocol, the master device accesses each slave device in turn based on the polling protocol. The polling step is implemented based on the polling protocol. The polling protocol is mainly used in scenarios where the real-time requirements are improved after the bus operation is stable. The master device sends a data request to the specified slave device, and the specified slave device returns the corresponding data.

[0082] In each cycle, the master device performs polling steps on each slave device connected to the bus in turn, see Figure 4 , which shows a single-cycle polling flow chart. The master device searches a comparison table and sorts the slave devices in the comparison table by communication address from smallest to largest to create a slave list. Starting with the first slave in the list, the master device executes the polling steps sequentially until the list is exhausted. The polling steps are used to obtain data from a single slave device. Within any cycle, the master device sequentially accesses each slave in the slave list to complete the polling.

[0083] See also Figure 5, which shows a data request sub-flowchart for a single slave device, that is, a polling step flow chart. The master device sends a request frame to the current slave device. If the master device successfully sent configuration information to the current slave device last time and the configuration information of the current slave device in the master device has not been modified, the master device sends a request frame without configuration information. Table 9 shows the request frame format.

[0084]

[0085] If the master device fails to send configuration information to the current slave device last time, or the configuration information of the current slave device in the master device is modified, the request frame sent by the master device contains the configuration information. Table 10 shows the format of the request frame containing configuration information sent by the master device.

[0086]

[0087] After receiving the request frame sent by the master device, the slave device returns the corresponding data in the request frame to the master device. The format of the returned data frame is shown in Table 11.

[0088]

[0089] The master device listens for data frames returned from the slave device during the third duration. If no data frames are received within the third duration, the master device determines that the configuration delivery has failed, ends the polling process for the current slave device, skips the current slave device, and begins polling the next slave device. The master device then attempts to deliver the configuration again when it requests data from the slave device to which the configuration delivery failed in the next cycle. The third duration can be set to 1 second.

[0090] In this embodiment, the master device periodically performs polling steps based on the comparison table on each slave device, sends request frames and listens for returned data frames. Regardless of whether a data frame is received, the current polling ends within the set time. This mechanism ensures that the system can check the status of each slave device or collect data in an orderly and efficient manner, thereby improving the response efficiency of the system.

[0091] A possible implementation of an embodiment of the present application is that when the master device broadcasts the switching of the current protocol to the synchronous protocol, the master device monitors the bus, determines that all slave devices connected to the bus have stopped pushing data, and then periodically performs a synchronization step; wherein the synchronization step includes: the master device broadcasts a synchronization beacon and starts a first timer; after the slave device receives the synchronization beacon, it starts a second timer and pushes data to the master device, and the timing difference between the first timer and the second timer is a first duration; when the first timer expires, the master device accesses each slave device in turn based on a polling protocol.

[0092] In this embodiment, the synchronous protocol combines the push protocol and the polling protocol through periodic synchronous switching, achieving real-time data refresh and dynamic networking capabilities, suitable for a variety of application scenarios. After the master device broadcasts the switch to the synchronous protocol, each slave device receives the broadcast and enters silence. The master device monitors the bus for a period of time (this period is greater than the maximum period for slave devices to push data) to confirm that all slave devices have stopped pushing data.

[0093] Taking any cycle as an example, the synchronization steps are executed based on the synchronization protocol within the cycle. Figure 6 A synchronization flow chart based on the synchronization protocol is shown, and the various main devices on the bus are represented as slave device 1 to slave device N. The synchronization steps include: the master device broadcasts a synchronization beacon and starts a first timer. The time of the first timer can be adjusted by the technician according to real-time performance. After the slave device receives the synchronization beacon, it starts a second timer. The timing difference between the first timer and the second timer is a first duration. Optionally, the first duration is 1s. After the slave device starts the second timer, it slowly pushes data to the master device using the push protocol. At this time, the slave can have two modes: network access + data push, and network access only. If a new slave device is incorporated into the bus during this process, the new slave device will be connected to the network in accordance with the slave device network access protocol and the configuration push protocol.

[0094] After the second timer of each slave device expires, it remains silent. After the first timer of the master device expires, all slave devices have entered silence. The master device begins to quickly obtain data from all slave devices in sequence using the polling protocol. The number of polling times is N. After the master device completes data acquisition, it broadcasts the synchronization beacon again and enters the next cycle of data synchronization.

[0095] In addition, in the synchronization protocol of this embodiment, synchronization can be performed without relying on synchronization beacons and timers, and synchronization can be performed directly by the master device periodically broadcasting the switching protocol.

[0096] In this embodiment, when the master device switches to the synchronization protocol, it monitors the bus to ensure that all slave devices stop pushing data, and then periodically performs synchronization steps, including broadcasting a synchronization beacon and starting a timer. After the slave device receives the beacon, it also starts the timer and pushes data. The time difference of the timer is used to ensure data synchronization. Finally, the master device checks the status of the slave device based on the polling protocol. This mechanism improves the accuracy of data synchronization and the stability of the system.

[0097] Compared with Modbus-RTU communication, the communication protocol provided in the embodiment of the present application greatly reduces the labor cost of on-site construction and realizes zero manual operation for slave machine access to the network; it also provides great flexibility, and can perform both low-load slow communication and high-speed data transmission and reception, and can quickly switch between different sub-protocols; the process is streamlined, and operations such as data push, configuration distribution and confirmation can be completed with only 2-3 sends in total; it fully considers the abnormal situations in the application scenario, so that the impact of slave machine failure on the bus is minimized.

[0098] In the dynamic communication system based on RS485 bus provided in this application, the RS485 bus can be replaced with a CAN bus, while other technical solutions remain unchanged. The communication effect is better, but the cost is higher. The dynamic communication system based on CAN bus should also be considered as the scope of protection of this application.

[0099] The present application embodiment provides a dynamic communication method based on RS485 bus, such as Figure 7 As shown, the method is applied to a dynamic communication system based on an RS485 bus. In the embodiment of the present application, the method provided is executed by a master device, and the method includes steps S501 to S704, wherein:

[0100] S701: Receive a network access request sent by a slave device, and allocate a communication address to the slave device based on the network access request.

[0101] S702: When the slave device successfully joins the network and the master device broadcasts switching of the current protocol to the push protocol or the synchronization protocol, the master device receives the current configuration information sent by the slave device.

[0102] S703: When the master device successfully receives and synchronizes the current configuration information, and the master device broadcasts a message indicating that the current protocol is switched to the push protocol, the master device receives data pushed by the slave device based on the push protocol.

[0103] S704 : When the master device broadcasts switching the current protocol to the polling protocol, each slave device is accessed in turn based on the polling protocol.

[0104] It should be understood that although the steps in the flowcharts of the accompanying drawings are shown in sequence as indicated by the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless otherwise specified herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least some of the steps in the flowcharts of the accompanying drawings may include multiple sub-steps or multiple stages, and these sub-steps or stages are not necessarily executed at the same time, but can be executed at different times, and their execution order is not necessarily sequential, but can be executed in turn or alternately with other steps or at least a portion of the sub-steps or stages of other steps.

[0105] The above are only some of the implementation methods of the present application. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present application. These improvements and modifications should also be regarded as the scope of protection of the present application.

Claims

1. A dynamic communication system based on RS485 bus, characterized in that: include: A master device and at least one slave device connected via an RS485 bus; The slave device sends a network access request to the master device, and the master device allocates a communication address to the slave device according to the network access request; When the slave device successfully joins the network and the master device broadcasts switching the current protocol to the push protocol or the synchronization protocol, the slave device sends the current configuration information to the master device; When the master device successfully receives and synchronizes the current configuration information, and the master device broadcasts a message indicating that the current protocol is switched to a push protocol, the slave device pushes data to the master device based on the push protocol; When the master device broadcasts switching the current protocol to the polling protocol, the master device sequentially accesses each slave device based on the polling protocol; When the master device broadcasts switching the current protocol to the synchronous protocol, the master device monitors the bus, and after determining that all slave devices connected to the bus have stopped pushing data, periodically performs the synchronization step; Among them, the synchronization step includes: the master device broadcasts a synchronization beacon and starts a first timer; after the slave device receives the synchronization beacon, it starts a second timer and pushes data to the master device, and the timing difference between the first timer and the second timer is a first duration; when the first timer ends, the master device accesses each slave device in turn based on the polling protocol.

2. The dynamic communication system based on RS485 bus according to claim 1, characterized in that, The slave device reports current configuration information to the master device, wherein the current configuration information includes a function code and device configuration information; After receiving the current configuration information, the master device synchronizes the current configuration information to the host memory of the master device and sends configuration reply information to the slave device; If the slave device does not receive the configuration reply information within the second time period, the slave device repeatedly sends the current configuration information to the master device based on a preset random delay until the configuration reply information is received within the second time period, and the configuration reply information includes a confirmation function code.

3. The dynamic communication system based on RS485 bus according to claim 1, characterized in that, The slave device periodically executes the data pushing step; The data pushing step includes: the slave device repeatedly pushing data to the master device until the number of pushes reaches a preset number of pushes, or until a reply message from the master device is received; After receiving the data pushed by the slave device, the master device determines whether the slave configuration information in the host memory is modified. If so, a reply message containing the modified slave configuration information is sent to the slave device.

4. The dynamic communication system based on RS485 bus according to claim 1, characterized in that, The master device periodically performs a polling step on each slave device in turn based on the comparison table; The polling step includes: the master device sends a request frame to the current slave device and listens for a data frame returned by the current slave device; if the master device receives the data frame, or the master device does not receive the data frame within a third time period, the current polling step is ended.

5. The dynamic communication system based on RS485 bus according to claim 1, characterized in that, The master device sends multiple broadcasts so that each slave device receives the broadcasts; The broadcast types of the master device include: control broadcast, host online broadcast and protocol switching broadcast.

6. A dynamic communication method based on RS485 bus, characterized in that, Applied to a dynamic communication system based on an RS485 bus, the method is executed by a master device and comprises: receiving a network access request sent by a slave device, and allocating a communication address to the slave device based on the network access request; When the slave device successfully joins the network and the master device broadcasts switching the current protocol to the push protocol or the synchronization protocol, receiving the current configuration information sent by the slave device; When the master device successfully receives and synchronizes the current configuration information, and the master device broadcasts a message indicating that the current protocol is switched to a push protocol, receiving data pushed by the slave device based on the push protocol; When the master device broadcasts switching the current protocol to a polling protocol, each slave device is accessed in turn based on the polling protocol; When the master device broadcasts switching the current protocol to the synchronous protocol, it monitors the bus, and after determining that all slave devices connected to the bus have stopped pushing data, it periodically performs the synchronization step; Among them, the synchronization step includes: broadcasting a synchronization beacon and starting a first timer; starting a second timer and pushing data after receiving the synchronization beacon from the slave device, and the timing difference between the first timer and the second timer is a first duration; when the first timer ends, accessing each slave device in turn based on the polling protocol.

Citation Information

Patent Citations

  • Communication switching method, device and system based on serial bus polling protocol

    CN112214441A

  • Communication method, system and equipment based on RS-485 bus and storage medium

    CN118445246A