Embedded Developer. the question is how to get rid of the malfunctioning opening of the serial port?

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,    // exclusive access
                          NULL,    // no security
                          OPEN_EXISTING,
                          FILE_FLAG_OVERLAPPED,    // overlapped I/O
                          NULL); // null template

any suggestions would be greatly appreciated

thank!

+3
3

? - - , .

, , , CreateFile() - , , .

+1

USB. .

+2

: WinCE, , , , "Blue Screen of Death" .

: , COM-?

You are requesting exclusive access. If anyone else has this, I expect the system to hang your task until the other guy releases the port.

0
source

Source: https://habr.com/ru/post/1746588/


All Articles