864
社区成员
发帖
与我相关
我的任务
分享Option Explicit
Dim strData As String
Private Sub Form_Load()
Text1 = ""
MSComm1.CommPort = 1
MSComm1.InputMode = comInputModeBinary '数据通过 Input 属性以文本形式取回。
MSComm1.RThreshold = 1
MSComm1.Settings = "9600,N,8,1"
MSComm1.PortOpen = True
End Sub
Private Sub MSComm1_OnComm() '接收数据
Dim BytReceived() As Byte
Dim strBuff As String
Select Case MSComm1.CommEvent
Case 2
MSComm1.InputLen = 0
strBuff = MSComm1.Input
BytReceived() = strBuff
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
Text1 = strData
'数据处理代码
End Select
End Sub