Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qt Serial Communication in Mac OS Buffer Problem
Forum Updated to NodeBB v4.3 + New Features

Qt Serial Communication in Mac OS Buffer Problem

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 503 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    kangherr
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      0
      • K Offline
        K Offline
        kangherr
        wrote on last edited by
        #3

        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]
        
        1 Reply Last reply
        0
        • K Offline
          K Offline
          kangherr
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            Hi,

            What type of serial port are you using ?

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            1

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved