串口通讯strData = strData & "0" & Hex(BytReceived(i)) 什么意思?
下面这段代码不太懂,那位大侠指点下If Len(Hex(BytReceived(i))) = 1 Then strData = strData & "0" & Hex(BytReceived(i)) Else strData = strData & Hex(BytReceived(i)) End If 完整代码如下Private Sub Form_Load() MSComm1.Settings = "9600,n,8,1" ✀暂定无校验,数据位8位,停止位1位 MSComm1.InputMode = comInputModeBinary ✀采用二进制传输 MSComm1.InBufferCount = 0 ✀清空接受缓冲区 MSComm1.OutBufferCount = 0 ✀清空传输缓冲区 MSComm1.RThreshold = 1 ✀产生MSComm事件 MSComm1.InBufferSize = 1024 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