数据通过串口进入计算机,在VB中怎么显示数据

来源:百度知道 编辑:UC知道 时间:2024/05/09 09:01:33
好象要添加MSCOMM控件,我是新手对这不是太懂.给详细介绍一下或给些参考网站
我邮箱地址是280045066@qq.com

新建VB工程,由工程菜单选部件项,在Microsoft Comm Control 6.0部件前打钩确定,VB的工具箱中就有MSCOMM控件,添加到窗体.下列代码可按2进制接收数据,处理为16进制字符串显示数据.
Option Explicit
Dim inData As String
Dim arr() As Byte

Private Sub Form_Load()
MSComm1.Settings = "9600,n,8,1"
MSComm1.RThreshold = 1
MSComm1.InputMode = comInputModeBinary '二进制接收
MSComm1.PortOpen = True
End Sub

Private Sub MsComm1_OnComm()
Dim intInputLen As Integer
Dim i As Integer
Select Case MSComm1.CommEvent
Case comEvReceive
'此处添加处理接收的代码
intInputLen = MSComm1.InBufferCount
ReDim arr(intInputLen)
arr = MSComm1.Input
For i = 0 To UBound(arr)
If Len(Hex(arr(i))) = 1 Then
inData = inData & "0" & Hex(arr(i))
Else
inData = inData & Hex(arr(i))
End If
Next
Text2 = inData
End Select
End Sub

在VB中用语句接收的。。。
我这有源码留下你的邮箱。给你传过去一份。

需要电子书籍的话留下邮件地址或给我发百度消息