Parallel thread to read coming data
-
I never managed concurrent threads in Qt but now I need a function in my application to monitor the presence of available data coming from an FTDI device (I'm using the FDTI driver to read/write data). I need a for loop that run every few millisecond to check if there are bytes in the receive queue and thet run concurrently with the application. If there are bytes in the receive queue then emits a signal for the main thread.
I read some example about the Concurrent library but I can't achieve my purpose cause I am not familiar with this stuff. Can someone help me or get me some suggestion ?
-
Don't use QtConcurrent but a simple QThread and run your loop inside the run() function.
-
@Andrew23 said in Parallel thread to read coming data:
I need a for loop that run every few millisecond
A QTimer should be enough for this, no need for a thread.
If you really need a thread then use the worker object approach like shown here: https://doc.qt.io/qt-6/qthread.html
If something does not work/is unclear ask a more specific question. -
-
-
Hi, if you have only to display what is coming in you don't need a thread. I suggest to use a thread only if you have a machine state related to the external device.
If you want to use a thread, when something is come in you only have to emit a event to update the gui.
Please have a look at emit and slot features and the event cnnection types.
A suggestion: if you use a thread please use syncronized methods to read and write the uart. -
Can you show me an example to how use the FT_SetEventNotification?
- Just create an event handle (via CreateEvent ... as mention in FTDI doc).
- Configure event notification mask (via FT_SetEventNotification, FT_EVENT_RXCHAR ... as mention in FTDI doc).
- Use QWinEventNotifier class https://doc.qt.io/qt-6/qwineventnotifier.html to watch when the FT_EVENT_RXCHAR event triggered.
- When the event triggeres, fetch the reason (via FT_GetStatus(ftHandle,&RxBytes,&TxBytes,&EventDWord); )
- If RxBytes > 0 then read the data (as mention in FTDI doc).
That's all,