Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QtSerialPort waitForReadyRead, read port error, timeout



  • 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!


  • Qt Champions 2020

    Hi.

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

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

    Use async approach.



  • 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.


  • Qt Champions 2020

    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.



  • 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


  • Qt Champions 2020

    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.


Log in to reply