MSComm1.InBufferCount 显示为22,但接收后 却没有数据 是咋回事

MSComm1.InBufferCount 显示为22,但接收后 却没有数据 是怎么回事
     '读表命令发送完毕后,等待读表数据返回到串口缓冲区
 
     Dim gs As Long,I as long , VBiaoFanh As Variant
     I = 0: J = False:gs=0

     Do While I < 200 And J = False
        gs = MSComm1.InBufferCount
        If gs >= 16 Then   
           J = True
           Exit Do
        End If
        I = I + 1
        Sleep (10)
      Loop

     VBiaoFanh = MSComm1.Input
当 程序在  gs=16时 继续向下执行的路径为:

        If gs >= 16 Then   
           J = True
           Exit Do

         VBiaoFanh = MSComm1.Input

  但是 VBiaoFanh = MSComm1.Input 执行完后,VBiaoFanh 却没有数据 监视窗口中显示
   Watch : - : VBiaoFanh :  : Variant/Byte(0 to -1) 

   这是什么原因呢,明明显示串口接收缓冲区中有16个数据,接收后,却没有数据?


------解决方案--------------------
循环 200 次后也会退出循环,你怎么保证这段时间内一定收到了数据?
------解决方案--------------------
个人觉得楼主的设计思路不好,完全可以有就读,读出来再处理。参阅:
http://download.****.net/detail/veron_04/4037248
------解决方案--------------------
引用:
Quote: 引用:

循环 200 次后也会退出循环,你怎么保证这段时间内一定收到了数据?


如果未收到数据,此段程序所在的函数返回值为FALSE,  如果收到了数据,则返回值 为TRUE,

没有说这段程序一定要收到数据。

没收到 VBiaoFanh 当然没数据,有什么问题?
------解决方案--------------------
你到达  MSComm1.Input 有两条分支,不能所明肯定是从 gs >= 16 分支来的。
------解决方案--------------------
你确定断点时光标没有在 MSComm1.Input 上停留过?
确定监视窗口没有用到 MSComm1.Input?
以上都会导致清空缓冲区。
------解决方案--------------------
这样试试:

     Do While I < 200 And J = False
        gs = MSComm1.InBufferCount
        If gs >= 16 Then 
           VBiaoFanh = MSComm1.Input  
           J = True
           Exit Do
        End If
        I = I + 1
        Sleep (10)
      Loop
把原来的 VBiaoFanh = MSComm1.Input 注掉。

或者:

VBiaoFanh = VBiaoFanh & MSComm1.Input