关注官方微信

中文.

Products

Products

The Key Technology for Serial to Ethernet

Date:2009-10-29 Author:Shanghai ZLAN Views:6275
1. Summary

Serial port to Ethernet can be implemented by serial port to Ethernet module, which is very simple and easy to use, but some new problems and use mistakes in this technology need to be noticed. Serial port to Ethernet is not a simple transfer medium, but a TCP/IP protocol conversion. The key technologies involved include: TCP/IP working mode, serial port framing, and the 9 bits technologies. The technology of these serial port to Ethernet is analyzed in detail here.

2. Clarify a concept: is it serial to Ethernet or serial port to TCP/IP?

The serial port is generally UART, which only defines the specification of the data link layer, which is the starting bit, data bit, and stop bit. However, the different physical layers are divided into: TTL serial port, RS232 serial port, RS485 serial port, etc.
TTL serial port: it is the serial port of data communication between MCU chip. It is represented 1 by +5V (or +3.3v), which is 0 in GND.
RS232 serial port: it is the serial port of communication between the devices, which mainly converts the voltage from 0~5V to ±15V (in fact, it is generally ±12V). The increase of voltage increases the distance and reliability of data transmission.
RS485 serial port: it is a serial port for remote communication, which can realize data transmission of thousands of meters. Its main characteristic is to use differential mode signal (voltage between two wires A and B) to replace the RS232 common-mode signal (the voltage between the signal lines & GND), which can resist common mode interference, achieve greater distances.

If classified according to the ISO 7 layer model (the physical layer, data link layer, network layer, transport layer, session layer, presentation layer, application layer), the serial port in fact only includes the physical layer and data link layer. The TCP/IP protocol should belong to the network layer and transport layer. So TCP/IP is not accurate. Ethernet belongs to the physical layer and data link layer, so the serial port to Ethernet is more accurate.

Because the protocol currently running on Ethernet is mostly TCP IP protocol, the serial port Ethernet can also be referred to as the serial port toTCP IP.

3. Key technology of serial port to Ethernet Port: TCP/IP working mode

Serial port to Ethernet is not a simple physical layer and data link layer conversion. Because the serial port protocol itself does not have network layer and transport layer, serial port to Ethernet, in fact, the serial port data is used as the application layer data of TCP/IP, and the transmission mode is encapsulated by TCP/IP. TCP/IP application layer data is the real valid data to be transmitted by TCP/IP. For example, the user receives and sends the application layer data through the socket's recv() and send() functions. This allows users using the recv() and send() functions to receive and send serial data through serial port to TCP IP.

However, TCP/IP is not simply recv() and send(), which is related to connection, closing, listening, and so on, depending on the mode of work. This is the part that needs to be processed after the serial port is transferred to the Ethernet port. The working mode of TCP IP can be divided into: TCP Server mode (TCP Server), TCP Client mode (TCP Client) and UDP mode.

UDP mode: UDP mode is based on a non-concatenated mode, which can be sent as long as the data is sent, and no prior connection is required. Therefore, this mode is closer to the serial communication mode. However, the UDP protocol cannot guarantee that the data is not lost, and it is easy to generate errors.

TCP mode: TCP mode adopts data reliable transmission mechanism, so it can guarantee that the data is basically not error code and not lost. In TCP communication, it must be composed of two sides of communication, one of which is the TCP client and the other is the TCP server. The concept of TCP client and TCP server is analogous to using the phone. The TCP client is the caller, and the TCP server is the person who answers the phone.

How do I select a TCP/IP working mode?
1). Selection of TCP and UDP: select the TCP mode as far as possible, especially the large data volume transmission over the Internet, and the UDP is prone to error code and loss.
2). Select TCP client or TCP server: please follow the following principles:
Principle 1: the party initiating the data transmission should choose the client. For example, a data acquisition system, the acquisition terminal should be the client. This is because when the TCP connection is disconnected, the client can initiate the connection when the data needs to be sent. The TCP server can only passively accept the connection so that the data cannot be sent out.
Principle 2: IP or domain name fixed on the server side. For example, in the case of multiple data acquisition terminals and only one central server, the central server should be the server. This is because the IP or domain name of the central server is generally fixed, and the IP of the acquisition terminal is constantly increasing and changing. The central server can't remember all the IP of the collection terminal, so it is difficult to initiate the connection. It is easier to find a central server from a collection terminal.

4. Key technology of Serial port to Ethernet port ii: serial port framing technology

Serial data can be sent continuously, while Ethernet data is sent in packets. This relates to the problem of sending how long serial data packets as an Ethernet packet.

Packet length: Ethernet packets are up to 1500 bytes long, so they must be packaged and sent when the serial port transponder receives 1500 bytes. Users can set this packet length limit.

Packet spacing: in addition to the packet length as the rule of serial framing, a more logical approach is through packet spacing. When the idle time of T millisecond occurred in the serial port data stream found by the TCP IP transponder, it is considered that the serial data received previously can be sent as an Ethernet packet. The T here is the packet interval that the user sets.

5. Key technology of serial port transfer: 9 bits technology

Ethernet data are calculated by Byte, each Byte is eight bits, but the serial data may appear nine bits, the ninth is often used to distinguish the address frame or a data frame, 1 indicates the address frame, 0 indicates the data frame. Then, after serial port converting to Ethernet port, how to transfer the 9th bit is a key technology.

In many serial port to Ethernet port solutions, the 9th bit is directly abandon, as far as known the solutions of Shanghai ZLAN information technology can quickly adapt to the function of the 9th, the called RealCom protocol is adopted in its implementation method. Because of the addition of the 9th position, the serial data cannot be converted directly to TCP IP application layer data. The Realcom protocol packages the serial port data as the application data transmission of TCP IP. In this way, 9th bit 1 or 0 of the packet can be added to the protocol header of the Realcom protocol to realize the 9th transmission technology.