加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

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

发布时间:2020-12-16 22:16:34 所属栏目:大数据 来源:网络整理
导读:Private Sub MSComm1_On Comm() 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.Inp

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读