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
Servers for Qt installer are currently down

QSerialPort open error code 10

Scheduled Pinned Locked Moved Solved General and Desktop
54 Posts 8 Posters 11.1k 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 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 Offline
      Christian EhrlicherC Offline
      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 Offline
                Christian EhrlicherC Offline
                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
                  • J.HilkJ Offline
                    J.HilkJ Offline
                    J.Hilk
                    Moderators
                    wrote on last edited by
                    #33

                    Well, if I'm not mistaken, then thats the error code for an invalid parameter 🤷‍♂️

                    What Windows version do you use ? Is it up to date ? The windows Api changes regularly


                    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
                    • J.HilkJ J.Hilk

                      Well, if I'm not mistaken, then thats the error code for an invalid parameter 🤷‍♂️

                      What Windows version do you use ? Is it up to date ? The windows Api changes regularly

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

                      @J-Hilk

                      https://docs.microsoft.com/it-it/windows/win32/debug/system-error-codes--0-499-?redirectedfrom=MSDN

                      Yes, from msdn
                      87 The parameter is incorrect.

                      What kind of parameters ??
                      Ohh Windows...
                      I'm definitely being roasted.

                      Windows 10 home
                      Auto update activated
                      QT 5.14.2

                      Any other suggestions?

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

                        @addebito said in QSerialPort open error code 10:

                        Any other suggestions?

                        Build qtserialport from sources (just download the sources, open in QtCreator and re-build all targets, include examples). And then from the QtCreator run the terminal-example under the debugger, open your serial port and try to debug as usual.. Then, try to comments-out step-by-step the functions like qt_set_{common|baudrate...}, and then re-build qtserialport and try again.. And then you can look wich function brokes the work.

                        For this, you can temporary rename the qtserialportd.dll in your installed Qt path.. In this case will be used another dll compiled in qtserialport build directory (make sure that this directory is in `run environment' PATH of your project settings in QtCreator).

                        A 1 Reply Last reply
                        2
                        • K kuzulis

                          @addebito said in QSerialPort open error code 10:

                          Any other suggestions?

                          Build qtserialport from sources (just download the sources, open in QtCreator and re-build all targets, include examples). And then from the QtCreator run the terminal-example under the debugger, open your serial port and try to debug as usual.. Then, try to comments-out step-by-step the functions like qt_set_{common|baudrate...}, and then re-build qtserialport and try again.. And then you can look wich function brokes the work.

                          For this, you can temporary rename the qtserialportd.dll in your installed Qt path.. In this case will be used another dll compiled in qtserialport build directory (make sure that this directory is in `run environment' PATH of your project settings in QtCreator).

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

                          Thank you @kuzulis , I'll try.

                          I've done another test, same hardware and same computer but with Linux Ubuntu 20.04.1 LTS.
                          No problem, I can open the "ttyACM0" write and receive data.

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

                            Since you can already call CreateFile() simply go further and call GetCommState/SetCommState and set the parameters one by one according to what Qt does and see which one fails. Maybe first try to call SetCommState without modifying the DCB structure at all.

                            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
                            • A Offline
                              A Offline
                              addebito
                              wrote on last edited by
                              #38

                              @kuzulis I've try to recompile step by step and try with the qt_set_{...} commented-out but... nope I've commented all the 5 lines without good result.

                              87e5b56b-a1cc-4937-b6dc-4a700e593a3c-immagine.png

                              BUT ....unbelievable...
                              I've try more than one time.
                              If I run the terminal example under Linux, everything works fine, after that if I restart the computer without power off the board and run Windows instead Linux.... The terminal example works !!!
                              If I switch OFF and after, switch ON again the board the terminal example under Windows going back to fail !!

                              So, follow step by step my tests

                              1. run my lapton on Linux partition and run the Terminal Example

                              1af54b33-b8fe-465b-b7fb-baa84532412a-immagine.png

                              1. Restart the computer, run the Windows partition and run the Terminal Example

                              32adcec7-bdae-4484-a012-d137e5349aeb-immagine.png

                              1. Switch off/on the board, the Terminal example doesn't work.

                              97b3a833-9564-4b5f-bb6b-0d6ce2ee9758-immagine.png

                              1. If I run Hercules... it's still working

                              979cb9a3-4e04-4c4d-bf1f-aeaec3ca109c-immagine.png

                              1 Reply Last reply
                              0
                              • O Offline
                                O Offline
                                ollarch
                                wrote on last edited by
                                #39

                                Can you try to remove the USB device, plug it again and start your software?
                                If if fails, could you try to delete the COM controller from Windows devices and force Windows to search for new devices?

                                A 1 Reply Last reply
                                0
                                • O ollarch

                                  Can you try to remove the USB device, plug it again and start your software?
                                  If if fails, could you try to delete the COM controller from Windows devices and force Windows to search for new devices?

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

                                  @ollarch thank you for your suggestion but doesn't work

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

                                  • I've unistall the COM driver in Windows device manager.
                                  • Unplug the COM in the same USB.
                                  • Windows reinstall the drivers.
                                  • Run my application but doesn't works.

                                  I've tried the same procedure with another USB port.

                                  Now I'm trying the last @Christian-Ehrlicher suggestion.

                                  1 Reply Last reply
                                  0
                                  • A Offline
                                    A Offline
                                    addebito
                                    wrote on last edited by
                                    #41

                                    This is my last test for today....

                                    • I run the terminal example under Linux (it's works fine)
                                    • Restart the computer without unplug or switch off the board
                                    • Run hte new code to get the com state (GetCommState). Thanks @Christian-Ehrlicher
                                    • Print screen

                                    615df85b-bccd-430b-ac11-0ff1da60b37c-immagine.png

                                    • Call SetCommState with these parameters... works under Windows.
                                    • Power off the board
                                    • Power on the board
                                    • Run again my demo and get the com state as before.
                                    • Apart the usual settings like 9600 8 N 1.... I see that Linux set the port with the RTS Control Enable, and now is not set !!
                                    • So, I add this line of code
                                    dcb.fRtsControl = RTS_CONTROL_ENABLE;
                                    
                                    • Run again the demo without success....
                                      setCommState error: 87 "Parameter is not correct."

                                    This is the used code:

                                        DWORD desiredAccess = GENERIC_READ | GENERIC_WRITE;
                                    
                                        HANDLE handle = ::CreateFile(reinterpret_cast<const wchar_t *>(L"COM5"), desiredAccess, 0, nullptr, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, nullptr);
                                        if (handle == INVALID_HANDLE_VALUE)
                                        {
                                            // OOPS
                                            const DWORD error = ::GetLastError();
                                            qDebug() << "ERROR:" << error;
                                        }
                                    
                                        DCB dcb;
                                        int systemErrorCode = 0;
                                    
                                        // --------------------------------------------------
                                        // bool QSerialPortPrivate::getDcb(DCB *dcb)
                                        ::ZeroMemory(&dcb, sizeof(DCB));
                                        dcb.DCBlength = sizeof(DCB);
                                    
                                        if (!::GetCommState(handle, &dcb))
                                        {
                                            systemErrorCode = ::GetLastError();
                                            qDebug() << "GetCommState error:" << systemErrorCode << qt_error_string(systemErrorCode);
                                            return;
                                        }
                                    
                                        // --------------------------------------------------
                                        // static inline void qt_set_common_props(DCB *dcb)
                                        dcb.fBinary       = TRUE;
                                        dcb.fAbortOnError = FALSE;
                                        dcb.fNull         = FALSE;
                                        dcb.fErrorChar    = FALSE;
                                    
                                        if (dcb.fDtrControl == DTR_CONTROL_HANDSHAKE)
                                            dcb.fDtrControl = DTR_CONTROL_DISABLE;
                                    
                                        if (dcb.fRtsControl != RTS_CONTROL_HANDSHAKE)
                                            dcb.fRtsControl = RTS_CONTROL_DISABLE;
                                    
                                        // --------------------------------------------------
                                        // baud rate
                                        dcb.BaudRate = QSerialPort::Baud9600;
                                        /*
                                        if (!::SetCommState(handle, &dcb))
                                        {
                                            systemErrorCode = ::GetLastError();
                                            qDebug() << "BaudRate: setCommState error:" << systemErrorCode << qt_error_string(systemErrorCode);
                                            ::CloseHandle(handle);
                                            return;
                                        }
                                        */
                                    
                                        // --------------------------------------------------
                                        // byte size
                                        dcb.ByteSize = QSerialPort::Data8;
                                        /*
                                        if (!::SetCommState(handle, &dcb))
                                        {
                                            systemErrorCode = ::GetLastError();
                                            qDebug() << "ByteSize: setCommState error:" << systemErrorCode << qt_error_string(systemErrorCode);
                                            ::CloseHandle(handle);
                                            return;
                                        }
                                        */
                                    
                                        // --------------------------------------------------
                                        // parity
                                        dcb.Parity  = NOPARITY;
                                        dcb.fParity = FALSE;
                                        /*
                                        if (!::SetCommState(handle, &dcb))
                                        {
                                            systemErrorCode = ::GetLastError();
                                            qDebug() << "Parity: setCommState error:" << systemErrorCode << qt_error_string(systemErrorCode);
                                            ::CloseHandle(handle);
                                            return;
                                        }
                                        */
                                    
                                        // --------------------------------------------------
                                        // stopbit
                                        dcb.StopBits = ONESTOPBIT;
                                        /*
                                        if (!::SetCommState(handle, &dcb))
                                        {
                                            systemErrorCode = ::GetLastError();
                                            qDebug() << "StopBit: setCommState error:" << systemErrorCode << qt_error_string(systemErrorCode);
                                            ::CloseHandle(handle);
                                            return;
                                        }
                                        */
                                    
                                        // --------------------------------------------------
                                        // flow control
                                        dcb.fInX         = FALSE;
                                        dcb.fOutX        = FALSE;
                                        dcb.fOutxCtsFlow = FALSE;
                                        if (dcb.fRtsControl == RTS_CONTROL_HANDSHAKE)
                                            dcb.fRtsControl = RTS_CONTROL_DISABLE;
                                        //    switch (flowcontrol)
                                        //    {
                                        //        case QSerialPort::NoFlowControl:
                                        //            break;
                                        //        case QSerialPort::SoftwareControl:
                                        //            dcb.fInX  = TRUE;
                                        //            dcb.fOutX = TRUE;
                                        //            break;
                                        //        case QSerialPort::HardwareControl:
                                        //            dcb.fOutxCtsFlow = TRUE;
                                        //            dcb.fRtsControl  = RTS_CONTROL_HANDSHAKE;
                                        //            break;
                                        //        default:
                                        //            break;
                                        //    }
                                    
                                        dcb.fRtsControl = RTS_CONTROL_ENABLE;
                                        if (!::SetCommState(handle, &dcb))
                                        {
                                            systemErrorCode = ::GetLastError();
                                            qDebug() << "setCommState error:" << systemErrorCode << qt_error_string(systemErrorCode);
                                            ::CloseHandle(handle);
                                            return;
                                        }
                                    
                                    1 Reply Last reply
                                    0
                                    • K Offline
                                      K Offline
                                      kuzulis
                                      Qt Champions 2020
                                      wrote on last edited by kuzulis
                                      #42

                                      If this does not work when you did:

                                      ...
                                          if (!::GetCommState(handle, &dcb))
                                          {
                                              systemErrorCode = ::GetLastError();
                                              qDebug() << "GetCommState error:" << systemErrorCode << qt_error_string(systemErrorCode);
                                              return;
                                          }
                                      ...
                                      

                                      and then immediatelly:

                                      ...
                                          if (!::SetCommState(handle, &dcb))
                                          {
                                              systemErrorCode = ::GetLastError();
                                              qDebug() << "SetCommState error:" << systemErrorCode << qt_error_string(systemErrorCode);
                                              return;
                                          }
                                      ...
                                      

                                      then it is LOL.

                                      Then you can install the serial port sniffer application and to sniff the device I/O control call for the SetCommStat. To see, which parameters are passed with this call e.g using the hercules application, and to compare with the qtserialport.

                                      Most likelly, it is a bug in FW of your device (in USB CDC class implementation). Or, maybe it expect some specific DCB structure (some specific DCB flags).

                                      Question: Do you have the specific serial port driver for your device, or do you use the 'standard' usbser.sys driver from Windows?

                                      PS: On Linux there are different drivers implementation.

                                      A 1 Reply Last reply
                                      2
                                      • Christian EhrlicherC Offline
                                        Christian EhrlicherC Offline
                                        Christian Ehrlicher
                                        Lifetime Qt Champion
                                        wrote on last edited by
                                        #43

                                        @kuzulis said in QSerialPort open error code 10:

                                        then it is LOL.

                                        Correct, that was the reason why I asked him to try it out to see if it's a driver problem :)

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

                                        K 1 Reply Last reply
                                        0
                                        • Christian EhrlicherC Christian Ehrlicher

                                          @kuzulis said in QSerialPort open error code 10:

                                          then it is LOL.

                                          Correct, that was the reason why I asked him to try it out to see if it's a driver problem :)

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

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

                                          I asked him to try it out to see if it's a driver problem :)

                                          Most likelly, it is a problem in device FW, not in driver (because I assume that there are used the CDC ACM driver). :)

                                          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