
实时采集的数据可直接用来画曲线,但往往为了以后查询,同时应按定时间隔写入数据库或文本文件。所以可在写入数据库后通过查询做到实时显示和更新。
'窗体加载时将已记录的数据查询后绘图
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
如果PLC支持RS232 协议 可以用控件mscomm,采取modbus通讯方式;
支持modbus tcp/ip的话 那就可以用winsock 控件
或者现在流行的OPC服务,将plc数据写入OPC服务器 然后通过VB做opc client来实现间接控制
数据接收参考代码:
Private Sub MSComm_OnComm()
Dim bytInput() As Byte
Dim intInputLen As Integer
Select Case frmMainctrMSCommCommEvent
Case comEvReceive
If blnReceiveFlag Then
If Not frmMainctrMSCommPortOpen Then
frmMainctrMSCommCommPort = intPort
frmMainctrMSCommSettings = strSet
frmMainctrMSCommPortOpen = True
End If
'此处添加处理接收的代码
frmMainctrMSCommInputMode = comInputModeText '按ASCII接收
intInputLen = frmMainctrMSCommInBufferCount
ReDim bytInput(intInputLen)
bytInput = frmMainctrMSCommInput
Text1 = bytInput
Text2 = Text1
jscd = Len(Text1)
If Left(Text1, 1) <> Chr(27) Or jscd > 25 Then '
frmMainLabel3BackColor = vbRed
frmMainLabel3ForeColor = vbWhite
frmMainLabel3Caption = "接收信号出错!"
ElseIf Left(Text2, 1) = Chr(27) And Mid(Text2, 25, 1) = Chr(13) Then
frmMainLabel3BackColor = vbGreen
frmMainLabel3ForeColor = vbBlack
frmMainLabel3Caption = "接收信号正常!"
If Left(Text2, 6) = Chr(27) & "R0032" And jscd = 25 Then
If Val(fa2) >= 0 And Len(fa2) = 4 Then
fa2 = "0" & Mid(fa2, 2, 3)
End If
frmMaintxtSend = Chr(27) & fa0 & fa1 & "9999" & zhenkong & fa2 & fa3 & fa4 & Chr(13)
lenTxtSend = Len(txtSend)
frmJishiLabel8Caption = txtSend
frmJishiLabel11Caption = lenTxtSend
If lenTxtSend = 24 Then
Call commFasong
Else
frmMainLabel3BackColor = vbRed
frmMainLabel3ForeColor = vbWhite
frmMainLabel3Caption = "发送信号出错!"
End If
blL1 = Mid$(Text2, 19, 2)
If blL1 = "01" Then
record_jmm(0) = Val(Mid$(Text2, 21, 4)) / 10 '制品1温度
ElseIf blL1 = "02" Then
record_jmm(1) = Val(Mid$(Text2, 21, 4)) / 10 '制品2温度
ElseIf blL1 = "03" Then
record_jmm(2) = Val(Mid$(Text2, 21, 4)) / 10 '制品3温度
ElseIf blL1 = "04" Then
record_jmm(3) = Val(Mid$(Text2, 21, 4)) / 10 '制品4温度
ElseIf blL1 = "05" Then
record_jmm(4) = Val(Mid$(Text2, 21, 4)) / 10 '制品5温度
ElseIf blL1 = "06" Then
record_jmm(5) = Val(Mid$(Text2, 21, 4)) / 10 '制品6温度
End If
record_jm(0) = Val(record_jmm(0))
record_jm(1) = Val(record_jmm(1))
record_jm(2) = Val(record_jmm(2))
record_jm(3) = Val(record_jmm(3))
record_jm(4) = Val(record_jmm(4))
record_jm(5) = Val(record_jmm(5))
blL = Mid$(Text2, 7, 6)
Call Hex_bin '输出口状态鉴别
blLg = Mid$(Text2, 13, 6)
Call hex_bin1 '输出口故障状态鉴别
txtSend = ""
Else
txtSend = ""
End If
End If
If Not blnAutoSendFlag And Not blnReceiveFlag Then
frmMainctrMSCommPortOpen = False
End If
End If
End Select
End Sub
接收的数据按上下位机约定取出赋值于全局变量,在其它窗体进行数据记录(写入数据库)
数据分析通过数据控件及SQL查询语句来完成任务
以下提供MSDN参考:
OnComm 常数
常数 值 描述
comEvSend 1 发送事件。
comEvReceive 2 接收事件。
comEvCTS 3 clear-to-send 线变化。
comEvDSR 4 data-set ready 线变化。
comEvCD 5 carrier detect 线变化。
comEvRing 6 振铃检测。
comEvEOF 7 文件结束。
MSComm 控件提供下列两种处理通讯的方式:
事件驱动通讯是处理串行端口交互作用的一种非常有效的方法。在许多情况下,在事件发生时需要得到通知,例如,在 Carrier Detect (CD) 或 Request To Send (RTS) 线上一个字符到达或一个变化发生时。在这些情况下,可以利用 MSComm 控件的 OnComm 事件捕获并处理这些通讯事件。OnComm 事件还可以检查和处理通讯错误。所有通讯事件和通讯错误的列表,参阅 CommEvent 属性。
在程序的每个关键功能之后,可以通过检查 CommEvent 属性的值来查询事件和错误。如果应用程序较小,并且是自保持的,这种方法可能是更可取的。例如,如果写一个简单的电话拨号程序,则没有必要对每接收一个字符都产生事件,因为唯一等待接收的字符是调制解调器的“确定”响应。
SThreshold 属性
在 MSComm 控件设置 CommEvent 属性为 comEvSend 并产生 OnComm 事件之前,设置并返回传输缓冲区中允许的最小字符数。
说明
若设置 Sthreshold 属性为 0(缺省值),数据传输事件不会产生 OnComm 事件。若设置 Sthreshold 属性为 1,当传输缓冲区完全空时,MSComm 控件产生 OnComm 事件。
如果在传输缓冲区中的字符数小于 value,CommEvent 属性设置为 comEvSend,并产生 OnComm 事件。comEvSend 事件仅当字符数与 Sthreshold 交叉时被激活一次。例如,如果 Sthreshold 等于 5,仅当在输出队列中字符数从 5 降到 4 时,comEvSend 才发生。如果在输出队列中从没有比 Sthreshold 多的字符,comEvSend 事件将绝不会发生。
CommEvent 属性包含实际错误或产生 OnComm 事件的数码。注意,设置 Rthreshold 或 Sthreshold 属性为 0,分别使捕获 comEvReceive 和 comEvSend 事件无效。
另请参阅:
>
>
使用定时器控件,在控件内编码!
或者使用Windows api函数
或者使用循环,利用datadiff函数
你可以把下面代码保存为vbs文件:每隔15秒就会出现一个对话框,你可以根据你的需要进行修改!
dim i,dt
dt=now()
i=0
do until i>=20
i=datediff("s",dt,now())
if i>=15 then
msgbox "采集数据"
i=0
dt=now()
end if
loop
以上就是关于VB 串口数据采集全部的内容,包括:VB 串口数据采集、vb如何从PLC采集数据、vb工控问题:实现各种数据的采集,写入数据库和曲线的绘制。等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)