WO2016095323A1 - Data transmission method and apparatus based on serial server - Google Patents

Data transmission method and apparatus based on serial server Download PDF

Info

Publication number
WO2016095323A1
WO2016095323A1 PCT/CN2015/071529 CN2015071529W WO2016095323A1 WO 2016095323 A1 WO2016095323 A1 WO 2016095323A1 CN 2015071529 W CN2015071529 W CN 2015071529W WO 2016095323 A1 WO2016095323 A1 WO 2016095323A1
Authority
WO
WIPO (PCT)
Prior art keywords
packet
timer
duration
data
network device
Prior art date
Application number
PCT/CN2015/071529
Other languages
French (fr)
Chinese (zh)
Inventor
刘昺麟
尹二飞
Original Assignee
北京东土科技股份有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 北京东土科技股份有限公司 filed Critical 北京东土科技股份有限公司
Publication of WO2016095323A1 publication Critical patent/WO2016095323A1/en

Links

Images

Definitions

  • the present invention relates to the field of network communication technologies, and in particular, to a data transmission method and apparatus based on a serial port server.
  • the serial port server is a server between the remote network device and the serial port terminal located in the Ethernet.
  • FIG. 1 is a schematic diagram of the connection structure between the serial port server, the remote network device, and the serial port terminal.
  • the serial port server connects the first serial port terminal and the second serial port terminal through the serial port 1 and the serial port 2 respectively, and connects to the remote network device by using a TCP connection. Only one remote network device is shown in FIG. 1 , and the serial port server can pass through A TCP connection that connects multiple remote network devices.
  • the serial port server completes the protocol conversion between the Ethernet data and the serial port data through software.
  • the serial port server not only expands the layout range of the device, but also makes the serial port data management more flexible and convenient.
  • the serial port server can realize the conversion between the serial port and the network interface, which can realize the conversion of RS-232, RS-485 and RS-422 serial port and TCP/IP network interface, thereby realizing RS-232, RS-485, RS-422. Two-way transparent transmission of serial port data and TCP/IP network interface data.
  • the serial server can work in TCP/UDP mode. In this mode, the serial server acts as the server and the remote network device acts as the client. The two establish a connection between the IP address and the port number to achieve bidirectional data. Transparent transmission.
  • the remote network device connected to the serial server is undefined.
  • the serial terminal is a passive device, and the data sent by the serial device does not include the start and end identifiers
  • the serial server divides the received multiple consecutive responses into multiple IP packets and sends them to the remote network device.
  • the remote network device needs to reassemble multiple IP packets.
  • the remote network device is In the case of a low-end network device, the low-end network device may not be able to reassemble the multiple IP packets. Even if it can be reassembled, it will consume a large amount of resources of the remote network device, thereby affecting the working efficiency of the remote network device.
  • the present invention has been made in order to provide a serial port server based data transmission method and apparatus that overcomes the above problems or at least partially solves the above problems.
  • the embodiment of the invention provides a data transmission method based on a serial port server, and the method includes:
  • the serial server receives the data packet sent by the serial terminal, caches the data packet, and starts a timer;
  • each buffered data packet is reassembled and sent to the first remote network device.
  • the re-synthesis of each data packet that is buffered and sent to the first remote network device includes:
  • the serial port server determines that a timeout interrupt is generated when no other data packet is received within the timer duration of the timer;
  • each buffered packet is reassembled and sent to the first remote network device.
  • the method further includes:
  • the serial port server generates an identifier packet, identifies whether the data packet in the cache is reassembled, and sends the identifier packet to the first remote network device.
  • determining the timing duration of the timer in the embodiment of the present invention includes:
  • the serial port server determines, according to each received data packet sent by the serial terminal terminal, a duration of two adjacent packet gaps;
  • the timing duration of the timer is determined to be greater than the packet gap duration
  • the timing duration of the timer is greater than the duration of the second packet gap is less than the duration of the first packet gap
  • the timing duration of the timer is greater than the duration of the first packet gap is less than the duration of the second packet gap.
  • determining the timing duration of the timer in the embodiment of the present invention includes:
  • the serial port server receives the response packet returned by the first remote network device, and when the response packet identifies that the reassembled data packet contains redundant information, the timer duration of the timer is adjusted to be less than the current timing duration. When the response packet identifies that the reassembled data packet contains incomplete information, the timer duration is adjusted to be greater than the current timing. duration.
  • the method further includes:
  • the serial server receives the data packet sent by the serial terminal, and determines whether the current timer expires
  • the data packet is sent to each remote network device connected to its TCP.
  • the method further includes:
  • the serial server buffers the request when receiving a request sent by the second remote network device and determining that the current time is within the time duration of the timer corresponding to the first remote network device.
  • the embodiment of the invention provides a data transmission device based on a serial port server, and the device includes:
  • a receiving buffer module configured to receive a data packet sent by the serial terminal, cache the data packet, and start a timer
  • a determining module configured to determine whether other data packets sent by the serial terminal are received within a timer duration of the timer
  • the cache sending module is configured to: when the determining module determines that other data packets are received, buffer the other data packets and restart the timer; otherwise, the buffered data packets are reassembled and sent to the first remote network device.
  • the cache sending module is specifically configured to determine that a timeout interrupt is generated when no other data packet is received within the timer duration; and the cache is cached according to the timeout interrupt. Each packet in the packet is reassembled and sent to the first remote network device.
  • the cache sending module is further configured to generate an identifier packet, identify whether the data packet in the buffer is reassembled, and send the identifier packet. Give the first remote network device.
  • the device in the embodiment of the present invention further includes:
  • a determining module configured to determine, according to the received each data packet sent by the serial terminal terminal, a duration of two adjacent packet gaps; determine whether the adjacent two packet gap durations are equal; When the packet gap duration is equal, the timing duration of the timer is determined to be greater than the packet gap duration; when the two packet gap durations are not equal, and the first packet gap duration is greater than the second packet gap duration, the determination is performed.
  • the timing duration of the timer is greater than the duration of the second packet gap is less than the duration of the first packet gap; when the duration of the two packet gaps is not equal, and the length of the first packet gap is less than the duration of the second packet gap, the timing is determined.
  • the timing duration of the device is greater than the duration of the first packet gap is less than the duration of the second packet gap.
  • the device in the embodiment of the present invention further includes:
  • the serial port server receives the response packet returned by the first remote network device, and when the response packet identifies that the reassembled data packet contains redundant information, the timer duration of the timer is adjusted to be less than the current timing duration. When the response packet identifies that the reassembled data packet contains incomplete information, the timer duration is adjusted to be greater than the current timing duration.
  • the determining module is further configured to: when receiving the data packet sent by the serial terminal, determine whether the current timer expires;
  • the cache sending module is further configured to: when the determining module determines that the current timer expires, send the data packet to each remote network device connected to the TCP.
  • the cache receiving module is further configured to receive a request sent by the second remote network device, in order to ensure the accuracy of the data transmission.
  • the determining module is further configured to determine whether it is currently located in a timing duration of a timer corresponding to the first remote network device;
  • the cache sending module is further configured to cache the request when the determining module determines that the current time is within a timer duration of a timer corresponding to the first remote network device.
  • the embodiment of the invention provides a data transmission method and device based on a serial port server.
  • the serial port server After the serial port server receives the data packet sent by the serial port terminal, the serial server starts a timer to determine whether to receive the timer within the time limit of the timer. When other data packets sent by the serial terminal are received, the data packet is buffered and the timer is restarted. Otherwise, each buffered data packet is reassembled and sent to the first remote network device.
  • the serial server after receiving the data packet of the serial port terminal, the serial server starts a timer. When the data packet is received again within the timer duration, the data packet is considered to be sent by the serial terminal, and the data is sent.
  • Packet buffering otherwise the data transmission process of the serial terminal is terminated, so that the buffered data packet is reassembled and sent to the remote network device, so that the data packet in the cache is reorganized, and the configuration requirements and resources of the remote network device are reduced. Consumption increases the efficiency of the remote network device.
  • FIG. 1 is a schematic structural diagram of a connection between a serial port server, a remote network device, and a serial port terminal provided by the prior art
  • FIG. 3 is a specific process of data transmission based on a serial port server according to an embodiment of the present invention:
  • FIG. 4 is a schematic structural diagram of a data transmission apparatus based on a serial port server according to an embodiment of the present invention.
  • the embodiment of the invention provides a data transmission method and device based on the serial port server.
  • FIG. 2 is a schematic diagram of a data transmission process based on a serial port server according to an embodiment of the present invention, where the process includes the following steps:
  • the serial server receives the data packet sent by the serial terminal, caches the data packet, and starts a timer.
  • the serial port terminal is a passive terminal, and the remote network device sends a request to the serial port terminal through the serial port server, and after receiving the request, the serial port terminal returns a data packet to the remote network device.
  • the serial terminal can return a data packet to the remote network device or return several data packets to the remote network device.
  • the serial server When the serial server receives the data packet sent by the serial terminal, in order to ensure that the data packet sent by the serial terminal is reassembled and sent to the remote network device, the serial server caches the data packet and starts a timer.
  • the timer can be implemented in software or in hardware.
  • step S202 Determine whether other data packets sent by the serial terminal terminal are received within the timer duration of the timer. If the determination result is yes, proceed to step S203; otherwise, proceed to step S204.
  • serial server can determine which serial terminal sends the data packet according to the identifier of the serial port that receives the data packet.
  • the serial server After receiving the other data packets sent by the serial terminal, the serial server ensures that each data packet requested by the first remote network device can be reassembled and returned. After receiving the other data packets, the serial server restarts the timer and determines that the data packet is Whether other data packets sent by the serial terminal can be received within the timer duration of the timer. In order to ensure that each packet of the serial port terminal can be reassembled, the serial server should set the timer duration longer than the packet gap length of the serial terminal to send the data packet.
  • S204 Reassemble each buffered packet and send it to the first remote network device.
  • the reply process of the serial terminal is considered to be completed, and each data packet in the cache is reassembled and sent to the first remote network device.
  • the serial server after receiving the data packet of the serial port terminal, the serial server starts the timer.
  • the data packet is considered to be sent by the serial terminal.
  • the data packet is cached. Otherwise, the data transmission process of the serial terminal is terminated, so that the buffered data packet is sent to the remote network device, so that the data packet in the cache is reorganized, and the configuration requirements and resources of the remote network device are reduced. Consumption increases the efficiency of the remote network device.
  • the cache is cached.
  • the data packet starts a timer.
  • the timer can be a T3 timer.
  • the timing of the T3 timer can be set as needed.
  • the serial server determines whether other data packets sent by the serial terminal are received within the timing of the T3 timer.
  • each data packet that is buffered is reassembled and sent. Give the first remote network device.
  • the serial port server receives the request sent by the second remote network device, and determines the timing of the timer currently located corresponding to the first remote network device.
  • the request is cached for a period of time.
  • the serial server receives another request sent by the first remote network device and determines that the current timer is located within the time duration of the timer corresponding to the first remote network device, the other request is cached.
  • a serial port interrupt can be generated based on the serial port controller integrated by the CPU chip of the serial server, thereby realizing the combination of software and hardware, and realizing high-precision data transceiving control.
  • the sending the buffered data packet to the first remote network device includes:
  • the serial port server determines that a timeout interrupt is generated when no other data packet is received within the timer duration of the timer;
  • the data packet in the cache is sent to the first remote network device.
  • the serial server When the serial server detects the timing of the timer, but does not receive other data packets sent by the serial terminal within the time limit, the serial server generates an interrupt to inform the end of the frame that the packet needs to be reorganized. Specifically, in the operating system of the serial server, after the serial port hardware (hardware) receives the data packet, the data packet is cached in the hardware cache, and the serial driver reads the data packet from the hardware cache. The data packet is transferred to the memory. When the interrupt is generated, the upper application reads the data packet from the memory and reassembles it, and sends the reassembled data packet through the network port.
  • the serial port hardware hardware
  • the serial port server provides a timeout interrupt mechanism
  • the serial port driver reads the data packet from the serial port hardware buffer, and puts the data packet into an identification field, identifies the data packet as data to be reassembled, and the data packet is After the memory is transferred to the memory, the upper layer application reads the data packet from the memory according to the identification field after receiving the interrupt, and reassembles the data packet and sends it.
  • the serial port driver reads the data packet from the hardware buffer, and adds an identification field to the data header portion of the data packet, and then transfers the data packet to the memory.
  • the data header of the data packet after the identifier field is added includes two parts, and the part is an identifier field.
  • the identifier field may be, for example, one byte, for example, may be “#”, and the other part is a data length, and the data length may occupy two. Byte to identify the actual length of the data after the packet is in the data header.
  • the application reads the data packet from the memory, the data header portion is first read, and the length of the subsequent data can be parsed according to the information contained in the data header, so that the corresponding data content can be obtained, thereby realizing data reorganization.
  • the format of the data packet encapsulated by the serial server can be as shown in the following table:
  • the data header of the data packet contains an identifier flag, which identifies it as the start bit of the data packet, and the identifier can take any value, the identifier occupies one byte, and the length portion occupies two bytes, indicating The length of the actual data content starting from the fourth byte, data is the reorganized data content.
  • the method further includes :
  • the serial port server generates an identifier packet, identifies whether the data packet in the cache is reassembled, and sends the identifier packet to the first remote network device.
  • the format of the identifier packet is as follows:
  • the flag is an identifier included in the header of the identifier packet to identify the start bit of the identifier packet
  • data is the actual data content of the identifier packet.
  • the data content can only be 0 or 1. 0 indicates that the data packet has been reorganized, 1 indicates that the data packet is not reassembled, and time is the time at which the serial port server currently encapsulates the identification packet, and is mainly used to distinguish the ordinary data packet of the serial port server from the identification packet.
  • determining the timing duration of the timer in the embodiment of the present invention includes:
  • the serial port server determines, according to each received data packet sent by the serial terminal terminal, a duration of two adjacent packet gaps;
  • the timing duration of the timer is determined to be greater than the packet gap duration
  • the timing duration of the timer is greater than the duration of the second packet gap is less than the duration of the first packet gap.
  • the serial port server can flexibly set the corresponding packet gap duration for each serial port terminal according to the characteristics of each serial port terminal. Specifically, when the serial port server sets its corresponding packet gap duration for each serial port terminal, according to the serial port terminal
  • Each data packet sent determines the length of two adjacent packet gaps of the serial terminal. For example, if the data packet sent by the serial terminal is A, B, C, ..., the time interval between the data packet A and the data packet B is the first packet gap length, and the time between the data packet B and the data packet C. The interval is the second packet gap length, and the two adjacent packet gap lengths are the first packet gap length and the second packet gap length.
  • the two packet gap lengths are the packet gaps corresponding to the data packets sent by the serial terminal terminal.
  • the length, the timer duration of the timer is set to be greater than the packet gap length.
  • the absolute value of the difference between the two packet gap lengths may be within a certain threshold range.
  • the two requested packet gaps can be set to be longer than the second packet gap duration, but less than the first packet gap duration.
  • the first packet gap is the reply to the first requested packet gap
  • the second packet gap is the reply.
  • the packet gap will be followed by another request.
  • the timer duration can be set to be longer than the first packet gap duration, but less than the second packet gap duration.
  • determining the timing duration of the timer includes:
  • the serial port server receives the response packet returned by the first remote network device, and when the response packet identifies that the reassembled data packet contains redundant information, adjusts the timer duration of the timer to be smaller than the current timing duration, when the response When the information contained in the packet after reassembly is incomplete, the timer duration of the timer is adjusted to be greater than the current timing duration.
  • the response packet may be returned to the serial server according to whether the data packet is complete.
  • the timer duration of the timer in the serial server can be arbitrarily set. According to the set timing of the timer, it is determined that the data packet is returned to the remote network device, reassembled and sent. After receiving the reassembled data packet, the remote network device determines the integrity of the data, and the integrity information is included in the response information and sent to the serial server.
  • the serial server determines, according to the information contained in the response information, that the reassembled data packet contains redundant information, that is, when the reassembled data packet contains more data than the remote network device requires, determining the current timer timing time is longer. If the information of the reassembled data packet is incomplete, it is determined that the current timer has a short duration and cannot obtain complete data. It is necessary to increase the timing of the timer.
  • the interaction between the serial server and the remote network device can determine the timing of the timer corresponding to the corresponding serial terminal.
  • the method further includes:
  • the serial server receives the data packet sent by the serial terminal, and determines whether the current timer expires
  • the data packet is sent to each remote network device connected to its TCP.
  • FIG. 3 is a specific process of data transmission based on a serial port server according to an embodiment of the present invention, where the process includes the following steps:
  • the serial server receives the request sent by the first remote network device, and sends the request to the first serial terminal.
  • the serial server receives the data packet returned by the first serial terminal, caches the data packet, and starts a timer.
  • step S303 Determine whether other data packets returned by the first serial port terminal are received within the time limit of the timer. If the determination result is yes, proceed to step S304; otherwise, proceed to step S305.
  • S305 Send the buffered data packet to the first remote network device.
  • the serial server receives other data packets sent by the first serial terminal.
  • step S307 The serial server determines whether the current timer has timed out. If the determination result is yes, proceed to step S308; otherwise, proceed to step S304.
  • S308 Send the data packet to each remote network device connected to its TCP.
  • the serial server establishes a TCP connection with the first remote network device, and receives the request sent by the first remote network device by using the TCP connection, where the request carries the identifier information of the serial terminal that communicates with the request, and the identifier information It can be the connection address information of the serial terminal.
  • the serial server sends the request to the corresponding serial terminal.
  • the serial terminal returns a data packet to the serial server according to the request.
  • the serial server receives the data packet, the data packet is buffered and a timer is started. Determining whether other data packets sent by the serial terminal are received within the time limit of the timer.
  • the other data packets are buffered and the timer is restarted. During the timer duration of the timer, it continues to monitor whether other data packets sent by the serial terminal are received. When the data packet returned by the serial terminal is not received within a certain timing of the timer, the timer is not received when the timer expires. When the data packet returned by the serial terminal is determined, it is determined that the reply process of the serial terminal ends, the data packet in the cache is reorganized, reassembled into an IP data packet, and the reassembled data packet is sent to the corresponding remote network device. .
  • the serial server accumulates each data packet returned by the serial terminal without timeout in a reply period, and reassembles the accumulated data packet into an IP data packet and sends it when timeout, thereby avoiding the far distance.
  • the network device reassembles the data packet, which reduces the configuration requirements and resource consumption of the remote network device, and improves the working efficiency of the remote network device.
  • the serial server receives other data packets sent by the serial terminal, and the serial server sends the data packet to each remote network device connected to the TCP.
  • the serial server after receiving the data packet of the serial port terminal, the serial server starts a timer.
  • the data packet is considered to be sent by the serial terminal, and the data is sent.
  • Packet buffering otherwise it is considered that the data transmission process of the serial terminal ends, thereby transmitting the buffered data packet to the remote network device, realizing the reorganization of the data packet in the cache, and reducing the configuration requirements and resource consumption of the remote network device. Improve the efficiency of remote network devices.
  • FIG. 4 is a schematic structural diagram of a data transmission apparatus based on a serial port server according to an embodiment of the present invention, where the apparatus includes:
  • the receiving buffer module 41 is configured to receive a data packet sent by the serial terminal, cache the data packet, and start a timer.
  • the determining module 42 is configured to determine whether other data packets sent by the serial terminal are received within the time duration of the timer;
  • the buffer sending module 43 is configured to: when the determining module determines that another data packet is received, buffer the other data packet and restart the timer; otherwise, send the buffered data packet to the first remote network device.
  • the cache sending module 43 is specifically configured to determine that a timeout interrupt is generated when no other data packet is received within the timer duration of the timer; The data packet in the cache is sent to the first remote network device.
  • the cache sending module 43 is further configured to generate an identifier packet, identify whether the data packet in the buffer is reorganized, and identify the packet. Send to the first remote network device.
  • the device in the embodiment of the present invention further includes:
  • the determining module 44 is configured to determine, according to the received data packet sent by the serial terminal terminal, a duration of two adjacent packet gaps; determine whether the adjacent two packet gap durations are equal; When the packet gap durations are equal, the timing duration of the timer is determined to be greater than the packet gap duration; when the two packet gap durations are not equal, and the first packet gap duration is greater than the second packet gap duration, The timing duration of the timer is greater than the duration of the second packet gap is less than the length of the first packet gap; when the duration of the two packet gaps is not equal, and the length of the first packet gap is less than the duration of the second packet gap, the determining The timer duration of the timer is greater than the duration of the first packet gap is less than the duration of the second packet gap.
  • the device also includes:
  • the determining module 44 is configured to receive a response packet returned by the first remote network device, and when the response packet identifies that the reassembled data packet includes redundant information, adjust a timer duration of the timer to be less than a current timing duration. When the response packet identifies that the information contained in the reassembled data packet is incomplete, the timer duration of the timer is adjusted to be greater than the current timing duration.
  • the determining module 42 is further configured to: when receiving the data packet sent by the serial terminal, determine whether the current timer expires;
  • the cache sending module 43 is further configured to: when the determining module determines that the current timer expires, send the data packet to each remote network device connected to the TCP.
  • the cache receiving module 41 is further configured to receive a request sent by the second remote network device, in order to ensure the accuracy of the data transmission.
  • the determining module 42 is further configured to determine whether it is currently located in a timing duration of a timer corresponding to the first remote network device;
  • the cache sending module 43 is further configured to cache the request when the determining module determines that the timing of the timer currently located in the first remote network device is within a predetermined duration.
  • the embodiment of the invention provides a data transmission method and device based on a serial port server.
  • the serial port server After the serial port server receives the data packet sent by the serial port terminal, the serial server starts a timer to determine whether to receive the timer within the time limit of the timer. When other data packets sent by the serial terminal are received, the data packet is buffered and the timer is restarted. Otherwise, each buffered data packet is reassembled and sent to the first remote network device.
  • the serial server after receiving the data packet of the serial port terminal, the serial server starts a timer. When the data packet is received again within the timer duration, the data packet is considered to be sent by the serial terminal, and the data is sent.
  • Packet buffering otherwise it is considered that the data transmission process of the serial terminal ends, thereby transmitting the buffered data packet to the remote network device, realizing the reorganization of the data packet in the cache, and reducing the configuration requirements and resource consumption of the remote network device. Improve the efficiency of remote network devices.
  • modules in the devices of the embodiments can be adaptively changed and placed in one or more devices different from the embodiment.
  • the modules or units or components of the embodiments may be combined into one module or unit or component, and further they may be divided into a plurality of sub-modules or sub-units or sub-components.
  • any combination of the features disclosed in the specification, including the accompanying claims, the abstract and the drawings, and any methods so disclosed, or All processes or units of the device are combined.
  • Each feature disclosed in this specification (including the accompanying claims, the abstract and the drawings) may be replaced by alternative features that provide the same, equivalent or similar purpose.
  • the various component embodiments of the present invention may be implemented in hardware, or in a software module running on one or more processors, or in a combination thereof.
  • a microprocessor or digital signal processor may be used in practice to implement some or all of the functionality of some or all of the components of a serial server based data transmission device in accordance with embodiments of the present invention.
  • the invention can also be implemented as a device or device program (e.g., a computer program and a computer program product) for performing some or all of the methods described herein.
  • Such a program implementing the invention may be stored on a computer readable medium or may be in the form of one or more signals. Such signals may be downloaded from an Internet website, provided on a carrier signal, or provided in any other form.

Abstract

Provided are a data transmission method and apparatus based on a serial server. In the method, when receiving a data packet sent by a serial terminal, a serial server starts a timer, judges whether other data packets sent by the serial terminal are received within a timing duration of the timer, and caches the data packet and restarts the timer when the other data packets are received, or otherwise sends the cached data packet to a first far-end network device. In the embodiments of the present invention, since after receiving a data packet from a serial terminal a serial server starts a timer, when the data packet is received again within the duration range of the timer it is considered that the data packet is sent by the serial terminal, and the data packet is cached, or otherwise it is considered that the data sending process of the serial terminal ends, and accordingly the cached data packet is sent to a far-end network device, so as to recombine the cached data packet, thereby reducing the configuration requirement and resource consumption of the far-end network device, and improving the operation efficiency of the far-end network device.

Description

一种基于串口服务器的数据传输方法及装置Data transmission method and device based on serial port server
本申请要求在2014年12月16日提交中国专利局、申请号为201410784390.6、发明名称为“一种基于串口服务器的数据传输方法及装置”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。This application claims priority to Chinese Patent Application No. 201410784390.6, entitled "A Serial Port Server-Based Data Transmission Method and Apparatus", filed on December 16, 2014, the entire contents of which are incorporated by reference. In this application.
技术领域Technical field
本发明涉及网络通信技术领域,尤其涉及一种基于串口服务器的数据传输方法及装置。The present invention relates to the field of network communication technologies, and in particular, to a data transmission method and apparatus based on a serial port server.
背景技术Background technique
串口服务器是位于以太网中的远端网络设备与串口终端之间的服务器,图1为串口服务器、远端网络设备及串口终端之间的连接结构示意图。串口服务器通过串口1和串口2分别连接第一串口终端和第二串口终端,并采用TCP连接的方式连接远端网络设备,图1中只示出了一个远端网络设备,串口服务器可以通过多条TCP连接,连接多个远端网络设备。串口服务器通过软件的方式完成以太网数据与串口数据之间的协议转换,通过串口服务器既扩展了设备的布局范围,又使串口数据的管理更加的灵活和方便。The serial port server is a server between the remote network device and the serial port terminal located in the Ethernet. FIG. 1 is a schematic diagram of the connection structure between the serial port server, the remote network device, and the serial port terminal. The serial port server connects the first serial port terminal and the second serial port terminal through the serial port 1 and the serial port 2 respectively, and connects to the remote network device by using a TCP connection. Only one remote network device is shown in FIG. 1 , and the serial port server can pass through A TCP connection that connects multiple remote network devices. The serial port server completes the protocol conversion between the Ethernet data and the serial port data through software. The serial port server not only expands the layout range of the device, but also makes the serial port data management more flexible and convenient.
串口服务器可以实现串口与网络接口之间的转换,其能够实现RS-232、RS-485以及RS-422串口与TCP/IP网络接口的转换,从而实现RS-232、RS-485、RS-422串口数据与TCP/IP网络接口数据的双向透明传输。The serial port server can realize the conversion between the serial port and the network interface, which can realize the conversion of RS-232, RS-485 and RS-422 serial port and TCP/IP network interface, thereby realizing RS-232, RS-485, RS-422. Two-way transparent transmission of serial port data and TCP/IP network interface data.
另外,串口服务器可以在TCP/UDP模式下工作,在该模式下,串口服务器作为server端,远端网络设备作为client端,两者之间通过IP地址与端口号建立连接,从而实现数据的双向透明传输。In addition, the serial server can work in TCP/UDP mode. In this mode, the serial server acts as the server and the remote network device acts as the client. The two establish a connection between the IP address and the port number to achieve bidirectional data. Transparent transmission.
在基于串口服务器进行通信时,与串口服务器连接的远端网络设备是不确定的,当串口终端为被动设备,并且串口设备发送的数据中不包含起始和终止标识,当远端网络设备与串口终端进行通信时,串口服务器会把收到的多个连续的应答分为多个IP包发送给远端网络设备,远端网络设备需要将多个IP包进行重组,当远端网络设备为低端网络设备时,该低端网络设备可能无法重组该多个IP包,即使能够重组也将消耗远端网络设备的大量资源,从而影响远端网络设备的工作效率。 When communicating based on the serial server, the remote network device connected to the serial server is undefined. When the serial terminal is a passive device, and the data sent by the serial device does not include the start and end identifiers, when the remote network device is When the serial terminal communicates, the serial server divides the received multiple consecutive responses into multiple IP packets and sends them to the remote network device. The remote network device needs to reassemble multiple IP packets. When the remote network device is In the case of a low-end network device, the low-end network device may not be able to reassemble the multiple IP packets. Even if it can be reassembled, it will consume a large amount of resources of the remote network device, thereby affecting the working efficiency of the remote network device.
发明内容Summary of the invention
鉴于上述问题,提出了本发明以便提供一种克服上述问题或者至少部分地解决上述问题的一种基于串口服务器的数据传输方法及装置。In view of the above problems, the present invention has been made in order to provide a serial port server based data transmission method and apparatus that overcomes the above problems or at least partially solves the above problems.
本发明实施例提供了一种基于串口服务器的数据传输方法,该方法包括:The embodiment of the invention provides a data transmission method based on a serial port server, and the method includes:
串口服务器接收串口终端发送的数据包,缓存所述数据包并启动定时器;The serial server receives the data packet sent by the serial terminal, caches the data packet, and starts a timer;
判断在定时器的定时时长内,是否接收到该串口终端发送的其他数据包;Determining whether other data packets sent by the serial terminal are received within the timer duration of the timer;
当接收到其他数据包时,缓存所述其他数据包并重新启动定时器,否则,将缓存的每个数据包重组后发送给第一远端网络设备。When other data packets are received, the other data packets are buffered and the timer is restarted. Otherwise, each buffered data packet is reassembled and sent to the first remote network device.
为了有效的提高数据传输的精度,在本发明实施例中所述将缓存的每个数据包重组后发送给第一远端网络设备包括:In order to effectively improve the accuracy of data transmission, in the embodiment of the present invention, the re-synthesis of each data packet that is buffered and sent to the first remote network device includes:
所述串口服务器确定在定时器的定时时长内未接收到其他数据包时,生成超时中断;The serial port server determines that a timeout interrupt is generated when no other data packet is received within the timer duration of the timer;
根据超时中断,将缓存的每个数据包重组后发送给第一远端网络设备。According to the timeout interrupt, each buffered packet is reassembled and sent to the first remote network device.
为了有效的提高数据传输的准确性,降低远端网络设备的配置要求,所述将缓存的每个数据包重组后发送给第一远端网络设备后,所述方法还包括:In order to effectively improve the accuracy of data transmission and reduce the configuration requirements of the remote network device, after the data packet is reassembled and sent to the first remote network device, the method further includes:
串口服务器生成标识报文,标识缓存中的数据包是否进行了重组,并将标识报文发送给第一远端网络设备。The serial port server generates an identifier packet, identifies whether the data packet in the cache is reassembled, and sends the identifier packet to the first remote network device.
为了有效的保证数据传输的准确性,在本发明实施例中确定所述定时器的定时时长包括:In order to effectively ensure the accuracy of the data transmission, determining the timing duration of the timer in the embodiment of the present invention includes:
串口服务器根据接收到的所述串口终端发送的每个数据包,确定相邻的两个包间隙时长;The serial port server determines, according to each received data packet sent by the serial terminal terminal, a duration of two adjacent packet gaps;
判断所述相邻的两个包间隙时长是否相等;Determining whether the lengths of the adjacent two packet gaps are equal;
当相邻的两个包间隙时长相等时,将所述定时器的定时时长确定为大于所述包间隙时长;When the lengths of the adjacent two packet gaps are equal, the timing duration of the timer is determined to be greater than the packet gap duration;
当两个包间隙时长不相等,且第一个包间隙时长大于第二个包间隙时长时,确定所述定时器的定时时长大于第二个包间隙时长小于第一个包间隙时长;When the duration of the two packet gaps is not equal, and the length of the first packet gap is greater than the length of the second packet gap, it is determined that the timing duration of the timer is greater than the duration of the second packet gap is less than the duration of the first packet gap;
当两个包间隙时长不相等,且第一个包间隙时长小于第二个包间隙时长时,确定所述定时器的定时时长大于第一个包间隙时长小于第二个包间隙时长。When the duration of the two packet gaps is not equal, and the length of the first packet gap is less than the duration of the second packet gap, it is determined that the timing duration of the timer is greater than the duration of the first packet gap is less than the duration of the second packet gap.
为了有效的保证数据传输的准确性,在本发明实施例中确定所述定时器的定时时长包括:In order to effectively ensure the accuracy of the data transmission, determining the timing duration of the timer in the embodiment of the present invention includes:
所述串口服务器接收第一远端网络设备返回的响应报文,当该响应报文标识重组后的数据包中包含多余信息时,将定时器的定时时长调整为小于当前的定时时长,当该响应报文标识重组后的数据包包含的信息不完整时,将定时器的定时时长调整为大于当前的定时 时长。The serial port server receives the response packet returned by the first remote network device, and when the response packet identifies that the reassembled data packet contains redundant information, the timer duration of the timer is adjusted to be less than the current timing duration. When the response packet identifies that the reassembled data packet contains incomplete information, the timer duration is adjusted to be greater than the current timing. duration.
为了有效的保证数据传输的准确性,所述方法还包括:In order to effectively ensure the accuracy of data transmission, the method further includes:
所述串口服务器接收所述串口终端发送的数据包,判断当前所述定时器是否超时;The serial server receives the data packet sent by the serial terminal, and determines whether the current timer expires;
当当前所述定时器超时时,将所述数据包发送给与其TCP连接的每个远端网络设备。When the current timer expires, the data packet is sent to each remote network device connected to its TCP.
为了有效的保证数据传输的准确性,所述方法还包括:In order to effectively ensure the accuracy of data transmission, the method further includes:
所述串口服务器接收第二远端网络设备发送的请求,判断当前位于与所述第一远端网络设备对应的定时器的定时时长内时,缓存所述请求。The serial server buffers the request when receiving a request sent by the second remote network device and determining that the current time is within the time duration of the timer corresponding to the first remote network device.
本发明实施例提供了一种基于串口服务器的数据传输装置,所述装置包括:The embodiment of the invention provides a data transmission device based on a serial port server, and the device includes:
接收缓存模块,用于接收串口终端发送的数据包,缓存所述数据包并启动定时器;a receiving buffer module, configured to receive a data packet sent by the serial terminal, cache the data packet, and start a timer;
判断模块,用于判断在定时器的定时时长内,是否接收到该串口终端发送的其他数据包;a determining module, configured to determine whether other data packets sent by the serial terminal are received within a timer duration of the timer;
缓存发送模块,用于当判断模块判断接收到其他数据包时,缓存所述其他数据包并重新启动定时器,否则,将缓存的每个数据包重组后发送给第一远端网络设备。The cache sending module is configured to: when the determining module determines that other data packets are received, buffer the other data packets and restart the timer; otherwise, the buffered data packets are reassembled and sent to the first remote network device.
为了有效的提高数据传输的精度,在本发明实施例中所述缓存发送模块,具体用于确定在定时器的定时时长内未接收到其他数据包时,生成超时中断;根据超时中断,将缓存中的每个数据包重组后发送给第一远端网络设备。In order to effectively improve the accuracy of the data transmission, in the embodiment of the present invention, the cache sending module is specifically configured to determine that a timeout interrupt is generated when no other data packet is received within the timer duration; and the cache is cached according to the timeout interrupt. Each packet in the packet is reassembled and sent to the first remote network device.
为了有效的提高数据传输的准确性,降低远端网络设备的配置要求,所述缓存发送模块,还用于生成标识报文,标识缓存中的数据包是否进行了重组,并将标识报文发送给第一远端网络设备。In order to effectively improve the accuracy of the data transmission and reduce the configuration requirements of the remote network device, the cache sending module is further configured to generate an identifier packet, identify whether the data packet in the buffer is reassembled, and send the identifier packet. Give the first remote network device.
为了有效的保证数据传输的准确性,在本发明实施例中所述装置还包括:In order to effectively ensure the accuracy of the data transmission, the device in the embodiment of the present invention further includes:
确定模块,用于根据接收到的所述串口终端发送的每个数据包,确定相邻的两个包间隙时长;判断所述相邻的两个包间隙时长是否相等;当相邻的两个包间隙时长相等时,将所述定时器的定时时长确定为大于所述包间隙时长;当两个包间隙时长不相等,且第一个包间隙时长大于第二个包间隙时长时,确定所述定时器的定时时长大于第二个包间隙时长小于第一个包间隙时长;当两个包间隙时长不相等,且第一个包间隙时长小于第二个包间隙时长时,确定所述定时器的定时时长大于第一个包间隙时长小于第二个包间隙时长。a determining module, configured to determine, according to the received each data packet sent by the serial terminal terminal, a duration of two adjacent packet gaps; determine whether the adjacent two packet gap durations are equal; When the packet gap duration is equal, the timing duration of the timer is determined to be greater than the packet gap duration; when the two packet gap durations are not equal, and the first packet gap duration is greater than the second packet gap duration, the determination is performed. The timing duration of the timer is greater than the duration of the second packet gap is less than the duration of the first packet gap; when the duration of the two packet gaps is not equal, and the length of the first packet gap is less than the duration of the second packet gap, the timing is determined. The timing duration of the device is greater than the duration of the first packet gap is less than the duration of the second packet gap.
为了有效的保证数据传输的准确性,在本发明实施例中所述装置还包括:In order to effectively ensure the accuracy of the data transmission, the device in the embodiment of the present invention further includes:
所述串口服务器接收第一远端网络设备返回的响应报文,当该响应报文标识重组后的数据包中包含多余信息时,将定时器的定时时长调整为小于当前的定时时长,当该响应报文标识重组后的数据包包含的信息不完整时,将定时器的定时时长调整为大于当前的定时时长。The serial port server receives the response packet returned by the first remote network device, and when the response packet identifies that the reassembled data packet contains redundant information, the timer duration of the timer is adjusted to be less than the current timing duration. When the response packet identifies that the reassembled data packet contains incomplete information, the timer duration is adjusted to be greater than the current timing duration.
为了有效的保证数据传输的准确性,所述判断模块,还用于当接收到所述串口终端发送的数据包,判断当前所述定时器是否超时; In order to ensure the accuracy of the data transmission, the determining module is further configured to: when receiving the data packet sent by the serial terminal, determine whether the current timer expires;
所述缓存发送模块,还用于当判断模块判断当前所述定时器超时时,将所述数据包发送给与其TCP连接的每个远端网络设备。The cache sending module is further configured to: when the determining module determines that the current timer expires, send the data packet to each remote network device connected to the TCP.
为了有效的保证数据传输的准确性,所述缓存接收模块,还用于接收第二远端网络设备发送的请求;The cache receiving module is further configured to receive a request sent by the second remote network device, in order to ensure the accuracy of the data transmission.
所述判断模块,还用于判断是否当前位于与所述第一远端网络设备对应的定时器的定时时长内;The determining module is further configured to determine whether it is currently located in a timing duration of a timer corresponding to the first remote network device;
所述缓存发送模块,还用于当所述判断模块判断当前位于与所述第一远端网络设备对应的定时器的定时时长内时,缓存所述请求。The cache sending module is further configured to cache the request when the determining module determines that the current time is within a timer duration of a timer corresponding to the first remote network device.
本发明实施例提供了一种基于串口服务器的数据传输方法及装置,该方法中当串口服务器接收到串口终端发送的数据包后,启动定时器,判断在该定时器的定时时长内,是否接收到该串口终端发送的其他数据包,当接收到其他数据包时,缓存该数据包并重启定时器,否则,将缓存的每个数据包重组后发送给第一远端网络设备。由于在本发明实施例中串口服务器接收到串口终端的数据包后,启动定时器,当在定时器时长范围内再次收到数据包时,认为该数据包为该串口终端发送的,将该数据包缓存,否则认为该串口终端的数据发送过程结束,从而将缓存的数据包重组后发送给远端网络设备,实现对缓存中数据包的重组,降低了对远端网络设备的配置要求及资源消耗,提高了远端网络设备的工作效率。The embodiment of the invention provides a data transmission method and device based on a serial port server. After the serial port server receives the data packet sent by the serial port terminal, the serial server starts a timer to determine whether to receive the timer within the time limit of the timer. When other data packets sent by the serial terminal are received, the data packet is buffered and the timer is restarted. Otherwise, each buffered data packet is reassembled and sent to the first remote network device. In the embodiment of the present invention, after receiving the data packet of the serial port terminal, the serial server starts a timer. When the data packet is received again within the timer duration, the data packet is considered to be sent by the serial terminal, and the data is sent. Packet buffering, otherwise the data transmission process of the serial terminal is terminated, so that the buffered data packet is reassembled and sent to the remote network device, so that the data packet in the cache is reorganized, and the configuration requirements and resources of the remote network device are reduced. Consumption increases the efficiency of the remote network device.
上述说明仅是本发明技术方案的概述,为了能够更清楚了解本发明的技术手段,而可依照说明书的内容予以实施,并且为了让本发明的上述和其它目的、特征和优点能够更明显易懂,以下特举本发明的具体实施方式。The above description is only an overview of the technical solutions of the present invention, and the above-described and other objects, features and advantages of the present invention can be more clearly understood. Specific embodiments of the invention are set forth below.
附图说明DRAWINGS
通过阅读下文优选实施方式的详细描述,各种其他的优点和益处对于本领域普通技术人员将变得清楚明了。附图仅用于示出优选实施方式的目的,而并不认为是对本发明的限制。而且在整个附图中,用相同的参考符号表示相同的部件。在附图中:Various other advantages and benefits will become apparent to those skilled in the art from a The drawings are only for the purpose of illustrating the preferred embodiments and are not to be construed as limiting. Throughout the drawings, the same reference numerals are used to refer to the same parts. In the drawing:
图1为现有技术提供的串口服务器、远端网络设备及串口终端之间的连接结构示意图;1 is a schematic structural diagram of a connection between a serial port server, a remote network device, and a serial port terminal provided by the prior art;
图2为本发明实施例提供的一种基于串口服务器的数据传输过程;2 is a data transmission process based on a serial port server according to an embodiment of the present invention;
图3为本发明实施例提供的一种基于串口服务器的数据传输的具体过程:FIG. 3 is a specific process of data transmission based on a serial port server according to an embodiment of the present invention:
图4为本发明实施例提供的一种基于串口服务器的数据传输装置结构示意图。FIG. 4 is a schematic structural diagram of a data transmission apparatus based on a serial port server according to an embodiment of the present invention.
具体实施方式detailed description
为了降低对远端网络设备的配置要求及资源消耗,提高远端网络设备的工作效率,本发明实施例提供了一种基于串口服务器的数据传输方法及装置。 In order to reduce the configuration requirements and resource consumption of the remote network device and improve the working efficiency of the remote network device, the embodiment of the invention provides a data transmission method and device based on the serial port server.
下面将参照附图更详细地描述本公开的示例性实施例。虽然附图中显示了本公开的示例性实施例,然而应当理解,可以以各种形式实现本公开而不应被这里阐述的实施例所限制。相反,提供这些实施例是为了能够更透彻地理解本公开,并且能够将本公开的范围完整的传达给本领域的技术人员。Exemplary embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. While the embodiments of the present invention have been shown in the drawings, the embodiments Rather, these embodiments are provided so that this disclosure will be more fully understood and the scope of the disclosure will be fully disclosed.
下面结合说明附图,对本发明实施例进行说明。The embodiments of the present invention will be described below with reference to the accompanying drawings.
图2为本发明实施例提供的一种基于串口服务器的数据传输过程,该过程包括以下步骤:FIG. 2 is a schematic diagram of a data transmission process based on a serial port server according to an embodiment of the present invention, where the process includes the following steps:
S201:串口服务器接收串口终端发送的数据包,缓存所述数据包并启动定时器。S201: The serial server receives the data packet sent by the serial terminal, caches the data packet, and starts a timer.
本发明实施例中串口终端为被动终端,远端网络设备通过串口服务器向串口终端发送请求,串口终端接收到请求后,向远端网络设备返回数据包。针对该请求,串口终端可以向远端网络设备返回一个数据包,也可以向远端网络设备返回几个数据包。In the embodiment of the present invention, the serial port terminal is a passive terminal, and the remote network device sends a request to the serial port terminal through the serial port server, and after receiving the request, the serial port terminal returns a data packet to the remote network device. For this request, the serial terminal can return a data packet to the remote network device or return several data packets to the remote network device.
当串口服务器接收到串口终端发送的数据包时,为了保证将该串口终端发送的数据包重组后发送给远端网络设备,串口服务器缓存该数据包并启动定时器。该定时器可以是以软件方式实现的,也可以是以硬件方式实现的。When the serial server receives the data packet sent by the serial terminal, in order to ensure that the data packet sent by the serial terminal is reassembled and sent to the remote network device, the serial server caches the data packet and starts a timer. The timer can be implemented in software or in hardware.
S202:判断在定时器的定时时长内,是否接收到该串口终端发送的其他数据包,当判断结果为是时,进行步骤S203,否则,进行步骤S204。S202: Determine whether other data packets sent by the serial terminal terminal are received within the timer duration of the timer. If the determination result is yes, proceed to step S203; otherwise, proceed to step S204.
串口服务器每个串口连接对应的串口终端,因此串口服务器根据接收数据包的串口的标识,即可确定是哪个串口终端发送的数据包。Each serial port of the serial server is connected to the corresponding serial terminal. Therefore, the serial server can determine which serial terminal sends the data packet according to the identifier of the serial port that receives the data packet.
S203:缓存所述其他数据包并重新启动定时器,之后进行步骤S202。S203: Cache the other data packet and restart the timer, and then proceed to step S202.
串口服务器接收到该串口终端发送的其他数据包后,为了保证能够将第一远端网络设备请求的每个数据包重组后返回,串口服务器接收到其他数据包后,重启定时器,判断在该定时器的定时时长内是否还能接收到该串口终端发送的其他数据包。串口服务器为了保证能够将串口终端此次回复的每个数据包重组,设置的定时器的定时时长应大于串口终端发送数据包的包间隙长度。After receiving the other data packets sent by the serial terminal, the serial server ensures that each data packet requested by the first remote network device can be reassembled and returned. After receiving the other data packets, the serial server restarts the timer and determines that the data packet is Whether other data packets sent by the serial terminal can be received within the timer duration of the timer. In order to ensure that each packet of the serial port terminal can be reassembled, the serial server should set the timer duration longer than the packet gap length of the serial terminal to send the data packet.
S204:将缓存的每个数据包重组后发送给第一远端网络设备。S204: Reassemble each buffered packet and send it to the first remote network device.
在定时器的定时时长内未接收到该串口终端发送的数据包时,可以认为该串口终端的回复过程结束,将缓存中的每个数据包重组后发送给第一远端网络设备。When the data packet sent by the serial terminal is not received within the time limit of the timer, the reply process of the serial terminal is considered to be completed, and each data packet in the cache is reassembled and sent to the first remote network device.
由于在本发明实施例中串口服务器接收到串口终端的数据包后,启动定时器,当在定时器的定时时长范围内再次收到数据包时,认为该数据包为该串口终端发送的,将该数据包缓存,否则认为该串口终端的数据发送过程结束,从而将缓存的数据包发送给远端网络设备,实现对缓存中数据包的重组,降低了对远端网络设备的配置要求及资源消耗,提高了远端网络设备的工作效率。In the embodiment of the present invention, after receiving the data packet of the serial port terminal, the serial server starts the timer. When the data packet is received again within the time limit of the timer, the data packet is considered to be sent by the serial terminal. The data packet is cached. Otherwise, the data transmission process of the serial terminal is terminated, so that the buffered data packet is sent to the remote network device, so that the data packet in the cache is reorganized, and the configuration requirements and resources of the remote network device are reduced. Consumption increases the efficiency of the remote network device.
具体的,在本发明实施例中当串口服务器接收到某一串口终端发送的数据包后,缓存 该数据包并启动定时器,该定时器可以是T3定时器,T3定时器的定时时长可以根据需要进行设置。串口服务器判断在该T3定时器的定时时长内是否接收到该串口终端发送的其他数据包,当接收到该串口终端发送的其他数据包时,缓存该其他数据包并重启定时器,并继续判断在该定时器的定时时长内是否接收到该串口终端发送的其他数据包;当在定时器的定时时长内未接收到串口终端发送的其他数据包时,将缓存的每个数据包重组后发送给第一远端网络设备。Specifically, in the embodiment of the present invention, after the serial port server receives the data packet sent by a serial port terminal, the cache is cached. The data packet starts a timer. The timer can be a T3 timer. The timing of the T3 timer can be set as needed. The serial server determines whether other data packets sent by the serial terminal are received within the timing of the T3 timer. When receiving other data packets sent by the serial terminal, buffering the other data packets and restarting the timer, and continuing to determine Whether other data packets sent by the serial port terminal are received within the time limit of the timer; when other data packets sent by the serial port terminal are not received within the time limit of the timer, each data packet that is buffered is reassembled and sent. Give the first remote network device.
在本发明实施例中为了保证数据发送的完整性及准确性,所述串口服务器接收第二远端网络设备发送的请求,判断当前位于与所述第一远端网络设备对应的定时器的定时时长内时,缓存所述请求。或者,当该串口服务器接收到第一远端网络设备发送的其他请求,判断当前位于与所述第一远端网络设备对应的定时器的定时时长内时,缓存该其他请求。In the embodiment of the present invention, in order to ensure the integrity and accuracy of the data transmission, the serial port server receives the request sent by the second remote network device, and determines the timing of the timer currently located corresponding to the first remote network device. The request is cached for a period of time. Alternatively, when the serial server receives another request sent by the first remote network device and determines that the current timer is located within the time duration of the timer corresponding to the first remote network device, the other request is cached.
为了有效的提高数据传输的精度,在本发明实施例中可以基于串口服务器的CPU芯片集成的串口控制器,生成超时中断,从而实现软件与硬件的结合,实现高精度数据收发控制。所述将缓存的数据包发送给第一远端网络设备包括:In order to effectively improve the accuracy of the data transmission, in the embodiment of the present invention, a serial port interrupt can be generated based on the serial port controller integrated by the CPU chip of the serial server, thereby realizing the combination of software and hardware, and realizing high-precision data transceiving control. The sending the buffered data packet to the first remote network device includes:
所述串口服务器确定在定时器的定时时长内未接收到其他数据包时,生成超时中断;The serial port server determines that a timeout interrupt is generated when no other data packet is received within the timer duration of the timer;
根据超时中断,将缓存中的数据包发送给第一远端网络设备。According to the timeout interrupt, the data packet in the cache is sent to the first remote network device.
串口服务器当检测到定时器的定时时长到来,但在该定时时长内未接收到该串口终端发送的其他数据包时,串口服务器生成中断,以告知驱动器帧结束需进行数据包的重组。具体的,在串口服务器的操作系统中,串口硬件(hardware)收到数据包后,将该数据包缓存在硬件的缓存中,串口驱动(serial driver)从硬件的缓存中读取该数据包,将该数据包转存到内存中,当生成中断后,上层的应用程序(application)从内存中读取数据包并重组,并通过网口将重组后的数据包发送出去。When the serial server detects the timing of the timer, but does not receive other data packets sent by the serial terminal within the time limit, the serial server generates an interrupt to inform the end of the frame that the packet needs to be reorganized. Specifically, in the operating system of the serial server, after the serial port hardware (hardware) receives the data packet, the data packet is cached in the hardware cache, and the serial driver reads the data packet from the hardware cache. The data packet is transferred to the memory. When the interrupt is generated, the upper application reads the data packet from the memory and reassembles it, and sends the reassembled data packet through the network port.
由于串口服务器提供一个超时中断机制,当产生超时中断时,串口驱动从串口硬件buffer中读取数据包,并将该数据包打上标识字段,标识该数据包为待重组数据,并将该数据包转存到内存,上层的应用程序在收到中断后,从内存中根据该标识字段读取该数据包,并将该数据包重组后发送。Since the serial port server provides a timeout interrupt mechanism, when a timeout interrupt occurs, the serial port driver reads the data packet from the serial port hardware buffer, and puts the data packet into an identification field, identifies the data packet as data to be reassembled, and the data packet is After the memory is transferred to the memory, the upper layer application reads the data packet from the memory according to the identification field after receiving the interrupt, and reassembles the data packet and sends it.
具体的,串口驱动从硬件buffer中读取该数据包,并在该数据包的数据头部分添加一个标识字段,之后将该数据包转存到内存中。添加标识字段后的该数据包的数据头包括两部分,一部分为标识字段,该标识字段例如可以为一个字节,例如可以为“#”,另一部分为数据长度,该数据长度可以占用两个字节,以标识该数据包在数据头之后的数据的实际长度。当应用程序从内存中读取该数据包时,首先读取数据头部分,根据数据头包含的信息可以解析出后面数据的长度,从而可以获取相应的数据内容,从而实现数据的重组。Specifically, the serial port driver reads the data packet from the hardware buffer, and adds an identification field to the data header portion of the data packet, and then transfers the data packet to the memory. The data header of the data packet after the identifier field is added includes two parts, and the part is an identifier field. The identifier field may be, for example, one byte, for example, may be “#”, and the other part is a data length, and the data length may occupy two. Byte to identify the actual length of the data after the packet is in the data header. When the application reads the data packet from the memory, the data header portion is first read, and the length of the subsequent data can be parsed according to the information contained in the data header, so that the corresponding data content can be obtained, thereby realizing data reorganization.
串口服务器封装的数据包的格式可以如下表所示: The format of the data packet encapsulated by the serial server can be as shown in the following table:
FlagFlag LengthLength DataData
该数据包的数据头中含有标识符flag,该标识符标识其为数据包的起始位,该标识符可以采用任何值,该标识符占用一个字节,length部分占用两个字节,表明从第四个字节开始的实际数据内容的长度,data为重组后的数据内容。The data header of the data packet contains an identifier flag, which identifies it as the start bit of the data packet, and the identifier can take any value, the identifier occupies one byte, and the length portion occupies two bytes, indicating The length of the actual data content starting from the fourth byte, data is the reorganized data content.
为了便于远端网络设备识别每个数据包,确定该数据包是否为重组数据包,在本发明实施例中所述将缓存的数据包发送给第一远端网络设备后,所述方法还包括:In order to facilitate the remote network device to identify each data packet, and determine whether the data packet is a reassembled data packet, after the data packet is sent to the first remote network device, in the embodiment of the disclosure, the method further includes :
串口服务器生成标识报文,标识缓存中的数据包是否进行了重组,并将标识报文发送给第一远端网络设备。The serial port server generates an identifier packet, identifies whether the data packet in the cache is reassembled, and sends the identifier packet to the first remote network device.
具体的,该标识报文的格式如下:Specifically, the format of the identifier packet is as follows:
FlagFlag DataData TimeTime
Flag为该标识报文的报文头中包含的标识符,以标识其为该标识报文的起始位,data为该标识报文的实际数据内容,该数据内容只能为0或者1,0标识数据包已经被重组,1标识数据包未被重组,time为串口服务器当前封装该标识报文的时间,主要用于区分串口服务器的普通数据包与该标识报文。The flag is an identifier included in the header of the identifier packet to identify the start bit of the identifier packet, and data is the actual data content of the identifier packet. The data content can only be 0 or 1. 0 indicates that the data packet has been reorganized, 1 indicates that the data packet is not reassembled, and time is the time at which the serial port server currently encapsulates the identification packet, and is mainly used to distinguish the ordinary data packet of the serial port server from the identification packet.
为了有效的保证数据传输的准确性,在本发明实施例中确定所述定时器的定时时长包括:In order to effectively ensure the accuracy of the data transmission, determining the timing duration of the timer in the embodiment of the present invention includes:
串口服务器根据接收到的所述串口终端发送的每个数据包,确定相邻的两个包间隙时长;The serial port server determines, according to each received data packet sent by the serial terminal terminal, a duration of two adjacent packet gaps;
判断所述相邻的两个包间隙时长是否相等;Determining whether the lengths of the adjacent two packet gaps are equal;
当相邻的两个包间隙时长相等时,将所述定时器的定时时长确定为大于所述包间隙时长;When the lengths of the adjacent two packet gaps are equal, the timing duration of the timer is determined to be greater than the packet gap duration;
当两个包间隙时长不相等,且第一个包间隙时长大于第二个包间隙时长时,确定所述定时器的定时时长大于第二个包间隙时长小于第一个包间隙时长。When the duration of the two packet gaps is not equal, and the length of the first packet gap is greater than the duration of the second packet gap, it is determined that the timing duration of the timer is greater than the duration of the second packet gap is less than the duration of the first packet gap.
串口服务器可以根据每个串口终端的特性,灵活的针对每个串口终端设置其对应的包间隙时长,具体的,串口服务器在针对每个串口终端设置其对应的包间隙时长时,根据该串口终端发送的每个数据包,确定该串口终端两个相邻的包间隙长度。例如串口终端发送的数据包按照顺序为A、B、C……,则数据包A和数据包B之间的时间间隔为第一个包间隙长度,数据包B和数据包C之间的时间间隔为第二个包间隙长度,两个相邻的包间隙长度即为第一个包间隙长度与第二个包间隙长度。 The serial port server can flexibly set the corresponding packet gap duration for each serial port terminal according to the characteristics of each serial port terminal. Specifically, when the serial port server sets its corresponding packet gap duration for each serial port terminal, according to the serial port terminal Each data packet sent determines the length of two adjacent packet gaps of the serial terminal. For example, if the data packet sent by the serial terminal is A, B, C, ..., the time interval between the data packet A and the data packet B is the first packet gap length, and the time between the data packet B and the data packet C. The interval is the second packet gap length, and the two adjacent packet gap lengths are the first packet gap length and the second packet gap length.
获取了两个相邻的包间隙长度后,判断该两个包间隙长度是否相等,当两个包间隙长度相等时,说明该两个包间隙长度为该串口终端发送的数据包对应的包间隙长度,将定时器的定时时长设置为大于该包间隙长度即可。这里认为两个包间隙长度相等,可以为两个包间隙长度的差值的绝对值位于一定的阈值范围内。当两个包间隙长度不同,且第一个包间隙长度大于第二个包间隙长度时,说明第一个包间隙为回复第一个请求结束后的包间隙,第二个包间隙为回复第二个请求的包间隙,此时可以将定时器的定时时长设置为大于第二个包间隙时长,但小于第一个包间隙时长。同样的,当两个包间隙长度不同,且第一个包间隙长度小于第二个包间隙长度时,说明第一个包间隙为回复第一个请求的包间隙,第二个包间隙为回复第一个请求结束后的包间隙,之后将会回复另一个请求,此时可以将定时器的定时时长设置为大于第一个包间隙时长,但小于第二个包间隙时长。After the two adjacent packet gap lengths are obtained, it is determined whether the two packet gap lengths are equal. When the two packet gap lengths are equal, the two packet gap lengths are the packet gaps corresponding to the data packets sent by the serial terminal terminal. The length, the timer duration of the timer is set to be greater than the packet gap length. Here, it is considered that the two packet gap lengths are equal, and the absolute value of the difference between the two packet gap lengths may be within a certain threshold range. When the gap lengths of the two packets are different, and the length of the first packet gap is greater than the length of the second packet gap, it indicates that the first packet gap is the packet gap after the end of the first request, and the second packet gap is the reply. The two requested packet gaps can be set to be longer than the second packet gap duration, but less than the first packet gap duration. Similarly, when the gap lengths of the two packets are different, and the first packet gap length is smaller than the second packet gap length, the first packet gap is the reply to the first requested packet gap, and the second packet gap is the reply. After the first request ends, the packet gap will be followed by another request. At this time, the timer duration can be set to be longer than the first packet gap duration, but less than the second packet gap duration.
在本发明实施例中当远端网络设备具有判断数据完整性的功能时,确定所述定时器的定时时长包括:In the embodiment of the present invention, when the remote network device has the function of determining data integrity, determining the timing duration of the timer includes:
所述串口服务器接收第一远端网络设备返回的响应报文,当该响应报文标识重组后的数据包包含多余信息时,将定时器的定时时长调整为小于当前的定时时长,当该响应报文标识重组后的数据包包含的信息不完整时,将定时器的定时时长调整为大于当前的定时时长。The serial port server receives the response packet returned by the first remote network device, and when the response packet identifies that the reassembled data packet contains redundant information, adjusts the timer duration of the timer to be smaller than the current timing duration, when the response When the information contained in the packet after reassembly is incomplete, the timer duration of the timer is adjusted to be greater than the current timing duration.
具体的,远端网络设备具有判断数据完整性的功能时,在接收到串口服务器重组后的数据包后,可以根据数据包是否完整,向串口服务器返回响应报文。此时串口服务器中定时器的定时时长可以任意设置,根据设置的定时器的定时时长,确定向该远端网络设备返回数据包,重组并发送。该远端网络设备接收到重组后的数据包后,判断数据的完整性,将该完整性信息包含在响应信息中发送到串口服务器。Specifically, when the remote network device has the function of determining data integrity, after receiving the data packet reassembled by the serial server, the response packet may be returned to the serial server according to whether the data packet is complete. At this time, the timer duration of the timer in the serial server can be arbitrarily set. According to the set timing of the timer, it is determined that the data packet is returned to the remote network device, reassembled and sent. After receiving the reassembled data packet, the remote network device determines the integrity of the data, and the integrity information is included in the response information and sent to the serial server.
串口服务器根据该响应信息中包含的信息,确定重组后的数据包中包含多余信息,即重组后的数据包包含的数据较该远端网络设备需要的数据多时,确定当前定时器的定时时长较长,此时需要将定时器的定时时长调小;当根据该响应信息,确定重组后的数据包包含的信息不完整时,确定当前定时器的定时时长较短,不能获取完整的数据,此时需要将定时器的定时时长调大。The serial server determines, according to the information contained in the response information, that the reassembled data packet contains redundant information, that is, when the reassembled data packet contains more data than the remote network device requires, determining the current timer timing time is longer. If the information of the reassembled data packet is incomplete, it is determined that the current timer has a short duration and cannot obtain complete data. It is necessary to increase the timing of the timer.
采用上述方式,通过串口服务器与远端网络设备的几次交互,可以较准确的确定对应的串口终端对应的定时器的定时时长。In the above manner, the interaction between the serial server and the remote network device can determine the timing of the timer corresponding to the corresponding serial terminal.
本发明实施例中为了有效的保证数据传输的准确性,所述方法还包括:In order to effectively ensure the accuracy of data transmission in the embodiment of the present invention, the method further includes:
所述串口服务器接收所述串口终端发送的数据包,判断当前所述定时器是否超时;The serial server receives the data packet sent by the serial terminal, and determines whether the current timer expires;
当当前所述定时器超时时,将所述数据包发送给与其TCP连接的每个远端网络设备。When the current timer expires, the data packet is sent to each remote network device connected to its TCP.
图3为本发明实施例提供的一种基于串口服务器的数据传输的具体过程,该过程包括以下步骤: FIG. 3 is a specific process of data transmission based on a serial port server according to an embodiment of the present invention, where the process includes the following steps:
S301:串口服务器接收第一远端网络设备发送的请求,将所述请求发送到第一串口终端。S301: The serial server receives the request sent by the first remote network device, and sends the request to the first serial terminal.
S302:串口服务器接收第一串口终端返回的数据包,缓存所述数据包并启动定时器。S302: The serial server receives the data packet returned by the first serial terminal, caches the data packet, and starts a timer.
S303:判断在定时器的定时时长内,是否接收到该第一串口终端返回的其他数据包,当判断结果为是时,进行步骤S304,否则,进行步骤S305。S303: Determine whether other data packets returned by the first serial port terminal are received within the time limit of the timer. If the determination result is yes, proceed to step S304; otherwise, proceed to step S305.
S304:缓存所述其他数据包并重新启动定时器,之后进行步骤S303。S304: Cache the other data packet and restart the timer, and then proceed to step S303.
S305:将缓存的数据包发送给第一远端网络设备。S305: Send the buffered data packet to the first remote network device.
S306:串口服务器接收该第一串口终端发送的其他数据包。S306: The serial server receives other data packets sent by the first serial terminal.
S307:串口服务器判断当前定时器是否超时,当判断结果为是时,进行步骤S308,否则,进行步骤S304。S307: The serial server determines whether the current timer has timed out. If the determination result is yes, proceed to step S308; otherwise, proceed to step S304.
S308:将所述数据包发送给与其TCP连接的每个远端网络设备。S308: Send the data packet to each remote network device connected to its TCP.
具体的,串口服务器与第一远端网络设备建立一条TCP连接,通过该TCP连接接收该第一远端网络设备发送的请求,其中该请求中携带与其通信的串口终端的标识信息,该标识信息可以是串口终端的连接地址信息。串口服务器接收到该请求后,将该请求发送到对应的串口终端。串口终端根据该请求向串口服务器返回数据包,当串口服务器接收到该数据包后,缓存该数据包并启动定时器。判断是否在该定时器的定时时长内接收到该串口终端发送的其他数据包,当在该定时时长内接收到该串口终端发送的其他数据包时,缓存该其他数据包并重新启动定时器,在定时器的定时时长内继续监控是否接收到该串口终端发送的其他数据包,当在定时器的某一定时时长内未接收到该串口终端返回的数据包时,即定时器超时时未接收到该串口终端返回的数据包时,确定该串口终端的回复过程结束,将缓存中的数据包进行重组,重组为一个IP数据包,并将重组后的数据包发送给对应的远端网络设备。Specifically, the serial server establishes a TCP connection with the first remote network device, and receives the request sent by the first remote network device by using the TCP connection, where the request carries the identifier information of the serial terminal that communicates with the request, and the identifier information It can be the connection address information of the serial terminal. After receiving the request, the serial server sends the request to the corresponding serial terminal. The serial terminal returns a data packet to the serial server according to the request. When the serial server receives the data packet, the data packet is buffered and a timer is started. Determining whether other data packets sent by the serial terminal are received within the time limit of the timer. When receiving other data packets sent by the serial terminal within the time limit, the other data packets are buffered and the timer is restarted. During the timer duration of the timer, it continues to monitor whether other data packets sent by the serial terminal are received. When the data packet returned by the serial terminal is not received within a certain timing of the timer, the timer is not received when the timer expires. When the data packet returned by the serial terminal is determined, it is determined that the reply process of the serial terminal ends, the data packet in the cache is reorganized, reassembled into an IP data packet, and the reassembled data packet is sent to the corresponding remote network device. .
在本发明实施例中串口服务器在一个回复周期内,会将串口终端未超时返回的每个数据包积攒起来,当超时时将积攒的数据包重组为一个IP数据包并发送,从而避免了远端网络设备进行数据包的重组,降低了对远端网络设备的配置要求及资源消耗,提高了远端网络设备的工作效率。In the embodiment of the present invention, the serial server accumulates each data packet returned by the serial terminal without timeout in a reply period, and reassembles the accumulated data packet into an IP data packet and sends it when timeout, thereby avoiding the far distance. The network device reassembles the data packet, which reduces the configuration requirements and resource consumption of the remote network device, and improves the working efficiency of the remote network device.
另外,当定时器已经超时,即当前定时器为未启动状态时,串口服务器接收到该串口终端发送的其他数据包,串口服务器将该数据包发送给与其TCP连接的每个远端网络设备。In addition, when the timer has expired, that is, the current timer is not activated, the serial server receives other data packets sent by the serial terminal, and the serial server sends the data packet to each remote network device connected to the TCP.
由于在本发明实施例中串口服务器接收到串口终端的数据包后,启动定时器,当在定时器时长范围内再次收到数据包时,认为该数据包为该串口终端发送的,将该数据包缓存,否则认为该串口终端的数据发送过程结束,从而将缓存的数据包发送给远端网络设备,实现对缓存中数据包的重组,降低了对远端网络设备的配置要求及资源消耗,提高了远端网络设备的工作效率。 In the embodiment of the present invention, after receiving the data packet of the serial port terminal, the serial server starts a timer. When the data packet is received again within the timer duration, the data packet is considered to be sent by the serial terminal, and the data is sent. Packet buffering, otherwise it is considered that the data transmission process of the serial terminal ends, thereby transmitting the buffered data packet to the remote network device, realizing the reorganization of the data packet in the cache, and reducing the configuration requirements and resource consumption of the remote network device. Improve the efficiency of remote network devices.
图4为本发明实施例提供了一种基于串口服务器的数据传输装置结构示意图,所述装置包括:FIG. 4 is a schematic structural diagram of a data transmission apparatus based on a serial port server according to an embodiment of the present invention, where the apparatus includes:
接收缓存模块41,用于接收串口终端发送的数据包,缓存所述数据包并启动定时器;The receiving buffer module 41 is configured to receive a data packet sent by the serial terminal, cache the data packet, and start a timer.
判断模块42,用于判断在定时器的定时时长内,是否接收到该串口终端发送的其他数据包;The determining module 42 is configured to determine whether other data packets sent by the serial terminal are received within the time duration of the timer;
缓存发送模块43,用于当判断模块判断接收到其他数据包时,缓存所述其他数据包并重新启动定时器,否则,将缓存的数据包发送给第一远端网络设备。The buffer sending module 43 is configured to: when the determining module determines that another data packet is received, buffer the other data packet and restart the timer; otherwise, send the buffered data packet to the first remote network device.
为了有效的提高数据传输的精度,在本发明实施例中所述缓存发送模块43,具体用于确定在定时器的定时时长内未接收到其他数据包时,生成超时中断;根据超时中断,将缓存中的数据包发送给第一远端网络设备。In order to effectively improve the accuracy of the data transmission, in the embodiment of the present invention, the cache sending module 43 is specifically configured to determine that a timeout interrupt is generated when no other data packet is received within the timer duration of the timer; The data packet in the cache is sent to the first remote network device.
为了有效的提高数据传输的准确性,降低远端网络设备的配置要求,所述缓存发送模块43,还用于生成标识报文,标识缓存中的数据包是否进行了重组,并将标识报文发送给第一远端网络设备。In order to effectively improve the accuracy of data transmission and reduce the configuration requirements of the remote network device, the cache sending module 43 is further configured to generate an identifier packet, identify whether the data packet in the buffer is reorganized, and identify the packet. Send to the first remote network device.
为了有效的保证数据传输的准确性,在本发明实施例中所述装置还包括:In order to effectively ensure the accuracy of the data transmission, the device in the embodiment of the present invention further includes:
确定模块44,用于根据接收到的所述串口终端发送的每个数据包,确定相邻的两个包间隙时长;判断所述相邻的两个包间隙时长是否相等;当相邻的两个包间隙时长相等时,将所述定时器的定时时长确定为大于所述包间隙时长;当两个包间隙时长不相等,且第一个包间隙时长大于第二个包间隙时长时,确定所述定时器的定时时长大于第二个包间隙时长小于第一个包间隙时长;当两个包间隙时长不相等,且第一个包间隙时长小于第二个包间隙时长时,确定所述定时器的定时时长大于第一个包间隙时长小于第二个包间隙时长。The determining module 44 is configured to determine, according to the received data packet sent by the serial terminal terminal, a duration of two adjacent packet gaps; determine whether the adjacent two packet gap durations are equal; When the packet gap durations are equal, the timing duration of the timer is determined to be greater than the packet gap duration; when the two packet gap durations are not equal, and the first packet gap duration is greater than the second packet gap duration, The timing duration of the timer is greater than the duration of the second packet gap is less than the length of the first packet gap; when the duration of the two packet gaps is not equal, and the length of the first packet gap is less than the duration of the second packet gap, the determining The timer duration of the timer is greater than the duration of the first packet gap is less than the duration of the second packet gap.
所述装置还包括:The device also includes:
确定模块44,用于接收第一远端网络设备返回的响应报文,当该响应报文标识重组后的数据包包含多余信息时,将定时器的定时时长调整为小于当前的定时时长,当该响应报文标识重组后的数据包包含的信息不完整时,将定时器的定时时长调整为大于当前的定时时长。The determining module 44 is configured to receive a response packet returned by the first remote network device, and when the response packet identifies that the reassembled data packet includes redundant information, adjust a timer duration of the timer to be less than a current timing duration. When the response packet identifies that the information contained in the reassembled data packet is incomplete, the timer duration of the timer is adjusted to be greater than the current timing duration.
为了有效的保证数据传输的准确性,所述判断模块42,还用于当接收到所述串口终端发送的数据包,判断当前所述定时器是否超时;In order to ensure the accuracy of the data transmission, the determining module 42 is further configured to: when receiving the data packet sent by the serial terminal, determine whether the current timer expires;
所述缓存发送模块43,还用于当判断模块判断当前所述定时器超时时,将所述数据包发送给与其TCP连接的每个远端网络设备。The cache sending module 43 is further configured to: when the determining module determines that the current timer expires, send the data packet to each remote network device connected to the TCP.
为了有效的保证数据传输的准确性,所述缓存接收模块41,还用于接收第二远端网络设备发送的请求;The cache receiving module 41 is further configured to receive a request sent by the second remote network device, in order to ensure the accuracy of the data transmission.
所述判断模块42,还用于判断是否当前位于与所述第一远端网络设备对应的定时器的定时时长内; The determining module 42 is further configured to determine whether it is currently located in a timing duration of a timer corresponding to the first remote network device;
所述缓存发送模块43,还用于当所述判断模块判断当前位于与所述第一远端网络设备对应的定时器的定时时长内时,缓存所述请求。The cache sending module 43 is further configured to cache the request when the determining module determines that the timing of the timer currently located in the first remote network device is within a predetermined duration.
本发明实施例提供了一种基于串口服务器的数据传输方法及装置,该方法中当串口服务器接收到串口终端发送的数据包后,启动定时器,判断在该定时器的定时时长内,是否接收到该串口终端发送的其他数据包,当接收到其他数据包时,缓存该数据包并重启定时器,否则,将缓存的每个数据包重组后发送给第一远端网络设备。由于在本发明实施例中串口服务器接收到串口终端的数据包后,启动定时器,当在定时器时长范围内再次收到数据包时,认为该数据包为该串口终端发送的,将该数据包缓存,否则认为该串口终端的数据发送过程结束,从而将缓存的数据包发送给远端网络设备,实现对缓存中数据包的重组,降低了对远端网络设备的配置要求及资源消耗,提高了远端网络设备的工作效率。The embodiment of the invention provides a data transmission method and device based on a serial port server. After the serial port server receives the data packet sent by the serial port terminal, the serial server starts a timer to determine whether to receive the timer within the time limit of the timer. When other data packets sent by the serial terminal are received, the data packet is buffered and the timer is restarted. Otherwise, each buffered data packet is reassembled and sent to the first remote network device. In the embodiment of the present invention, after receiving the data packet of the serial port terminal, the serial server starts a timer. When the data packet is received again within the timer duration, the data packet is considered to be sent by the serial terminal, and the data is sent. Packet buffering, otherwise it is considered that the data transmission process of the serial terminal ends, thereby transmitting the buffered data packet to the remote network device, realizing the reorganization of the data packet in the cache, and reducing the configuration requirements and resource consumption of the remote network device. Improve the efficiency of remote network devices.
在此提供的算法和显示不与任何特定计算机、虚拟系统或者其它设备固有相关。各种通用系统也可以与基于在此的示教一起使用。根据上面的描述,构造这类系统所要求的结构是显而易见的。此外,本发明也不针对任何特定编程语言。应当明白,可以利用各种编程语言实现在此描述的本发明的内容,并且上面对特定语言所做的描述是为了披露本发明的最佳实施方式。The algorithms and displays provided herein are not inherently related to any particular computer, virtual system, or other device. Various general purpose systems can also be used with the teaching based on the teachings herein. The structure required to construct such a system is apparent from the above description. Moreover, the invention is not directed to any particular programming language. It is to be understood that the invention may be embodied in a variety of programming language, and the description of the specific language has been described above in order to disclose the preferred embodiments of the invention.
在此处所提供的说明书中,说明了大量具体细节。然而,能够理解,本发明的实施例可以在没有这些具体细节的情况下实践。在一些实例中,并未详细示出公知的方法、结构和技术,以便不模糊对本说明书的理解。In the description provided herein, numerous specific details are set forth. However, it is understood that the embodiments of the invention may be practiced without these specific details. In some instances, well-known methods, structures, and techniques are not shown in detail so as not to obscure the understanding of the description.
类似地,应当理解,为了精简本公开并帮助理解各个发明方面中的一个或多个,在上面对本发明的示例性实施例的描述中,本发明的各个特征有时被一起分组到单个实施例、图、或者对其的描述中。然而,并不应将该公开的方法解释成反映如下意图:即所要求保护的本发明要求比在每个权利要求中所明确记载的特征更多的特征。更确切地说,如下面的权利要求书所反映的那样,发明方面在于少于前面公开的单个实施例的所有特征。因此,遵循具体实施方式的权利要求书由此明确地并入该具体实施方式,其中每个权利要求本身都作为本发明的单独实施例。Similarly, the various features of the invention are sometimes grouped together into a single embodiment, in the above description of the exemplary embodiments of the invention, Figure, or a description of it. However, the method disclosed is not to be interpreted as reflecting the intention that the claimed invention requires more features than those recited in the claims. Rather, as the following claims reflect, inventive aspects reside in less than all features of the single embodiments disclosed herein. Therefore, the claims following the specific embodiments are hereby explicitly incorporated into the embodiments, and each of the claims as a separate embodiment of the invention.
本领域那些技术人员可以理解,可以对实施例中的设备中的模块进行自适应性地改变并且把它们设置在与该实施例不同的一个或多个设备中。可以把实施例中的模块或单元或组件组合成一个模块或单元或组件,以及此外可以把它们分成多个子模块或子单元或子组件。除了这样的特征和/或过程或者单元中的至少一些是相互排斥之外,可以采用任何组合对本说明书(包括伴随的权利要求、摘要和附图)中公开的所有特征以及如此公开的任何方法或者设备的所有过程或单元进行组合。除非另外明确陈述,本说明书(包括伴随的权利要求、摘要和附图)中公开的每个特征可以由提供相同、等同或相似目的的替代特征来代替。 Those skilled in the art will appreciate that the modules in the devices of the embodiments can be adaptively changed and placed in one or more devices different from the embodiment. The modules or units or components of the embodiments may be combined into one module or unit or component, and further they may be divided into a plurality of sub-modules or sub-units or sub-components. In addition to such features and/or at least some of the processes or units being mutually exclusive, any combination of the features disclosed in the specification, including the accompanying claims, the abstract and the drawings, and any methods so disclosed, or All processes or units of the device are combined. Each feature disclosed in this specification (including the accompanying claims, the abstract and the drawings) may be replaced by alternative features that provide the same, equivalent or similar purpose.
此外,本领域的技术人员能够理解,尽管在此所述的一些实施例包括其它实施例中所包括的某些特征而不是其它特征,但是不同实施例的特征的组合意味着处于本发明的范围之内并且形成不同的实施例。例如,在下面的权利要求书中,所要求保护的实施例的任意之一都可以以任意的组合方式来使用。In addition, those skilled in the art will appreciate that, although some embodiments described herein include certain features that are included in other embodiments and not in other features, combinations of features of different embodiments are intended to be within the scope of the present invention. Different embodiments are formed and formed. For example, in the following claims, any one of the claimed embodiments can be used in any combination.
本发明的各个部件实施例可以以硬件实现,或者以在一个或者多个处理器上运行的软件模块实现,或者以它们的组合实现。本领域的技术人员应当理解,可以在实践中使用微处理器或者数字信号处理器(DSP)来实现根据本发明实施例的基于串口服务器的数据传输装置中的一些或者全部部件的一些或者全部功能。本发明还可以实现为用于执行这里所描述的方法的一部分或者全部的设备或者装置程序(例如,计算机程序和计算机程序产品)。这样的实现本发明的程序可以存储在计算机可读介质上,或者可以具有一个或者多个信号的形式。这样的信号可以从因特网网站上下载得到,或者在载体信号上提供,或者以任何其他形式提供。The various component embodiments of the present invention may be implemented in hardware, or in a software module running on one or more processors, or in a combination thereof. Those skilled in the art will appreciate that a microprocessor or digital signal processor (DSP) may be used in practice to implement some or all of the functionality of some or all of the components of a serial server based data transmission device in accordance with embodiments of the present invention. . The invention can also be implemented as a device or device program (e.g., a computer program and a computer program product) for performing some or all of the methods described herein. Such a program implementing the invention may be stored on a computer readable medium or may be in the form of one or more signals. Such signals may be downloaded from an Internet website, provided on a carrier signal, or provided in any other form.
应该注意的是上述实施例对本发明进行说明而不是对本发明进行限制,并且本领域技术人员在不脱离所附权利要求的范围的情况下可设计出替换实施例。在权利要求中,不应将位于括号之间的任何参考符号构造成对权利要求的限制。单词“包含”不排除存在未列在权利要求中的元件或步骤。位于元件之前的单词“一”或“一个”不排除存在多个这样的元件。本发明可以借助于包括有若干不同元件的硬件以及借助于适当编程的计算机来实现。在列举了若干装置的单元权利要求中,这些装置中的若干个可以是通过同一个硬件项来具体体现。单词第一、第二、以及第三等的使用不表示任何顺序。可将这些单词解释为名称。It is to be noted that the above-described embodiments are illustrative of the invention and are not intended to be limiting, and that the invention may be devised without departing from the scope of the appended claims. In the claims, any reference signs placed between parentheses shall not be construed as a limitation. The word "comprising" does not exclude the presence of the elements or steps that are not recited in the claims. The word "a" or "an" The invention can be implemented by means of hardware comprising several distinct elements and by means of a suitably programmed computer. In the unit claims enumerating several means, several of these means can be embodied by the same hardware item. The use of the words first, second, and third does not indicate any order. These words can be interpreted as names.
显然,本领域的技术人员可以对本发明进行各种改动和变型而不脱离本发明的精神和范围。这样,倘若本发明的这些修改和变型属于本发明权利要求及其等同技术的范围之内,则本发明也意图包含这些改动和变型在内。 It is apparent that those skilled in the art can make various modifications and variations to the invention without departing from the spirit and scope of the invention. Thus, it is intended that the present invention cover the modifications and modifications of the invention

Claims (14)

  1. 一种基于串口服务器的数据传输方法,其特征在于,该方法包括:A serial port server based data transmission method, characterized in that the method comprises:
    串口服务器接收串口终端发送的数据包,缓存所述数据包并启动定时器;The serial server receives the data packet sent by the serial terminal, caches the data packet, and starts a timer;
    判断在定时器的定时时长内,是否接收到该串口终端发送的其他数据包;Determining whether other data packets sent by the serial terminal are received within the timer duration of the timer;
    当接收到其他数据包时,缓存所述其他数据包并重新启动定时器,否则,将缓存的每个数据包重组后发送给第一远端网络设备。When other data packets are received, the other data packets are buffered and the timer is restarted. Otherwise, each buffered data packet is reassembled and sent to the first remote network device.
  2. 如权利要求1所述的方法,其特征在于,所述将缓存的每个数据包重组后发送给第一远端网络设备包括:The method of claim 1, wherein the reassembling each of the cached data packets and transmitting the data to the first remote network device comprises:
    所述串口服务器确定在定时器的定时时长内未接收到其他数据包时,生成超时中断;The serial port server determines that a timeout interrupt is generated when no other data packet is received within the timer duration of the timer;
    根据超时中断,将缓存的每个数据包重组后发送给第一远端网络设备。According to the timeout interrupt, each buffered packet is reassembled and sent to the first remote network device.
  3. 如权利要求1或2所述的方法,其特征在于,所述将缓存的每个数据包重组后发送给第一远端网络设备后,所述方法还包括:The method according to claim 1 or 2, wherein after the reassembling each of the cached data packets and transmitting the data to the first remote network device, the method further includes:
    串口服务器生成标识报文,标识缓存中的数据包是否进行了重组,并将标识报文发送给第一远端网络设备。The serial port server generates an identifier packet, identifies whether the data packet in the cache is reassembled, and sends the identifier packet to the first remote network device.
  4. 如权利要求1所述的方法,其特征在于,确定所述定时器的定时时长包括:The method of claim 1 wherein determining the timing duration of the timer comprises:
    串口服务器根据接收到的所述串口终端发送的每个数据包,确定相邻的两个包间隙时长;The serial port server determines, according to each received data packet sent by the serial terminal terminal, a duration of two adjacent packet gaps;
    判断所述相邻的两个包间隙时长是否相等;Determining whether the lengths of the adjacent two packet gaps are equal;
    当相邻的两个包间隙时长相等时,将所述定时器的定时时长确定为大于所述包间隙时长;When the lengths of the adjacent two packet gaps are equal, the timing duration of the timer is determined to be greater than the packet gap duration;
    当两个包间隙时长不相等,且第一个包间隙时长大于第二个包间隙时长时,确定所述定时器的定时时长大于第二个包间隙时长小于第一个包间隙时长;When the duration of the two packet gaps is not equal, and the length of the first packet gap is greater than the length of the second packet gap, it is determined that the timing duration of the timer is greater than the duration of the second packet gap is less than the duration of the first packet gap;
    当两个包间隙时长不相等,且第一个包间隙时长小于第二个包间隙时长时,确定所述定时器的定时时长大于第一个包间隙时长小于第二个包间隙时长。When the duration of the two packet gaps is not equal, and the length of the first packet gap is less than the duration of the second packet gap, it is determined that the timing duration of the timer is greater than the duration of the first packet gap is less than the duration of the second packet gap.
  5. 如权利要求1所述的方法,其特征在于,确定所述定时器的定时时长包括:The method of claim 1 wherein determining the timing duration of the timer comprises:
    所述串口服务器接收第一远端网络设备返回的响应报文,当该响应报文标识重组后的数据包中包含多余信息时,将定时器的定时时长调整为小于当前的定时时长,当该响应报文标识重组后的数据包包含的信息不完整时,将定时器的定时时长调整为大于当前的定时时长。The serial port server receives the response packet returned by the first remote network device, and when the response packet identifies that the reassembled data packet contains redundant information, the timer duration of the timer is adjusted to be less than the current timing duration. When the response packet identifies that the reassembled data packet contains incomplete information, the timer duration is adjusted to be greater than the current timing duration.
  6. 如权利要求1所述的方法,其特征在于,所述方法还包括:The method of claim 1 wherein the method further comprises:
    所述串口服务器接收所述串口终端发送的数据包,判断当前定时器是否超时;The serial port server receives the data packet sent by the serial port terminal, and determines whether the current timer expires;
    当当前所述定时器超时时,将所述数据包发送给与其TCP连接的每个远端网络设备。 When the current timer expires, the data packet is sent to each remote network device connected to its TCP.
  7. 如权利要求1所述的方法,其特征在于,所述方法还包括:The method of claim 1 wherein the method further comprises:
    所述串口服务器接收第二远端网络设备发送的请求,判断当前位于与所述第一远端网络设备对应的定时器的定时时长内时,缓存所述请求。The serial server buffers the request when receiving a request sent by the second remote network device and determining that the current time is within the time duration of the timer corresponding to the first remote network device.
  8. 一种基于串口服务器的数据传输装置,其特征在于,所述装置包括:A serial port server-based data transmission device, characterized in that the device comprises:
    接收缓存模块,用于接收串口终端发送的数据包,缓存所述数据包并启动定时器;a receiving buffer module, configured to receive a data packet sent by the serial terminal, cache the data packet, and start a timer;
    判断模块,用于判断在定时器的定时时长内,是否接收到该串口终端发送的其他数据包;a determining module, configured to determine whether other data packets sent by the serial terminal are received within a timer duration of the timer;
    缓存发送模块,用于当判断模块判断接收到其他数据包时,缓存所述其他数据包并重新启动定时器,否则,将缓存的每个数据包重组后发送给第一远端网络设备。The cache sending module is configured to: when the determining module determines that other data packets are received, buffer the other data packets and restart the timer; otherwise, the buffered data packets are reassembled and sent to the first remote network device.
  9. 如权利要求8所述的装置,其特征在于,所述缓存发送模块,具体用于确定在定时器的定时时长内未接收到其他数据包时,生成超时中断;根据超时中断,将缓存的每个数据包重组后发送给第一远端网络设备。The device according to claim 8, wherein the buffer sending module is configured to: determine that a timeout interrupt is generated when no other data packet is received within a timer duration; and each cache is buffered according to a timeout interrupt The data packets are reassembled and sent to the first remote network device.
  10. 如权利要求8或9所述的装置,其特征在于,所述缓存发送模块,还用于生成标识报文,标识缓存中的数据包是否进行了重组,并将标识报文发送给第一远端网络设备。The device according to claim 8 or 9, wherein the buffer sending module is further configured to generate an identifier packet, identify whether the data packet in the buffer is reorganized, and send the identifier packet to the first far End network equipment.
  11. 如权利要求8所述的装置,其特征在于,所述装置还包括:The device of claim 8 further comprising:
    确定模块,用于根据接收到的所述串口终端发送的每个数据包,确定相邻的两个包间隙时长;判断所述相邻的两个包间隙时长是否相等;当相邻的两个包间隙时长相等时,将所述定时器的定时时长确定为大于所述包间隙时长;当两个包间隙时长不相等,且第一个包间隙时长大于第二个包间隙时长时,确定所述定时器的定时时长大于第二个包间隙时长小于第一个包间隙时长;当两个包间隙时长不相等,且第一个包间隙时长小于第二个包间隙时长时,确定所述定时器的定时时长大于第一个包间隙时长小于第二个包间隙时长。a determining module, configured to determine, according to the received each data packet sent by the serial terminal terminal, a duration of two adjacent packet gaps; determine whether the adjacent two packet gap durations are equal; When the packet gap duration is equal, the timing duration of the timer is determined to be greater than the packet gap duration; when the two packet gap durations are not equal, and the first packet gap duration is greater than the second packet gap duration, the determination is performed. The timing duration of the timer is greater than the duration of the second packet gap is less than the duration of the first packet gap; when the duration of the two packet gaps is not equal, and the length of the first packet gap is less than the duration of the second packet gap, the timing is determined. The timing duration of the device is greater than the duration of the first packet gap is less than the duration of the second packet gap.
  12. 如权利要求8所述的装置,其特征在于,所述装置还包括:The device of claim 8 further comprising:
    确定模块,用于接收第一远端网络设备返回的响应报文,当该响应报文标识重组后的数据包中包含多余信息时,将定时器的定时时长调整为小于当前的定时时长,当该响应报文标识重组后的数据包包含的信息不完整时,将定时器的定时时长调整为大于当前的定时时长。a determining module, configured to receive a response packet returned by the first remote network device, and when the response packet identifies that the reassembled data packet includes redundant information, adjust a timer duration of the timer to be less than a current timing duration. When the response packet identifies that the information contained in the reassembled data packet is incomplete, the timer duration of the timer is adjusted to be greater than the current timing duration.
  13. 如权利要求8所述的装置,其特征在于,所述判断模块,还用于当接收到所述串口终端发送的数据包,判断当前定时器是否超时;The device according to claim 8, wherein the determining module is further configured to: when receiving the data packet sent by the serial terminal, determine whether the current timer expires;
    所述缓存发送模块,还用于当判断模块判断当前所述定时器超时时,将所述数据包发送给与其TCP连接的每个远端网络设备。The cache sending module is further configured to: when the determining module determines that the current timer expires, send the data packet to each remote network device connected to the TCP.
  14. 如权利要求8所述的装置,其特征在于,所述缓存接收模块,还用于接收第二远端网络设备发送的请求;The device according to claim 8, wherein the buffer receiving module is further configured to receive a request sent by the second remote network device;
    所述判断模块,还用于判断是否当前位于与所述第一远端网络设备对应的定时器的定 时时长内;The determining module is further configured to determine whether a timer that is currently located corresponding to the first remote network device is determined Within a period of time;
    所述缓存发送模块,还用于当所述判断模块判断当前位于与所述第一远端网络设备对应的定时器的定时时长内时,缓存所述请求。 The cache sending module is further configured to cache the request when the determining module determines that the current time is within a timer duration of a timer corresponding to the first remote network device.
PCT/CN2015/071529 2014-12-16 2015-01-26 Data transmission method and apparatus based on serial server WO2016095323A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201410784390.6A CN104486247A (en) 2014-12-16 2014-12-16 Data transmission method and device based on serial server
CN201410784390.6 2014-12-16

Publications (1)

Publication Number Publication Date
WO2016095323A1 true WO2016095323A1 (en) 2016-06-23

Family

ID=52760752

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2015/071529 WO2016095323A1 (en) 2014-12-16 2015-01-26 Data transmission method and apparatus based on serial server

Country Status (2)

Country Link
CN (1) CN104486247A (en)
WO (1) WO2016095323A1 (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110113707A (en) * 2018-01-30 2019-08-09 四川中电昆辰科技有限公司 Multifrequency point location data return system and positioning system and its method

Families Citing this family (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106850713B (en) * 2015-12-04 2020-01-21 北京东土科技股份有限公司 Data transmission method and device based on serial server and serial server
CN108304335A (en) * 2018-02-07 2018-07-20 南京南瑞继保电气有限公司 A method of the indefinite long message of serial ports is received by DMA
CN113741718A (en) * 2020-05-29 2021-12-03 杭州海康威视数字技术股份有限公司 Control data conversion method and device and master control equipment
CN114465966A (en) * 2022-01-23 2022-05-10 山东云海国创云计算装备产业创新中心有限公司 Data packet recombination control system and data packet recombination method

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6076181A (en) * 1998-03-03 2000-06-13 Nokia Mobile Phones Limited Method and apparatus for controlling a retransmission/abort timer in a telecommunications system
CN101030943A (en) * 2007-04-03 2007-09-05 华为技术有限公司 Method for transmitting message and route
CN101800652A (en) * 2010-02-04 2010-08-11 深圳市金宏威实业发展有限公司 Mode switching method and system of serial port and Ethernet and industrial Ethernet switch
CN102624738A (en) * 2012-03-28 2012-08-01 瑞斯康达科技发展股份有限公司 Serial port server, protocol conversion chip and data transmission method

Family Cites Families (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6690648B2 (en) * 1998-02-24 2004-02-10 Canon Kabushiki Kaisha Data communication apparatus, method, and system utilizing reception capability information of a destination node
US6973598B2 (en) * 2002-01-28 2005-12-06 Dell Products L.P. Computer system with improved data capture system
CN101699298B (en) * 2009-11-12 2011-08-10 安徽鑫龙电器股份有限公司 One-phase digital current/voltage measuring instrument and measuring method thereof
CN101841542B (en) * 2010-05-07 2012-11-07 北京鼎实创新科技有限公司 Method for realizing PROFIBUS master station communication protocol based on FPGA (Field Programmable Gate Array) technology
CN101908031B (en) * 2010-07-23 2012-11-14 四川九洲电器集团有限责任公司 FPGA-based enhanced serial port
CN102724122B (en) * 2012-06-21 2015-04-29 广东威创视讯科技股份有限公司 Reliable serial port transmission method and device based on hardware system
CN103078871A (en) * 2013-01-18 2013-05-01 武汉迈威实达软件有限公司 Serial port Ethernet protocol conversion method
CN104155905A (en) * 2014-08-22 2014-11-19 南京领先环保技术有限公司 Control system for remotely monitoring brushless motor, and control method thereof

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6076181A (en) * 1998-03-03 2000-06-13 Nokia Mobile Phones Limited Method and apparatus for controlling a retransmission/abort timer in a telecommunications system
CN101030943A (en) * 2007-04-03 2007-09-05 华为技术有限公司 Method for transmitting message and route
CN101800652A (en) * 2010-02-04 2010-08-11 深圳市金宏威实业发展有限公司 Mode switching method and system of serial port and Ethernet and industrial Ethernet switch
CN102624738A (en) * 2012-03-28 2012-08-01 瑞斯康达科技发展股份有限公司 Serial port server, protocol conversion chip and data transmission method

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110113707A (en) * 2018-01-30 2019-08-09 四川中电昆辰科技有限公司 Multifrequency point location data return system and positioning system and its method
CN110113707B (en) * 2018-01-30 2024-03-22 四川中电昆辰科技有限公司 Multi-frequency point positioning data return system, positioning system and method thereof

Also Published As

Publication number Publication date
CN104486247A (en) 2015-04-01

Similar Documents

Publication Publication Date Title
WO2016095323A1 (en) Data transmission method and apparatus based on serial server
US20180157562A1 (en) Virtual machine-based data transmission method, apparatus and system
CN106034084B (en) Data transmission method and device
US8311059B2 (en) Receive coalescing and automatic acknowledge in network interface controller
US20170373804A1 (en) Methods for enabling delay-awareness in the constrained application protocol (coap)
WO2021042783A1 (en) Video image display method and apparatus, electronic device and storage medium
CN110830460B (en) Connection establishing method and device, electronic equipment and storage medium
WO2017035763A1 (en) Data packet transmission method utilized in ipv6 network and device utilizing same
WO2017198108A1 (en) Method and device for processing fragment messages
WO2018188084A1 (en) Data access method and device
CN103957169A (en) Reliable UDP achievement method based on reserve request
US11218564B2 (en) Methods and devices for signalling in a communication network
CN105472023A (en) Method and device for remote direct memory access
JP2009080584A (en) Protocol processing apparatus and control method
US20090225757A1 (en) Processing apparatus and method for processing ip packets
US7761587B2 (en) Apparatus and method for transmitting packet IP offload
JP2007200055A (en) Iscsi communication control method and storage system using it
CN104753813B (en) The method that DMA transmits message
CN104378778B (en) Method, system and the transfer gateway to communicate in Internet of Things between master-salve station
US20120066305A1 (en) Transmitting system and method thereof
US7426589B2 (en) Network interface card for reducing the number of interrupts and method of generating interrupts
JP6851754B2 (en) Relay device, relay system, relay program, and relay method
CN104012054A (en) Video processing method, device and system
TWI689820B (en) Usb transmission system, usb device and host capable of usb transmission
CN114338477A (en) Communication link monitoring method, device, equipment and storage medium

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 15868840

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 15868840

Country of ref document: EP

Kind code of ref document: A1