注册 登录
编程论坛 VB6论坛

我在调试过程中,发现关闭串口来源的数据后。我的程序还在不断的显示和处理数据。。

zyj13 发布于 2013-10-18 14:48, 303 次点击
我觉得这显然是因为处理速度慢,而积压在缓冲区的数据。。。如何提高和改善。。用的oncomm事件做的。 代码大致如下
MSComm1.Settings = "115200,n,8,1"       '设置comm参数
MSComm1.InputMode = 1           '以二进制的形式取回传入的数据
MSComm1.InputLen = 1            '每次接受一个字节的数据
MSComm1.RThreshold = 1
MSComm1.InBufferCount = 0  '清空接受缓冲区

Private Sub MSComm1_OnComm()
Dim bytInput() As Byte
 Dim intInputLen As Integer
 Dim n As Integer
Dim test As String

Select Case

        Case comEvReceive
        
        intInputLen = MSComm1.InBufferCount
        bytInput = MSComm1.Input

        For n = 0 To UBound(bytInput)
      
       If Len(Hex(bytInput(n))) = 1 Then
       test = "0" & Hex(bytInput(n))
       Else
       test = Hex(bytInput(n))
       End If
            Text1.Text = Text1.Text & " " & test

     Next n
SendMessage Text1.hwnd, WM_VSCROLL, SB_BOTTOM, 0         'textbox

End Select
End Sub
0 回复
1