vb程序实现串口通信,将接到的数据动态保存,并可以图表绘制曲线(X:时间,Y:数据)

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

vb程序实现串口通信,将接到的数据动态保存,并可以图表绘制曲线(X:时间,Y:数据)将接到的数据赋值于全局变量,通过ADO数据控件连接数据库及表,用以下代码保存数据: Private Sub Timer1_Timer()
If Label1.Caption <> CStr(Time$) Then
Label1.Caption = Time$
sum_zj = sum_zj + 1
Text3 = sum_zj
'校准
If sum_zj >= 3 Then
sum_zj1 = sum_zj1 + 1
sum_zj = sum_zj - 3
Text4 = sum_zj1
Adodc1.Recordset.AddNew '每3秒记录一组数据
Adodc1.Recordset(0) = shiY AnH
Adodc1.Recordset(1) = Mid(Time$, 1, 2) & Mid(Time$, 4, 2) & Mid(Time$, 7, 2) '记录time Adodc1.Recordset(2) = record_jm(0) '记录数据
Adodc1.Recordset(3) = record_jm(1) '记录数据
Adodc1.Recordset(4) = record_jm(2) '记录数据
Adodc1.Recordset(5) = record_jm(3) '记录数据
Adodc1.Recordset(6) = record_jm(4) '记录数据
Adodc1.Recordset(7) = record_jm(5) '记录数据
Adodc1.Recordset(8) = record_jm(6) '记录数据
Adodc1.Recordset(9) = record_jm(7) '记录数据
Adodc1.Recordset(10) = record_jm(8) '记录数据
Adodc1.Recordset(11) = record_jm(9) '记录数据
Adodc1.Recordset(12) = record_jm(10) '记录数据
Adodc1.Recordset(13) = record_jm(11) '记录数据
Adodc1.Recordset.Update
End If
End If
End Sub
Private Sub Timer2_Timer()
Picture4.DrawStyle = 0
以下代码绘制实时曲线(6点):
Picture4.DrawWidth = 3 ' = dash
Picture4.Line (sum_z1 * 18 + 500, record_jm(0) * -150 + 7900)-(sum_z1 * 18 + 500, record_jm(2) * -150 + 7900), vbRed ', BF
Picture4.Line (sum_z1 * 18 + 500, record_jm(1) * -150 + 7900)-(sum_z1 * 18 + 500, record_jm(3) * -150 + 7900), vbCyan ', BF
Picture4.Line (sum_z1 * 18 + 500, record_jm(2) * -150 + 7900)-(sum_z1 * 18 + 500, record_jm(4) * -150 + 7900), vbBlack ', BF
Picture4.Line (sum_z1 * 18 + 500, record_jm(3) * -150 + 7900)-(sum_z1 * 18 + 500, record_jm(5) * -150 + 7900), vbMagenta ', BF
Picture4.Line (sum_z1 * 18 + 500, record_jm(4) * -150 + 7900)-(sum_z1 * 18 + 500, record_jm(6) * -150 + 7900), vbGreen ', BF
Picture4.Line (sum_z1 * 18 + 500, record_jm(5) * -150 + 7900)-(sum_z1 * 18 + 500, record_jm(7) * -150 + 7900), vbBlue ', BF
End Sub
Private Sub Timer3_Timer()
If Label32 <> CStr(Time$) Then 'Label1.Caption
Label32.Caption = Time$
sum_z = sum_z + 1
Text31 = sum_z
'校准
If sum_z >= 5 Then
sum_z = sum_z - 5
sum_z1 = sum_z1 + 1
Text30 = sum_z1
End If
End If
End Sub
以下代码绘制曲线的坐标:
Private Sub Form_Load()
With Adodc1
Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\kongtiao\cartemp.mdb;Persist Security Info=False"
Adodc1.RecordSource = "select * form car_bm"
End With
Text1 = ""
Text2 = "": Text3 = "": Text4 = "":
Text5 = "": Text6 = "": Text7 = "": Text12 = ""
Text8 = "": Text9 = "": Text10 = "": Text11 = ""
Text13 = "": Text14 = "": Text15 = "": Text16 = ""
'Load frmMain
colvb = vbBlack
xx = 100
yy = 150
txt = "℃"
wp = xp(colvb, xx, yy, txt)
xx = 200
yy = 350
txt = "50"
wp = xp(colvb, xx, yy, txt)
xx = 200
yy = 1850
wp = xp(colvb, xx, yy, txt) yy = 3350
xx = 200
txt = "30"
wp = xp(colvb, xx, yy, txt) xx = 200
yy = 4850
txt = "20"
wp = xp(colvb, xx, yy, txt) xx = 200
yy = 6350
txt = "10"
wp = xp(colvb, xx, yy, txt) 'Time坐标
colvb = vbRed
yy = 6500
xx = 400
txt = "0"
wp = xp(colvb, xx, yy, txt) xx = 1480
txt = "5"
wp = xp(colvb, xx, yy, txt) xx = 2560
txt = "10"
wp = xp(colvb, xx, yy, txt) xx = 3640
txt = "15"
wp = xp(colvb, xx, yy, txt) xx = 4720
txt = "20"
wp = xp(colvb, xx, yy, txt) xx = 5800
txt = "25 min"
wp = xp(colvb, xx, yy, txt) xx = 6880
txt = "30"
wp = xp(colvb, xx, yy, txt) xx = 7960
txt = "35"
wp = xp(colvb, xx, yy, txt) xx = 9040
txt = "40"
wp = xp(colvb, xx, yy, txt)
txt = "45"
wp = xp(colvb, xx, yy, txt)
xx = 11200
txt = "50"
wp = xp(colvb, xx, yy, txt)
'画格
Picture1.DrawWidth = 1 ' = dash
Picture1.DrawStyle = 0
Picture1.ForeColor = vbCyan
For i = 0 To 39
Picture4.Line (450, 550 + i * 150)-(500, 550 + i * 150) Next
Picture4.DrawStyle = 2
For i = 0 To 8
Picture4.Line (450, 400 + i * 750)-(11300, 400 + i * 750) Next
For i = 0 To 15
Picture4.Line (450, 1000 + i * 300)-(500, 1000 + i * 300) Next
For i = 0 To 10
Picture4.Line (500 + i * 1080, 400)-(500 + i * 1080, 6400) Next
Picture4.DrawStyle = 0
End Sub。

相关文档
最新文档