?
Solved

Check is com port is open

Posted on 2004-09-15
5
Medium Priority
?
346 Views
Last Modified: 2013-11-20
I'm writing a program that needs to check is the user has the com port open. Is there any way to check if it is open and not disrupt the com port if it is?
0
Comment
Question by:greg_100
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 12064517
Just call 'CreateFile()' on the COM port in question - if it is in use, you'll get ERROR_ACCESS_DENIED
0
 

Author Comment

by:greg_100
ID: 12065003
Do you have an example of how to do this?
0
 
LVL 86

Accepted Solution

by:
jkr earned 500 total points
ID: 12065094
Well, you could just use

    HANDLE hPort;

    hPort   =   CreateFile  (   "COM1",
                                GENERIC_READ | GENERIC_WRITE,
                                0,
                                0,
                                OPEN_EXISTING,
                                0,
                                0
                            );

    if  (   INVALID_HANDLE_VALUE ==  hPort)
        {

            if ( ERROR_ACCESS_DENIED == GetLastError ())
            {
                // port in use
            }
        }

0
 

Author Comment

by:greg_100
ID: 12068427
jkr,

That worked all I had to add was CloseHandle(hPort); to the end.
0
 
LVL 86

Expert Comment

by:jkr
ID: 12068733
Ooops, sorry, should have mentioned that...
0

Featured Post

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

In this article, you will read about the trends across the human resources departments for the upcoming year. Some of them include improving employee experience, adopting new technologies, using HR software to its full extent, and integrating artifi…
This article was originally published on Monitis Blog, you can check it here . If you have responsibility for software in production, I bet you’d like to know more about it. I don’t mean that you’d like an extra peek into the bowels of the sourc…
XMind Plus helps organize all details/aspects of any project from large to small in an orderly and concise manner. If you are working on a complex project, use this micro tutorial to show you how to make a basic flow chart. The software is free when…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

762 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