CN116366391A - MODBUS communication method and device based on data list structure - Google Patents
MODBUS communication method and device based on data list structure Download PDFInfo
- Publication number
- CN116366391A CN116366391A CN202310332136.1A CN202310332136A CN116366391A CN 116366391 A CN116366391 A CN 116366391A CN 202310332136 A CN202310332136 A CN 202310332136A CN 116366391 A CN116366391 A CN 116366391A
- Authority
- CN
- China
- Prior art keywords
- parameter
- command
- data
- communication
- host
- 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.)
- Pending
Links
- 230000006854 communication Effects 0.000 title claims abstract description 234
- 238000004891 communication Methods 0.000 title claims abstract description 229
- 238000000034 method Methods 0.000 title claims abstract description 49
- 230000004044 response Effects 0.000 claims abstract description 85
- 238000000605 extraction Methods 0.000 claims abstract description 17
- 238000004806 packaging method and process Methods 0.000 claims abstract description 12
- 230000006870 function Effects 0.000 claims description 31
- 230000015654 memory Effects 0.000 claims description 19
- 230000005540 biological transmission Effects 0.000 claims description 18
- 238000012795 verification Methods 0.000 claims description 6
- 238000012986 modification Methods 0.000 claims description 5
- 230000004048 modification Effects 0.000 claims description 5
- 238000004590 computer program Methods 0.000 claims description 4
- 238000013461 design Methods 0.000 description 20
- 238000010586 diagram Methods 0.000 description 13
- 239000000306 component Substances 0.000 description 12
- 230000008878 coupling Effects 0.000 description 8
- 238000010168 coupling process Methods 0.000 description 8
- 238000005859 coupling reaction Methods 0.000 description 8
- 238000012545 processing Methods 0.000 description 4
- 230000007547 defect Effects 0.000 description 3
- 230000009286 beneficial effect Effects 0.000 description 2
- 238000004422 calculation algorithm Methods 0.000 description 2
- 238000000151 deposition Methods 0.000 description 2
- 230000007246 mechanism Effects 0.000 description 2
- 239000000203 mixture Substances 0.000 description 2
- 230000003287 optical effect Effects 0.000 description 2
- 238000013515 script Methods 0.000 description 2
- 238000006467 substitution reaction Methods 0.000 description 2
- 238000002054 transplantation Methods 0.000 description 2
- 238000012356 Product development Methods 0.000 description 1
- 230000002411 adverse Effects 0.000 description 1
- 239000008358 core component Substances 0.000 description 1
- 230000001419 dependent effect Effects 0.000 description 1
- 238000005516 engineering process Methods 0.000 description 1
- 239000000284 extract Substances 0.000 description 1
- 238000012423 maintenance Methods 0.000 description 1
- 230000008569 process Effects 0.000 description 1
- 230000002035 prolonged effect Effects 0.000 description 1
- 230000002441 reversible effect Effects 0.000 description 1
- 238000012163 sequencing technique Methods 0.000 description 1
- 230000036964 tight binding Effects 0.000 description 1
Images
Classifications
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L12/00—Data switching networks
- H04L12/28—Data switching networks characterised by path configuration, e.g. LAN [Local Area Networks] or WAN [Wide Area Networks]
- H04L12/40—Bus networks
- H04L12/40169—Flexible bus arrangements
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F8/00—Arrangements for software engineering
- G06F8/10—Requirements analysis; Specification techniques
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F8/00—Arrangements for software engineering
- G06F8/20—Software design
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F8/00—Arrangements for software engineering
- G06F8/40—Transformation of program code
- G06F8/41—Compilation
- G06F8/45—Exploiting coarse grain parallelism in compilation, i.e. parallelism between groups of instructions
- G06F8/457—Communication
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F8/00—Arrangements for software engineering
- G06F8/70—Software maintenance or management
- G06F8/75—Structural analysis for program understanding
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F8/00—Arrangements for software engineering
- G06F8/70—Software maintenance or management
- G06F8/76—Adapting program code to run in a different environment; Porting
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L69/00—Network arrangements, protocols or services independent of the application payload and not provided for in the other groups of this subclass
- H04L69/03—Protocol definition or specification
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L69/00—Network arrangements, protocols or services independent of the application payload and not provided for in the other groups of this subclass
- H04L69/12—Protocol engines
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L69/00—Network arrangements, protocols or services independent of the application payload and not provided for in the other groups of this subclass
- H04L69/30—Definitions, standards or architectural aspects of layered protocol stacks
- H04L69/32—Architecture of open systems interconnection [OSI] 7-layer type protocol stacks, e.g. the interfaces between the data link level and the physical level
- H04L69/322—Intralayer communication protocols among peer entities or protocol data unit [PDU] definitions
- H04L69/329—Intralayer communication protocols among peer entities or protocol data unit [PDU] definitions in the application layer [OSI layer 7]
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L12/00—Data switching networks
- H04L12/28—Data switching networks characterised by path configuration, e.g. LAN [Local Area Networks] or WAN [Wide Area Networks]
- H04L12/40—Bus networks
- H04L2012/40208—Bus networks characterized by the use of a particular bus standard
- H04L2012/40228—Modbus
-
- Y—GENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
- Y02—TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
- Y02P—CLIMATE CHANGE MITIGATION TECHNOLOGIES IN THE PRODUCTION OR PROCESSING OF GOODS
- Y02P90/00—Enabling technologies with a potential contribution to greenhouse gas [GHG] emissions mitigation
- Y02P90/02—Total factory control, e.g. smart factories, flexible manufacturing systems [FMS] or integrated manufacturing systems [IMS]
Landscapes
- Engineering & Computer Science (AREA)
- General Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Software Systems (AREA)
- Physics & Mathematics (AREA)
- General Physics & Mathematics (AREA)
- Computer Networks & Wireless Communication (AREA)
- Signal Processing (AREA)
- Computer Security & Cryptography (AREA)
- Communication Control (AREA)
Abstract
The application provides a MODBUS communication method and device based on a data list structure body, electronic equipment and a storage medium, wherein the method comprises the following steps: responding to the command storage request, and sequentially placing at least one command into a linked list buffer through a target interface; extracting a target command from at least one command in response to the command extraction request; traversing from a preset data list structure body based on the target command to obtain a first communication parameter matched with the target command, and packaging the first communication parameter to obtain a host command; the master command is sent to the slave so that the slave responds to the master command based on the data list structure. The method and the device can enable the communication protocol and the communication parameter variable to be independent and thoroughly unhook and decouple.
Description
Technical Field
The present disclosure relates to the field of communications technologies, and in particular, to a MODBUS communication method and device based on a data list structure, an electronic device, and a storage medium.
Background
MODBUS communication is an application layer message transport protocol on layer 7 of the OSI model, which is applied to buses or networks of different types to provide communication services between devices; the method uses the data variable address as a reference, and uses the number of access parameters or parameter values as data units for transmission.
The vast majority of MODBUS communication software design ideas at present are that a communication protocol and a communication parameter variable are deeply bound, the communication parameter variable is directly nested in the communication protocol, no matter data transmission or data reception is carried out, the communication protocol and the communication parameter variable are always kneaded into a whole, so that the binding between the MODBUS communication protocol and the communication parameter variable is too tight, the dependency relationship is too complex, and once the attribute (such as a register address, a read-write access authority, a parameter value range and the like) of the communication parameter variable is changed, the MODBUS communication protocol part is correspondingly modified. Meanwhile, in the existing MODBUS communication software design process, if the addresses of the communication parameter variable registers are discontinuous, the communication software design generally distributes the sending and analyzing functions of the communication parameter variable into different code segments according to the number of the segmented segments of the addresses of the communication parameter variable registers to finish implementation, and the MODBUS protocol has a plurality of communication commands, so that the more the number of the commands is, the more the segmented processing of the software codes is, and thus a plurality of adverse factors such as more occupied resources are caused.
In addition, in the MODBUS communication process, besides sending a query command to the slave, the host generally needs to send some setting parameters to the slave, when the host sets parameters to the slave, the whole communication state and steps are unknown, or the host is sending other commands to the slave, or the host is waiting for the reply of the slave, or the slave is replying information to the host, etc., so many MODBUS communication mechanism software designs currently, or the situation is not considered, thereby causing collision damage to data on a communication transmission line, causing sudden increase of communication failure rate and increasing the unreliability of communication; or adopts a complex multiple state machine to switch the design mode, thereby increasing the complexity of software.
In summary, the current MODBUS communication software design mode causes that the coupling and the relevance of the software code are too strong, the readability is poor, the maintenance and the upgrading of the software are inconvenient, the transplantation of the MODBUS communication protocol software designed in the past is too complicated, the multiplexing rate is too low, if the transplantation is improper, new errors are easy to generate, almost the product communication protocol needs are changed, the MODBUS communication protocol needs to be rewritten once, the workload of a product developer is increased, and the product development period is prolonged.
Disclosure of Invention
In view of this, the embodiments of the present application provide a method, an apparatus, an electronic device, and a storage medium for MODBUS communication based on a data list structure, which can enable a communication protocol and a communication parameter variable to be independent and thoroughly unhook and decouple.
The technical scheme of the embodiment of the application is realized as follows:
in a first aspect, an embodiment of the present application provides a MODBUS communication method based on a data list structure, which is applied to a host, and includes the following steps:
responding to the command storage request, and sequentially placing at least one command into a linked list buffer through a target interface;
extracting a target command from the at least one command in response to a command extraction request;
traversing from a preset data list structure body based on the target command to obtain a first communication parameter matched with the target command, and packaging the first communication parameter to obtain a host command;
and sending the host command to a slave so that the slave responds to the host command based on the data list structure.
In one possible embodiment, the data list structure includes the following members:
Bit number of parameter variable, parameter storage pointer, parameter register address, parameter access authority, whether parameter is modified flag bit, parameter variable value compliance judging callback function, parameter index number, data list type and data list name;
the bit number of the parameter variable is used for identifying the bit number of the communication parameter variable in the memory;
the parameter storage pointer is used for pointing to the storage address of the communication parameter variable;
the parameter register address is a register address value allocated to the communication parameter variable in MODBUS communication protocol transmission;
the parameter access authority comprises three types of read-only, write-only and read-write;
whether the parameter is modified or not is used for marking when the parameter value is changed;
the parameter variable value compliance judgment callback function is used for judging the limit value range of the set parameter;
the parameter index number is used for carrying out limit value judgment and modification on the corresponding communication parameter according to the index number in cooperation with the parameter variable value compliance judgment callback function;
the data list type is a container type for storing bit numbers of parameter variables, parameter storage pointers, parameter register addresses, parameter access rights, whether parameters are modified flag bits, parameter variable value compliance judging callback functions and parameter index numbers;
The name of the data list is the number of bits for storing parameter variables, a parameter storage pointer, a parameter register address, parameter access permission, whether the parameters are modified flag bits, a parameter variable value compliance judging callback function and the container name of a parameter index number.
In one possible implementation manner, the linked list buffer is a FIFO linked list buffer, and the responding to the command depositing request sequentially places at least one command into the linked list buffer through the target interface includes:
detecting the empty and full states of the FIFO linked list buffer in response to a command storage request; when the FIFO linked list buffer is not full, sequentially placing at least one command into the linked list buffer through a target interface;
and stopping putting when the FIFO linked list buffer is full.
In one possible implementation manner, the linked list buffer is a FIFO linked list buffer, and the extracting, in response to a command extraction request, a target command from the at least one command includes:
the response command extraction request detects the empty and full states of the FIFO linked list buffer;
when the FIFO linked list buffer is not empty, the target command is fetched from the FIFO linked list buffer according to the first-in first-out sequence;
And stopping taking out when the FIFO linked list buffer is empty.
In a second aspect, the present application further provides a MODBUS communication method based on a data list structure, which is applied to a slave, and includes the following steps:
responding to a host command sent by a host, analyzing the host command to obtain first analysis data, and checking CRC16 of the first analysis data;
after the CRC16 of the first analysis data is checked to be correct, traversing from a preset data list structure body according to the first analysis data to obtain second communication parameters matched with the first analysis data, and packaging the second communication parameters to obtain first response data;
and verifying the first response data, and when the verification result of the first response data is normal, sending the first response data to the host, so that the host responds to the first response data based on the data list structure body.
In a third aspect, an embodiment of the present application further provides a MODBUS communication method based on a data list structure, which is applied to a host, and includes the following steps:
responding to first response data sent by a slave, analyzing the first response data to obtain second analysis data, and checking CRC16 of the second analysis data;
And traversing from a preset data list structure body according to the second analysis data after the CRC16 of the second analysis data is checked, obtaining a third communication parameter matched with the second analysis data, and packaging the third communication parameter to obtain second response data.
In a fourth aspect, an embodiment of the present application further provides a MODBUS communication device based on a data list structure, where the device includes:
the first response module is used for responding to the command storage request and sequentially placing at least one command into the linked list buffer through the target interface;
the second response module is used for responding to the command extraction request and extracting a target command from the at least one command;
the first traversal packaging module is used for traversing from a preset data list structure body based on the target command to obtain a first communication parameter matched with the target command, and packaging the first communication parameter to obtain a host command;
and the first sending module is used for sending the host command to the slave so that the slave responds to the host command based on the data list structure body.
In a fifth aspect, an embodiment of the present application further provides a MODBUS communication device based on a data list structure, where the device includes:
The third response module is used for responding to a host command sent by a host, analyzing the host command to obtain first analysis data and checking CRC16 of the first analysis data;
the second traversal packet-grouping module is used for traversing from a preset data list structure body according to the first analysis data after the CRC16 of the first analysis data is checked to be correct, obtaining second communication parameters matched with the first analysis data, and grouping the second communication parameters to obtain first response data;
and the second sending module is used for verifying the first response data, and sending the first response data to the host when the verification result of the first response data is normal, so that the host responds to the first response data based on the data list structure body.
In a sixth aspect, embodiments of the present application further provide an electronic device, including: a processor, a storage medium, and a bus, the storage medium storing machine-readable instructions executable by the processor, the processor and the storage medium communicating over the bus when the electronic device is running, the processor executing the machine-readable instructions to perform the data list structure-based MODBUS communication method of any one of the first aspect, or to perform the data list structure-based MODBUS communication method of any one of the second aspect, or to perform the data list structure-based MODBUS communication method of any one of the third aspect.
In a fourth aspect, an embodiment of the present application further provides a computer readable storage medium, where a computer program is stored, where the computer program when executed by a processor performs the MODBUS communication method based on a data list structure according to any one of the first aspect, or performs the MODBUS communication method based on a data list structure according to any one of the second aspect, or performs the MODBUS communication method based on a data list structure according to any one of the third aspect.
The embodiment of the application has the following beneficial effects:
aiming at the defects and shortcomings of the prior art, a brand new design thought of a data list structure body is adopted, all communication parameter variables are listed in the structure body in a data list form, a data list set is constructed, the communication protocol and the communication parameter variables are independent, decoupling is thoroughly carried out, the problems that the binding between the MODBUS communication protocol and the communication parameter variables is too tight and the dependency relationship is too complex are solved to a great extent, the coupling and the relevance of software codes are weakened to a great extent, the readability and the portability of the software are enhanced, and the multiplexing price value of the software is improved. Meanwhile, a FIFO (first in first out) linked list buffer design mode is adopted for commands issued by a host in a MODBUS communication protocol, when the host needs to issue commands to a slave, the commands are sequentially placed into the FIFO linked list buffer one by one, then the host sequentially takes out from the FIFO linked list buffer, and when a communication bus is idle, the commands stored in the FIFO linked list buffer are preferentially issued to the slave, so that collision damage caused by data on a communication transmission line is avoided, and the stability, reliability and instantaneity of communication are improved; in communication management, complicated multiple 'state machine' switching design modes are abandoned, software design flow is simplified, and the regularity and readability of software are enhanced.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings that are needed in the embodiments will be briefly described below, it being understood that the following drawings only illustrate some embodiments of the present application and therefore should not be considered limiting the scope, and that other related drawings may be obtained according to these drawings without inventive effort for a person skilled in the art.
Fig. 1 is a schematic flow chart of steps S101-S104 provided in the embodiment of the present application;
fig. 2 is a schematic flow chart of steps S201 to S203 provided in the embodiment of the present application;
fig. 3 is a schematic flow chart of steps S301 to S302 provided in the embodiment of the present application;
FIG. 4 is a flow chart of a host protocol stack send command provided in an embodiment of the present application;
FIG. 5 is a control flow diagram of a host command FIFO linked list buffer provided in an embodiment of the present application;
FIG. 6 is a schematic diagram of a MODBUS communication protocol stack component of a data list structure provided in an embodiment of the present application;
FIG. 7 is an exemplary diagram of a data list structure provided by an embodiment of the present application;
FIG. 8 is a flow chart of a slave protocol stack responding to a master command provided in an embodiment of the present application;
FIG. 9 is a flow chart of a host protocol stack parsing slave response provided in an embodiment of the present application;
Fig. 10 is a schematic structural diagram of a MODBUS communication device based on a data list structure according to an embodiment of the present application;
fig. 11 is a schematic structural diagram of another MODBUS communication device based on a data list structure according to an embodiment of the present application;
fig. 12 is a schematic diagram of a composition structure of an electronic device according to an embodiment of the present application.
Detailed Description
For the purpose of making the objects, technical solutions and advantages of the embodiments of the present application more clear, the technical solutions of the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present application, and it should be understood that the accompanying drawings in the present application are only for the purpose of illustration and description, and are not intended to limit the protection scope of the present application. In addition, it should be understood that the schematic drawings are not drawn to scale. A flowchart, as used in this application, illustrates operations implemented according to some embodiments of the present application. It should be understood that the operations of the flow diagrams may be implemented out of order and that steps without logical context may be performed in reverse order or concurrently. Moreover, one or more other operations may be added to the flow diagrams and one or more operations may be removed from the flow diagrams as directed by those skilled in the art.
In the following description, reference is made to "some embodiments" which describe a subset of all possible embodiments, but it is to be understood that "some embodiments" can be the same subset or different subsets of all possible embodiments and can be combined with one another without conflict.
In addition, the described embodiments are only some, but not all, of the embodiments of the present application. The components of the embodiments of the present application, which are generally described and illustrated in the figures herein, may be arranged and designed in a wide variety of different configurations. Thus, the following detailed description of the embodiments of the present application, as provided in the accompanying drawings, is not intended to limit the scope of the application, as claimed, but is merely representative of selected embodiments of the application. All other embodiments, which can be made by those skilled in the art based on the embodiments of the present application without making any inventive effort, are intended to be within the scope of the present application.
In the following description, the terms "first", "second", "third" and the like are merely used to distinguish similar objects and do not represent a particular ordering of the objects, it being understood that the "first", "second", "third" may be interchanged with a particular order or sequence, as permitted, to enable embodiments of the application described herein to be practiced otherwise than as illustrated or described herein.
It should be noted that the term "comprising" will be used in the embodiments of the present application to indicate the presence of the features stated hereinafter, but not to exclude the addition of other features.
Unless defined otherwise, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application belongs. The terminology used herein is for the purpose of describing embodiments of the present application and is not intended to be limiting of the present application.
Referring to fig. 1, fig. 1 is a schematic flow chart of steps S101-S104 of a MODBUS communication method based on a data list structure provided in an embodiment of the present application, which is applied to a host, and will be described with reference to steps S101-S104 shown in fig. 1.
Step S101, in response to a command storage request, sequentially placing at least one command into a linked list buffer through a target interface;
step S102, in response to a command extraction request, extracting a target command from the at least one command;
step S103, traversing from a preset data list structure body based on the target command to obtain a first communication parameter matched with the target command, and packaging the first communication parameter to obtain a host command;
Step S104, the host command is sent to the slave, so that the slave responds to the host command based on the data list structure.
The MODBUS communication method based on the data list structure body adopts a brand-new design thought of 'the data list structure body', arranges all communication parameter variables in the structure body in a data list form to construct a 'data list set', enables the communication protocol and the communication parameter variables to be independent and completely unhooked and decoupled, solves the problems that the MODBUS communication protocol and the communication parameter variables are too tightly bound and the dependency relationship is too complex to a great extent, weakens the coupling and the relevance of software codes to a great extent, enhances the readability and the portability of the software, and improves the multiplexing price value of the software. Meanwhile, a FIFO (first in first out) linked list buffer design mode is adopted for commands issued by a host in a MODBUS communication protocol, when the host needs to issue commands to a slave, the commands are sequentially placed into the FIFO linked list buffer one by one, then the host sequentially takes out from the FIFO linked list buffer, and when a communication bus is idle, the commands stored in the FIFO linked list buffer are preferentially issued to the slave, so that collision damage caused by data on a communication transmission line is avoided, and the stability, reliability and instantaneity of communication are improved; in communication management, complicated multiple 'state machine' switching design modes are abandoned, software design flow is simplified, and the regularity and readability of software are enhanced.
The following describes the above exemplary steps of the embodiments of the present application, respectively.
In step S101, at least one command is placed in the linked list buffer in sequence through the target interface in response to the command deposit request.
For example, referring to fig. 4, fig. 4 is a command transmission flow chart of a host protocol stack provided in the embodiment of the present application, as shown in fig. 4, a host transmits a command, enters a communication protocol stack (host protocol stack), and then selects a corresponding target interface (a host read coil command interface, a host read register command interface, a host write single or multiple coil command interfaces, and a host write single or multiple register command interfaces) according to a specific transmission command, and sequentially stores the command in a linked list buffer.
In some embodiments, the linked list buffer is a FIFO linked list buffer, and the responding to the command depositing request sequentially places at least one command into the linked list buffer through the target interface includes:
detecting the empty and full states of the FIFO linked list buffer in response to a command storage request;
when the FIFO linked list buffer is not full, sequentially placing at least one command into the linked list buffer through a target interface;
And stopping putting when the FIFO linked list buffer is full.
For example, referring to fig. 5, fig. 5 is a control flow chart of a host command FIFO linked list buffer provided in the embodiment of the present application, as shown in fig. 5, the host FIFO linked list buffer is initialized first, after the host sends a deposit command, it needs to determine whether the FIFO linked list buffer is full, and when the FIFO linked list buffer is not full, the command can be put into the FIFO linked list buffer, otherwise, the putting is stopped.
In step S102, a target command is extracted from the at least one command in response to the command extraction request.
In some embodiments, the linked list buffer is a FIFO linked list buffer, and the extracting, in response to a command extraction request, a target command from the at least one command includes:
the response command extraction request detects the empty and full states of the FIFO linked list buffer;
when the FIFO linked list buffer is not empty, the target command is fetched from the FIFO linked list buffer according to the first-in first-out sequence;
and stopping taking out when the FIFO linked list buffer is empty.
For example, with continued reference to fig. 5, after the host sends the extraction command, the empty and full states of the FIFO linked list buffer also need to be determined, and only when the FIFO linked list buffer is not empty, the command can be put into the host protocol stack, where the host protocol stack of the present application includes a data list structure, and in a subsequent processing process, the data list set is traversed and then the data list set is packaged for sending.
In step S103, based on the target command, a first communication parameter matched with the target command is traversed from a preset data list structure body, and the first communication parameter is packaged to obtain a host command.
For example, with continued reference to fig. 4, in the communication protocol stack (host protocol stack), according to the difference of the commands (host read holding register traversal, host read coil traversal, host write register traversal, host write coil traversal), the first communication parameter matched with the target command is traversed from the data list set (a specific lower expression of the data list structure, that is, the data list set formed by listing all the communication parameter variables in the data list structure in the form of a data list), and then the parameter sequencing packet is performed, so as to finally obtain the host command.
In step S104, the master command is sent to the slave, so that the slave responds to the master command based on the data list structure.
By way of example, with continued reference to fig. 4, the host command is ultimately sent to the slave via the host transport packet interface and the host transport data send interface, which is still responsive to the host command based on the data list structure.
In some embodiments, referring to fig. 6, fig. 6 is a component of a MODBUS communication protocol stack of the data list structure provided in the embodiments of the present application, as shown in fig. 6, a MODBUS communication protocol stack based on the data list structure is a new MODBUS communication protocol stack software, which includes a host protocol stack software and a slave protocol stack software, strictly adheres to a MODBUS transmission standard specification, has a complete error exception handling mechanism, and can be used in various MODBUS communication devices, and a physical layer supports RTU and ethernet. The method adopts a brand new design thought of a data list structure body, and all communication parameter variables are listed in the structure body in a data list form to construct a data list set; in addition to the data list structure, the method also comprises traversal comparison of the data list structure, a grouping algorithm and an analysis algorithm of MODBUS data frames and a transmitting and receiving interface function.
The data list structure body is used as a carrier to complete unhooking between the communication protocol and the communication parameter variable, and the coupling between the communication protocol and the communication parameter variable is relieved; therefore, the data list structure body is a core component of the MODBUS communication protocol stack software, the whole protocol stack is always unfolded around the data list structure body, the register addresses of the communication parameter variables are searched and address compared around the data list structure body, and the communication parameter variables in the data list structure body are all surrounded by the host protocol stack and the slave protocol stack for packet sending and receiving analysis.
Referring to fig. 7, fig. 7 is an exemplary diagram of a data list structure provided in embodiments of the present application, which in some embodiments includes the following members:
bit number of parameter variable, parameter storage pointer, parameter register address, parameter access authority, whether parameter is modified flag bit, parameter variable value compliance judging callback function, parameter index number, data list type and data list name;
in some embodiments, if the function of the protocol stack needs to be upgraded, other members can be added to the data list structure body. The data list structures at both sides of the master and slave computers between the same pair of master-slave communication groups are required to be completely consistent with each other, and other members make corresponding regulations according to the respective requirements of the master and slave computers.
The bit number of the parameter variable is used for identifying the bit number of the communication parameter variable in the memory; coil status, discrete amounts, etc. in the MODBUS protocol are generally defined as a pool or unsigned char or unsigned short data type, taking only 1 bit in the actual memory address; communication parameter variables with values ranging from-128 to 255 are generally defined as signed or unsigned data types, and occupy 8 bits; communication parameter variables with values ranging from-32768 to 32767 are generally defined as unsigned short or signed short data types, and occupy 16 bits. In the data list set, bit limit is needed to be made for each communication parameter variable, when the protocol stack reads and writes the communication parameter variables, the protocol stack must access their respective storage areas according to the bit limit set in advance to complete the reading and writing of the corresponding communication parameter variables, otherwise, the protocol stack cannot know the bit number occupied by each parameter in its storage area.
The parameter storage pointer is used for pointing to the storage address of the communication parameter variable; the pointer is used for pointing to a specific communication parameter variable, so that repeated definition of parameter variables with the same meaning in a software code is avoided, the direct reading and writing operation of the values of the communication parameter variables is also facilitated, the parameter values of the MODBUS protocol transmission register are carried out according to 2 bytes at most, and therefore the pointer is defined as an unsigned short pointer type.
The parameter register address (parameter address value in fig. 7) is a register address value allocated to the communication parameter variable in the MODBUS communication protocol transmission; the MODBUS protocol specifies a register address of 2 bytes, so a "parameter register address" is defined as an unsigned short data type.
The parameter access authority comprises three types of read-only, write-only and read-write; the MODBUS protocol makes 'read-only', 'read-write' attribute regulations on communication parameter variables, the attribute is divided into 'read-only', 'write-only', 'read-write', access authority of each communication parameter variable is specified in a data list set in advance, when a transmitted parameter value does not meet the access attribute specified in advance, the parameter value is ignored, and the parameter value is prevented from being modified by mistake due to communication transmission, so that the stability and reliability of product operation are ensured.
Whether the parameter is modified or not is used for marking when the parameter value is changed; specifically, the method is used for identifying some conditions that parameter values need to be forwarded to a next-stage sub-component through a MODBUS communication dependent intermediate component; when the parameter value is changed, the protocol stack reserves the flag bit for other functional modules of the product software to call and judge, and the parameter value is forwarded to the next-stage subcomponent at proper time.
The parameter variable value compliance judgment callback function is used for judging the limit value range of the set parameter; the method exists in a callback function mode, and a user can write corresponding parameter variable value compliance judging and processing function according to the parameter requirement of the callback function; when the transmitted value does not accord with the limit value range of the communication parameter, the modification of the communication parameter value is ignored.
The parameter index number is used for carrying out limit value judgment and modification on the corresponding communication parameter according to the index number in cooperation with the parameter variable value compliance judgment callback function;
the data List type is a container type for storing bit numbers of parameter variables, parameter storage pointers, parameter register addresses, parameter access rights, whether parameters are modified flag bits, parameter variable value compliance judgment callback functions and parameter index numbers, and is usually a List;
The name of the data List is the number of bits for storing parameter variables, a parameter storage pointer, a parameter register address, parameter access permission, whether the parameters are modified flag bits, a parameter variable value compliance judging callback function, and the container name of a parameter index number, namely the name of the List.
Referring to fig. 2, fig. 2 is a schematic flow chart of steps S201 to S203 of a MODBUS communication method based on a data list structure according to an embodiment of the present application, which is applied to a slave, and will be described with reference to steps S201 to S203 shown in fig. 2.
In step S201, in response to a host command sent by a host, the host command is parsed to obtain first parsed data, and CRC16 of the first parsed data is checked.
In step S202, after the CRC16 of the first analysis data is checked, according to the first analysis data, a second communication parameter matching with the first analysis data is obtained from a preset data list structure body, and the second communication parameter is packaged to obtain first response data.
In step S203, the first response data is verified, and when the verification result of the first response data is normal, the first response data is sent to the host, so that the host responds to the first response data based on the data list structure.
For example, referring to fig. 8, fig. 8 is a flowchart of a slave protocol stack response master command provided in this embodiment, as shown in fig. 8, after a master command is received, a communication protocol stack (slave protocol stack) is entered, first, a data frame needs to be parsed, an address, a function code, and the like are parsed to obtain first parsed data, then a CRC16 check code is checked, after checking, specific first parsed data (read holding register, read coil, read/write multiple registers, mask write register, write multiple registers, read input register, write single coil, write multiple coils, read discrete quantity input) is traversed from a data list set to obtain second communication parameters matched with the first parsed data, then a first response data is formed by grouping, whether the first response data is normal or not is judged, if so, the response data is sent, and if so, an error code is returned.
Referring to fig. 3, fig. 3 is a schematic flow chart of steps S301 to S302 of a MODBUS communication method based on a data list structure provided in the embodiment of the present application, which is applied to a host, and will be described with reference to steps S301 to S302 shown in fig. 3.
In step S301, in response to the first response data sent by the slave, the first response data is parsed to obtain second parsed data, and the CRC16 of the second parsed data is checked.
In step S302, after the CRC16 of the second analysis data is checked, a third communication parameter matching the second analysis data is obtained from a preset data list structure body according to the second analysis data, and the third communication parameter is packaged to obtain second response data.
As an example, referring to fig. 9, fig. 9 is a response flow chart of a host protocol stack analysis slave machine provided in this embodiment of the present application, where, as shown in fig. 9, the host machine needs to analyze response data (second response data) of the slave machine, after receiving the second response data sent by the slave machine, it enters a communication protocol stack (host protocol stack), still analyzes a data frame first, analyzes an address, a function code, and the like to obtain second analysis data, checks a CRC16 check code, and after checking, traverses from a data list to obtain a third communication parameter matched with the second analysis data according to specific second analysis data (read hold register, read coil, read/write multiple registers, mask write register, write multiple registers, read input register, write single coil, write multiple coils, read discrete quantity input), and then forms the second response data by grouping packets.
In summary, the embodiment of the application has the following beneficial effects:
aiming at the defects and shortcomings of the prior art, a brand new design thought of a data list structure body is adopted, all communication parameter variables are listed in the structure body in a data list form, a data list set is constructed, the communication protocol and the communication parameter variables are independent, decoupling is thoroughly carried out, the problems that the binding between the MODBUS communication protocol and the communication parameter variables is too tight and the dependency relationship is too complex are solved to a great extent, the coupling and the relevance of software codes are weakened to a great extent, the readability and the portability of the software are enhanced, and the multiplexing price value of the software is improved. Meanwhile, a FIFO (first in first out) linked list buffer design mode is adopted for commands issued by a host in a MODBUS communication protocol, when the host needs to issue commands to a slave, the commands are sequentially placed into the FIFO linked list buffer one by one, then the host sequentially takes out from the FIFO linked list buffer, and when a communication bus is idle, the commands stored in the FIFO linked list buffer are preferentially issued to the slave, so that collision damage caused by data on a communication transmission line is avoided, and the stability, reliability and instantaneity of communication are improved; in communication management, complicated multiple 'state machine' switching design modes are abandoned, software design flow is simplified, and the regularity and readability of software are enhanced.
Based on the same inventive concept, the embodiment of the present application further provides a MODBUS communication device based on a data list structure corresponding to the MODBUS communication method based on a data list structure in the embodiment of the first aspect, and since the principle of solving the problem of the device in the embodiment of the present application is similar to that of the MODBUS communication method based on a data list structure, implementation of the device may refer to implementation of the method, and repeated descriptions are omitted.
Fig. 10 is a schematic structural diagram of a MODBUS communication device based on a data list structure according to an embodiment of the present disclosure, as shown in fig. 10. The MODBUS communication device based on the data list structure body comprises:
a first response module 1001, configured to sequentially place at least one command into a linked list buffer through a target interface in response to a command storage request;
a second response module 1002, configured to extract a target command from the at least one command in response to a command extraction request;
a first traverse packet module 1003, configured to traverse from a preset data list structure based on the target command to obtain a first communication parameter that matches the target command, and packet the first communication parameter to obtain a host command;
A first sending module 1004 is configured to send the master command to a slave, so that the slave responds to the master command based on the data list structure.
It will be appreciated by those skilled in the art that the implementation of the units in the MODBUS communication device based on a data list structure shown in fig. 10 can be understood with reference to the foregoing description of the MODBUS communication method based on a data list structure. The functions of each unit in the MODBUS communication device based on the data list structure shown in fig. 10 may be implemented by a program running on a processor, or may be implemented by a specific logic circuit.
In one possible implementation, the data list structure used by the first traversal package module includes the following members:
bit number of parameter variable, parameter storage pointer, parameter register address, parameter access authority, whether parameter is modified flag bit, parameter variable value compliance judging callback function, parameter index number, data list type and data list name;
the bit number of the parameter variable is used for identifying the bit number of the communication parameter variable in the memory;
the parameter storage pointer is used for pointing to the storage address of the communication parameter variable;
The parameter register address is a register address value allocated to the communication parameter variable in MODBUS communication protocol transmission;
the parameter access authority comprises three types of read-only, write-only and read-write;
whether the parameter is modified or not is used for marking when the parameter value is changed;
the parameter variable value compliance judgment callback function is used for judging the limit value range of the set parameter;
the parameter index number is used for carrying out limit value judgment and modification on the corresponding communication parameter according to the index number in cooperation with the parameter variable value compliance judgment callback function;
the data list type is a container type for storing bit numbers of parameter variables, parameter storage pointers, parameter register addresses, parameter access rights, whether parameters are modified flag bits, parameter variable value compliance judging callback functions and parameter index numbers;
the name of the data list is the number of bits for storing parameter variables, a parameter storage pointer, a parameter register address, parameter access permission, whether the parameters are modified flag bits, a parameter variable value compliance judging callback function and the container name of a parameter index number.
In one possible implementation, the linked list buffer is a FIFO linked list buffer, and the first response module 1001 sequentially places at least one command into the linked list buffer through the target interface in response to the command deposit request, including:
Detecting the empty and full states of the FIFO linked list buffer in response to a command storage request;
when the FIFO linked list buffer is not full, sequentially placing at least one command into the linked list buffer through a target interface;
and stopping putting when the FIFO linked list buffer is full.
In one possible implementation, the linked list buffer is a FIFO linked list buffer, and the second response module 1002, in response to a command extraction request, extracts a target command from the at least one command, including:
the response command extraction request detects the empty and full states of the FIFO linked list buffer;
when the FIFO linked list buffer is not empty, the target command is fetched from the FIFO linked list buffer according to the first-in first-out sequence;
and stopping taking out when the FIFO linked list buffer is empty.
The MODBUS communication device based on the data list structure body adopts a brand-new design thought of 'the data list structure body', arranges all communication parameter variables in the structure body in a data list form to construct a 'data list set', enables the communication protocol and the communication parameter variables to be independent and completely unhooked and decoupled, solves the problems that the MODBUS communication protocol and the communication parameter variables are too tightly bound and the dependency relationship is too complex to a great extent, weakens the coupling and the relevance of software codes to a great extent, enhances the readability and the portability of the software, and improves the multiplexing price value of the software. Meanwhile, a FIFO (first in first out) linked list buffer design mode is adopted for commands issued by a host in a MODBUS communication protocol, when the host needs to issue commands to a slave, the commands are sequentially placed into the FIFO linked list buffer one by one, then the host sequentially takes out from the FIFO linked list buffer, and when a communication bus is idle, the commands stored in the FIFO linked list buffer are preferentially issued to the slave, so that collision damage caused by data on a communication transmission line is avoided, and the stability, reliability and instantaneity of communication are improved; in communication management, complicated multiple 'state machine' switching design modes are abandoned, software design flow is simplified, and the regularity and readability of software are enhanced.
Based on the same inventive concept, the embodiment of the present application further provides a MODBUS communication device based on a data list structure corresponding to the MODBUS communication method based on a data list structure in the second embodiment of the present application, and since the principle of solving the problem of the device in the embodiment of the present application is similar to that of the MODBUS communication method based on a data list structure, the implementation of the device may refer to the implementation of the method, and the repetition is omitted.
Fig. 11 is a schematic structural diagram of another MODBUS communication device based on a data list structure according to an embodiment of the present application. Another MODBUS communication device based on a data list structure includes:
a third response module 1101, configured to respond to a host command sent by a host, parse the host command to obtain first parsed data, and check a CRC16 of the first parsed data;
the second traversal packet-grouping module 1102 is configured to traverse from a preset data list structure body according to the first analysis data after the CRC16 of the first analysis data is checked to be correct, obtain a second communication parameter that is matched with the first analysis data, and group the second communication parameter to obtain first response data;
And a second sending module 1103, configured to verify the first response data, and send the first response data to the host when the verification result of the first response data is normal, so that the host responds to the first response data based on the data list structure.
As shown in fig. 12, fig. 12 is a schematic diagram of a composition structure of an electronic device 1200 provided in an embodiment of the present application, where the electronic device 1200 includes:
a processor 1201, a storage medium 1202 and a bus 1203, wherein the storage medium 1202 stores machine readable instructions executable by the processor 1201, and when the electronic device 1200 is running, the processor 1201 communicates with the storage medium 1202 through the bus 1203, and the processor 1201 executes the machine readable instructions to perform the steps of the MODBUS communication method based on a data list structure described in the embodiments of the present application.
In practice, the various components of the electronic device 1200 are coupled together via a bus 1203. It is understood that the bus 1203 is configured to implement connected communications between these components. The bus 1203 includes a power bus, a control bus, and a status signal bus in addition to the data bus. But for clarity of illustration, the various buses are labeled as bus 1203 in fig. 12.
Aiming at the defects and shortcomings of the prior art, the electronic equipment adopts a brand-new design thought of a data list structure body, all communication parameter variables are listed in the structure body in a data list form to construct a data list set, the communication protocol and the communication parameter variables are independent and decoupled thoroughly, the problems that the binding between the MODBUS communication protocol and the communication parameter variables is too tight and the dependency relationship is too complex are solved to a great extent, the coupling and the relevance of software codes are weakened to a great extent, the readability and the portability of the software are enhanced, and the multiplexing price value of the software is improved. Meanwhile, a FIFO (first in first out) linked list buffer design mode is adopted for commands issued by a host in a MODBUS communication protocol, when the host needs to issue commands to a slave, the commands are sequentially placed into the FIFO linked list buffer one by one, then the host sequentially takes out from the FIFO linked list buffer, and when a communication bus is idle, the commands stored in the FIFO linked list buffer are preferentially issued to the slave, so that collision damage caused by data on a communication transmission line is avoided, and the stability, reliability and instantaneity of communication are improved; in communication management, complicated multiple 'state machine' switching design modes are abandoned, software design flow is simplified, and the regularity and readability of software are enhanced.
The embodiment of the application also provides a computer readable storage medium, which stores executable instructions that, when executed by the at least one processor 1201, implement the MODBUS communication method based on the data list structure described in the embodiment of the application.
In some embodiments, the storage medium may be a magnetic random Access Memory (FRAM, ferromagneticRandom Access Memory), read Only Memory (ROM), programmable Read Only Memory (PROM, programmable Read Only Memory), erasable programmable Read Only Memory (EPROM, erasableProgrammable Read Only Memory), electrically erasable programmable Read Only Memory (EEPROM, electricallyErasable Programmable Read Only Memory), flash Memory (Flash Memory), magnetic surface Memory, optical disk, or compact disk Read Only Memory (CD ROM, compact Disc Read Only Memory), among others; but may be a variety of devices including one or any combination of the above memories.
In some embodiments, the executable instructions may be in the form of programs, software modules, scripts, or code, written in any form of programming language (including compiled or interpreted languages, or declarative or procedural languages), and they may be deployed in any form, including as stand-alone programs or as modules, components, subroutines, or other units suitable for use in a computing environment.
As an example, the executable instructions may, but need not, correspond to files in a file system, may be stored as part of a file that holds other programs or data, for example, in one or more scripts in a hypertext markup Language (HTML, hyperTextMarkup Language) document, in a single file dedicated to the program in question, or in multiple coordinated files (e.g., files that store one or more modules, sub-programs, or portions of code).
As an example, executable instructions may be deployed to be executed on one computing device or on multiple computing devices located at one site or, alternatively, distributed across multiple sites and interconnected by a communication network.
The computer readable storage medium adopts a brand new design thought of a data list structure body to list all communication parameter variables in the structure body in a data list form to construct a data list set, so that the communication protocol and the communication parameter variables are independent and decoupled thoroughly, the problems of too tight binding and too complex dependency relationship between the MODBUS communication protocol and the communication parameter variables are solved to a great extent, the coupling and the relevance of software codes are weakened to a great extent, the readability and the portability of the software are enhanced, and the multiplexing price value of the software is improved. Meanwhile, a FIFO (first in first out) linked list buffer design mode is adopted for commands issued by a host in a MODBUS communication protocol, when the host needs to issue commands to a slave, the commands are sequentially placed into the FIFO linked list buffer one by one, then the host sequentially takes out from the FIFO linked list buffer, and when a communication bus is idle, the commands stored in the FIFO linked list buffer are preferentially issued to the slave, so that collision damage caused by data on a communication transmission line is avoided, and the stability, reliability and instantaneity of communication are improved; in communication management, complicated multiple 'state machine' switching design modes are abandoned, software design flow is simplified, and the regularity and readability of software are enhanced.
In several embodiments provided in the present application, it should be understood that the disclosed method and electronic device may be implemented in other manners. The above described device embodiments are only illustrative, e.g. the division of the units is only one logical function division, and there may be other divisions in practice, such as: multiple units or components may be combined or may be integrated into another system, or some features may be omitted, or not performed. In addition, the various components shown or discussed may be coupled or directly coupled or communicatively coupled to each other via some interface, whether indirectly coupled or communicatively coupled to devices or units, whether electrically, mechanically, or otherwise.
The modules described as separate components may or may not be physically separate, and components shown as modules may or may not be physical units, may be located in one place, or may be distributed over multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
In addition, each functional unit in each embodiment of the present application may be integrated in one processing unit, or each unit may exist alone physically, or two or more units may be integrated in one unit.
The functions, if implemented in the form of software functional units and sold or used as a stand-alone product, may be stored in a non-volatile computer readable storage medium executable by a processor. Based on such understanding, the technical solution of the present application may be embodied essentially or in a part contributing to the prior art or in a part of the technical solution, in the form of a software product stored in a storage medium, including several instructions for causing a computer device (which may be a personal computer, a platform server, or a network device, etc.) to perform all or part of the steps of the methods described in the embodiments of the present application. And the aforementioned storage medium includes: a usb disk, a removable hard disk, a ROM, a RAM, a magnetic disk, or an optical disk, etc.
The foregoing is merely a specific embodiment of the present application, but the protection scope of the present application is not limited thereto, and any person skilled in the art can easily think about changes or substitutions within the technical scope of the present application, and the changes or substitutions are covered in the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the protection scope of the claims.
Claims (10)
1. The MODBUS communication method based on the data list structure body is characterized by being applied to a host machine and comprising the following steps of:
responding to the command storage request, and sequentially placing at least one command into a linked list buffer through a target interface;
extracting a target command from the at least one command in response to a command extraction request;
traversing from a preset data list structure body based on the target command to obtain a first communication parameter matched with the target command, and packaging the first communication parameter to obtain a host command;
and sending the host command to a slave so that the slave responds to the host command based on the data list structure.
2. The method of claim 1, wherein the data list structure comprises the following members:
bit number of parameter variable, parameter storage pointer, parameter register address, parameter access authority, whether parameter is modified flag bit, parameter variable value compliance judging callback function, parameter index number, data list type and data list name;
the bit number of the parameter variable is used for identifying the bit number of the communication parameter variable in the memory;
The parameter storage pointer is used for pointing to the storage address of the communication parameter variable;
the parameter register address is a register address value allocated to the communication parameter variable in MODBUS communication protocol transmission;
the parameter access authority comprises three types of read-only, write-only and read-write;
whether the parameter is modified or not is used for marking when the parameter value is changed;
the parameter variable value compliance judgment callback function is used for judging the limit value range of the set parameter;
the parameter index number is used for carrying out limit value judgment and modification on the corresponding communication parameter according to the index number in cooperation with the parameter variable value compliance judgment callback function;
the data list type is a container type for storing bit numbers of parameter variables, parameter storage pointers, parameter register addresses, parameter access rights, whether parameters are modified flag bits, parameter variable value compliance judging callback functions and parameter index numbers;
the name of the data list is the number of bits for storing parameter variables, a parameter storage pointer, a parameter register address, parameter access permission, whether the parameters are modified flag bits, a parameter variable value compliance judging callback function and the container name of a parameter index number.
3. The method of claim 1, wherein the linked list buffer is a FIFO linked list buffer, and wherein the sequentially placing at least one command into the linked list buffer via the target interface in response to the command deposit request comprises:
detecting the empty and full states of the FIFO linked list buffer in response to a command storage request;
when the FIFO linked list buffer is not full, sequentially placing at least one command into the linked list buffer through a target interface;
and stopping putting when the FIFO linked list buffer is full.
4. The method of claim 1, wherein the linked list buffer is a FIFO linked list buffer, and wherein the extracting the target command from the at least one command in response to the command extraction request comprises:
the response command extraction request detects the empty and full states of the FIFO linked list buffer;
when the FIFO linked list buffer is not empty, the target command is fetched from the FIFO linked list buffer according to the first-in first-out sequence;
and stopping taking out when the FIFO linked list buffer is empty.
5. The MODBUS communication method based on the data list structure body is characterized by being applied to a slave machine and comprising the following steps of:
Responding to a host command sent by a host, analyzing the host command to obtain first analysis data, and checking CRC16 of the first analysis data;
after the CRC16 of the first analysis data is checked to be correct, traversing from a preset data list structure body according to the first analysis data to obtain second communication parameters matched with the first analysis data, and packaging the second communication parameters to obtain first response data;
and verifying the first response data, and when the verification result of the first response data is normal, sending the first response data to the host, so that the host responds to the first response data based on the data list structure body.
6. The MODBUS communication method based on the data list structure body is characterized by being applied to a host machine and comprising the following steps of:
responding to first response data sent by a slave, analyzing the first response data to obtain second analysis data, and checking CRC16 of the second analysis data;
and traversing from a preset data list structure body according to the second analysis data after the CRC16 of the second analysis data is checked, obtaining a third communication parameter matched with the second analysis data, and packaging the third communication parameter to obtain second response data.
7. A MODBUS communication device based on a data list structure, the device comprising:
the first response module is used for responding to the command storage request and sequentially placing at least one command into the linked list buffer through the target interface;
the second response module is used for responding to the command extraction request and extracting a target command from the at least one command;
the first traversal packaging module is used for traversing from a preset data list structure body based on the target command to obtain a first communication parameter matched with the target command, and packaging the first communication parameter to obtain a host command;
and the first sending module is used for sending the host command to the slave so that the slave responds to the host command based on the data list structure body.
8. A MODBUS communication device based on a data list structure, the device comprising:
the third response module is used for responding to a host command sent by a host, analyzing the host command to obtain first analysis data and checking CRC16 of the first analysis data;
the second traversal packet-grouping module is used for traversing from a preset data list structure body according to the first analysis data after the CRC16 of the first analysis data is checked to be correct, obtaining second communication parameters matched with the first analysis data, and grouping the second communication parameters to obtain first response data;
And the second sending module is used for verifying the first response data, and sending the first response data to the host when the verification result of the first response data is normal, so that the host responds to the first response data based on the data list structure body.
9. An electronic device, comprising: a processor, a storage medium, and a bus, the storage medium storing machine-readable instructions executable by the processor, the processor and the storage medium communicating over the bus when the electronic device is running, the processor executing the machine-readable instructions to perform the data list structure-based MODBUS communication method of any one of claims 1 to 4, or to perform the data list structure-based MODBUS communication method of claim 5, or to perform the data list structure-based MODBUS communication method of claim 6.
10. A computer-readable storage medium, on which a computer program is stored, which computer program, when being executed by a processor, performs the MODBUS communication method based on a data list structure as claimed in any one of claims 1 to 4, or performs the MODBUS communication method based on a data list structure as claimed in claim 5, or performs the MODBUS communication method based on a data list structure as claimed in claim 6.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202310332136.1A CN116366391A (en) | 2023-03-29 | 2023-03-29 | MODBUS communication method and device based on data list structure |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202310332136.1A CN116366391A (en) | 2023-03-29 | 2023-03-29 | MODBUS communication method and device based on data list structure |
Publications (1)
Publication Number | Publication Date |
---|---|
CN116366391A true CN116366391A (en) | 2023-06-30 |
Family
ID=86919310
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202310332136.1A Pending CN116366391A (en) | 2023-03-29 | 2023-03-29 | MODBUS communication method and device based on data list structure |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN116366391A (en) |
Cited By (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN117032579A (en) * | 2023-08-21 | 2023-11-10 | 上海合芯数字科技有限公司 | Slave starting method, device and storage medium |
-
2023
- 2023-03-29 CN CN202310332136.1A patent/CN116366391A/en active Pending
Cited By (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN117032579A (en) * | 2023-08-21 | 2023-11-10 | 上海合芯数字科技有限公司 | Slave starting method, device and storage medium |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN100565472C (en) | A kind of adjustment method that is applicable to multiprocessor karyonide system chip | |
CN102622253B (en) | A kind of method of single-chip microcomputer and online upgrading thereof | |
CN105446806B (en) | A kind of processing method and processing device of the application program without response | |
CN116366391A (en) | MODBUS communication method and device based on data list structure | |
CN105741879B (en) | A kind of simulation intelligent electric energy meter memory test plate system and its test method | |
CN103685578B (en) | The data transmission method of master-slave equipment | |
CN114047712B (en) | Data communication method of semi-physical simulation system based on reflective memory network | |
CN111258832B (en) | Interface parameter verification method, device, equipment and medium | |
CN112100081B (en) | Upgrade test method and device based on double-core intelligent electric meter and computer equipment | |
CN110866152A (en) | Fault code retrieval method and device, electronic equipment and readable storage medium | |
CN112445490A (en) | File sequence processing method and device, terminal equipment and storage medium | |
CN114531289A (en) | System interaction method based on artificial intelligence and related equipment | |
CN110689238B (en) | Method and system for realizing MMS (multimedia message service) information simulation and point-to-point of intelligent substation | |
CN111291022A (en) | Data storage system based on block chain | |
CN118294809A (en) | Linkage control method and system for battery detection equipment and external connection equipment | |
CN114116337A (en) | Hard disk test method, system, terminal and storage medium based on PCIE link configuration | |
CN104516953B (en) | A kind of black box subsystem for power dispatching automation magnanimity message | |
CN104780123A (en) | Network packet receiving and sending processing device and design method thereof | |
CN112711432A (en) | Feature library upgrading method and device for network security equipment | |
CN111371799B (en) | Method, device and equipment for controlling data receiving and transmitting of MCTP (Multi-channel media Port) controller | |
CN105739919B (en) | Data accessing system and method | |
CN105511815B (en) | A kind of PLC based on segment table can operating file storing and resolving method and storage system | |
CN102243617B (en) | Read/write processing method, read/write processing equipment and read/write processing system | |
CN107230263A (en) | A kind of WTB bus datas frame recording instrument and recording method | |
CN103164290A (en) | Management method and management device of application memory |
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 |