[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


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

Posted on 2009-04-24
Medium Priority
Last Modified: 2013-12-03
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.
Question by:NetSoftDS
  • 2
  • 2

Expert Comment

ID: 24241174
wouldn't it be possible for you close the port with a set value, and re-open and see whether the same value exists ?

Author Comment

ID: 24246502
Hi ahalya,

I'm interested in what happens with the actual voltage on the pins.
LVL 49

Accepted Solution

DanRollins earned 2000 total points
ID: 24393979
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.

Author Comment

ID: 24461775
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.
LVL 49

Expert Comment

ID: 24478174
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

Featured Post

[Video] Oticon Case Study

Open office environments can create the dynamics for innovation, but they also bring some challenges. With over 1,000 employees in an open office, Oticon needed a solution that would preserve the environment while mitigating disruptive background noises.

Watch how they did it.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Make the most of your online learning experience.
Backups and Disaster RecoveryIn this post, we’ll look at strategies for backups and disaster recovery.
Introduction to Processes
Loops Section Overview

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question