Results 1 to 2 of 2

Thread: COM auto detect ???

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jul 1999
    Location
    St-Élie d'Orford, Quebec, Canada
    Posts
    133
    Hi all,

    how can I have a list of all COMs ( communication ports ) available on a PC. Like I call the function and it returns
    something like an array of available COMs 1, 2, 5, 9.


    Thanks...

  2. #2
    Hyperactive Member
    Join Date
    Mar 2000
    Location
    Boulder, Colorado, USA
    Posts
    325
    You'll want to do something like this:

    Code:
    Public Sub SenseCOMPorts(ByRef com_list() As Integer)
      
      On Error Resume Next
      
      Dim i     As Integer
      Dim l_cnt As Integer
      
      Erase com_list
      l_cnt = -1
    
      '' check ports 1 - 16
      For i = 1 To 16 Step 1
        vbCOM.CommPort = i    '' set the port #
        vbCOM.PortOpen = True '' try to open the port
        
        '' add it to the list if it is open
        If (vbCOM.PortOpen) Then
          l_cnt = l_cnt + 1
          ReDim Preserve com_list(l_cnt) As Integer
          com_list(l_cnt) = i
        End if
        
        vbCOM.PortOpen = False '' close the port
      Next i
      
    End Sub
    -Shickadance

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