vb串口mscomm接收问题
用单片机发字符串“ABCDEFGHIJKL”时vb串口只能接受到“IJKL”而用虚拟串口发送相同的字符串时vb界面上显示完整的字符“ABCDEFGHIJKL”程序代码如下...
用单片机发字符串“ABCDEFGHIJKL”时vb串口只能接受到“IJKL”而用虚拟串口发送相同的字符串时 vb界面上显示完整的字符“ABCDEFGHIJKL”
程序代码如下:
Private Sub Command1_Click()
MSComm1.Output = Text1.Text
End Sub
Private Sub Command2_Click()
MSComm1.Output = Chr(&H49)
End Sub
Private Sub Form_Load()
MSComm1.CommPort = 1
MSComm1.InputMode = 0
MSComm1.RThreshold = 2
MSComm1.SThreshold = 1
MSComm1.Settings = "9600,n,8,1"
MSComm1.PortOpen = True
End Sub
Private Sub MSComm1_OnComm()
'Dim indata As Variant '定义变量
Dim arr(1) As Variant '定义字节数组
Dim i As Single
Select Case MSComm1.CommEvent ''CommEvent属性:返回最近的通讯事件或错误。通过对它具体属性值的查询,
'我们就可以获得通讯事件和通 讯错误的完整信息。当其值是comEvReceive时表示接收到数据。
Case comEvReceive '有接收事件
arr(i) = MSComm1.Input '接收到的数据存放到indata里
'indata = AscB(indata) '返回indata的值
Text2.Text = arr(0) '在text2中显示数据
MSComm1.InBufferCount = 0 ' 清空接收缓冲区
End Select
End Sub 展开
程序代码如下:
Private Sub Command1_Click()
MSComm1.Output = Text1.Text
End Sub
Private Sub Command2_Click()
MSComm1.Output = Chr(&H49)
End Sub
Private Sub Form_Load()
MSComm1.CommPort = 1
MSComm1.InputMode = 0
MSComm1.RThreshold = 2
MSComm1.SThreshold = 1
MSComm1.Settings = "9600,n,8,1"
MSComm1.PortOpen = True
End Sub
Private Sub MSComm1_OnComm()
'Dim indata As Variant '定义变量
Dim arr(1) As Variant '定义字节数组
Dim i As Single
Select Case MSComm1.CommEvent ''CommEvent属性:返回最近的通讯事件或错误。通过对它具体属性值的查询,
'我们就可以获得通讯事件和通 讯错误的完整信息。当其值是comEvReceive时表示接收到数据。
Case comEvReceive '有接收事件
arr(i) = MSComm1.Input '接收到的数据存放到indata里
'indata = AscB(indata) '返回indata的值
Text2.Text = arr(0) '在text2中显示数据
MSComm1.InBufferCount = 0 ' 清空接收缓冲区
End Select
End Sub 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询