Wincc 记录数据到sql
Posted nianjitao
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Wincc 记录数据到sql相关的知识,希望对你有一定的参考价值。
添加如下vbs脚本.
并在适当的时候调用,比如定时器触发
Sub LogVal(furno)
‘记录温度值等等
Dim conn ,sqlstr
Set conn = CreateObject("ADODB.Connection")
conn.open "Provider=SQLOLEDB.1;Initial Catalog=L2Share;Data Source=192.168.11.1;User ID=xcg;Password=123456;"
If(furno =1) Then Call LogValF1(conn,furno) End If
If(furno =2) Then Call LogValF2(conn,furno) End If
conn.close ‘关闭连接
Set conn=Nothing ‘释放对象
End Sub
Sub LogValF1(conn,furno)
‘F1记录温度值等等
Dim sqlstr
Dim ValuesList
Dim t1,s1,s2,s3
Dim v0,v1,v2,v3,v4,v5,v6,v7
t1= ",‘"&Now()&"‘"
‘‘‘ t1= "‘" & Year(Now)&"-"&Month(Now)&"-"&Day(Now)&" "& Hour(Now)&":"&Minute(Now)&":"&Second(Now)& "‘"
v0=",100"
v1=",101"
ValuesList =furno &t1 &v0 &v1
sqlstr= "Insert Into 退火炉采集值表 (炉号,时间,V0,V1) Values("& ValuesList &")"
conn.Execute(sqlstr)
End Sub
Sub LogValF2(conn,furno)
‘F2记录温度值等等
Dim sqlstr
Dim ValuesList
Dim t1,s1,s2,s3
Dim v0,v1,v2,v3,v4,v5,v6,v7
t1= ",‘"&Now()&"‘"
‘‘‘ t1= "‘" & Year(Now)&"-"&Month(Now)&"-"&Day(Now)&" "& Hour(Now)&":"&Minute(Now)&":"&Second(Now)& "‘"
v0=",200"
v1=",201"
ValuesList = furno &t1 &v0 &v1
sqlstr= "Insert Into 退火炉采集值表 (炉号,时间,V0,V1) Values("& ValuesList &")"
conn.Execute(sqlstr)
End Sub
Sub LogEvent(furno,planid,e)
‘记录事件名等等
Dim conn ,sqlstr
Set conn = CreateObject("ADODB.Connection")
conn.open "Provider=SQLOLEDB.1;Initial Catalog=L2Share;Data Source=192.168.11.1;User ID=xcg;Password=123456;"
Dim t1,t2
Dim ValuesList
t1="‘"&Date()&"‘"
t2="‘"&Now()&"‘"
ValuesList =t1 &","&t2 &","&furno&",‘" &planid &"‘,‘" &e&"‘"
sqlstr= "Insert Into 退火炉事件表 (日期,时间,炉号,生产计划号,事件名) Values("&ValuesList&")"
conn.Execute(sqlstr)
conn.close ‘关闭连接
Set conn=Nothing ‘释放对象
End Sub
以上是关于Wincc 记录数据到sql的主要内容,如果未能解决你的问题,请参考以下文章