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

Posted on 2005-05-12
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.

Question by:Xircon
    LVL 8

    Accepted Solution

    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. ["CreateFile"]

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


    Author Comment

    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?
    LVL 6

    Assisted Solution

    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
    LVL 6

    Expert Comment

    Both corey and me made good suggestions here, I suggest a split.
    LVL 3

    Expert Comment

    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.

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    Join & Write a Comment

    If you have ever found yourself doing a repetitive action with the mouse and keyboard, and if you have even a little programming experience, there is a good chance that you can use a text editor to whip together a sort of macro to automate the proce…
    This article describes a technique for converting RTF (Rich Text Format) data to HTML and provides C++ source that does it all in just a few lines of code. Although RTF is coming to be considered a "legacy" format, it is still in common use... po…
    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.…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    731 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

    17 Experts available now in Live!

    Get 1:1 Help Now