Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Detecting available serial ports

Status
Not open for further replies.

Motor11

Technical User
Jul 30, 2002
60
US
I typically use the MSCOMM control for my serial communication. Since my company (offshore surveying) often uses many serial devices into or out of a single computer, the 16-port limitation of this control has always be inconvenient, but I have managed to live with it.

Now, I have purchased an activeX control that lets me create virtual comm ports. This control is very slick and I can communicate with our survey software without any cabling whatsoever. It is easy to create comm ports with this control and my virtual ports are not limited to Comm1 through 16, yahoo!!

Normally, I use the mscomm control to check which ports are available (see code snippet below). This works really well, but I can't see anything above Comm 16. I would like to check the registry for existing Comm ports before I create a virtual comm port with my snazy new control. It wouldn't do to try to create a port that already exists. Does anyone have an idea of how to do this?

Here is the code that checks the first 16 ports with the MSComm control. Note that this particular code adds the comm port (if available) to the listbox, lisports(0).


Code:
    addthisport = True
    On Error GoTo set_port_not_avail_flag
        For i = 1 To 18
            Portcheck.commport = i
            Portcheck.PortOpen = True
        If addthisport Then 'port is avail
                lisPorts(0).AddItem ("COM " + Trim(Str(i)))
        End If
            Portcheck.PortOpen = False
            addthisport = True
        Next i
        lisPorts(0).ListIndex = 0
    Exit Function
set_port_not_avail_flag:
    addthisport = False
    Resume Next
 

First, manually create a virtual comm port with your snazy new control that you know is available, and then check how that shows up in the registry or what it does that you can look for. Then you can right the code to look for whatever it is doing.

You might also just email the vendor of your control and ask them how you can programmatically check for the virtual comm ports it creates.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top