CN106712902B - Coding, coding/decoding method and encoder, the decoder of Modbus document of agreement - Google Patents
Coding, coding/decoding method and encoder, the decoder of Modbus document of agreement Download PDFInfo
- Publication number
- CN106712902B CN106712902B CN201611177281.3A CN201611177281A CN106712902B CN 106712902 B CN106712902 B CN 106712902B CN 201611177281 A CN201611177281 A CN 201611177281A CN 106712902 B CN106712902 B CN 106712902B
- Authority
- CN
- China
- Prior art keywords
- parameter
- frame
- event
- agreement
- modbus
- 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
Links
Classifications
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L1/00—Arrangements for detecting or preventing errors in the information received
- H04L1/0001—Systems modifying transmission characteristics according to link quality, e.g. power backoff
- H04L1/0015—Systems modifying transmission characteristics according to link quality, e.g. power backoff characterised by the adaptation strategy
- H04L1/0016—Systems modifying transmission characteristics according to link quality, e.g. power backoff characterised by the adaptation strategy involving special memory structures, e.g. look-up tables
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L1/00—Arrangements for detecting or preventing errors in the information received
- H04L1/004—Arrangements for detecting or preventing errors in the information received by using forward error control
- H04L1/0056—Systems characterized by the type of code used
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L1/00—Arrangements for detecting or preventing errors in the information received
- H04L1/004—Arrangements for detecting or preventing errors in the information received by using forward error control
- H04L1/0056—Systems characterized by the type of code used
- H04L1/0061—Error detection codes
-
- 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
-
- 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
Landscapes
- Engineering & Computer Science (AREA)
- Computer Networks & Wireless Communication (AREA)
- Signal Processing (AREA)
- Quality & Reliability (AREA)
- Compression, Expansion, Code Conversion, And Decoders (AREA)
Abstract
A kind of coding, coding/decoding method and encoder, the decoder of Modbus document of agreement, the coding method include: parameter needed for obtaining the first function code and corresponding transmission frame;Parameter needed for the transmission frame is mapped and generates parameter object, and is stored in Parameter Dictionary;The first functional object corresponding with first function code is searched from preset function code dictionary;The parameter description information of the parameter needed for reading the transmission frame in first functional object;According to the parameter description information of parameter needed for the transmission frame, corresponding parameter object is searched from the Parameter Dictionary;Determine corresponding position of the data of the parameter object in the valid data for sending frame;It generates and sends frame and be sent to from equipment.Above scheme can reduce using the complexity during coding and decoding when Modbus protocol communication, reduce error probability.
Description
Technical field
The present invention relates to protocol processes field more particularly to a kind of coding, coding/decoding method and the volumes of Modbus document of agreement
Code device, decoder.
Background technique
Modbus agreement is applied to a kind of all-purpose language on electronic controller.Pass through Modbus agreement, controller phase
Between mutually, controller is between network and other equipment via may be implemented to communicate.
Controller communication uses principal and subordinate's technology, i.e. main equipment initial interrogation, other are mentioned from equipment according to main equipment inquiry
The data of confession make corresponding reaction.Modbus communication mode establishes the format of main equipment inquiry: from device address, function generation
Code, all data to be sent and check code.It receives the response from equipment and is carried out using Modbus communication mode, it is described from equipment
It receives the response including confirming the domain to be taken action, the data to be returned and check code.
PC host is a typical main equipment.PC software is needed when realizing Modbus protocol communication for the agreement
Realize corresponding coding and decoding.It requires to be combined for the concrete composition structure of agreement in each coding function,
Duplicate array manipulation is more, is easy error.
Summary of the invention
Present invention solves the technical problem that being the complexity reduced using during coding and decoding when Modbus protocol communication
Degree reduces error probability.
In order to solve the above technical problems, the embodiment of the present invention provides a kind of coding method of Modbus document of agreement, it is described
Modbus document of agreement includes from equipment essential information and protocol data, and the coding method includes: to obtain the first function code
And parameter needed for corresponding transmission frame;Parameter needed for the transmission frame is mapped and generates the first parameter object, and is stored in the
In one Parameter Dictionary;The first functional object corresponding with first function code is searched from preset function code dictionary;From institute
State the parameter description information of parameter needed for reading the transmission frame in the first functional object;According to parameter needed for the transmission frame
Parameter description information searches corresponding first parameter object from first Parameter Dictionary;Determine first parameter object
Data it is described send frame valid data in corresponding position;It generates and sends frame and be sent to from equipment.
Optionally, the function code dictionary generates in the following way: reading the Modbus document of agreement;To described
Protocol data in Modbus document of agreement is parsed, and is generated and the one-to-one functional object of the protocol data;It reads
Preset special event processing method obtains and the preset one-to-one functional object of special event;According to it is described with
The one-to-one functional object of the protocol data and with the preset one-to-one functional object of special event, establish
The mapping relations of functional object and function code generate the function code dictionary.
Optionally, after searching corresponding first parameter object in first Parameter Dictionary, further includes: judgement is
It is no that there are preset specially treated events;When there are the specially treated event, to first parameter of correspondence found
The data of object are updated.
Optionally, from read in first functional object it is described transmission frame needed for parameter parameter description information it
Before, further includes: it judges whether there is and sends frame pretreatment event;When pre-processing event there are the transmission frame, to the hair
Frame is sent to carry out pretreatment operation.
Optionally, before generating transmission frame, further includes: judge whether there is and send frame post-processing event;When there are institute
When stating transmission frame post-processing event, post-processing operation is carried out to the transmission frame.
Optionally, the generation sends frame, comprising: according to the data from equipment essential information, in the transmission frame
Partial valid data generate the transmission frame.
The embodiment of the invention also provides a kind of coding/decoding methods of Modbus document of agreement, comprising: receives and sends from equipment
Frame;The valid data of the second function code and the receiving frame are parsed from receiving frame;From preset function code dictionary
Search the second functional object corresponding with second function code;It is read in the receiving frame from second functional object
Parameter description information;According to the parameter description information in the receiving frame, determine described in the valid data of the receiving frame from
The corresponding character array of equipment return parameters;Described the second parameter will be generated from the corresponding character array mapping of equipment return parameters
Object, and be stored in the second Parameter Dictionary;Second Parameter Dictionary is parsed, decoding result is obtained.
Optionally, it before the valid data for parsing the second function code and the receiving frame in receiving frame, also wraps
It includes: the receiving frame being verified, and check results are judged;When the check results are correct, execute from described
The operation of the valid data of the second function code and the receiving frame is parsed in receiving frame;When the check results mistake,
It returns to error message and terminates decoding operate.
Optionally, before it described will generate the second parameter object from the corresponding character array mapping of equipment return parameters,
Further include: judge whether there is preset specially treated event;When there are the preset specially treated event, to it is described from
The corresponding character array of equipment return parameters is updated.
Optionally, described in the valid data for determining the receiving frame from the corresponding character array of equipment return parameters it
Before, further includes: judge whether there is receiving frame pretreatment event;When pre-processing event there are the receiving frame, connect to described
It receives frame and carries out pretreatment operation.
Optionally, before being parsed to second Parameter Dictionary, further includes: after judging whether there is receiving frame
Director's part;When post-processing event there are the receiving frame, post-processing operation is carried out to the receiving frame.
Optionally, described that second Parameter Dictionary is parsed, comprising: to read institute from second Parameter Dictionary
State the second parameter object;Obtain the corresponding character array of second parameter object;The character array is parsed, is obtained
The decoding result.
The embodiment of the invention provides a kind of encoders, for being encoded to Modbus document of agreement, the Modbus
Document of agreement includes from equipment essential information and protocol data, and the encoder includes: acquiring unit, for obtaining the first function
Parameter needed for energy code and corresponding transmission frame;First map unit, for by the mapping of parameter needed for transmissions frame generation the
One parameter object, and be stored in the first Parameter Dictionary;First searching unit, for from preset function code dictionary search with
Corresponding first functional object of first function code;First reading unit, for reading institute from first functional object
State the parameter description information of parameter needed for sending frame;Second searching unit, the parameter for the parameter according to needed for the transmission frame
Description information searches corresponding first parameter object from first Parameter Dictionary;First determination unit, described in determining
Corresponding position of the data of first parameter object in the valid data for sending frame;First generation unit, for generating hair
Send frame;Transmission unit, for being sent to the transmission frame from equipment.
Optionally, the function code dictionary generates in the following way: reading the Modbus document of agreement;To described
Protocol data in Modbus document of agreement is parsed, and is generated and the one-to-one functional object of the protocol data;It reads
Preset special event processing method obtains and the preset one-to-one functional object of special event;According to it is described with
The one-to-one functional object of the protocol data and with the preset one-to-one functional object of special event, establish
The mapping relations of functional object and function code generate the function code dictionary.
Optionally, the encoder further include: the first updating unit, in second searching unit from described first
After searching corresponding first parameter object in Parameter Dictionary, preset specially treated event is judged whether there is;When there are institute
When stating specially treated event, the data of first parameter object of correspondence found are updated.
Optionally, the encoder further include: the first pretreatment unit is used for when there is transmission frame pretreatment event,
Pretreatment operation is carried out to the transmission frame.
Optionally, the encoder further include: the first post-processing unit is used for when there is transmission frame post-processing event,
Post-processing operation is carried out to the transmission frame.
Optionally, first generation unit, for according to the data from equipment essential information, in the transmission frame
Partial valid data generate the transmission frame.
The embodiment of the invention also provides a kind of decoders, for being decoded to Modbus document of agreement, comprising: receive
Unit, for receiving the frame sent from equipment;First resolution unit, for parsing the second function code and institute from receiving frame
State the valid data of receiving frame;Third searching unit, for being searched and second function code from preset function code dictionary
Corresponding second functional object;Second reading unit, for reading the ginseng in the receiving frame from second functional object
Number description information;Second determination unit, for determining having for the receiving frame according to the parameter description information in the receiving frame
It imitates described in data from the corresponding character array of equipment return parameters;Second generation unit is joined for that described will return from equipment
The corresponding character array mapping of number generates the second parameter object, and is stored in the second Parameter Dictionary;Second resolution unit, is used for
Second Parameter Dictionary is parsed, decoding result is obtained.
Optionally, the decoder further include: verification unit, for being parsed from receiving frame in first resolution unit
Out before the valid data of the second function code and the receiving frame, the receiving frame is verified.
Optionally, the decoder further include: the second updating unit, for when there are preset specially treated event,
It is updated to described from the corresponding character array of equipment return parameters.
Optionally, the decoder further include: the second pretreatment unit, for when there are receiving frame pre-process event when,
Pretreatment operation is carried out to the receiving frame.
Optionally, the decoder further include: the second post-processing unit, for when there are receiving frame post-process event when,
Post-processing operation is carried out to the receiving frame.
Optionally, second resolution unit, for reading second parameter object from second Parameter Dictionary;
Obtain the corresponding character array of second parameter object;The character array is parsed, the decoding result is obtained.
Compared with prior art, the technical solution of the embodiment of the present invention has the advantages that
When parameter needed for the different corresponding transmission frames of function code encodes, ginseng needed for frame will can be first sent
Number mapping generates the first parameter object and is stored in the first Parameter Dictionary.Later, the parameter of the parameter according to needed for sending frame is retouched
Information is stated, corresponding first parameter object is searched from the first Parameter Dictionary, determines that the first parameter object is sending the effective of frame
Encoding operation is completed to generate transmission frame in the position of data.For parameter needed for the different corresponding transmission frames of function code into
It when row coding, can be encoded using same coding method, without using different codings for different function codes
Agreement is encoded, and can be reduced using encoder complexity when Modbus protocol communication, and coding error probability is reduced.
When receiving from the frame that equipment is sent, function code and receiving frame can be first parsed from receiving frame has
Data are imitated, corresponding functional object are searched according to function code, to obtain the parameter description information in receiving frame.According in receiving frame
Parameter description information, search from the corresponding character array of equipment return parameters, mapping generates the second parameter object and is simultaneously stored in
In second Parameter Dictionary.By parsing to the second Parameter Dictionary, that is, it can reach decoding result.It is sent out for different from equipment
The frame or the same different frame sent from equipment sent, can adopt the same method and be decoded, without for different
Receiving frame is decoded using different decoding protocols, therefore can be reduced using decoding complex degree when Modbus protocol communication,
Reduce decoding error probability.
Detailed description of the invention
Fig. 1 is the flow chart of the coding method of one of embodiment of the present invention Modbus document of agreement;
Fig. 2 is the flow chart of the coding method of another Modbus document of agreement in the embodiment of the present invention;
Fig. 3 is the flow chart of the coding/decoding method of one of embodiment of the present invention Modbus document of agreement;
Fig. 4 is the flow chart of the coding/decoding method of another Modbus document of agreement in the embodiment of the present invention;
Fig. 5 is the structural schematic diagram of one of embodiment of the present invention encoder;
Fig. 6 is the structural schematic diagram of one of embodiment of the present invention decoder.
Specific embodiment
In the prior art, PC software needs to encode accordingly for every protocol realization when realizing Modbus agreement
And decoding.When encoding to an agreement, the data needed from equipment are combined into respective symbols number according to agreement regulation
Group, decoding be then the character array that will be exported from equipment according to protocol analysis at data needed for PC software.PC software is at each
It requires to be combined or parse for the concrete composition structure of agreement in coding, decoding functions, number present in software code
It is more according to operating, it is easy error.
In embodiments of the present invention, when parameter needed for the different corresponding transmission frames of function code encodes,
It is generated and the first parameter object and is stored in the first Parameter Dictionary with parameter mapping needed for will first sending frame.Later, according to transmission
The parameter description information of parameter needed for frame searches corresponding first parameter object from the first Parameter Dictionary, determines the first parameter
Object is in the position for the valid data for sending frame, to generate transmission frame, completes encoding operation.It is corresponding for different function codes
Transmission frame needed for parameter when being encoded, can be encoded using same coding method, without being directed to different function
Energy code is encoded using different coding protocols, can be reduced using encoder complexity when Modbus protocol communication, be reduced and compile
Code error probability.
It is understandable to enable above-mentioned purpose of the invention, feature and beneficial effect to become apparent, with reference to the accompanying drawing to this
The specific embodiment of invention is described in detail.
In specific implementation, before being performed the encoding operation to Modbus document of agreement, first to being mentioned in the embodiment of the present invention
The Modbus document of agreement of confession is briefly described.
In embodiments of the present invention, Modbus document of agreement may include device address, function code, data and check code
Etc. information.For different application demands, the information such as frame head, data length can also be added in Modbus document of agreement.
Referring to table 1, the coded format of one of embodiment of the present invention Modbus document of agreement is given.In table 1,
Device address, function code, valid data and check code in Modbus document of agreement are essential option, frame head and data length
To be optional, data length refers to the byte length of valid data.The byte length that frame head occupies is 4 bytes, and device address accounts for
Byte length is 1 byte, and the byte length that function code occupies is 1 byte, and the byte length that data length occupies is 2 words
Section, the byte length of valid data are N byte, and verification code length is 2 bytes.In practical applications, in each frame, significant figure
According in frame carry useful information data, namely in a frame remove frame head, device address, function code, data length and
Data except check code are valid data.
Frame head | Device address | Function code | Data length | Valid data | Check code |
4 bytes | 1 byte | 1 byte | 2 bytes | N byte | 2 bytes |
Table 1
In specific implementation, each Modbus document of agreement includes two parts: a part is to equipment essential information
Description, referred to as equipment essential information describe;Another part is the description to protocol data, and referred to as protocol data describes.
In the description of equipment essential information, the description to equipment essential information may include device name, device type, number
According to information such as default size end format and the basic structure, the basic structures of receiving frame that send frame.Send the basic structure of frame
The format provided in table 1 is referred to the basic structure of receiving frame.
It may include a plurality of protocol data in Modbus document of agreement.In protocol data description, assisted for each
Data are discussed, structure, the structure of receiving frame that there is one-to-one function code, send frame.Sending frame can be by pretreatment thing
Part, post-processing event and parameter composition, receiving frame can also be made of pretreatment event, post-processing event and parameter.Hair
Send the parameter in frame can be different from the parameter in receiving frame.
It is directed to each protocol data, the number of pretreatment event therein can be 0 or 1, namely may deposit
In pretreatment event, it is also possible to pretreatment event be not present;The number of post-processing event may be 0 or 1, namely may
In the presence of post-processing event, it is also possible to post-processing event be not present.Parameter in each protocol data may be 0, it is also possible to
For one or more.When the parameter in protocol data may include parameter name, data length, default value, big small end mode and
Specially treated event.
It in embodiments of the present invention, can there are the events of specific purposes as specially treated event using some.For example, will
Encrypted event is as specially treated event.Specially treated event can pre-process event for agreement, namely carry out parameter processing
The event first carried out before;Specially treated event may be agreement post-processing event, namely hold after carrying out parameter processing
Capable event;The event that specially treated event executes when can also be processing parameter.
The coding method of the Modbus document of agreement provided in the embodiment of the present invention is illustrated below.
Referring to Fig.1, the embodiment of the invention provides a kind of coding methods of Modbus document of agreement, below by way of specific step
Suddenly it is described in detail.
Step S101, parameter needed for obtaining the first function code and corresponding transmission frame.
From in the above embodiment of the present invention it is found that in each protocol data include an one-to-one function code and
Several parameters.It includes an one-to-one function code and several parameters in frame that each, which sends,.In the embodiment of the present invention
In, for ease of description, several parameters sent in frame are referred to as parameter needed for sending frame.The number of parameter needed for sending frame can
Think 0, or one or more.The number of parameter needed for sending frame is related to control information entrained in frame is sent.
In specific implementation, the first function code can be used for identifying main equipment to the operational order from equipment.For example, master sets
The standby data read from the device, the then operational order that the first function code identifies are as follows: main equipment reads data from the device.Hair
Sending parameter needed for frame can be main equipment to the control parameter controlled from equipment, namely include master in parameter needed for sending frame
Equipment is to the parameter information controlled from equipment.For example, including address 0x0100 in parameter needed for sending frame, then mean to lead
It is the data in the register of 0x0100 that equipment, which reads address from the device,.
In practical applications, for main equipment to the different demands for control from equipment, the first function code and transmission frame institute
Need parameter can be different.
Parameter needed for the transmission frame is mapped and generates the first parameter object, and is stored in the first parameter word by step S102
In allusion quotation.
In specific implementation, getting needed for sending frame after parameter, can the parameter according to needed for sending frame generate the
One Parameter Dictionary.In the first Parameter Dictionary, may include send frame needed for parameter and with its one-to-one first parameter pair
As namely the first Parameter Dictionary be send frame needed for parameter and the first parameter object mapping relations one by one.
For example, parameter needed for sending frame includes parameter 1~5, then the mapping of the parameter needed for it will send frame generates the first parameter
When object, the first parameter object 1~5 can be generated, wherein parameter 1 is corresponding with the first parameter object 1, parameter 2 and the first parameter
Object 2 is corresponding, and so on, parameter 5 is corresponding with the first parameter object 5.
Step S103 searches the first functional object corresponding with first function code from preset function code dictionary.
In specific implementation, function code dictionary can be pre-generated.Briefly it is situated between to the generation of function code dictionary below
It continues.
Modbus document of agreement is read in advance, and Modbus document of agreement is parsed.To Modbus document of agreement
When being parsed, node reading device-dependent message first can be described from the equipment in Modbus document of agreement and saved.Later,
Protocol data is read from Modbus document of agreement.Due to may include a plurality of protocol data in Modbus document of agreement,
For each protocol data, one-to-one function (Function) object therewith can be generated.
The corresponding functional object of each protocol data is being got, the mapping that can establish functional object and function code is closed
System, systematic function code word allusion quotation.In function code dictionary, function code is key, and functional object is value.
In specific implementation, it is also possible to which there are some preset special treatment methods.For example, it is desired to certain data
It is encrypted, then can preset cipher processing method as special treatment method.For preset processing side
It can be established mapping relations with functional object in advance by method.Later, the corresponding functional object of special treatment method and function are established
The mapping relations of energy code, systematic function code word allusion quotation.
Function code dictionary is substantially the mapping relations one by one of function code and functional object, and function code is substantially an association
Discuss the abstract of data.
After getting the first function code in step s101, corresponding first function can be found from function code dictionary
It can object.
In specific implementation, the first functional object corresponding with the first function code is being searched from preset function code dictionary
When, it is understood that there may be the case where the first functional object corresponding with the first function code can not be found.When the nothing from function code dictionary
When method finds the first functional object corresponding with the first function code, it can be generated and report an error instruction and terminate coding process.
Step S104, the parameter description information of the parameter needed for reading the transmission frame in first functional object.
In specific implementation, it is directed to each functional object, parameter needed for being previously provided with corresponding transmission frame
Parameter description information.The description information of parameter needed for sending frame can retouch for what the attribute information to parameter needed for sending frame carried out
It states.
In embodiments of the present invention, the parameter description information of parameter needed for sending frame can refer to parameter needed for sending frame
The information that is described such as title, data length, default value, big small end format, specially treated event, do not include sending frame institute
Need the specific value of parameter.
Step S105, according to parameter description information ginseng needed for searching the transmission frame in first Parameter Dictionary
Number.
In specific implementation, the number of parameter needed for sending frame can be multiple.The number of the parameter needed for sending frame is
When multiple, the corresponding parameter description information of each parameter can be different.That is, the description information of parameter and parameter it
Between be it is one-to-one, by the description information of parameter, corresponding parameter can be found.
In embodiments of the present invention, corresponding can be found from the first Parameter Dictionary by parameter description information
One parameter object.
Step S106 determines corresponding positions of the data of first parameter object in the valid data for sending frame
It sets.
From in the above embodiment of the present invention it is found that including parameter name and parameter length in parameter description information.?
In specific implementation, it according to parameter name and parameter length, can determine that the data of the first parameter object are sending frame
Corresponding position in valid data.
For example, parameter needed for sending frame includes parameter 1~3.The corresponding parameter description information of parameter 1 includes: entitled ginseng
Number 1, length are 4 bytes;The corresponding parameter description information of parameter 2 include: entitled parameter 2, length be 3 bytes;Parameter 3 is corresponding
Parameter description information include: entitled parameter 3, length be 2 bytes.Then by the data of corresponding first parameter object 1 of parameter 1
The data of corresponding first parameter object 2 of parameter 2 are placed on transmission by 0~3 byte being placed in the valid data for sending frame
Corresponding first parameter object 3 of parameter 3 is placed in the valid data for sending frame by 4~6 bytes in the valid data of frame
7~8 bytes.
Step S107 is generated and is sent frame and be sent to from equipment.
In specific implementation, corresponding in the valid data that the data of the first parameter object are sequentially filled to transmission frame
After position, it can be carried out to from device address, the first function code, data length, the valid data for sending frame and check code
Combination generates and sends frame, completes cataloged procedure.After generating transmission frame, it can will send frame and be sent to accordingly from equipment.
In practical applications, can by from device address, the first function code, data length and send frame valid data
It is cumulative to carry out step-by-step, generates check code.It is understood that can also be using others verification code generating method come check code.
It should be noted that the method for generating check code when generation sends frame, verifies transmission frame when sending frame with reception
Method is related.
In specific implementation, before the parameter description information of the parameter needed for reading transmission frame in the first functional object,
It can also first judge whether there is and send frame pretreatment event.When there is no frame pretreatment event is sent, then can directly it hold
Row step S104;When there is transmission frame pretreatment event, then it can first carry out and send frame pretreatment event, and is pre- sending frame
After the completion of processing event executes, then execute step S104.
During sending frame pretreatment event and executing, it is also possible to exist and send the feelings that frame pretreatment event executes failure
Condition.When appearance sends the case where frame pretreatment event executes failure, it can be generated and report an error instruction and terminate coding process, namely
No longer execute step S104.
In specific implementation, before executing step S105, it can also determine whether there is transmission frame post-processing event.When
When there is no sending frame post-processing event, then step S105 can be directly executed;When there is transmission frame post-processing event, then may be used
To first carry out the frame post-processing event that sends, and after the completion of sending frame post-processing event execution, then execute step S105.
During sending frame post-processing event and executing, it is also possible to exist and send the feelings that frame post-processing event executes failure
Condition.When appearance sends the case where frame post-processing event executes failure, it can be generated and report an error instruction and terminate coding process, namely
No longer execute step S105.
In specific implementation, after step S105, namely corresponding first ginseng is being found from the first Parameter Dictionary
After number object, it is also possible to which there are preset specially treated events.For example, there is also the first parameter object progress to finding
Encryption event.When there are preset specially treated event, the data of the first parameter object found are updated.
From it is known that the coding method provided in the embodiment of the present invention, there is no to function in the above embodiment of the present invention
Parameter needed for the corresponding transmission frame of energy code carries out direct coding, but parameter mapping the first parameter pair of generation needed for sending frame
As.By obtaining the parameter description information in the corresponding functional object of function code, corresponding first parameter object data are found
And determine the corresponding position in the valid data for sending frame.Therefore for ginseng needed for the different corresponding transmission frames of function code
Number, can realize coding using same coding method.
And in the prior art, when being encoded for parameter needed for the different corresponding transmission frames of function code, need to adopt
With a variety of different coding methods.Accordingly, with respect to the prior art, the coding method provided in the embodiment of the present invention can be reduced
Using encoder complexity when Modbus protocol communication, coding error probability is reduced.
The coding method of the Modbus document of agreement provided in the embodiment of the present invention is illustrated below by citing.
Firstly, being illustrated by way of example to the generation of function code dictionary.
Before systematic function code word allusion quotation, specially treated event and corresponding ID can be first registered, by specially treated thing
Part and corresponding ID are stored in specially treated event dictionary.
For example, being followed successively by specially treated event 1, specially treated event 2 and special place there are three specially treated events
Director's part 3.The ID of specially treated event 1 is ID1, and the ID of specially treated event 2 is ID2, and the ID of specially treated event 3 is ID3,
Then in specially treated event dictionary, specially treated event 1 and ID1 map, and specially treated event 2 and ID2 map, specially treated
Event 3 and ID3 map.
In practical applications, RegProc function can be defined as registration specially treated event functions, pass through RegProc letter
Number registration specially treated event and corresponding ID.
Later, document of agreement is parsed.In practical applications, can define LoadProtocal function is to agreement
File is parsed.When calling LoadProtocal function, this means that being parsed to document of agreement.
When being parsed to document of agreement, node first can be described from the equipment in document of agreement and read equipment correlation letter
It ceases and saves.In practical applications, device-dependent message can be saved as to Device object.It, can in device-dependent message
To be arranged Device class, it is corresponding that Device class and equipment describe node, including device type, device address, default size end lattice
Formula sends the attributes such as frame structure object and receiving frame structure objects.
After the extraction and preservation for completing device-dependent message, protocol data is read from document of agreement.For every
One protocol data generates one-to-one functional object therewith.The mapping relations of functional object and function code are established, function is generated
It can code word allusion quotation.
Refer to when existing in the specially treated event of the pretreatment event of transmission frame or receiving frame, post-processing event and parameter
When fixed ID, for example, then generating corresponding function pair to specially treated event 1 when specifying ID1 in post-processing event
As.Later, the mapping relations of functional object and function code are established, are added into function code dictionary.
The coding method of the Modbus document of agreement provided in the embodiment of the present invention is illustrated below.
Referring to Fig. 2, the coding method of another Modbus document of agreement in the embodiment of the present invention is given.Below by way of
Specific steps are described in detail.
In embodiments of the present invention, when encoding to Modbus document of agreement, setting can be passed through
EncodeFrame function is realized.
Step S201, parameter needed for obtaining the corresponding transmission frame of the first function code.
Step S202, the mapping of the parameter according to needed for sending frame generate Paraval object.
In embodiments of the present invention, the first parameter object that the mapping of parameter needed for sending frame generates is Paraval object.?
After the parameter according to needed for sending frame generates Paraval object, by the mapping relations storage of parameter name and Paraval object to the
In one Parameter Dictionary.
In an embodiment of the present invention, using the static method GetParaval () of Paraval class, it will send needed for frame and join
Number is converted into Paraval object, and generates Paraval dictionary corresponding with parameter name needed for transmission frame.
Step S203 searches the first functional object corresponding with the first function code from preset function code dictionary.
In embodiments of the present invention, step S203 is referred to step S103, is not repeated herein.
Step S204 judges whether to find the first functional object.
In embodiments of the present invention, when finding the first functional object, step S205 is executed;When not finding the first function
When energy object, step S218 is executed.
Step S205 is judged whether there is and is sent frame pretreatment event.
In embodiments of the present invention, in each functional object, there are corresponding function code, send frame Decl class and
Three attributes of receiving frame Decl class.
It may include after sending frame pretreatment event id, sending frame pretreatment event, send frame in sending frame Decl class
The FuncPara list of parameter needed for handling event id, sending frame post-processing event and send frame.Parameter needed for sending frame
The parameter description information of parameter needed for FuncPara list can characterize transmission frame, title, number including parameter needed for sending frame
According to six attributes such as length, default value, big small end format, specially treated event id, specially treated events.For needed for transmission frame
There is one-to-one FuncPara list in each of parameter parameter.
When judging whether there is transmission frame pretreatment event, can judge whether to deposit from sending in the corresponding Decl class of frame
Event is pre-processed sending frame pretreatment event id and sending frame.When there is transmission frame pretreatment event, step is executed
S206;When there is no frame pretreatment event is sent, step S208 is executed.
Step S206 carries out pretreatment operation to the transmission frame.
Step S207, judges whether pretreatment operation runs succeeded.
When pretreatment operation runs succeeded, step S208 is executed;Otherwise, step S218 is executed.
Step S208, the parameter description information of the parameter needed for reading transmission frame in the first functional object.
In embodiments of the present invention, it can be read from the first functional object and send frame Decl class, and then available the
The FuncPara list of parameter needed for the corresponding transmission frame of one functional object.
Step S209 reads the number of corresponding Paraval object according to parameter description information from the first Parameter Dictionary
According to.
In embodiments of the present invention, the FuncPara list of the parameter according to needed for sending frame, reads from the first Parameter Dictionary
Take the data of corresponding Paraval object.
Step S210 judges whether there is specially treated event.
When there are specially treated event, step S211 is executed;When specially treated event is not present, step is executed
S212。
Step S211 is updated the data of the Paraval object found.
After the data to Paraval object are updated, step S212 is executed.
For example, existing specially treated event is encryption, then the data of Paraval object are encrypted.
The data of Paraval object are placed into the valid data corresponding position for sending frame by step S212.
That is, in embodiments of the present invention, when there are specially treated event, sending the valid data corresponding positions of frame
The data for setting placement are by updated data.
Step S213 judges whether there is frame post-processing event.
When judging whether there is transmission frame pretreatment event, can judge whether to deposit from sending in the corresponding Decl class of frame
Event is pre-processed sending frame pretreatment event id and sending frame.When post-processing event there are frame, step S214 is executed;When
When post-processing event there is no frame, step S216 is executed.
Step S214 carries out post-processing operation to frame is sent.
Step S215, judges whether post-processing operation runs succeeded.
When post-processing operation runs succeeded, step S216 is executed;When post-processing operation executes failure, step is executed
S218。
Step S216, according to the valid data for generating transmission frame from equipment essential information.
In embodiments of the present invention, in the data of the first parameter object to be sequentially filled to the valid data for sending frame
After corresponding position, can to from device address, the first function code, data length, send frame valid data and check code
It is combined, generates and send frame, complete cataloged procedure.
Step S217 will send frame and be sent to accordingly from equipment.
Step S218 returns to error message.
Referring to Fig. 3, the embodiment of the invention also provides a kind of coding/decoding methods of Modbus document of agreement, below by way of specific
Step is described in detail.
Step S301 receives the frame sent from equipment.
In specific implementation, it after equipment data needed for receiving the transmission frame that main equipment is sent, can be set to master
It is standby to return to return parameters corresponding with data needed for transmission frame.From equipment when sending return parameters to main equipment, it can pass through
The mode of data frame sends return parameters to main equipment.
Step S302 parses the valid data of the second function code and receiving frame from receiving frame.
In specific implementation, main equipment is receiving after the frame that equipment is sent, and can read from receiving frame from setting
Standby equipment essential information, namely know that current receiving frame is which sends from equipment.
In embodiments of the present invention, before being parsed to receiving frame, first receiving frame can be verified.It is receiving
When to the frame sent from equipment, check code can be got from receiving frame.To the data in receiving frame in addition to check code into
Row verification, generates check results.Check code present in check results and receiving frame by generation verifies, when the two is identical
When, judgement verifies successfully, can execute step S303;When the two difference, verification failure is determined, return to error message and terminate
Decoding process.
It, can be from the significant figure read in receiving frame in the second function code and receiving frame after receiving frame check success
According to the valid data in receiving frame are from the corresponding character array of equipment return parameters.
Step S303 searches the second functional object corresponding with second function code.
It in specific implementation, can be in preset function code dictionary after parsing the second function code in receiving frame
In, search the second functional object corresponding with the second function code.The generation of preset function code dictionary is referred in the present invention
The description in embodiment is stated, is not repeated herein.
Step S304 reads the parameter description information of the receiving frame from the second functional object.
In specific implementation, it for each functional object, is previously provided with the corresponding parameter for receiving frame parameter and retouches
State information.The parameter description information for receiving frame parameter can refer to that the title of frame parameter, data length, big small end lattice are received in docking
The information that formula, specially treated event etc. are described, but do not include the specific value for receiving frame parameter.
After finding the second functional object according to the second function code, you can learn that the corresponding receiving frame of the second functional object
Parameter description information.
Step S305, according to the parameter description information of the receiving frame, described in the valid data for determining the receiving frame
From the corresponding character array of equipment return parameters.
In specific implementation, according to the parameter name of return parameters, data length, big small end format etc. in receiving frame, i.e.,
It can determine the position of the corresponding character array of each return parameters in the valid data of receiving frame.The valid data of receiving frame are carried out
It divides, the corresponding character array of each return parameters in receiving frame can be obtained.
Step S306 described will generate the second parameter object from the corresponding character array mapping of equipment return parameters, and protect
There are in the second Parameter Dictionary.
It in specific implementation, can be by return parameters after getting the corresponding character data of each return parameters
Corresponding character array is mapped, and is generated the second parameter object and is stored in the second Parameter Dictionary.In the second Parameter Dictionary
In, the mapping relations that are stored between the second parameter object character array corresponding with return parameters.
Step S307 parses second Parameter Dictionary, obtains decoding result.
In specific implementation, the second parameter object is read out from the second Parameter Dictionary, can obtain the second parameter object
Corresponding character array.By parsing to character array, decoding result can be obtained.
The coding/decoding method of the Modbus document of agreement provided in the above embodiment of the present invention is said below by citing
It is bright.
Referring to Fig. 4, the coding/decoding method of another Modbus document of agreement in the embodiment of the present invention is given, below by way of
Specific steps are described in detail.
In an embodiment of the present invention, DecodeFrame function can be preset as decoding functions.To receiving
Modbus document of agreement when being decoded, call DecodeFrame function to be decoded.
Step S401 receives the frame sent from equipment.
Step S402, verifies receiving frame.
In embodiments of the present invention, receiving frame can be verified, check code is read out from receiving frame, to receiving frame
In data in addition to check code verified, obtained check results are compared with the check code read out.
For example, bit-wise addition can be carried out to all data in receiving frame in addition to check code, obtain and value is made
For check results, check results are compared with the check code read out.
Step S403, judges whether verification succeeds.
When check results are identical as the check code read out, judgement is verified successfully, executes step S404;Work as check results
With read out check code difference when, determine verification failure, execute step S419.
Step S404 parses the valid data of the second function code and receiving frame from receiving frame.
Step S405 searches the second functional object corresponding with the second function code from preset function code dictionary.
In embodiments of the present invention, it can be searched corresponding with the second function code using in pre-generated function code dictionary
The second functional object.
Step S406 judges whether there is receiving frame pretreatment event.
From it is found that in each functional object, there are corresponding function code, sending frame in the above embodiment of the present invention
Three attributes of Decl class and receiving frame Decl class.
It may include after receiving frame pre-processes event id, receiving frame pretreatment event, receiving frame in receiving frame Decl class
Handle event id, receiving frame post-processes the FuncPara list of return parameters in event and receiving frame.Ginseng is returned in receiving frame
Several FuncPara lists can characterize the parameter description information of return parameters in receiving frame, including return parameters title, data
Six attributes such as length, default value, big small end format, specially treated event id, specially treated event.For being returned in receiving frame
There is one-to-one FuncPara list in each of parameter parameter.
When judging whether there is receiving frame pretreatment event, can judge whether to deposit from the corresponding Decl class of receiving frame
Event id is pre-processed in receiving frame and receiving frame pre-processes event.When pre-processing event there are receiving frame, step is executed
S407;Conversely, executing step S409 when not receiving frame pretreatment event.
Step S407 carries out pretreatment operation to receiving frame.
Step S408, judges whether pretreatment operation runs succeeded.
When pretreatment operation runs succeeded, step S409 is executed;When pretreatment operation executes failure, step is executed
S419。
Step S409, from the parameter description information read in the second functional object in receiving frame.
In an embodiment of the present invention, receiving frame Decl class can be read from the second functional object, and then available
The corresponding FuncPara list of each return parameters in the corresponding receiving frame of second functional object.Each return parameters are corresponding
FuncPara list can characterize the parameter description information in receiving frame.
Step S410 is determined corresponding from equipment return parameters in the valid data of receiving frame according to parameter description information
Character array.
In embodiments of the present invention, it can be connect according to the information such as data length, big small end in FuncPara list, determination
Receive the position of the corresponding character array of return parameters in the valid data of frame.
Step S411 judges whether there is preset specially treated event.
When there are preset specially treated event, step S412 is executed;When specially treated event is not present, step is executed
Rapid S413.
Step S412 is updated from the corresponding character array of equipment return parameters.
Step S413 will generate the second parameter object from the corresponding character array mapping of equipment return parameters, and be stored in
In second Parameter Dictionary.
Step S414 judges whether there is receiving frame post-processing event.
When post-processing event there are receiving frame, step S415 is executed;Conversely, when there is no receiving frames to post-process event
When, execute step S417.
Step S415 carries out post-processing operation to receiving frame.
Step S416, judges whether post-processing operation runs succeeded.
When post-processing operation runs succeeded, step S417 is executed;When post-processing operation executes failure, step is executed
S419。
Step S417 returns to the second Parameter Dictionary.
Step S418 parses the second Parameter Dictionary, obtains decoding result.
Step S419 returns to error message.
After returning to error message, decoding operate process is exited.
It can be seen that receive from equipment send frame when, can first be parsed from receiving frame function code and
The valid data of receiving frame search corresponding functional object according to function code, to obtain the parameter description information in receiving frame.Root
According to the parameter description information in receiving frame, search from the corresponding character array of equipment return parameters, mapping generates the second parameter pair
As and be stored in the second Parameter Dictionary.By parsing to the second Parameter Dictionary, that is, it can reach decoding result.For difference
Slave equipment send frame or it is same from equipment send different frame, can adopt the same method and be decoded, without
It is decoded, therefore can reduced using solution when Modbus protocol communication using different decoding protocols for different receiving frames
Code complexity reduces decoding error probability.
Referring to Fig. 5, the embodiment of the invention provides a kind of encoder, the encoder be used for Modbus document of agreement into
Row coding, the Modbus document of agreement includes from equipment essential information and protocol data, and the encoder includes:
Acquiring unit 501, for parameter needed for obtaining the first function code and corresponding transmission frame;
First map unit 502 generates the first parameter object for mapping parameter needed for the transmission frame, and is stored in
In first Parameter Dictionary;
First searching unit 503, for searching corresponding with first function code the from preset function code dictionary
One functional object;
First reading unit 504, the parameter for the parameter needed for reading the transmission frame in first functional object
Description information;
Second searching unit 505, for the parameter description information of the parameter according to needed for the transmission frame, from first ginseng
Corresponding first parameter object is searched in digital allusion quotation;
First determination unit 506, for determining the data of first parameter object in the valid data for sending frame
In corresponding position;
First generation unit 507 sends frame for generating;
Transmission unit 508, for being sent to the transmission frame from equipment.
In specific implementation, the function code dictionary can generate in the following way: read the Modbus agreement text
Part;Protocol data in the Modbus document of agreement is parsed, is generated and the one-to-one function of the protocol data
Object;Preset special event processing method is read, is obtained and the preset one-to-one functional object of special event;Root
According to it is described with the one-to-one functional object of the protocol data and with the preset one-to-one function of special event
Object establishes the mapping relations of functional object and function code, generates the function code dictionary.
In specific implementation, the encoder can also include: the first updating unit 509, for searching described second
For unit 505 after searching corresponding first parameter object in first Parameter Dictionary, it is preset special to judge whether there is
Processing event;When there are the specially treated event, the data of first parameter object of correspondence found are carried out more
Newly.
In specific implementation, the encoder can also include: the first pretreatment unit (being not shown in Fig. 5), for working as
When in the presence of sending frame pretreatment event, pretreatment operation is carried out to the transmission frame.
In specific implementation, the encoder can also include: the first post-processing unit (being not shown in Fig. 5), for working as
When in the presence of sending frame post-processing event, post-processing operation is carried out to the transmission frame.
In specific implementation, first generation unit 507 can be used for according to described from equipment essential information, be described
The valid data for sending the data portion in frame, generate the transmission frame.
Referring to Fig. 6, a kind of decoder provided in the embodiment of the present invention is given, the decoder is used to assist Modbus
View file is decoded, comprising:
Receiving unit 601, for receiving the frame sent from equipment;
First resolution unit 602, for parsing the valid data of the second function code and receiving frame from receiving frame;
Third searching unit 603, for searching corresponding with second function code the from preset function code dictionary
Two functional objects;
Second reading unit 604, for reading the description letter of the parameter in the receiving frame from second functional object
Breath;
Second determination unit 605, for determining having for the receiving frame according to the parameter description information in the receiving frame
It imitates described in data from the corresponding character array of equipment return parameters;
Second generation unit 606, for described the second ginseng will to be generated from the corresponding character array mapping of equipment return parameters
Number object, and be stored in the second Parameter Dictionary;
Second resolution unit 607 obtains decoding result for parsing to second Parameter Dictionary.
In specific implementation, the decoder can also include: verification unit 608, in first resolution unit
602 before the valid data for parsing the second function code and receiving frame in receiving frame, verify the receiving frame.
In specific implementation, the decoder can also include: the second updating unit 609, for when there are preset spies
When different processing event, it is updated to described from the corresponding character array of equipment return parameters.
In specific implementation, the decoder can also include: the second pretreatment unit (being not shown in Fig. 6), for working as
When pre-processing event there are receiving frame, pretreatment operation is carried out to the receiving frame.
In specific implementation, the decoder can also include: the second post-processing unit (being not shown in Fig. 6), for working as
When post-processing event there are receiving frame, post-processing operation is carried out to the receiving frame.
In specific implementation, second resolution unit 607 can be used for from second Parameter Dictionary described in reading
Second parameter object;Obtain the corresponding character array of second parameter object;The character array is parsed, institute is obtained
State decoding result.
Those of ordinary skill in the art will appreciate that all or part of the steps in the various methods of above-described embodiment is can
It is completed with instructing relevant hardware by program, which can be stored in a computer readable storage medium, storage
Medium may include: ROM, RAM, disk or CD etc..
Although present disclosure is as above, present invention is not limited to this.Anyone skilled in the art are not departing from this
It in the spirit and scope of invention, can make various changes or modifications, therefore protection scope of the present invention should be with claim institute
Subject to the range of restriction.
Claims (24)
1. a kind of coding method of Modbus document of agreement, which is characterized in that the Modbus document of agreement includes from equipment base
This information and protocol data, the coding method include:
Parameter needed for obtaining the first function code and corresponding transmission frame;
Parameter needed for the transmission frame is mapped and generates the first parameter object, and is stored in the first Parameter Dictionary;
The first functional object corresponding with first function code is searched from preset function code dictionary;
The parameter description information of the parameter needed for reading transmission frame to be sent in first functional object;
According to the parameter description information of parameter needed for the transmission frame to be sent, looked into from preset first Parameter Dictionary
Look for corresponding first parameter object;
Determine corresponding position of the data of first parameter object in the valid data for sending frame;
It generates and sends frame and be sent to from equipment.
2. the coding method of Modbus document of agreement as described in claim 1, which is characterized in that the function code dictionary uses
As under type generates:
Read the Modbus document of agreement;
Protocol data in the Modbus document of agreement is parsed, is generated and the one-to-one function of the protocol data
Object;
Preset special event processing method is read, is obtained and the preset one-to-one functional object of special event;
It is corresponded according to the described and one-to-one functional object of the protocol data and with the preset special event
Functional object, establish the mapping relations of functional object and function code, generate the function code dictionary.
3. the coding method of Modbus document of agreement as described in claim 1, which is characterized in that from preset described first
After searching corresponding first parameter object in Parameter Dictionary, further includes:
Judge whether there is preset specially treated event;
When there are the specially treated event, the data of first parameter object of correspondence found are updated.
4. the coding method of Modbus document of agreement as described in claim 1, which is characterized in that from first function pair
Before the parameter description information of the parameter as needed for middle reading transmission frame to be sent, further includes:
It judges whether there is and sends frame pretreatment event;
When pre-processing event there are the transmission frame, pretreatment operation is carried out to the transmission frame to be sent.
5. the coding method of Modbus document of agreement as described in claim 1, which is characterized in that before generating transmission frame,
Further include:
It judges whether there is and sends frame post-processing event;
When post-processing event there are the transmission frame, post-processing operation is carried out to the transmission frame.
6. the coding method of Modbus document of agreement as described in claim 1, which is characterized in that the generation sends frame, packet
It includes: according to the valid data of the data portion from equipment essential information, in the transmission frame, generating the transmission frame.
7. a kind of coding/decoding method of Modbus document of agreement characterized by comprising
Receive the frame sent from equipment;
The valid data of the second function code and the receiving frame are parsed from receiving frame;
The second functional object corresponding with second function code is searched from preset function code dictionary;
The parameter description information in the receiving frame is read from second functional object;
According to the parameter description information in the receiving frame, determines to return described in the valid data of the receiving frame from equipment and join
The corresponding character array of number;
Described the second parameter object will be generated from the corresponding character array mapping of equipment return parameters, and be stored in the second parameter word
In allusion quotation;
Second Parameter Dictionary is parsed, decoding result is obtained.
8. the coding/decoding method of Modbus document of agreement as claimed in claim 7, which is characterized in that parsed from receiving frame
Before the valid data of second function code and the receiving frame, further includes:
The receiving frame is verified, and check results are judged;
When the check results are correct, execute and parse having for the second function code and the receiving frame from the receiving frame
Imitate the operation of data;
When the check results mistake, returns to error message and terminate decoding operate.
9. the coding/decoding method of Modbus document of agreement as claimed in claim 7, which is characterized in that described will returned from equipment
The corresponding character array mapping of parameter generates before the second parameter object, further includes:
Judge whether there is preset specially treated event;
When there are the preset specially treated event, carried out more to described from the corresponding character array of equipment return parameters
Newly.
10. the coding/decoding method of Modbus document of agreement as claimed in claim 7, which is characterized in that determining the receiving frame
Valid data described in front of the corresponding character array of equipment return parameters, further includes:
Judge whether there is receiving frame pretreatment event;
When pre-processing event there are the receiving frame, pretreatment operation is carried out to the receiving frame.
11. the coding/decoding method of Modbus document of agreement as claimed in claim 7, which is characterized in that second parameter
Before dictionary is parsed, further includes:
Judge whether there is receiving frame post-processing event;
When post-processing event there are the receiving frame, post-processing operation is carried out to the receiving frame.
12. the coding/decoding method of Modbus document of agreement as claimed in claim 7, which is characterized in that described to second ginseng
Digital allusion quotation is parsed, comprising:
Second parameter object is read from second Parameter Dictionary;
Obtain the corresponding character array of second parameter object;
The character array is parsed, the decoding result is obtained.
13. a kind of encoder, for being encoded to Modbus document of agreement, which is characterized in that the Modbus document of agreement
Including from equipment essential information and protocol data, the encoder includes:
Acquiring unit, for parameter needed for obtaining the first function code and corresponding transmission frame;
First map unit generates the first parameter object for mapping parameter needed for the transmission frame, and is stored in the first ginseng
In digital allusion quotation;
First searching unit, for searching the first function pair corresponding with first function code from preset function code dictionary
As;
First reading unit, the parameter description for the parameter needed for reading transmission frame to be sent in first functional object
Information;
Second searching unit, for the parameter description information of the parameter according to needed for the transmission frame to be sent, from preset institute
It states and searches corresponding first parameter object in the first Parameter Dictionary;
First determination unit, the data for determining first parameter object are corresponding in the valid data for sending frame
Position;
First generation unit sends frame for generating;
Transmission unit, for being sent to the transmission frame from equipment.
14. encoder as claimed in claim 13, which is characterized in that the function code dictionary generates in the following way: reading
Take the Modbus document of agreement;Protocol data in the Modbus document of agreement is parsed, is generated and the agreement
The one-to-one functional object of data;Preset special event processing method is read, is obtained and the preset special event one
One corresponding functional object;According to it is described with the one-to-one functional object of the protocol data and with it is described preset special
The one-to-one functional object of event, establishes the mapping relations of functional object and function code, generates the function code dictionary.
15. encoder as claimed in claim 13, which is characterized in that further include: the first updating unit, for described second
For searching unit after searching corresponding first parameter object in first Parameter Dictionary, it is preset special to judge whether there is
Processing event;When there are the specially treated event, the data of first parameter object of correspondence found are carried out more
Newly.
16. encoder as claimed in claim 13, which is characterized in that further include: the first pretreatment unit, for when in the presence of hair
When frame being sent to pre-process event, pretreatment operation is carried out to the transmission frame to be sent.
17. encoder as claimed in claim 13, which is characterized in that further include: the first post-processing unit, for when in the presence of hair
When frame being sent to post-process event, post-processing operation is carried out to the transmission frame.
18. encoder as claimed in claim 13, which is characterized in that first generation unit, for according to described from setting
Standby essential information, the valid data for sending the data portion in frame, generate the transmission frame.
19. a kind of decoder, for being decoded to Modbus document of agreement characterized by comprising
Receiving unit, for receiving the frame sent from equipment;
First resolution unit, for parsing the valid data of the second function code and the receiving frame from receiving frame;
Third searching unit, for searching the second function pair corresponding with second function code from preset function code dictionary
As;
Second reading unit, for reading the parameter description information in the receiving frame from second functional object;
Second determination unit, for determining the valid data of the receiving frame according to the parameter description information in the receiving frame
Described in from the corresponding character array of equipment return parameters;
Second generation unit, for described the second parameter object will to be generated from the corresponding character array mapping of equipment return parameters,
And it is stored in the second Parameter Dictionary;
Second resolution unit obtains decoding result for parsing to second Parameter Dictionary.
20. decoder as claimed in claim 19, which is characterized in that further include: verification unit, in first parsing
Unit verifies the receiving frame before the valid data for parsing the second function code and receiving frame in receiving frame.
21. decoder as claimed in claim 19, which is characterized in that further include: the second updating unit, for default when existing
Specially treated event when, be updated to described from the corresponding character array of equipment return parameters.
22. decoder as claimed in claim 19, which is characterized in that further include: the second pretreatment unit connects for working as to exist
When receiving frame pretreatment event, pretreatment operation is carried out to the receiving frame.
23. decoder as claimed in claim 19, which is characterized in that further include: the second post-processing unit connects for working as to exist
When receiving frame post-processing event, post-processing operation is carried out to the receiving frame.
24. decoder as claimed in claim 19, which is characterized in that second resolution unit, for joining from described second
Second parameter object is read in digital allusion quotation;Obtain the corresponding character array of second parameter object;To the number of characters
Group is parsed, and the decoding result is obtained.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201611177281.3A CN106712902B (en) | 2016-12-19 | 2016-12-19 | Coding, coding/decoding method and encoder, the decoder of Modbus document of agreement |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201611177281.3A CN106712902B (en) | 2016-12-19 | 2016-12-19 | Coding, coding/decoding method and encoder, the decoder of Modbus document of agreement |
Publications (2)
Publication Number | Publication Date |
---|---|
CN106712902A CN106712902A (en) | 2017-05-24 |
CN106712902B true CN106712902B (en) | 2019-09-27 |
Family
ID=58939243
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201611177281.3A Active CN106712902B (en) | 2016-12-19 | 2016-12-19 | Coding, coding/decoding method and encoder, the decoder of Modbus document of agreement |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN106712902B (en) |
Families Citing this family (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN109120477B (en) * | 2018-08-16 | 2021-09-24 | 广东芬尼克兹节能设备有限公司 | Dynamic analysis method, device, server and storage medium based on modbus protocol |
CN110198202B (en) * | 2019-06-03 | 2022-01-28 | 北京润科通用技术有限公司 | Method and device for checking AFDX (avionics full Duplex switched Ethernet) bus message data source |
CN113824621B (en) * | 2021-09-22 | 2023-04-14 | 石家庄通合电子科技股份有限公司 | CAN communication method based on signals and CAN controller |
CN113852531B (en) * | 2021-09-22 | 2022-11-15 | 河北通合新能源科技有限公司 | CAN communication method and CAN controller for function code matching |
CN114448685B (en) * | 2022-01-13 | 2023-11-03 | 绿盟科技集团股份有限公司 | Method and device for generating network protocol message protection strategy |
Citations (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN101702119A (en) * | 2009-09-01 | 2010-05-05 | 广州致远电子有限公司 | Device oriented programming technology and method |
EP2642693B1 (en) * | 2012-03-20 | 2014-12-10 | Schneider Electric Automation Gmbh | Method for connecting a switching assembly automation device in accordance with IEC61850 to an industrial automation field bus |
CN105450359A (en) * | 2015-10-14 | 2016-03-30 | 深圳市网通电子商务有限公司 | Methods for sending and receiving user-defined binary structured protocol data |
-
2016
- 2016-12-19 CN CN201611177281.3A patent/CN106712902B/en active Active
Patent Citations (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN101702119A (en) * | 2009-09-01 | 2010-05-05 | 广州致远电子有限公司 | Device oriented programming technology and method |
EP2642693B1 (en) * | 2012-03-20 | 2014-12-10 | Schneider Electric Automation Gmbh | Method for connecting a switching assembly automation device in accordance with IEC61850 to an industrial automation field bus |
CN105450359A (en) * | 2015-10-14 | 2016-03-30 | 深圳市网通电子商务有限公司 | Methods for sending and receiving user-defined binary structured protocol data |
Also Published As
Publication number | Publication date |
---|---|
CN106712902A (en) | 2017-05-24 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN106712902B (en) | Coding, coding/decoding method and encoder, the decoder of Modbus document of agreement | |
CN103618794B (en) | Method, terminal and the server of automated log on | |
US8091071B2 (en) | Method and system for template-based code generation | |
CN106970820A (en) | Code storage method and code storage | |
CN107168765A (en) | A kind of method and system of remote compilation software | |
CN105337950A (en) | Form filling method and related terminals | |
CN106776639B (en) | Data processing method and data processing device based on structured query language | |
CN106656998B (en) | server communication method and device | |
CN112732321B (en) | Firmware modification method, device, computer readable storage medium and equipment | |
CN110445815A (en) | A kind of industry control protocol depth analytic method | |
CN104252531A (en) | File type identification method and device | |
CN110990008B (en) | Page updating method and device, storage medium and electronic equipment | |
CN110489207A (en) | Verification method, apparatus and computer readable storage medium | |
CN108153528B (en) | Flow model expansion processing method and device, storage medium and electronic equipment | |
CN107273102A (en) | The generation method and device of mobile applications | |
CN107622201B (en) | A kind of Android platform clone's application program rapid detection method of anti-reinforcing | |
CN105550022B (en) | A kind for the treatment of method and apparatus of business datum | |
CN107832046A (en) | Data creation method and device | |
CN113342811A (en) | HBase table data processing method and device | |
CN107404464B (en) | Signaling decoding method and system | |
CN112800185B (en) | Method and device for generating and matching text of interface node in mobile terminal | |
CN117556391B (en) | Activation code generation method, electronic equipment activation method and device | |
CN109428885B (en) | Method and apparatus for protecting a device | |
Meng et al. | Automatic Generation of Security Protocol Implementations Written in Java from Abstract Specifications Proved in the Computational Model. | |
CN112925841B (en) | Distributed JDBC implementation method, device and computer-readable storage medium |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
GR01 | Patent grant | ||
GR01 | Patent grant |