Summary of the invention
Task of the present invention provides a kind of MODBUS-RTU protocol conformance test method, solves the problem of testing the realization of an authentication function in the past and ignoring agreement test itself.
For finishing above-mentioned task, in the present invention, utilize realization that the protocol test instrument checks agreement whether with conformance to standard, utilize tester to apply of ac, the auxiliary checking of finishing application function and data correctness, content measurement comprises the checking of uniformity test, application function and the data correctness of agreement, and wherein testing protocol consistency comprises the proper testing of link layer, function code, data field and negates test.This method of testing has provided system of Modbus-RTU agreement, comprehensive content measurement and method of testing, and guarantee agreement is realized that consistency and interoperability have very important significance.
The concrete steps of MODBUS-RTU protocol conformance test method of the present invention are as follows:
The first step: fill in Modbus-RTU protocol conformance statement table;
Second step: according to Fig. 1 test system building;
The 3rd step: communication interface test;
The 4th step: communication baud rate test;
The 5th step: link layer test;
The 6th step: the proper testing of function code 01 (read coil);
The 7th step: the negative test of function code 01 (read coil);
The 8th step: the proper testing of function code 02 (reading the discrete magnitude input);
The 9th step: the negative test of function code 02 (reading the discrete magnitude input);
The tenth step: the proper testing of function code 03 (reading to keep register);
The 11 step: the negative test of function code 03 (reading to keep register);
The 12 step: the proper testing of function code 04 (reading input register);
The 13 step: the negative test of function code 04 (reading input register);
The 14 step: the proper testing of function code 05 (writing single coil);
The 15 step: the negative test of function code 05 (writing single coil);
The 16 step: the proper testing of function code 06 (writing single register);
The 17 step: the negative test of function code 06 (writing single register);
The 18 step: the proper testing of function code 07 (reading abnormality);
The 19 step: the proper testing of function code 08 (diagnostic function);
The 20 step: the negative test of function code 08 (diagnostic function);
The 21 step: the proper testing of function code 11 (obtaining the communication event counter);
The 22 step: the proper testing of function code 12 (obtaining the communication event record)
The 23 step: the proper testing of function code 15 (writing a plurality of coils);
The 24 step: the negative test of function code 15 (writing a plurality of coils);
The 25 step: the proper testing of function code 16 (writing a plurality of registers);
The 26 step: the negative test of function code 16 (writing a plurality of registers);
The 27 step: the proper testing of function code 17 (report substation ID);
The 28 step: the proper testing of function code 20/6 (reading file logging);
The 29 step: the negative test of function code 20/6 (reading file logging);
The 30 step: the proper testing of function code 21/6 (written document record);
The 31 step: the negative test of function code 21/6 (written document record);
The 32 step: the proper testing of function code 22 (masked-write register);
The 33 step: the negative test of function code 22 (masked-write register);
The 34 step: the proper testing of function code 23 (a plurality of registers of read/write);
The 35 step: the negative test of function code 23 (a plurality of registers of read/write);
The 36 step: the proper testing of function code 24 (reading fifo queue);
The 37 step: the negative test of function code 24 (reading fifo queue);
The 38 step: the proper testing of function code 43/14 (reading device identification);
The 39 step: function code 43/14 (reading device identification) negates test;
The 40 step: the not test of support function sign indicating number;
The 41 step: the test of data field;
The 42 step: the test of application function;
The 43 step: the test of data correctness.
In detail comprehensively content measurement has been formulated in the invention of this method of testing, and utilize special protocol test instrument to help through testing protocol consistency, content measurement comprises the checking of uniformity test, application function and the data correctness of agreement, and wherein testing protocol consistency comprises the proper testing of link layer, function code, data field and negates test.This method of testing has provided system of Modbus-RTU agreement, comprehensive content measurement and method of testing, and guarantee agreement is realized that consistency and interoperability have very important significance.
Major advantage of the present invention is as follows:
1) content measurement is comprehensive, and content measurement comprises the checking of uniformity test, application function and the data correctness of agreement, and wherein testing protocol consistency comprises the proper testing of link layer, function code, data field and negates test.This method of testing has provided system of Modbus-RTU agreement, comprehensive content measurement and method of testing, comes guarantee agreement to realize consistency and interoperability;
2) special modbus-RTU protocol test instrument uses special protocol test instrument more to help finding mistake in the protocol massages.
Embodiment
This method of testing mainly comprises the following aspects:
1) content measurement
A) transmission mode is mainly examined or check in link layer test, the message frame form, and address field, check code and link transmission state guarantee that at link layer device can provide correct response, and can normally move under the normal and abnormal conditions;
B) form of function code and the requirement whether transmission course satisfies standard are mainly examined or check in function code test, and when function code was unusual, whether device can exception response;
C) form of data field and the requirement whether data satisfy standard are mainly examined or check in data field test;
D) application function test, on the basis that protocol conformance realizes, whether examination device application function is correctly realized;
E) data correctness test, on the basis that protocol conformance realizes, whether the data of sending on the examination device are correct.
Detailed test item is seen for oneself Fig. 1 table.
2) protocol test instrument
The protocol test instrument can send the various command frame according to the needs simulation of test, receives the response frame of equipment under test, and message is carried out analysis and judgement.
3) test system structure figure sees Fig. 2
4) protocol conformance test method
A) at first equipment under test need provide the communication protocol explanation and fill in Modbus-RTU protocol conformance statement table, Modbus-RTU protocol conformance statement table is the basis of whole testing protocol consistency, a lot of test events are to select according to the content of Declaration of Consistency, and Modbus-RTU protocol conformance statement table is seen appendix;
B) according to Fig. 2 test system building;
C) communication interface of tape deck;
D) traffic rate of adjustment protocol test instrument is consistent with the traffic rate of equipment under test, utilizes testing tool to send correct order, checks the communication message that equipment under test is responded, and detects and whether supports this traffic rate; According to MODBUS-RTU protocol conformance statement table, the traffic rate of each support of retest;
E) link layer test:
I) utilize the protocol test instrument to send correct communication message, comprise correct address, correct frame format, correct check code checks whether the frame format that can equipment under test correctly respond and respond is correct;
Ii) utilize in the communication message of protocol test instrument transmission, address error checks whether equipment under test does not respond;
The frame format unusual (multibyte or few byte) of iii) utilizing the protocol test instrument to send checks whether equipment under test abandons this frame information;
The check code mistake of iv) utilizing the protocol test instrument to send checks whether equipment under test abandons this frame;
V) utilize the protocol test instrument to send the broadcasting command of read command, check whether equipment under test responds;
Vi) utilize the protocol test instrument to send the broadcasting command of write order, check whether equipment under test responds.
F) function code test
The test of function code mainly is divided into the test of support function sign indicating number and the test of non-support function sign indicating number, can learn according to MODBUS-RTU protocol conformance statement table which function code equipment under test supports.
I) proper testing of support function sign indicating number
(1) proper testing of function code 01 (read coil), protocol test instrument sending function sign indicating number 01 reads 1-2000 continuous coil state, checks whether equipment under test is responded with function code 01, and goes up the sending coil current state; If the coil quantity of returning is not 8 multiple, will be with the remaining bit of zero padding final data byte (until high order end of byte);
(2) proper testing of function code 02 (read discrete magnitude input), protocol test instrument send with function code 02 and read 1-2000 continuous discrete magnitude input state, check whether equipment under test is responded with function code 02, and on send discrete magnitude to import current state; If the input quantity of returning is not 8 multiple, will be with the remaining bit (high order end of byte always) of zero padding final data byte;
(3) proper testing of function code 03 (reading to keep register), protocol test instrument sending function sign indicating number 03 reads one or more maintenance register currencys, check whether equipment under test is responded with function code 03, and on send the register currency, the register data in response message is packaged into each register two bytes;
(4) proper testing of function code 04 (reading input register), protocol test instrument sending function sign indicating number 03 reads one or more maintenance register currencys, check whether equipment under test is responded with function code 03, and on send the register currency, the register data in response message is packaged into each register two bytes;
(5) proper testing of function code 05 (writing single coil), protocol test instrument sending function sign indicating number the last 05 put the on off operating mode of a coil, and equipment under test is responded the frame message identical with claim frame behind the write coil state;
(6) proper testing of function code 06 (writing single register), the value that protocol test instrument sending function sign indicating number 06 is put single register checks whether equipment under test responds the frame message identical with claim frame after writing the content of register;
(7) proper testing of function code 07 (reading abnormality), protocol test instrument sending function sign indicating number 07 reads the content of 8 abnormality outputs, check whether equipment under test responds with function code 07, and in response frame, comprise the content of 8 abnormalities output, these outputs are packaged into a byte, each position of abnormality output;
(8) proper testing of function code 08 (diagnostic function), protocol test instrument sending function sign indicating number 08 provides a series of tests, be used for checking the communication system between main website and the substation or the various error states of substation, in claim frame, comprise a sub-function code and define the performed test-types in substation, check equipment under test whether application function sign indicating number 08 and the subfunction sign indicating number response identical with claim frame;
(9) proper testing of function code 11 (obtaining the communication event counter), protocol test instrument sending function sign indicating number 11 obtains status word and event count from equipment under test communication event counter, check whether equipment under test responds with function code 11;
(10) proper testing of function code 12 (obtaining the communication event record), protocol test instrument sending function sign indicating number 12 obtains status word, event count, packet counting and an incident byte field from equipment under test, checks whether equipment under test uses function code 12 responses;
(11) proper testing of function code 15 (writing a plurality of coils), protocol test instrument sending function sign indicating number 15 is put the on off operating mode of a plurality of coils, check whether application function sign indicating number 15 of equipment under test, the same in the register address that comprises in the response frame, register quantity and the claim frame;
(12) proper testing of function code 16 (writing a plurality of registers), the value that protocol test instrument sending function sign indicating number 16 is put a plurality of continuous registers, check whether application function sign indicating number 16 responses of equipment under test, the same in the register address that comprises in the response frame, register quantity and the received frame;
(13) proper testing of function code 17 (report substation ID), protocol test instrument sending function sign indicating number 17 reads the specific type specification of equipment under test, current state and other information, check whether equipment under test responds with function code 17, and in response frame, comprise equipment under test ID, operation indicating status and additional data;
(14) proper testing of function code 20/6 (reading file logging), protocol test instrument sending function sign indicating number 20 reads file logging, check that whether application function sign indicating number 20/6 responds equipment under test, comprises each sub-request responding (" 6 " refer to parameter type) in response frame;
(15) proper testing of function code 21/6 (written document record), protocol test instrument sending function sign indicating number 21/6 writes file logging, checks whether application function sign indicating number 21/6 responds equipment under test, and normal response is duplicate (" 6 " expression parameter type) of request;
(16) proper testing of function code 22 (masked-write register), protocol test instrument sending function sign indicating number 22 masked-write registers check whether application function sign indicating number 22 responds equipment under test, and normal response is duplicating of request;
(17) proper testing of function code 23 (a plurality of registers of read/write), protocol test instrument sending function sign indicating number 23 is finished the combination of read operation and write operation, checks whether application function sign indicating number 23 responds equipment under test, and normal response should comprise institute's read register data;
(18) proper testing of function code 24 (reading fifo queue), protocol test instrument sending function sign indicating number 24 reads first-in first-out in the equipment under test (FIFO) register queue content, this function can be read 32 registers at most: counting adds the data register of maximum 31 formations, checks whether equipment under test responds with function code 24;
(19) proper testing of function code 43/14 (reading device identification), protocol test instrument sending function sign indicating number 43/14 reads physics sign and the additional information relevant with functional description of equipment under test, wherein 14 expression MEI types check whether equipment under test responds with function code 43;
The ii) negative test of support function sign indicating number
(1) the negative test of function code 01 (read coil)
Protocol test instrument sending function sign indicating number 01 read coil quantity is not in 1~2000 scope, check whether equipment under test gives an exception response with function code 81H, and it is invalid to comprise the coil quantity that an abnormality code 03 expression reads in response frame, i.e. the invalid data value;
Protocol test instrument sending function sign indicating number 01 reads the coil state of one group of invalid address, checks whether equipment under test gives an exception response with function code 81H, and comprises an abnormality code 02 represent it is illegal data address in response frame;
(2) the negative test of function code 02 (reading the discrete magnitude input)
Protocol test instrument sending function sign indicating number 02 reads discrete magnitude input quantity not in 1~2000 scope, check whether equipment under test gives an exception response with function code 82H, and it is invalid to comprise the discrete magnitude input quantity that an abnormality code 03 expression reads in response frame, i.e. the invalid data value;
Protocol test instrument sending function sign indicating number 02 reads the discrete magnitude input state of one group of invalid address, checks whether equipment under test gives an exception response with function code 82H, and comprises an abnormality code 02 represent it is illegal data address in response frame;
(3) the negative test of function code 03 (reading to keep register)
The maintenance register quantity that protocol test instrument sending function sign indicating number 03 reads is not in 1~125 scope, check whether equipment under test gives an exception response with function code 83H, and it is invalid to comprise the maintenance register quantity that an abnormality code 03 expression reads in response frame, i.e. the invalid data value;
Protocol test instrument sending function sign indicating number 03 reads one group of invalid address and keeps the register currency, checks whether equipment under test gives an exception response with function code 83H, and comprises an abnormality code 02 represent it is illegal data address in response frame;
(4) the negative test of function code 04 (reading input register)
The input register quantity that protocol test instrument sending function sign indicating number 04 reads is not in 1~125 scope, check whether equipment under test gives an exception response with function code 84H, and it is invalid to comprise the input register quantity that an abnormality code 03 expression reads in response frame, i.e. the invalid data value;
Protocol test instrument sending function sign indicating number 04 reads one group of invalid address input register currency, checks whether equipment under test gives an exception response with function code 84H, and comprises an abnormality code 02 represent it is illegal data address in response frame;
(5) the negative test of function code 05 (writing single coil)
When the on off operating mode of protocol test instrument sending function sign indicating number 05 write coil is not " 0000 " or " FF00 ", check whether equipment under test gives an exception response with function code 85H, and the on off operating mode that comprises an abnormality code 03 expression coil in response frame is invalid, i.e. the invalid data value;
Protocol test instrument sending function sign indicating number the last 05 put the on off operating mode of an invalid address coil, checks whether equipment under test gives an exception response with function code 85H, and comprises an abnormality code 02 represent it is illegal data address in response frame;
Protocol test instrument sending function sign indicating number 05 write order, if expendable mistake appears in equipment under test when attempting to handle request, check whether equipment under test gives an exception response with function code 85H, and in response frame, comprise an exception code 04 expression equipment under test fault;
(6) the negative test of function code 06 (writing single register)
The register value that protocol test instrument sending function sign indicating number 06 writes is not in the scope that equipment under test allows the time, check whether equipment under test gives an exception response with function code 86H, and comprising an exception code 03 expression at response frame, to write the value of register invalid, i.e. the invalid data value;
The value that protocol test instrument sending function sign indicating number 06 is put an invalid address register checks whether equipment under test gives an exception response with function code 86H, and comprises an abnormality code 02 represent it is illegal data address in response frame;
(7) the negative test of function code 08 (diagnostic function)
Protocol test instrument sending function sign indicating number 08 provides invalid data field, checks whether equipment under test gives exception response with function code 88H, and it is invalid to comprise an abnormality code 03 expression data field in response frame;
(8) the negative test of function code 15 (writing a plurality of coils)
The coil quantity that protocol test instrument sending function sign indicating number 15 writes is not in 1~1968 scope, check whether equipment under test gives an exception response with function code 8FH, and it is invalid to comprise an exception code 03 expression register quantity in response frame, i.e. the invalid data value;
Protocol test instrument sending function sign indicating number 15 is put the on off operating mode of an invalid address coil, checks whether equipment under test gives an exception response with function code 8FH, and comprise an abnormality code 02 invalid data address in response frame;
(9) the negative test of function code 16 (writing a plurality of registers)
The register quantity that protocol test instrument sending function sign indicating number 16 writes is not in 1~123 scope or byte count when being not equal to 2 times of register quantity, check whether equipment under test gives an exception response with function code 90H, and it is invalid to comprise an abnormality code 03 expression register quantity in response frame, i.e. the invalid data value;
Protocol test instrument sending function sign indicating number 16 is put an invalid address register value, checks whether equipment under test gives an exception response with function code 90H, and comprise an abnormality code 02 invalid data address in response frame;
(10) the negative test of function code 20/6 (reading file logging)
The byte count that protocol test instrument sending function sign indicating number 20/6 reads checks whether equipment under test gives an exception response with function code 94H not in 7~245 scopes, and it is invalid to comprise an exception code 03 expression byte count in response frame;
In the initial address that protocol test instrument sending function sign indicating number 20/6 reads, parameter type, document number and the record quantity any one or several invalid, check whether equipment under test gives an exception response with function code 94H, and in response frame, comprise an abnormality code 02 expression invalid data address;
(11) the negative test of function code 21/6 (written document record)
The byte count that protocol test instrument sending function sign indicating number 21/6 writes is not in 7~245 scopes, check whether equipment under test gives an exception response with function code 95H, and it is invalid to comprise an abnormality code 03 expression register quantity in response frame, i.e. the invalid data value;
In the initial address that protocol test instrument sending function sign indicating number 21/6 writes, parameter type, document number and the record quantity any one or several when invalid, check whether equipment under test gives an exception response with function code 95H, and in response frame, comprise an abnormality code 02 expression invalid data address;
(12) the negative test of function code 22 (masked-write register)
Protocol test instrument sending function sign indicating number 22, in the claim frame " and_mask " or " r_mask " when invalid, check whether equipment under test gives an exception response with function code 96H, and in response frame, comprise an abnormality code 03 and represent the invalid data value;
During invalid address register of protocol test instrument sending function sign indicating number 22 shieldings, check whether equipment under test gives an exception response with function code 96H, and in response frame, comprise an abnormality code 02 expression invalid data address;
(13) the negative test of function code 23 (a plurality of registers of read/write)
The quantity that protocol test instrument sending function sign indicating number 23 reads register not in the 1-125 scope or the register quantity that writes not in 1~121 scope or to write byte number be not to write 2 times of register quantity to check whether equipment under tests give an exception response with function code 97H, and it is invalid to comprise an abnormality code 03 expression register quantity in response frame, i.e. the invalid data value;
Protocol test instrument sending function sign indicating number 23 reads the register of invalid address or writes the register of invalid address, check whether equipment under test gives an exception response with function code 97H, and in response frame, comprise an abnormality code 02 expression invalid data address;
(14) the negative test of function code 24 (reading fifo queue)
The quantity that protocol test instrument sending function sign indicating number 24 reads fifo register checks whether equipment under test gives exception response with function code 98H not between 0~31, and comprises an abnormality code 03 expression invalid data value in response frame;
Protocol test instrument sending function sign indicating number 24 reads the fifo register of an invalid address, checks whether equipment under test gives exception response with function code 98H, and comprises an abnormality code 02 expression invalid data address in response frame;
(15) the negative test of function code 43/14 (reading device identification)
The protocol test instrument sends when reading an invalid device id, checks whether equipment under test gives an exception response with function code abH, and comprises an abnormality code 03 represent the invalid data value in response frame;
When the protocol test instrument sends an invalid object ID, check whether equipment under test gives an exception response with function code abH, and in response frame, comprise an abnormality code 02 and represent the invalid data address;
The iii) not test of support function sign indicating number, utilize the protocol test instrument to send the arbitrary unsupported function code of equipment under test, check whether equipment under test carries out exception response, function code in the exception response is the function code of 80H+ request, and comprises the illegal function of an abnormality code 01 expression in response frame;
G) data field test utilizes the protocol test instrument to send correct command frame, checks whether data field in the message of equipment under test response satisfies the requirement of standard;
Whether h) application function test according to the application function that equipment under test in the communication protocol explanation is supported, checks each application function can correctly finish;
I) data correctness test at first needs to utilize tester to apply of ac to equipment under test, utilizes the protocol test instrument to send command frame then, checks whether the data of sending on the equipment under test are correct.
5) testing protocol consistency step
The first step: fill in Modbus-RTU protocol conformance statement table;
Second step: according to Fig. 1 test system building;
The 3rd step: communication interface test;
The 4th step: communication baud rate test;
The 5th step: link layer test;
The 6th step: the proper testing of function code 01 (read coil);
The 7th step: the negative test of function code 01 (read coil);
The 8th step: the proper testing of function code 02 (reading the discrete magnitude input);
The 9th step: the negative test of function code 02 (reading the discrete magnitude input);
The tenth step: the proper testing of function code 03 (reading to keep register);
The 11 step: the negative test of function code 03 (reading to keep register);
The 12 step: the proper testing of function code 04 (reading input register);
The 13 step: the negative test of function code 04 (reading input register);
The 14 step: the proper testing of function code 05 (writing single coil);
The 15 step: the negative test of function code 05 (writing single coil);
The 16 step: the proper testing of function code 06 (writing single register);
The 17 step: the negative test of function code 06 (writing single register);
The 18 step: the proper testing of function code 07 (reading abnormality);
The 19 step: the proper testing of function code 08 (diagnostic function);
The 20 step: the negative test of function code 08 (diagnostic function);
The 21 step: the proper testing of function code 11 (obtaining the communication event counter);
The 22 step: the proper testing of function code 12 (obtaining the communication event record)
The 23 step: the proper testing of function code 15 (writing a plurality of coils);
The 24 step: the negative test of function code 15 (writing a plurality of coils);
The 25 step: the proper testing of function code 16 (writing a plurality of registers);
The 26 step: the negative test of function code 16 (writing a plurality of registers);
The 27 step: the proper testing of function code 17 (report substation ID);
The 28 step: the proper testing of function code 20/6 (reading file logging);
The 29 step: the negative test of function code 20/6 (reading file logging);
The 30 step: the proper testing of function code 21/6 (written document record);
The 31 step: the negative test of function code 21/6 (written document record);
The 32 step: the proper testing of function code 22 (masked-write register);
The 33 step: the negative test of function code 22 (masked-write register);
The 34 step: the proper testing of function code 23 (a plurality of registers of read/write);
The 35 step: the negative test of function code 23 (a plurality of registers of read/write);
The 36 step: the proper testing of function code 24 (reading fifo queue);
The 37 step: the negative test of function code 24 (reading fifo queue);
The 38 step: the proper testing of function code 43/14 (reading device identification);
The 39 step: function code 43/14 (reading device identification) negates test;
The 40 step: the not test of support function sign indicating number;
The 41 step: the test of data field;
The 42 step: the test of application function;
The 43 step: the test of data correctness.