1,451
社区成员
发帖
与我相关
我的任务
分享
Option Explicit
Dim yy As String
Private Sub Command1_Click()
MSComm1.CommPort = 3
MSComm1.Settings = "9600,n,8,1"
MSComm1.InBufferCount = 0
MSComm1.InputLen = 0
MSComm1.RThreshold = 14
MSComm1.InputMode = comInputModeBinary
MSComm1.PortOpen = True
End Sub
Private Sub Command2_Click()
MSComm1.PortOpen = False
End Sub
Private Sub MSComm1_OnComm()
Dim xx() As Byte
Dim i As Integer
Select Case MSComm1.CommEvent
Case comEvReceive
xx = MSComm1.Input
For i = 0 To UBound(xx)
If Len(Hex(xx(i))) = 1 Then
yy = yy & "0" & Hex(xx(i))
Else
yy = yy & Hex(xx(i))
End If
Next
If Len(yy) = 28 Then '本句最好有对首字节符合通信协议规定的判断
Label1.Caption = yy
List1.AddItem yy & "/" & Len(yy)
yy = ""
End If
End Select
End Sub