Reopening the serial port fails if it is not closed properly with CloseHandle

I am working with a USB device in Windows that is seen as a virtual serial port. I can communicate with the device using the CreateFile and ReadFile functions, but in some cases my application does not call CloseHandle (when my application in case of development crashes). After that, all calls to CreateFile fail (ERROR_ACCESS_DENIED), and the only solution is to log into my computer again. Is there a way to forcefully close an open handle (or reopen) programmatically?

+2
source share
6 answers

This, of course, is not normal. Windows automatically closes all handles that remain open after the process completes. This should be a flaw in your USB device driver, although it's hard to figure out how it might go bad. Those that emulate serial ports are generally sad. Well, you can’t do anything, but you are hoping for a driver update from the manufacturer. Or a device from another manufacturer.

+2
source

I agree with both previous posts.

  • This is not a normal situation.
  • Usually disconnects the USB device.

This problem is due to glitches in the FTDI driver, which is responsible for implementing the virtual COM port. On the other hand, these "glitches" are associated with various malfunctions of USB devices. (Of course, this does not justify the FTDI driver).

, FTDI:

  • CloseHandle .
  • "" , . , . EXE ( ).

USB- . FTDI, , , " -", .

+2

, ? , ? , . ; , .

+1

, , - USB, USB- . (?) .

" Microsoft 27.03.2009 16:03 , . .NET.

- , , . , "

, . Microsoft Connect USB.

0

, Try catch CloseHandle catch. , , CloseHandle.

{  HANDLE hPort = NULL;  hPort = CreateFile (...);  // ...

} (...) {  if (hPort!= NULL)      CloseHandle (hPort); }

0

. Windows , .

-1

All Articles