In industrial control, it is difficult to expand the signal acquisition and monitoring of each device by relying solely on the serial bus. To connect the field control network and the information network, it is necessary to solve the conversion problem between the serial communication protocol and the Internet communication protocol, that is, to convert the original equipment into a peripheral with a network interface, so that the data on the traditional serial link can be transmitted to the information network without replacing the original equipment. In this way, the utilization rate of the original equipment can be improved, the number of multi-terminal connections can be increased, costs can be saved, the complexity of wiring can be simplified, and the communication distance can be extended.
In recent years, due to the needs of information technology and the development of the Internet of Things, a large number of serial port servers have emerged. They do not occupy host resources and have the function of terminal servers. However, the equipment is bulky, expensive, the serial port is not easy to cut or expand, packet loss occurs when transmitting a large number of data frames, and parameter configuration is complicated.
The core device of the serial server used in this design, Raspberry Pi, is a small, cheap but very powerful platform. It can access the Internet through a variety of communication methods and support a variety of complete network protocols. Combined with USB-hub and USB/serial port converter, it can ensure the ease of use of the serial server and achieve real-time, accurate, long-term and stable data transmission.
1 Overall design
According to the current industrial field data transmission requirements, the technical indicators and setting parameters should be as follows.
1.1 Technical indicators
① Main control chip: 32-bit 700 MHz ARM1176JZF-S processor;
②Operating system: Linux;
③Supported protocols: TCP/IP, UDP, HTTP, FTP;
④Network interface: 10/100 Mbps adaptive Ethernet interface;
⑤Serial port type: 1~16 RS 232/RS485/RS422 interfaces, 1 TTL level serial port;
⑥Parameter configuration method: WEB browser configuration;
⑦Number of sessions: supports multiple connections, allowing up to 5 users to manage one module device at the same time;
⑧Working mode: TCP client, TCP server, UDP broadcast mode;
⑨Indicator light: power indicator light, communication indicator light;
⑩Power supply voltage: 5 V.
1.2 Setting parameters
This device uses a web browser to set up, and has a built-in web server. Users can manage and configure IP addresses, serial port communication parameters, working modes, etc. The following mainly introduces the settings of serial port communication and working mode parameters.
(1) Serial communication parameters
①Baud rate is 2400~115200 bps;
②The data bits are 6/7/8/9;
③The check digit is None/Even/Odd;
④The stop bit is 1/1.5/2;
⑤The frame length is 1~15000 bytes;
⑥The framing interval is 30~500 bits.
Among them, the framing length refers to the length of each frame of received data. Once the receiving end buffer receives data of this length, it will forward it; the framing interval is the so-called serial port timeout. The relationship between the timeout time T (s), the framing interval N (bits), and the baud rate B (b/s) is as follows. Once the timeout occurs, regardless of whether the existing data length reaches the framing length, the receiving end buffer will frame the existing data and forward it.
T = N/B (1)
(2) Working mode parameters
①A single serial port supports 1 to 5 sessions, and each session mode is independent of each other;
②The TCP server mode is bound to a port range of 1025~65535;
③TCP client mode requires configuration of the target server IP, port and automatic reconnection time. The automatic reconnection time refers to the time interval for re-initiating active connection when the network connection is interrupted or the server is abnormal, and the automatic reconnection is cyclical until a normal connection is established;
④UDP broadcast mode requires configuration of local port, target server IP and target port.
2 Hardware Design
This serial port server is composed of the latest Raspberry Pi, USB-hub and USB/quad serial port converter produced by Beijing Century Link Technology Co., Ltd. according to the above indicators.
2.1 Hardware structure
The hardware structure of the serial server is shown in Figure 1. The Raspberry Pi has two USB ports, a TTL serial port, and a 10/100 MHz adaptive Ethernet port. One USB port can be extended to 4n RS232/RS422/RS455 serial ports through a USB-hub and n (optional, up to n=4) USB/serial port converters. Another can be connected to an external wireless USB network card to achieve wired or wireless data transmission in a LAN or WAN.
Figure 1 Hardware structure diagram
2.2 Introduction to Raspberry Pi
Raspberry Pi is a single-board computer based on Linux system, which is only the size of a credit card. It is equipped with a 700 MHz ARM architecture BCM2835 processor produced by Broadcom, 512 MB memory, and uses SD card as storage medium. The operating system uses the open source Linux system and provides and supports Python as the main programming language. [page]
2.3 USB-hub Introduction
A USB-hub is a device that connects multiple USB devices to a USB port on a computer or another USB hub. At some point, they all come from one or two main USB ports inside the motherboard, rather than independent hardware. A USB port, a USB hub, and several peripheral devices can build a USB network. The USB-hub selected in this system expands from one USB port to 4 USB ports.
2.4 Introduction to USB/Serial Converter
The USB/serial port converter uses the Beijing Century Lianxin LENSYS-USB2COM-4 module. It is a rail-mounted serial port expansion module that realizes the function of expanding 4 serial ports with the USB port. It can quickly expand four computer serial ports through USB, set the RS 232/422/485 interface mode through the dip switch, and can also realize the function of 4 RS 232 to 4 RS422/485. This module can reliably, real-time and conveniently complete the transmission and conversion of RS232/485/422 signals in industrial sites, and is widely used in industries such as oil and gas, water conservancy, power dispatching, and municipal dispatching.
3 Software Design
The basic structure of the serial port server software design is shown in Figure 2. The client is just a WEB browser, and the software design is mainly reflected in the server-side web page display, business logic and data storage.
The WEB server is responsible for the manual configuration and storage of serial port server communication parameters, manual start and stop of communication programs, etc.; the application server is responsible for realizing the intercommunication between TCP/IP network and serial interface devices, and completing the conversion between data in TCP/IP protocol format and serial data; the database mainly includes user management data table, serial port parameter configuration data table, and working mode configuration data table.
Figure 2 Basic structure diagram of software design
The following introduces the three main tasks in the serial port server software design: the design of the WEB server, the design of the WEB configuration page, and the design of the serial port networking communication program.
3.1 Design of WEB Server
Due to the large number of serial ports, a web server is implanted in the Raspberry Pi. The web server converts user requests into queries or updates of background data, and displays a friendly graphical interface to users on the browser, realizing simple and unified remote communication parameter configuration, device management, user management, and monitoring of the running status of the serial port server.
This serial port network server uses Python that comes with the Raspberry Pi as the development language and uses the compact and flexible web.py development framework to provide HTTP services. Its lightweight meets the requirements of the acquisition system for data transmission modules and can improve the efficiency of the system. The WEB server design process is shown in Figure 3.
Figure 3 WEB server design process
After the device is powered on or the system is restarted, the WEB service starts automatically and initializes the information required for display and configuration of the WEB server. Users can access the parameter configuration page by logging in and authenticating through the browser to the designated port of the system. Among them, device information and network information are viewed and configured through the system file manager, user information, serial port parameters and working mode information are read and written through the database, and help information is downloaded through the FTP server for serial port server manuals, company service information and other documents.
3.2 WEB configuration page design
The WEB configuration page is the display layer of the WEB server, as shown in Figure 4. The number of serial ports scanned indicates that the serial port server has 16 serial ports, and each serial port configuration is independent of each other.
Figure 4 WEB configuration interface
Since the configuration program is designed to associate the working mode configuration with the serial port parameter configuration, if the first three serial ports are selected, only the working mode configuration interfaces of these three serial ports will be displayed in the working mode configuration, as shown in FIG5 .
Figure 5 Working mode configuration interface
The above configuration method can easily realize batch configuration. After the configuration is completed, a configuration information viewing interface can be generated, as shown in Figure 6. This interface can also edit and delete the communication parameters and working modes of the selected serial port. [page]
Figure 6 Configuration information viewing interface
3.3 Serial port networking communication program design
After the WEB server completes the configuration, the communication program can be started for data communication. The specific implementation process is shown in Figure 7. This program automatically starts after the device is powered on or the system is restarted. After reading the serial port communication and working mode parameters configured by the user, it enters an infinite loop of the communication program. The number of processes in the figure is the total number of serial ports configured for the field application. Among them, N is the number of serial ports of the serial port server, M (M≤W) is the number of serial ports used in N serial ports; n is the respective number, I is the process number; S is the number of configured sessions, and s is the thread number.
Figure 7 Serial server communication program workflow
In the three working modes, TCP server and TCP client belong to the same TCP protocol transmission program, and their data frame sending and receiving processing adopts the same idea. The following introduces the design of TCP, UDP protocol transmission program and data frame forwarding program:
3.3.1 TOP protocol transmission program design
The TCP protocol transmission program involves the design of the server and the client.
Server-side programming:
①Create a socket, select INET type and TCP connection mode;
② Read the configuration port for binding listening and wait for the client to actively connect;
③Set the listening queue size;
④ Enter an infinite loop, use accept() to wait for the client to connect, and the returned new connection corresponds to the client IP to establish a communication channel;
⑤Enter an infinite sub-loop and perform read and write operations through sendall() and recv().
Client programming:
①Create a socket, select the type and connection method the same as the server;
②Read the remote server IP and port configured;
③ Enter an infinite loop and use connect() to connect to the remote server. If the connection fails, reconnect after the configured timeout interval.
④After the connection is successful, it enters an infinite sub-loop and performs read and write operations through sendall() and recv().
3.3.2 UDP protocol transmission program design
UDP transmission is called connectionless transmission. There is no three-way handshake and error retransmission mechanism in TCP. Its transmission program needs to read the configured local IP and port, remote IP and port at the same time. After establishing a socket in the form of datagram, it can act as both the sender and the receiver. When acting as a sender, sendto() sends the address to the remote receiver's IP and port. When acting as a receiver, the local IP and port are made public. Recvfrom() waits for the data from the remote sender to arrive. Data packets sent from any address can be received.
3.3.3 Data frame forwarding program design
The serial port server function module realizes the function of converting serial link data and Ethernet data: on the one hand, it receives data frames from the serial link and converts them into Ethernet link data frames before sending them out; on the other hand, it receives data frames from the Ethernet link and converts them into serial link data frames before sending them out. The above two communication processes are executed in parallel, and multi-threading is adopted in the program design.
(1) Receiving network data
In each communication mode, the reception of network data is implemented in the specified callback function. The TCP communication reception function is recv(), while the UDP communication function is recvfrom(). When the data frame length accumulates to the specified receiving buffer size or reaches the serial port timeout and is still less than the specified data frame length, the instantiated serial port sending function write() is immediately called to forward the data received in the buffer through the serial port.
(2) Sending network data
When receiving serial port data, the serial port receiving function read() is called. When the data frame length reaches the serial port receiving buffer size or the serial port times out, the network sending function is immediately called to forward the data frame in the buffer through the network port. The TCP communication sending function is sendall(), and the UDP communication is sendto().
Conclusion
After passing comprehensive tests, this serial device server has been successfully applied to industrial sites. It can be seen that this serial device server supports high-frequency forwarding and real-time forwarding of large data frames, and can operate stably for a long time and around the clock.
Previous article:Design of electronic let-off and take-up system based on ARM7 and CAN bus
Next article:S3C2440 NAND Flash Controller
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- [STM32F769Discovery development board trial] Discussion and application of DMA2D screen refresh efficiency
- Using Energia to develop MSP430F5529LP under Windows 10 Basic process and problems encountered
- Wi-Fi 6E has been launched. What is the difference between it and ordinary Wi-Fi?
- uboot operates gpio level
- UNI-T UT70B Multimeter Schematic Diagram and Instruction Manual (EN)
- DIY Music Box (Ask a master to help come up with an attractive title)
- Can you analyze the circuit for me?
- RSL10 information summary, sharing and exchange
- RF PCB Simulation Cookbook
- This year's Mid-Autumn Festival and National Day will not leave Shanghai