Application of Multithread Serial Communication Technology in GPS

introduction

GPS (Global PosiTIon System) has a global, all-weather positioning, timing, and speed measurement system. Users use GPS receivers to receive signals from satellites to obtain information such as geodetic coordinates, elevation, and time of the current location, to achieve positioning and navigation. Or the purpose of measuring elevation. Satellite navigation and positioning technology is widely used in marine surveys, marine engineering, marine development, and military operations. Its high precision, speed, convenience, and all-weather characteristics make it more and more popular. In GPS navigation, GPS data following the NMEA0183 protocol needs to be collected in real time. After processing the data, the user's position, time, speed, and other information are stored in the database through the ODBC interface to provide a basis for displaying the target location on the electronic map in real time . In order to avoid the thread blocking caused by waiting for the serial port I / 0 operation, the program is required to perform data extraction, storage, display and other operations in the foreground while monitoring the serial port in real time. In order to solve real-time and multi-tasking, to avoid a certain task to occupy the CPU for a long time, multi-threaded programming is an ideal choice.

1 Multithreading overview

1.1 Basic concepts

A process is an execution instance of a program on a computer, a thread is an execution branch in a program, and multithreading means that multiple tasks can be executed simultaneously in the same program. Every process has at least one main execution thread. It does not need to be actively created by the user. It is automatically created by the system. The user creates other threads in the application as needed, and multiple threads run concurrently in the same process.

All threads in a process are in the virtual address space of the process, and these virtual address spaces, global variables, and system resources are used together.

1.2 VC

VC ++ environment support for multithreading technology visual c ++ 6.0, MFC class library provides support for multithreading programming, making multithreading programming more convenient. There are two types of threads in MFC, called worker threads and user interface threads. The main difference between the two is that the worker thread has no message loop, while the user interface thread has its own message queue and message loop. Worker threads are usually used to perform background calculation and maintenance tasks. User interface threads are generally used to process user input independent of the execution of other threads, and to respond to events and messages generated by users and the system.

1.3 Thread creation, suspend, resume, terminate

In MFC, the global function AfxBeginThread () is generally used to create and initialize the running of a thread. This function has two overloaded forms, which are used to create worker threads and user interface threads. Sus-pendThread () and ResumeThread () are used to suspend the specified thread and resume the thread suspended by SuspendThread (), respectively. Exit-Thread (DWORD dwExitC0de) is used to terminate the execution of the thread.

1.4 Thread synchronization

Threads often have to access some resources at the same time, so conflicts caused by access to shared resources are inevitable. In order to solve this resource conflict problem, the concept of thread synchronization must be introduced. The Win32 API provides a variety of synchronization control objects to resolve shared resource access conflicts, including the use of critical sections, the use of mutually exclusive objects, the use of semaphores, and use of events.

2 Serial communication programming

At present, when programming under Windows, there are three main methods of common serial communication: using MSC0mm communication control; programming with Windows API; and using some serial communication classes provided by third parties to write.

(1) MSComm control

Using the MSComm control will make programming quick and easy. However, due to the large amount of packaging, which reduces the controllability and flexibility of programming, so when multi-threaded multi-serial port programming, a lot of complicated processing needs to be done.

(2) Windows API

Using the Windows API to write serial port programs, especially complex multi-thread serial port programs, requires high programming ability for programmers. In addition to requiring programmers to be proficient in using and using numerous API functions and being able to write a lot of low-level code, they must also be familiar with thread programming methods.

(3) Third-party serial communication

When using the third-party serial communication class for serial port programming, it can make the programming efficiency high, the program controllable, and simpler than the Window API programming. Among them, the third-party serial port communication class that is most used is CSerial-Port. It is based on multi-threading and is a packaged class of Win32 API. It encapsulates the Win32 API class that handles serial ports. With this class, it is easy to operate the serial port. It is easy to implement multi-threaded serial communication. The program is written in Windows 98 It can run well under the operating system of / NT / 2000 / XP.

Comparing the three serial communication methods, it can be found that the use of third-party serial communication CSerialPort is a better choice for multi-thread serial port programming under Windows.

3 Application of multi-thread programming technology in GPS data acquisition system

3.1 Function analysis of GPS navigation system

GPS navigation gives the user's location in real time through GPS positioning technology, which requires receiving positioning data from the serial port of the GPS receiver in real time, while monitoring the serial port in real time, data storage and display, etc. Technology will solve this problem well. By analyzing the GPS navigation system, the program is divided into the following threads:

Main thread: Responsible for processing the user interface message processing, scheduling other threads to process data according to a predefined process.

Serial port monitoring thread: monitor the serial port, collect data and save the data to a buffer.

Warehousing thread: read data from the buffer for corresponding processing and store the processed data in the database.

Display thread: display the user's real-time location on an electronic map through a map matching algorithm.

The block diagram of the GPS navigation system is shown in Figure 1.

3.2 Specific implementation

The system first describes the thread in the corresponding header file, and then adds the creation program code when the program is initialized, so that after creation, the thread can execute concurrently with the main thread. The main thread, the storage thread, and the display thread are the same as the general programming process, so the following focuses on the serial port monitoring thread.

The serial port operation is based on the CSerialPort class based on multi-threaded programming. Its workflow is as follows: first set the serial port parameters, and then start the serial port monitoring working thread. After the serial port monitoring worker thread detects the data stream, control event or other serial port event received by the serial port, it notifies the main program by message, and stimulates the message processing function to perform data processing. This is for receiving data; sending data can be directly Send to the serial port. The application process is shown in Figure 2.

The programming steps are as follows:

(1) Establish procedures

Create an MFC application CSerial-PortteST based on a single document, and keep the default state for other steps.

Semiconductor Plastic Package

Semiconductor Plastic Package.Refers to the material whose conductivity is between the conductor and the insulator at room temperature. Semiconductors have a wide range of applications in radios, televisions, and temperature measurement. Diodes are semiconductor devices. Semiconductor refers to a material whose conductivity can be controlled and can range from insulator to conductor. Regardless of technology or economic development, the importance of semiconductors is enormous. Most of today`s electronic products, such as computers, mobile phones or digital recorders, have core units that are very closely related to semiconductors. The common semiconductor materials are silicon, germanium, gallium arsenide, etc., and silicon is a kind of most influential one among various semiconductor materials in commercial applications.

Semiconductor Plastic Package,Semiconductor Package,Silicon Transistor,Bi Directions Thyristor

YANGZHOU POSITIONING TECH CO., LTD. , https://www.cnpositioning.com

Posted on