A kind of communication processing method of wide area data collection
Technical field:
The present invention relates to a kind of wide area data collection system that is applied to, based on the communication processing method of GPRS/CDMA and RS232/485.
Background technology:
The mode that the front-end collection equipment of the wide area data collection system of present maturation adopts special-purpose GPRS/CMDA dialing attached device GPRS/CDMA Modem and front end data acquisition terminal RTU to be used more realizes the data acquisition and monitoring function.System generally adopts the mode of transparent transmission in the process of transfer of data, namely Modem does not carry out any data processing, and any application layer data former state that receives is transmitted the data communication function that the front end data acquisition terminal that places one's entire reliance upon RTU provides.
Because special-purpose GPRS/CDMA Modem adopts the transparent transmission mode; needing data collection station RTU to cooperate with remote monitoring terminal for communication link keep-alive (keep alive) detection of adopting ICP/IP protocol finishes; Modem does not participate in detecting; therefore keep-alive detects and does not have the transparency, and working method and data format that the realization of the keepalive feature of namely communicating by letter needs modem, data collection station RTU and remote monitoring terminal jointly to consult keep-alive could be realized.For RTU, need to remodify communication mechanism and data format, the state of timed sending keep-alive Data Detection TCP link has increased the complexity of communicating by letter.
The keepalive command frame structure that initiatively sends the keep-alive data by RTU is:
See Fig. 6,
The keep-alive ACK frame structure that remote monitoring terminal is replied is:
See Fig. 7,
The tcp data zone length of keepalive command is len, and therefore, the keepalive method data traffic that initiatively sends data by RTU is large, has improved the communication cost of TCP link maintenance.
Usually the function of front-end collection equipment generally is designed to towards real-time highly reliable fieldbus, GPRS/CDMA wireless network for the employing of wide area monitoring system, data acquisition at a high speed can improve the real-time of data acquisition to a certain extent, but what accompany with it is high data communication expense and the restriction of communication reliability.Therefore need RTU that the active upload function is provided especially, but the RTU for most of supporting industry bus communication protocols, active upload function when substantially not possessing the event generation, therefore directly adopt the very difficult application of supporting the wide area data collection system of mode of transparent transmission Modem, especially large-scale supervisory control system.
Summary of the invention:
Purpose of the present invention is exactly the deficiency for the above-mentioned wide area data collection existing Modem of system and RTU communication process mode; a kind of communication processing method of wide area data collection is proposed; keep-alive is detected have the transparency, save communication cost, possess simultaneously the function of event active upload.
For achieving the above object, the invention provides a kind of communication processing method of wide area data collection, the method comprises the following steps:
1) dials by serial line interface control Modem at Micro-processor MCV, by GPRS/CDMA correct be connected to the dedicated network that Internet or mobile operator provide after, initiate TCP Client connection request by MCU master, linking objective is the remote monitoring terminal that is connected to network of appointment, and this monitor terminal has fixing IP address and port numbers of the time of running;
2) if successfully be connected to remote monitoring terminal; namely between MCU and remote monitoring terminal, set up a TCP interface channel; remote monitoring terminal is TCP Server; MCU is TCP Client; the executed in parallel multitask; this multitask comprises TCP link keep-alive Detection task and accepts the remote monitoring task, otherwise, return step 1).
Wherein: TCP link keep-alive Detection task comprises the following steps:
2A1) Micro-processor MCV regularly initiatively sends keepalive command, detects the connection of TCP link;
If 2A2) remote monitoring terminal is not in time replied keep-alive and is replied ACK; MCU meeting repeated attempt repeatedly; repeated attempt repeatedly after, remote monitoring terminal is not all replied keep-alive and is replied, then the TCP link fails; MCU control Modem closes; cut off GPRS/CDMA communication, and after time-delay a period of time, get back to step 1), if replying keep-alive, remote monitoring terminal replys ACK; the TCP communication link is normal, then returns step 2A1).The TCP keepalive frame structure that MCU initiatively sends is:
See Fig. 8,
The keep-alive that remote monitoring terminal is replied is replied the ACK frame structure and is:
See Fig. 9,
It is zero TCP keepalive command that the keepalive command that MCU initiatively sends adopts the basic data area length of Transmission Control Protocol.
Above-mentioned multitask also comprises event detection active upload task.
The above-mentioned remote monitoring task of accepting comprises the following steps:
2B1) Micro-processor MCV detects the remote monitoring order;
2B2) detected the remote monitoring order, then accept the packet that remote monitoring terminal sends accurate Modbus/TCP agreement regulation, accurate Modbus/Tcp protocol definition, the Client that the MCU that holds as Modbus/TCP Slave connects as TCP, the Server that the remote monitoring terminal of holding as Modbus/TCP Master connects as TCP, accurate Modbus/TCP agreement has also defined the active upload command frame format that MCU sends simultaneously, MCU is when receiving the standard Modbus/TCP reading and writing data order of remote monitoring terminal transmission, MCU realizes the conversion between Modbus/TCP and the Modbus rtu protocol, the Modbus/TCP Frame that MCU will receive by the TCP interface, pass through protocol conversion process, convert standard Modbua RTU data frame format to and be forwarded on the RTU equipment that is connected with the MCU serial line interface, be forwarded to simultaneously the answer frame of the modbus RTU Frame of RTU equipment for this MCU, also the protocol conversion process by MCU converts standard Modbus/TCP to, send to remote monitoring terminal by the TCP link, finish this protocol conversion process process, return step 2B1).
Do not detected the remote monitoring order, MCU produces the active upload information of Report ID, returns step 2B1).Report id command lattice comprise one to have the unique ID of whole system number, and this ID number corresponding one by one with the MCU of current transmission Report id command, by the MCU of ID remote monitoring terminal in can recognition system;
Above-mentioned event detection active upload task comprises the following steps:
2C1) in the idle period of time that remote monitoring terminal is read and write the RTU facility information by the MCU protocol conversion, whether the RTU equipment that MCU initiatively detects on the interface by the serial line interface that is connected with RTU rapidly has event flag;
2C2) in case find that one of them RTU equipment has produced event, MCU generates the order of event active upload immediately, and read the event content in the RTU equipment, through protocol conversion process, by the TCP link active upload command frame is sent to remote monitoring terminal, finish the quick renewal of remote monitoring terminal event content, return step 2C1); If not finding has event, then directly return step 2C1).
The modbus TCP active upload command frame format that above-mentioned MCU sends is:
See Figure 10,
Transaction ID: remote monitoring terminal generates, the MCU slavish copying;
Always ZERO: always zero, show it is the modbus/TCP agreement;
Byte Count: show data word joint number after this;
The ID of Slave address:RTU number, content can be 1~254;
Fouction: active upload command number;
Starting Address: upload register initial address high byte and low byte;
No.of Registers: upload register number high byte and low byte;
The length in ByteCount:Data zone;
Data ...: data.
Because the keepalive command that communication processing method of the present invention adopts, tcp data zone length are zero, thus the keep-alive data total length of the method always initiatively to send the keepalive method data traffic of data by RTU little than existing.The at present general GPRS/CDMA of cause is according to flow charging, so can save communication cost.Simultaneously; hold for remote monitoring terminal TCP Server; do not need the data in the keep-alive TCP order of the present invention are carried out the explanation of application layer; keep-alive is received the rear automatically realization of this order answer by TCP Server termination after MCU sends order; transparent for remote monitoring terminal; remote monitoring terminal TCP Server end does not need to do any processing, thereby, keep-alive is detected have the transparency.
Communication processing method of the present invention can be connected to remote monitoring terminal with RTU, makes remote monitoring terminal can monitor the data of its collection, can also keep the link-attached reliability of TCP by transparent keepalive feature simultaneously.
For the monitoring of wide area, cannot be rapidly according to the speed quick obtaining RTU data ceaselessly of level second, otherwise the flow of communication can be very large.The present invention is in can not the situation of quick obtaining RTU data, by event detection active upload task, to remote monitoring terminal, whether the data that make remote monitoring terminal know that in time certain RTU of front end gathers occur unusually at the very first time Active report of pinpointing the problems.The high data communication expense of having avoided data acquisition at a high speed to follow.
The present invention is keeping having realized normal remote monitoring data collection, event active upload and communication keepalive feature under the constant prerequisite of front-end collection equipment existing communication function.
Description of drawings:
Fig. 1 is that the embodiment of the invention is based on the front-end collection equipment block diagram of wide area data collection;
Fig. 2 is communication processing method main flow chart of the present invention;
Fig. 3 is TCP link keep-alive Detection task flow chart in Fig. 2 flow process;
Fig. 4 accepts the remote monitoring mission flow diagram in Fig. 2 flow process;
Fig. 5 is event detection active upload mission flow diagram in Fig. 2 flow process;
Fig. 6 is the existing keepalive command frame structure that initiatively sends the keep-alive data by RTU;
Fig. 7 is the keep-alive ACK frame structure that existing remote monitoring terminal is replied;
Fig. 8 is the TCP keepalive frame structure that MCU of the present invention initiatively sends;
Fig. 9 is that the ACK frame structure is replied in the keep-alive that remote monitoring terminal of the present invention is replied;
Figure 10 is the modbus TCP active upload command frame format that MCU of the present invention sends.
Embodiment:
As shown in Figure 1, the embodiment of the invention comprises GPRS/CDMA wireless Modem, universal industrial Micro-processor MCV and a plurality of front end data acquisition terminal RTU1 to RTUx based on the front-end collection equipment of wide area data collection.Different from existing front-end collection equipment, method of the present invention is embodied in and adopts the universal industrial Micro-processor MCV on the hardware configuration is working centre, Micro-processor MCV is realized being connected with the wireless modem of GPRS/CDMA by the RS232 standard interface, Micro-processor MCV provides the computer that a RS232 interface is used for connecting the operation configuration software simultaneously, and one or more RS485 interface is used for connecting the normal data acquisition terminal RTU of front end.As shown in Figure 1, only used one of them RS485 interface, this interface connects one or more data collection station RTU1 to RTUx.Modem is the GPRS/CDMA communication dialing device of standard, MCU is general industrial single board computer processing unit, MCU has comprised processor and the interface circuit of the CPU that is used for protocol processes and associated RS232, RS485 communication, and RTU is general front end data acquisition terminal based on the Modbus agreement.
As shown in Figure 2, be communication processing method main flow chart of the present invention, the communication processing method of a kind of wide area data collection of the present invention, the method comprises the following steps:
1) dials by RS232 interface control Modem at Micro-processor MCV, by GPRS/CDMA correct be connected to the dedicated network that Internet or mobile operator provide after, initiate the TCPClient connection request by MCU master, linking objective is the remote monitoring terminal that is connected to network of appointment, and this monitor terminal has fixing IP address and port numbers of the time of running;
2) if successfully be connected to remote monitoring terminal; namely between MCU and remote monitoring terminal, set up a TCP interface channel; remote monitoring terminal is TCP Server; MCU is TCP Client; the executed in parallel multitask; this multitask comprises TCP link keep-alive Detection task, event detection active upload task, accepts remote monitoring task and parameter configuration task, otherwise, return step 1).
Wherein, the parameter configuration task is that the Set arbitrarily keepalive command sends the time-out time parameter that interval, number of attempt and reception keepalive command are replied as required.Do not need during proper communication, need correct configuration parameter when using for the first time, can in the middle of communication, realize that TCP connects after the keep-alive, revises configuration parameter at any time yet.
As shown in Figure 3, TCP link keep-alive Detection task comprises the following steps:
2A1) Micro-processor MCV regularly initiatively sends keepalive command, detects the connection of TCP link;
If 2A2) remote monitoring terminal is not in time replied keep-alive and is replied ACK, MCU meeting repeated attempt repeatedly, repeated attempt repeatedly after, remote monitoring terminal is not all replied keep-alive and is replied, then the TCP link fails, MCU control Modem closes, cut off GPRS/CDMA communication, and after time-delay a period of time, get back to step 1), if replying keep-alive, remote monitoring terminal replys ACK, the TCP communication link is normal, then returns step 2A1);
The TCP keepalive frame structure that MCU initiatively sends is:
See Fig. 8,
The keep-alive that remote monitoring terminal is replied is replied the ACK frame structure and is:
See Fig. 9,
It is zero TCP keepalive command that the keepalive command that MCU initiatively sends adopts the basic data area length of Transmission Control Protocol.
The present invention is initiatively finished by MCU for the keep-alive control that TCP connects, and remote monitoring terminal only needs to realize the basic function of intercepting, accepting to connect, accept data and send data of TCP Server end.After between MCU and remote monitoring terminal, setting up TCP and being connected; it is zero TCP order that the keepalive command that MCU initiatively sends adopts the basic data area length of Transmission Control Protocol; what the keepalive command that initiatively sends from RTU was different is; by the keepalive command that RTU initiatively sends, TCP command frame data area has comprised the keep-alive data of certain-length.Adopt the benefit of keepalive command of the present invention to be that command frame does not comprise data; reduced the flow of transfer of data; reduced the communication cost of TCP link maintenance in certain degree; hold for remote monitoring terminal TCP Server simultaneously; do not need the data in the keep-alive TCP order of the present invention are carried out the explanation of application layer; keep-alive is received the rear automatically realization of this order answer by TCP Server termination after MCU sends order; transparent for remote monitoring terminal; remote monitoring terminal TCP Server end does not need to do any processing; thereby, keep-alive is detected has the transparency.
The main distinction of the keepalive command that the keepalive command that the present invention adopts and prior art adopt is:
In the keepalive command that the present invention adopts; num1; position in num2 and the keep-alive commands in return and the pass of value are; work as sequence number=num1 in the keepalive command; during acknowledgement number=num2; sequence number one in the keep-alive commands in return is decided to be num2,, acknowledgement number one is decided to be num1+1.TCP comprises an application layer data scarcely in the keepalive command simultaneously.
In the prior art keepalive command; as sequence number=num1; during acknowledgement number=num2; this moment, TCP necessarily comprised the application layer data that length is len>0; and in the order of replying; sequence number one is decided to be num2, and acknowledgement number one is decided to be num1+len.
The realization of prior art communication keepalive feature, the working method and the data format that need modem, data collection station RTU and remote monitoring terminal jointly to consult keep-alive could realize that keep-alive detects does not have the transparency.
The communicate by letter realization of keepalive feature of the present invention; the active procedure that modem, data collection station RTU and remote monitoring terminal three sub-systems is not needed to be concerned about fully keep-alive; just look like not exist equally, the keep-alive process is finished automatically by TCP communication protocol fully, and keep-alive detects has the transparency.
As shown in Figure 4, accepting the remote monitoring task comprises the following steps:
2B1) Micro-processor MCV detects the remote monitoring order;
2B2) detected the remote monitoring order, then accept the packet that remote monitoring terminal sends accurate Modbus/TCP agreement regulation, accurate Modbus/Tcp protocol definition, the Client that the MCU that holds as Modbus/TCP Slave connects as TCP, the Server that the remote monitoring terminal of holding as Modbus/TCP Master connects as TCP, accurate Modbus/TCP agreement has also defined the active upload command frame format that MCU sends simultaneously, MCU is when receiving the standard Modbus/TCP reading and writing data order of remote monitoring terminal transmission, MCU realizes the conversion between Modbus/TCP and the Modbus rtu protocol, the Modbus/TCP Frame that MCU will receive by the TCP interface, pass through protocol conversion process, convert standard Modbua RTU data frame format to and be forwarded on the RTU equipment that is connected with MCU serial line interface RS485, be forwarded to simultaneously the answer frame of the modbus RTU Frame of RTU equipment for this MCU, also the protocol conversion process by MCU converts standard Modbus/TCP to, send to remote monitoring terminal by the TCP link, finish this protocol conversion process process, return step 2B1);
Do not detected the remote monitoring order, judged whether greater than ReportID transmission times num, if greater than ReportID transmission times num, directly return step 2B1), otherwise MCU produces the active upload information of Report ID, returns step 2B1); Report id command lattice comprise one to have the unique ID of whole system number, and this ID number corresponding one by one with the MCU of current transmission Report id command, by the MCU of ID remote monitoring terminal in can recognition system.
As shown in Figure 5, event detection active upload task comprises the following steps:
2C1) in the idle period of time that remote monitoring terminal is read and write the RTU facility information by the MCU protocol conversion, whether the RTU equipment that MCU initiatively detects on the interface by the serial line interface RS485 that is connected with RTU rapidly has event flag;
2C2) in case find that one of them RTU equipment has produced event, MCU generates the order of event active upload immediately, and read the event content in the RTU equipment, through protocol conversion process, by the TCP link active upload command frame is sent to remote monitoring terminal, finish the quick renewal of remote monitoring terminal event content, return step 2C1); If not finding has event, then directly return step 2C1).
The modbus TCP active upload command frame format that above-mentioned MCU sends is:
See Figure 10,
Transaction ID: remote monitoring terminal generates, the MCU slavish copying;
Always ZERO: always zero, show it is the modbus/TCP agreement;
Byte Count: show data word joint number after this;
The ID of Slave address:RTU number, content can be 1~254;
Fouction: active upload command number;
Starting Address: upload register initial address high byte and low byte;
No.of Registers: upload register number high byte and low byte;
The length in ByteCount:Data zone;
Data ...: data.
Remote monitoring terminal of the present invention sends the packet of accurate Modbus/TCP agreement regulation.Accurate Modbus/Tcp protocol definition, the Client that the MCU that holds as Modbus/TCP Slave connects as TCP, the Server that the remote monitoring terminal of holding as Modbus/TCP Master connects as TCP, accurate Modbus/TCP agreement has also defined the command frame format of active upload simultaneously.In addition, the frame structure and the standard Modbus/TCP that use in the communicating by letter between MCU and the remote monitoring terminal are in full accord.MCU can produce the active upload information of Report ID, by the MCU of ReportID remote monitoring terminal in can recognition system, modbus TCP active upload command frame by the MCU transmission, obtain ID number of RTU according to Slave address, so each MCU has unique ID number, each has unique Slave ID by the RTU that MCU is connected to remote monitoring terminal, by the ID of MCU, just can identify different RTU in conjunction with Slave ID.Event among MCU active upload and the RTU is closely related, even MCU does not receive the order that remote monitoring terminal sends, if conditions permit, for example event has occured in certain RTU, MCU can send active upload command frame notice remote monitoring terminal, remote monitoring terminal can be resolved the data message that comprises in the active upload Frame, thereby obtains in time the content of event.
In sum, data collection station RTU is connected to GPRS/CDMA by the RS485 interface, finally is connected to remote monitoring terminal, sets up reliable TCP and be connected between RTU and remote monitoring terminal, realizes monitoring.Communication processing method of the present invention has been realized the conversion of modbus/RTU and modbus/TCP agreement; remote monitoring terminal can be connected by TCP; adopt the modbus/TCP agreement to realize adopting being connected of RS485 interface modbus/RTU communication protocol with RTU equipment, the keep-alive of TCP link and the active upload function of wide area monitoring also is provided simultaneously.The accurate modbus/TCP of wide area monitoring and the conversion of modbus/RTU agreement have finally been realized to adapt to.