⑴ 如何 用数据库保存串口采集到的数据
假设你有表test={ID,数值} 假设你已经连接上了数据库,你的连接对象为cnn 假设你的数组为arrlngData(),里面存了数据 8,写入数据库 dim i as long dim strsql as string dim rst as objec...
⑵ VB2010中如何将串口采集的数据存入到数据库中,并用数据库中数据画实时曲线和历史曲线
使用串口控件获取数据流并存入字符串变量中。
按照预先制定的数据规则解析获取到的数据流,尔后通过SQL语句存入数据库。
而至于曲线图的作法,则是通过SQL语句取出结果集,然后通过VB的CHART控件作出。相关的设置请自己查阅文档。
⑶ 串口数据采集程序
直接上参考程序:
DimavAsVariant
DimdatacountAsLong
PrivateSubcmdClear_Click()
txtData.Text=""
EndSub
PrivateSubcmdStop_Click()
'关闭端口
IfMSComm.PortOpen=TrueThen
MSComm.InBufferCount=0'清空缓冲区
MSComm.PortOpen=False
EndIf
cmdReceive.Enabled=True
lblStatus.Caption="停止接收,空闲"
EndSub
PrivateSubcmdReceive_Click()
'串口设置
WithMSComm
.CommPort=1
.Settings="9600,N,8,1"
.RThreshold=1'接收1字节触发oncomm事件
.InputMode=comInputModeBinary
.InputLen=1'输入长度为1
.InBufferCount=0'清除接收缓冲区
EndWith
'打开端口
IfMSComm.PortOpen=FalseThen
MSComm.PortOpen=True
IfErrThen
MsgBox(Err.Description)
ExitSub
EndIf
EndIf
lblStatus.Caption="打开端口,等待接收"
datacount=0
cmdReceive.Enabled=False
EndSub
PrivateSubcmdSave_Click()
DimoutfnAsString
MsgBox("接收了"+CStr(datacount)+"组数据")
lblStatus.Caption="接收完成,请选择输出文件"
cmdReceive.Enabled=True
'选择输出文件
CommonDialog1.FileName=CStr(Date)+".txt"
CommonDialog1.Filter="TextFiles|*.txt"
CommonDialog1.Flags=CommonDialog1.FlagsOrcdlOFNOverwritePrompt
CommonDialog1.CancelError=True
OnErrorGoToerrhandler
CommonDialog1.ShowSave
outfn=CommonDialog1.FileName
OpenoutfnForOutputAs#1
Print#1,txtData.Text
Close#1
'txtData.SaveFileoutfn
lblStatus.Caption="输出完成,空闲"
errhandler:
ExitSub
EndSub
PrivateSubForm_Load()
lblStatus.Caption="空闲"
EndSub
PrivateSubForm_Unload(CancelAsInteger)
'关闭端口
IfMSComm.PortOpen=TrueThen
MSComm.InBufferCount=0'清空缓冲区
MSComm.PortOpen=False
EndIf
EndSub
PrivateSubMSComm_OnComm()
DimT1,T2AsLong
SelectCaseMSComm.CommEvent
CasecomEvReceive'收到Rthreshold个字节产生的接收事件
MSComm.RThreshold=0'关闭OnComm事件接收
lblStatus.Caption="接收"
av=MSComm.Input'读取一个接收字节
dataframe(1)=av(0)'转换为字节
Ifdataframe(1)=&HAThen'接收到T1
Do
DoEvents
LoopUntilMSComm.InBufferCount>=2'循环等待接收缓冲区>=2个字节
av=MSComm.Input
dataframe(2)=av(0)
av=MSComm.Input
dataframe(3)=av(0)'接收T1
T1=dataframe(2)+CLng(dataframe(3))*256'计算T1
EndIf
Do
DoEvents
LoopUntilMSComm.InBufferCount>=1'循环等待接收缓冲区>=1个字节
av=MSComm.Input'读取一个接收字节
dataframe(4)=av(0)'转换为字节
'接收到T2
Ifdataframe(4)=&HA0Then
'MSComm.RThreshold=0'关闭OnComm事件接收
'循环等待接收缓冲区>=2个字节
Do
DoEvents
LoopUntilMSComm.InBufferCount>=2
av=MSComm.Input
dataframe(5)=av(0)
av=MSComm.Input
dataframe(6)=av(0)'接收T2
T2=dataframe(5)+CLng(dataframe(6))*256'计算T2
'显示T1T2enter
txtData.Text=txtData.Text+CStr(T1)+""+CStr(T2)+Chr(&HD)+Chr(&HA)
datacount=datacount+1'数据组数+1
EndIf
MSComm.RThreshold=1'打开OnComm事件接收
CaseElse
EndSelect
EndSub
RS232串行通信的波特率设为9600,8位数据位,一位停止位,无校验位。
2. 每组数据包含T1(16位)和T2(16位),将每个数据分成2个8位的数据,先是低8位,然后是高8位。数据为无符号整型。
先发T1,然后发T2,然后是下一组T1、T2。
T1以头数据0x0A(16进制,10进制位10)为头字节,然后是T1的低8位,T1的高8位。
T2以头数据0xA0(16进制,10进制位160)为头字节,然后是T2的低8位,T2的高8位。
发送时序举例:0x0A, t1低8位,t1高8位,0xA0, t2低8位,t2高8位……
将收到的数据T1、T2的高低8位合并,转换成10进制数,以每行T1 T2的形式存储到txt文本文件中
如果需要 做其他‘文件格式的处理, 数据已经拿到了,想怎么弄就变通下吧。
⑷ 怎么从串口读取数据到数据库呢
用C#编程,很方便。串口收发用System.IO.SerialPort组件,收到数据,解析出来需要的数,再操作数据库就可以了。
⑸ 怎么将虚拟串口的数据采集到数据库里面呢
写成SELECT* FROM t WHERE object_id = decode(:OID,null,object_id,:OID) ;计划与NVL的一样(略)。现在的计划,ORACLE实际是转换成两条语句,然后进行类似于UNION ALL的操作。注意看计划中的FILTER操作,FILTER操作的子操作,如果是单个子操作,那么就会先执行FILTER(父操作),满足FILTER条件的,则执行子操作,否则不执行子操作(如果FILTER有2个子操作,则类似于NESTED LOOPS的操作)。看ID=2的FILTER条件是:OID IS NULL,ID=4的FILTER操作:OID IS NOT NULL,他们两个完全是互斥条件,所以,对于传入的:OID,肯定只能执行一个分支:要么执行全表扫描(传入NULL),要么执行索引扫描(传入非NULL值)。这也就实现了前面说的IF .... ELSE ....END IF的操作。
⑹ 利用ASP.net怎样实现对串口数据的采集
简单的说一下吧,爪机打字麻烦。
服务器端对串口的操作可以用winform来完成也可以写成一个服务,随系统启动而启动,负责写数据到数据库或从响应用户的命令,
而你说的b/s架构则仅仅提供数据浏览与提交命令,回显命令的执行结果即可
⑺ 如何在web页面上获取客户端的串口数据
web页面上获取客户端的串口数据的方法:
可以写一个串口代理程序,读取本地串口,将获取到的数据存入数据库。web通过ajax+定时器获取数据库中的数据显示就好了。
如果要交互,可以搞一个让上面提到的串口程序开一个socket.将串口通信获取的数据,通过socket发出去,web页面可以用websocket。
下面一个通过flash操作ardiuno的demo.用的是类似于第二种交互的方法。只不过用的是ActionScript.原理是一样的。
串行接口是一种可以将接收来自CPU的并行数据字符转换为连续的串行数据流发送出去,同时可将接收的串行数据流转换为并行的数据字符供给CPU的器件。一般完成这种功能的电路,我们称为串行接口电路。
串口通信(Serial Communications)的概念非常简单,串口按位(bit)发送和接收字节的通信方式。
注意事项:
户端的系统数据如果能随便被web页面读取,那大家也不敢随便打开网页了,至于说用IE的ActiveX 控件,这个也没有前途,IE默认不开启,现在有IE的也没什么人,当然如果是用于特定客户的话可以了,反正你想干嘛就干嘛。
⑻ VB 串口数据采集
实时采集的数据可直接用来画曲线,但往往为了以后查询,同时应按定时间隔写入数据库或文本文件。所以可在写入数据库后通过查询做到实时显示和更新。
'窗体加载时将已记录的数据查询后绘图
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
'记录时间最长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
'记录时间最长96小时
cmdPrint.Enabled = True
End If
zslOld = zslNew
End Sub
⑼ 如何采集单片机串口发送过来的数据,怎么编程实现温度数据的WEB显示,数据类型32.1℃,求完整代码
PC端用 C++/Delphi 之类软件写个小程序
一般情况利用串口RS232 与你的硬件通讯读到温度值写入数据库
建议用Delphi 有现成组件,个把小时就可以搞定
网页哪块就是标准的网页编程了,使用 ASP/PHP/JAVA 都可以
如果你是多个硬件采集点的话,可考虑485总线
如果采集点非常分散距离很远的话,这就需要考虑 RS232转TCP/IP模块
硬件都有了? 看起来你对需求根本没考虑过。
至少:
硬件通讯接口,供电方式
采集点数目
采集点分布
数据组织形式
数据显示形式
控制要求
要搞清楚
⑽ 如何实现串口数据采集,如何分析这些数据
MSCOMM控件在VB6的企业版中有,需通过部件添加方式加载。
Private Sub MSComm_OnComm()
Dim bytInput() As Byte
Dim intInputLen As Integer
Select Case frmMain.ctrMSComm.CommEvent
Case comEvReceive
If blnReceiveFlag Then
If Not frmMain.ctrMSComm.PortOpen Then
frmMain.ctrMSComm.CommPort = intPort
frmMain.ctrMSComm.Settings = strSet
frmMain.ctrMSComm.PortOpen = True
End If
'此处添加处理接收的代码
frmMain.ctrMSComm.InputMode = comInputModeText '按ASCII接收
intInputLen = frmMain.ctrMSComm.InBufferCount
ReDim bytInput(intInputLen)
bytInput = frmMain.ctrMSComm.Input
Text1 = bytInput
Text2 = Text1
jscd = Len(Text1)
If Left(Text1, 1) <> Chr(27) Or jscd > 25 Then '
frmMain.Label3.BackColor = vbRed
frmMain.Label3.ForeColor = vbWhite
frmMain.Label3.Caption = "接收信号出错!"
ElseIf Left(Text2, 1) = Chr(27) And Mid(Text2, 25, 1) = Chr(13) Then
frmMain.Label3.BackColor = vbGreen
frmMain.Label3.ForeColor = vbBlack
frmMain.Label3.Caption = "接收信号正常!"
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
frmMain.txtSend = Chr(27) & fa0 & fa1 & "9999" & zhenkong & fa2 & fa3 & fa4 & Chr(13)
lenTxtSend = Len(txtSend)
frmJishi.Label8.Caption = txtSend
frmJishi.Label11.Caption = lenTxtSend
If lenTxtSend = 24 Then
Call commFasong
Else
frmMain.Label3.BackColor = vbRed
frmMain.Label3.ForeColor = vbWhite
frmMain.Label3.Caption = "发送信号出错!"
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
frmMain.ctrMSComm.PortOpen = False
End If
End If
End Select
End Sub
以上是一段MSCOMM的ONCOMM事件代码,接收的数据按上下位机约定取出赋值于全局变量,在其它窗体进行数据记录(写入数据库).至于数据分析确如一楼说的可以海阔天空,通过数据控件及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 事件无效。