Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. 3rd Party Software
  4. [solved] QtSerialPort - Problem with waitForReadyRead() and bytesAvailable()
Forum Updated to NodeBB v4.3 + New Features

[solved] QtSerialPort - Problem with waitForReadyRead() and bytesAvailable()

Scheduled Pinned Locked Moved 3rd Party Software
4 Posts 2 Posters 5.2k 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.
  • J Offline
    J Offline
    jlind74
    wrote on last edited by
    #1

    Hello

    I can't get the functions waitForReadyRead() and bytesAvailable() to work as I expect them to.

    I'm using Qt 4.7.4, Win 7, MinGW compiler.
    QtSerialPort downloaded 11 Feb 2013.

    The code in short is:
    @
    openSerialPort();
    if(serial->isOpen())
    {
    serial->flush();

        RS232Cmd[0] = 0x1B; // 2 bytes, Esc A
        RS232Cmd[1] = 'A';
    
        serial->write(RS232Cmd,2);
        serial->waitForBytesWritten(100);
    
        bTest = serial->waitForReadyRead(5000);
        qDebug("w %d", bTest);
    
        temp_value  = serial->bytesAvailable();
        temp_value2 = serial->read(RS232Buffer, 8);
        qDebug("a %d", temp_value);
        qDebug("r %d", temp_value2);
    
        closeSerialPort();
    }
    

    @

    The output I get is this:
    @
    w 0
    a 0
    r 0
    @

    First of all, with the 5000 parameter to waitForReadyRead(); I expect the program to wait 5 seconds before displaying the debug output if no data comes in, but there is no wait time that I can notice.

    Second, I can see on the oscilloscope that the two bytes ('Esc' + 'A') are sent and that a 8 byte reply is received within 2ms.

    Third, with a terminal program I can verify that the 8 byte reply is correctly received on the PC.

    Any ideas on what's going wrong?
    Or have I misunderstood the functionality of these functions?

    1 Reply Last reply
    0
    • K Offline
      K Offline
      kuzulis
      Qt Champions 2020
      wrote on last edited by
      #2

      Yes, it is a bug. Thx for posting.

      Patch to fix it here: https://codereview.qt-project.org/#change,47729

      You can wait and update repo after applied this patch,
      or make changes yourself.

      1 Reply Last reply
      0
      • J Offline
        J Offline
        jlind74
        wrote on last edited by
        #3

        Thanks kuzulis,

        I changed line 161 in qserialport_win.cpp from:
        @
        return error;
        @
        to
        @
        return !error;
        @

        and now my simplified example works.

        Now, I can start working on the more complex software.

        1 Reply Last reply
        0
        • K Offline
          K Offline
          kuzulis
          Qt Champions 2020
          wrote on last edited by
          #4

          Please add [SOLVED] to caption

          1 Reply Last reply
          0

          • Login

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