如何用VB做温度和时间曲线
现在做一个温度传感器的温度记录:需要做两个问题1.用串口和传感器连接如何用VB实现温度随时间变化的曲线实时输出(横坐标:时间,纵坐标:温度)两个数间隔是24秒有时是25秒...
现在做一个温度传感器的温度记录: 需要做两个问题
1.用串口和传感器连接
如何用VB实现温度随时间变化的曲线实时输出(横坐标:时间,纵坐标:温度)两个数间隔是24秒有时是25秒(最好简单点的)
2.从数据库(SQL2000)里调出数据(按日期),格式如下:
2007-8-7 下午 09:35:18 28.0051
2007-8-7 下午 09:35:42 28.0033
2007-8-7 下午 09:36:06 28.0015
2007-8-7 下午 09:36:31 27.9997
2007-8-7 下午 09:36:55 27.9979
2007-8-7 下午 09:37:19 27.9961
2007-8-7 下午 09:43:01 27.9744
2007-8-7 下午 09:43:25 27.9708
2007-8-7 下午 09:43:51 27.9693
2007-8-7 下午 09:44:15" 27.9678
有时时间间隔是24秒有时是25秒,请问如何做一天的曲线图?
3.请给出详细代码,如果好用,加分.十分谢谢.
与数据库是用ADO连接的,用datafird 读取SQL中数据,而且个数不确定,请给出详细代码 展开
1.用串口和传感器连接
如何用VB实现温度随时间变化的曲线实时输出(横坐标:时间,纵坐标:温度)两个数间隔是24秒有时是25秒(最好简单点的)
2.从数据库(SQL2000)里调出数据(按日期),格式如下:
2007-8-7 下午 09:35:18 28.0051
2007-8-7 下午 09:35:42 28.0033
2007-8-7 下午 09:36:06 28.0015
2007-8-7 下午 09:36:31 27.9997
2007-8-7 下午 09:36:55 27.9979
2007-8-7 下午 09:37:19 27.9961
2007-8-7 下午 09:43:01 27.9744
2007-8-7 下午 09:43:25 27.9708
2007-8-7 下午 09:43:51 27.9693
2007-8-7 下午 09:44:15" 27.9678
有时时间间隔是24秒有时是25秒,请问如何做一天的曲线图?
3.请给出详细代码,如果好用,加分.十分谢谢.
与数据库是用ADO连接的,用datafird 读取SQL中数据,而且个数不确定,请给出详细代码 展开
5个回答
推荐于2016-07-02 · 知道合伙人软件行家
关注
展开全部
VB可通过Timer控件的Timer事件中使用Line方法或PSet 方法绘制线条、色彩实现实时显示采集数据的曲线。
Line方法,在对象上画直线和矩形。
PSet 方法,将对象上的点设置为指定颜色。
Print方法,可打印数字项的值。
在指定位置显示 Print 输出,使用 CurrentX 和 CurrentY 属性,设置绘图坐标。
实例代码:
Option Explicit
Dim quitflag As Boolean
Dim cmdXianshiFlag As Boolean
Dim cmdTestFlag As Boolean
Dim p As Integer
Dim h As Integer
Dim miao1 As Integer
Dim fen1 As Integer
Dim j As Integer
Dim ii As Integer
Private br_br As Double
Private ab_bm As Double
Private wy_wy As Double
Private shijian(360) As String * 10
Private shijian_zh(360) As String * 10
Private record_zh(5, 360) As Single
Private record(5, 360) As Single
Private c(360) As Variant
Const a = 3.141592654 * 2
Public Function xp(colvb As Variant, xx As Variant, yy As Variant, txt As Variant)
Picture1.ForeColor = colvb 'QBColor(14)
Picture1.CurrentX = xx
Picture1.CurrentY = yy
Picture1.Print txt '
End Function
Private Sub CmdTest_Click()
If cmdTestFlag Then
For j = 0 To 359
record(0, j) = 0
record(1, j) = 0
record(2, j) = 0
record(3, j) = 0
record(4, j) = 0
record(5, j) = 0
Next j
cmdTest.Caption = "试验"
Else
For j = 0 To 359
c(j) = j * a / 60
record(0, j) = Sin(c(j)) * -450
record(1, j) = Sin(c(j)) * -300
record(2, j) = Sin(c(j) + a / 3) * -450
record(3, j) = Sin(c(j) + 2 * a / 3) * -450
record(4, j) = Sin(c(j) + 2 * a / 3) * -300
record(5, j) = Sin(c(j) + 2 * a / 3) * -150
Next j
cmdTest.Caption = "记录"
End If
cmdTestFlag = Not cmdTestFlag
End Sub
Private Sub Timer1_Timer()
If lblTime.Caption <> CStr(Time$) Then
lblTime.Caption = Time$
Frmjly.Caption = "记录仪" & Space(90) & Date$ & Space(6) & Time$
miao1 = Mid(lblTime, 7, 2)
fen1 = Mid(Time$, 4, 2)
If fen1 = 0 And miao1 = 0 Then
shijian(0) = lblTime
End If
Label1 = lblTime
If miao1 = 0 Then
For k = 0 To 358
record_zh(0, k + 1) = record(0, k)
record_zh(1, k + 1) = record(1, k)
record_zh(2, k + 1) = record(2, k)
record_zh(3, k + 1) = record(3, k)
record_zh(4, k + 1) = record(4, k)
record_zh(5, k + 1) = record(5, k)
Next k
For j = 1 To 359 '9
record(0, j) = record_zh(0, j)
record(1, j) = record_zh(1, j)
record(2, j) = record_zh(2, j)
record(3, j) = record_zh(3, j)
record(4, j) = record_zh(4, j)
record(5, j) = record_zh(5, j)
Next j
End If
If fen1 = 0 And miao1 = 1 Then
For ii = 0 To 5
shijian_zh(ii + 1) = shijian(ii)
Next ii
For h = 1 To 6
shijian(h) = shijian_zh(h)
Next h
Label1.Visible = False
Label2.Visible = True
End If
End If
End Sub
Private Sub Timer2_Timer()
BitBlt Me.Picture1.hDC, 0, 0, Me.Picture1.ScaleWidth, Me.Picture1.ScaleHeight, 0, 0, 0, vbBlack 'ness
Text1 = Time$
miao = Right$(Time$, 2)
Text2 = fen1
record(0, 0) = record_jm(3) * -30
record(1, 0) = record_jm(4) * -30
record(2, 0) = record_jm(5) * -30
record(3, 0) = record_jm(0) * -30
record(4, 0) = record_jm(1) * -30
record(5, 0) = record_jm(10) * -30 '干箱真空
mmm = Val(fen1 * 60) + Val(miao)
j = mmm
p = (j / 360) - Int(j / 360)
j = p * 360
Text2 = Date$
Label8 = Date$
Label2 = shijian(1)
Label2.Left = fen1 * 30 + 140
Label3 = shijian(2)
Label3.Left = fen1 * 30 + 1800 * 1 + 140
Label4 = shijian(3)
Label4.Left = fen1 * 30 + 1800 * 2 + 140
Label5 = shijian(4)
Label5.Left = fen1 * 30 + 1800 * 3 + 140
Label6 = shijian(5)
Label6.Left = fen1 * 30 + 1800 * 4 + 140
Label7 = shijian(6)
Label7.Left = fen1 * 30 + 1800 * 5 + 140
'温度坐标
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)
'真空坐标
colvb = vbRed
xx = 11500
yy = 150
txt = "Pa"
wp = xp(colvb, xx, yy, txt)
yy = 350
txt = "10000"
wp = xp(colvb, xx, yy, txt)
xx = 11500
yy = 1850
txt = "1000"
wp = xp(colvb, xx, yy, txt)
yy = 3350
xx = 11500
txt = "100"
wp = xp(colvb, xx, yy, txt)
xx = 11500
yy = 4850
txt = "10"
wp = xp(colvb, xx, yy, txt)
xx = 11500
yy = 6350
txt = "1"
wp = xp(colvb, xx, yy, txt)
xx = 500
yy = 150
txt = "Pa"
wp = xp(colvb, xx, yy, txt)
yy = 350
txt = "10000"
wp = xp(colvb, xx, yy, txt)
xx = 500
yy = 1850
txt = "1000"
wp = xp(colvb, xx, yy, txt)
yy = 3350
xx = 500
txt = "100"
wp = xp(colvb, xx, yy, txt)
xx = 500
yy = 4850
txt = "10"
wp = xp(colvb, xx, yy, txt)
xx = 500
yy = 6350
txt = "1"
wp = xp(colvb, xx, yy, txt)
'画格
Picture1.ForeColor = vbWhite
Picture1.Line (450, 400)-(11300, 400)
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, 1900)-(11300, 1900)
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, 3400)-(11300, 3400)
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, 4900)-(11300, 4900)
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 (450, 6400)-(11300, 6400)
Picture1.Line (500, 400)-(500, 6400)
Picture1.Line (11300, 400)-(11300, 6400)
'画时间坐标
If -700 + fen1 * 30 > 200 Then
Picture1.Line (-400 + fen1 * 30, 400)-(-400 + fen1 * 30, 6400)
End If
Picture1.Line (500 + fen1 * 30, 400)-(500 + fen1 * 30, 6400)
Picture1.Line (1400 + fen1 * 30, 400)-(1400 + fen1 * 30, 6400)
Picture1.Line (2300 + fen1 * 30, 400)-(2300 + fen1 * 30, 6400)
Picture1.Line (3200 + fen1 * 30, 400)-(3200 + fen1 * 30, 6400)
Picture1.Line (4100 + fen1 * 30, 400)-(4100 + fen1 * 30, 6400)
Picture1.Line (5000 + fen1 * 30, 400)-(5000 + fen1 * 30, 6400)
Picture1.Line (5900 + fen1 * 30, 400)-(5900 + fen1 * 30, 6400)
Picture1.Line (6800 + fen1 * 30, 400)-(6800 + fen1 * 30, 6400)
Picture1.Line (7700 + fen1 * 30, 400)-(7700 + fen1 * 30, 6400)
Picture1.Line (8600 + fen1 * 30, 400)-(8600 + fen1 * 30, 6400)
Picture1.Line (9500 + fen1 * 30, 400)-(9500 + fen1 * 30, 6400)
If 10400 + fen1 * 30 < 11300 Then
Picture1.Line (10400 + fen1 * 30, 400)-(10400 + fen1 * 30, 6400)
End If
If 11300 + fen1 * 30 < 11300 Then
Picture1.Line (11300 + fen1 * 30, 400)-(11300 + fen1 * 30, 6400)
End If
'显示记录
Picture1.ForeColor = vbYellow
For j = 0 To 359
Picture1.Line (j * 30 + 500, record(0, j) + 3395)-(j * 30 + 502, record(0, j) + 3405), vbRed, BF
Picture1.Line (j * 30 + 500, record(1, j) + 3395)-(j * 30 + 502, record(1, j) + 3405), QBColor(7), BF
Picture1.Line (j * 30 + 500, record(2, j) + 3395)-(j * 30 + 502, record(2, j) + 3405), vbWhite, BF
Picture1.Line (j * 30 + 500, record(3, j) + 3395)-(j * 30 + 502, record(3, j) + 3405), vbYellow, BF
Picture1.Line (j * 30 + 500, record(4, j) + 3395)-(j * 30 + 502, record(4, j) + 3405), vbGreen, BF
If record(5, j) / -30 < 10 Then
wy_wy = -0 + 166.7
br_br = 5.5556
ElseIf record(5, j) / -30 >= 10 And record(5, j) / -30 < 100 Then
wy_wy = -1500 + 166.7
br_br = 0.5555
ElseIf record(5, j) / -30 >= 100 And record(5, j) / -30 < 1000 Then
wy_wy = -3000 + 166.7
br_br = 0.055555
ElseIf record(5, j) / -30 >= 1000 And record(5, j) / -30 < 10000 Then
wy_wy = -4500 + 166.7
br_br = 0.0055555
End If
Picture1.Line (j * 30 + 500, record(5, j) * br_br + wy_wy + 3395 + 3000)-(j * 30 + 502, record(5, j) * br_br + wy_wy + 3405 + 3000), QBColor(11), BF
Next j
Picture1.Refresh
End Sub
展开全部
算法:
1.每秒时间间隔单位计为100点。
2.用line控件。
3.第一个line的Y值是((360/第一个记录里面的时间)*100)
4.剩下line控件的左端是((360/当前记录里面的时间)*100)
5.line总数为(数据库记录数-1)
明白了把?
1.每秒时间间隔单位计为100点。
2.用line控件。
3.第一个line的Y值是((360/第一个记录里面的时间)*100)
4.剩下line控件的左端是((360/当前记录里面的时间)*100)
5.line总数为(数据库记录数-1)
明白了把?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
我回答了一个和你相似的问题,你可以去看看
并且我把代码已经写出来了,上面的有些东西你改改就可以用了
http://zhidao.baidu.com/question/29995182.html
关于时间间隔的问题使用
datediff函数就可以搞定了
并且我把代码已经写出来了,上面的有些东西你改改就可以用了
http://zhidao.baidu.com/question/29995182.html
关于时间间隔的问题使用
datediff函数就可以搞定了
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
参考MeasureEasy,vb编的实时温度监控软件
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
加我QQ:905906 我给你写一段代码.
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询