实现16进制接收实质就是按2进制接收
设置MSComm控件的属性InputMode = comInputModeBinary '二进制接收
接收后由HEX函数转为16进制字符串形式显示
Option Explicit
Dim strData As String
Dim bytInput() As Byte
Private Sub MsComm1_OnComm()
Dim intInputLen As Integer
Select Case Me.MSComm2.CommEvent
Case comEvReceive
'此处添加处理接收的代码
MSComm1.InputMode = comInputModeBinary '二进制接收
intInputLen = MSComm1.InBufferCount
ReDim bytInput(intInputLen)
bytInput = MSComm1.Input
jieshou
End Select
End Sub
Public Function jieshou() '接收数据处理为16进制
Dim i As Integer
For i = 0 To UBound(bytInput)
If Len(Hex(bytInput(i))) = 1 Then
strData = strData & "0" & Hex(bytInput(i))
Else
strData = strData & Hex(bytInput(i))
End If
Next
Text1 = strData
End Function
Private Sub Form_Load()
MSComm1.CommPort = 1
MSComm1.InBufferSize = 1024
MSComm1.OutBufferSize = 512
MSComm1.Settings = "9600,n,8,1"
MSComm1.PortOpen = True
Text1 = ""
End Sub