vb与单片机的串口通信
单片机发送4位数据串口调试软件可以正常收到4位,而vb只能收到后两位DimBytReceived()AsByteDimstrBuffAsStringDimiAsInteg...
单片机发送4位数据串口调试软件可以正常收到4位,而vb只能收到后两位
Dim BytReceived() As Byte
Dim strBuff As String
Dim i As Integer
Select Case MSComm1.CommEvent '事件发生
Case 2
MSComm1.InputLen = 0 '读入缓冲区全部内容
strBuff = MSComm1.Input '读入到缓冲区
BytReceived() = strBuff '二进制接收模式,进行数据处理
For i = 0 To UBound(BytReceived)
strData = strData & Hex(BytReceived(i))
Next
Label1 = Val("&H " + strData)
End Select
strData = ""
End Select
End Sub 展开
Dim BytReceived() As Byte
Dim strBuff As String
Dim i As Integer
Select Case MSComm1.CommEvent '事件发生
Case 2
MSComm1.InputLen = 0 '读入缓冲区全部内容
strBuff = MSComm1.Input '读入到缓冲区
BytReceived() = strBuff '二进制接收模式,进行数据处理
For i = 0 To UBound(BytReceived)
strData = strData & Hex(BytReceived(i))
Next
Label1 = Val("&H " + strData)
End Select
strData = ""
End Select
End Sub 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询