As part of the WindowsCE, C ++ project, I am trying to work with devices connected via “real” serial ports and / or serial to USB wrappers (“virtual” serial ports); my problem is when I try to open the port, if something goes wrong, the function will never return, and the system goes into some kind of insensitive state and should eventually be rebooted. I need to open ports from the main thread. The question is, how can I do this in a controlled way? this is the opening piece of code:
std::ostringstream device_name;
device_name << "\\\\.\\COM" << port;
m_port = ::CreateFile(device_name.str().c_str(),
GENERIC_READ | GENERIC_WRITE,
0,
NULL,
OPEN_EXISTING,
FILE_FLAG_OVERLAPPED,
NULL);
any suggestions would be greatly appreciated
thank!