-
-
Notifications
You must be signed in to change notification settings - Fork 123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SetCommState
return False but GetLastError
return 0 (Success). And when used RegOpenKeyEx
, SetCommState
will fail.
#925
Comments
It's not fixed yet because it's still blocked on dart-lang/sdk#38832.
You can do that by calling the relevant APIs in C, C++, or Rust.
After running So, I modified the code you provided as follows: void testOpenPort(String portName) {
- final dcb = calloc<DCB>();
+ final dcb = calloc<DCB>()..ref.DCBlength = sizeOf<DCB>();
var handler = CreateFile(
TEXT('\\\\.\\$portName'),
GENERIC_ACCESS_RIGHTS.GENERIC_READ | GENERIC_ACCESS_RIGHTS.GENERIC_WRITE,
0,
nullptr,
FILE_CREATION_DISPOSITION.OPEN_EXISTING,
FILE_FLAGS_AND_ATTRIBUTES.FILE_FLAG_OVERLAPPED,
NULL);
if (handler == INVALID_HANDLE_VALUE) {
final lastError = GetLastError();
if (lastError == WIN32_ERROR.ERROR_FILE_NOT_FOUND) {
throw Exception("not available");
} else {
throw Exception('Open port failed, win32 error code is $lastError');
}
}
+ // Initialize the DCB structure with current settings
+ if (GetCommState(handler, dcb) == FALSE) {
+ CloseHandle(handler);
+ free(dcb);
+ throw Exception('GetCommState failed');
+ }
if (SetCommState(handler, dcb) == FALSE) {
throw Exception(
'SetCommState error, win32 error code is ${GetLastError()}');
} else {
PurgeComm(handler,
PURGE_COMM_FLAGS.PURGE_RXCLEAR | PURGE_COMM_FLAGS.PURGE_TXCLEAR);
}
} With these changes, the call to EDIT: I noticed we already have an example in the repo: serial.dart |
@halildurmus Thanks for your response! After call But it's really weird. I can run it without any |
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including a minimal reproduction of the issue. |
Description
SetCommState(handler, dcb) == FALSE
, ButGetLastError
give me 0. 0 means ERROR_SUCCESS. WhySetCommState
returns false butGetLastError()
says it is successful. IsGetLastError()
doesn't work #384 not fixed yet? How can I get real error code for debug it?But I found that if I use
RegOpenKeyEx
function, then I cannot useSetCommState
function with any handle which was created byCreateFile
function. My package issues 38The console app dart test code is here:
projects files
register_open_close_test.zip
Steps to reproduce
bin/register_open_close_test.dart
Expected behavior
GetLastError
should not be0
when functions return FALSE.SetCommState
should successEnvironment
Windows 11, 23H2
Screenshots (optional)
No response
Additional context (optional)
No response
The text was updated successfully, but these errors were encountered: