List available com ports

jon.Haigh

New member
Joined
Oct 17, 2011
Messages
2
Programming Experience
Beginner
Hello

I am very new to .net and I am trying to figure out the best way to get a list of all of the currently available com ports. I have tried some code I found on the forum and it isn't working.

Dim ports As String() = SerialPort.GetPortNames()




Dim port As String
Dim x As SerialPort
For Each port In ports
x = port
If x.IsOpen Then
MessageBox.Show("hello")




End If
Next port

it says that the port string cannot be saved to x

Any ideas as to how I can correct this or do it better. Thanks!
 
You know that each 'port' in 'ports' string array is the string name, is is not a SerialPort object.
So how you can get a SerialPort object by its string name? Yes, you go to documentation and find that you can use one of the constructors: SerialPort Constructor (System.IO.Ports)
 
Thank you for the help. I corrected the code and it is working by showing me the com's of all my serial ports. Why doesn't it show USB ports though? shouldn't it? If not what else do I need to do? Thanks
 
USB ports are not serial ports. For USB you probably need a third party library.
 
Back
Top