7,789
社区成员
发帖
与我相关
我的任务
分享Private Sub MSComm1_OnComm()
Dim bytInput() As Byte
Dim intInputLen As Integer
Dim n As Integer
Dim teststring As String
Select Case MSComm1.CommEvent
Case comEvReceive
If Option1.Value = True Then
MSComm1.InputMode = 1 '0:文本方式,1:二进制方式
Else
MSComm1.InputMode = 0 '0:文本方式,1:二进制方式
End If
intInputLen = MSComm1.InBufferCount
bytInput = MSComm1.Input
If Option1.Value = True Then
For n = 0 To intInputLen - 1
Text1.Text = Trim(Text1.Text) & " " & IIf(Len(Hex$(bytInput(n))) > 1, Hex$(bytInput(n)), "0" & Hex$(bytInput(n)))
Next n
Else
teststring = bytInput
Text1.Text = Text1.Text + teststring
End If
End Select
End Sub