求大神帮忙,怎样用 VB 程序对串口接收到的数据进行处理,然后放到 MSHFlex 上进行显示。
接收的数据有起始标志位11和结束标志位55单片机是主机,电脑是从机,单片机一直在发送数据到电脑。
所以串口一直在接收数据,由于小妹不晓得怎么去处理接收到的数据,将它一个一个放入一个数组里,然后再放到MSHFlex中一个一个进行显示。
求大神帮忙修改下 谢谢!
不知怎么样去设标志位进行判断!
Private Sub MSComm1_OnComm()
Select Case '事件发生
Case 2
Cls
MSComm1.InputLen = 0 '读入缓冲区全部内容
strBuff = MSComm1.Input '读入到缓冲区
If MSComm1.InputMode = comInputModeBinary Then
BytReceived() = strBuff '如果是二进制接收模式则进行数据处理,否则直接显示字符串
For I = 0 To UBound(BytReceived())
If Len(Hex(BytReceived(I))) = 1 Then
strdata = strdata & "0" & Hex(BytReceived(I)) '如果只有一个字符,则前补0,如F显示0F,最后补空格
Else '方便显示观察如:00 0F FE
strdata = strdata & Hex(BytReceived(I))
End If
Next
TextReceive = TextReceive & strdata
strdata = ""
Else
TextReceive = TextReceive & strBuff
End If
TextReceive = TextReceive & strdata
Text1.Text = Text1.Text + TextReceive
a(2) = Mid(Text1.Text, 5, 2)
If a(2) = "01" Then
j = 1
For k = 1 To 19
MSHFlex2.TextMatrix(k, 1) = Mid(Text1.Text, j, 2)
j = j + 2
MSHFlex2.ColAlignment = flexAlignRightCenter
Next
ElseIf a(2) = "02" Then
j = 1
For k = 1 To 19
MSHFlex3.TextMatrix(k, 1) = Mid(Text1.Text, j, 2)
j = j + 2
MSHFlex3.ColAlignment = flexAlignRightCenter
Next
End If
End Select
MSComm1.InBufferCount = 0
MSComm1.OutBufferCount = 0
End Sub