Private Sub MSComm1_On
Dim BytReceived() As Byte
Dim strBuff As String
Dim i As Integer
Select Case MSComm1.CommEvent '事件发生
Case 2
Cls
MSComm1.InputLen = 0 '读入缓冲区全部内容
strBuff = MSComm1.Input '读入到缓冲区
If MSComm1.InputMode = comInputModeBinary Then BytReceived() = strBuff '如果是二进制接收模式则进行数据处理,否则直接显示字符串 For i = 0 To UBound(BytReceived) If Len(Hex(BytReceived(i))) = 1 Then strData = strData & "0" & Hex(BytReceived(i)) & " " '如果只有一个字符,则前补0,如F显示0F,最后补空格 Else '方便显示观察如: 00 0F FE strData = strData & Hex(BytReceived(i)) & " " End If Next Text2 = Text2 & strData strData = "" Else Text2 = Text2 & strBuff End If End Select End Sub