Qt Serial Communication in Mac OS Buffer Problem
Unsolved
General and Desktop
-
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]
-
Hi,
What type of serial port are you using ?