Win32API and QT Library implementation Win32 Serial Port programming solution

Source: Internet
Author: User
Tags win32

Using the QT interface, using QT multithreading, serial operation does not use the control, direct to the Win32 API to invoke, most of the serial operation are encapsulated in a class, in the auxiliary thread to set up the serial events and wait, according to my needs, set waiting for the arrival of specific characters, temporarily set to ' n ', which is the Terminator of a statement in the NMEA statement.

When a specific character arrives, the worker thread emit a signal to the GUI main thread, calls the serial operation class in the main thread for non-overlapping read operations, reads the byte length = the length of the string within the input buffer, and satisfies the need by dynamically allocating memory. Displays the read string in the main thread, and then frees the dynamically allocated memory.

Now the multithreaded part of the problem, most of the time today is debugging multithreading, in the beginning eclipse seems to be unable to use GDB to debug multiple threads in Windows, always error. Later, I do not know how to do it again, to catch up, and found that the main problem is waiting for the 500ms timeout, want to let the auxiliary thread sleep 100ms, use of sleeping (100), hey, it should be msleep (100).

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.