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

x
?
Solved

how to check if the modem on a comm port is opened or not used?

Posted on 2005-05-12
9
Medium Priority
?
1,313 Views
Last Modified: 2013-12-03
can anyone share a code that checks for modem activity?
say i have a modem on com3, the program would check
if com3 port is open, like when using the internet or when
sending fax.

thanks...
0
Comment
Question by:Xircon
5 Comments
 
LVL 8

Accepted Solution

by:
_corey_ earned 500 total points
ID: 14001098
The quickest way to see if a COM port is in use is to try and open it.  It will fail to open if another application has it open.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/fs/createfile.asp ["CreateFile"]

You can use the filename "COM1" through "COM9" or for higher numbers "\\.\com##" with OPEN_EXISTING.

corey
0
 

Author Comment

by:Xircon
ID: 14002660
thanks corey.  thats what i had in mind.

id like to make a program that records the length of usage of the com ports, so it would need to check the ports at regular intervals. is there any less intrusive way of doing this?
0
 
LVL 6

Assisted Solution

by:jarnsater
jarnsater earned 500 total points
ID: 14107443
I use the win32 API GetCommModemStatus to check the status of a COM port opened against a scanner. I assume you could use this in your scenario as well. Match the returned status value against MS_DSR_ON to see if it's active or not.

/ Jon
0
 
LVL 6

Expert Comment

by:jarnsater
ID: 14361153
Both corey and me made good suggestions here, I suggest a split.
0
 
LVL 3

Expert Comment

by:Diego Pazos
ID: 14503994
I'd go for jarnsater's approach.
The one suggested by corey could lead to other programs getting access denied to the port because your 'check' has it open.
0

Featured Post

Restore individual SQL databases with ease

Veeam Explorer for Microsoft SQL Server delivers an easy-to-use, wizard-driven interface for restoring your databases from a backup. No expert SQL background required. Web interface provides a complete view of all available SQL databases to simplify the recovery of lost database

Question has a verified solution.

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

This article shows how to make a Windows 7 gadget that extends its U/I with a flyout panel -- a window that pops out next to the gadget.  The example gadget shows several additional techniques:  How to automatically resize a gadget or flyout panel t…
This article surveys and compares options for encoding and decoding base64 data.  It includes source code in C++ as well as examples of how to use standard Windows API functions for these tasks. We'll look at the algorithms — how encoding and decodi…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Integration Management Part 2

834 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