CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jul 2002
    Location
    .NET 2.0/.NET 3.0/.NET 3.5 VS2005/VS2008
    Posts
    284

    Enumerating comports

    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.
    WM.

    What about weapons of mass construction?

  2. #2
    Join Date
    May 2000
    Location
    New York, NY, USA
    Posts
    2,878
    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
    Iouri Boutchkine
    [email protected]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured