QSerialPort Qt5.9.1 issue
-
Hi,
i am facing an issue on QSerialPort. In Qt5.7.1 works fine but on Qt5.9.1 it is not receiving all values i am sending.
The code is the same and i am only changing the kits/version from 5.7.1 to 5.9.1.What i am doing is waiting so that bytes available are equal or greater than 160 and i will only read 160 bytes.
Here is my code:if(serial->bytesAvailable()>=160) { num=serial->read(buffer,160); if((num != -1) && num) { QByteArray DSI_Array = QByteArray(buffer, 160); ...Any idea? Is tehre a known issue on QSerialPort in Qt5.9.1?
-
Hi,
i am facing an issue on QSerialPort. In Qt5.7.1 works fine but on Qt5.9.1 it is not receiving all values i am sending.
The code is the same and i am only changing the kits/version from 5.7.1 to 5.9.1.What i am doing is waiting so that bytes available are equal or greater than 160 and i will only read 160 bytes.
Here is my code:if(serial->bytesAvailable()>=160) { num=serial->read(buffer,160); if((num != -1) && num) { QByteArray DSI_Array = QByteArray(buffer, 160); ...Any idea? Is tehre a known issue on QSerialPort in Qt5.9.1?
-
Hi,
i am facing an issue on QSerialPort. In Qt5.7.1 works fine but on Qt5.9.1 it is not receiving all values i am sending.
The code is the same and i am only changing the kits/version from 5.7.1 to 5.9.1.What i am doing is waiting so that bytes available are equal or greater than 160 and i will only read 160 bytes.
Here is my code:if(serial->bytesAvailable()>=160) { num=serial->read(buffer,160); if((num != -1) && num) { QByteArray DSI_Array = QByteArray(buffer, 160); ...Any idea? Is tehre a known issue on QSerialPort in Qt5.9.1?
@michaelL said in QSerialPort Qt5.9.1 issue:
What i am doing is waiting so that bytes available are equal or greater than 160
Which leads me to the question, how you are doing that.
Also, on which platform are you experiencing this behavior?
-
So looking in the read part if i do:
QByteArray Array=serial->readAll();
it really does receive all bytes but the issue is when i want to read a specific amount of bytes like 160 and not all:So everytime i do this:
serial->read(buffer,160);The QSerialPort buffer "erase" all bytes that where read from "read()" function plus the left ones inside.
Why is the internal QSerialPort buffer been completely erased if i do "read(buffer,160);"
I understand if i do "readAll()" it will read all values from serialport and delete them.
But why is "read()" function doing the same in Qt5.9.1? -
@aha_1980 so i am reading in a slot
connect(serial, &QSerialPort::readyRead, this, &QelcSystemSerialport::run);Everytime QSerialPort send "readyRead" it goes to slot "run"
A MCU is sending values to Qt Application. I debug MCu and it is sending, i measured the RX and TX with an oscilloscope and the values are send out.
So the issue is in Qt -
I dont know if this is causing the issue:
void QIODevice::readyRead():
" you should always emit readyRead() when new data has arrived (do not emit it only because there's data still to be read in your buffers"Everything was working with Qt5.7.1. Maybe i have to make a new loop to check if buffer still has values more ore equal than 160. If so, it should be read them, because the signal "readyRead()" wont be send out again.
-
Ok so this resolve my issue
Instead ofif(serial->bytesAvailable()>=160)I change it to
while(serial->bytesAvailable()>=160)So if buffer has more values it should read them too. Once is less then 160 bytes, it will leave the slot. It iwll come back when "readyRead" signal is emitted again.