Preface system. For users, the key equipment is the user receiver (GPS receiver). In many cases, users use a computer to communicate with a GPS receiver, import GPS information into the computer, and then process it. Because of its powerful functions in serial communication and post-reception data processing, VC has become the preferred development language for many users to develop GPS applications.
GPS data transmission and data format GPS data transmission is divided into synchronous serial transmission and asynchronous serial transmission.
Synchronous serial transmission uses a separate clock signal to time the transmitted data, so strict time control and synchronization protocols are required; asynchronous serial transmission does not require strict time control and synchronization protocols, but it requires Some regulations: Before data transmission, a "start" bit must be sent, and after a set of data is sent, a "stop" bit is sent, so asynchronous serial transmission is based on characters.
When the computer communicates with GPS for data transmission, asynchronous serial transmission is usually used. GPS is used as data terminal equipment (DTE) and computer (DCE) to use D-type RS-232C cable interface for data exchange. From the data output form, the output of GPS is divided into two categories: this code is intuitive, easy to identify and apply, and the unified standard format of GPS NMEA-3183 output uses ASC code. The format is defined as follows: The binary code is an encoding represented by 0 and 1. Although this code is not intuitive, it is easy to operate and is very common in computers. The current common word length is 8 bits, which can be represented by two hexadecimal numbers. When encoding, a binary number consists of a decimal point to the left, a point every 4 digits, and a zero before the 4 digits to form an integer part; a decimal point to the right, a minute every 4 digits, and a zero before the 4 digits to form the fraction. The format of the output / input binary data stream is low byte / high byte arrangement, and the output order of each byte is from least significant bit (LSB) to most significant bit (MSB).
The original GPS observations, ephemeris and other data are all binary coded. In order to meet the requirements of asynchronous serial communication, each group of data must contain three parts: prefix block, data block and end character. The prefix block includes the logo and sentence name of the message; the data block includes all the data in the message; the end character includes the checksum and carriage return and line feed.
The data format of various GPS receivers is the same in the overall structure, but the specific symbols, content, word length, etc. are different; therefore, before writing the program, you need to know the specific structure of this data.
In addition, when writing applications, in order to ensure the data transmission and the quality of the meter set, the checksum must be checked.
3. Use VC to write a basic serial communication program to create a serial communication handle. HFile takes the serial communication handle created above. DwinQueue and dvOutQueue are the size of the input buffer and output buffer respectively. Generally, DCB is the control word of the serial communication device. For GPS, it is necessary to set bit rate, data bit, parity bit, start bit, stop bit, and also set up serial communication protocols such as RTSDTR.
Time and the total time unit is milliseconds. Through the above settings, you can read and connect the serial port.
The read data is placed in the memory pBufier. pBuffer must first apply for memory space. iLength is the length of the data to be read, and pReadFact stores the length of the data actually read.
Please make good memory space and have assigned values). iLength is the length of the data to be written, and pReadFact stores the length of the data actually written.
4Compared with GPS data processing, the multi-thread communication program, the communication between the computer and GPS is much slower, and the communication with GPS may also be blocked, and sometimes the computer needs to communicate with multiple GPS, so if the application is written as a single thread , Is a very unrealistic choice.
Writing multi-threaded programs is mainly to open a separate thread for reading and writing GPS communications. The API for threading is as follows: LpThreadAttributes is a security attribute structure, which can generally be NULL. wStackSize is the size of the thread stack, generally 0, the system sets the parameters of the function. DwCreationFlags is a parameter for creating a thread. Generally, 0 is taken to execute the thread immediately after creation without suspending it. LpThreadld is to store the ID of the thread. When writing a multi-threaded program, for the convenience of transferring data between threads, you must carefully consider the parameter structure to be passed. In addition, when writing a multi-threaded program, we must also consider the problem of thread synchronization, which is mainly solved by the following API: HHandle is the handle of the object that needs to be synchronized. In this program, mhComm is the serial port handle. DwMilliseconds is the waiting time, generally iNFiNiTE, that is, infinite waiting.
The transmission of Windows messages is a multi-threaded program. When the communication between the computer and a GPS is completed, the GPS data processing thread must be notified to process the data. Then the communication thread continues to communicate with the GPS, and the data processing thread starts to process the data.
The communication between the communication thread and the data processing thread uses the Windows message mechanism. The APIs for sending messages are as follows: hWnd is the window handle of the data processing thread; Msg is a custom message flag, such as successful reception (WMRECEiVEK), etc .; wParam and lParam are the message parameters that need to be passed, for example, you can pass the received data to Data processing threads, etc.
The PostMessageO function is a program that processes this thread immediately after the message is sent. Unlike SendMessageO, it needs to wait for the data processing thread to finish executing before processing this thread's program.
First set the parameters of the serial port, please refer to the discussion above for details.
The parameter data structure passed to the reading thread: HWNDhWnd; // The window handle of the thread that called the thread // The main thread creates a reading thread between 300 and 6 â‘´, and a regional power grid may have more than 10 substations, If they are built into a table, the time required to locate a fault will not meet the real-time requirements of the system. The actual measurement shows that when using the double-layer library structure, the time required to locate a fault will not exceed 0.2 seconds, which is within the allowable range.
The program is easy to implement and the software is easy to use. Restricted by the computer screen, the wiring diagram of a power grid is likely to be displayed on the screen, and field operators are often accustomed to using substations as a unit to check the status of the power grid. It will automatically display the wiring diagram of this substation completely on the screen.
Maintainability is strong. In the process of automatically generating grid wiring information, you can directly select any existing components, modify or delete them; for substations, you can also add, delete, and modify operations, so it is easy to maintain.
7 Conclusion In summary, the network topology information automatic generation system realized by the above method satisfies the real-time display requirements of the fault diagnosis system. At the same time, in the process of software implementation, due to the full use of the advantages of VC ++ object-oriented, the system functions are divided into several parts, which are completed by several modules. They are both independent and organically combined. On the one hand, the program design is clear and easy to implement; on the other hand, the safety, reliability and accuracy of the entire system have been greatly improved.
Practice has proved that the method implemented by this system not only has good performance indicators in the above fault diagnosis system, but also has good application value for similar real-time monitoring systems.
Gold Finger Pcb,Flexible Circuit Board Gold Finger,Circuit Board Gold Finger Plating,Gold Finger Circuit Board
Shenzheng Weifu Circuit Technology Co.Ld , https://www.viafoem.com