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. QtSerialPort waitForReadyRead, read port error, timeout

QtSerialPort waitForReadyRead, read port error, timeout

Scheduled Pinned Locked Moved General and Desktop
6 Posts 2 Posters 5.3k 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.
  • C Offline
    C Offline
    CarlStenquist
    wrote on last edited by
    #1

    There seems to be a problem with QtSeriaPort when reading a (USB COM) port. Transmit always works fine. But every so often, I get a read() error. That is; the function waitForReadyRead() returns false. This is even though I know that the data is going across, as I am using a USB bus analyzer. I have captured this several times when waitForReadyRead() times out.

    When QtSeriaPort .error() is called at the time above happens, no error code is there (value is zero).

    I got around this frustrating problem by prompting the target to retransmit, but this was a tedious workaround for something that should work.

    Below is the read code which is called right after a transmit of 1-64 bytes.

    USBSER.SYS is the driver that windows is using for the COM port.

    @ /* waitForReadyRead() blocks until new data is available for reading and the readyRead()
    * signal has been emitted. The function will timeout after msecs milliseconds.
    * The function returns true if the readyRead() signal is emitted and there is new
    * data available for reading, otherwise it returns false (if an error occurred or the
    * operation timed out). */
    read_result = port->waitForReadyRead(PORT_RW_TIMEOUT);
    if (read_result)
    {
    response_record = port->readAll();

        /* Make sure ALL data has come in by waiting a few more ms. */
        while (port->waitForReadyRead(PORT_RW_TIMEOUT_DELTA))
        {
            response_record += port->readAll();
        }
    

    ...
    }
    else /* SOMETIMES IT TIMES OUT TO HERE, THOUGH I AM WAITING THREE SECONDS FOR DATA
    AND THE BUS ANALYZER SHOWS THE DATA ON THE BUS. /
    {
    /
    Read error, or timed out (read_result was false). */
    rr_err_code = RR_ERR_OR_TIMEOUT;
    port_error = port->error();
    }@
    ...

    Using Qt 5.1 on Win7/64 bit.
    Thanks for any insight!

    P.S. I'm not really a "lab rat". Just an applications engineer.

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

      Hi.

      Do not use the waitForxx() methods because they still has bugs:

      https://bugreports.qt-project.org/browse/QTBUG-33987

      Use async approach.

      1 Reply Last reply
      0
      • C Offline
        C Offline
        CarlStenquist
        wrote on last edited by
        #3

        Could you please explain more abut this?
        Will it be fixed?
        I will not be given the time to implement a thread or signal solution currently.

        P.S. I'm not really a "lab rat". Just an applications engineer.

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

          bq. Could you please explain more abut this?

          You can try do a workaround, like: https://codereview.qt-project.org/#change,67962

          bq. Will it be fixed?
          I hope - yes.

          1 Reply Last reply
          0
          • C Offline
            C Offline
            CarlStenquist
            wrote on last edited by
            #5

            Above does not seem to do anything to this issue. (Plus the English is hard to understand!)
            Implemented my own workaround: If Windows does not cooperate, I ask the target once more for the latest data. (Added a "Repeat Response Request" frame to my protocol.)
            Carl Stenquist

            P.S. I'm not really a "lab rat". Just an applications engineer.

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

              You can try this patch: https://codereview.qt-project.org/#change,74396 , for me it works.

              This patch still not merged yet. Maybe I will merge some later.. (e.g. after yours confirmation that it works).

              I mean that maybe in Qt 5.2.1 it will be fixed.

              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