864
社区成员
发帖
与我相关
我的任务
分享Option Explicit
Dim strData As String
Private Sub Form_Load()
MSComm1.Settings = "9600,N,8,1"
MSComm1.RThreshold = 1
MSComm1.InputMode = comInputModeBinary
MSComm1.PortOpen = True
End Sub
Private Sub MSComm1_OnComm()
Dim BytReceived() As Byte
Select Case MSComm1.CommEvent
Case 2
MSComm1.InputLen = 0
BytReceived() = MSComm1.Input
Dim i As Integer
For i = 0 To UBound(BytReceived)
If Len(Hex(BytReceived(i))) = 1 Then
strData = strData & "0" & Hex(BytReceived(i))
Else
strData = strData & Hex(BytReceived(i))
End If
Next
'按通信协议写接收数据处理代码
End Select
End Sub