Design of Data Acquisition System for VC Serial Communication

1 Introduction

Serial communication is one of the methods often used when computers exchange data with other devices.It has the advantages of simple implementation, flexible and convenient use, and reliable data transmission.It is widely used in industrial monitoring, data acquisition, and real-time monitoring systems.

The design of the high-speed serial data acquisition software is different from the ordinary serial communication.It requires the real-time storage of the received data while receiving a large amount of data from the data acquisition device.If the relationship between the two is not handled well, it will cause data Missing or even program crashing. This requires the application to be able to handle more than two different tasks at the same time. Win32 is a thread-based preemptive multitasking operating system that enables the application to perform multiple tasks at the same time, that is, in one process. Run multiple threads. A thread refers to an execution path of a program. The system constantly switches between multiple threads. Due to the short time, it seems that multiple threads are running at the same time. It takes a lot of time to communicate. For applications that test I / O operations while still responding to other user operations, creating multiple threads is the best choice.

2 System structure

The composition of the system is shown in Figure 1. The central control PC is the core of the system, which requires the data collection software to have good stability and compatibility. Therefore, a set of multi-thread communication software based on Visual C ++ 6.0 was independently designed The serial port communication of the scanner at the front end is a typical master-slave type, and the acquisition rate of 500K baud is realized on the hardware through the serial card of the MOXA company.

3 Use MSComm control to realize the problem of high-speed serial data acquisition

The MSComm control is very convenient when programming serial ports. Programmers do not have to spend time to understand more complicated API functions. They only need to configure the serial port in the properties of the serial communication resources (ProperTIes) .The baud rate, number of data bits, and The number of stop bits, parity, send buffer size, receive buffer size, and timeout settings are all configured at this time. After completing the serial port configuration, you can open the serial port to read and write data.

For general data exchange and serial communication, the MSComm control can fully meet the requirements. However, because the control itself limits the size of the receive buffer, it brings trouble to the design of high-speed data acquisition software. If the receive buffer cannot meet the design It is required that when the data in the buffer reaches the message response value and responds to the storage command, and the transmission speed of the newly collected data is faster than the storage speed of the received data, it will cause the overflow of the reception buffer and directly cause the system to crash. Have a deep understanding in the early stage of program design.

In the program design, when the buffer reaches the threshold response message, a new thread is started in the message response, the data received in the buffer is first taken out into the newly opened memory unit, and then the data is stored. The program can Running, but there is a new problem, that is, the data in some data frames is lost. Analysis of the reason for this data loss is still due to the limit of the control itself for the setting of the receive buffer size.

4 Programming innovation

4.1 Multithreaded programming ideas

In 32-bit Windows systems, the term multitasking means that the system can run multiple processes at the same time, and each process can also execute multiple threads at the same time. Processes are running instances of applications. Each process has its own private virtual address Space, each process has a main thread, but another thread can be established. The threads in the process are executed in parallel, and the time spent by each thread on the CPU is divided by the system.

You can think of a thread as the basic entity that the operating system allocates CPU time. The system constantly switches between threads. Its interruption to threads is assembly language level. The system allocates a CPU time period for each thread. Threads have control of the CPU only during the allocated time period.

All threads in the process share the virtual address space of the process, which means that all threads can access the global variables and resources of the process. This aspect brings convenience to programming, but on the other hand, it is also easy to cause conflicts. Although in the process Doing time-consuming work will not cause the system to hang, but it will cause the process itself to hang. So, if the process is to perform long-term work and respond to user input, then it can start a thread to be specifically responsible for time-consuming work , And the main thread can still interact with the user. It can be seen that using Win32's overlapping I / O operations and multi-threading features, you can compile efficient communication programs.

The characteristic of high-speed serial data acquisition software is that the speed of receiving data is very high, the amount of received data is large, and the amount of command word data sent by the control scanner is small. According to these characteristics, an auxiliary worker thread can be created in the program specifically To monitor the input of the serial port. Because the amount of data written to the serial port is not large, it will not be too time-consuming, so it is possible to complete the task of writing the port in the main thread without having to create another thread.

30KW-200KW Generator

Silent Generator For Home,200Kw Generator,30Kw Generator,100Kw Generator Diesel

Jiangsu Lingyu Generator CO.,LTD , https://www.lygenset.com