Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
QT5.1 Serial Communications Errors using QSerialPort
KarolyS last edited by
I've got an interesting issue when making use of the new QSerialPort class in QT5.1. I am communicating with what is effectively an Arduino Leonardo and am getting inconsistent serial reads via QT. The flow from the application(Windows 8) is as follows:
Software writes to Arduino
Arduino returns string/line to software
Software sends command to Arduino
Arduino runs function and returns string/lines during and after function completes
Software waits for these strings/lines and handles accordingly
My issue stems from the fact that after I write to the serial comm telling my Arduino to run the function, the serial comm just breaks down and I receive nothing further. I know that the issue is not with the Arduino because the Arduino IDE Serial Monitoring tool displays everything as expected. Below is my read/write code in my QT5 application.
@void serial_client::slot_messageSend(char * msgToSend)
QByteArray data = serialPort->readAll();
QString message = data;
data += serialPort->readAll();
message = data;
Aside from the emission of signals based off of what is read from the serial comm, nothing else interacts with it in my application. If anyone could shed some light onto whats going on it would be immensely appreciated, I've used the examples to get this far, but they've stopped being helpful.
EDIT: As an after the fact thought, ill bundle in here that QSerialPortInfo causes unfixable errors and is unusable. Much lower priority but a small allegedly functional example of that usage would be great.
If anyone could shed some light onto whats going on it would be immensely appreciated, I’ve used the examples to get this far, but they’ve stopped being helpful.
Please update Qt up to 5.2 (or take and build QtSerialPort from Git).
Do not use methods like waitForXX(), because they still has an errors, see https://bugreports.qt-project.org/browse/QTBUG-33987. You can download sources from git, apply it patch and let me know how it work.
In your case it is better to use the non-blocking approach with use the readyRead() signal.
Usual is used the state machine's approach for send/receive messages.
As an after the fact thought, ill bundle in here that QSerialPortInfo causes unfixable errors and is unusable.
Can you say more informative about your problem with QSerialPortInfo?
KarolyS last edited by
I've gone ahead and updated to 5.2, I hadn't realized it had been released! I am attempting to use the readyRead() signal, my problem starts there actually. Unless I use waitForXX() I I never receive the readyRead() signal. It just never triggers. I've made sure that I've actually got my slot connected and everything yet it is never triggered.
I know that I'm receiving serial communication because as I mentioned in my first post, the Arduino IDE shows the messages with no problems.
Could you elaborate what you mean by your 4th point?
Ill have to try QSerialPortInfo again now that I've got Qt 5.2, once I've got a result I'll post an update, but its a low priority.