Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Call for Presentations - Qt World Summit

    Solved Qt Serial Port "parameter is incorrect" error

    General and Desktop
    serialport qtserialport qt 5.14.2 creator 4.11.2
    4
    12
    1135
    Loading More Posts
    • 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.
    • raymalifalitiko
      raymalifalitiko last edited by

      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_1980 1 Reply Last reply Reply Quote 0
      • K
        kuzulis Qt Champions 2020 last edited by 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.

        raymalifalitiko 1 Reply Last reply Reply Quote 3
        • aha_1980
          aha_1980 Lifetime Qt Champion @raymalifalitiko last edited by

          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.

          raymalifalitiko 1 Reply Last reply Reply Quote 0
          • raymalifalitiko
            raymalifalitiko @aha_1980 last edited by

            @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_1980 1 Reply Last reply Reply Quote 0
            • aha_1980
              aha_1980 Lifetime Qt Champion @raymalifalitiko last edited by

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

              raymalifalitiko 1 Reply Last reply Reply Quote 0
              • raymalifalitiko
                raymalifalitiko @aha_1980 last edited by

                @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 Reply Quote 0
                • K
                  kuzulis Qt Champions 2020 @raymalifalitiko last edited by 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)?

                  raymalifalitiko 1 Reply Last reply Reply Quote 1
                  • raymalifalitiko
                    raymalifalitiko @kuzulis last edited by raymalifalitiko

                    @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 Reply Quote 0
                    • K
                      kuzulis Qt Champions 2020 last edited by 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.

                      raymalifalitiko 1 Reply Last reply Reply Quote 3
                      • raymalifalitiko
                        raymalifalitiko @kuzulis last edited by

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

                        K 1 Reply Last reply Reply Quote 0
                        • CKurdu
                          CKurdu last edited by

                          @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 Reply Quote 0
                          • K
                            kuzulis Qt Champions 2020 @raymalifalitiko last edited by

                            @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 Reply Quote 0
                            • raymalifalitiko
                              raymalifalitiko last edited by

                              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 Reply Quote 1
                              • First post
                                Last post