Private Sub LoadComms(Combo As ComboBox, Optional Default As Byte, Optional NotReload As Boolean)
Dim N As Byte, nIndex As Byte, IniTime As Double, Buffer As String
If NotReload = False Then
Combo.Clear
List2.Clear
List2.AddItem "Puertos disponibles:"
nIndex = 0
For N = 1 To 16
On Local Error Resume Next
Buffer = ""
MSComm1.CommPort = N
If MSComm1.PortOpen = False Then
MSComm1.PortOpen = True
If Err Then
Err.Clear
Else
MSComm1.Output = "ATV1Q0" & Chr$(13)
If Err Then
Combo.AddItem "Puerto serie " & N
Combo.ItemData(Combo.NewIndex) = N
If Default = N Then nIndex = Combo.NewIndex
List2.AddItem "Puerto serie " & N
Err.Clear
Else
IniTime = Timer
Do
Buffer = Buffer & MSComm1.Input
If IniTime + 3 < Timer Then
Combo.AddItem "Puerto serie " & N
Combo.ItemData(Combo.NewIndex) = N
If Default = N Then nIndex = Combo.NewIndex
List2.AddItem "Puerto serie " & N
Exit Do
End If
If InStr(Buffer, "OK" & vbCrLf) Then
Combo.AddItem "Modem en com " & N
Combo.ItemData(Combo.NewIndex) = N
If Default = N Then nIndex = Combo.NewIndex
List2.AddItem "Modem en com " & N
Exit Do
End If
Loop
End If
End If
MSComm1.PortOpen = False
End If
Next
Else
If Combo.ListCount > 0 Then
For N = 0 To Combo.ListCount - 1
If Combo.ItemData(N) = Default Then
nIndex = N
End If
Next
End If
End If
If Combo.ListCount > 0 Then
Combo.ListIndex = nIndex
End If
End Sub