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

Qt Serial Port "parameter is incorrect" error



  • I have a very basic serial port application for general reading/writing purposes.

    Sometimes I am facing error "parameter is incorrect" when I try to open a non-busy com port. When this error occurs, I tried with qt serial terminal example too. I get the same error with qt example. As I mentioned, the same code generally works with no error but sometimes I face this problem and I can not fix even if I restart the computer and target device.

    I am sure that com port is not in use and there is no error with the target device because I tried with a lot of 3rd party serial terminal programs. I can read/write by using these 3rd party terminal programs.

    In the below post, there is a related topic but I could not fix it.
    https://forum.qt.io/topic/49812/resolved-can-t-configure-setting-when-my-program-use-qserialport

    I am using Qt Creator 4.11.2. Based on Qt 5.14.2.

        m_serial->setPortName(p.name);
        m_serial->setBaudRate(p.baudRate);
        m_serial->setDataBits(p.dataBits);
        m_serial->setParity(p.parity);
        m_serial->setStopBits(p.stopBits);
        m_serial->setFlowControl(p.flowControl);
        if (m_serial->open(QIODevice::ReadWrite)) {
            showStatusMessage(tr("Connected to %1 : %2, %3, %4, %5, %6")
                              .arg(p.name).arg(p.stringBaudRate).arg(p.stringDataBits)
                              .arg(p.stringParity).arg(p.stringStopBits).arg(p.stringFlowControl));
        } else {
            QMessageBox::critical(this, tr("Error"), m_serial->errorString());
            showStatusMessage(tr("Open error"));
        }
    


  • One of them is my STM board.
    power meter device from Siemens

    Most likely, these devices does not handles properly some CDC-class callbacks (or does not support some ioctl's or its values) in their FW's.

    F.e. it may not support some properties of DCB or COMMTIMEOUTS structures, its ranges and so forth (or it does not suport the OVERLAPPED operations). You need re-build the QSP, add there the debug outputs and to see where it fails.


  • Lifetime Qt Champion

    Hi @raymalifalitiko,

    I am using Qt Creator 4.11.2. Based on Qt 5.14.2.

    More interesting would be the Qt version and the operating system you are using.

    QtSerialPort creates a lockfile on successful port open, if that file still exists you cannot open it again. That may happen after a crash of your program for example. However, after reboot it should be fine...

    Regards



  • @aha_1980 Thanks for your answer. I am using qt creator on Windows 64 Bit machine. As I mentioned in my post, even if I restart the computer and the target device, I get the same error again.


  • Lifetime Qt Champion

    @raymalifalitiko said in Qt Serial Port "parameter is incorrect" error:

    I am using qt creator on Windows 64 Bit machine.

    Windows 10? And you still didn't tell us the Qt version that you use in your Kit.

    Which type of serial port is that, by the way?

    Regards



  • @aha_1980 Win10 and Desktop_Qt_5_14_2_MinGW_64_bit. I could not understand what you mean for serial port type? I use qt serial port example as a reference.



  • @raymalifalitiko

    What's a serial port chip do you use (is it USB/serial port converter, is it your custom device with a custom FW, e.g. based on Arduino, STM32 or other stuff)?



  • @kuzulis I used two different devices and get the same error within different times. One of them is my STM board. I am connecting to it through USB CDC Virtual Port. Another is the power meter device from Siemens. I tried with 3 different USB-232 convertors when this problem occurs. I can connect with 3rd party terminal programs in this case with these different converters and also to STM board directly using virtual com port.



  • One of them is my STM board.
    power meter device from Siemens

    Most likely, these devices does not handles properly some CDC-class callbacks (or does not support some ioctl's or its values) in their FW's.

    F.e. it may not support some properties of DCB or COMMTIMEOUTS structures, its ranges and so forth (or it does not suport the OVERLAPPED operations). You need re-build the QSP, add there the debug outputs and to see where it fails.



  • @kuzulis Is it normal that after rebooting of both devices and host computer, the problem still continues?



  • @raymalifalitiko said in Qt Serial Port "parameter is incorrect" error:

    Desktop_Qt_5_14_2_MinGW_64_bit

    Have you ever been tried it on MSVC based kit? Did you have the same problem?



  • @raymalifalitiko said in Qt Serial Port "parameter is incorrect" error:

    @kuzulis Is it normal that after rebooting of both devices and host computer, the problem still continues?

    I' don't know. You need debug it himself.



  • Thanks, @kuzulis for giving me a reference to look at the device side.

    The problem is solved by adding line coding settings to the CDC buffer on the STM. It is related to the hardware. STM users should bind USBD_CDC_LineCodingTypeDef data structure to CDC_Control_FS function.

    In ready-made examples, this binding does not exist. Users who do not add this binding can face the same problem in long term tests. Maybe it can help people who face the same problem.

    Regards