Unsolved Qt Serial Communication in Mac OS Buffer Problem
-
I tried run samples of qt serial blocking master on Mac OS Sierra, I tried to loop the serial line (loopback) but I got problem there the data going bad.
I tried to add flush command but still problem.How to fix it?
-
Make sure to read old data from the serial device after you've opened it by calling readAll() - it may be that the serial port has some data which was not yet read.
-
I have added readAll() after opened the port but problem still in there, also I tried to modified timeout time for ready read but not help.
while (!m_quit) { //![6] //! [7] if (currentPortNameChanged) { serial.close(); serial.setPortName(currentPortName); if (!serial.open(QIODevice::ReadWrite)) { emit error(tr("Can't open %1, error code %2") .arg(m_portName).arg(serial.error())); return; } //I added this one QByteArray responseData = serial.readAll(); while (serial.waitForReadyRead(500)) responseData += serial.readAll(); } //! [7] //! [8] // write request const QByteArray requestData = currentRequest.toUtf8(); serial.write(requestData); if (serial.waitForBytesWritten(m_waitTimeout)) { //! [8] //! [10] // read response if (serial.waitForReadyRead(currentWaitTimeout)) { QByteArray responseData = serial.readAll(); while (serial.waitForReadyRead(500)) //and modified this time responseData += serial.readAll(); const QString response = QString::fromUtf8(responseData); //! [12] emit this->response(response); //! [10] //! [11] //! [12]
-
I've tested with two serial port (no loopback communication) but the problem still in there.
This problem not appear when I use windows operating system.
-
Hi,
What type of serial port are you using ?