Summary of the invention
In view of above-mentioned the deficiencies in the prior art, the object of the present invention is to provide the adaptive method and system of a kind of photoelectric direct-reading water meter multi-communication protocol, be intended to solve the problem that existing processing mode cost is high, be unfavorable for later maintenance.
Technical scheme of the present invention is as follows:
A kind of adaptive method of photoelectric direct-reading water meter multi-communication protocol, wherein, comprising:
Step 1, receives data according to the mode of first in first out, and the data received are put into buffer zone BUFF;
Step 2, judges whether the data received meet DL/T645-1997 or DL/T645-2007 agreement, if then put agreement mark, and enter into step 4, then enter step 3 if not;
Step 3, judges whether the data received meet CJ/T188-2004 agreement, if then put agreement mark, and enter into step 4;
Step 4, according to agreement mark, processes data.
The described adaptive method of photoelectric direct-reading water meter multi-communication protocol, wherein, step 2 specifically comprises:
Step (1), cyclic buffer BUFF, if find start-of-frame 68H, mark buffer reference position i, turn next step, otherwise flow process terminates;
Step (2), judges whether BUFF [i+7] is start-of-frame 68H, if turn next step, otherwise flow process terminates;
BUFF [i+8] unloading is control code C, BUFF [i+9] unloading by step (3) is data length L, turns next step;
Step (4), judges whether BUFF [i+11+L] equals 16H, if turn next step, otherwise flow process terminates;
Step (5), judge that whether check code is correct, if turn next step, otherwise flow process terminates;
Step (6), judges whether control code C is greater than 10H, if turn next step, otherwise goes to step (8);
Step (7), put DL/T645-2007 agreement mark, flow process terminates;
Step (8), put DL/T645-1997 agreement mark, flow process terminates.
The described adaptive method of photoelectric direct-reading water meter multi-communication protocol, wherein, step 3 specifically comprises:
Step (1), cyclic buffer BUFF, if find start-of-frame 68H, mark buffer reference position i, turn next step, otherwise flow process terminates;
BUFF [i+10] unloading is data length L by step (2), turns next step;
Step (3), judges whether BUFF [i+12+L] equals 16H, if turn next step, otherwise flow process terminates;
Step (4), judge that whether check code is correct, if turn next step, otherwise flow process terminates;
Step (5), put CJ/T188-2004 agreement mark, flow process terminates.
The adaptive system of a kind of photoelectric direct-reading water meter multi-communication protocol, wherein, comprising:
Receiver module, receives data for the mode according to first in first out, and the data received are put into buffer zone BUFF;
First determination module, for judging whether the data received meet DL/T645-1997 or DL/T645-2007 agreement, if then put agreement mark, and enters and manages module everywhere, then enter the second determination module if not;
Second determination module, for judging whether the data received meet CJ/T188-2004 agreement, if then put agreement mark, and enters and manages module everywhere;
Processing module, for according to agreement mark, processes data.
The described adaptive system of photoelectric direct-reading water meter multi-communication protocol, wherein, described first determination module specifically comprises:
First indexing unit, for cyclic buffer BUFF, if find start-of-frame 68H, mark buffer reference position i, turns the first judging unit;
First judging unit, for judging whether BUFF [i+7] is start-of-frame 68H, if turn the first unloading unit;
First unloading unit is data length L for being control code C, BUFF [i+9] unloading by BUFF [i+8] unloading, turns the second judging unit;
Second judging unit, for judging whether BUFF [i+11+L] equals 16H, if turn the 3rd judging unit;
3rd judging unit, for judging that whether check code is correct, if turn the 4th judging unit;
4th judging unit, for judging whether control code C is greater than 10H, if turn the first mark adding device, otherwise turns the second mark adding device;
First mark adding device, for putting DL/T645-2007 agreement mark;
Second mark adding device, for putting DL/T645-1997 agreement mark.
The described adaptive system of photoelectric direct-reading water meter multi-communication protocol, wherein, described second determination module specifically comprises:
Second indexing unit, for cyclic buffer BUFF, if find start-of-frame 68H, mark buffer reference position i, turns the second unloading unit;
Second unloading unit, for being data length L by BUFF [i+10] unloading, turns the 5th judging unit;
5th judging unit, for judging whether BUFF [i+12+L] equals 16H, if turn the 6th judging unit;
6th judging unit, for judging that whether check code is correct, if turn the 3rd mark adding device;
3rd mark adding device, for putting CJ/T188-2004 agreement mark.
Beneficial effect: make photoelectric direct-reading water meter support the communication protocol commonly used by the present invention simultaneously, simplify production link, reduce production cost, handling cost and maintenance cost.
Embodiment
The invention provides the adaptive method and system of a kind of photoelectric direct-reading water meter multi-communication protocol, for making object of the present invention, technical scheme and effect clearly, clearly, the present invention is described in more detail below.Should be appreciated that specific embodiment described herein only in order to explain the present invention, be not intended to limit the present invention.
Refer to Fig. 1, Fig. 1 is the main flow chart of the adaptive method of a kind of photoelectric direct-reading water meter of the present invention multi-communication protocol, and it comprises:
Step 1, receives data according to the mode of first in first out, and the data received are put into buffer zone BUFF;
Step 2, judges whether the data received meet DL/T645-1997 or DL/T645-2007 agreement, if then put agreement mark, and enter into step 4, then enter step 3 if not;
Step 3, judges whether the data received meet CJ/T188-2004 agreement, if then put agreement mark, and enter into step 4;
Step 4, according to agreement mark, processes data.
The principle that realizes of the present invention is: the data received are put into buffer zone BUFF, then carries out agreement judgement to buffer data, after judging protocol type, and juxtaposition respective protocol mark, then carry out protocol processes according to agreement mark.
DL/T645-1997 agreement wherein, comprises start-of-frame (68H), address field (A0, A1, A2, A3, A4, A5), start-of-frame (68H), control code (C), data length field (L), data field (DATA), check code (CS), end mark (16H) successively in the form of Frame.Start-of-frame 68H wherein: the beginning identifying a frame information, its value is 68H=01101000B.Address field is made up of 6 bytes, every byte 2 binary-coded decimals, and address size is 12 decimal numbers, can be table number, assets number, user number, device number etc.When the address field used is less than 6 byte, supply 6 bytes with sexadecimal AAH.Formerly, upper address bits, rear, as address bit 999999999999H, is broadcast address in low address position.Data length L:L is the byte number of data field.L≤200 during read data, L≤50 when writing data, L=0 indicates without data element.Data element DATA comprises Data Identification and data, password etc., and its structure changes with the function of control code.During transmission, transmit leg is undertaken adding 33H process by byte.Check code CS represent from start-of-frame to check code before all each byte mould 256 and, namely each byte binary arithmetic sum, disregards the overflow value more than 256.End mark 16H identifies the end of a frame information, and its value is 16H=00010110B.
The key distinction of DL/T645-1997 and DL/T645-2007 is, whether control code C is greater than 10H, if be greater than 10H, is then DL/T645-2007 agreement, if be not more than 10H, is then DL/T645-1997.
Its every byte of CJ/T188-2004 agreement, containing 8 binary codes, adds a start bit (0), an even parity bit (E) and a position of rest (1), totally 11 during transmission.Its frame format also comprises start-of-frame 68H, address field, control code, data length field (L), data field, end mark (16H).
Detailed process is:
(1) according to the sequence reception data of first in first out, and the data received are put into buffer zone BUFF;
(2) judge whether data are DL/T645 protocol frame, if turn next step, otherwise go to (6);
(3) judge whether data are DL/T645-2007 protocol frame, if turn a step, otherwise go to (5);
(4) put DL/T645-2007 agreement mark, go to (8);
(5) put DL/T645-1997 agreement mark, go to (8);
(6) judge whether CJ/T188-2004 protocol frame, if turn next step, otherwise go to (9);
(7) put CJ/T188-2004 agreement mark, turn next step.
(8) according to agreement mark, agreement is processed.
(9) terminate.
Further, as shown in Figure 2, step 2 specifically comprises:
Step (1), cyclic buffer BUFF, if find start-of-frame 68H, mark buffer reference position i, turn next step, otherwise flow process terminates;
Step (2), judges whether BUFF [i+7] is start-of-frame 68H, if turn next step, otherwise flow process terminates;
BUFF [i+8] unloading is control code C, BUFF [i+9] unloading by step (3) is data length L, turns next step;
Step (4), judges whether BUFF [i+11+L] equals 16H, if turn next step, otherwise flow process terminates;
Step (5), judge that whether check code is correct, if turn next step, otherwise flow process terminates;
Step (6), judges whether control code C is greater than 10H, if turn next step, otherwise goes to step (8);
Step (7), put DL/T645-2007 agreement mark, flow process terminates;
Step (8), put DL/T645-1997 agreement mark, flow process terminates.
Further, as shown in Figure 3, step 3 specifically comprises:
Step (1), cyclic buffer BUFF, if find start-of-frame 68H, mark buffer reference position i, turn next step, otherwise flow process terminates;
BUFF [i+10] unloading is data length L by step (2), turns next step;
Step (3), judges whether BUFF [i+12+L] equals 16H, if turn next step, otherwise flow process terminates;
Step (4), judge that whether check code is correct, if turn next step, otherwise flow process terminates.
Step (5), put CJ/T188-2004 agreement mark, flow process terminates.
Based on said method, the present invention also provides a kind of photoelectric direct-reading water meter multi-communication protocol adaptive system preferred embodiment, and it comprises:
Receiver module, receives data for the mode according to first in first out, and the data received are put into buffer zone;
First determination module, for judging whether the data received meet DL/T645-1997 or DL/T645-2007 agreement, if then put agreement mark, and enters and manages module everywhere, then enter the second determination module if not;
Second determination module, for judging whether the data received meet CJ/T188-2004 agreement, if then put agreement mark, and enters and manages module everywhere;
Processing module, for according to agreement mark, processes data.
Further, described first determination module specifically comprises:
First indexing unit, for cyclic buffer BUFF, if find start-of-frame 68H, mark buffer reference position i, turns the first judging unit;
First judging unit, for judging whether BUFF [i+7] is start-of-frame 68H, if turn the first unloading unit;
First unloading unit is data length L for being control code C, BUFF [i+9] unloading by BUFF [i+8] unloading, turns the second judging unit;
Second judging unit, for judging whether BUFF [i+11+L] equals 16H, if turn the 3rd judging unit;
3rd judging unit, for judging that whether check code is correct, if turn the 4th judging unit;
4th judging unit, for judging whether control code C is greater than 10H, if turn the first mark adding device, otherwise turns the second mark adding device;
First mark adding device, for putting DL/T645-2007 agreement mark;
Second mark adding device, for putting DL/T645-1997 agreement mark.
Further, described second determination module specifically comprises:
Second indexing unit, for cyclic buffer BUFF, if find start-of-frame 68H, mark buffer reference position i, turns the second unloading unit;
Second unloading unit, for being data length L by BUFF [i+10] unloading, turns the 5th judging unit;
5th judging unit, for judging whether BUFF [i+12+L] equals 16H, if turn the 6th judging unit;
6th judging unit, for judging that whether check code is correct, if turn the 3rd mark adding device.
3rd mark adding device, for putting CJ/T188-2004 agreement mark.
Ins and outs about above-mentioned modular unit are existing in method above to be described in detail, therefore repeats no more.
In sum, make photoelectric direct-reading water meter support the communication protocol commonly used by the present invention simultaneously, simplify production link, reduce production cost, handling cost and maintenance cost.
Should be understood that, application of the present invention is not limited to above-mentioned citing, for those of ordinary skills, can be improved according to the above description or convert, and all these improve and convert the protection domain that all should belong to claims of the present invention.