| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1443 人关注过本帖
标题:关于Mscomm如何清空接收显示框
只看楼主 加入收藏
孙文
Rank: 1
等 级:新手上路
帖 子:25
专家分:0
注 册:2016-5-5
结帖率:50%
收藏
 问题点数:0 回复次数:0 
关于Mscomm如何清空接收显示框
Option Explicit
Dim inData As String      '串口接收显示数据变量

'--------------加载串口设置---------------
Private Sub Form_Load()
   = 3
  MSComm1.Settings = "9600,N,8,1"
  MSComm1.InBufferSize = 1024
  MSComm1.OutBufferSize = 4096
  MSComm1.InBufferCount = 0
  MSComm1.OutBufferCount = 0
  MSComm1.SThreshold = 1
  MSComm1.RThreshold = 1
  MSComm1.InputMode = 1
  MSComm1.InputLen = 0
  MSComm1.PortOpen = True
  Text2.Text = ""
End Sub
'--------------发送------------------
Private Sub Command1_Click()
 Dim aa(0 To 14) As Byte                     
 aa(0) = &H55
 aa(1) = &H55
 aa(2) = &HFA
 aa(3) = &H9
 aa(4) = &HE5
 aa(5) = &H5
 aa(6) = &H4
 aa(7) = &H12
 aa(8) = &H12
 aa(9) = &H48
 aa(10) = &H0
 aa(11) = &H63
 aa(12) = &HD
 aa(13) = &H55
 aa(14) = &H55
 Text2.Text = ""             '发送前清空Text2.text
 MSComm1.InBufferCount = 0   '发送前清空接收缓冲区
 Text1.Text = Hex(aa(0)) & " " & Hex(aa(1)) & " " & Hex(aa(2)) & " " & Hex(aa(3)) & " " & Hex(aa(4)) & " " _
 & Hex(aa(5)) & " " & Hex(aa(6)) & " " & Hex(aa(7)) & " " & Hex(aa(8)) & " " & Hex(aa(9)) & " " & Hex(aa(10)) & " " _
  & Hex(aa(11)) & " " & Hex(aa(12)) & " " & Hex(aa(13)) & " " & Hex(aa(14))
 MSComm1.Output = aa     '发送
End Sub
'-------退出----------
Private Sub Command3_Click()
  End
End Sub
'---------------接收数据------------------  
Private Sub MSComm1_OnComm()
  Dim InByte() As Byte      '定义一个二进制指针放接收到的数据
  Dim i As Integer
  Select Case
     Case comEvReceive
       InByte = MSComm1.Input '数据转移到指针
       For i = LBound(InByte) To UBound(InByte)
           If Len(Hex(InByte(i))) = 1 Then
              inData = inData & "0" & Hex(InByte(i)) & Chr(32)
           Else
              inData = inData + Hex(InByte(i)) + Chr(32)
           End If
       Next i
       Text2.Text = inData   '数据显示
  End Select
End Sub


以上代码是无法在发送时清空text2.text当中的数据,请教下如何清空!谢谢!
搜索更多相关主题的帖子: 如何 
2016-12-24 12:27
快速回复:关于Mscomm如何清空接收显示框
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.020017 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved