vb6串口接收数据事件的数据读出示例

前端之家收集整理的这篇文章主要介绍了vb6串口接收数据事件的数据读出示例前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

Private Sub MSComm1_OnComm()

Dim BytReceived() As Byte
Dim strBuff As String
Dim i As Integer
Select Case MSComm1.CommEvent '事件发生
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 Text2 = Text2 & strData strData = "" Else Text2 = Text2 & strBuff End If End Select End Sub

猜你在找的VB相关文章