怎样在vb中自动检测到可用串口号
时间:10-02
整理:3721RD
点击:
单片机的串口与VB通信,怎样在vb中自动检测到可用串口号,比如我的电脑串口号是com6那么一上电通信就自动选择com6?
Private Sub Form_Load()
On Error GoTo Handle_Error
For i = 1 To 16
MSComm1.CommPort = i
MSComm1.PortOpen = True
'If Err.Number = comPortInvalid Then
' Print "Error"
'Else
Combo1.AddItem "COM" & i
'End If
MSComm1.PortOpen = False
Next i
Handle_Error: Print "Error"
End Sub
试试这样行不行~