在VB6.0中如何通过计算机串口采集仪表的实时数据,并显示曲线,然后保存数据。

我初学VB,现需要采集实时数据,并显示保存曲线。该仪表的串口数据通信协议是:数据传输速率为2400bps,1位开始位,8位数据位,1位停止位,无奇偶校验位。仪表每秒发送1... 我初学VB,现需要采集实时数据,并显示保存曲线。该仪表的串口数据通信协议是:数据传输速率为 2400bps,1位开始位,8位数据位,1位停止位,无奇偶校验位。仪表每秒发送10个数据,数据输出格式为ASCAII码。仪表量程为0-5000Pa,每次大概测量三分钟左右。
现请教各位,如何做这个东东,要是有源码,那就更好了。在此先谢谢各位了。
展开
 我来答
hunter206
2010-12-21 · TA获得超过234个赞
知道答主
回答量:108
采纳率:0%
帮助的人:78.2万
展开全部
给你个我编过的源代码吧!
Option Explicit
Dim sinX As Integer

Private Sub Command1_Click()
Picture1.AutoRedraw = True
Call DrawAxis(Picture1)
If (Command1.Caption = "开始") Then
Command1.Caption = "重画"
End If
sinX = 1
Timer1.Enabled = True
End Sub
Private Sub DrawAxis(mypicture As PictureBox) '画x,y坐标轴,图片框对象mypicture为形参传递到过程中
Dim x1 As Integer, y1 As Integer, x2 As Integer, y2 As Integer
Dim y As Integer
mypicture.BackColor = QBColor(0) '绘制图板坐标,确定颜色
mypicture.Cls
mypicture.DrawStyle = 0
x1 = 200
y1 = (mypicture.ScaleHeight - 200)
y = y1 / 2
x2 = mypicture.ScaleWidth - 200
y2 = 200
mypicture.Line (x1, y1)-(x1, y2), QBColor(11)
mypicture.Line (x1, y)-(x2, y), QBColor(11)
mypicture.Line (x1 - 50, y2 + 120)-(x1, y2), QBColor(11)
mypicture.Line (x1 + 50, y2 + 120)-(x1, y2), QBColor(11)
mypicture.Line (x2 - 120, y + 50)-(x2, y), QBColor(11)
mypicture.Line (x2 - 120, y - 50)-(x2, y), QBColor(11)
End Sub

Private Sub Command2_Click()
Timer1.Enabled = False

End Sub

Private Sub Command3_Click()
Timer1.Enabled = True
Timer1.Interval = 50
End Sub

Private Sub Command4_Click()
End
End Sub

Private Sub Form_Load()
MSComm1.CommPort = 3 '串口初始化
MSComm1.Settings = "9600,n,8,1"
MSComm1.InputLen = 0
MSComm1.InBufferSize = 512
MSComm1.InBufferCount = 0
MSComm1.SThreshold = 1
MSComm1.PortOpen = True
MSComm1.RThreshold = 1
End Sub

Private Sub MSComm1_OnComm()
Debug.Print "status:" & MSComm1.CommEvent
End Sub

Private Sub Timer1_Timer() '画正弦曲线
Dim x As Integer
Dim y As Integer
Dim scaleY As Integer
Dim m As Integer
scaleY = Picture1.ScaleHeight / 4 '1/4图面高度
Picture1.CurrentX = 200
Picture1.CurrentY = (Picture1.ScaleHeight - 200) / 2 '起点纵坐标(当前点)
x = sinX / 720 * scaleY * 3.14
If Option1.Value = True Then
y = Sin(3.14 / 180 * sinX) * scaleY
End If
If Option2.Value = True Then
y = Cos(3.14 / 180 * sinX) * scaleY
End If
If Option3.Value = True Then
y = Text3.Text / 100 * scaleY
End If
Picture1.PSet Step(x, -y), QBColor(14)
sinX = sinX + 1
Text1.Text = x
Text2.Text = y
End Sub

Private Sub Timer2_Timer()
Dim a As Variant
a = MSComm1.Input
If Len(a) <> 0 Then
Text3.Text = Val(a)
End If
End Sub
本回答被提问者和网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式