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. Qt Serial Port "parameter is incorrect" error
QtWS25 Last Chance

Qt Serial Port "parameter is incorrect" error

Scheduled Pinned Locked Moved Solved General and Desktop
serialportqtserialportqt 5.14.2creator 4.11.2
12 Posts 4 Posters 2.7k Views
  • 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.
  • raymalifalitikoR Offline
    raymalifalitikoR Offline
    raymalifalitiko
    wrote on last edited by
    #1

    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"));
        }
    
    aha_1980A 1 Reply Last reply
    0
    • K Offline
      K Offline
      kuzulis
      Qt Champions 2020
      wrote on last edited by kuzulis
      #8

      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.

      raymalifalitikoR 1 Reply Last reply
      3
      • raymalifalitikoR raymalifalitiko

        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"));
            }
        
        aha_1980A Offline
        aha_1980A Offline
        aha_1980
        Lifetime Qt Champion
        wrote on last edited by
        #2

        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

        Qt has to stay free or it will die.

        raymalifalitikoR 1 Reply Last reply
        0
        • aha_1980A aha_1980

          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

          raymalifalitikoR Offline
          raymalifalitikoR Offline
          raymalifalitiko
          wrote on last edited by
          #3

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

          aha_1980A 1 Reply Last reply
          0
          • raymalifalitikoR raymalifalitiko

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

            aha_1980A Offline
            aha_1980A Offline
            aha_1980
            Lifetime Qt Champion
            wrote on last edited by
            #4

            @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

            Qt has to stay free or it will die.

            raymalifalitikoR 1 Reply Last reply
            0
            • aha_1980A aha_1980

              @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

              raymalifalitikoR Offline
              raymalifalitikoR Offline
              raymalifalitiko
              wrote on last edited by
              #5

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

              K 1 Reply Last reply
              0
              • raymalifalitikoR raymalifalitiko

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

                K Offline
                K Offline
                kuzulis
                Qt Champions 2020
                wrote on last edited by kuzulis
                #6

                @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)?

                raymalifalitikoR 1 Reply Last reply
                1
                • K kuzulis

                  @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)?

                  raymalifalitikoR Offline
                  raymalifalitikoR Offline
                  raymalifalitiko
                  wrote on last edited by raymalifalitiko
                  #7

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

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

                    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.

                    raymalifalitikoR 1 Reply Last reply
                    3
                    • K kuzulis

                      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.

                      raymalifalitikoR Offline
                      raymalifalitikoR Offline
                      raymalifalitiko
                      wrote on last edited by
                      #9

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

                      K 1 Reply Last reply
                      0
                      • CKurduC Offline
                        CKurduC Offline
                        CKurdu
                        wrote on last edited by
                        #10

                        @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?

                        You reap what you sow it

                        1 Reply Last reply
                        0
                        • raymalifalitikoR raymalifalitiko

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

                          K Offline
                          K Offline
                          kuzulis
                          Qt Champions 2020
                          wrote on last edited by
                          #11

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

                          1 Reply Last reply
                          0
                          • raymalifalitikoR Offline
                            raymalifalitikoR Offline
                            raymalifalitiko
                            wrote on last edited by
                            #12

                            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

                            1 Reply Last reply
                            1

                            • Login

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