91.Wincc V7.3 使用用户归档实现报表1-用户归档+Activex控件
(2016-06-01 09:43:34)
标签:
wincc用户及归档报表vbs |
分类: 西门子软硬件 |
1. 先定义和配置一个用户归档,具体方法参考其他博客。
2. 由于没有实际硬件,我们可以使用随机函数的方法模拟产生现场来的数据,随机函数可以写在项目模板里面,具体方法参考其他博客。
3. 新建vbs全局动作,把随机函数赋给各变量
Option Explicit
Function action
Dim
FT101,FT102,FT103,PT101,PT102,PT103,TT101,TT102,TT103,LT101,LT102,LT103
Set FT101=HMIRuntime.Tags("S7$程序(1)/FT101")
Set FT102=HMIRuntime.Tags("S7$程序(1)/FT102")
Set FT103=HMIRuntime.Tags("S7$程序(1)/FT103")
Set PT101=HMIRuntime.Tags("S7$程序(1)/PT101")
Set PT102=HMIRuntime.Tags("S7$程序(1)/PT102")
Set PT103=HMIRuntime.Tags("S7$程序(1)/PT103")
Set TT101=HMIRuntime.Tags("S7$程序(1)/TT101")
Set TT102=HMIRuntime.Tags("S7$程序(1)/TT102")
Set TT103=HMIRuntime.Tags("S7$程序(1)/TT103")
Set LT101=HMIRuntime.Tags("S7$程序(1)/LT101")
Set LT102=HMIRuntime.Tags("S7$程序(1)/LT102")
Set LT103=HMIRuntime.Tags("S7$程序(1)/LT103")
FT101.Write MyRnd(100,200)
FT102.Write MyRnd(110,220)
FT103.Write MyRnd(120,230)
PT101.Write MyRnd(100,200)
PT102.Write MyRnd(110,220)
PT103.Write MyRnd(120,230)
TT101.Write MyRnd(100,200)
TT102.Write MyRnd(110,220)
TT103.Write MyRnd(120,230)
LT101.Write MyRnd(100,200)
LT102.Write MyRnd(110,220)
LT103.Write MyRnd(120,230)
End Function
4. 新建全局动作,把数据定期存入用户归档数据表
Option Explicit
Function action
Dim CurDate,CurTime
Dim id,job
Set CurDate=HMIRuntime.Tags("CurDate")
Set CurTime=HMIRuntime.Tags("CurTime")
Set id=HMIRuntime.Tags("@UA_ID")
Set JOB=HMIRuntime.Tags("@UA_JOB")
CurDate.Write Date()
CurTime.Write Time()
id.Write -1
job.Write 6
End Function
5. 画面上放一个DTPicker控件,名字修改为DTP,放一个MSHFGrid控件,名字修改为Report,放一个按钮,按钮鼠标点击VBS脚本为
Sub OnClick(ByVal
Item)
Dim DT,Report,DBName,PCName
Dim conn,ssql,ors,ocom,scon
Dim sYear,sMonth,sDay,sDate
Set DT=ScreenItems("DTP")
Set Report=ScreenItems("Report")
Set DBName=HMIRuntime.Tags("@DatasourceNameRT")
Set PCName=HMIRuntime.Tags("@LocalMachineName")
sYear=Year(DTP.Value)
sMonth=Month(DTP.Value)
sDay=Day(DTP.Value)
sDate=sYear & "/" & sMonth & "/" & sDay
'Msgbox sDate
scon="Provider = SQLOLEDB.1;Integrated Security=SSPI;Persist
SecurityInfo=False;Initial Catalog ='" _
ssql="select Curdate as '日期',Curtime as '时间',FT101 as '流量1',FT102
as '流量2',FT103 as '流量3'," _
Set conn=CreateObject("ADODB.Connection")
conn.ConnectionString=scon
conn.Cursorlocation=3
conn.open
Set ors=CreateObject("ADODB.RecordSet")
Set ocom=CreateObject("ADODB.Command")
ocom.commandtype=1
Set ocom.ActiveConnection=conn
ocom.CommandText=ssql
Set ors=ocom.Execute
Set Report.DataSource=ors
Report.Refresh
Set ors=Nothing
conn.close
Set conn=Nothing
End Sub
保存,计算机属性-启动项目勾选“全局脚本”,运行后就可以看到效果了。