Important: Please read the Qt Code of Conduct -

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?

    0_1561875996719_Screen Shot 2019-06-30 at 10.56.18.png

  • Lifetime Qt Champion

    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) {
                if (! {
                    emit error(tr("Can't open %1, error code %2")
                //I added this one
                QByteArray responseData = serial.readAll();
                while (serial.waitForReadyRead(500))
                    responseData += serial.readAll();
            //! [7] //! [8]
            // write request
            const QByteArray requestData = currentRequest.toUtf8();
            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.

    0_1561890437159_Screen Shot 2019-06-30 at 17.24.48.png

    This problem not appear when I use windows operating system.

  • Lifetime Qt Champion


    What type of serial port are you using ?

Log in to reply