7,763
社区成员
发帖
与我相关
我的任务
分享
If Len(Hex(inByte(i))) = 1 Then '将接收的Byte字节流转换为16进制字符串
strData = strData & "0" & Hex(inByte(i))
Else
strData = strData & Hex(inByte(i))
End If
Private Sub MsComm1_OnComm()
Dim inByte() As Byte
Dim i As Integer
Select Case MsComm1.CommEvent
Case comEvReceive
inByte = MsComm1.Input
For i = 0 To UBound(inByte)
If Len(Hex(inByte(i))) = 1 Then
strData = strData & "0" & Hex(inByte(i))
Else
strData = strData & Hex(inByte(i))
End If
Next
If Mid(strData,1,2) = "11" And Mid(strData,9,2) = "22" Then
Text1.Text = strData
strData = ""
End If
End Select
End Sub
Option Explicit
Dim strData As String
Private Sub MsComm1_OnComm()
Dim inByte() As Byte
Dim i As Integer
Select Case MsComm1.CommEvent
Case comEvReceive
inByte = MsComm1.Input
For i = 0 To UBound(inByte)
If Len(Hex(inByte(i))) = 1 Then
strData = strData & "0" & Hex(inByte(i))
Else
strData = strData & Hex(inByte(i))
End If
Next
If Mid(strData,1,2) = "11" And RighT(strData,2) = "22" Then
Text1.Text = strData
strData = ""
End If
End Select
End Sub
Private Sub Form_Load()
With MsComm1
.CommPort = 1
.Settings = "9600,n,8,1"
.InBufferCount = 0
.InputLen = 0
.RThreshold = 1
.InputMode = comInputModeBinary '以2进制接收
.PortOpen = True
End With
Text1 = ""
End Sub
Option Explicit
Dim strData As String
Private Sub MsComm1_OnComm()
Dim inByte() As Byte
Dim i As Integer
Select Case MsComm1.CommEvent
Case comEvReceive
inByte = MsComm1.Input
For i = 0 To UBound(inByte)
If Len(Hex(inByte(i))) = 1 Then
strData = strData & "0" & Hex(inByte(i))
Else
strData = strData & Hex(inByte(i))
End If
Next
If Mid(strData,1,2) = "11" And Mid(strData,5,2) = "22" Then
Text1.Text = strData
strData = ""
End If
End Select
End Sub
Private Sub Form_Load()
With MsComm1
.CommPort = 1
.Settings = "9600,n,8,1"
.InBufferCount = 0
.InputLen = 0
.RThreshold = 1
.InputMode = comInputModeBinary '以2进制接收
.PortOpen = True
End With
Text1 = ""
End Sub