各位大侠:
小弟遇到串口通讯的问题,捆扰小弟多日.我想要实现的是单片机随机采集数据发给上位机,但是总也实现不了,如果一次发一个就可以实现,但是多发了的话就实现不了.下面是代码,敬请赐教.
Private Sub Command1_Click()
If Me.Text1.Text = "" Then
Dim MyVar
MyVar = MsgBox("请输入数字!", 6, "提示")
GoTo ee
End If
Dim a(0) As Byte
a(0) = Text1.Text
MSComm1.Output = a
ee:
End Sub
Private Sub Form_Load()
MSComm1.InputLen = 0 '告诉控件读入整个缓冲区
If MSComm1.PortOpen = False Then
MSComm1.PortOpen = True '打开端口
End If
MSComm1.RThreshold = 1 '设置接收的字符数
End Sub
Private Sub MSComm1_OnComm()
Select Case MSComm1.CommEvent
Case comEvReceive '这里我们只处理接收字符的事件
Dim R() As Byte
' Dim Buff As String
MSComm1.InputLen = MSComm1.InBufferCount
'Buff = MSComm1.Input
R = MSComm1.Input
'R = Buff
'For i = LBound(R) To UBound(R)
Text2.Text = Text2.Text + CStr(R(i)) + " "
'Next
End Select
End Sub
PC与单片机串口通讯问题