lib60870
lib60870 copied to clipboard
windows open serial device fail
In windows, open serial device fail. The function CreateFile accept LPCWSTR type, in code pass device name (self->interfaceName) is a char* data type. serial_port_win32.c
self->comPort = CreateFile(self->interfaceName, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
if (self->comPort == INVALID_HANDLE_VALUE) {
self->lastError = SERIAL_PORT_ERROR_OPEN_FAILED;
return false;
}
I think this problem happens when the code is compilied with UNICODE defined. See also here: https://stackoverflow.com/questions/51462048/what-is-the-difference-between-createfile-and-createfilea
When you are using a string constant you can try to provide them like _T("COM8")
Thanks. The code it build without UNICODE.