WillemM
February 7th, 2003, 11:24 AM
How can I enumerate the comports in VB.NET ?
I have made a modified comport driver for an Atmel AVR 4414 controllerboard connected to my PC and now I want to enumerate my comports to see what ports I have.
Iouri
February 7th, 2003, 02:02 PM
Private m_CommPort As New Rs232()
' This subroutine checks for available ports on the local machine. It does
' this by attempting to open ports 1 through 4.
Private Sub btnCheckForPorts_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCheckForPorts.Click
' Check for Availability of each of the 4 Comm Ports, and
' place a check in the list box items that have openable ports.
Dim i As Integer
For i = 1 To 4
If IsPortAvailable(i) Then
'do something
Else
'do something
End If
Next
End Sub
Private Function IsPortAvailable(ByVal ComPort As Integer) As Boolean
Try
m_CommPort.Open(ComPort, 115200, 8, Rs232.DataParity.Parity_None, _
Rs232.DataStopBit.StopBit_1, 4096)
' If it makes it to here, then the Comm Port is available.
m_CommPort.Close()
Return True
Catch
' If it gets here, then the attempt to open the Comm Port
' was unsuccessful.
Return False
End Try
End Function