我的项目有100多个母线的电流要做趋势图,我想建一个趋势画面,然后用一个按钮去调用这个趋势画面,并给趋势控件符不同的变量,这样我只做100个按钮就可以实现了,但是我用C脚本做的,只能弹出窗口,不能给趋势控件符变量值,具体见图,请各路大神指导
图片说明:
最佳答案
建议你用vbs写吧,wincc的hlep里面有现成的例子代码可以参考,我贴给你
示例: 如何向 WinCC 线趋势控件添加元素
简介
在下面的示例中,将趋势和设定值趋势添加到了空的 WinCC 在线趋势控件。为趋势窗口中的趋势添加了时间轴和数值轴。
要求
已在图形编辑器中将名为“Control2”的“WinCC 在线趋势控件”插入到过程画面中。
已在图形编辑器中插入按钮。已使用 VBS 动作和以下脚本为按钮等组态了“鼠标单击”事件。
''VBS352
Dim objTrendControl
Dim objTrendWindow
Dim objTimeAxis
Dim objValueAxis
Dim objTrend
''tags used to generate trend data
Dim dtCurrent
Dim dblCurrent
Dim lIndex
Dim vValues(360)
Dim vTimeStamps(360)
''create reference to TrendControl
Set objTrendControl = ScreenItems("Control2")
''---- reference trend ----
''create reference to new window, time and value axis
Set objTrendWindow = objTrendControl.GetTrendWindowCollection.AddItem("myWindow")
Set objTimeAxis = objTrendControl.GetTimeAxisCollection.AddItem("myRefTimeAxis")
Set objValueAxis = objTrendControl.GetValueAxisCollection.AddItem("myRefValueAxis")
''assign time and value axis to the window
objTimeAxis.TrendWindow = objTrendWindow.Name
objTimeAxis.ShowDate = False
objValueAxis.TrendWindow = objTrendWindow.Name
''add trend and assign propertys
Set objTrend = objTrendControl.GetTrendCollection.AddItem("myRefTrend")
objTrend.Provider = 0
objTrend.Color = RGB(0,0,0)
objTrend.TrendWindow = objTrendWindow.Name
objTrend.TimeAxis = objTimeAxis.Name
objTrend.ValueAxis = objValueAxis.Name
''generate values for reference trend
dtCurrent = CDate("23.11.2006 00:00:00")
For lIndex = 0 To 360
vValues(lIndex) = ( Sin(dblCurrent) * 60 ) + 60
vTimeStamps(lIndex) = dtCurrent
dblCurrent = dblCurrent + 0.105
dtCurrent = dtCurrent + CDate ("00:00:01")
Next
''insert data to the reference trend
objTrend.RemoveData
objTrend.InsertData vTimeStamps, vValues
''---- data trend ----
''add time and value axis to the existing window
Set objTimeAxis = objTrendControl.GetTimeAxisCollection.AddItem("myTimeAxis")
Set objValueAxis = objTrendControl.GetValueAxisCollection.AddItem("myValueAxis")
''assign time and value axis to the window
objTimeAxis.TrendWindow = objTrendWindow.Name
objTimeAxis.ShowDate = False
objValueAxis.TrendWindow = objTrendWindow.Name
''add new trend and assign properties
Set objTrend = objTrendControl.GetTrendCollection.AddItem("myTrend")
objTrend.Provider = 0
objTrend.Color = RGB(255,200,0)
objTrend.Fill = True
objTrend.TrendWindow = objTrendWindow.Name
objTrend.TimeAxis = objTimeAxis.Name
objTrend.ValueAxis = objValueAxis.Name
''generate values for data trend
dtCurrent = CDate("23.11.2006 00:00:00")
For lIndex = 0 To 360
vValues(lIndex) = ( Sin(dblCurrent) * 60 ) + 60
vTimeStamps(lIndex) = dtCurrent
dblCurrent = dblCurrent + 0.106
dtCurrent = dtCurrent + CDate ("00:00:01")
Next
''insert values to the data trend
objTrend.RemoveData
objTrend.InsertData vValues, vTimeStamps
提问者对于答案的评价:
谢谢,解决了,曲线的指向不对,吧Index改成TrendIndex就可以了
原创文章,作者:more0621,如若转载,请注明出处:https://www.zhaoplc.com/plc319102.html