在MSComm控件中用二进制方式读取串口,定义byte型数组,然后将Input直接赋给该数组。
   
     With .MSComm1
        .CommPort = 1  ‘设置端口号
        .Settings = "38400,n,8,1"   '打开COM口,并设置其参数
        .PortOpen = True
        .InputLen = 0
        .InputMode = comInputModeBinary
     End With
Private Sub MSComm_OnComm
Dim inch() As Tyte
    ReDim inch1(MSComm(0).InBufferCount)
    inch = MSComm1.Input  'inch数组中即为串口中的数据
End Sub

解决方案 »

  1.   

    不好意思,上面有点小错误:
       
         With .MSComm1
            .CommPort = 1  ‘设置端口号
            .Settings = "38400,n,8,1"   '打开COM口,并设置其参数
            .PortOpen = True
            .InputLen = 0
            .InputMode = comInputModeBinary
         End With然后在MSComm控件的OnComm中:Private Sub MSComm_OnComm
    Dim inch() As Tyte
        ReDim inch1(MSComm1.InBufferCount)
        inch = MSComm1.Input  'inch数组中即为串口中的数据
    End Sub
      

  2.   

    多谢~!
    虽然里面还有点错误,但我还看得懂:)
    还有一点不大明白,我的程序部分如下:MSComm1.RThreshold = 64 '接收64字节发生OnComm事件
    我想让他一次只接收64字节,然后要处理的.
    如果1
    Dim binBuf(63) As Byte
    为什么就错误提示,不能给数组属值
    如果2
    Dim binBuf() As Byte
    就可以了,不用上面的ReDim重新定义数组的大小--
    ReDim inch1(MSComm1.InBufferCount)?????
      

  3.   

    我想应该是InBufferCount和Input动态值,你只能在运行中根据InBufferCount来确定Input的长度,所以相应用来接收Input的数组也应该是动态的。这是我的理解,而且Input本身是一段缓冲区中的二进制数据流,应该用动态的数组来接收
      

  4.   

    http://www.csdn.net/expert/topic/1088/1088962.xml?temp=.3615229