In the process of processing data collection, the most common practice is to use the channel loop-driven protocol, and then let the Protocol send and receive data through the device. This method is not suitable for large systems. It will make the system inefficient, especially when reading and writing serial ports, affecting the system's real-time response speed. Another approach is to generate a process for each channel to avoid inefficiency caused by channel polling. The disadvantage of this approach is to exchange space resources of the operating system for efficiency.
This article proposes a concurrent processing process. The technical solution is for reference only. Two horse driving thread car: one horse is the protocol processing thread, and the other is the device processing thread. Under the joint drive of the two horses, the channel and the living body of the Protocol will start up. Each channel is allocated with a "sending zone" and a "receiving zone". The device includes a serial port, Ethernet, and CANbus. The Protocol includes Modbus, iec101/103/104, and so on. The device sends the data in the "sending zone" to the driver buffer zone through the device driver interface of the operating system, and stores the data received by the device in the "receiving zone, through corresponding rules, the Protocol fills in the corresponding received data in the raw data sharing area.