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 said gateway and said slave computer, said 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, said packet comprises address, point of destination, data address and data value; Parsing module extracts the address, point of destination in the packet in advance; 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 the data value in this packet according to data address in the packet and local data district.
Above-mentioned serial communication gateway, wherein, said local data district is the static configuration data district that said configuration module provides.
Above-mentioned serial communication gateway, wherein, said local data district is the dynamic configuration data district that said configuration module provides; Said preparatory parsing module extracts the data address in the packet; If said 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 said serial communication gateway and slave computer simultaneously; Said data transparency forwarding module is transmitted this packet to message queue, when message queue length surpasses threshold value, said 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, said 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 said gateway timed backup local data district.
The present invention contrasts prior art has following beneficial effect: serial communication gateway provided by the invention; Support various protocols through the expansion of data transparency forwarding module; The quick exchange of frequently-used data be can guarantee again through 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
Below in conjunction with accompanying drawing and embodiment the present invention is done further description.
Fig. 1 is that serial communication gateway of the present invention connects sketch map; 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, said gateway 12 and said slave computer 13 unified numberings; Said 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, said packet comprises address, point of destination, data address and data value; Parsing module 23 extracts the address, point of destination in the packet in advance; 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 the data value in this packet according to data address in the packet and local data district.
Above-mentioned serial communication gateway 12 is supported various protocols through 24 expansions of data transparency forwarding module, through 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 following:
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 gets into 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, receives entering step S303 behind the packet;
Step S303: preparatory parsing module 23, extract the address, point of destination in the packet, get into step S304 then;
Step S304: whether the address, point of destination in the judgment data bag is this gateway address, if get into step S306, otherwise gets into 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 writing request package, 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 accomplish serial communication gateway main flow processing of the present invention.
Above-mentioned serial communication gateway; Said local data district is the static configuration data district that is provided by said configuration module 21; In the packet of receiving in the serial communication gateway work,, the data address of request visit then exchanges data can't be provided 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 following:
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, receives entering step S402 behind the packet;
Step S402: preparatory 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, get into 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 gets into step S404;
Step S404: continue to judge that gateway has or not the read-write requests that receives from different port,, otherwise get into step S406 if get into 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 said serial communication gateway and a certain slave computer; Said data transparency forwarding module 24 is transmitted this packet to message queue, promptly when the serial network port communication is smooth and easy, adopts forwarding capability to obtain initial data as far as possible.But when message queue length surpasses threshold value; Said 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, said local data district often adopts the internal storage data district, and local data district like hard disk or USB flash disk, automatically from fixed memory device recovered after restarting to fixed memory device by said 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, specify the process that gateway of the present invention utilizes local data district exchange Modbus data.
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 through Ethernet interface as host computer 11; The Modbus serial device links to each other with serial communication gateway 12 through the RS485 communication port as slave computer 13, and 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 following:
The address, point of destination |
Function code |
Initial address is high-order |
The initial address low level |
The register number is high-order |
Register is counted low level |
Byte count |
Data |
Checksum CRC |
The respond packet form is following:
The address, point of destination |
Function code |
Initial address is high-order |
The initial address low level |
The register number is high-order |
Register is counted low level |
Checksum CRC |
The address, point of destination of standard Modbus agreement is a byte, is said 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 distributed 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 the use 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, and Modbus/TCP is that Modbus forms the TCP information frame according to the Modbus call format, like 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. like step.In like manner, the Modbus serial device sends the Modbus request package, like 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. like step.Controller Controller and Modbus serial device; One-period property is read the ModbusData on the serial communication gateway 12; Another periodically writes the ModbusData on the serial communication gateway 12, promptly accomplishes 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 sketch map.
See also Fig. 6; After serial communication gateway 12 is received the request package on the host computer 11, like step 1., carry out simple port format conversion; Be about to convert Modbus to based on serial ports based on the Modbus/TCP of Ethernet; Preparatory parsing module on the serial communication gateway 12 23 extracts the address, point of destination of request package then, and shuts the binding relationship of each serial port and purpose station number according to Home Network, transmits the slave computer 13 that request package is given correspondence from the corresponding port; Be Modbus Serial Device, 2. like step; The Modbus serial device, after promptly slave computer 13 is received the Modbus request package that forwards, the response bag, like step 3., serial communication gateway 12 transmitted response bags are given host computer 11, like step 4..Through above-mentioned steps 1.~4., host computer 11 is accomplished an exchanges data with slave computer 13.
Though the present invention discloses as above with preferred embodiment; Right its is not that any those skilled in the art are not breaking away from the spirit and scope of the present invention in order to qualification the present invention; When can doing a little modification and perfect, so protection scope of the present invention is when being as the criterion with what claims defined.