你每次读数据前把txtBuf清空试试?

解决方案 »

  1.   

    怎么清空?为什么我在读后加一个msgbox txtBuf,读的数据好像比较正确,另外,如果我在form上添加一个文本框txtShowData,每次MSComm1_OnComm事件时让txtShowData=txtShowData+txtBuf,这样就是对的呢?
      

  2.   

    我也遇到了类似的问题,后来我没有用这个它的事件来得数据,而用了一个时钟控件,
    定时查看mscomm1.input属性。
      

  3.   

    在读入前用API sleep 喊数,一定行,
      

  4.   

    var
       recstr:Olevariant;
       i:integer;
    begin
       if Mscomm1.CommEvent = 2 then
       begin    repeat
          i := MSComm1.InBufferCount;
          Sleep (200);  //'API 函数,挂起当前进程一段时间      Until MSComm1.InBufferCount = i;      recstr := MSComm1.Input;
      // showmessage( recstr);
       self.CheckFileEx ;
       try
       self.ReadstrFromCom(recstr)
       except
           on EconvertError  do Application.MessageBox('条码识读出错。','提示',64);
       end;
       end;
    把这段译成BASIC就行了,这段是我从BASIC中转过去的.一定行.
    这是我工程中的源码,没问题的 .
      

  5.   

    做个全局变量GETSTRPrivate Sub MSComm1_OnComm()
        Dim i As Integer, b As String
        Dim Buffer As Variant
        
        'MDIForm1.StatusBar1.Panels(1).Picture = MDIForm1.ImageList1.ListImages(1).Picture
        i = MSComm1.CommEvent
        If i > 1000 Then
            If i = 1001 Then b = "接受到一个中断信号!"
            If i = 1002 Then b = "Clear To Send 超时!"
            If i = 1003 Then b = "Date Set Ready 超时!"
            If i = 1004 Then b = "通讯帧错误!"
            If i = 1006 Then b = "端口超速!"
            If i = 1007 Then b = "载波检测超时!"
            If i = 1008 Then b = "接受缓冲区溢出!"
            If i = 1009 Then b = "奇偶校验错误!"
            If i = 1010 Then b = "传送缓冲区溢出!"
            If i = 1011 Then b = "检测端口设备控制块DCB错误!"
        Else
            If i = 2 Then
                Form5.Label3(0).BackColor = QBColor(2)
                Buffer = MSComm1.Input
                getstr = getstr + StrConv(Buffer, vbUnicode)
                Form5.Label3(0).BackColor = 0
            End If
            If i = 3 Then b = "检波状态改变"
        End If
        'MDIForm1.StatusBar1.Panels(1).Picture = MDIForm1.ImageList1.ListImages(2).Picture
        If b <> "" Then addtip 2, 1, b
    End Sub