我要发布
仪器网/ 仪器社区/ 数据采集/ VB 串口数据采集

VB 串口数据采集

塞又亦    2007-04-25    数据采集    浏览 402 次

这个问题恐怕没有几个人会吧!!!主要是太难了,呵呵,一般的回答的都是在别的地方复制的,我想听听你们自己的想法,我要实现串口数据的保存和实时显示,保存在数据库中,实时显示是... 这个问题恐怕没有几个人会吧!!!

主要是太难了,呵呵,一般的回答的都是在别的地方复制的,我想听听你们自己的想法,我要实现串口数据的保存和实时显示,保存在数据库中,实时显示是用曲线图的形式画出来,真难啊,想以采集的时间为横坐标,采集到的压力数据为纵坐标,请你们告诉我一下啊,现在高手太少了。。。。。
画图是应该先入库再调数据库的数据还是直接接受串口数据进行做图?这一点我还不知道!

精彩问答
靳薪善 发布日期:2016-08-22
实时采集的数据可直接用来画曲线,但往往为了以后查询,同时应按定时间隔写入数据库或文本文件。所以可在写入数据库后通过查询做到实时显示和更新。
'窗体加载时将已记录的数据查询后绘图
Private Sub Form_Load()
chaxun1 = "select * from jishijilu where gyh_riqi='" & gongyi_sj(0) & "-" & record_rq & "'order by shijian "
mdh = chaxun1
Adodc3.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Ldgz\wd.mdb;Persist Security Info=False"
Adodc3.RecordSource = mdh
Adodc3.Refresh
zslNew = Adodc3.Recordset.RecordCount
Text4 = zslNew
If zslNew >= 1 Then
Adodc3.Recordset.MoveFirst
For i = 0 To zslNew - 1
quexian(0, i) = Adodc3.Recordset(0)
For j = 2 To 9
quexian(j, i) = Adodc3.Recordset(j)
Next j
Adodc3.Recordset.MoveNext
Next i
Adodc3.Recordset.MoveFirst
For j = 0 To zslNew - 1
Picture1.Line (j * 5 + 500, quexian(2, j) * -30 + 3399)-(j * 5 + 500, quexian(2, j) * -30 + 3401), vbRed, BF
Picture1.Line (j * 5 + 500, quexian(3, j) * -30 + 3399)-(j * 5 + 500, quexian(3, j) * -30 + 3401), QBColor(7), BF
Picture1.Line (j * 5 + 500, quexian(4, j) * -30 + 3399)-(j * 5 + 500, quexian(4, j) * -30 + 3401), vbWhite, BF
Picture1.Line (j * 5 + 500, quexian(5, j) * -30 + 3399)-(j * 5 + 500, quexian(5, j) * -30 + 3401), vbYellow, BF
Picture1.Line (j * 5 + 500, quexian(6, j) * -30 + 3399)-(j * 5 + 500, quexian(6, j) * -30 + 3401), vbGreen, BF
If quexian(8, j) < 1 Then
wy_wy = 0 + 166.7
br_br = 55
ElseIf quexian(8, j) >= 1 And quexian(8, j) < 10 Then
wy_wy = -1500 + 166.7
br_br = 5.5556
ElseIf quexian(8, j) >= 10 And quexian(8, j) < 100 Then
wy_wy = -3000 + 166.7
br_br = 0.5555
ElseIf quexian(8, j) >= 100 And quexian(8, j) < 1000 Then
wy_wy = -4500 + 166.7
br_br = 0.055555
End If
Picture1.Line (j * 5 + 500, quexian(8, j) * br_br * -30 + wy_wy + 3397 + 3000)-(j * 5 + 500, quexian(8, j) * br_br * -30 + wy_wy + 3403 + 3000), QBColor(11), BF
Next j
zslOld = zslNew
End If
'记录时间Z长75小时
Picture2.Height = 10000
Picture2.Visible = True
Picture1.Visible = True
colvb = vbWhite
xx = 100
yy = 150
txt = "℃"
wp = xp(colvb, xx, yy, txt)
yy = 350
txt = "100"
wp = xp(colvb, xx, yy, txt)
xx = 200
yy = 1850
txt = "50"
wp = xp(colvb, xx, yy, txt)
yy = 3350
xx = 300
txt = "0"
wp = xp(colvb, xx, yy, txt)
xx = 100
yy = 4850
txt = "-50"
wp = xp(colvb, xx, yy, txt)
xx = 0
yy = 6350
txt = "-100"
wp = xp(colvb, xx, yy, txt)
xx = 10800 + 100
yy = 150
txt = "℃"
wp = xp(colvb, xx, yy, txt)
yy = 350
txt = "100"
wp = xp(colvb, xx, yy, txt)
xx = 10800 + 200
yy = 1850
txt = "50"
wp = xp(colvb, xx, yy, txt)
yy = 3350
xx = 10800 + 300
txt = "0"
wp = xp(colvb, xx, yy, txt)
xx = 10800 + 100
yy = 4850
txt = "-50"
wp = xp(colvb, xx, yy, txt)
xx = 10800 + 0
yy = 6350
txt = "-100"
wp = xp(colvb, xx, yy, txt)
'真空坐标

colvb = vbRed
xx = 11400
yy = 150
txt = "Pa"
wp = xp(colvb, xx, yy, txt)
yy = 350
txt = "1000"
wp = xp(colvb, xx, yy, txt)
xx = 11500
yy = 1850
txt = "100"
wp = xp(colvb, xx, yy, txt)
yy = 3350
xx = 11600
txt = "10"
wp = xp(colvb, xx, yy, txt)
xx = 11700
yy = 4850
txt = "1"
wp = xp(colvb, xx, yy, txt)
xx = 11500
yy = 6350
txt = "0.1"
wp = xp(colvb, xx, yy, txt)

xx = 500
yy = 150
txt = "Pa"
wp = xp(colvb, xx, yy, txt)
yy = 350
txt = "1000"
wp = xp(colvb, xx, yy, txt)
yy = 150
xx = 2200
txt = "6hr"
wp = xp(colvb, xx, yy, txt)
xx = 4000
txt = "12hr"
wp = xp(colvb, xx, yy, txt)
xx = 5800
txt = "18hr"
wp = xp(colvb, xx, yy, txt)
xx = 7600
txt = "24hr"
wp = xp(colvb, xx, yy, txt)
xx = 9400
txt = "30hr"
wp = xp(colvb, xx, yy, txt)
xx = 13000
txt = "42hr"
wp = xp(colvb, xx, yy, txt)
xx = 14800
txt = "48hr"
wp = xp(colvb, xx, yy, txt)
xx = 16600
txt = "54hr"
wp = xp(colvb, xx, yy, txt)
xx = 18400
txt = "60hr"
wp = xp(colvb, xx, yy, txt)
xx = 20200
txt = "66hr"
wp = xp(colvb, xx, yy, txt)
xx = 22000
txt = "72hr"
wp = xp(colvb, xx, yy, txt)
xx = 23800
txt = "78hr"
wp = xp(colvb, xx, yy, txt)
xx = 25600
txt = "84hr"
wp = xp(colvb, xx, yy, txt)
xx = 27400
txt = "90hr"
wp = xp(colvb, xx, yy, txt)
xx = 29200
txt = "96hr"
wp = xp(colvb, xx, yy, txt)
xx = 600
yy = 1850
txt = "100"
wp = xp(colvb, xx, yy, txt)
yy = 3350
xx = 11600
txt = "10"
wp = xp(colvb, xx, yy, txt)
xx = 700
yy = 4850
txt = "1"
wp = xp(colvb, xx, yy, txt)
xx = 600
yy = 6350
txt = "0.1"
wp = xp(colvb, xx, yy, txt)
xx = 22100
yy = 350
txt = "1000"
wp = xp(colvb, xx, yy, txt)
yy = 1850
txt = " 100"
wp = xp(colvb, xx, yy, txt)
yy = 3350
txt = " 10"
wp = xp(colvb, xx, yy, txt)
yy = 4850
txt = " 1"
wp = xp(colvb, xx, yy, txt)
yy = 6350
txt = " 0.1"
wp = xp(colvb, xx, yy, txt)
'画格

Picture1.ForeColor = vbWhite
Picture1.Line (450, 700)-(500, 700)
Picture1.Line (450, 1000)-(500, 1000)
Picture1.Line (450, 1300)-(500, 1300)
Picture1.Line (450, 1600)-(500, 1600)
Picture1.ForeColor = vbRed

Picture1.Line (500, 566.7)-(550, 566.7)
Picture1.Line (500, 733.3)-(550, 733.3)
Picture1.Line (500, 900)-(550, 900)
Picture1.Line (500, 1066.7)-(550, 1066.7)
Picture1.Line (500, 1233.3)-(550, 1233.3)
Picture1.Line (500, 1400)-(550, 1400)
Picture1.Line (500, 1566.7)-(550, 1566.7)
Picture1.Line (500, 1733.3)-(550, 1733.3)
Picture1.Line (500, 2066.7)-(550, 2066.7)
Picture1.Line (500, 2233.3)-(550, 2233.3)
Picture1.Line (500, 2400)-(550, 2400)
Picture1.Line (500, 2566.7)-(550, 2566.7)
Picture1.Line (500, 2733.3)-(550, 2733.3)
Picture1.Line (500, 2900)-(550, 2900)
Picture1.Line (500, 3066.7)-(550, 3066.7)
Picture1.Line (500, 3233.3)-(550, 3233.3)
Picture1.Line (500, 3566.7)-(550, 3566.7)
Picture1.Line (500, 3733.3)-(550, 3733.3)
Picture1.Line (500, 3900)-(550, 3900)
Picture1.Line (500, 4066.7)-(550, 4066.7)
Picture1.Line (500, 4233.3)-(550, 4233.3)
Picture1.Line (500, 4400)-(550, 4400)
Picture1.Line (500, 4566.7)-(550, 4566.7)
Picture1.Line (500, 4733.3)-(550, 4733.3)
Picture1.Line (500, 5066.7)-(550, 5066.7)
Picture1.Line (500, 5233.3)-(550, 5233.3)
Picture1.Line (500, 5400)-(550, 5400)
Picture1.Line (500, 5566.7)-(550, 5566.7)
Picture1.Line (500, 5733.3)-(550, 5733.3)
Picture1.Line (500, 5900)-(550, 5900)
Picture1.Line (500, 6066.7)-(550, 6066.7)
Picture1.Line (500, 6233.3)-(550, 6233.3)
Picture1.ForeColor = vbWhite
Picture1.Line (450, 400)-(27500, 400)
Picture1.Line (450, 1900)-(27500, 1900)
Picture1.Line (450, 3400)-(27500, 3400)
Picture1.Line (450, 4900)-(27500, 4900)
Picture1.Line (450, 6400)-(27500, 6400)
Picture1.Line (450, 2200)-(500, 2200)
Picture1.Line (450, 2500)-(500, 2500)
Picture1.Line (450, 2800)-(500, 2800)
Picture1.Line (450, 3100)-(500, 3100)
Picture1.Line (450, 3700)-(500, 3700)
Picture1.Line (450, 4000)-(500, 4000)
Picture1.Line (450, 4300)-(500, 4300)
Picture1.Line (450, 4600)-(500, 4600)
Picture1.Line (450, 5200)-(500, 5200)
Picture1.Line (450, 5500)-(500, 5500)
Picture1.Line (450, 5800)-(500, 5800)
Picture1.Line (450, 6100)-(500, 6100)
Picture1.Line (500, 400)-(500, 6400)
Picture1.Line (500 + 0, 400)-(500 + 0, 6400)
Picture1.Line (1400 + 0, 400)-(1400 + 0, 6400)
Picture1.Line (2300 + 0, 400)-(2300 + 0, 6400)
Picture1.Line (3200 + 0, 400)-(3200 + 0, 6400)
Picture1.Line (4100 + 0, 400)-(4100 + 0, 6400)
Picture1.Line (5000 + 0, 400)-(5000 + 0, 6400)
Picture1.Line (5900 + 0, 400)-(5900 + 0, 6400)
Picture1.Line (6800 + 0, 400)-(6800 + 0, 6400)
Picture1.Line (7700 + 0, 400)-(7700 + 0, 6400)
Picture1.Line (8600 + 0, 400)-(8600 + 0, 6400)
Picture1.Line (9500 + 0, 400)-(9500 + 0, 6400)
Picture1.Line (10400 + 0, 400)-(10400 + 0, 6400)
Picture1.Line (11300, 400)-(11300, 6400)
Picture1.Line (12200, 400)-(12200, 6400)
Picture1.Line (13100, 400)-(13100, 6400)
Picture1.Line (14000, 400)-(14000, 6400)
Picture1.Line (14900, 400)-(14900, 6400)
Picture1.Line (15800, 400)-(15800, 6400)
Picture1.Line (16700, 400)-(16700, 6400)
Picture1.Line (17600, 400)-(17600, 6400)
Picture1.Line (18500, 400)-(18500, 6400)
Picture1.Line (19400, 400)-(19400, 6400)
Picture1.Line (20300, 400)-(20300, 6400)
Picture1.Line (21200, 400)-(21200, 6400)
Picture1.Line (22100, 400)-(22100, 6400)
Picture1.Line (23000, 400)-(23000, 6400)
Picture1.Line (23900, 400)-(23900, 6400)
Picture1.Line (24800, 400)-(24800, 6400)
Picture1.Line (25700, 400)-(25700, 6400)
Picture1.Line (26600, 400)-(26600, 6400)
Picture1.Line (27500, 400)-(27500, 6400)
Picture1.Line (0 * 5 + 500, 3400 - b(0) * 30)-(c(1) * 5 + 500, 3400 - b(0) * 30), QBColor(12)
Picture1.Line (c(1) * 5 + 498, 3400 - b(1) * 30)-(c(2) * 5 + 502, 3400 - b(1) * 30), QBColor(12)
Picture1.Line (c(2) * 5 + 498, 3400 - b(2) * 30)-(c(3) * 5 + 502, 3400 - b(2) * 30), QBColor(12)
Picture1.Line (c(3) * 5 + 498, 3400 - b(3) * 30)-(c(4) * 5 + 502, 3400 - b(3) * 30), QBColor(12)
Picture1.Line (c(4) * 5 + 498, 3400 - b(4) * 30)-(c(5) * 5 + 502, 3400 - b(4) * 30), QBColor(12)
Picture1.Line (c(5) * 5 + 498, 3400 - b(5) * 30)-(c(6) * 5 + 502, 3400 - b(5) * 30), QBColor(12)
Picture1.Line (c(6) * 5 + 498, 3400 - b(6) * 30)-(c(7) * 5 + 502, 3400 - b(6) * 30), QBColor(12)
Picture1.Line (c(7) * 5 + 498, 3400 - b(7) * 30)-(c(8) * 5 + 502, 3400 - b(7) * 30), QBColor(12)
Picture1.Line (c(8) * 5 + 498, 3400 - b(8) * 30)-(c(9) * 5 + 502, 3400 - b(8) * 30), QBColor(12)
Picture1.Line (c(9) * 5 + 498, 3400 - b(9) * 30)-(c(10) * 5 + 502, 3400 - b(9) * 30), QBColor(12)
Picture1.Line (c(10) * 5 + 498, 3400 - b(10) * 30)-(c(11) * 5 + 502, 3400 - b(10) * 30), QBColor(12)
Picture1.Line (c(11) * 5 + 498, 3400 - b(11) * 30)-(c(12) * 5 + 502, 3400 - b(11) * 30), QBColor(12)
Picture1.Line (c(12) * 5 + 498, 3400 - b(12) * 30)-(c(13) * 5 + 502, 3400 - b(12) * 30), QBColor(12)
Picture1.Line (c(13) * 5 + 498, 3400 - b(13) * 30)-(c(14) * 5 + 502, 3400 - b(13) * 30), QBColor(12)
Picture1.Line (c(14) * 5 + 498, 3400 - b(14) * 30)-(c(15) * 5 + 502, 3400 - b(14) * 30), QBColor(12)
Picture1.Line (c(15) * 5 + 498, 3400 - b(15) * 30)-(c(16) * 5 + 502, 3400 - b(15) * 30), QBColor(12)
chaxun1 = "select * from jishijilu where gyh_riqi='" & gongyi_sj(0) & "-" & record_rq & "'order by shijian "
mdh = chaxun1
Adodc3.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Ldgz\wd.mdb;Persist Security Info=False"
Adodc3.RecordSource = mdh
Adodc3.Refresh
zslNew = Adodc3.Recordset.RecordCount
Text4 = zslNew
If zslNew >= 1 Then
Adodc3.Recordset.MoveFirst
For i = 0 To zslNew - 1
quexian(0, i) = Adodc3.Recordset(0)
For j = 2 To 7
quexian(j, i) = Adodc3.Recordset(j)
Next j
Adodc3.Recordset.MoveNext
Next i
Adodc3.Recordset.MoveFirst
For j = 0 To zslNew - 1
Picture1.Line (j * 5 + 500, quexian(2, j) * -30 + 3399)-(j * 5 + 500, quexian(2, j) * -30 + 3401), vbRed, BF
Picture1.Line (j * 5 + 500, quexian(3, j) * -30 + 3399)-(j * 5 + 500, quexian(3, j) * -30 + 3401), QBColor(7), BF
Picture1.Line (j * 5 + 500, quexian(4, j) * -30 + 3399)-(j * 5 + 500, quexian(4, j) * -30 + 3401), vbWhite, BF
Picture1.Line (j * 5 + 500, quexian(5, j) * -30 + 3399)-(j * 5 + 500, quexian(5, j) * -30 + 3401), vbYellow, BF
Picture1.Line (j * 5 + 500, quexian(6, j) * -30 + 3399)-(j * 5 + 500, quexian(6, j) * -30 + 3401), vbGreen, BF
If quexian(8, j) < 1 Then
wy_wy = 0 + 166.7
br_br = 55
ElseIf quexian(8, j) >= 1 And quexian(8, j) < 10 Then
wy_wy = -1500 + 166.7
br_br = 5.5556
ElseIf quexian(8, j) >= 10 And quexian(8, j) < 100 Then
wy_wy = -3000 + 166.7
br_br = 0.5555
ElseIf quexian(8, j) >= 100 And quexian(8, j) < 1000 Then
wy_wy = -4500 + 166.7
br_br = 0.055555
End If
Picture1.Line (j * 5 + 500, quexian(8, j) * br_br * -30 + wy_wy + 3397 + 3000)-(j * 5 + 500, quexian(8, j) * br_br * -30 + wy_wy + 3403 + 3000), QBColor(11), BF
Next j
zslOld = zslNew
End If
zslOld = zslNew
End Sub
'通过计时器调用定时更新
Private Sub cmdRef_Click()
chaxun1 = "select * from jishijilu where gyh_riqi='" & gongyi_sj(0) & "-" & record_rq & "'order by shijian "
mdh = chaxun1
Adodc3.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Ldgz\wd.mdb;Persist Security Info=False"
Adodc3.RecordSource = mdh
Adodc3.Refresh
zslNew = Adodc3.Recordset.RecordCount
Text4 = zslNew
If zslNew > 1 Then
Adodc3.Recordset.MoveLast
For j = 2 To 7
quexian(j, i) = Adodc3.Recordset(j)
Next j
Picture2.Height = 10000
Picture1.Visible = True
If zslOld >= 1 Then
For j = zslOld - 1 To zslNew - 1
Picture1.Line (j * 5 + 500, quexian(2, j) * -30 + 3399)-(j * 5 + 500, quexian(2, j) * -30 + 3401), vbRed, BF
Picture1.Line (j * 5 + 500, quexian(3, j) * -30 + 3399)-(j * 5 + 500, quexian(3, j) * -30 + 3401), QBColor(7), BF
Picture1.Line (j * 5 + 500, quexian(4, j) * -30 + 3399)-(j * 5 + 500, quexian(4, j) * -30 + 3401), vbWhite, BF
Picture1.Line (j * 5 + 500, quexian(5, j) * -30 + 3399)-(j * 5 + 500, quexian(5, j) * -30 + 3401), vbYellow, BF
Picture1.Line (j * 5 + 500, quexian(6, j) * -30 + 3399)-(j * 5 + 500, quexian(6, j) * -30 + 3401), vbGreen, BF
If quexian(8, j) < 1 Then
wy_wy = 0 + 166.7
br_br = 55
ElseIf quexian(8, j) >= 1 And quexian(8, j) < 10 Then
wy_wy = -1500 + 166.7
br_br = 5.5556
ElseIf quexian(8, j) >= 10 And quexian(8, j) < 100 Then
wy_wy = -3000 + 166.7
br_br = 0.5555
ElseIf quexian(8, j) >= 100 And quexian(8, j) < 1000 Then
wy_wy = -4500 + 166.7
br_br = 0.055555
End If
Picture1.Line (j * 5 + 500, quexian(8, j) * br_br * -30 + wy_wy + 3395 + 3000)-(j * 5 + 500, quexian(8, j) * br_br * -30 + wy_wy + 3405 + 3000), QBColor(11), BF
Next j
End If
'记录时间Z长96小时
cmdPrint.Enabled = True
End If
zslOld = zslNew
End Sub
全部评论
havehou932 发布日期:2007-04-26
我看你主要是难在画图吧,你可以用MSCHART控件,具体用法可以参考MSDN
最新主题
相关版块
我要评论
X您尚未登录
账号登录
X您尚未登录
手机动态密码登录
X您尚未登录
扫码登录
官方微信

仪器网微信服务号

扫码获取最新信息


仪器网官方订阅号

扫码获取最新信息

在线客服

咨询客服

在线客服
工作日:  9:00-18:00
联系客服 企业专属客服
电话客服:  400-822-6768
工作日:  9:00-18:00
订阅商机

仪采招微信公众号

采购信息一键获取海量商机轻松掌控