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

Posted on 2009-04-24
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
    LVL 7

    Expert Comment

    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

    Hi ahalya,

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

    Accepted Solution

    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

    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

    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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
    In the modern office, employees tend to move around the workplace a lot more freely. Conferences, collaborative groups, flexible seating and working from home require a new level of mobility. Technology has not only changed the behavior and the expe…
    Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
    In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

    759 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

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now