Implementation of multi-serial port conversion gateway based on TCP / IP

Implementation of multi-serial port conversion gateway based on TCP / IP

With the expansion of the scale of enterprises and the widespread popularity of Internet technology, different companies in various fields around the world have reached a consensus on "connecting devices to the network", and among industrial control and communication equipment, more are serial ports that comply with the RS232 standard device. How to forward the data of multiple serial ports to the network to realize the remote control of the device and the remote transmission of data has become an urgent problem to be solved. At the same time, considering the cost issue, it is impossible to eliminate all the equipment in the past. Therefore, this paper proposes a multi-serial port conversion gateway based on TCP / IP, which can fundamentally solve this problem.

Multiple serial port conversion gateways make it possible to transfer serial data streams to Ethernet data streams. It can connect multiple RS232 serial port devices, and select and process serial port data, convert the RS232 interface data stream into an Ethernet data stream, so that networked data processing can be performed, and serial data can be networked. With this solution, there is no need to eliminate the original serial device. Multiple devices can be connected to the network at the same time, which can not only improve the utilization rate of the device, but also save the cost of networking, and simplify the wiring complexity on the basis of the existing network. The serial port expansion chip GM8123 can realize a multi-serial port scheme with low cost, high speed and simple control.

1 System application plan

In the enterprise automation system, the upper-layer enterprise management layer and production monitoring layer generally use Ethernet and PC, while the lower-level workshop scene is mostly RS232 serial port measurement and control equipment. The multi-serial port conversion gateway proposed in this paper can facilitate the communication between the upper and lower layers.

The ability to connect multiple serial devices is the biggest feature of this system, avoiding the disadvantages of higher cost and complicated networking caused by configuring a gateway for each device.

2 System structure

TCP / IP protocol is composed of application layer, UDP layer, IP layer and data link layer. In order to achieve transparent transmission, increase the application process protocol layer-serial port layer. The serial port layer is composed of a serial link layer and a serial network layer. The gateway is constructed at the serial port layer, and simultaneously parses RS232 data packets, and serves as data transmission at the TCP / IP network application layer. Multi-serial gateway consists of TCP / IP protocol conversion module and multi-serial transceiver control module, the structure is shown in Figure 1.


(1) TCP / lP protocol conversion module

It is a miniature Ethernet access module, consisting of a microcontroller (MCU), a network interface card, EEPROM 93C46, an off-chip 512 KBSRAM chip IS6lLV5128, and auxiliary components. The micro-controller controls the network card interface chip to perform network communication, and realizes the parsing and packetization of protocols such as Address Resolution Protocol (ARP), Internet Control Message Protocol (ICMP), IP protocol, and User Datagram Protocol (UDP). Encapsulate the serial frame of the Ethernet send buffer in a UDP packet and pass it to the IP layer; at the same time, receive the Ethernet data frame and unpack it to the upper layer, separate the application layer data, and then parse the data and send it to multiple serial ports The module is completed to realize the transparent conversion between RS232 serial port stream and Ethernet port stream.


(2) Multi-serial port transceiver control module


Realize the receiving / transmitting control of multiple RS232 serial data streams, including microcontrollers, serial expansion chips (GM8123), MAX232 and other components. The microcontroller controls the GM8123 to complete multi-serial data transmission and reception, receives multiple serial port source data, writes it into the Ethernet transmission buffer for packaging and transmission; at the same time, receives the data of the Ethernet application layer, parses and sends it to the measurement and control equipment. It does not care about the specific meaning of the communication data, but is only responsible for receiving / transmitting, encapsulating / unpacking serial frames, and providing a common interface.

3 Multi-serial port implementation

3.1 Implementation scheme-using serial port expansion chip

Based on 2 UARTs in the microcontroller, using GM8123, the system can provide 2 sets (UARTO, UARTl) of a total of 4 serial ports (COM1, COM2, C0M3, COM4), using two levels of priority to control UARTO and UART1 interrupt request and allow nesting. Within the UARTO interrupt routine, determine which sub-serial port the data source is by querying.


When two serial ports have data requests at the same time, first of all, the interrupt mechanism of the MCU judges the priority of the interrupt request, and responds to the interrupt request with high priority first. The system assigns priorities: UART0 is 2 and UART1 is 1, that is, the MCU gives priority to the interrupt request of UART0. When the three sub-ports of UARTO have data requests at the same time, they respond to each sub-port by polling, that is, they respond according to the address of the sub-port number from small to large. In this way, a multi-serial port implementation scheme with 2 levels of interrupts and 4 serial ports is formed.


3.2 Multi-serial port expansion chip-GM8123

GM8123 can expand a full-duplex standard serial port into 3 standard serial ports, and can be controlled by external pins. The choice of this chip is based on its own characteristics:

â‘  Control the chip by writing control words, the control is simple;

â‘¡The data format can be selected from 10 digits or 11 digits;

â‘¢ Has 3 sub-serial ports. And the baud rate of each sub-serial port is adjustable (uniform adjustment);

â‘£Two modes (single-channel mode and multi-channel mode) can be controlled by 1 pin;

⑤ In the multi-channel working mode, the baud rate of each sub-serial port is equal to the frequency divided by 4 of the baud rate of the female serial port;

⑥ In multi-channel working mode, the address line SRADD1 ~ 0 returns the address of the receiving sub-channel to the MCU during reception. After the MCU receives the data sent from the mother serial port, it can determine which sub-serial port the data is from according to the state of SRADDl ~ 0 When sent, the MCU selects the sub-serial port before sending data to the mother serial port;

⑦ Compatible with standard serial communication format, TTL level output;

⑧Sample 16 times per bit to improve data accuracy;

⑨ The wide working voltage is 2.3 ~ 6.7 V.

⑩ Input address pin has 50 ~ 80 kΩ pull-down resistor, other inputs

The pins have 50 to 80 kΩ pull-up resistors (except OSCI).


3.3 Characteristics and application analysis of each serial port


The resources used by the two sets of serial ports in the system are different, and there are differences in speed between them. The serial ports COMl, COM2 and COM3 are obtained through the GM8123 expansion microcontroller's UARTO, suitable for devices with slow transmission rate and small data volume; COM4 is the microcontroller's UARTl, which can adapt to the transmission rate of the first group of serial ports well. Quick device.


GM8123 works in multi-channel mode, and each sub-serial port must be set with a uniform baud rate, which is not suitable for occasions where the serial baud rate of each serial device is inconsistent and requires simultaneous work. This is also the shortcoming of this chip. In practical applications, COM1, COM2, and COM3 should be connected to devices of the same type and rate. The baud rate of COM4 can be configured according to the requirements, so that the four serial ports of the system can form two application solutions from the speed: one is that the four serial ports are configured with the same baud rate; the other is that each b group is configured with one baud rate value.

In summary, the system provides a multi-serial port implementation method consisting of 2 sets of 4 serial ports, two-level priority control, and 2 baud rate configuration schemes.


4 Working principle

4.1 Unification of frames

The data of the four serial port sources of the system should be part of the Ethernet frame. In order to provide a transparent interface to the device and distinguish the data source, a unified frame format needs to be developed. The frame format is shown in Figure 2, where the serial number field is used to distinguish the data source; the frame header and frame end are used as the starting boundary of a serial port frame (can be customized); the data part is the original data stream from the serial port. Similarly, the data sent by the network port must have a consistent frame format, as shown in Figure 3. Obviously, the serial frame is transmitted as the protocol data of the UDP layer.


4.2 Analysis of system data flow

The multi-serial port conversion gateway realizes the data conversion between multiple serial ports and one network port. The key is how to send multiple serial port data to the network and how to transfer the network data to multiple serial ports. Among them, the serial port link layer completes the serial port data receiving and sending function, and the serial port network layer is used as a part of the TCP / IP application layer to realize the encapsulation of the serial port frame. Sending is the process of entering the protocol stack. As shown in Figure 4, receiving is the process of leaving the protocol stack (figure omitted). The difference lies in the data receiving / transmitting process.

Multi-serial port to network port data conversion and transmission: serial port link layer, receiving data from the measurement and control equipment, and handing it to the serial port network layer, which completes the encapsulation of the serial data frame and puts it into the Ethernet transmission buffer. When the UDP packaging time specified by the system is reached or there are already 4 serial data frames, UDP packets are sent and sent layer by layer until the data is sent to the physical medium to complete the bit stream transmission.

In order to transmit as much data as possible at one time, the system strictly defines the data length: the maximum length of the data segment of the serial port data frame is 300 bytes; the data segment of the frame sent by the network port allows up to 4 serial data frames. At the same time, it also needs to meet the real-time requirements of specific applications: specify a maximum response time for each serial port. When the time is up, no matter whether it has been received: 300 bytes must be encapsulated to the serial port data and placed in the Ethernet transmission buffer; at the same time, in order to avoid the system from waiting for the Ethernet transmission buffer serial port number to reach 4, Serial data cannot be sent in real time, and it is required to perform an Ethernet communication within a certain period of time, without having to wait for the four serial frames to be packaged for transmission.

In this way, the system's double regulations on data capacity and time can ensure the real-time requirements of specific applications, and can transmit as much data as possible at a time, reducing the possibility of poor real-time performance due to "empty" time. The functions of the four serial ports on the serial port layer are the same. Only COM1 is used as an example to give the data on the serial port layer.

Flow, as shown in Figure 5.

Figure 6 illustrates the process of multi-serial data frame waiting for package transmission.

The flow of data from the network port data to multiple serial ports is a process of unpacking the data frames of the Ethernet link layer upward. As shown in Figure 7, the received Ethernet frames are sequentially removed to decompose the application layer data of each layer, and then separated by 0x24 and OxOa as the boundary. According to the value of the serial number field, the information is sent to the corresponding device To complete the scheduled control.

Conclusion

This article introduces a multi-serial port conversion gateway based on TCP / IP. The GM8123 chip is used to increase the number of serial ports, which is suitable for occasions requiring a lot of serial devices connected to the network. With the help of the multi-serial gateway, the transparent data communication between the serial device and the monitoring layer can be conveniently realized, and the networked control of the device and the distributed management of information can be realized. It must be widely used in the distributed measurement and control network based on Ethernet. Similar to it is the GM8125 serial port expansion chip, but the GM8125 is a serial expansion chip with five expansions.

We offer Industry's leading lipo cells from Panasonic, Sanyo, Samsung, ATL, Wanma, HYB, DLG, BAK, as well as sourcing low cost cells from other small size Lipo cell factories.  There are regular lipo cells with discharge rate below 1C, and high discharge rate lipo cells up to 40C.  

lithium polymer battery, Lithium Ion Polymer Battery, polymer battery, lithium polymer, 3.7 v Lipo Battery , lipo, batterie lithium polymère,  li ion li polymer,  batterie lipo,  li po, lithium ion vs lithium polymer.

3 v battery, 3 volt lipo battery, 3v lithium, 3.2 v lipo battery,  
3.2 volt lithium battery, 3.2v Lithium Ion Battery, 3.3 v battery pack, 
3.3v lipo battery, 3.5 volt Rechargeable Batteries
3.6 Lithium Ion polymer battery, 3.6 v LiPo, 3.6 volt LIP,  
3.7 volt single cell battery pack, 3.7v 1s Lipo, 
3.8 lipo cell, 3.8 v Lipo Rechargeable Battery, 3.8v rechargeable batteries, 
3.7 Li-poly, 3.7 lithium-poly, 3.7 v battery cell.
4 v li battery, 4.2 v lipo battery, 4.2 volt lithium ion polymer rechargeable battery.

Lipo Battery

Lipo Battery,Lithium Ion Polymer Battery,Lipo Rechargeable Battery,Lithium-Poly Battery

Asarke Industry Co., Limited , https://www.asarke-industry.com

Posted on