Under WindowsCE, C++ project, I’m trying to work with devices connected via both “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 never returns and the system goes into some non-responsive state and has to be eventually rebooted. I need to open the ports from the main thread. The question is – how can I make it happen in a controlled way??
this is the opening code snippet:
std::ostringstream device_name;
device_name << "\\\\.\\COM" << port;
m_port = ::CreateFile(device_name.str().c_str(),
GENERIC_READ | GENERIC_WRITE,
0, // exclusive access
NULL, // no security
OPEN_EXISTING,
FILE_FLAG_OVERLAPPED, // overlapped I/O
NULL); // null template
any suggestions would be greatly appreciated
thanks!
Why not perform the open in another thread? There’s no reason to do anything else in that thread – just open the port and you can use the handle for the opened port in any other thread in your process.
However, I’m not sure what’s so screwed up that your
CreateFile()call seems to hang – I wonder if this happens even on another thread whether things will still be stable in your application.