![]() ![]() You should only need to spawn a single thread. ![]() (perhaps more important) Avoid loss of serial data caused by buffer overflow when the GUI routines hold off the serial-data-reading routine for too long.Avoiding poor GUI performance due to the GUI-handling routines being held off by the serial port processing routine.I think there are two main advantages that you can obtain by using multithreading: Spawning a thread for each message also makes the order of the messages non-deterministic, which hasn't been a major problem so far.Īre there other methods, what are the pros (if any) and cons of each, and which is the best to use? Thanks!ĮDIT: A problem with processing messages in the main thread is that interacting with GUI (even moving the window) would block the message processing function. I'm currently using method 4, which is horribly inefficient and doesn't work well on lower-end computers, due to the enormous number of threads being spawned, and every time I move or interact with the GUI, serial communication halts. Methods 1,2 and 3 differ by the number of threads the general workload is split up into, though I don't know which is best. Using the main thread to asynchronously read serial port, extract a valid message, and for each message, spawn a new thread to process them.Using one thread to read a serial port, extract a valid message, and block till that message is processed, making use of QtSerialPort's internal read buffer to buffer incoming data.Using another thread to parse the messages Using one thread to read a serial port, and extract valid messages into a buffer ![]() Using yet another thread to parse the messages Using another thread to read the buffer, extract valid messages (into another buffer? not sure how this will work yet) Using one thread to read a serial port and fill a buffer ![]() The message protocol is simple, 0xff is used to end each message. My aim is to receive messages from a serial device without blocking the main thread (GUI) and to try to separate the platform-dependent logic (GUI and serial port) from the business logic (processing the messages) for ease of porting to other platformsĬontext: I'm using Qt, and the QtSerialPort module. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |