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...
Printable View
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...
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