Background technology
Ethernet and on-the-spot universal serial bus are industrial automation field communication modes commonly used, in fact, no matter be field bus or Industrial Ethernet, situations that has formed many standards and deposited all, kind of fieldbus surplus existing about 40 in the world at present, as the FIP of France, the ERA of Britain, the ProfiBus of Siemens Siemens, the FINT of Norway, the LONWorks of Echelon company, the InterBus of PhenixContact company, the CAN of RoberBosch company, the HART of Rosemounr company, the Dupline of CarloGarazzi company, the P-net of Denmark ProcessData company, the F-Mux of PeterHans company, and ASI (ActraturSensorInterface), MODBus, SDS, Arcnet, International Standards Organization-foundation fieldbus FF:FieldBusFoundat ion, WorldFIP, BitBus, the DeviceNet of the U.S. and ControlNet or the like.These fieldbus mostly are used for fields such as process automation, field of medicaments, processing and manufacturing, communications and transportation, national defence, space flight, agricultural and building, and in protocol conversion, heterogeneous network access procedure, gateway plays an important role.
Serial communication gateway commonly used at present comprises ethernet communication port that connects host computer and the communication port that is connected slave computer, serial communication gateway generally all is to transmit packet according to the address, point of destination, because industry control agreement commonly used is various, the employing data transparency is transmitted, serial communication gateway only need be done simple FPDP conversion to Ethernet and on-the-spot universal serial bus, do not need concrete resolution data, therefore can connect various existing field apparatuss, guarantee that gateway has good expanded function.
Above-mentioned serial communication gateway, because the transmission rate of Ethernet and on-the-spot universal serial bus does not generally match, the rate-constrained of whole communication gate in transmission rate the slowest communication port, in order to guarantee not packet loss of data, serial communication gateway generally all will use message queue to do buffering.Along with improving constantly of communicating requirement, when guaranteeing that gateway has good expanded function, be necessary to provide the quick exchange of communication data commonly used.
Summary of the invention
Technical problem to be solved by this invention provides a kind of serial communication gateway, can expand the support various protocols, can guarantee the quick exchange of frequently-used data again.
The present invention solves the problems of the technologies described above the technical scheme that adopts to provide a kind of serial communication gateway, comprise ethernet communication port that connects host computer and the communication port that is connected slave computer, wherein, the unified numbering of described gateway and described slave computer, described gateway comprises configuration module, and gateway address, local data district and point of destination/serial port path configurations is provided; Data transmit-receive module, the packet of transmitting-receiving ethernet communication port and communication port, described packet comprises address, point of destination, data address and data value; Pre-parsing module extracts the address, point of destination in the packet; The data transparency forwarding module if the address, point of destination in the packet is not a gateway address, is transmitted packet to the corresponding port according to address, point of destination in the packet and port path configuration; Data resolution module if the address, point of destination in the packet is a gateway address, is handled data value in this packet according to the data address in the packet and local data district.
Above-mentioned serial communication gateway, wherein, the static configuration data district that described local data district provides for described configuration module.
Above-mentioned serial communication gateway, wherein, the dynamic configuration data district that described local data district provides for described configuration module, described pre-parsing module extracts the data address in the packet, if described data address does not belong to the local data district, temporary this packet is in certain threshold value, if collect the read-write requests of different port to this data address, then this data address of dynamic assignment is to the local data district.
Above-mentioned serial communication gateway, wherein, if the address, point of destination in the packet is specified described serial communication gateway and slave computer simultaneously, described data transparency forwarding module is transmitted this packet to message queue, when message queue length surpasses threshold value, described data resolution module adopt successively packet in the processing messages formation of local data district until message queue length less than threshold value.
Above-mentioned serial communication gateway, wherein, described local data district is the internal storage data district, restart the back and recover the local data district from fixed memory device to fixed memory device in described gateway timed backup local data district.
The present invention contrasts prior art following beneficial effect: serial communication gateway provided by the invention, support various protocols by the expansion of data transparency forwarding module, the quick exchange of frequently-used data be can guarantee again by the local data district, protocol extension and fast data exchange taken into account.In addition, serial communication gateway of the present invention can also use data forwarding module and local data function of exchange simultaneously and adjust data exchange ways automatically according to network service speed.
Embodiment
The invention will be further described below in conjunction with drawings and Examples.
Fig. 1 is a serial communication gateway connection diagram of the present invention; Fig. 2 is a serial communication gateway structured flowchart of the present invention.
See also Fig. 1 and Fig. 2, serial communication gateway 12 provided by the invention, comprise the ethernet communication port that connects host computer 11 and be connected slave computer 13 communication ports, wherein, described gateway 12 and described slave computer 13 unified numberings, described gateway comprises configuration module 21, and gateway address, local data district and point of destination/serial port path configurations is provided; Data transmit-receive module 22, the packet of transmitting-receiving ethernet communication port and communication port, described packet comprises address, point of destination, data address and data value; Pre-parsing module 23 extracts the address, point of destination in the packet; Data transparency forwarding module 24 if the address, point of destination in the packet is not a gateway address, is transmitted packet to the corresponding port according to address, point of destination in the packet and port path configuration; Data resolution module 25 if the address, point of destination in the packet is a gateway address, is handled data value in this packet according to the data address in the packet and local data district.
Above-mentioned serial communication gateway 12 is supported various protocols by 24 expansions of data transparency forwarding module, by the quick exchange that the local data district can guarantee frequently-used data again, has taken into account protocol extension and fast data exchange.Fig. 1 has provided dual serial communication gate 12, and one of them backs up, and forms redundant system, during actual the use, also can singlely use certainly.
Fig. 3 is a serial communication gateway main flow chart of the present invention.
See also Fig. 3, serial communication gateway main flow of the present invention is as follows:
Step S301: serial communication gateway system initialization, configuration module 21 provides gateway address, local data district and port path configuration, wherein, the port path configuration comprises the station number of serial communication gateway station number and slave computer that each communication port connects, and enters step S302 then;
Step S302: the packet of data transmit-receive module 22 transmitting-receiving Ethernet interfaces and communication port, communication port can be the fieldbus of using always, enters step S303 after receiving packet;
Step S303: pre-parsing module 23, extract the address, point of destination in the packet, enter step S304 then;
Step S304: whether the address, point of destination in the judgment data bag is this gateway address, if enter step S306, otherwise enters step S305;
Step S305: data transparency forwarding module 24, transmit packet to the corresponding port according to address, point of destination in the packet and port path configuration, and carry out simple format conversion between Ethernet interface and the communication port, concrete packet is not done to resolve and handle;
Step S306: data resolution module 25 is responsible for the resolution data bag, to read request packet, according to the data address in the packet, searches corresponding value in the local data district and makes up respond packet; To the write request bag, according to data address in the packet and data value, search corresponding address variable in the local data district, upgrade the variables corresponding value and make up respond packet;
Repeat above-mentioned steps S302~step S306 and promptly finish serial communication gateway main flow processing of the present invention.
Above-mentioned serial communication gateway, described local data district is the static configuration data district that is provided by described configuration module 21, in the packet of receiving in the serial communication gateway work,, the data address of request visit then can't not provide exchanges data if not belonging to the local data district.
Fig. 4 is a serial communication gateway dynamic assignment local data of the present invention district flow chart.
See also Fig. 4, serial communication gateway dynamic assignment local data of the present invention district flow process is as follows:
Step S401: the packet of data transmit-receive module 22 transmitting-receiving Ethernet interfaces and communication port, communication port can be the fieldbus of using always, enters step S402 after receiving packet;
Step S402: pre-parsing module 23, extract the address, point of destination in the packet, if the address, point of destination is a gateway address, continue to extract the data address in the packet, enter step S403 then;
Step S403: whether the judgment data address is positioned at the local data district, if then give the data resolution module in the main flow, otherwise enters step S404;
Step S404: continue to judge that gateway has or not the read-write requests that receives from different port,, otherwise enter step S406 if enter step S405;
Step S405: this data address of dynamic assignment is given the data resolution module in the main flow then to the local data district;
Step S406: only receive the request of reading or writing, the temporal data bag, repeating step S401~step S406, if receive a certain data address read or write then this data address of dynamic assignment to the local data district, otherwise surpass threshold value sometime, packet discard.
In addition, serial communication gateway of the present invention can also use data forwarding module and local data function of exchange simultaneously, can specify the address, point of destination simultaneously from the request package of host computer 11 is described serial communication gateway and a certain slave computer, described data transparency forwarding module 24 is transmitted this packet to message queue, promptly when the serial network port communication is smooth and easy, adopt forwarding capability to obtain initial data as far as possible.But when message queue length surpasses threshold value, described data resolution module 25 adopt successively packet in the processing messages formation of local data district until message queue length less than threshold value, promptly when the serial network port communication blocks up, utilize the local data district on the gateway that fast data exchange is provided.
Above-mentioned serial communication gateway, described local data district often adopts the internal storage data district, and local data district as hard disk or USB flash disk, automatically from fixed memory device recovered after restarting to fixed memory device by described gateway timed backup local data district.
In order further to describe the exchanges data flow process of gateway of the present invention, be example with Modbus agreement commonly used below, describe the process that gateway of the present invention utilizes local data district exchange Modbus data in detail.
Fig. 5 is that the present invention utilizes local data district quick exchange schematic diagram data.
See also Fig. 5, controller Controller links to each other with serial communication gateway 12 by Ethernet interface as host computer 11, the Modbus serial device links to each other with serial communication gateway 12 by the RS485 communication port as slave computer 13, wherein, controller Controller and Modbus serial device are as the Master of main website, serial communication gateway 12 utilizes local data district ModbusData that fast data exchange is provided as slave station Slave.The Modbus communication mode comprises broadcast type and replys formula that wherein, the request package form is as follows:
The address, point of destination |
Function code |
An initial address high position |
The initial address low level |
Register is counted a high position |
Register is counted low level |
Byte count |
Data |
Checksum CRC |
The respond packet form is as follows:
The address, point of destination |
Function code |
An initial address high position |
The initial address low level |
Register is counted a high position |
Register is counted low level |
Checksum CRC |
The address, point of destination of standard Modbus agreement is a byte, is described serial communication gateway and a certain slave computer in order to specify the address, point of destination simultaneously, and the present invention can be appointed as the slave computer station number with wherein low four, and Gao Siwei specifies gateway address.If slave computer equipment surpasses 16, can the extended address byte be 2 byte also then.
The data variable of ModbusData, it is the register number, comprise coiled type state variable (Coil status), input switch amount (Input status), input register variable (Input register), internal register variable (Holding register) and extended register variable (Extended register), concrete data address is allocated as follows:
Coil?status:1-9999
Input?status:10001-19999
Input?register:30001-39999
Holding?register:40001-49999
Extended?register:600001-665535
Local data district ModbusData is according to can be according to using needs, or static state or the above-mentioned data field of dynamic-configuration.
Controller Controller goes up communication module ModnetM and sends the Modbus/TCP request package, Modbus/TCP is that Modbus forms the TCP information frame according to the Modbus call format, as step 1., comprise address, point of destination, data address and request command in the request package, wherein, the address, point of destination is the station number of serial communication gateway 12, and serial communication gateway 12 is received request package, utilize ModbusData to make up respond packet, 2. as step.In like manner, the Modbus serial device sends the Modbus request package, as step 3., comprise address, point of destination, data address and request command in the request package, wherein, the address, point of destination is the station number of serial communication gateway 12, and serial communication gateway 12 is received request package, utilize ModbusData to make up respond packet, 4. as step.Controller Controller and Modbus serial device, one-period is read the ModbusData on the serial communication gateway 12, another periodically writes the ModbusData on the serial communication gateway 12, promptly finishes the fast data exchange between controller Controller and Modbus serial device.
Fig. 6 is that the present invention utilizes data transparency forwarding module swap data schematic diagram.
See also Fig. 6, after serial communication gateway 12 is received request package on the host computer 11, as step 1., carry out simple port format conversion, be about to Modbus/TCP based on Ethernet and convert Modbus to based on serial ports, pre-parsing module on the serial communication gateway 12 23 extracts the address, point of destination of request package then, and shut the binding relationship of each serial port and purpose station number according to Home Network, transmit request package from the corresponding port and give corresponding slave computer 13, be Modbus Serial Device, 2. as step; The Modbus serial device, after promptly slave computer 13 is received the Modbus request package that forwards, the response bag, as step 3., serial communication gateway 12 transmitted response bags are given host computer 11, as step 4..By above-mentioned steps 1.~4., host computer 11 and slave computer 13 are finished exchanges data one time.
Though the present invention discloses as above with preferred embodiment; right its is not in order to qualification the present invention, any those skilled in the art, without departing from the spirit and scope of the present invention; when can doing a little modification and perfect, so protection scope of the present invention is when with being as the criterion that claims were defined.