
串口获取数据的话,首先要初始化串口,这个你首先要知道你的传口设备的一个参数(彼特率等)初始化后,那么使用API也可以VB里面的函数也可以,直接就可以获取到串口的数据,有些设备是有指令的,必须要先去一个指令才会给你发数据,这个都要先了解要处理的设备。
或者设备后,在可以将获得数据当作数据源赋给你想要显示的图形文件!
不是很明白你的题意
strHex = strHex + [String]Format("{0:X2} "
这里的意思是把每个字节数据转换成了十六进制,每个字节占两个字符
如果你串口收到的4个字节数据:43,27,56,200
那么你的结果是:2B1B38C8
即receivebytesText="2B1B38C8"
不足两位的补0
如果你串口收到的4个字节数据:3,27,56,200
那么你的结果是:031B38C8
即receivebytesText="031B38C8"
Option Explicit
Dim strss As String
Private Sub Form_Load()
MSComm1CommPort = 1 '串口号,
MSComm1Settings = "9600,n,8,1 " '串口的属性
MSComm1InputLen = 0
MSComm1InputMode = comInputModeText
MSComm1RThreshold = 1
MSComm1PortOpen = True
End Sub
Private Sub MSComm1_OnComm()
Select Case MSComm1CommEvent
Case comEvReceive
strss = strss & MSComm1Input
If Right(strss, 2) = vbCrLf Then
Label1Caption = strss
Open "D:\DATAtxt" For Append As #1
Print #1, Mid(strss, 1, Len(strss) - 2) '去除回车换行
Close
strss = ""
End If
End Select
End Sub
实时采集的数据可直接用来画曲线,但往往为了以后查询,同时应按定时间隔写入数据库或文本文件。所以可在写入数据库后通过查询做到实时显示和更新。
'窗体加载时将已记录的数据查询后绘图
Private Sub Form_Load()
chaxun1 = "select from jishijilu where gyh_riqi='" & gongyi_sj(0) & "-" & record_rq & "'order by shijian "
mdh = chaxun1
Adodc3ConnectionString = "Provider=MicrosoftJetOLEDB40;Data Source=C:\Ldgz\wdmdb;Persist Security Info=False"
Adodc3RecordSource = mdh
Adodc3Refresh
zslNew = Adodc3RecordsetRecordCount
Text4 = zslNew
If zslNew >= 1 Then
Adodc3RecordsetMoveFirst
For i = 0 To zslNew - 1
quexian(0, i) = Adodc3Recordset(0)
For j = 2 To 9
quexian(j, i) = Adodc3Recordset(j)
Next j
Adodc3RecordsetMoveNext
Next i
Adodc3RecordsetMoveFirst
For j = 0 To zslNew - 1
Picture1Line (j 5 + 500, quexian(2, j) -30 + 3399)-(j 5 + 500, quexian(2, j) -30 + 3401), vbRed, BF
Picture1Line (j 5 + 500, quexian(3, j) -30 + 3399)-(j 5 + 500, quexian(3, j) -30 + 3401), QBColor(7), BF
Picture1Line (j 5 + 500, quexian(4, j) -30 + 3399)-(j 5 + 500, quexian(4, j) -30 + 3401), vbWhite, BF
Picture1Line (j 5 + 500, quexian(5, j) -30 + 3399)-(j 5 + 500, quexian(5, j) -30 + 3401), vbYellow, BF
Picture1Line (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 + 1667
br_br = 55
ElseIf quexian(8, j) >= 1 And quexian(8, j) < 10 Then
wy_wy = -1500 + 1667
br_br = 55556
ElseIf quexian(8, j) >= 10 And quexian(8, j) < 100 Then
wy_wy = -3000 + 1667
br_br = 05555
ElseIf quexian(8, j) >= 100 And quexian(8, j) < 1000 Then
wy_wy = -4500 + 1667
br_br = 0055555
End If
Picture1Line (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
'记录时间最长75小时
Picture2Height = 10000
Picture2Visible = True
Picture1Visible = 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 = "01"
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 = "01"
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 = " 01"
wp = xp(colvb, xx, yy, txt)
'画格
Picture1ForeColor = vbWhite
Picture1Line (450, 700)-(500, 700)
Picture1Line (450, 1000)-(500, 1000)
Picture1Line (450, 1300)-(500, 1300)
Picture1Line (450, 1600)-(500, 1600)
Picture1ForeColor = vbRed
Picture1Line (500, 5667)-(550, 5667)
Picture1Line (500, 7333)-(550, 7333)
Picture1Line (500, 900)-(550, 900)
Picture1Line (500, 10667)-(550, 10667)
Picture1Line (500, 12333)-(550, 12333)
Picture1Line (500, 1400)-(550, 1400)
Picture1Line (500, 15667)-(550, 15667)
Picture1Line (500, 17333)-(550, 17333)
Picture1Line (500, 20667)-(550, 20667)
Picture1Line (500, 22333)-(550, 22333)
Picture1Line (500, 2400)-(550, 2400)
Picture1Line (500, 25667)-(550, 25667)
Picture1Line (500, 27333)-(550, 27333)
Picture1Line (500, 2900)-(550, 2900)
Picture1Line (500, 30667)-(550, 30667)
Picture1Line (500, 32333)-(550, 32333)
Picture1Line (500, 35667)-(550, 35667)
Picture1Line (500, 37333)-(550, 37333)
Picture1Line (500, 3900)-(550, 3900)
Picture1Line (500, 40667)-(550, 40667)
Picture1Line (500, 42333)-(550, 42333)
Picture1Line (500, 4400)-(550, 4400)
Picture1Line (500, 45667)-(550, 45667)
Picture1Line (500, 47333)-(550, 47333)
Picture1Line (500, 50667)-(550, 50667)
Picture1Line (500, 52333)-(550, 52333)
Picture1Line (500, 5400)-(550, 5400)
Picture1Line (500, 55667)-(550, 55667)
Picture1Line (500, 57333)-(550, 57333)
Picture1Line (500, 5900)-(550, 5900)
Picture1Line (500, 60667)-(550, 60667)
Picture1Line (500, 62333)-(550, 62333)
Picture1ForeColor = vbWhite
Picture1Line (450, 400)-(27500, 400)
Picture1Line (450, 1900)-(27500, 1900)
Picture1Line (450, 3400)-(27500, 3400)
Picture1Line (450, 4900)-(27500, 4900)
Picture1Line (450, 6400)-(27500, 6400)
Picture1Line (450, 2200)-(500, 2200)
Picture1Line (450, 2500)-(500, 2500)
Picture1Line (450, 2800)-(500, 2800)
Picture1Line (450, 3100)-(500, 3100)
Picture1Line (450, 3700)-(500, 3700)
Picture1Line (450, 4000)-(500, 4000)
Picture1Line (450, 4300)-(500, 4300)
Picture1Line (450, 4600)-(500, 4600)
Picture1Line (450, 5200)-(500, 5200)
Picture1Line (450, 5500)-(500, 5500)
Picture1Line (450, 5800)-(500, 5800)
Picture1Line (450, 6100)-(500, 6100)
Picture1Line (500, 400)-(500, 6400)
Picture1Line (500 + 0, 400)-(500 + 0, 6400)
Picture1Line (1400 + 0, 400)-(1400 + 0, 6400)
Picture1Line (2300 + 0, 400)-(2300 + 0, 6400)
Picture1Line (3200 + 0, 400)-(3200 + 0, 6400)
Picture1Line (4100 + 0, 400)-(4100 + 0, 6400)
Picture1Line (5000 + 0, 400)-(5000 + 0, 6400)
Picture1Line (5900 + 0, 400)-(5900 + 0, 6400)
Picture1Line (6800 + 0, 400)-(6800 + 0, 6400)
Picture1Line (7700 + 0, 400)-(7700 + 0, 6400)
Picture1Line (8600 + 0, 400)-(8600 + 0, 6400)
Picture1Line (9500 + 0, 400)-(9500 + 0, 6400)
Picture1Line (10400 + 0, 400)-(10400 + 0, 6400)
Picture1Line (11300, 400)-(11300, 6400)
Picture1Line (12200, 400)-(12200, 6400)
Picture1Line (13100, 400)-(13100, 6400)
Picture1Line (14000, 400)-(14000, 6400)
Picture1Line (14900, 400)-(14900, 6400)
Picture1Line (15800, 400)-(15800, 6400)
Picture1Line (16700, 400)-(16700, 6400)
Picture1Line (17600, 400)-(17600, 6400)
Picture1Line (18500, 400)-(18500, 6400)
Picture1Line (19400, 400)-(19400, 6400)
Picture1Line (20300, 400)-(20300, 6400)
Picture1Line (21200, 400)-(21200, 6400)
Picture1Line (22100, 400)-(22100, 6400)
Picture1Line (23000, 400)-(23000, 6400)
Picture1Line (23900, 400)-(23900, 6400)
Picture1Line (24800, 400)-(24800, 6400)
Picture1Line (25700, 400)-(25700, 6400)
Picture1Line (26600, 400)-(26600, 6400)
Picture1Line (27500, 400)-(27500, 6400)
Picture1Line (0 5 + 500, 3400 - b(0) 30)-(c(1) 5 + 500, 3400 - b(0) 30), QBColor(12)
Picture1Line (c(1) 5 + 498, 3400 - b(1) 30)-(c(2) 5 + 502, 3400 - b(1) 30), QBColor(12)
Picture1Line (c(2) 5 + 498, 3400 - b(2) 30)-(c(3) 5 + 502, 3400 - b(2) 30), QBColor(12)
Picture1Line (c(3) 5 + 498, 3400 - b(3) 30)-(c(4) 5 + 502, 3400 - b(3) 30), QBColor(12)
Picture1Line (c(4) 5 + 498, 3400 - b(4) 30)-(c(5) 5 + 502, 3400 - b(4) 30), QBColor(12)
Picture1Line (c(5) 5 + 498, 3400 - b(5) 30)-(c(6) 5 + 502, 3400 - b(5) 30), QBColor(12)
Picture1Line (c(6) 5 + 498, 3400 - b(6) 30)-(c(7) 5 + 502, 3400 - b(6) 30), QBColor(12)
Picture1Line (c(7) 5 + 498, 3400 - b(7) 30)-(c(8) 5 + 502, 3400 - b(7) 30), QBColor(12)
Picture1Line (c(8) 5 + 498, 3400 - b(8) 30)-(c(9) 5 + 502, 3400 - b(8) 30), QBColor(12)
Picture1Line (c(9) 5 + 498, 3400 - b(9) 30)-(c(10) 5 + 502, 3400 - b(9) 30), QBColor(12)
Picture1Line (c(10) 5 + 498, 3400 - b(10) 30)-(c(11) 5 + 502, 3400 - b(10) 30), QBColor(12)
Picture1Line (c(11) 5 + 498, 3400 - b(11) 30)-(c(12) 5 + 502, 3400 - b(11) 30), QBColor(12)
Picture1Line (c(12) 5 + 498, 3400 - b(12) 30)-(c(13) 5 + 502, 3400 - b(12) 30), QBColor(12)
Picture1Line (c(13) 5 + 498, 3400 - b(13) 30)-(c(14) 5 + 502, 3400 - b(13) 30), QBColor(12)
Picture1Line (c(14) 5 + 498, 3400 - b(14) 30)-(c(15) 5 + 502, 3400 - b(14) 30), QBColor(12)
Picture1Line (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
Adodc3ConnectionString = "Provider=MicrosoftJetOLEDB40;Data Source=C:\Ldgz\wdmdb;Persist Security Info=False"
Adodc3RecordSource = mdh
Adodc3Refresh
zslNew = Adodc3RecordsetRecordCount
Text4 = zslNew
If zslNew >= 1 Then
Adodc3RecordsetMoveFirst
For i = 0 To zslNew - 1
quexian(0, i) = Adodc3Recordset(0)
For j = 2 To 7
quexian(j, i) = Adodc3Recordset(j)
Next j
Adodc3RecordsetMoveNext
Next i
Adodc3RecordsetMoveFirst
For j = 0 To zslNew - 1
Picture1Line (j 5 + 500, quexian(2, j) -30 + 3399)-(j 5 + 500, quexian(2, j) -30 + 3401), vbRed, BF
Picture1Line (j 5 + 500, quexian(3, j) -30 + 3399)-(j 5 + 500, quexian(3, j) -30 + 3401), QBColor(7), BF
Picture1Line (j 5 + 500, quexian(4, j) -30 + 3399)-(j 5 + 500, quexian(4, j) -30 + 3401), vbWhite, BF
Picture1Line (j 5 + 500, quexian(5, j) -30 + 3399)-(j 5 + 500, quexian(5, j) -30 + 3401), vbYellow, BF
Picture1Line (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 + 1667
br_br = 55
ElseIf quexian(8, j) >= 1 And quexian(8, j) < 10 Then
wy_wy = -1500 + 1667
br_br = 55556
ElseIf quexian(8, j) >= 10 And quexian(8, j) < 100 Then
wy_wy = -3000 + 1667
br_br = 05555
ElseIf quexian(8, j) >= 100 And quexian(8, j) < 1000 Then
wy_wy = -4500 + 1667
br_br = 0055555
End If
Picture1Line (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
Adodc3ConnectionString = "Provider=MicrosoftJetOLEDB40;Data Source=C:\Ldgz\wdmdb;Persist Security Info=False"
Adodc3RecordSource = mdh
Adodc3Refresh
zslNew = Adodc3RecordsetRecordCount
Text4 = zslNew
If zslNew > 1 Then
Adodc3RecordsetMoveLast
For j = 2 To 7
quexian(j, i) = Adodc3Recordset(j)
Next j
Picture2Height = 10000
Picture1Visible = True
If zslOld >= 1 Then
For j = zslOld - 1 To zslNew - 1
Picture1Line (j 5 + 500, quexian(2, j) -30 + 3399)-(j 5 + 500, quexian(2, j) -30 + 3401), vbRed, BF
Picture1Line (j 5 + 500, quexian(3, j) -30 + 3399)-(j 5 + 500, quexian(3, j) -30 + 3401), QBColor(7), BF
Picture1Line (j 5 + 500, quexian(4, j) -30 + 3399)-(j 5 + 500, quexian(4, j) -30 + 3401), vbWhite, BF
Picture1Line (j 5 + 500, quexian(5, j) -30 + 3399)-(j 5 + 500, quexian(5, j) -30 + 3401), vbYellow, BF
Picture1Line (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 + 1667
br_br = 55
ElseIf quexian(8, j) >= 1 And quexian(8, j) < 10 Then
wy_wy = -1500 + 1667
br_br = 55556
ElseIf quexian(8, j) >= 10 And quexian(8, j) < 100 Then
wy_wy = -3000 + 1667
br_br = 05555
ElseIf quexian(8, j) >= 100 And quexian(8, j) < 1000 Then
wy_wy = -4500 + 1667
br_br = 0055555
End If
Picture1Line (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
'记录时间最长96小时
cmdPrintEnabled = True
End If
zslOld = zslNew
End Sub
以上就是关于请教,VB6.0怎样采集计算机串口输入的数据并以图形显示全部的内容,包括:请教,VB6.0怎样采集计算机串口输入的数据并以图形显示、vb.net2010十六进制读取串口的问题、如何用VB6.0通过串口从电子秤中获取数据等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)