CN106712902A - Modbus protocol file encoding method, Modbus protocol file decoding method, encoder and decoder - Google Patents

Modbus protocol file encoding method, Modbus protocol file decoding method, encoder and decoder Download PDF

Info

Publication number
CN106712902A
CN106712902A CN201611177281.3A CN201611177281A CN106712902A CN 106712902 A CN106712902 A CN 106712902A CN 201611177281 A CN201611177281 A CN 201611177281A CN 106712902 A CN106712902 A CN 106712902A
Authority
CN
China
Prior art keywords
parameter
frame
event
function code
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.)
Granted
Application number
CN201611177281.3A
Other languages
Chinese (zh)
Other versions
CN106712902B (en
Inventor
卢昊
裘巍
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Shanghai Eastsoft Microelectronics Co Ltd
Original Assignee
Shanghai Eastsoft Microelectronics Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Shanghai Eastsoft Microelectronics Co Ltd filed Critical Shanghai Eastsoft Microelectronics Co Ltd
Priority to CN201611177281.3A priority Critical patent/CN106712902B/en
Publication of CN106712902A publication Critical patent/CN106712902A/en
Application granted granted Critical
Publication of CN106712902B publication Critical patent/CN106712902B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L1/00Arrangements for detecting or preventing errors in the information received
    • H04L1/0001Systems modifying transmission characteristics according to link quality, e.g. power backoff
    • H04L1/0015Systems modifying transmission characteristics according to link quality, e.g. power backoff characterised by the adaptation strategy
    • H04L1/0016Systems 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
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L1/00Arrangements for detecting or preventing errors in the information received
    • H04L1/004Arrangements for detecting or preventing errors in the information received by using forward error control
    • H04L1/0056Systems characterized by the type of code used
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L1/00Arrangements for detecting or preventing errors in the information received
    • H04L1/004Arrangements for detecting or preventing errors in the information received by using forward error control
    • H04L1/0056Systems characterized by the type of code used
    • H04L1/0061Error detection codes
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L12/00Data switching networks
    • H04L12/28Data switching networks characterised by path configuration, e.g. LAN [Local Area Networks] or WAN [Wide Area Networks]
    • H04L12/40Bus networks
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L12/00Data switching networks
    • H04L12/28Data switching networks characterised by path configuration, e.g. LAN [Local Area Networks] or WAN [Wide Area Networks]
    • H04L12/40Bus networks
    • H04L2012/40208Bus networks characterized by the use of a particular bus standard
    • H04L2012/40228Modbus

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Quality & Reliability (AREA)
  • Compression, Expansion, Code Conversion, And Decoders (AREA)

Abstract

The invention relates to a Modbus protocol file encoding method, a Modbus protocol file decoding method, an encoder and a decoder. The Modbus protocol file encoding method comprises the steps of acquiring a first function code and a parameter required by a corresponding transmission frame; mapping the parameter required by the transmission frame so as to generate a parameter object, and storing the parameter object in a parameter dictionary; searching a first function object corresponding to the first function code from a preset function code dictionary; reading parameter description information of the parameter required by the transmission frame from the first function object; searching the corresponding parameter object from the parameter dictionary according to the parameter description information of the parameter required by the transmission frame; determining a corresponding position of data of the parameter object in valid data of the transmission frame; and generating a transmission frame and sending the transmission frame to a slave device. According to the scheme provided by the invention, the complexity of the encoding and decoding process when a Modbus protocol is adopted in communication can be reduced, and the error probability is reduced.

Description

The coding of Modbus document of agreement, coding/decoding method and encoder, decoder
Technical field
The present invention relates to protocol processes field, more particularly to a kind of coding of Modbus document of agreement, coding/decoding method and volume Code device, decoder.
Background technology
Modbus agreements are a kind of all-purpose languages being applied on electronic controller.By Modbus agreements, controller phase Between mutually, controller can realize communicating between network and other equipment.
Controller communication uses principal and subordinate's technology, i.e. main equipment initial interrogation, other slave units to be carried according to main equipment inquiry The data of confession make corresponding reaction.Modbus communication modes establish the form of main equipment inquiry:Slave unit address, function generation Code, all data to be sent and check code.Slave unit is receiveed the response to be carried out using Modbus communication modes, the slave unit Receive the response and include validating that the domain to be taken action, the data to be returned and check code.
PC main frames are a typical main equipments.PC softwares are when Modbus protocol communications are realized, it is necessary to be directed to the agreement Realize corresponding coding and decoding.It is required for being combined for the concrete composition structure of agreement in each coding function, The array manipulation for repeating is more, easily error.
The content of the invention
Present invention solves the technical problem that being to reduce complexity during using Modbus protocol communications during coding and decoding 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 slave unit essential information and protocol data, and the coding method includes:Obtain the first function code And parameter needed for corresponding transmission frame;By parameter mapping the first parameter object of generation needed for the transmission frame, and it is stored in the In one Parameter Dictionary;The first functional object corresponding with first function code is searched from default function code dictionary;From institute State the parameter description information that parameter needed for the transmission frame is read in the first functional object;The parameter according to 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 transmission frame valid data in relevant position;Generation sends frame and sends to slave unit.
Optionally, the function code dictionary is generated in the following way:Read 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;Read Default special event processing method, obtains and the default one-to-one functional object of special event;According to it is described with The one-to-one functional object of protocol data and with the default one-to-one functional object of special event, set up Functional object and the mapping relations of function code, generate the function code dictionary.
Optionally, after corresponding first parameter object is searched from first Parameter Dictionary, also include:Judgement is It is no to there is default specially treated event;When there is the specially treated event, to the parameter of correspondence first for finding The data of object are updated.
Optionally, read from first functional object it is described transmission frame needed for parameter parameter description information it Before, also include:Judge whether to send frame pretreatment event;When there is the transmission frame pretreatment event, to the hair Sending frame carries out pretreatment operation.
Optionally, before generation sends frame, also include:Judge whether to send frame post processing event;When existing When stating transmission frame post processing event, post-processing operation is carried out to the transmission frame.
Optionally, the generation sends frame, including:According to the data in the slave unit essential information, the transmission frame Partial valid data, generate the transmission frame.
The embodiment of the present invention additionally provides a kind of coding/decoding method of Modbus document of agreement, including:Slave unit is received to send Frame;The valid data of the second function code and the receiving frame are parsed from receiving frame;From default function code dictionary Search the second functional object corresponding with second function code;In reading the receiving frame from second functional object Parameter description information;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;By corresponding character array mapping the second parameter of generation of the slave unit return parameters Object, and be stored in the second Parameter Dictionary;Second Parameter Dictionary is parsed, decoded result is obtained.
Optionally, before the valid data of the second function code and the receiving frame are parsed from receiving frame, also wrap Include:The receiving frame is verified, and check results are judged;When the check results are correct, perform 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, Return to error message and terminate decoding operate.
Optionally, before by corresponding character array mapping the second parameter object of generation of the slave unit return parameters, Also include:Judge whether default specially treated event;When there is the default specially treated event, to it is described from The corresponding character array of equipment return parameters is updated.
Optionally, it is determined that the corresponding character array of slave unit return parameters described in the valid data of the receiving frame it Before, also include:Judge whether that receiving frame pre-processes event;When there is the receiving frame pretreatment event, connect to described Receiving frame carries out pretreatment operation.
Optionally, before being parsed to second Parameter Dictionary, also include:Locate after judging whether receiving frame Director's part;When there is the receiving frame post processing event, post-processing operation is carried out to the receiving frame.
Optionally, it is described that second Parameter Dictionary is parsed, including:Institute is read 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 decoded result.
A kind of encoder is the embodiment of the invention provides, for being encoded to Modbus document of agreement, the Modbus Document of agreement includes slave unit essential information and protocol data, and the encoder includes:Acquiring unit, for obtaining the first work( Can code and parameter needed for corresponding transmission frame;First map unit, for by parameter mapping generation the needed for the transmission frame One parameter object, and be stored in the first Parameter Dictionary;First searching unit, for from default 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 for sending parameter needed for frame;Second searching unit, for the parameter of the parameter according to needed for the transmission frame Description information, searches corresponding first parameter object from first Parameter Dictionary;First determining unit, it is described for determining Relevant position of the data of the first parameter object in the valid data of the transmission frame;First generation unit, sends out for generating Send frame;Transmitting element, for the transmission frame to be sent to slave unit.
Optionally, the function code dictionary is generated in the following way:Read 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;Read Default special event processing method, obtains and the default one-to-one functional object of special event;According to it is described with The one-to-one functional object of protocol data and with the default one-to-one functional object of special event, set up Functional object and the mapping relations of function code, generate the function code dictionary.
Optionally, the encoder also includes:First updating block, in second searching unit from described first Searched in Parameter Dictionary after corresponding first parameter object, judge whether default specially treated event;When existing When stating specially treated event, the data to the parameter object of correspondence first for finding are updated.
Optionally, the encoder also includes:First pretreatment unit, for when exist send frame pretreatment event when, Pretreatment operation is carried out to the transmission frame.
Optionally, the encoder also includes:First post-processing unit, for when exist send frame post processing event when, Post-processing operation is carried out to the transmission frame.
Optionally, first generation unit, for the data in the slave unit essential information, the transmission frame Partial valid data, generate the transmission frame.
The embodiment of the present invention additionally provides a kind of decoder, for being decoded to Modbus document of agreement, including:Receive Unit, the frame for receiving slave unit transmission;First resolution unit, for parsing the second function code and institute from receiving frame State the valid data of receiving frame;3rd searching unit, for being searched from default function code dictionary and second function code Corresponding second functional object;Second reading unit, for reading the ginseng in the receiving frame from second functional object Number description information;Second determining unit, for the parameter description information in the receiving frame, determines having for the receiving frame The corresponding character array of slave unit return parameters described in effect data;Second generation unit, joins for the slave unit to be returned Corresponding character array mapping the second parameter object of generation of number, and be stored in the second Parameter Dictionary;Second resolution unit, is used for Second Parameter Dictionary is parsed, decoded result is obtained.
Optionally, the decoder also includes:Verification unit, for being parsed from receiving frame in first resolution unit Before going out the valid data of the second function code and the receiving frame, the receiving frame is verified.
Optionally, the decoder also includes:Second updating block, for when there is default specially treated event, The corresponding character array of the slave unit return parameters is updated.
Optionally, the decoder also includes:Second pretreatment unit, for when exist receiving frame pretreatment event when, Pretreatment operation is carried out to the receiving frame.
Optionally, the decoder also includes:Second post-processing unit, for when exist receiving frame post processing 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 decoded result is obtained.
Compared with prior art, the technical scheme of the embodiment of the present invention has the advantages that:
When parameter needed for the different corresponding transmission frames of function code is encoded, ginseng needed for frame can will be first sent Number mapping the first parameter object of generation is simultaneously stored in the first Parameter Dictionary.Afterwards, the parameter of parameter is retouched according to needed for sending frame Information is stated, corresponding first parameter object is searched from the first Parameter Dictionary, determine that the first parameter object is sending the effective of frame The position of data, so as to generate transmission frame, completes encoding operation.Enter for parameter needed for the different corresponding transmission frames of function code During row coding, can be encoded using same coding method, and different codings need not be used for different function codes Agreement is encoded, and can reduce encoder complexity during using Modbus protocol communications, reduces coding error probability.
When the frame of slave unit transmission is received, function code and receiving frame can be first parsed from receiving frame has Effect data, search corresponding functional object, to obtain the parameter description information in receiving frame according to function code.According in receiving frame Parameter description information, search the corresponding character array of slave unit return parameters, mapping the second parameter object of generation is simultaneously stored in In second Parameter Dictionary.Parsed by the second Parameter Dictionary, you can reach decoded result.Sent out for different slave units The frame for sending, or the different frame that same slave unit sends, can adopt the same method and be decoded, and need not be for different Receiving frame is decoded using different decoding protocols, therefore can reduce decoding complex degree during using Modbus protocol communications, Reduce decoding error probability.
Brief description of the drawings
Fig. 1 is a kind of flow chart of the coding method of the Modbus document of agreement in the embodiment of the present invention;
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 a kind of flow chart of the coding/decoding method of the Modbus document of agreement in the embodiment of the present invention;
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 a kind of structural representation of the encoder in the embodiment of the present invention;
Fig. 6 is a kind of structural representation of the decoder in the embodiment of the present invention.
Specific embodiment
In the prior art, PC softwares are encoded accordingly when Modbus agreements are realized, it is necessary to be directed to every protocol realization And decoding.When being encoded to an agreement, the data that slave unit is needed are combined into respective symbols number according to agreement regulation Group, decoding is then the character array for exporting slave unit data according to needed for protocol analysis into PC softwares.PC softwares are at each It is required for being combined or parsing for the concrete composition structure of agreement in coding, decoding functions, number present in software code It is more according to operating, easily error.
In embodiments of the present invention, when parameter needed for the different corresponding transmission frames of function code is encoded, Will first send parameter mapping the first parameter object of generation needed for frame and be stored in the first Parameter Dictionary.Afterwards, 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 of the valid data for sending frame, so as to generate transmission frame, completes encoding operation.For different function code correspondences Transmission frame needed for parameter when being encoded, can be encoded using same coding method, and different work(need not be directed to Energy code is encoded using different coding protocols, can reduce encoder complexity during using Modbus protocol communications, is reduced and is compiled Code error probability.
It is understandable to enable above-mentioned purpose of the invention, feature and beneficial effect to become apparent, below in conjunction with the accompanying drawings 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 carried 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 can 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.
With reference to table 1, a kind of coded format of the Modbus document of agreement in the embodiment of the present invention 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 For optional, data length refers to the byte length of valid data.The byte length that frame head takes is 4 bytes, and device address accounts for Byte length is 1 byte, and the byte length that function code takes is 1 byte, and the byte length that data length takes is 2 words Section, the byte length of valid data is N byte, and verification code length is 2 bytes.In actual applications, in each frame, significant figure According to in frame carry useful information data, namely in a frame remove frame head, device address, function code, data length and Data outside 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 description;Another part is the description to protocol data, referred to as protocol data description.
In the description of equipment essential information, the description to equipment essential information can include device name, device type, number According to information such as default size end form and the basic structure, the basic structures of receiving frame that send frame.Send the basic structure of frame With the form that the basic structure of receiving frame is referred to offer in table 1.
In Modbus document of agreement, a plurality of protocol data can be included.In protocol data description, for each association , there is one-to-one function code, send structure, the structure of receiving frame of frame in view data.Sending frame can be by pretreatment thing Part, post processing event and parameter composition, receiving frame can also be made up of pretreatment event, post processing event and parameter.Hair Send the parameter in frame can be different from the parameter in receiving frame.
Each protocol data is directed to, the number of pretreatment event therein can be 0 or 1, namely may deposit In pretreatment event, it is also possible in the absence of pretreatment event;The number of post processing event can also be 0 or 1, namely may In the presence of post processing event, it is also possible in the absence of post processing event.Parameter in each protocol data may be 0, it is also possible to For one or more.When the parameter in protocol data can include parameter name, data length, default value, big small end mode and Specially treated event.
In embodiments of the present invention, some can be existed the event of specific purposes as specially treated event.For example, will Encrypted event is used as specially treated event.Specially treated event can pre-process event for agreement, namely carry out parameter processing The event for first carrying out before;Specially treated event can also post-process event for agreement, namely be held after parameter processing is carried out Capable event;The event that specially treated event is performed when can also be processing parameter.
The coding method of the Modbus document of agreement to being provided in the embodiment of the present invention below is illustrated.
Reference picture 1, the embodiment of the invention provides a kind of coding method of Modbus document of agreement, below by way of specific step Suddenly it is described in detail.
Step S101, obtains the first function code and parameter needed for corresponding transmission frame.
Knowable to from the above embodiment of the present invention, each protocol data include an one-to-one function code and Some parameters.Each includes an one-to-one function code and some parameters in sending frame.In the embodiment of the present invention In, for ease of description, some parameters sent in frame are referred to as to send parameter needed for frame.The number for sending parameter needed for frame can Think 0, or one or more.Send the number of parameter needed for frame related to control information entrained in transmission frame.
In specific implementation, the first function code can be used for identifying operational order of the main equipment to slave unit.For example, master sets For the data read in slave unit, then the operational order that the first function code is identified is:Main equipment reads the data in slave unit.Hair It can be the control parameter that is controlled to slave unit of main equipment to send parameter needed for frame, namely parameter needed for sending frame includes leading The parameter information that equipment is controlled to slave unit.For example, parameter needed for sending frame includes address 0x0100, then mean master Address is the data in the register of 0x0100 during equipment reads slave unit.
In actual applications, for main equipment to the different demands for control of slave unit, the first function code and frame institute is sent Need the parameter can be with difference.
Step S102, by parameter mapping the first parameter object of generation needed for the transmission frame, and is stored in the first parameter word In allusion quotation.
In specific implementation, get send frame needed for after parameter, can the parameter generation the according to needed for sending frame One Parameter Dictionary.In the first Parameter Dictionary, can include send frame needed for parameter and with its one-to-one first parameter pair As, namely the first Parameter Dictionary parameter and first parameter object for needed for sending frame mapping relations one by one.
For example, sending parameter needed for frame includes parameter 1~5, then parameter mapping the first parameter of generation needed for frame will be being sent During object, the first parameter object 1~5 can be generated, wherein, parameter 1 is corresponding with the first parameter object 1, the parameter of parameter 2 and first The correspondence of object 2, by that analogy, parameter 5 is corresponding with the first parameter object 5.
Step S103, searches the first functional object corresponding with first function code from default function code dictionary.
In specific implementation, function code dictionary can be previously generated.Generation to function code dictionary below is briefly situated between Continue.
Modbus document of agreement is read in advance, and Modbus document of agreement is parsed.To Modbus document of agreement When being parsed, first can describe node from the equipment in Modbus document of agreement and read device-dependent message and preserve.Afterwards, Protocol data is read from Modbus document of agreement.Due to potentially including a plurality of protocol data in Modbus document of agreement, therefore, 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, functional object can set up and closed with the mapping of function code 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 there are some special treatment methods set in advance.For example, it is desired to some data It is encrypted, then can presets cipher processing method as special treatment method.For treatment side set in advance Method, can set up mapping relations by it with functional object in advance.Afterwards, the corresponding functional object of special treatment method and work(are set up 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 the first function code is got in the step S101, you can corresponding first work(is found from function code dictionary Can object.
In specific implementation, the first functional object corresponding with the first function code is being searched from default function code dictionary When, it is understood that there may be the situation of the first functional object corresponding with the first function code cannot be found.When the nothing from function code dictionary When method finds the first functional object corresponding with the first function code, can generate report an error instruct and terminate encode flow.
Step S104, reads the parameter description information of parameter needed for the transmission frame from first functional object.
In specific implementation, each functional object is directed to, is previously provided with parameter needed for corresponding transmission frame Parameter description information.The description information for sending parameter needed for frame can be retouching that the attribute information to parameter needed for transmission frame is carried out State.
In embodiments of the present invention, the parameter description information for sending parameter needed for frame can refer to sending parameter needed for frame The information that is described such as title, data length, default value, big small end form, specially treated event, not including sending frame institute Need the concrete numerical value of parameter.
Step S105, joins according to needed for the parameter description information searches the transmission frame from first Parameter Dictionary Number.
In specific implementation, the number for sending parameter needed for frame can be multiple.The number of parameter is needed for frame is sent When multiple, the corresponding parameter description information of each parameter can be with difference.That is, the description information of parameter and parameter it Between be one-to-one, by the description information of parameter, you can find corresponding parameter.
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 of the transmission frame Put.
Knowable to from the above embodiment of the present invention, parameter name and parameter length are included in parameter description information. In specific implementation, can be according to parameter name and parameter length, it may be determined that the data of the first parameter object are sending frame Relevant position in valid data.
For example, sending parameter needed for frame includes parameter 1~3.The corresponding parameter description information of parameter 1 includes:Entitled ginseng Number 1, length is 4 bytes;The corresponding parameter description information of parameter 2 includes:Entitled parameter 2, length is 3 bytes;The correspondence of parameter 3 Parameter description information include:Entitled parameter 3, length is 2 bytes.Then by the data of corresponding first parameter object 1 of parameter 1 0~3 byte in the valid data for sending frame is placed on, the data of corresponding first parameter object 2 of parameter 2 are placed on transmission 4~6 bytes in the valid data of frame, corresponding first parameter object 3 of parameter 3 are placed in the valid data for sending frame 7~8 bytes.
Step S107, generation sends frame and sends to slave unit.
It is corresponding in the data of the first parameter object to be sequentially filled the valid data for sending frame in specific implementation After position, slave unit address, the first function code, data length, the valid data of transmission frame and check code can be carried out Combination, generation sends frame, completes cataloged procedure.After generation sends frame, can will send frame and send to corresponding slave unit.
In actual applications, can be by the valid data of slave unit address, the first function code, data length and transmission frame Carry out step-by-step to add up, generate 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 that check code is generated when generation sends frame, to sending what frame was verified when sending frame with reception Method is related.
In specific implementation, before the parameter description information of parameter needed for transmission frame is read from the first functional object, Can also first judge whether to send frame pretreatment event.When in the absence of frame pretreatment event is sent, then can directly hold Row step S104;When there is transmission frame pretreatment event, then transmission frame pretreatment event can be first carried out, and it is pre- frame is sent After the completion for the treatment of event is performed, then perform step S104.
During frame pretreatment event execution is sent, it is also possible to exist and send the feelings that frame pretreatment event performs failure Condition.When occur send frame pretreatment event perform failure situation when, can generate report an error instruct and terminate encode flow, namely No longer perform step S104.
In specific implementation, before step S105 is performed, can also determine whether there is transmission frame post processing event.When During in the absence of sending frame post processing event, then step S105 can be directly performed;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 frame post processing event execution is sent, then perform step S105.
During frame post processing event execution is sent, it is also possible to exist and send the feelings that frame post processing event performs failure Condition.When occur send frame post processing event perform failure situation when, can generate report an error instruct and terminate encode flow, namely No longer perform 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 there is default specially treated event.For example, the first parameter object also existed to finding is carried out Encryption event.When there is default specially treated event, the data of the first parameter object to finding are updated.
From the above embodiment of the present invention it is known that in the embodiment of the present invention provide coding method, not to work( Parameter needed for the corresponding transmission frame of energy code carries out direct coding, but will send parameter mapping needed for frame and generate the first parameter pair 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 relevant 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, it is necessary to adopt when being encoded for parameter needed for the different corresponding transmission frames of function code With various different coding methods.Accordingly, with respect to prior art, the coding method provided in the embodiment of the present invention can be reduced Encoder complexity during using Modbus protocol communications, reduces coding error probability.
The coding method of the Modbus document of agreement below by citing to being provided in the embodiment of the present invention is illustrated.
First, the generation by way of example to function code dictionary is illustrated.
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 storages are in specially treated event dictionary.
For example, in the presence of three specially treated events, being followed successively by specially treated event 1, specially treated event 2 and special place 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 maps with ID1, and specially treated event 2 maps with ID2, specially treated Event 3 maps with ID3.
In actual applications, it is registration specially treated event functions that can define RegProc functions, by RegProc letters Number registration specially treated event and corresponding ID.
Afterwards, document of agreement is parsed.In actual applications, it is to agreement that can define LoadProtocal functions File is parsed.When LoadProtocal functions are called, that is, mean to parse document of agreement.
When being parsed to document of agreement, first can describe node from the equipment in document of agreement and read the related letter of equipment Cease and preserve.In actual applications, device-dependent message can be saved as Device objects.In device-dependent message, can To set Device classes, it is corresponding that Device classes and equipment describe node, including device type, device address, default size end lattice Formula, the transmission attribute such as frame structure object and receiving frame structure objects.
After completing the extraction of device-dependent message and preserving, 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 set up, work(is generated Can code word allusion quotation.
Exist in the specially treated event of pretreatment event, post processing event and parameter of frame or receiving frame is sent and refer to During fixed ID, for example, when specifying ID1 in post processing event, then generating corresponding function pair to specially treated event 1 As.Afterwards, the mapping relations of functional object and function code are set up, is added into function code dictionary.
The coding method of the Modbus document of agreement to being provided in the embodiment of the present invention below is illustrated.
Reference picture 2, gives the coding method of another Modbus document of agreement in the embodiment of the present invention.Below by way of Specific steps are described in detail.
In embodiments of the present invention, when being encoded to Modbus document of agreement, can be by setting EncodeFrame functions are realized.
Step S201, obtains parameter needed for the corresponding transmission frame of the first function code.
Step S202, the parameter mapping generation Paraval objects according to needed for sending frame.
In embodiments of the present invention, the first parameter object for sending parameter mapping generation needed for frame is Paraval objects. After the parameter generation Paraval objects according to needed for sending frame, by the mapping relations storage of parameter name and Paraval objects to the In one Parameter Dictionary.
In an embodiment of the present invention, using static method GetParaval () of Paraval classes, ginseng needed for frame will be sent Number is converted into Paraval objects, and generates Paraval dictionaries corresponding with parameter name needed for frame is sent.
Step S203, searches the first functional object corresponding with the first function code from default function code dictionary.
In embodiments of the present invention, step S203 is referred to step S103, does not repeat herein.
Step S204, judges whether to find the first functional object.
In embodiments of the present invention, when the first functional object is found, step S205 is performed;When not finding the first work( During energy object, step S218 is performed.
Step S205, judges whether to send frame pretreatment event.
In embodiments of the present invention, in each functional object, exist corresponding function code, send frame Decl classes and Three attributes of receiving frame Decl classes.
After it can include transmission frame pretreatment event id, transmission frame pretreatment event in sending frame Decl classes, send frame Treatment event id, the FuncPara lists for sending frame post processing event and parameter needed for transmission frame.Send parameter needed for frame FuncPara lists can characterize the parameter description information for sending parameter needed for frame, including title, the number for sending parameter needed for frame According to six attributes such as length, default value, big small end form, specially treated event id, specially treated events.For needed for transmission frame Each parameter in parameter, in the presence of one-to-one FuncPara lists.
When judging whether to send frame pretreatment event, can judge whether to deposit from the corresponding Decl classes of frame are sent Send frame pretreatment event id and send frame pretreatment event.When there is transmission frame pretreatment event, step is performed S206;When in the absence of frame pretreatment event is sent, step S208 is performed.
Step S206, pretreatment operation is carried out to the transmission frame.
Step S207, judges whether pretreatment operation runs succeeded.
When pretreatment operation runs succeeded, step S208 is performed;Otherwise, step S218 is performed.
Step S208, reads the parameter description information for sending parameter needed for frame from the first functional object.
In embodiments of the present invention, transmission frame Decl classes can be read from the first functional object, and then the can be obtained The corresponding FuncPara lists for sending parameter needed for frame of one functional object.
Step S209, according to parameter description information, reads the number of corresponding Paraval objects from the first Parameter Dictionary According to.
In embodiments of the present invention, according to send frame needed for parameter FuncPara lists, from the first Parameter Dictionary read Take the data of corresponding Paraval objects.
Step S210, judges whether specially treated event.
When there is specially treated event, step S211 is performed;When in the absence of specially treated event, step is performed S212。
Step S211, the data of the Paraval objects to finding are updated.
After the data to Paraval objects are updated, step S212 is performed.
For example, the specially treated event for existing is encryption, then the data to Paraval objects are encrypted.
Step S212, the data of Paraval objects are placed into the valid data relevant position for sending frame.
That is, in embodiments of the present invention, when there is specially treated event, sending the valid data corresponding positions of frame The data for putting placement are by the data after renewal.
Step S213, judges whether that frame post-processes event.
When judging whether to send frame pretreatment event, can judge whether to deposit from the corresponding Decl classes of frame are sent Send frame pretreatment event id and send frame pretreatment event.When there is frame post processing event, step S214 is performed;When When post-processing event in the absence of frame, step S216 is performed.
Step S214, post-processing operation is carried out to sending frame.
Step S215, judges whether post-processing operation runs succeeded.
When post-processing operation runs succeeded, step S216 is performed;When post-processing operation performs failure, step is performed S218。
Step S216, the valid data of frame are sent according to the generation of slave unit essential information.
In embodiments of the present invention, in the data of the first parameter object to be sequentially filled the valid data for sending frame After relevant position, can to slave unit address, the first function code, data length, send frame valid data and check code It is combined, generation sends frame, completes cataloged procedure.
Step S217, will send frame and sends to corresponding slave unit.
Step S218, returns to error message.
Reference picture 3, the embodiment of the present invention additionally provides a kind of coding/decoding method of Modbus document of agreement, below by way of specific Step is described in detail.
Step S301, receives the frame that slave unit sends.
In specific implementation, slave unit can set after data needed for the transmission frame for receiving main equipment transmission to master It is standby to return to return parameters corresponding with data needed for frame are sent.Slave unit can pass through when return parameters are sent to main equipment 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 can read from setting after the frame for receiving slave unit transmission from receiving frame Standby equipment essential information, namely know that current receiving frame is which slave unit sends.
In embodiments of the present invention, before being parsed to receiving frame, first receiving frame can be verified.Receiving To slave unit send frame when, check code can be got from receiving frame.Data in receiving frame in addition to check code are entered Row verification, generates check results.The check results of generation and check code present in receiving frame are verified, when the two is identical When, judgement is verified successfully, can perform step S303;When the two is different, verification failure is judged, return to error message and terminate Decoding process.
After frame check success is received, the significant figure in the second function code and receiving frame can be read from receiving frame According to the valid data in receiving frame are the corresponding character array of slave unit return parameters.
Step S303, searches the second functional object corresponding with second function code.
In specific implementation, after the second function code is parsed from receiving frame, can be in default function code dictionary In, search the second functional object corresponding with the second function code.The generation of default 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, for each functional object, the parameter for being previously provided with corresponding reception frame parameter is retouched State information.The parameter description information for receiving frame parameter can refer to title, data length, the big small end lattice to receiving frame parameter The information that formula, specially treated event etc. are described, but do not include receiving the concrete numerical value of frame parameter.
After the second functional object is found according to the second function code, you can know the corresponding receiving frame of the second functional object Parameter description information.
Step S305, the parameter description information according to the receiving frame, determines described in the valid data of the receiving frame The corresponding character array of slave unit return parameters.
In specific implementation, according to the parameter name of return parameters, data length, big small end form etc. in receiving frame, i.e., Can determine that 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 Divide, you can obtain the corresponding character array of each return parameters in receiving frame.
Step S306, by corresponding character array mapping the second parameter object of generation of the slave unit return parameters, and protects In the presence of in the second Parameter Dictionary.
In specific implementation, after the corresponding character data of each return parameters is got, can be by 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 between second parameter object that is stored with character array corresponding with return parameters.
Step S307, parses to second Parameter Dictionary, obtains decoded result.
In specific implementation, the second parameter object is read out from the second Parameter Dictionary, you can obtain the second parameter object Corresponding character array.Parsed by character array, you can obtain decoded result.
The coding/decoding method of the Modbus document of agreement below by citing to being provided in the above embodiment of the present invention is said It is bright.
Reference picture 4, gives the coding/decoding method of another Modbus document of agreement in the embodiment of the present invention, below by way of Specific steps are described in detail.
In an embodiment of the present invention, DecodeFrame functions can be preset as decoding functions.To receiving Modbus document of agreement when being decoded, call DecodeFrame functions to be decoded.
Step S401, receives the frame that slave unit sends.
Step S402, verifies to 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, the check results that will be obtained are compared with the check code for reading 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 It is check results, check results is compared with the check code for reading out.
Step S403, judges whether verification succeeds.
When check results are identical with the check code for reading out, judgement is verified successfully, performs step S404;Work as check results When different from the check code for reading out, verification failure is judged, perform 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 default function code dictionary.
In embodiments of the present invention, in can be using the function code dictionary for previously generating, search corresponding with the second function code The second functional object.
Step S406, judges whether that receiving frame pre-processes event.
Knowable to from the above embodiment of the present invention, in each functional object, there is corresponding function code, send frame Three attributes of Decl classes and receiving frame Decl classes.
After receiving frame pretreatment event id, receiving frame pretreatment event, receiving frame can be included in receiving frame Decl classes Treatment event id, receiving frame post-process the FuncPara lists 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 form, specially treated event id, specially treated event.Returned in receiving frame Each parameter in parameter, in the presence of one-to-one FuncPara lists.
When receiving frame pretreatment event is judged whether, can judge whether to deposit from the corresponding Decl classes of receiving frame Event id and receiving frame pretreatment event are pre-processed in receiving frame.When there is receiving frame pretreatment event, step is performed S407;Conversely, when frame pretreatment event is not received, performing step S409.
Step S407, pretreatment operation is carried out to receiving frame.
Step S408, judges whether pretreatment operation runs succeeded.
When pretreatment operation runs succeeded, step S409 is performed;When pretreatment operation performs failure, step is performed S419。
Step S409, reads the parameter description information in receiving frame from the second functional object.
In an embodiment of the present invention, receiving frame Decl classes can be read from the second functional object, and then can be obtained The corresponding FuncPara lists of each return parameters in the corresponding receiving frame of second functional object.Each return parameters are corresponding FuncPara lists can characterize the parameter description information in receiving frame.
Step S410, according to parameter description information, slave unit return parameters are corresponding in determining the valid data of receiving frame Character array.
In embodiments of the present invention, can be according to information such as the data length in FuncPara lists, big small ends, it is determined that connecing Receive the position of the corresponding character array of return parameters in the valid data of frame.
Step S411, judges whether default specially treated event.
When there is default specially treated event, step S412 is performed;When in the absence of specially treated event, step is performed Rapid S413.
Step S412, updates the corresponding character array of slave unit return parameters.
Step S413, by corresponding character array mapping the second parameter object of generation of slave unit return parameters, and is stored in In second Parameter Dictionary.
Step S414, judges whether that receiving frame post-processes event.
When there is receiving frame post processing event, step S415 is performed;Conversely, when in the absence of receiving frame post processing event When, perform step S417.
Step S415, post-processing operation is carried out to receiving frame.
Step S416, judges whether post-processing operation runs succeeded.
When post-processing operation runs succeeded, step S417 is performed;When post-processing operation performs failure, step is performed S419。
Step S417, returns to the second Parameter Dictionary.
Step S418, parses to the second Parameter Dictionary, obtains decoded result.
Step S419, returns to error message.
After error message is returned, decoding operate flow is exited.
As can be seen here, receive slave unit transmission frame when, first can be parsed from receiving frame function code and The valid data of receiving frame, search corresponding functional object, to obtain the parameter description information in receiving frame according to function code.Root According to the parameter description information in receiving frame, the corresponding character array of slave unit return parameters, mapping the second parameter pair of generation are searched As and be stored in the second Parameter Dictionary.Parsed by the second Parameter Dictionary, you can reach decoded result.For difference The frame that sends of slave unit, or the different frame that same slave unit sends can adopt the same method and be decoded, and need not Solved when being decoded using different decoding protocols for different receiving frames, therefore can reduced using Modbus protocol communications Code complexity, reduces decoding error probability.
Reference picture 5, the embodiment of the invention provides a kind of encoder, and the encoder is used to enter Modbus document of agreement Row coding, the Modbus document of agreement includes slave unit essential information and protocol data, and the encoder includes:
Acquiring unit 501, for obtaining the first function code and parameter needed for corresponding transmission frame;
First map unit 502, for parameter mapping needed for the transmission frame to be generated into the first parameter object, and is stored in In first Parameter Dictionary;
First searching unit 503, for searching corresponding with first function code from default function code dictionary One functional object;
First reading unit 504, the parameter for reading parameter needed for the transmission frame from 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 the described first ginseng Corresponding first parameter object is searched in digital allusion quotation;
First determining unit 506, valid data of the data in the transmission frame for determining first parameter object In relevant position;
First generation unit 507, frame is sent for generating;
Transmitting element 508, for the transmission frame to be sent to slave unit.
In specific implementation, the function code dictionary can be generated in the following way:Read the Modbus agreements 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;Default special event processing method is read, is obtained and the default 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 default one-to-one function of special event Object, sets up the mapping relations of functional object and function code, generates the function code dictionary.
In specific implementation, the encoder can also include:First updating block 509, for being searched described second Unit 505 is searched after corresponding first parameter object from first Parameter Dictionary, and it is default special to judge whether Treatment event;When there is the specially treated event, the data to the parameter object of correspondence first for finding are carried out more Newly.
In specific implementation, the encoder can also include:First pretreatment unit (not shown in Fig. 5), for working as During 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:First post-processing unit (not shown in Fig. 5), for working as During 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 the slave unit essential information, described The valid data of the data division in frame are sent, the transmission frame is generated.
Reference picture 6, gives a kind of decoder provided in the embodiment of the present invention, and the decoder is used to assist Modbus View file is decoded, including:
Receiving unit 601, the frame for receiving slave unit transmission;
First resolution unit 602, the valid data for parsing the second function code and receiving frame from receiving frame;
3rd searching unit 603, for searching corresponding with second function code from default 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 determining unit 605, for the parameter description information in the receiving frame, determines having for the receiving frame The corresponding character array of slave unit return parameters described in effect data;
Second generation unit 606, for the corresponding character array mapping generation second of the slave unit return parameters to be joined Number object, and be stored in the second Parameter Dictionary;
Second resolution unit 607, for being parsed to second Parameter Dictionary, obtains decoded result.
In specific implementation, the decoder can also include:Verification unit 608, in first resolution unit Before 602 valid data that the second function code and receiving frame are parsed from receiving frame, the receiving frame is verified.
In specific implementation, the decoder can also include:, there is default spy for working as in the second updating block 609 During different treatment event, the corresponding character array of the slave unit return parameters is updated.
In specific implementation, the decoder can also include:Second pretreatment unit (not shown in Fig. 6), for working as When there is receiving frame pretreatment event, pretreatment operation is carried out to the receiving frame.
In specific implementation, the decoder can also include:Second post-processing unit (not shown in Fig. 6), for working as When there is receiving frame post processing event, post-processing operation is carried out to the receiving frame.
In specific implementation, second resolution unit 607 can be used for the reading from second Parameter Dictionary described Second parameter object;Obtain the corresponding character array of second parameter object;The character array is parsed, institute is obtained State decoded result.
One of ordinary skill in the art will appreciate that all or part of step in the various methods of above-described embodiment is can Completed with instructing the hardware of correlation by program, the program can be stored in a computer-readable recording medium, storage Medium can include:ROM, RAM, disk or CD etc..
Although present disclosure is as above, the present invention is not limited to this.Any those skilled in the art, are not departing from this 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 The scope of restriction is defined.

Claims (24)

1. a kind of coding method of Modbus document of agreement, it is characterised in that the Modbus document of agreement includes slave unit base This information and protocol data, the coding method include:
Obtain the first function code and parameter needed for corresponding transmission frame;
By parameter mapping the first parameter object of generation needed for the transmission frame, and it is stored in the first Parameter Dictionary;From default The first functional object corresponding with first function code is searched in function code dictionary;
The parameter description information of parameter needed for the transmission frame is read from first functional object;
The parameter description information of parameter according to needed for the transmission frame, searches corresponding first ginseng from first Parameter Dictionary Number object;
Determine relevant position of the data of first parameter object in the valid data of the transmission frame;
Generation sends frame and sends to slave unit.
2. the coding method of Modbus document of agreement as claimed in claim 1, it is characterised in that the function code dictionary is used Following manner is generated:
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;
Default special event processing method is read, is obtained and the default one-to-one functional object of special event;
Corresponded with the one-to-one functional object of the protocol data and with the default special event according to described Functional object, set up the mapping relations of functional object and function code, generate the function code dictionary.
3. the coding method of Modbus document of agreement as claimed in claim 1, it is characterised in that from first parameter word Searched in allusion quotation after corresponding first parameter object, also included:
Judge whether default specially treated event;
When there is the specially treated event, the data to the parameter object of correspondence first for finding are updated.
4. the coding method of Modbus document of agreement as claimed in claim 1, it is characterised in that from first function pair Before the parameter description information of parameter as needed for the middle reading transmission frame, also include:Judge whether to send frame pretreatment Event;
When there is the transmission frame pretreatment event, pretreatment operation is carried out to the transmission frame.
5. the coding method of Modbus document of agreement as claimed in claim 1, it is characterised in that before generation sends frame, Also include:
Judge whether to send frame post processing event;
When there is the transmission frame post processing event, post-processing operation is carried out to the transmission frame.
6. the coding method of Modbus document of agreement as claimed in claim 1, it is characterised in that the generation sends frame, bag Include:The valid data of the data division in the slave unit essential information, the transmission frame, generate the transmission frame.
7. a kind of coding/decoding method of Modbus document of agreement, it is characterised in that including:
Receive the frame that slave unit sends;
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 default function code dictionary;
The parameter description information in the receiving frame is read from second functional object;
Parameter description information in the receiving frame, determines that slave unit described in the valid data of the receiving frame returns to ginseng The corresponding character array of number;
By corresponding character array mapping the second parameter object of generation of the slave unit return parameters, and it is stored in the second parameter word In allusion quotation;
Second Parameter Dictionary is parsed, decoded result is obtained.
8. the coding/decoding method of Modbus document of agreement as claimed in claim 7, it is characterised in that parsed from receiving frame Before the valid data of the second function code and the receiving frame, also include:
The receiving frame is verified, and check results are judged;
When the check results are correct, execution parses having for the second function code and the receiving frame from the receiving frame Imitate the operation of data;
When the check results mistake, return to error message and terminate decoding operate.
9. the coding/decoding method of Modbus document of agreement as claimed in claim 7, it is characterised in that returned by the slave unit Before corresponding character array mapping the second parameter object of generation of parameter, also include:
Judge whether default specially treated event;
When there is the default specially treated event, the corresponding character array of the slave unit return parameters is carried out more Newly.
10. the coding/decoding method of Modbus document of agreement as claimed in claim 7, it is characterised in that it is determined that the receiving frame Valid data described in before the corresponding character array of slave unit return parameters, also include:Judge whether that receiving frame is pre- Treatment event;
When there is the receiving frame pretreatment event, pretreatment operation is carried out to the receiving frame.
The coding/decoding method of 11. Modbus document of agreement as claimed in claim 7, it is characterised in that to second parameter Before dictionary is parsed, also include:
Judge whether that receiving frame post-processes event;
When there is the receiving frame post processing event, post-processing operation is carried out to the receiving frame.
The coding/decoding method of 12. Modbus document of agreement as claimed in claim 7, it is characterised in that described to join to described second Digital allusion quotation is parsed, including:
Second parameter object is read from second Parameter Dictionary;
Obtain the corresponding character array of second parameter object;
The character array is parsed, the decoded result is obtained.
A kind of 13. encoders, for being encoded to Modbus document of agreement, it is characterised in that the Modbus document of agreement Including slave unit essential information and protocol data, the encoder includes:
Acquiring unit, for obtaining the first function code and parameter needed for corresponding transmission frame;
First map unit, for parameter mapping needed for the transmission frame to be generated into the first parameter object, 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 default function code dictionary As;
First reading unit, the parameter for reading parameter needed for the transmission frame from first functional object describes letter Breath;
Second searching unit, for the parameter description information of the parameter according to needed for the transmission frame, from first Parameter Dictionary It is middle to search corresponding first parameter object;
First determining unit, the data for determining first parameter object are corresponding in the valid data of the transmission frame Position;
First generation unit, frame is sent for generating;
Transmitting element, for the transmission frame to be sent to slave unit.
14. encoders as claimed in claim 13, it is characterised in that the function code dictionary is generated in the following way:Read 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;Default special event processing method is read, is obtained and the default special event one One corresponding functional object;According to described with the one-to-one functional object of the protocol data and default special with described The one-to-one functional object of event, sets up the mapping relations of functional object and function code, generates the function code dictionary.
15. encoders as claimed in claim 13, it is characterised in that also include:First updating block, for described second Searching unit is searched after corresponding first parameter object from first Parameter Dictionary, and it is default special to judge whether Treatment event;When there is the specially treated event, the data to the parameter object of correspondence first for finding are carried out more Newly.
16. encoders as claimed in claim 13, it is characterised in that also include:First pretreatment unit, for when in the presence of hair When sending frame to pre-process event, pretreatment operation is carried out to the transmission frame.
17. encoders as claimed in claim 13, it is characterised in that also include:First post-processing unit, for when in the presence of hair When sending frame to post-process event, post-processing operation is carried out to the transmission frame.
18. encoders as claimed in claim 13, it is characterised in that first generation unit, for according to described from setting The valid data of the data division in standby essential information, the transmission frame, generate the transmission frame.
19. a kind of decoders, for being decoded to Modbus document of agreement, it is characterised in that including:
Receiving unit, the frame for receiving slave unit transmission;
First resolution unit, the valid data for parsing the second function code and the receiving frame from receiving frame;
3rd searching unit, for searching the second function pair corresponding with second function code from default function code dictionary As;
Second reading unit, for reading the parameter description information in the receiving frame from second functional object;
Second determining unit, for the parameter description information in the receiving frame, determines the valid data of the receiving frame Described in the corresponding character array of slave unit return parameters;
Second generation unit, for the corresponding character array mapping of the slave unit return parameters to be generated into the second parameter object, And be stored in the second Parameter Dictionary;
Second resolution unit, for being parsed to second Parameter Dictionary, obtains decoded result.
20. decoders as claimed in claim 19, it is characterised in that also include:Verification unit, in the described first parsing Before unit parses the valid data of the second function code and receiving frame from receiving frame, the receiving frame is verified.
21. decoders as claimed in claim 19, it is characterised in that also include:Second updating block, for default when existing Specially treated event when, the corresponding character array of the slave unit return parameters is updated.
22. decoders as claimed in claim 19, it is characterised in that also include:Second pretreatment unit, connects for working as to exist When receiving frame pretreatment event, pretreatment operation is carried out to the receiving frame.
23. decoders as claimed in claim 19, it is characterised in that also include: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. decoders as claimed in claim 19, it is characterised 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 obtains the decoded result.
CN201611177281.3A 2016-12-19 2016-12-19 Coding, coding/decoding method and encoder, the decoder of Modbus document of agreement Active CN106712902B (en)

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 true CN106712902A (en) 2017-05-24
CN106712902B 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)

Cited By (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109120477A (en) * 2018-08-16 2019-01-01 广东芬尼克兹节能设备有限公司 Dynamic analysis method, apparatus, server and storage medium based on modbus agreement
CN110198202A (en) * 2019-06-03 2019-09-03 北京润科通用技术有限公司 A kind of method of calibration and device of AFDX bus message data source
CN113824621A (en) * 2021-09-22 2021-12-21 石家庄通合电子科技股份有限公司 CAN communication method based on signals and CAN controller
CN113852531A (en) * 2021-09-22 2021-12-28 石家庄通合电子科技股份有限公司 CAN communication method and CAN controller for function code matching
CN114448685A (en) * 2022-01-13 2022-05-06 绿盟科技集团股份有限公司 Method and device for generating network protocol message protection strategy

Citations (3)

* Cited by examiner, † Cited by third party
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

Patent Citations (3)

* Cited by examiner, † Cited by third party
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

Cited By (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109120477A (en) * 2018-08-16 2019-01-01 广东芬尼克兹节能设备有限公司 Dynamic analysis method, apparatus, server and storage medium based on modbus agreement
CN109120477B (en) * 2018-08-16 2021-09-24 广东芬尼克兹节能设备有限公司 Dynamic analysis method, device, server and storage medium based on modbus protocol
CN110198202A (en) * 2019-06-03 2019-09-03 北京润科通用技术有限公司 A kind of method of calibration and device of AFDX bus message data source
CN110198202B (en) * 2019-06-03 2022-01-28 北京润科通用技术有限公司 Method and device for checking AFDX (avionics full Duplex switched Ethernet) bus message data source
CN113824621A (en) * 2021-09-22 2021-12-21 石家庄通合电子科技股份有限公司 CAN communication method based on signals and CAN controller
CN113852531A (en) * 2021-09-22 2021-12-28 石家庄通合电子科技股份有限公司 CAN communication method and CAN controller for function code matching
CN113852531B (en) * 2021-09-22 2022-11-15 河北通合新能源科技有限公司 CAN communication method and CAN controller for function code matching
CN114448685A (en) * 2022-01-13 2022-05-06 绿盟科技集团股份有限公司 Method and device for generating network protocol message protection strategy
CN114448685B (en) * 2022-01-13 2023-11-03 绿盟科技集团股份有限公司 Method and device for generating network protocol message protection strategy

Also Published As

Publication number Publication date
CN106712902B (en) 2019-09-27

Similar Documents

Publication Publication Date Title
CN106712902A (en) Modbus protocol file encoding method, Modbus protocol file decoding method, encoder and decoder
CN103618794B (en) Method, terminal and the server of automated log on
US8155683B2 (en) Physical downlink control channel specific scrambling
CN104660726B (en) Network collocating method, the apparatus and system of smart machine
CN109617680A (en) Encryption method, device, equipment and medium
US9529932B2 (en) XML node labeling and querying using logical operators
CN1943203A (en) A method for verifying a first identity and a second identity of an entity
EP3614568A1 (en) Encoding method and device
CN103475577A (en) Method, device and network equipment for obtaining characteristic information
CN109257764B (en) User portrait data processing method and device
Allamigeon et al. Reconstruction of attacks against cryptographic protocols
CN112948083B (en) Data processing method and device and electronic equipment
CN107168765A (en) A kind of method and system of remote compilation software
CN109286933B (en) Authentication method, device, system, computer equipment and storage medium
KR20070010048A (en) Method of and system for storage of i-wlan temporary indentities
CN110990008B (en) Page updating method and device, storage medium and electronic equipment
CN112130830A (en) Interface generation method and device and electronic equipment
CN108153528B (en) Flow model expansion processing method and device, storage medium and electronic equipment
CN116886391A (en) Internet of things equipment authentication method and device, storage medium and electronic equipment
Norman et al. Model checking the probabilistic pi-calculus
CN112118564A (en) Method, system and computer program product for generating a personalized profile package
CN107273102A (en) The generation method and device of mobile applications
CN102957494B (en) Method for blind test calibration and related devices
CN113364821B (en) Function service access method, equipment and storage medium
KR20190082542A (en) Method, system and apparatus for generating source code from table and using the same

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