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 定义为静态变量
你用mscomm控件,可以参考www.china_askpro.com的
感谢大家的帮助,我是要接收字符串,如“hello world",但现在还是字节流。
发送端: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 你弄根串口线直接将你的两个串口连起来对发,收到的就是你想要的字符
Me.MSComm1.InputMode = comInputModeText
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
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 定义为静态变量
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
你弄根串口线直接将你的两个串口连起来对发,收到的就是你想要的字符
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