QSerialPort with Thread miss same data
-
Please try to download this source of an application Qt based that uses QSerialPort
https://www.linux-apps.com/content/show.php/QtComPort?content=142378
It uses event approach. Please have a look that if it can help you.
The application can put in bridge two serial ports in order to monitor what is passing through. -
@jsulm and @mrdebug I just now tried the terminal program in examples and added only a few lines code in order to start the MCU. It too missed data.
If USB_Can converter's red led is on, it means that there is a missing transfer. However, while Hercules that is a serial port terminal program using, there is no missing data.
You can see this in below video.
Link : https://drive.google.com/file/d/0B7WvtYBLRY0YVFFmRzZvWWZKVFk/view -
@Gokhan I would say that is expected behaviour. By "resizing" the gui your main thread is blocked/busy with that.
But the statement is still true, QSerialport does not loose data.
Your device probably runs in an timeout because it gets no answer from your serialport, because the old data was not collected.Seems like Threading your SerialPort-communictation is the only option in this particular case.
-
@J.Hilk thank you, actually, first I wrote it like in my first post, and after that, I saw that it's not working, started to try all possibilities. I guess that there is a bug in Qt, because the assignee wrote a bug about this subject.
https://bugreports.qt.io/browse/QTBUG-61237@mrdebug I have gotten lots of errors with this Project QtComPort, I didn't compile it, guess that it needs a Linux PC.
-
- I guess that there is a bug in Qt, because the assignee wrote a bug about this subject.
https://bugreports.qt.io/browse/QTBUG-61237
Hi.
It is not in Qt. its a windows/platform thing.
It is a known thing with windows.
It applies to all apps. Also those not written in Qt.
https://stackoverflow.com/questions/18041622/how-do-i-stop-windows-from-blocking-the-program-during-a-window-drag-or-menu-but - I guess that there is a bug in Qt, because the assignee wrote a bug about this subject.
-
@mrjj However, another program is working well like you can see my video. Is this big problem for application? e.g my application must immediately give an error in this condition and stop the communication.
What do you suggest me in order to solve this problem? I had used the LabVIEW before and developed like this application, it had worked flawlessly. -
I have added for you an example "qsp-no-freeze-workaround-windows" which demonstrates how it should work with threads!
-
@kuzulis Thank you very much, it's really working well. My first code that is in my first post here looks like this, but there is one different between them, it is inheritance. Is this a problem?
Also, how should I use qmutex between two classes in order to syncrhronşze? It's not declared the static and global variable is not recommended for it.
-
@Gokhan said in QSerialPort with Thread miss same data:
how should I use qmutex between two classes in order to syncrhronşze?
What do you need to synchronize ?
You could use signals to tell other class about new data. -
@Gokhan
Hi, you cannot use any widget in any other thread than the main thread.
But using a signal to tell the some other class about the formatted data will work super.
https://stackoverflow.com/questions/15276628/send-data-from-worker-thread-to-gui-thread-in-qt -
@Gokhan
The signal will contain a copy of the data so in most cases you do not need to protect it.
But depends on your design. If its possible that array is being written to , while you clear it then, yes
you need concurrency control.