QSerialPort open error code 10
-
@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.
-
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
-
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.2Any other suggestions?
-
@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 likeqt_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).
-
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.
-
@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.
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
- run my lapton on Linux partition and run the Terminal Example
- Restart the computer, run the Windows partition and run the Terminal Example
- Switch off/on the board, the Terminal example doesn't work.
- If I run Hercules... it's still working
-
@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.
-
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
- 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; }
-
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 theqtserialport
.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.
-
@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 :)
-
@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). :)
-
@kuzulis said in QSerialPort open error code 10:
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;
}
...Doesn't work. Look tha values on the right side... ?!?
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.
Do you know some good sniffer program that you have already used?
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?No, I'm using the standard windows usbser.sys
-
Maybe you can check if the dcb contains a difference when it works (so when it was first started on linux) and when not. Don't know if it helps though.
-
@Christian-Ehrlicher Thanks but I've already done when, in my previuos post I wrote "This is my last test for today...."
-
Even though I haven't solved it I'd like to give you a big thank you.
@Christian-Ehrlicher
@J-Hilk
@KroMignon
@kuzulis
@ollarch
@Pablo-J-RoginaI'll try to contact the board supplier to investigate if there was some fw changes.