Serial communication

krsh24

Active member
Joined
Sep 16, 2006
Messages
25
Programming Experience
3-5
How to i get the list of Available COM ports in VS.NET2003, VS.NET2005 supports this. any ideas plz share
 
As far as I know there is no 100% certain way to know what ports are available. The reason for this is that no all applications keep the port open when it is in use, there for you may have a connected device with a closed port. The code below will show you how to find all serial ports on your system, under the for each section, I showed how to check if the port is open, but like I stated this will not always be 100%


Imports System
Imports System.IO.Ports



Module SerialPortExample

Sub Main()
' Get a list of serial port names.
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
'whatever
end if
Next port

End Sub
End Module
 
This method is new in the .NET Framework version 2.0.

I know in plain vb there was a class called my.COmputer.Ports, you may want to try and see what the workaround is for .net. Everything I can find only relates to 2.0
 
Back
Top