QSerialPort reads only one byte
Unsolved
General and Desktop
-
I connect TX/Rx contacts together. Then I send **IDN?*. My oscilloscop shows that all of 5 bytes are sent. But readAll returns a QByteArray with only first byte.
#include <QCoreApplication> #include <QtSerialPort> int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); printf("initialization...\n"); //debug QSerialPort serial; serial.setPortName("COM2"); serial.setBaudRate(QSerialPort::Baud9600); serial.setDataBits(QSerialPort::Data8); serial.setParity(QSerialPort::NoParity); serial.setStopBits(QSerialPort::OneStop); serial.setFlowControl(QSerialPort::NoFlowControl); serial.open(QSerialPort::ReadWrite); QString sendData("*IDN?"); printf("send data: "); //debug printf(sendData.toUtf8()); //debug serial.write(sendData.toUtf8()); serial.waitForBytesWritten(1000); serial.waitForReadyRead(1000); QByteArray receiveData = serial.readAll(); printf("\nreceive data: "); //debug printf(receiveData.data()); //debug printf("\nreceive byts: "); //debug printf("%d\n", receiveData.size()); //debug serial.close(); printf("end"); //debug return a.exec(); }
I use a USB-UART demoboard PL2302 from the WaveShare with PL2303TA IC. My enviornment is Windows 7 and Qt 5.10.0. Also I have test this code on a UAS-DB9M-02 USB-UART cable from the Gembird with the same behavior. Examples from LabVIEW works fine with PL2303. So I think it's a Qt problem.
What am I doing wrong?
-
@flammmable said in QSerialPort reads only one byte:
readAll
You should not expect that it delivers you everything at once. You should rather connect a slot to readyRead signal, call readAll in that slot and accumulate the data in a buffer until you got everything.
-
This post is deleted!