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. QSerialPort open error code 10
Forum Updated to NodeBB v4.3 + New Features

QSerialPort open error code 10

Scheduled Pinned Locked Moved Solved General and Desktop
54 Posts 8 Posters 12.0k Views 1 Watching
  • 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.
  • Pablo J. RoginaP Pablo J. Rogina

    @addebito said in QSerialPort open error code 10:

    qDebug() << QString("Can't open %1, error code %2").arg(m_portName).arg(m_serial->error()) << m_serial->errorString();

    could you please show the actual output of this statement?

    A Offline
    A Offline
    addebito
    wrote on last edited by
    #3

    Yes of course @Pablo-J-Rogina

    "Can't open COM11, error code 10" "Parametro non corretto."

    "Parametro non corretto" it's written in Italian language.
    Parameter isn't correct.

    KroMignonK 1 Reply Last reply
    0
    • A addebito

      Yes of course @Pablo-J-Rogina

      "Can't open COM11, error code 10" "Parametro non corretto."

      "Parametro non corretto" it's written in Italian language.
      Parameter isn't correct.

      KroMignonK Offline
      KroMignonK Offline
      KroMignon
      wrote on last edited by
      #4

      @addebito said in QSerialPort open error code 10:

      "Can't open COM11, error code 10"

      Error 10 is QSerialPort::UnsupportedOperationError, are you sure the SerialPort is not already opened/used by another process?

      It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

      A 1 Reply Last reply
      2
      • K Offline
        K Offline
        kuzulis
        Qt Champions 2020
        wrote on last edited by kuzulis
        #5

        @addebito said in QSerialPort open error code 10:

        UnsupportedOperationError

        It is:

            case ERROR_INVALID_PARAMETER:
                error.errorCode = QSerialPort::UnsupportedOperationError;
                break;
        

        Maybe it is QSP bug, but also maybe, it is a bug in the serial-port HW firmware (if you use own USB/Serial implementation, and, e.g. it does not handle some USB class-specific callbacks). E.g. such as 'overlapped' operations, the RTS/CTS pins support and do on.

        1 Reply Last reply
        1
        • KroMignonK KroMignon

          @addebito said in QSerialPort open error code 10:

          "Can't open COM11, error code 10"

          Error 10 is QSerialPort::UnsupportedOperationError, are you sure the SerialPort is not already opened/used by another process?

          A Offline
          A Offline
          addebito
          wrote on last edited by
          #6

          @KroMignon Yes of course, I've done some test and the result is the same.
          With hercules, I open the port and I can communicate without any problem.
          After that I close the port and close Hercules, run my QT program but doesn't open the port and give me the error 10.

          KroMignonK 1 Reply Last reply
          0
          • A addebito

            @KroMignon Yes of course, I've done some test and the result is the same.
            With hercules, I open the port and I can communicate without any problem.
            After that I close the port and close Hercules, run my QT program but doesn't open the port and give me the error 10.

            KroMignonK Offline
            KroMignonK Offline
            KroMignon
            wrote on last edited by
            #7

            @addebito said in QSerialPort open error code 10:

            After that I close the port and close Hercules, run my QT program but doesn't open the port and give me the error 10.

            I don't know if it is relevant, but did you check if serial port is detected by Qt?

                for(const auto &serialPortInfo : QSerialPortInfo::availablePorts())
                {
                    qDebug() << "find serial port: " << serialPortInfo.portName() << '"/" << serialPortInfo.description();
                }
            
            

            It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

            A 1 Reply Last reply
            1
            • KroMignonK KroMignon

              @addebito said in QSerialPort open error code 10:

              After that I close the port and close Hercules, run my QT program but doesn't open the port and give me the error 10.

              I don't know if it is relevant, but did you check if serial port is detected by Qt?

                  for(const auto &serialPortInfo : QSerialPortInfo::availablePorts())
                  {
                      qDebug() << "find serial port: " << serialPortInfo.portName() << '"/" << serialPortInfo.description();
                  }
              
              
              A Offline
              A Offline
              addebito
              wrote on last edited by
              #8

              @KroMignon I've tried now.

              find serial port: "COM5" / "Dispositivo seriale USB"

              "Dispositivo seriale USB" means "USB serial device"

              KroMignonK 1 Reply Last reply
              0
              • A addebito

                @KroMignon I've tried now.

                find serial port: "COM5" / "Dispositivo seriale USB"

                "Dispositivo seriale USB" means "USB serial device"

                KroMignonK Offline
                KroMignonK Offline
                KroMignon
                wrote on last edited by
                #9

                @addebito said in QSerialPort open error code 10:

                find serial port: "COM5" / "Dispositivo seriale USB"

                Maybe that is your problem: "COM5" != "COM11"
                Is it the same serial port?

                It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

                A 1 Reply Last reply
                1
                • KroMignonK KroMignon

                  @addebito said in QSerialPort open error code 10:

                  find serial port: "COM5" / "Dispositivo seriale USB"

                  Maybe that is your problem: "COM5" != "COM11"
                  Is it the same serial port?

                  A Offline
                  A Offline
                  addebito
                  wrote on last edited by addebito
                  #10

                  @KroMignon I'm sorry, yes during the test I have also try to change the port number but the result is the same.
                  Now I'm using the same port configured as COM5.
                  The computer is my laptop and there is only this com port.

                  KroMignonK 1 Reply Last reply
                  0
                  • A addebito

                    @KroMignon I'm sorry, yes during the test I have also try to change the port number but the result is the same.
                    Now I'm using the same port configured as COM5.
                    The computer is my laptop and there is only this com port.

                    KroMignonK Offline
                    KroMignonK Offline
                    KroMignon
                    wrote on last edited by
                    #11

                    @addebito said in QSerialPort open error code 10:

                    I'm sorry, yes during the test I have also try to change the port number but the result is the same.
                    Now I'm using the same port configured as COM5.

                    I am sorry, but I am not sure to understand you.
                    Do you still have same error, even when using serial port detected with QSerialPortInfo::availablePorts()?

                    It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

                    A 1 Reply Last reply
                    0
                    • KroMignonK KroMignon

                      @addebito said in QSerialPort open error code 10:

                      I'm sorry, yes during the test I have also try to change the port number but the result is the same.
                      Now I'm using the same port configured as COM5.

                      I am sorry, but I am not sure to understand you.
                      Do you still have same error, even when using serial port detected with QSerialPortInfo::availablePorts()?

                      A Offline
                      A Offline
                      addebito
                      wrote on last edited by
                      #12

                      Yes @KroMignon, I've the same error and I dont know how to resolve...

                      find serial port: "COM5" / "Dispositivo seriale USB"
                      "Can't open COM5, error code 10" "Parametro non corretto."

                      I can download the source of QSerialPort and try to debug when I open it.
                      It could help me to investigate the real problem?

                      1 Reply Last reply
                      0
                      • Christian EhrlicherC Offline
                        Christian EhrlicherC Offline
                        Christian Ehrlicher
                        Lifetime Qt Champion
                        wrote on last edited by
                        #13

                        Try to remove the setFoo() calls before open to see if it helps. If so re-add them until the error occurs again.

                        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                        Visit the Qt Academy at https://academy.qt.io/catalog

                        A 1 Reply Last reply
                        0
                        • Christian EhrlicherC Christian Ehrlicher

                          Try to remove the setFoo() calls before open to see if it helps. If so re-add them until the error occurs again.

                          A Offline
                          A Offline
                          addebito
                          wrote on last edited by
                          #14

                          Hi @Christian-Ehrlicher, what you means with setFoo() ?
                          Did you mean setFlowControl ?

                          I've try to remove it before open the com port but I get the same result.

                          "Can't open COM5, error code 10" "Parametro non corretto."

                          1 Reply Last reply
                          0
                          • Christian EhrlicherC Offline
                            Christian EhrlicherC Offline
                            Christian Ehrlicher
                            Lifetime Qt Champion
                            wrote on last edited by
                            #15

                            @addebito said in QSerialPort open error code 10:

                            Did you mean setFlowControl ?

                            all setXXX() - functions

                            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                            Visit the Qt Academy at https://academy.qt.io/catalog

                            A 1 Reply Last reply
                            0
                            • Christian EhrlicherC Christian Ehrlicher

                              @addebito said in QSerialPort open error code 10:

                              Did you mean setFlowControl ?

                              all setXXX() - functions

                              A Offline
                              A Offline
                              addebito
                              wrote on last edited by
                              #16

                              @Christian-Ehrlicher Nope, same error.

                                  for (const auto &serialPortInfo : QSerialPortInfo::availablePorts())
                                  {
                                      qDebug() << "find serial port: " << serialPortInfo.portName() << "/" << serialPortInfo.description();
                                  }
                              
                                  m_portName = "COM5";
                                  m_serial   = new QSerialPort();
                                  m_serial->setPortName(m_portName);
                                  //    m_serial->setBaudRate(QSerialPort::Baud115200);
                                  //    m_serial->setParity(QSerialPort::NoParity);
                                  //    m_serial->setStopBits(QSerialPort::OneStop);
                                  //    m_serial->setDataBits(QSerialPort::Data8);
                                  //    m_serial->setFlowControl(QSerialPort::NoFlowControl);
                              
                                  if (!m_serial->open(QIODevice::ReadWrite))
                                  {
                                      qDebug() << QString("Can't open %1, error code %2").arg(m_portName).arg(m_serial->error()) << m_serial->errorString();
                                      emit signalError(tr("Can't open %1, error code %2\n%3").arg(m_portName).arg(m_serial->error()).arg(m_serial->errorString()));
                                      return;
                                  }
                              

                              find serial port: "COM5" / "Dispositivo seriale USB"
                              "Can't open COM5, error code 10" "Parametro non corretto."

                              1 Reply Last reply
                              0
                              • Christian EhrlicherC Offline
                                Christian EhrlicherC Offline
                                Christian Ehrlicher
                                Lifetime Qt Champion
                                wrote on last edited by
                                #17

                                Ok, was just a guess... looks like you have to download the debug symbols and debug into QSerialPort.
                                Do you have maybe another USB-serial converter for testing?

                                Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                                Visit the Qt Academy at https://academy.qt.io/catalog

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

                                  You can try the following WinAPI code at first:

                                      QByteArray systemLocation = "COM5";
                                      DWORD desiredAccess = GENERIC_READ | GENERIC_WRITE;
                                  
                                      HANDLE handle = ::CreateFile(reinterpret_cast<const wchar_t*>(systemLocation.utf16()),
                                                                desiredAccess, 0, nullptr, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, nullptr);
                                      if (handle == INVALID_HANDLE_VALUE) {
                                          // OOPS
                                          const DWORD error = ::GetLastError();
                                          qDebug() << "ERROR:" << error;
                                      }
                                  

                                  ti see what happens.

                                  A 1 Reply Last reply
                                  3
                                  • K Offline
                                    K Offline
                                    kuzulis
                                    Qt Champions 2020
                                    wrote on last edited by
                                    #19

                                    I can download the source of QSerialPort and try to debug when I open it.
                                    It could help me to investigate the real problem?

                                    Yes, of course.

                                    1 Reply Last reply
                                    0
                                    • K kuzulis

                                      You can try the following WinAPI code at first:

                                          QByteArray systemLocation = "COM5";
                                          DWORD desiredAccess = GENERIC_READ | GENERIC_WRITE;
                                      
                                          HANDLE handle = ::CreateFile(reinterpret_cast<const wchar_t*>(systemLocation.utf16()),
                                                                    desiredAccess, 0, nullptr, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, nullptr);
                                          if (handle == INVALID_HANDLE_VALUE) {
                                              // OOPS
                                              const DWORD error = ::GetLastError();
                                              qDebug() << "ERROR:" << error;
                                          }
                                      

                                      ti see what happens.

                                      A Offline
                                      A Offline
                                      addebito
                                      wrote on last edited by
                                      #20

                                      @kuzulis I get the error 2.... file doesn't exist ??
                                      the error code 2 is really file not exixt ??

                                      Screenshot from Windows device manager:

                                      17ebc648-69aa-4e80-8854-e00d61ee7412-immagine.png

                                      This is the code.

                                          DWORD desiredAccess = GENERIC_READ | GENERIC_WRITE;
                                      
                                          HANDLE handle = ::CreateFile(reinterpret_cast<const wchar_t *>("COM5"), desiredAccess, 0, nullptr, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, nullptr);
                                          if (handle == INVALID_HANDLE_VALUE)
                                          {
                                              // OOPS
                                              const DWORD error = ::GetLastError();
                                              qDebug() << "ERROR:" << error;
                                          }
                                      
                                      1 Reply Last reply
                                      0
                                      • Christian EhrlicherC Christian Ehrlicher

                                        Ok, was just a guess... looks like you have to download the debug symbols and debug into QSerialPort.
                                        Do you have maybe another USB-serial converter for testing?

                                        A Offline
                                        A Offline
                                        addebito
                                        wrote on last edited by addebito
                                        #21

                                        @Christian-Ehrlicher said in QSerialPort open error code 10:

                                        Do you have maybe another USB-serial converter for testing?

                                        No, is not a USB serial converter but is a USB connected directly on the device/board.
                                        I can ask my customer to give me back the fisrt board (the one that I starting to work with).
                                        It could be the board or firmware yes.... but why with Hercules I can communicate without problems ??

                                        1 Reply Last reply
                                        0
                                        • Christian EhrlicherC Offline
                                          Christian EhrlicherC Offline
                                          Christian Ehrlicher
                                          Lifetime Qt Champion
                                          wrote on last edited by
                                          #22

                                          @addebito said in QSerialPort open error code 10:

                                          reinterpret_cast<const wchar_t *>("COM5")

                                          And this is wrong. Either use the solution from @kuzulis or pass a proper utf-16 encoded string: L"COM5"

                                          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                                          Visit the Qt Academy at https://academy.qt.io/catalog

                                          A 1 Reply Last reply
                                          3

                                          • Login

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