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

QSerialPort not working without explicit setDataTerminalReady for USB serial

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 6.6.2
    • Serial Port
    • None
    • Windows

    Description

      This is yet another case of serial ports not immediately working on Windows, as they are working out of the box on Linux and Mac OS. After hours of searching and tweaking I managed to find the issue and a fix.

      This is using a Raspberry Pi Pico acting as USB Serial converter on Windows 10 Enterprise. The observed behavior is that no data is read from the serial device, unless it is opened and closed first by another application such as Putty - which has no issue opening the COM port and reading from it using default settings.

      Comparing source code of qtserialport-everywhere-src-6.6.2 and Putty 0.80 it is clear that Putty sets `dcb.fDtrControl = DTR_CONTROL_ENABLE` by default whereas qtserialport sets `dcb.fDtrControl = DTR_CONTROL_DISABLE` or leaves the default value of `dcb.fDtrControl`. A fix in the application is to call `serialport->setDataTerminalReady(true);` immediately after opening. A different fix is to open, initialize and close the serial port using the Windows API with `dcb.fDtrControl = DTR_CONTROL_ENABLE` in the application before calling the regular `serialport->open()`, also hinting at the issue being related to the default value of `dcb.fDtrControl`.

      One could argue this is a COM port driver issue in Windows, which maybe has the wrong default for `fDtrControl`; I don't know, nor care, but the clear point is that for my pretty common USB Serial gadget even the qtserialport examples don't work whereas one of the most widely used terminal programs on Windows (Putty) does. I suspect the behavior of Putty is tuned to be the "just works" method of opening a serial port, and suggest Qt should follow this approach.

      I will look into supplying a patch and PR, but before I find the time to do so, this bug report may already help someone else out.

      Attachments

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

        Activity

          People

            ivan.solovev Ivan Solovev
            maartenvds Maarten van der Schrieck
            Vladimir Minenko Vladimir Minenko
            Alex Blasche Alex Blasche
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes