发表于:2009-04-15 13:15:41
2楼
http://www.ad.siemens.com.cn/club/bbs/post_elite.asp?b_id=5&a_id=530192看了这里的程序,也有关于这方面的疑问
在全局动作中写入如下代码:
Function action
Dim objConnection
Dim strConnectionString
Dim P1101VALUE,P1102VALUE,P1103VALUE,T1101VALUE,T1102VALUE,T1103VALUE
Dim strSQL
Dim objCommand
Dim DsnStr
Dim dt
Dim UserName
DsnStr=HMIRuntime.Tags("@DatasourceNameRT").Read ‘取当前的DSN值
strConnectionString = "Provider=MSDASQL;DSN="&DsnStr&";UID=;PWD=;"
HMIRuntime.Trace strConnectionString
dt=Now()
P1101Value = HMIRuntime.Tags("P1101_PV").Read
P1102Value = HMIRuntime.Tags("P1102_PV").Read
P1103Value = HMIRuntime.Tags("P1103_PV").Read
T1101Value = HMIRuntime.Tags("T1101_PV").Read
T1102Value = HMIRuntime.Tags("T1102_PV").Read
T1103Value = HMIRuntime.Tags("T1103_PV").Read
UserName = HMIRuntime.Tags("@CurrentUserName").Read ‘取当前操作员
HMIRuntime.Trace p1101value
strSQL = "INSERT INTO WINCC_DATA (OP,DT,P1,P2,P3,T1,T2,T3) VALUES ("
strsql=strsql+"‘"& UserName &"‘"
strsql=strsql+",‘"&dt&"‘"
strSql=StrSql+","& P1101Value &""
strSql=StrSql+"," & P1102Value &""
strsql=strsql+","& P1103Value &""
strsql=strsql+","& T1101Value &""
strsql=strsql+","& T1102Value &""
strsql=strsql+","& T1103Value &")"
Set objConnection = CreateObject("ADODB.Connection")
objConnection.ConnectionString = strConnectionString
objConnection.Open
Set objCommand = CreateObject("ADODB.Command")
HMIRuntime.Trace "Ok"
HMIRuntime.Trace strsql
objCommand.ActiveConnection = objConnection
objCommand.CommandText = strSQL
HMIRuntime.Trace "Ok1"
objCommand.Execute
Set objCommand = Nothing
objConnection.Close
Set objConnection = Nothing
End Function
设置每30秒触发一次。把数据写入数据库中。接下来是如何实现报表的格式,采用EXECL不是一个好方法,因为对于求平均值和最大值/最小值来说,要先把数据写入EXECL中,然后才能再EXECL中做统计计算。在这里我们使用SQL语句的强大的数据统计功能,在WINCC的报表编辑器中有一个动态对象:ODBC数据库域。这个对象是WINCC5.1所没有的。这个对象中可以使用标准SQL语句。
strSQL = "INSERT INTO WINCC_DATA (OP,DT,P1,P2,P3,T1,T2,T3) VALUES ("
strsql=strsql+"‘"& UserName &"‘"
strsql=strsql+",‘"& dt &"‘"
strSql=StrSql+","& P1101Value &""
strSql=StrSql+"," & P1102Value &""
strsql=strsql+","& P1103Value &""
strsql=strsql+","& T1101Value &""
strsql=strsql+","& T1102Value &""
strsql=strsql+","& T1103Value &")"
这个数据库中有8个字段,而在赋值语句strsql=strsql+"‘"& UserName &"‘" 可以这样分行写吗?没有,号分隔。请解读一下意思,
我想这句话也可以写成strSQL = "INSERT INTO WINCC_DATA (OP,DT,P1,P2,P3,T1,T2,T3) VALUES (‘‘"& UserName &"‘‘,‘"& dt &"‘,"& P1101Value &"," & P1102Value &","& P1103Value &","& T1101Value &","& T1102Value &","& T1103Value &")"
这样是不是好理解些呢?