串口通讯控件MSCOMM,我要自动判断设备是接那个口一般怎么处理
我现在是循环打开com1,com2,com3,com4这样,打开看是不是出错,on error捕获,不过不太正常,想问问大家是怎么处理这类问题的.
[解决办法]
关注!
[解决办法]
top
[解决办法]
我正在做一个视频的,我一般都用com1.
[解决办法]
串口本身,无论接没接设备,貌似都是可以成功打开的吧......?
如果没记错,真是这样....那只能通过与设备进行交流得到设备连接状态了
你可以找一个指令,发到串口
然后看看有没有正确的返回值....
[解决办法]
Option Explicit
Dim a As Integer
Private Sub Command1_Click()
On Error GoTo uerror
For a = 1 To 4
MSComm1(a).CommPort = a
MSComm1(a).PortOpen = True
Print "可用Com号= "; a
Next
Exit Sub
uerror:
Print "出错Com号= "; a
[解决办法]
笔误,修改:
Private Sub Command1_Click()
On Error GoTo uerror
For a = 1 To 4
MSComm1.CommPort = a
MSComm1.PortOpen = True
Print "可用Com号= "; a
MSComm1.PortOpen = False
Next
Exit Sub
uerror:
Print "出错Com号= "; a
End Sub
[解决办法]
Private Sub Command1_Click()
On Error GoTo uerror
For a = 1 To 4
MSComm1.CommPort = a
MSComm1.PortOpen = True
Print "可用Com号= "; a
MSComm1.PortOpen = False
Next
Exit Sub
uerror:
Print "出错Com号= "; a
End Sub