串口助手接收了fe01130501
为什么VB界面不显示,以下是VB程序
  rivate Sub Command3_Click()
Text1.Text = ""
End Sub
Private Sub Form_Load()
MSComm1.Settings = "9600,n,8,1"
MSComm1.RThreshold = 6
MSComm1.InputLen = 0
MSComm1.InputMode = comInputModeBinary
End Sub
Private Sub MSComm1_OnComm()
Select Case MSComm1.CommEvent
Case comEvReceive
MSComm1.RThreshold = 0
buffer = MSComm1.Input '接收数据至字符串中
BytesReceived() = buffer '将数据转入Byte数组中
For i = 0 To UBound(BytesReceived) '显示结果以十六进制显示
If Len(Hex(BytesReceived(i))) = 1 Then
HData = HData & "0" & Hex(BytesReceived(i))
Else
HData = HData & Hex(BytesReceived(i))
End If
Next i
If Mid(HData, 1, 2) = "FE" And Len(HData) = 10 Then '提取帧结构
Text1.Text = Text1.Text & HData & Chr(13) & Chr(10) '显示接收到的数据 Text7.Text = HData
A = Val("&H" & Mid(HData, 5, 2)) + (Mid(HData, 7, 2) * 0.1)
dizhi = Mid(HData, 3, 2)
If dizhi = "01" Then
Text3.Text = A & "℃"
ElseIf dizhi = "02" Then
Text5.Text = A & "℃"
End If
End If
MSComm1.InBufferCount = 0
MSComm1.RThreshold = 6
End Select
End Sub
Private Sub Timer1_Timer()
Label6.Caption = Now
End Sub
|