Application of Multithread Serial Communication Technology in GPS

June 19, 2020

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.

PanelView Plus 6 Graphic Terminals

Our Bulletin 2711P PanelViewâ„¢ Plus 6 Graphic Terminals let you monitor, control, and display application status information graphically. These terminals offer the open-platform flexibility of the Windows® CE operating system. They are available in 4-15 in. standard display sizes. FactoryTalk® View Studio Machine Edition software lets you program all of your PanelView Plus 6 graphic terminals.


Features

  • Provides significant improvements over the PanelViewâ„¢ Plus 400 graphic terminals
    • Processor speed increased from 350 MHz to 1 GHz
    • Screen transition rate is up to 70% faster
    • System memory increased from 64MB RAM to 256MB RAM
    • Flash storage space increased from 64MB to 512MB
    • Includes 80MB nonvolatile storage for applications
    • Increased illumination of LED backlight displays
    • Greater connectivity to a variety of peripherals such as printers, mice, and keyboards
  • Supports ActiveX® Controls
  • Integrates with third-party software such as Microsoft® Internet Explorer® and Microsoft Office Viewers
  • Supports remote connectivity (VNC and FTP)
  • Offers backup restore functionality
  • Provides remote recipe and data management through .CSV files
  • Uses vector-based graphics from Symbol Factory
  • Includes built-in PDF viewer for context-sensitive operator support
  • Supports DataStore Plus logging and trending, which eliminates the 300,000 data point limit

PanelView Plus 6 400 Graphic Terminals

  • Includes a 4 in. flat-panel color display with 320 x 240 resolution and 18-bit graphics

PanelView Plus 6 600 Graphic Terminals

  • Includes a 6 in. flat-panel color display with 320 x 240 resolution and 18-bit graphics

PanelView Plus 6 700 Graphic Terminals

  • Includes a 6.5 in. flat-panel color display with 640 x 480 resolution (minimum) and 18-bit graphics
  • Supports operator input via keypad (22 funtion keys), via touch screen or via keypad and touch screen

PanelView Plus 6 1000 Graphic Terminals

  • Includes a 10.4 in. flat-panel color display with 640 x 480 resolution (minimum) and 18-bit graphics
  • Supports operator input via keypad (32 function keys), via touch screen or via keypad and touch screen

PanelView Plus 6 1250 Graphic Terminals

  • Includes a 12.1 in. flat-panel color display with 800 x 600 resolution (mimimum) and 18-bit graphics
  • Supports operator input via keypad (40 function keys), via touch screen or via keypad and touch screen

PanelView  Plus 6 1500 Graphic Terminals

  • Includes a 15 in. flat-panel color display with 1024 x 768 resolution (minimm) and 18-bit graphics
  • Supports operator input via keypad (40 function keys), via touch screen or via keypad and touch screen


AB PanelView Modules

AB PanelView Modules,Terminal Touch Screen,Grayscale Terminal Keypad,Display Module Panel View

Xiamen The Anaswers Trade Co,.LTD , https://www.answersplc.com