Master station communication method and device based on Modbus-RTU protocol and medium

Optimizing Modbus-RTU main station communication through priority linked lists and dynamic scheduling mechanisms, solving the problem of inefficiency in traditional communication methods, achieving efficient data transmission and real-time updates, and is suitable for industrial automation systems.

CN120281598APending Publication Date: 2025-07-08NEW SCENERY (SUZHOU) TECH CO LTD +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510616389.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-05-14
Publication Date
2025-07-08

AI Technical Summary

Technical Problem

The existing Modbus-RTU master station communication method is inefficient when processing multiple discrete high-priority data, and the code writing is complex, making it difficult to meet the real-time update requirements of key data.

Method used

The main station communication method based on the Modbus-RTU protocol is adopted. By generating a priority link list, the communication data is attached to the nodes of the corresponding priority according to the degree of importance, and the high-priority data is dynamically dispatched by the traverser and the scheduler, and data frame encapsulation and transmission are combined with the communication manager.

Benefits of technology

It improves data transmission efficiency, solves the problems of high-priority data response latency and insufficient real-time performance, supports multi-task parallel processing, and meets the real-time update requirements of complex industrial scenarios.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120281598A_ABST
    Figure CN120281598A_ABST
Patent Text Reader

Abstract

The invention discloses a master station communication method and device based on a Modbus-RTU protocol, and a medium. The method comprises the following steps: generating communication data sent to a Modbus slave station; filling the communication data into the newly-added data node, and hooking the newly-added data node to the head node or the data node with the corresponding priority according to the communication importance degree corresponding to the communication data to obtain a priority chain table; modifying node attributes in the priority linked list through a traversal device, so as to switch node states or adjust the priority linked list when the modified node attributes meet a preset condition; submitting a data node which is in a ready state and has the highest priority in the priority linked list to a communication manager; the method comprises the following steps: analyzing a data node through a communication manager, carrying out communication message packaging through node attributes obtained through analysis to obtain a Modbus data frame, and controlling a transceiver to send the Modbus data frame to a Modbus slave station so as to realize communication with the Modbus slave station.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of communication technologies, and particularly to a master station communication method, device, and medium based on the Modbus-RTU protocol. Background Art

[0002] Modbus-RTU is a serial communication protocol used for PLC communication. Now it has become an industry standard for communication protocols in the industrial field. In many industrial scenarios, Modbus-RTU communication is used for device-to-device communication. Generally, RS485 and RS422 are used as electrical interfaces to transmit data through twisted pairs as the medium.

[0003] For existing Modbus-RTU master stations, they generally use a single state machine polling scheme. Command frames are sent in a linear or partially circular order according to a preset state transition method. This method is relatively easy to implement in theory, but it is essentially a centralized management method. For occasions with multiple discrete high-priority data, it needs to rotate in certain states frequently, which will lead to low data transmission efficiency and complex code writing prone to errors. In the case of polling with extremely large amounts of data, certain key real-time data does not allow the update cycle process, and the traditional Modbus-RTU master station communication polling scheme is difficult to meet the application requirements for real-time update of device key data. Summary of the Invention

[0004] To solve the above problems, this application proposes a master station communication method based on the Modbus-RTU protocol, which is applied to a Modbus-RTU master station and includes: Generating communication data to be sent to the Modbus slave station through a data generation module; wherein, the communication data includes data sent to the Modbus slave station and the data address corresponding to the data; Filling the communication data into a newly added data node, and hanging the newly added data node behind the head node or data node corresponding to the priority according to the communication importance degree corresponding to the communication data, so as to obtain a priority linked list; wherein, the priority linked list refers to a linked list group composed of multiple linked lists corresponding to priorities; Modifying the node attributes in the priority linked list through a traverser, so as to perform a node state switching operation or adjust the priority linked list when the modified node attributes meet a preset condition; Searching the priority linked list in sequence according to the priorities corresponding to the priority linked list from high to low through a scheduler, so as to submit the data node in the priority linked list that is in the ready state and has the highest priority to the communication manager; Through the communication manager, the data node is parsed, and a communication message is encapsulated based on the node attributes obtained by the parsing to obtain a Modbus data frame. Then, the transceiver is controlled to send the Modbus data frame to the Modbus slave station, thereby realizing communication with the Modbus slave station.

[0005] In one implementation manner of the present application, the communication data is filled into a newly added data node, and according to the communication importance level corresponding to the communication data, the newly added data node is attached after the head node or data node with the corresponding priority to obtain a priority linked list, which specifically includes: Determine the corresponding communication priority type according to the communication importance level corresponding to the communication data; wherein, the communication priority types include, in order from high to low communication priority: starvation priority, forced polling / non-polling priority, limited node priority, and general polling priority; Select a head node whose corresponding priority matches the communication priority type, and attach the newly added data node after the head node or data node of the priority linked list where the head node is located to obtain the attached priority linked list.

[0006] In one implementation manner of the present application, the node attributes include a sleep time. Through a traverser, the node attributes in the priority linked list are modified so that when the modified node attributes meet a preset condition, a node state switching operation is performed, which specifically includes: Traverse all data nodes in the priority linked list through the traverser; For the infinite-life cycle nodes in the sleep state among all the data nodes, modify the sleep time of the infinite-life cycle nodes so as to shorten the sleep time through the call period of the traverser; wherein, the infinite-life cycle node refers to a data node that is periodically scheduled and enters the sleep state after being scheduled; Repeat the modification operation until the sleep time meets the preset condition, and then switch the infinite-life cycle node from the sleep state to the ready state.

[0007] In one implementation manner of the present application, during the traversal process, the data node in the ready state and with the highest priority in the priority linked list is submitted to the communication manager, which specifically includes: During the traversal process, determine the data node in the ready state and with the highest priority in the priority linked list; According to the node attributes of the data node, delay the submission of the data node to the communication manager by a preset duration, so that the Modbus slave station can complete the processing of adjacent Modbus data frames submitted by the communication manager according to the preset duration.

[0008] In one implementation of the present application, after submitting the data node in the ready state and with the highest priority in the priority linked list to the communication manager, the method further includes: Adjust the state of the scheduler to the locked state; After sending the Modbus data frame to the Modbus slave, the method further includes: Control the communication manager to enter the waiting for response state and attempt to obtain the response information returned by the Modbus slave; According to the response type of the response information, control the communication manager to perform the corresponding response operation.

[0009] In one implementation of the present application, according to the response type of the response information, controlling the communication manager to perform the corresponding response operation specifically includes: If the communication manager does not obtain the response information within the preset time period, or the response type corresponding to the response information is an error, adjust the communication manager from the waiting for response state to the idle state, and unlock the scheduler, so that the scheduler continues to schedule the data nodes in the priority linked list; If the response type corresponding to the response information is a successful response, update the buffer according to the response information, adjust the communication manager from the waiting for response state to the idle state, and unlock the scheduler through the communication manager, so that the scheduler continues to schedule the data nodes in the priority linked list.

[0010] In one implementation of the present application, after sending the Modbus data frame to the Modbus slave, the method further includes: Modify the node attribute of the data node corresponding to the Modbus data frame according to the response information; The modification at least includes any one or more of the following: Adjust the data node corresponding to the Modbus data frame to the sleep state, and hang the data node in the sleep state to the end of its corresponding priority linked list, delete or mark for retransmission the data node, mark the data node for retransmission, restore the original priority of the data node.

[0011] In one implementation of the present application, adjusting the priority linked list specifically includes: Based on the traverser, for the data nodes in the hungry state among all data nodes, in the case that the data nodes in the hungry state are not located in the priority linked list corresponding to the hunger priority, the data nodes in the hungry state are re - attached from the priority linked list where they are located to the priority linked list corresponding to the hunger priority.

[0012] An embodiment of the present application provides a master station communication device based on the Modbus - RTU protocol, and the device includes: At least one processor; And a memory communicatively connected to the at least one processor; Wherein, the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor, so that the at least one processor can execute a master station communication method based on the Modbus - RTU protocol as described in any one of the above.

[0013] An embodiment of the present application provides a non - volatile computer storage medium, storing computer - executable instructions, and the computer - executable instructions are set as: A master station communication method based on the Modbus - RTU protocol as described in any one of the above.

[0014] A master station communication method based on the Modbus - RTU protocol proposed by the present application can bring the following beneficial effects: Through the priority assignment of nodes, combined with the dynamic scheduling mechanism of the priority linked list, it effectively solves the problems of high - priority data response delay and insufficient real - time performance in the traditional Modbus - RTU master single - state - machine polling mode, can skip invalid polling according to the task priority, and supports multi - task parallel processing, significantly improving the data transmission efficiency in complex industrial scenarios and meeting the real - time update requirements of data. BRIEF DESCRIPTION OF THE DRAWINGS

[0015] The drawings described herein are used to provide a further understanding of the present application, and constitute a part of the present application. The schematic embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation to the present application. In the drawings: Figure 1 It is a schematic flowchart of a master station communication method based on the Modbus - RTU protocol provided by an embodiment of the present application; Figure 2 It is a schematic diagram of a Modbus - RTU master station communication architecture provided by an embodiment of the present application; Figure 3 It is a schematic diagram of the principle of a priority linked list provided by an embodiment of the present application; Figure 4A schematic diagram of data node generation provided by an embodiment of the present application; Figure 5 A schematic flowchart of another master station communication method based on the Modbus-RTU protocol provided by an embodiment of the present application; Figure 6 A schematic structural diagram of a master station communication device based on the Modbus-RTU protocol provided by an embodiment of the present application. Detailed implementation manners

[0016] To make the objectives, technical solutions, and advantages of the present application clearer, the technical solutions of the present application will be clearly and completely described below in conjunction with specific embodiments of the present application and the corresponding drawings. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all of the embodiments. All other embodiments obtained by those of ordinary skill in the art based on the embodiments in the present application without creative efforts shall fall within the protection scope of the present application.

[0017] The technical solutions provided by each embodiment of the present application will be described in detail below with reference to the drawings.

[0018] As Figure 1 shown, a master station communication method based on the Modbus-RTU protocol provided by an embodiment of the present application is applied to a Modbus-RTU master station and includes: S101: Generate communication data to be sent to a Modbus slave station through a data generation module; where the communication data includes data sent to the Modbus slave station and the data address corresponding to the data.

[0019] The Modbus master station and the slave station are two device roles defined in the Modbus-RTU communication protocol for realizing data interaction between devices in an industrial automation system. The Modbus master station is the initiator of communication and is responsible for controlling the entire communication process. The Modbus slave station, as the responder to the communication, passively receives the master station instructions and makes responses. The communication method provided by the embodiment of the present application is applied to a Modbus-RTU master station. As Figure 2 shown in a schematic diagram of a Modbus-RTU master station communication architecture, the Modbus-RTU master station includes a data generation module, a scheduler, a traverser, a communication manager, and a transceiver. Through the coordinated use of each module, data transmission in an industrial scenario can be realized.

[0020] Among them, the data generation module can generate certain communication data after power-on initialization according to communication characteristics. The communication data includes the data sent to the Modbus slave and the corresponding data address of the data. These communication data will be sent to the Modbus slave. When generating communication data, the main parameters to be considered are: whether it is a finite life cycle, the importance of the finite life cycle, the message sleep time (i.e., the scheduling period) in the infinite life cycle (i.e., cyclic polling), the bus load, the node starvation time strategy, etc.

[0021] S102: Fill the communication data into the newly added data node, and according to the communication importance level corresponding to the communication data, hang the newly added data node after the head node or data node with the corresponding priority to obtain a priority linked list; among them, the priority linked list refers to a linked list group composed of multiple linked lists corresponding to multiple priorities.

[0022] Compared with the traditional message polling strategy, in the embodiment of the present application, the node generation module can generate a corresponding newly added data node for each communication message, and after the communication data is generated, fill the communication data into the newly added data node, and according to the communication importance level corresponding to the communication data, hang the newly added data node after the head node or data node with the corresponding priority matching the communication priority, so as to obtain a priority linked list. The priority linked list is a linked list structure organized in an orderly manner according to communication priorities. Each priority corresponds to a linked list, and the linked list is led by a head node. The communication data with the same priority is hung in the corresponding linked list in sequence. The priority linked list is not a single priority, but multiple priorities. Each priority is a linked list, and the linked list group composed of multiple linked lists is called a priority linked list. The data node refers to the node that stores the actual communication data. In the traditional communication method, the master station needs to poll all slave stations in a fixed order. Even if some slave stations have no key data updates, they still need to occupy communication time. However, in the embodiment of the present application, each communication message is abstracted into an independent priority linked list node, and the message with a higher priority will be scheduled first, skipping the invalid polling and shortening the overall communication cycle. Moreover, in the traditional state machine polling, if a certain slave station responds timeout or has a large amount of data, it will block all subsequent polling tasks. Through the priority linked list, even if a certain slave station's communication fails, other data nodes can still be normally scheduled to ensure the overall communication continuity.

[0023] The principle of the priority linked list is as Figure 3 shown. There is a Modbus-RTU master station manager. The manager manages 8 priorities. Each priority is a linked list with a fixed linked list head, and multiple data nodes (the number of data nodes is based on the number of messages and is limited by the MCU memory) can be hung or not hung behind it. During operation, the node generation module can also dynamically generate data nodes, such as single-bit change data, and summarize the newly generated data nodes under the structure of the priority linked list.

[0024] The master station manager includes pointers to the structure heads of eight priority linked lists, the total number of nodes, transmit and receive buffers, baud rate, stop bits, etc.; the structure of the linked list head node: it includes the number of nodes in the linked list under the current priority, the pointer to the next valid node, etc.; the structure of the linked list data node (the relevant attribute information of the message is in this node): it includes the entry address of the next valid node, the number of valid elements in the current node, Modbus message information, the number of times of timeout retransmission of the station node, etc.

[0025] When hanging the node corresponding to the communication data to the priority linked list, it is first necessary to determine the corresponding communication priority type according to the importance of the communication data. The communication priority types include, in order from highest to lowest communication priority: starvation priority, forced polling / non-polling priority, limited node priority, and general polling priority. That is to say, the starvation message has the highest priority, and the general polling message has the lowest priority. According to the Figure 3 priority linked list shown, priority 0 is the highest priority and priority 7 is the lowest priority.

[0026] According to the above communication priority types, priority 0 is the starvation priority, priority 1 is the forced polling / non - polling priority, priority 2 is the limited node priority, and priorities 3 - 7 are the general polling priorities. Among them, the starvation priority is the highest level. It refers to the priority that cannot be based on the nodes assigned by the user and is used for internal calls by the traverser. This priority is mainly used to solve the "starvation" problem caused by the too - low node priority resulting in the node not being scheduled. When a node is in the starvation state, the traverser will remove the node from its original priority and attach it to this priority. Then, the scheduler will quickly remove the node from the priority 0 linked list and put it into the communication processor for communication processing. After processing, the communication manager restores the original priority of the node. The forced polling / non - polling priority is for data with very high polling requirements (such as closed - loop control - type data) or some non - polling but fast - transmission message nodes (such as safety shutdown messages). Such nodes do not want to be affected by other messages and need to strictly follow the transmission periodicity and real - time nature. At this time, they can be attached to this priority for processing. The limited node priority: Some messages may not be polling messages, such as the common "status - change transmission" messages, which only need to initiate a transmission when the data changes. At this time, the node where the message is located will be destroyed after successful transmission and released to the common resource pool. The life cycle of such nodes is limited and they have little impact on the bus, so their priority is relatively high. The general polling priority: In common communication transmission tasks, this type of priority is generally used for periodic transmission communication. Because compared with the strict polling priority of priority 1, this type of priority has less impact on the bus. If it is difficult to plan when there are too many messages, only priority 3 can be used for design. If the concurrent number of polling messages is small and the bus bandwidth is sufficient, using priorities 4 - 7 for reasonable allocation can make the communication strategy more reasonable and orderly.

[0027] After determining the communication priority type corresponding to the communication data, the head node matching the corresponding priority of the priority linked list can be selected according to the communication priority type. One head node corresponds to the priority linked list of one priority, and the data nodes attached to each priority linked list have the same priority. If there are no data nodes attached to the priority linked list, the newly added data node corresponding to the current communication data can be directly attached after the head node. If there are already attached data nodes in the priority linked list, then the newly added data node corresponding to the communication data is attached after the data node at the end of the priority linked list.

[0028] Such as Figure 4A schematic diagram of data node generation is shown. A new communication message is generated from state 1 to state 2. The priority of the communication data matches that of priority 2. Since no data node is attached to the priority linked list of priority 2, the previously generated communication data is filled into node 20 and attached to the head node. At the same time, the subsequently generated communication data is filled into node 21 and attached to the back of node 20.

[0029] S103: Through a traverser, modify the node attributes in the priority linked list so that when the modified node attributes meet the preset conditions, perform a switching operation on the node state.

[0030] The traverser will periodically traverse all nodes in the priority linked list and, during the traversal process, modify the node attributes of the data nodes. For example, modify the sleep time of the data nodes. In this way, when the node attributes meet the preset conditions, the node state can be switched, or the node connection relationship in the priority linked list can be adjusted.

[0031] In one embodiment, when scheduling data nodes, before each execution of the scheduling process, it is necessary to traverse the data nodes through a traverser to find the data nodes that can be scheduled from the priority linked list. During the search process, if the data node is a finite node, since the finite node will initiate a transmission when the data changes and will be destroyed after a successful transmission, for such data nodes, the traverser generally does nothing. If the data node is an infinite life cycle node, this type of data node can only be scheduled when other data nodes are in the sleep state. During the traversal of the data nodes, for the infinite life cycle nodes in the sleep state, each time the traversal process is executed, it is necessary to modify their node attributes. The node attributes here refer to the sleep time. Modifying the sleep time is essentially reducing the sleep time of the infinite life cycle node according to the call period of the traverser. For example, if the sleep time of a data node is 30s and the call period of the traverser is 1s, then each time the traverser is called and 1s has passed, 1s needs to be subtracted from the sleep time of the data node accordingly. Each time the traverser is scheduled, the above modification operation needs to be repeated until the sleep time of the infinite life cycle node meets the preset conditions, that is, when it is 0, the infinite life cycle node switches from the sleep state to the ready state, and at this time the infinite life cycle node will wait to be scheduled by the scheduler.

[0032] In addition, the traverser also counts the starvation time of data nodes. When the starvation time reaches the preset time, the data node is updated to a starved data node. At the same time, the traverser will operate on the priority linked list where the starved data node is located, remove the starved data node from its original priority linked list, and reattach it to the starvation priority linked list, i.e., the priority linked list corresponding to priority 0, so as to preferentially process the data nodes in the starved state. In addition to the above features, the traverser also ignores data nodes with some special features, such as data nodes in the Block state in the priority linked list for some reason.

[0033] S104: Through the scheduler, search the priority linked lists in turn according to the priorities of the priority linked lists from high to low, so as to submit the data node in the ready state and with the highest priority in the priority linked list to the communication manager.

[0034] After filling and attaching the communication data to the priority linked list, it is necessary to traverse the priority linked list in turn based on the scheduler according to the priorities of the priority linked lists from high to low. First, it will check priority 0. If there are data nodes at this priority, the data nodes after the head node of priority 0 will be removed and submitted to the communication manager. If there are no nodes at priority 0, the scheduler will continue to search for priority 1, priority 2, and so on until the traversal is completed. By analogy, when the scheduler finishes querying the priority linked list of the last priority and still cannot obtain a valid data node, it will exit this scheduling process, and the scheduler will self-block until it is awakened after waiting for a fixed period and then perform the scheduling process again. It should be noted that the data nodes submitted to the communication manager need to be in the ready state, i.e., the Ready state. If the data node is in the sleep state, even if its priority is very high, it will not be preferentially scheduled.

[0035] Take Figure 4 as an example. Suppose data node 10 is in the ready state, then data node 10 is the node with the highest priority in the ready state. If data node 10 is in the sleep state, and data nodes 20 and 21 are both in the ready state, then data node 20 is the node with the highest priority in the ready state. If data nodes 10 and 20 are both in the sleep state, data node 21 is in the ready state, and data node 30 is also in the ready state. Although on the linked list with priority 3, the first ready state node is data node 30, since there is a ready state data node 21 at priority 2, the node with the highest priority in the ready state is data node 21, not data node 30. In this case, data node 21 should be submitted to the scheduler first.

[0036] The main function of the scheduler is to remove the data node with the highest priority in the Ready state from the priority linked list and write it into the communication manager. If the scheduler obtains a valid Ready data node, it will enter the additional feature module of the scheduler, that is, the delay scheduling module. The main function of the delay scheduling module is to delay the time for submitting the data node in the ready state to the communication manager by a preset duration, that is, to ensure that the bus is idle for a period of time before sending the communication message into the communication manager. The main purpose of this is to control the delay between two adjacent data frames of Modbus-RTU, so that the Modbus slave can normally complete the processing of adjacent Modbus data frames submitted by the communication manager according to the preset duration, and avoid some slaves being unable to correctly process the command information of the master station when the scheduler works too fast.

[0037] If the delay scheduling module of the scheduler successfully sends the first data node into the communication manager, the scheduler will enter the locked state, and the scheduler cannot unlock itself in this locked state and needs to be unlocked using the communication manager.

[0038] S105: Through the communication manager, parse the data node, encapsulate the communication message according to the node attributes obtained by the parsing, obtain the Modbus data frame, and control the transceiver to send the Modbus data frame to the Modbus slave to achieve communication with the Modbus slave.

[0039] After receiving the data node, the communication manager will parse it to obtain the node attributes in the data node. At the same time, according to the key information in the node provided by the scheduler, such as the station address, function code, etc., combined with the node attributes, the communication message of the data node is encapsulated to obtain the Modbus data frame. The data nodes in the priority linked list mentioned above are essentially virtual nodes because they only store the communication data of the communication message, but essentially do not have the communication attributes of the message and cannot forward communication externally. And the process of encapsulating the communication message is essentially a process of instantiating the virtual data nodes in the priority linked list. This encapsulation function is provided by the Modbus-RTU link layer module integrated in the communication manager. The link layer module provides a general abstract interface, that is, the "virtual physical layer" interface, which is also a sub-module of the communication manager. The virtual physical layer interface stipulates the buffer structure, endianness, CPU bus width, flag bit group, physical layer transceiver peripheral pointer, etc. Through this interface, the communication manager can easily adapt to different MCUs to implement master station communication.

[0040] The encapsulated Modbus data frame will be submitted to the virtual physical layer, which sends it to the Modbus slave via a transceiver. The transceiver is responsible for signal conditioning and level conversion, such as converting the TTL or CMOS level of the communication peripheral to the 485 level, and its behavior characteristics are controlled by the communication manager. After the Modbus slave responds, the communication with the Modbus slave is achieved.

[0041] After the Modbus data frame is sent, the master manager will control the communication manager to enter the "SendingWait" state, that is, the waiting response state. In this state, the communication manager is in a blocked state waiting for the slave's response and tries to obtain the response information returned by the Modbus slave. During this period, no other operations can be performed. According to the response type of the received response information, the master manager will control the communication manager to perform the corresponding response operation, thus starting the next message scheduling process.

[0042] In one embodiment, if the communication manager does not obtain the response information within the preset time period, or although a response is obtained, the response type corresponding to the response information is an error, such as error messages like incorrect message length, CRC check error, etc., at this time, it is determined that this communication fails, and the communication management needs to be adjusted from the waiting response state to the "Free-Scheduled" state (i.e., the idle state). This state indicates that the communication manager has released resources and returned to the idle state, allowing the scheduler to continue to execute subsequent tasks. Therefore, in this state, the communication manager will unlock the scheduler so that the scheduler can continue to perform the next scheduling of the data nodes in the priority list.

[0043] If the response type corresponding to the response information is a successful response and the CRC check is successful, then this communication is successful. At this time, the buffer will be updated according to the response information, and the communication manager will be adjusted from the waiting response state to the idle state, and at the same time, the scheduler will be unlocked so that the scheduler can continue to schedule the data nodes in the priority list. When any of the above situations occurs, the relevant flags need to be processed, such as incrementing (failure) or decrementing (success) the fault counter, recording the total number of faults, etc.

[0044] In one embodiment, after the flags are processed, the communication manager will modify the node attributes of the data node corresponding to the currently processed Modbus data frame according to the response information. The modification includes at least any one or more of the following: adjusting the data node corresponding to the Modbus data frame to the sleep state and hanging the data node in the sleep state to the end of its corresponding priority list, deleting or marking the retransmission data node, marking the data node for retransmission, restoring the original priority of the data node.

[0045] The above modification operations are set according to the processing flags (success, failure, timeout). For the data nodes with successfully sent data, they are nodes with infinite life cycle and have completed a periodic task. Set the next wake-up time for such nodes. In the same-priority linked list, move this node to the end of the queue to ensure that other nodes with the same priority have the opportunity to be scheduled and avoid the "starvation" phenomenon. By integrating the strategy of round-robin scheduling for the same priority, the nodes processed by the scheduler and the communication manager with the same priority will be placed at the end of the linked list of this priority, ensuring that other nodes of this priority can definitely be scheduled. For nodes with a finite life cycle, they will be deleted when the sending is successful and the resources occupied by the nodes will be released. When the sending fails, mark and retransmit, and wait for retry by re-adding the node to the sending queue. For data nodes with a priority of 0, their priorities are temporarily adjusted in special cases and need to be restored to their original priorities after the task is completed.

[0046] Figure 5 It is a schematic flow chart of another master station communication method based on the Modbus-RTU protocol provided by the embodiment of the present application. As Figure 5 shown, the scheduler finds the data node in the Ready state from the priority linked list, that is, node 11, and submits node 11 to the communication manager. The communication manager will parse its message to obtain the corresponding node attributes, instantiate the virtual node, implement the encapsulation of the communication message, and obtain the Modbus data frame after the encapsulation is completed. The Modbus data frame will be sent to the corresponding Modbus slave station through the transceiver. After the Modbus slave station responds, the communication manager will analyze the response information to process the flag. At the same time, the communication manager will unlock the scheduler, and the scheduler will re-schedule the nodes in the priority linked list and perform the next message interaction with the Modbus slave station. The successfully sent data node will be re-inserted at the end of its corresponding priority linked list and become the sleep state at the same time, until the sleep time is 0, it will resume the Ready state and wait to be re-scheduled.

[0047] The above is the method embodiment proposed by the present application. Based on the same idea, some embodiments of the present application also provide the devices and non-volatile computer storage media corresponding to the above method.

[0048] Figure 6 It is a schematic structural diagram of a master station communication device based on the Modbus-RTU protocol provided by the embodiment of the present application. As Figure 6 shown, it includes: At least one processor; and, A memory communicatively connected to at least one processor; wherein, The memory stores instructions that can be executed by at least one processor. The instructions are executed by at least one processor, enabling the at least one processor to execute a master station communication method based on the Modbus-RTU protocol as described in any one of the above.

[0049] Embodiments of the present application provide a non-volatile computer storage medium storing computer-executable instructions, and the computer-executable instructions are configured as: A master station communication method based on the Modbus-RTU protocol as described in any one of the above.

[0050] The various embodiments in the present application are described in a progressive manner. For the same or similar parts among the various embodiments, reference can be made to each other. Each embodiment focuses on the differences from other embodiments. In particular, for the device and medium embodiments, since they are basically similar to the method embodiments, the description is relatively simple, and for the relevant parts, reference can be made to the partial description of the method embodiments.

[0051] The devices and media provided by the embodiments of the present application correspond one-to-one with the methods. Therefore, the devices and media also have beneficial technical effects similar to those of their corresponding methods. Since the beneficial technical effects of the methods have been described in detail above, the beneficial technical effects of the devices and media will not be elaborated here.

[0052] Those skilled in the art should understand that the embodiments of the present application can be provided as methods, systems, or computer program products. Therefore, the present application can take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware aspects. Moreover, the present application can take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk memories, CD-ROMs, optical memories, etc.) containing computer-usable program code.

[0053] The present application is described with reference to the flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each flow and / or block in the flowcharts and / or block diagrams, as well as the combination of flows and / or blocks in the flowcharts and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to the processors of general-purpose computers, special-purpose computers, embedded processors, or other programmable data processing devices to generate a machine, such that the instructions executed by the processors of the computer or other programmable data processing devices generate means for implementing the functions specified in Figure 1 one flow or multiple flows and / or blocks Figure 1 one block or multiple blocks.

[0054] These computer program instructions can also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to operate in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including an instruction means that implements the functions specified in one or more of the processes Figure 1 one or more of the processes and / or blocks Figure 1 specified in one or more of the blocks or blocks.

[0055] These computer program instructions can also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer-implemented process, so that the instructions executed on the computer or other programmable apparatus provide steps for implementing the functions specified in one or more of the processes Figure 1 one or more of the processes and / or blocks Figure 1 specified in one or more of the blocks or blocks.

[0056] In a typical configuration, a computing device includes one or more processors (CPUs), an input / output interface, a network interface, and memory.

[0057] Memory may include non-permanent memory in the form of computer-readable media, random access memory (RAM) and / or non-volatile memory such as read-only memory (ROM) or flash RAM. Memory is an example of computer-readable media.

[0058] Computer-readable media includes both permanent and non-permanent, removable and non-removable media implemented by any method or technology for storing information. The information can be computer-readable instructions, data structures, program modules, or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, compact disc read-only memory (CD-ROM), digital versatile discs (DVD) or other optical storage, magnetic cassettes, magnetic tape magnetic disk storage or other magnetic storage devices, or any other non-transitory media that can be used to store information accessible by a computing device. As defined herein, computer-readable media does not include transitory media such as modulated data signals and carrier waves.

[0059] It should also be noted that the term "comprising", "including" or any other variant thereof is intended to cover non-exclusive inclusion, such that a process, method, commodity or device comprising a series of elements not only includes those elements but also includes other elements not expressly listed, or further includes elements inherent to such process, method, commodity or device. Without further limitation, an element defined by the phrase "comprising an..." does not exclude the presence of additional identical elements in the process, method, commodity or device comprising said element.

[0060] The above description is only for the embodiments of the present application and is not intended to limit the present application. For those skilled in the art, various changes and modifications can be made to the present application. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application shall be included within the scope of the claims of the present application.

Claims

1. A master station communication method based on the Modbus-RTU protocol, characterized in that, Applied to a Modbus-RTU master station, the method includes: Generating communication data to be sent to a Modbus slave station through a data generation module; wherein, the communication data includes data sent to the Modbus slave station and the data address corresponding to the data; Filling the communication data into a newly added data node, and hanging the newly added data node after a header node or a data node corresponding to the priority according to the communication importance level corresponding to the communication data, so as to obtain a priority linked list; wherein, the priority linked list refers to a linked list group composed of multiple linked lists corresponding to different priorities; Modifying the node attributes in the priority linked list through a traverser, so as to perform a switching operation on the node state or adjust the priority linked list when the modified node attributes meet a preset condition; Sequentially searching the priority linked list through a scheduler according to the priorities of the priority linked list from high to low, so as to submit the data node in the priority linked list that is in a ready state and has the highest priority to a communication manager; Parsing the data node through the communication manager, encapsulating a communication message through the node attributes obtained by parsing to obtain a Modbus data frame, and controlling a transceiver to send the Modbus data frame to the Modbus slave station to implement communication with the Modbus slave station.

2. The master station communication method based on the Modbus-RTU protocol according to claim 1, wherein, Filling the communication data into a newly added data node, and hanging the newly added data node after a header node or a data node corresponding to the priority according to the communication importance level corresponding to the communication data, so as to obtain a priority linked list, specifically including: Determining a corresponding communication priority type according to the communication importance level corresponding to the communication data; wherein, the communication priority types include, in order from high to low communication priority: starvation priority, forced polling / non-polling priority, limited node priority, and general polling priority; Selecting a header node whose corresponding priority matches the communication priority type, and hanging the newly added data node after the header node or the data node of the priority linked list where the header node is located to obtain a hung priority linked list.

3. The master station communication method based on the Modbus-RTU protocol according to claim 1, wherein The node attributes include a sleep time. Modifying the node attributes in the priority linked list through a traverser, so as to perform a switching operation on the node state when the modified node attributes meet a preset condition, specifically including: Traversing all the data nodes in the priority linked list through a traverser; For the infinite-life cycle nodes in the sleep state among all the data nodes, modifying the sleep time of the infinite-life cycle nodes so as to shorten the sleep time through the call period of the traverser; wherein, the infinite-life cycle node refers to a data node that is periodically scheduled and enters the sleep state after being scheduled; Repeating the modification operation until the sleep time meets the preset condition, and switching the infinite-life cycle node from the sleep state to the ready state.

4. A master station communication method based on the Modbus-RTU protocol according to claim 1, characterized in that, Submitting the data node in the priority linked list that is in a ready state and has the highest priority to the communication manager, specifically including: Determine the data node in the priority linked list that is in the ready state and has the highest priority; According to the node attributes of the data node, delay the submission of the data node to the communication manager by a preset duration, so that the Modbus slave completes the processing of adjacent Modbus data frames submitted to the communication manager according to the preset duration.

5. A master station communication method based on the Modbus-RTU protocol according to claim 1, characterized in that, After submitting the data node in the priority linked list that is in the ready state and has the highest priority to the communication manager, the method further includes: Adjust the state of the scheduler to the locked state; After sending the Modbus data frame to the Modbus slave, the method further includes: Control the communication manager to enter the waiting for response state and attempt to obtain the response information returned by the Modbus slave; Control the communication manager to perform corresponding response operations according to the response type of the response information.

6. The master station communication method based on the Modbus-RTU protocol according to claim 5, characterized in that, Controlling the communication manager to perform corresponding response operations according to the response type of the response information specifically includes: If the communication manager does not obtain the response information within the preset time period, or the response type corresponding to the response information is an error, adjust the communication manager from the waiting for response state to the idle state, and unlock the scheduler, so that the scheduler continues to schedule the data nodes in the priority linked list; If the response type corresponding to the response information is a successful response, update the buffer according to the response information, adjust the communication manager from the waiting for response state to the idle state, and unlock the scheduler through the communication manager, so that the scheduler continues to schedule the data nodes in the priority linked list.

7. A master station communication method based on the Modbus-RTU protocol according to claim 5, characterized in that, After sending the Modbus data frame to the Modbus slave, the method further includes: Modify the node attributes of the data node corresponding to the Modbus data frame according to the response information; The modification at least includes any one or more of the following: Adjust the data node corresponding to the Modbus data frame to the sleep state, and hang the data node in the sleep state to the end of its corresponding priority linked list, delete or mark for retransmission the data node, mark the data node for retransmission, restore the original priority of the data node.

8. A master station communication method based on the Modbus-RTU protocol according to claim 1, characterized in that Adjust the priority linked list, specifically including: Based on the traverser, for the data nodes in the hungry state among all data nodes, in the case that the data node in the hungry state is not in the priority linked list corresponding to the hungry priority, re-hang the data node in the hungry state from its current priority linked list to the priority linked list corresponding to the hungry priority.

9. A master station communication device based on the Modbus-RTU protocol, characterized in that, The device includes: At least one processor; And a memory communicatively connected to the at least one processor; Wherein, the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor, so that the at least one processor can execute a master station communication method based on the Modbus-RTU protocol according to any one of claims 1-8.

10. A non-volatile computer storage medium storing computer-executable instructions, characterized in that, The computer-executable instructions are set to: A master station communication method based on the Modbus-RTU protocol according to any one of claims 1-8.