Comm Ports

S

Steve

Hi All and seasons greetings.

Is there an easy way of getting a list of current Comm ports on a machine?
I suspect that most machines these days have 1 and 2, but there could be
others and I would like to get a list of them to offer the end user.

Many thanks,
Steve.
 
D

Dick Grier

Hi,

You can use WMI, which will report which serial ports are installed (but,
the System.Management wrapper doesn't seem to work for anything other than
installed modems -- I have example code in my book). Or, you can simply
open each possible port in turn. If the port opens it is available, and
(usually) if there is an error, the error return will allow you to determine
if some other program is using the port.

The System.IO.Ports.GetPortNames method in Visual Studio 2005 has this
"built-in."

Dick

--
Richard Grier (Microsoft Visual Basic MVP)

See www.hardandsoftware.net for contact information.

Author of Visual Basic Programmer's Guide to Serial Communications, 4th
Edition ISBN 1-890422-28-2 (391 pages) published July 2004. See
www.mabry.com/vbpgser4 to order.
 
J

Jay Taplin

Here's the code (*borrowed* from Microsoft):

Private Sub DisplaySerialPortNames()
Dim sp As System.Collections.ObjectModel.ReadOnlyCollection(Of
String)

For Each sp As String In My.Computer.Ports.SerialPortNames
System.Console.WriteLine(sp)
Next
End Sub


For further info, check out Microsoft's site:

http://msdn2.microsoft.com/library/9wahf8t8.aspx
 
J

Jay Taplin

This is probably beside the point, but I really have needed to vent about
this for about three months... the new Dell systems are not shipping with
COM or keyboard ports any more, unless if you explicitely request the
adapter for an extra $15.00. Apparently the world no longer has need for
COM ports.

Jay Taplin, MCP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

USB Com ports 6
Comm Ports 5
COMM Ports 1
HELP Unable to set COMM Ports 1 & 2, New PCI Card 7
Post my named ranges in column A 10
SerialPort.GetPortNames with Friendly Names 4
Com ports 2
Serial Port Assignment 2

Top