Option Explicit
Dim a As Integer
Private Sub Form_Load()
MSComm1.Settings = "9600,n,8,1"
MSComm1.InputMode = comInputModeBinary '采用二进制传输
MSComm1.InBufferCount = 0 '清空接受缓冲区
MSComm1.OutBufferCount = 0 '清空传输缓冲区
MSComm1.RThreshold = 1 '产生MSComm事件
MSComm1.InBufferSize = 1024
Shape1.FillStyle = 0
OpenPortNum
End Sub
Private Sub OpenPortNum()
On Error GoTo uerror
For a = 1 To 16
MSComm1.CommPort = a
MSComm1.PortOpen = True
If MSComm1.PortOpen = True Then
Print "可用Com号= "a
MSComm1.PortOpen = False
End If
Next
Exit Sub
uerror:
Print "出错或占用Com号= "a
Resume Next
End Sub
如要探测某个COM口是否有数据输入则需在打开某个串口后,用OnComm事件来接收.
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)