Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-66716

Sequential QSerialPort::write()'s require QThread::msleep() between them in MacOs Sierra

    XMLWordPrintable

Details

    • Bug
    • Resolution: Cannot Reproduce
    • P2: Important
    • None
    • 5.7
    • Serial Port
    • None
    • MacOs Sierra
    • macOS

    Description

      I have noticed some very strange behavior in QSerialPort on QT 5.7 between Windows7 and MacOs Sierra. On my particular setup, I'm communicating with a custom serial device. I have code that works on Windows 7 just fine, but it requires modification to work properly on MacOs. I've spent 20 or so hours fiddling around with the code, and I've found what works, but in searching the documentation, I have no idea why it works-- the QT documentation does not appear to say anything about this at all.

      Here's the code that works just fine on Windows7

       

      QByteArray line = FileToWriteOut.readLine();
      while (!line.isEmpty())
      {   
          //QThread::msleep(2); //Apparently MacOs won't continuously write to the   port without this?
          qint64 nwrite = MyQSerialPort->write(line); 
          line = FileToWriteOut.readLine();
      }
      

       

       On MacOS (In this case – the version is Sierra,) I run into different behavior. After some small number of writes (on the order of 13 writes of 44 characters each,) writing stops. No signals are thrown, and upon probing futher, I find that the serial port buffer fills up, and a QSerialPort::ResourceError is set.

       

      I've tried using waitForBytesWritten(-1).  This results in freezing after 13 writes, just as described above.  Unless the msleep is thrown in, then it works fine.

      I've tried using signals/slots on both a direct and a queued connection, using the slot to trigger the next write, and again, unless msleep is thrown in, it doesn't work.

      I've tried using flush() after writes, but again, it doesn't work unless msleep is thrown in before sequential writes.

       

      All of this works just fine on Windows7, and I see nothing in the documentation to suggest that sleeping the thread should be required.  In the signals/slots case, the thread goes back to it's exec loop after a write and waits for a signal indicating that bytes have been written. After 13 or so sequential writes, the signal fails to fire, and the process times out, even though there is more to be written. When this happens the bytes stay in the write buffer.  

       

      I've posted this question to stack overflow here: https://stackoverflow.com/questions/48935965/qserialport-write-only-works-on-macos-if-qthreadsleep-is-called but I'm starting to be convinced that this is a bug in QT itself.

       

       

       

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            kuzulis Denis Shienkov
            mtsmith MIchael SMith
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes