03-04-2011 12:57 AM
Hi out there,
accidentally I noticed that OpenComConfig opens an already opened port twice.
I'm using LabWindows CVI 2009 (9.1.0)
In my Application I open a serial port with
iStatus = OpenComConfig (iComPort, "", 19200, 0, 8, 1, 512, 0); with iComPort = 1
OpenComConfig returns 0 as expected.
From a panel callback there is a second
iStatus = OpenComConfig (iComPort, "", 19200, 0, 8, 1, 512, 0); with iComPort = 1
Again OpenComConfig returns 0! I expected an error because the port is already open!
Is that the intended behavior of OpenComConfig ?
thx in advance
ah
03-04-2011 01:08 AM
everything seems to be fine; official help says:
If the specified port is already open, OpenComConfig closes the port and then opens it again.
03-04-2011 01:30 PM - edited 03-04-2011 01:33 PM
Wolfgang has it right - I like treating opening an already open com port as an error, but to do so I use a static variable to retain the com port open / closed state, for this very reason, if you reopen it with OpenComConfig there's no error.
If the com port has been opened by another process however, you do get an error. I think the com port is a process resource, not a thread resource, so if you reopen from a different thread in your process you get no error.