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.2k 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.
  • Christian EhrlicherC Online
    Christian EhrlicherC Online
    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 Online
        Christian EhrlicherC Online
        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 Online
            Christian EhrlicherC Online
            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 Online
                      Christian EhrlicherC Online
                      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
                      • Christian EhrlicherC Christian Ehrlicher

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

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

                        @Christian-Ehrlicher you are right but there isn't a call ".utf16()" in QByteArray class so I've replaced with a mistake.

                        Now the CreateFile with L"COM5" works. I don't get any error.

                        Christian EhrlicherC 1 Reply Last reply
                        0
                        • A addebito

                          @Christian-Ehrlicher you are right but there isn't a call ".utf16()" in QByteArray class so I've replaced with a mistake.

                          Now the CreateFile with L"COM5" works. I don't get any error.

                          Christian EhrlicherC Online
                          Christian EhrlicherC Online
                          Christian Ehrlicher
                          Lifetime Qt Champion
                          wrote on last edited by
                          #24

                          @addebito said in QSerialPort open error code 10:

                          QByteArray

                          Because it should be QString :)

                          Ok, then you have to debug by yourself, don't see what should go wrong within QSerialPort code nor can I test it locally.

                          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:

                            QByteArray

                            Because it should be QString :)

                            Ok, then you have to debug by yourself, don't see what should go wrong within QSerialPort code nor can I test it locally.

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

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

                            Ok, then you have to debug by yourself, don't see what should go wrong within QSerialPort code nor can I test it locally.

                            Yes but is not as easy as I thought.
                            I've run the maintenance QT software and I've check if the source was installed.

                            60e27300-e95c-4640-8d1c-b0a0236db1a3-immagine.png

                            I've created a simple demo project and added this lines inside the .pro

                            include(C:/Qt/5.14.2/Src/qtserialport/src/serialport/serialport-lib.pri)
                            

                            I have to add also these lines to resolve some issues

                            INCLUDEPATH += "C:/Qt/5.14.2/Src/qtbase/include/QtCore/5.14.2/QtCore"
                            INCLUDEPATH += "C:/Qt/5.14.2/Src/qtbase/include/QtCore/5.14.2"
                            INCLUDEPATH += "C:/Qt/5.14.2/msvc2017_64/include/QtCore/5.14.2"
                            

                            But now, when I compile I get this error:

                            38197876-cda2-4183-8712-84ff8cd559d2-immagine.png

                            definition of dllimport static data member not allowed

                            I think there is something wrong in my approach...
                            How should i do to debug QSerialPort class?
                            thank you for your time and your patience.

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

                              I don't understand why you try to compile QSerialPort by yourself. Install the debug symbols and sources, compile your app with debug informations, add a breakpoint on QSP::open() call and step into the call.

                              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
                              1
                              • Christian EhrlicherC Christian Ehrlicher

                                I don't understand why you try to compile QSerialPort by yourself. Install the debug symbols and sources, compile your app with debug informations, add a breakpoint on QSP::open() call and step into the call.

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

                                @Christian-Ehrlicher what you means with "Install the debug symbols and sources"?

                                I'm in debug with a breakpoint but if try to step into by F11...

                                d7196e67-9508-42a5-a240-0ec3910a5d33-immagine.png

                                b2c95cad-6693-42e3-a10a-da1530295797-immagine.png

                                KroMignonK 1 Reply Last reply
                                0
                                • A addebito

                                  @Christian-Ehrlicher what you means with "Install the debug symbols and sources"?

                                  I'm in debug with a breakpoint but if try to step into by F11...

                                  d7196e67-9508-42a5-a240-0ec3910a5d33-immagine.png

                                  b2c95cad-6693-42e3-a10a-da1530295797-immagine.png

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

                                  @addebito said in QSerialPort open error code 10:

                                  what you means with "Install the debug symbols and sources"?

                                  With Maintenance Tool, select "Sources" and "Qt Debug Information Files" for the select Qt Version:
                                  3ca5c8cb-9646-4d2a-a8c7-bc957ad0ebda-image.png

                                  Then build your project in "Debug" and start debugging.

                                  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:

                                    what you means with "Install the debug symbols and sources"?

                                    With Maintenance Tool, select "Sources" and "Qt Debug Information Files" for the select Qt Version:
                                    3ca5c8cb-9646-4d2a-a8c7-bc957ad0ebda-image.png

                                    Then build your project in "Debug" and start debugging.

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

                                    @KroMignon I've already installed but I don't see anything when I step into...
                                    I see only the debugger on line 118 (qflags.h) and after F11 again the debugger return on my mainwindow.cpp.

                                    a95dbbc9-6205-48f1-90f4-0f9cb11f83b1-immagine.png

                                    J.HilkJ Christian EhrlicherC 2 Replies Last reply
                                    0
                                    • A addebito

                                      @KroMignon I've already installed but I don't see anything when I step into...
                                      I see only the debugger on line 118 (qflags.h) and after F11 again the debugger return on my mainwindow.cpp.

                                      a95dbbc9-6205-48f1-90f4-0f9cb11f83b1-immagine.png

                                      J.HilkJ Offline
                                      J.HilkJ Offline
                                      J.Hilk
                                      Moderators
                                      wrote on last edited by
                                      #30

                                      @addebito
                                      did you add the sources inside QtCreator ? In the Debugger section

                                      ba3478a3-4772-421f-8c3d-9e8d7d9a717b-image.png


                                      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                                      Q: What's that?
                                      A: It's blue light.
                                      Q: What does it do?
                                      A: It turns blue.

                                      A 1 Reply Last reply
                                      0
                                      • A addebito

                                        @KroMignon I've already installed but I don't see anything when I step into...
                                        I see only the debugger on line 118 (qflags.h) and after F11 again the debugger return on my mainwindow.cpp.

                                        a95dbbc9-6205-48f1-90f4-0f9cb11f83b1-immagine.png

                                        Christian EhrlicherC Online
                                        Christian EhrlicherC Online
                                        Christian Ehrlicher
                                        Lifetime Qt Champion
                                        wrote on last edited by
                                        #31

                                        @addebito said in QSerialPort open error code 10:

                                        I see only the debugger on line 118 (qflags.h) and after F11 again the debugger return on my mainwindow.cpp.

                                        That's correct since first the flags ctor is called, then hit F11 again to step into the function call.

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

                                        1 Reply Last reply
                                        0
                                        • J.HilkJ J.Hilk

                                          @addebito
                                          did you add the sources inside QtCreator ? In the Debugger section

                                          ba3478a3-4772-421f-8c3d-9e8d7d9a717b-image.png

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

                                          @J-Hilk Thank you. Now I can step into.

                                          Now I found the line when the class call "return false"

                                          45d0652c-96b3-43f6-8962-92b606046882-immagine.png

                                          d3a5f4c4-94a2-4d1e-b958-2bc603f74529-immagine.png

                                          92c63d68-d6d6-4c30-af72-dae2dd900a31-immagine.png

                                          SetCommState return 87

                                          1 Reply Last reply
                                          0

                                          • Login

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