高分求用vb编写的读取串口字符串的源代码?
是读取字符串,不是二进制。

解决方案 »

  1.   

    没做过……只知道这里有~http://www.21code.com/codebase/?pos=list&type=search&key=串口
      

  2.   

    If commGet.PortOpen = False Then
            commGet.Settings = "9600,N,8,1"
            commGet.PortOpen = True
            commGet.InputLen = 0
            
            Do
                
                InByte = commGet.Input       '从串行口读入数据,并保存与数组中
               
                If UBound(InByte) > -1 Then
                    For i = 0 To UBound(InByte)
                    
                        If InByte(i) <> 0 Then
                         
                            AllByte(j) = InByte(i)
                            j = j + 1
                        End If
                    Next i
                    
                End If
    end if
    allbyte()为公用的
    j 定义为静态变量
      

  3.   

    你用mscomm控件,可以参考www.china_askpro.com的
      

  4.   

    感谢大家的帮助,我是要接收字符串,如“hello world",但现在还是字节流。
      

  5.   

    发送端:Private Sub Form_Load()Me.MSComm1.CommPort = 1
    Me.MSComm1.PortOpen = True
    Me.MSComm1.InputMode = comInputModeText
    Me.MSComm1.Settings = "9600,N,8,1"End SubPrivate Sub Command1_Click()
    Me.MSComm1.Output = "hello world"
    End Sub
    接收端:
    Private Sub Form_Load()Me.MSComm1.CommPort = 2
    Me.MSComm1.PortOpen = True
    Me.MSComm1.InputMode = comInputModeText
    Me.MSComm1.Settings = "9600,N,8,1"End Sub
    Text1.Text = Me.MSComm1.Input    
    你弄根串口线直接将你的两个串口连起来对发,收到的就是你想要的字符
     
      

  6.   

    Me.MSComm1.InputMode = comInputModeText
      

  7.   

    If commGet.PortOpen = False Then
            commGet.Settings = "9600,N,8,1"
            commGet.PortOpen = True
            commget.inputmode=cominputmodetext
            commGet.InputLen = 0 Do            BufferForRec = commGet.Input
                If BufferForRec <> "" Then
                                    txtRs.Text = txtRs.Text & BufferForRec
                End If
                DoEvents        Loop Until commGet.PortOpen = False
    end if