CN111181824B - Method for realizing master-slave dual-role node in Modbus RTU network - Google Patents

Method for realizing master-slave dual-role node in Modbus RTU network Download PDF

Info

Publication number
CN111181824B
CN111181824B CN201911417851.5A CN201911417851A CN111181824B CN 111181824 B CN111181824 B CN 111181824B CN 201911417851 A CN201911417851 A CN 201911417851A CN 111181824 B CN111181824 B CN 111181824B
Authority
CN
China
Prior art keywords
master
slave
node
mode
master node
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201911417851.5A
Other languages
Chinese (zh)
Other versions
CN111181824A (en
Inventor
孙宝石
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Datatellit (suzhou) Inc
Original Assignee
Datatellit (suzhou) Inc
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Datatellit (suzhou) Inc filed Critical Datatellit (suzhou) Inc
Priority to CN201911417851.5A priority Critical patent/CN111181824B/en
Publication of CN111181824A publication Critical patent/CN111181824A/en
Application granted granted Critical
Publication of CN111181824B publication Critical patent/CN111181824B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L12/00Data switching networks
    • H04L12/28Data switching networks characterised by path configuration, e.g. LAN [Local Area Networks] or WAN [Wide Area Networks]
    • H04L12/40Bus networks
    • H04L12/40169Flexible bus arrangements
    • H04L12/40176Flexible bus arrangements involving redundancy
    • H04L12/40202Flexible bus arrangements involving redundancy by using a plurality of master stations
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L12/00Data switching networks
    • H04L12/28Data switching networks characterised by path configuration, e.g. LAN [Local Area Networks] or WAN [Wide Area Networks]
    • H04L12/40Bus networks
    • H04L12/407Bus networks with decentralised control
    • H04L12/413Bus networks with decentralised control with random access, e.g. carrier-sense multiple-access with collision detection (CSMA-CD)
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L12/00Data switching networks
    • H04L12/28Data switching networks characterised by path configuration, e.g. LAN [Local Area Networks] or WAN [Wide Area Networks]
    • H04L12/40Bus networks
    • H04L2012/40208Bus networks characterized by the use of a particular bus standard
    • H04L2012/40228Modbus

Abstract

The invention discloses a method for realizing master-slave dual-role nodes in the same Modbus RTU network. The master-slave double-role node only needs one Modbus physical interface, which is used as a slave node and responds to an operation request of a standard master node; meanwhile, the master node is also used as an extension master node to control slave nodes which cannot be controlled or do not need to be controlled by a standard master node in the network. The method avoids physical division of the network, saves a gateway, and has simpler network structure, quicker system deployment and lower cost.

Description

Method for realizing master-slave dual-role node in Modbus RTU network
Technical Field
The invention relates to the field of Modbus, in particular to a method for realizing master-slave dual-role nodes in a Modbus RTU network.
Background
The Modbus communication protocol is widely applied in the field of automation control, and is particularly divided into three communication modes of Modbus ASCII, Modbus RTU and Modbus TCP, wherein the Modbus RTU is the most common in practical application. The Modbus RTU protocol is a serial protocol of master-slave (master/slave) architecture: in a ModBus network, a master node (master) with an address of 0 and a plurality of slave nodes (slave) are included, each slave device has a unique address, and the address value is between 1 and 247. The Modbus RTU is a serial protocol that uses a daisy chain topology and typically uses a 485 interface, so nodes in the Modbus network are in a half-duplex mode of operation, i.e., the nodes cannot send and receive data simultaneously.
The characteristics of the Modbus RTU protocol limit that only one master node exists in one Modbus network; one node is either a master node or a slave node, and the master node and the slave node cannot be used in a mixed mode. In actual work, if a plurality of master nodes are needed or slave nodes from different manufacturers have compatibility problems, a plurality of Modbus networks need to be physically divided and connected through Modbus gateways.
The traditional technology has the following technical problems:
1. essentially all based on physical partitioning of the Modbus network;
2. the node device is a gateway-like technical idea and is characterized in that the node device needs a plurality of physical interfaces and is respectively connected with different Modbus networks;
3. the network structure cannot be simplified, the deployment is troublesome and the cost is high.
Disclosure of Invention
The invention provides a method for realizing master-slave double-role nodes in a Modbus RTU network, wherein the master-slave double-role nodes only need one Modbus physical interface and serve as slave nodes to respond to operation requests of standard master nodes; meanwhile, the master node is also used as an extension master node to control other slave nodes outside the administration range of the standard master node in the network. The method avoids physical division of the network, saves a gateway, and has simpler network structure, quicker system deployment and lower cost. A Modbus node is allowed to have the attributes of a master role and a slave role at the same time, and the master/slave mode and the receiving/sending state are dynamically switched according to the context requirement of the operation. The master-slave double-role nodes only need one Modbus physical interface, and all the Modbus nodes are in the same physical network and adopt unified serial port communication parameters including baud rate, data bits, stop bits, check bits and the like. The master-slave dual-role node can effectively avoid the conflict caused by master/slave mode switching and half-duplex receiving/sending modes. The innovativeness of the method is concentrated on the working mechanism and the collision avoidance algorithm of the master-slave dual-role node, and the communication protocol completely conforms to the Modbus specification and has wide compatibility.
In order to solve the technical problem, the invention provides a method for realizing master-slave dual-role nodes in a Modbus RTU network, which comprises the following steps: the network structure is a standard Modbus RTU serial network, the network comprises a standard Master node (Master), a plurality of (1 to n) standard Slave nodes (Slave) and a Master-Slave dual-role node (specially named Master), and addresses of the Master nodes are assumed to be n +1 when the Master nodes are switched to be Slave node modes; and, the n standard slave nodes are divided into two categories: wherein nodes 1 to m are within the jurisdiction of a standard master node; nodes m +1 to n are not governed by a standard master node, but by Maslave; all the nodes in the Modbus network are in the same physical network, and unified serial port communication parameters are adopted; the Maslave node only needs one Modbus physical interface, serves as a slave node and responds to an operation request of a standard master node, and is equal to nodes 1 to m; and meanwhile, the master node is also used as an extension master node to control the slave nodes m +1 to n outside the administration range of the standard master node in the network.
In one of the two casesIn the embodiment, after a Maslave node is started, loading the model parameters which are stored last time before shutdown from FLASH to complete field recovery; if the operation is the first time, loading default model parameters; then, immediately entering a master node working mode, and finishing the first slave node query, wherein the process comprises switching to the master node mode, switching to a sending mode, and sending an instruction to the slave node under jurisdiction; after the instruction is sent, maslay immediately switches to a receiving mode to wait for the response of the slave node. According to the Modbus standard, the slave node should respond immediately, thus, with a timeout t1(hundred millisecond) is taken as a limit, Maslave receives a response from a node or overtime; if the response is received, corresponding application layer processing is carried out; and simultaneously, the Maslave updates the model parameters, recalculates the collision probability of the master-slave mode, writes the parameters back to the FLASH, and the Maslave node determines whether to switch to the master node mode or the slave node mode according to the model calculation result.
In one embodiment, if switching to the slave mode, the process includes switching to the slave mode, switching to the receive mode, waiting for a standard master node instruction, if at timeout t2When receiving the instruction within the second level, the corresponding application layer processing is carried out, and the sending mode is switched to the sending mode to send the response message to the standard main node, and simultaneously (including t)2After overtime), the Maslave updates the model parameters, recalculates the collision probability of the master-slave mode, writes the parameters back to the FLASH, and the Maslave node determines whether to switch to the master node mode or the slave node mode according to the model calculation result.
In one embodiment, the Maslave real-time operation master-slave role conflict prediction algorithm (P) predicts conflicts which may be generated, and when the conflict occurrence probability (P) is greater than a preset threshold (h), active avoidance is performed, wherein input parameters comprise a parameter set (M) influencing the opportunity of switching to the master node and a parameter set (S) influencing the opportunity of switching to the slave node.
In one embodiment, the master-slave role conflict prediction algorithm calculates the two groups of parameters to obtain the probability of encountering conflict when the master node mode is switched to at the next moment, and if the probability p is greater than a preset threshold (h) of the system, the master node with a higher probability standard sends an instruction, so that the master node mode is switched to the slave node mode to prepare for receiving the standard master node instruction; otherwise, the master switches to the master node mode and sends an instruction to the slave nodes (part or all) under the jurisdiction. The threshold h is a preset parameter (0< ═ h < ═ 1) and represents the tolerance to the collision, and the larger the value of h, the higher the tolerance to the collision. The prediction algorithm of the master-slave role collision probability p can be expressed by the following formula:
p=P(M,S)
wherein the content of the first and second substances,
M=[m1,m2,…,mm]
S=[S1,S2,…,Sn]
in one embodiment, the master-slave role conflict prediction algorithm performs the transformation from M, S to p, and the specific algorithm has various choices, including but not limited to linear formulas, forms of which at least include linear formulas, quadratic functions, high-order functions, and machine learning models, wherein the machine learning models at least include random forests and neural networks; in addition, the master-slave role conflict prediction algorithm supports multi-stage processing, each stage can adopt the enumeration algorithm to process M and S respectively or compositely, and then substitutes an intermediate result into a lower stage.
In one embodiment, the master-slave role conflict prediction algorithm has a two-stage processing function, which is specifically as follows: the first-level transformation respectively calculates the urgency (p) of sending instructions to the subordinate nodes aiming at the parameter set M and the parameter set Sm) Probability (p) of imminent message transmission with standard master nodes);
Where p ism=f1(M),f1A piecewise linear function is used:
Figure BDA0002351639980000041
in the formula, a is a constant (a > -0) and represents the penalty amplitude after exceeding the maximum time interval for sending the instruction to the slave node;
where p iss=f2(S),f2A piecewise linear function is used:
Figure BDA0002351639980000042
b is a constant in the formula (b)>0) represents t2Percentage over time psThe penalty amplitude of (2).
Second stage of conversion will pmAnd psAnd (4) obtaining the conflict probability p through comprehensive operation, wherein the function f adopts a weighted average formula.
p=f(pm,ps)=w1·pm+w2·ps+c
In the formula, c is a compensation constant (-1)<c<1),w1、w2Is a weight constant and satisfies-1<=w1<=0,0<=w2<=1。
Based on the same inventive concept, the present application also provides a computer device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, the processor implementing the steps of any of the methods when executing the program.
Based on the same inventive concept, the present application also provides a computer-readable storage medium, on which a computer program is stored, which, when being executed by a processor, carries out the steps of any of the methods.
Based on the same inventive concept, the present application further provides a processor for executing a program, wherein the program executes to perform any one of the methods.
The invention has the beneficial effects that:
1. the prior art is essentially based on physical segmentation of the Modbus network, the adopted design is also a technical idea similar to a gateway, and the typical characteristic is that a node device needs to be provided with a plurality of physical interfaces and is respectively connected with different Modbus networks. The double-role node designed by the invention only needs one physical interface, and simultaneously works in a master-slave mode, so that the double-role node does not conflict with a standard master node in the same network, and can control other slave nodes outside the jurisdiction range of the standard master node.
2. The invention solves the problem that various slave nodes respectively administrate and take agents in a Modbus network, only one Modbus physical interface is needed for the master-slave double-role nodes, the physical division of the network is avoided, a gateway is saved, the network structure is simpler, the system deployment is quicker, and the cost is saved.
3. The conflict prediction algorithm provided by the invention enables the master-slave dual-role node to effectively avoid the conflict caused by master/slave mode switching and half-duplex receiving/transmitting modes.
4. The innovativeness of the method is concentrated on the working mechanism and the collision avoidance algorithm of the master-slave dual-role node, and the communication protocol completely conforms to the Modbus specification and has wide compatibility.
5. The master-slave dual-role node provided by the invention has the advantages of simple structure, high processing efficiency, low cost and strong practicability, and the middle and low-end microprocessors can support the operation of the master-slave dual-role node.
Drawings
Fig. 1 is a structure diagram of a Modbus network including master-slave dual-role nodes in the method for implementing the master-slave dual-role nodes in a Modbus RTU network according to the present invention.
FIG. 2 is a working flow chart of the master-slave dual-role node in the method for implementing the master-slave dual-role node in the Modbus RTU network according to the present invention.
FIG. 3 is a frame structure diagram of a collision avoidance algorithm of master-slave dual-role nodes in the method for implementing the master-slave dual-role nodes in a Modbus RTU network according to the present invention.
Fig. 4 is an exemplary schematic diagram of a collision avoidance algorithm of a multi-stage master-slave dual-role node in the method for implementing the master-slave dual-role node in a Modbus RTU network according to the present invention.
Detailed Description
The present invention is further described below in conjunction with the following figures and specific examples so that those skilled in the art may better understand the present invention and practice it, but the examples are not intended to limit the present invention.
The invention discloses a method for realizing master-slave dual-role nodes in the same Modbus RTU network. The master-slave double-role node only needs one Modbus physical interface, which is used as a slave node and responds to an operation request of a standard master node; meanwhile, the master node is also used as an extension master node to control slave nodes which cannot be controlled or do not need to be controlled by a standard master node in the network. The method avoids physical division of the network, saves a gateway, and has simpler network structure, quicker system deployment and lower cost.
The invention discloses a method for realizing Master-Slave dual-role nodes in the same Modbus RTU network, wherein a network structure (shown in figure 1) is a standard Modbus RTU serial network (comprising RS485, RS232 and the like), the network comprises a standard Master node (Master), a plurality of (1 to n) standard Slave nodes (Slave) and a Master-Slave dual-role node (specially named Master), and the Master node assumes an address of n +1 when being switched to a Slave node mode. And, the n standard slave nodes are divided into two categories: wherein nodes 1 to m are within the jurisdiction of a standard master node; nodes m +1 to n are not governed by standard master nodes, but by Maslave.
All nodes in the Modbus network are in the same physical network, and unified serial port communication parameters including baud rate, data bits, stop bits, check bits and the like are adopted. The communication protocol completely conforms to the Modbus specification and has wide compatibility.
The Maslave node only needs one Modbus physical interface, serves as a slave node and responds to an operation request of a standard master node, and is equal to nodes 1 to m; and meanwhile, the master node is also used as an extension master node to control the slave nodes m +1 to n outside the administration range of the standard master node in the network. The Maslave node has a simple structure and high processing efficiency, and the operation of the Maslave node can be supported by the middle and low-end microprocessor, such as: STM 8. The workflow of the Maslave node is shown in FIG. 2:
loading the model parameters which are stored last time before shutdown from FLASH after the Maslave node is started, and completing field recovery; if it is the first run, the default model parameters are loaded (see the relevant description in the collision avoidance algorithm for master-slave dual-role nodes). Then, immediately entering a main node working mode to complete the first slave node query, and the process thereof includesSwitching to a master node mode, switching to a sending mode, and sending an instruction to a slave node under charge. After the instruction is sent, maslay immediately switches to a receiving mode to wait for the response of the slave node. According to the Modbus standard, the slave node should respond immediately (in the order of tens of milliseconds), and therefore with a timeout t1(hundreds of milliseconds) limit, Maslave either receives slave response or times out. And if the received response is received, corresponding application layer processing is carried out. At the same time (including t)1After overtime), the Maslave updates the model parameters, recalculates the collision probability of the master-slave mode, writes the parameters back to the FLASH, and the Maslave node determines whether to switch to the master node mode or the slave node mode according to the model calculation result.
If switching to the slave mode, the process includes switching to the slave mode, switching to the receive mode, waiting for a standard master node instruction, if at timeout t2When receiving the instruction within the second level, the corresponding application layer processing is carried out, and the sending mode is switched to the sending mode to send the response message to the standard main node, and simultaneously (including t)2After overtime), the Maslave updates the model parameters, recalculates the collision probability of the master-slave mode, writes the parameters back to the FLASH, and the Maslave node determines whether to switch to the master node mode or the slave node mode according to the model calculation result.
Only when an instruction needs to be sent to the slave node in charge, Maslave needs to switch to the master node mode, and the time for operating in the master node mode each time is short (about hundreds of milliseconds). However, when the master is operating in the master node mode, the master node may send a command to the master exactly, causing a conflict. The Maslave node predicts the possible conflict through a conflict avoidance algorithm, and actively avoids when the probability of conflict occurrence is high. The framework of the collision avoidance algorithm is seen in fig. 3, where the set of parameters (M) affecting the timing of switching to the master node includes, but is not limited to, the parameters listed in table 1, and the set of parameters (S) affecting the timing of switching to the slave node includes, but is not limited to, the parameters listed in table 2.
Figure BDA0002351639980000081
Table 1: parameter set (M) main parameter description for influencing the switching to main node
Figure BDA0002351639980000082
Table 2: parameter set (S) primary parameter specification affecting handover to slave node opportunity
Calculating the two groups of parameters by a master-slave role conflict prediction algorithm (big P) to obtain the probability (small P) of encountering conflict when the master node mode is switched to the master node mode at the next moment, and if the probability P is greater than a preset threshold (h) of the system, indicating that the master node with higher probability can send an instruction, so that the master node mode is switched to the slave node mode to prepare for receiving the instruction of the standard master node; otherwise, the master switches to the master node mode and sends an instruction to the slave nodes (part or all) under the jurisdiction. The threshold h is a preset parameter (0< ═ h < ═ 1) and represents the tolerance to the collision, and the larger the value of h, the higher the tolerance to the collision. The prediction algorithm of the master-slave role collision probability p can be expressed by the following formula:
p=P(M,S)
wherein the content of the first and second substances,
M=[m1,m2,…,mm]
S=[S1,S2,…,Sn]
in the Maslave operation process, the parameter sets M and S change continuously with the time and the messaging events, and the P value obtained by the algorithm P also changes dynamically. In principle, on one hand, the closer to the expected time (S parameter leading) for sending an instruction to the master by the standard master node, the higher the p value; on the other hand, the closer to the maximum interval time for Maslave to send instructions to the governed slave node, the lower the p value tends to be (M parameter is dominant). The purpose of the algorithm P is to keep the balance of the two parties, thereby realizing master-slave dual-role dynamic switching and effectively avoiding the occurrence of conflicts.
The algorithm P completes the transformation from M, S to P, and the specific algorithm has various choices, including but not limited to linear formulas, forms at least including linear formulas, quadratic functions, higher-order functions, and machine learning models at least including random forests and neural networks. In addition, the algorithm P also supports multi-stage processing, and each stage can adopt the enumerated algorithm to process M and S respectively or compositely, and then substitutes an intermediate result into a lower stage. Fig. 4 depicts an example of a two-level calculation of the algorithm P:
in this example algorithm, the first-level transformation calculates the urgency (p) required to issue instructions to the governed slave node for parameter set M and parameter set S, respectivelym) Probability (p) of imminent message transmission with standard master nodes)。
Where p ism=f1(M),f1A piecewise linear function is used:
Figure BDA0002351639980000091
in the formula, a is a constant (a > -0) and represents the penalty amplitude after exceeding the maximum time interval for sending the instruction to the slave node.
Where p iss=f2(S),f2A piecewise linear function is used:
Figure BDA0002351639980000101
b is a constant in the formula (b)>0) represents t2Percentage over time psThe penalty amplitude of (2).
In this example algorithm, the second stage transform will be pmAnd psAnd (4) obtaining the conflict probability p through comprehensive operation, wherein the function f adopts a weighted average formula.
p=f(pm,ps)=w1·pm+w2·ps+c
In the formula, c is a compensation constant (-1)<c<1),w1、w2Is a weight constant and satisfies-1<=w1<=0,0<=w2<=1。
The above algorithm example is only one specific example of the collision avoidance algorithm (P) of the master-slave dual-role node, and in practice, the algorithm P can be implemented in various ways, and the method related to the present invention is established as long as the input and output meet the requirements of the algorithm framework shown in fig. 3.
A specific application scenario of the present invention is given below:
take an intelligent classroom as an example of an application scenario:
the intelligent classroom comprises an intelligent control center, a lighting system, an air conditioner, fresh air, an electric curtain, a fan, an electronic blackboard, various sensors (such as a temperature sensor, a humidity sensor, a human body sensor, a light sensor, a PM2.5 sensor and the like), an electric meter and the like. Wherein, intelligent control center is the core server in wisdom classroom, mainly provides teaching relevant control service (as teachers and students sign in, multi-screen interaction, classroom evaluation etc.), and equipment control function is relatively weak, can only carry out the management and control to some equipment like electronic blackboard, attendance machine equipment etc. can't accomplish through acting as an agent, for example to other equipment direct management and control: controlling air conditioning, fresh air, electric curtains, sensor readings, electricity meter readings, etc.
The intelligent classroom teaching room is characterized in that the devices are connected through a Modbus network, the intelligent control center is a standard Master node (Master), and is directly communicated with devices such as Master-slave dual-role nodes (Master) and electronic blackboards, and the Master-slave dual-role nodes (Master) are used as agents for managing and controlling other Modbus node devices. The master-slave double-role node only needs one Modbus physical interface, physical division of a network is avoided, a gateway is omitted, the network structure is simpler, system deployment is quicker, and cost is saved.
The key technology of the invention is as follows:
the invention discloses a method for realizing master-slave dual-role nodes (Maslave) in a Modbus RTU network, which allows one Modbus node to have master and slave role attributes simultaneously and dynamically switch a master/slave mode and a receiving/transmitting state according to the context requirement during operation.
The Modbus RTU master-slave dual-role nodes (Maslave) only need one Modbus physical interface, all the Modbus nodes are in the same physical network, unified serial port communication parameters including baud rate, data bits, stop bits, check bits and the like are adopted, and any physical isolation is not needed.
The invention completely conforms to Modbus RTU communication specifications and has wide compatibility. The Maslave node provided by the invention has a simple structure and high processing efficiency, and the middle and low-end microprocessors can support the operation of the Maslave node.
Loading the model parameters which are stored for the last time before shutdown from FLASH after a master-slave dual-role node (Maslave) of the Modbus RTU is started, and completing field recovery; if it is the first run, the default model parameters are loaded. The mask continuously updates the model parameters in the running process and writes the parameters back into the FLASH.
The Master-slave role conflict prediction algorithm (P) is used for carrying out real-time operation, predicting possible conflicts and determining whether to switch to a master node mode or a slave node mode.
After the Maslave is started, the master node mode is firstly entered, and an instruction is sent to the slave node under the jurisdiction. In the master node mode, t is set by a parameter1Timeout (in the order of hundred milliseconds). Slave node response or trigger t received by Master1And if the time is out, the updating and operation process of the master-slave role conflict prediction algorithm (P) is entered.
In slave node mode, t is set by a parameter2Timeout (seconds). Master completes communication with standard main node or triggers t2And if the time is out, the updating and operation process of the master-slave role conflict prediction algorithm (P) is entered.
Master real-time operation master-slave role conflict prediction algorithm (P) predicts possible conflicts, and when the conflict occurrence probability (P) is larger than a preset threshold (h), active avoidance is carried out. Characterized in that the input parameters comprise a set of parameters (M) affecting the timing of the switch-over to the master node and a set of parameters (S) affecting the timing of the switch-over to the slave node.
Parameter sets (M) include, but are not limited to, parameters: minimum interval time (m) for sending an instruction to a slave node1) Maximum interval time (m) for sending an instruction to a slave node2) Time (m) elapsed since the last transmission of an instruction to a slave node3) And the like.
Parameter sets (S) include, but are not limited to, parameters: average time interval(s) for a standard master node to send an instruction1) Standard deviation(s) of mean time of transmission of instructions by standard master node2) The time(s) elapsed since the last receipt of a standard master node command3)、t2Percentage timeout(s)4) And the like.
The preset threshold h (0< ═ h < ═ 1) represents the tolerance to collision, and the larger the value of h, the higher the tolerance to collision.
The master-slave role conflict prediction algorithm P completes the transformation from M, S to P, and the specific algorithm has various choices, including but not limited to linear formulas, forms at least including linear formulas, quadratic functions and high-order functions, and machine learning models at least including random forests and neural networks. And the algorithm P also supports multi-stage processing, each stage can adopt the enumeration algorithm to process M and S respectively or compositely, and then substitutes an intermediate result into a lower stage.
The algorithm, the invention provides an example of a two-stage calculation, characterized by a first stage of transformation f1(M) and f2(S) calculating the urgency (p) required to instruct the slave node in charge for parameter set M and parameter set S, respectivelym) Probability (p) of imminent message transmission with standard master nodes),f1(M) and f2(S) using a piecewise linear function with penalty coefficients (a and b). Second stage of conversion will pmAnd psThe collision probability p is obtained by a comprehensive operation, and the function f adopts a weighted average formula with a compensation constant (c).
The algorithm example is only one specific example of the collision avoidance algorithm (P) of the master-slave dual-role node, and in practice, the algorithm P can be implemented in various ways, as long as the input and output conform to the algorithm framework described in claim 12, the method according to the present invention is true, and any modification, equivalent replacement, improvement, etc. made should be included in the protection scope of the present invention.
The above-mentioned embodiments are merely preferred embodiments for fully illustrating the present invention, and the scope of the present invention is not limited thereto. The equivalent substitution or change made by the technical personnel in the technical field on the basis of the invention is all within the protection scope of the invention. The protection scope of the invention is subject to the claims.

Claims (7)

1. A method for realizing master-slave dual-role nodes in a Modbus RTU network is characterized by comprising the following steps: the network structure is a standard Modbus RTU serial network, the network comprises a standard Master node Master, standard Slave nodes Slave from 1 to n and a Master-Slave dual-role node Master, and the address of the Master node is assumed to be n +1 when the Master node is switched to the Slave node mode; and, the n standard slave nodes are divided into two categories: wherein nodes 1 to m are within the jurisdiction of a standard master node; nodes m +1 to n are not governed by a standard master node, but by Maslave; all the nodes in the Modbus network are in the same physical network, and unified serial port communication parameters are adopted; the Maslave node only needs one Modbus physical interface, serves as a slave node and responds to an operation request of a standard master node, and is equal to nodes 1 to m; meanwhile, the master node is also used as an extension master node to control slave nodes m +1 to n outside the jurisdiction range of a standard master node in the network;
loading the model parameters which are stored last time before shutdown from FLASH after the Maslave node is started, and completing field recovery; if the operation is the first time, loading default model parameters; then, immediately entering a master node working mode, and finishing the first slave node query, wherein the process comprises switching to the master node mode, switching to a sending mode, and sending an instruction to the slave node under jurisdiction; after the instruction is sent, maslay immediately switches to a receiving mode to wait for the response of the slave node; according to the Modbus standard, the slave node should respond immediately, thus, with a timeout t1If the master node is in the limit, the master node receives a response from the slave node or overtime; if the response is received, corresponding application layer processing is carried out; meanwhile, the Maslave updates model parameters, recalculates the collision probability of the master-slave mode, writes the parameters back to the FLASH, and the Maslave node determines whether to switch to the master node mode or the slave node mode according to the model calculation result;
the master-slave role conflict prediction algorithm P is operated in real time by the master, possible conflicts are predicted, when the conflict occurrence probability P is larger than a preset threshold h, the slave node mode is switched, and input parameters comprise a parameter set M influencing the opportunity of switching to the master node and a parameter set S influencing the opportunity of switching to the slave node.
2. A method as claimed in claim 1, wherein if switching to slave mode, the process includes switching to slave mode, switching to receive mode, waiting for standard master node commands, if at timeout t2And if receiving the instruction, performing corresponding application layer processing, switching to a sending mode to send a response message to the standard master node, updating model parameters by the Maslave, recalculating the collision probability of the master-slave mode, writing the parameters back to the FLASH, and determining whether to switch to the master node mode or the slave node mode by the Maslave according to the model calculation result.
3. The method for realizing master-slave dual-role nodes in a Modbus RTU network according to claim 1, wherein the master-slave role conflict prediction algorithm calculates the two sets of parameters to obtain the probability of encountering conflict if the master mode is switched to the master node mode at the next moment, and if the probability p is greater than a preset threshold h of the system, the master node with higher probability sends an instruction, so that the master mode is switched to the slave node mode to prepare for receiving the instruction of the standard master node; otherwise, switching the master to the master node mode, and sending an instruction to the slave node under jurisdiction; the threshold h is a preset parameter, 0< = h < = 1 and represents the tolerance to the conflict, and the larger the h value is, the higher the tolerance to the conflict is; the prediction algorithm of the master-slave role collision probability p can be expressed by the following formula:
p = P(M, S)
wherein the content of the first and second substances,
M = [m1, m2, …, mm]
S = [S1, S2, …, Sn]。
4. as claimed in claimThe method for realizing the master-slave dual-role node in the Modbus RTU network is characterized in that a master-slave role conflict prediction algorithm has two-stage processing functions, and specifically comprises the following steps: the first-stage transformation respectively calculates the urgency degree p required to send instructions to the subordinate nodes aiming at the parameter set M and the parameter set SmProbability p of imminent message transmission with standard master nodes
Where p ism = f1(M),f1A piecewise linear function is used:
Figure 965557DEST_PATH_IMAGE001
a in the formula is a constant, wherein a > = 0, and represents the penalty amplitude after exceeding the maximum time interval for sending the instruction to the slave node;
where p iss= f2(S),f2A piecewise linear function is used:
Figure 820381DEST_PATH_IMAGE002
b is a constant in the formula, b>= 0, representing t2Percentage over time psThe penalty amplitude of (d);
second stage of conversion will pmAnd psThe collision probability p is obtained by comprehensive operation, and the function f adopts a weighted average formula:
Figure 537801DEST_PATH_IMAGE003
in the formula, c is a compensation constant, -1< c < 1,w1、w2Is a weight constant and satisfies-1<= w1 <= 0,0 <= w2<= 1。
5. A computer device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, characterized in that the steps of the method of any of claims 1 to 4 are implemented when the program is executed by the processor.
6. A computer-readable storage medium, on which a computer program is stored which, when being executed by a processor, carries out the steps of the method of any one of claims 1 to 4.
7. A processor, characterized in that the processor is configured to run a program, wherein the program when running performs the method of any of claims 1 to 4.
CN201911417851.5A 2019-12-31 2019-12-31 Method for realizing master-slave dual-role node in Modbus RTU network Active CN111181824B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201911417851.5A CN111181824B (en) 2019-12-31 2019-12-31 Method for realizing master-slave dual-role node in Modbus RTU network

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201911417851.5A CN111181824B (en) 2019-12-31 2019-12-31 Method for realizing master-slave dual-role node in Modbus RTU network

Publications (2)

Publication Number Publication Date
CN111181824A CN111181824A (en) 2020-05-19
CN111181824B true CN111181824B (en) 2021-10-12

Family

ID=70623467

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201911417851.5A Active CN111181824B (en) 2019-12-31 2019-12-31 Method for realizing master-slave dual-role node in Modbus RTU network

Country Status (1)

Country Link
CN (1) CN111181824B (en)

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102385351A (en) * 2010-09-03 2012-03-21 上海电器科学研究院 Configurable remote input/output (IO) controller host
CN102722535A (en) * 2012-05-21 2012-10-10 周明 Method for avoiding modbus real-time database access conflict
CN105978896A (en) * 2016-06-24 2016-09-28 天津瑞能电气有限公司 Communication device for converting industry Ethernet slave station into Modbus master station
CN107948059A (en) * 2017-12-21 2018-04-20 中国电子信息产业集团有限公司第六研究所 EtherCAT and Modbus protocol conversion gateways based on SPARC architecture microprocessors
CN108737590A (en) * 2018-05-15 2018-11-02 浙江正泰电器股份有限公司 A kind of method that address is distributed automatically, system, Modbus main websites, Modbus slave stations

Family Cites Families (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6792337B2 (en) * 1994-12-30 2004-09-14 Power Measurement Ltd. Method and system for master slave protocol communication in an intelligent electronic device
DE102012112225B3 (en) * 2012-12-13 2014-01-30 Schneider Electric Automation Gmbh Method for exchanging device-specific data between devices and / or systems of different network systems and bus system for carrying out the method
US9787495B2 (en) * 2014-02-18 2017-10-10 Allegro Microsystems, Llc Signaling between master and slave components using a shared communication node of the master component

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102385351A (en) * 2010-09-03 2012-03-21 上海电器科学研究院 Configurable remote input/output (IO) controller host
CN102722535A (en) * 2012-05-21 2012-10-10 周明 Method for avoiding modbus real-time database access conflict
CN105978896A (en) * 2016-06-24 2016-09-28 天津瑞能电气有限公司 Communication device for converting industry Ethernet slave station into Modbus master station
CN107948059A (en) * 2017-12-21 2018-04-20 中国电子信息产业集团有限公司第六研究所 EtherCAT and Modbus protocol conversion gateways based on SPARC architecture microprocessors
CN108737590A (en) * 2018-05-15 2018-11-02 浙江正泰电器股份有限公司 A kind of method that address is distributed automatically, system, Modbus main websites, Modbus slave stations

Also Published As

Publication number Publication date
CN111181824A (en) 2020-05-19

Similar Documents

Publication Publication Date Title
CN113835344B (en) Control optimization method of equipment, display platform, cloud server and storage medium
CN111322719B (en) Building heating ventilation air-conditioning control system and method and wireless Mesh communication equipment
CN105847438A (en) Event trigger based multi-agent consistency control method
CN103294019B (en) Building automation and control system and the method for operating this system
Lissa et al. Transfer learning applied to reinforcement learning-based hvac control
CN108880909B (en) Network energy saving method and device based on reinforcement learning
CN111830842A (en) Intelligent household non-inductive control system
CN111181824B (en) Method for realizing master-slave dual-role node in Modbus RTU network
CN113028599B (en) Heating ventilation air conditioner monitoring system and method based on cloud platform
CN112579053A (en) Design architecture of ultra-light embedded internet of things rule engine
Althoff et al. An architecture for real-time control in multi-robot systems
CN111695194A (en) Embedded hardware-based unmanned helicopter flight control improved PSO algorithm verification method
CN113915741B (en) Instruction sending method, device and system
CN113259246B (en) Method for automatically generating RYU controller flow table under uncertain network environment
CN115235050A (en) Simulation method and device for energy-saving strategy of central air-conditioning water chilling unit
CN113423025B (en) Data management terminal with artificial intelligence
CN115686594A (en) Terminal automatic operation and maintenance management system and method
CN212032429U (en) Teacher control system of flight simulator
CN114526537A (en) Equipment energy-saving control method and device
CN113655764A (en) Cloud edge cooperative control system and control method
CN101197707A (en) Method for updating double standby cabinet management system
CN115128961B (en) Self-triggering model prediction method and system based on LoRaWAN (Long Range network)
Romanov et al. Platform-independent SCADA and IoT Architecture Based on Metadata
CN117707180A (en) Energy-saving event-triggered agent formation control method and system
CN107506021A (en) Blank pipe simulated training cooperative control system and control method

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant