What Happens to COM Port Outputs When COM handle is Closed?

When I use the Windows API call CloseHandle() to close a handle to a Serial Port previously opened with a call to CreateFile(), what happens to the COM Port output signal levels?

Do they remain unchanged, (from level set when the port was open), or do they change to a default state, or are they undefined?

Note: For the purposes of this discussion assume that I am using the EscapeCommFunction() function to set signal levels.
Who is Participating?
DanRollinsConnect With a Mentor Commented:
As best as I can tell, the physical state of the serial port's pins are undefined after CloseHandle.  The reasoning would be this:  There is no software access at all to the device until a handle has been opened to it.  The open operation would initialize to a known state.  Therefore, since it can't be programmatically accessed, there is no need to know its state and no way to set its state.
I think, therefore, that the state upon closure would depend on the whims of the writers of the device driver.  It's possible that there are standards that such programmers follow, but that is no guarantee that those standards were followed.
You could go the pragmatic route:  
Just test the pins yourself.  If you get consistent results across a variety of platforms, then you might assume that those results will be in effect for most serial port drivers.
wouldn't it be possible for you close the port with a set value, and re-open and see whether the same value exists ?
NetSoftDSAuthor Commented:
Hi ahalya,

I'm interested in what happens with the actual voltage on the pins.
NetSoftDSAuthor Commented:
Thanks for your Reply Dan,

I guess that was what I suspected too, but I was seeking a definitive answer one way or the other.

Personally, I think its a little dangerous not to leave the pins in some kind of defined state after releasing the device handle. The only way to ensure levels would then be to never release the handle!

I think I will leave this question open a little longer and see if anyone else can give a definite answer.
OK. Fine by me.
One possible source for additional inormation would be to see what the example sample serial device driver does when the handle closes.

Windows Server 2003 DDK
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.