Today I spent several hours hunting down a problem with opening a COM port. Basically the program opens a COM port, writes some bytes to it, reads an answer and closes it again. This determines whether the expected device is connected to the COM port or not.

Today I spent several hours hunting down a problem with opening a COM port. Basically the program opens a COM port, writes some bytes to it, reads an answer and closes it again. This determines whether the expected device is connected to the COM port or not.

If the answer is the expected one, so the device is connected and active, the detection loop exists (the COM port has been closed using CloseHandle).

Now the actual communication with the device starts. The first thing is does, is open the same COM port again. Which fails with the error code 5 (ERROR_ACCESS_DENIED). WTF?
http://blog.dummzeuch.de/2014/11/05/when-closehandle-does-not-close-the-handle/

Comments

  1. why not incorporate the detection loop into the use com port code after the com port open...i.e dont close then to have to re open...to get around the problem?

    ReplyDelete
  2. That would have solved that particular problem, yes, but also required to pass an open COM port object around which is a rather large change to an otherwise working program to fix a bug that only occurs in some very specific circumstances.

    ReplyDelete

Post a Comment