我用Buffer = MSComm1.Input收到兩個byte 的數據(FF 00)
這兩個byte就是代表LED現是的狀態(OFF ON),我怎樣才能用這兩個byte呢?
我不懂buffer的用法,有人幫到我嗎?
謝謝

解决方案 »

  1.   

    buffer应该是以个数组吧?直接读数组就可以了??
      

  2.   

    这是因为你设了: MSComm1.InputMode = 1 ,所以接收的数据是二进制数据。
    Buffer 是一个缓冲区。直接读取数据。这里有例子:
    http://www.phpchinaz.cn/c/VB_Basic/51_5101_1236005626.html
      

  3.   

    http://www.gjwtech.com/scomm/sc2vb6mscomm128chapi.htm
      

  4.   

    http://blog.csdn.net/zdingyun/archive/2008/09/23/2969936.aspx
    请参阅本人BLOG
    "MSComm 控件的Input 属性及InputMode 属性探究"
      

  5.   

    以2进制接收转换为16进制字符串来处理数据.
    buffer()作为动态Byte字节数组处理接收的2进制字节流.
    Option Explicit
        Dim strData As StringPrivate Sub MsComm1_OnComm()
        Dim buffer() As Byte
        Dim i As Integer
        Select Case MsComm1.CommEvent
            Case comEvReceive
            buffer = MsComm1.Input
            For i = 0 To UBound(inByte)
            If Len(Hex(buffer(i))) = 1 Then
                strData = strData & "0" & Hex(buffer(i))
            Else
                strData = strData & Hex(buffer(i))
            End If
            Next
            If Mid(strData,1,4) = "FF00"  Then
                Text1.Text = strData '
                strData = ""
            End If
         End Select
    End SubPrivate Sub Form_Load()
        With MsComm1
            .CommPort = 1
            .Settings = "9600,n,8,1"
            .InBufferCount = 0
            .InputLen = 0
            .RThreshold = 1
            .InputMode = comInputModeBinary '以2进制接收
             .PortOpen = True
        End With
        Text1 = ""
    End Sub