YetAnotherForum
Welcome Guest Search | Active Topics | Log In | Register

How to add a trace to a trend using vba? Options · View
Schalk
#1 Posted : Friday, February 12, 2010 11:18:41 PM
Rank: Newbie
Groups: Member

Joined: 2/12/2010
Posts: 2
Location: Australia
Some background first. I may be trying to dig a dam with a teaspoon.

I am building a availability model of the plant. The values and trends worked fine, until you change the time scale on the trend. I tried to change the time scale on the values, but it failed. I tried to change the expression of the value, but was unable to get to it. It’s just blank.

I extracted the trace values for the trend, did the calculations with it and the calculation work just fine.

Now when I try to build a hierarchy, the performance equations just get longer and longer and really messy. I can use the values of the trend traces to simplify it, but I do not know how to add back a trace with the new calculated values again?

Any help would be appreciated. I saw an example of importing a spreadsheet using menu’s, but I need to do it programmatically. Thanks in advance.

Cool
Sponsor  
 

OSIsoft vCampus is a subscription-based, online offering that consists of providing everything people need to develop applications on the PI System.
We invite you to take a "tour" of the OSIsoft Virtual Campus - also feel free to consult the FAQ  or contact OSIsoft vCampus for more details.
RJK Solutions
#2 Posted : Monday, February 15, 2010 11:33:25 AM
Rank: Administration

Groups: Administration

Joined: 6/20/2008
Posts: 612
Location: Cheshire, United Kingdom.
Welcome to the forum.

Can you clarify what you refer to as "Values". Do you mean value symbols that are placed on the display - are you using PI Points or using PI Expression DataSets?

If you are using DataSets to build a hierarchy, then yes you are going to hit an issue as you can't have DataSets referencing each other.

Not totally clear what you need to do...manipulate Datasets, add/remove traces etc

Cheers,
Rhys.
Principal Consultant
Real-Time Data Management @ Wipro Technologies
Schalk
#3 Posted : Monday, February 15, 2010 10:14:58 PM
Rank: Newbie
Groups: Member

Joined: 2/12/2010
Posts: 2
Location: Australia
Values in the 12.3 button on the drawing toolbar.

To calculate my availability figure for a trend, I use the traces of a trend in a display. Simply the sum of them divided by the count :

Code:
Dim TheTrend As Trend
Set TheTrend = ThisDisplay.Symbols("Trend1")

Dim iTrace As Integer, iTraceValue As Integer

ReDim lgSum(TheTrend.TraceCount)
For iTrace = 1 To TheTrend.TraceCount
    TheTrend.CurrentTrace = iTrace
    lgSum(iTrace) = 0
    For iTraceValue = 1 To TheTrend.TraceValuesCount
       
        Dim vValue As Variant, vTime As Variant, vStatus As Variant
        vValue = TheTrend.GetTraceValue(iTraceValue, vTime, vStatus)
        lgSum(iTrace) = lgSum(iTrace) + vValue
       
    Next iTraceValue
    If TheTrend.TraceValuesCount > 0 Then lgSum(iTrace) = CLng(lgSum(iTrace) / _ TheTrend.TraceValuesCount) Else lgSum(iTrace) = -1
    'Debug.Print TheTrend.GetTagName(iTrace); " Avail " & lgSum(iTrace)

Next iTrace

Set TheTrend = Nothing


The traces are PI Equations are typically like the following :

Code:
if ('643PMP016' = "START") then 100 else 0


I change the time range of the trends and values using :
Code:

    ThisDisplay.Trend1.SetStartAndEndTime StartTime, EndTime
    ThisDisplay.Value1.SetStartAndEndTime StartTime, EndTime


It work for the Trends, but it does not change the value of the values at all. So I end up wit a trend showing data of a different time frame than the values.

For a two out of three system the equations become messy :

Code:
If ((if ('643PMP016' = "START") then 1 else 0) + (if ('643PMP017' = "START") then 1 else 0
) + (if ('643PMP018' = "START") then 1 else 0)) > 1 then 100 else 0


That is on the lower level, two or three levels up it really becomes ….stringy

If I could add a trace in a reverse way of the GetTraceValue, I could just calculate the trace average instead of the longer growing PI Equations. It also allows me to declare extra variable, and simplify calculation. Or of cause any other beter way....BigGrin
RJK Solutions
#4 Posted : Tuesday, February 16, 2010 9:59:28 AM
Rank: Administration

Groups: Administration

Joined: 6/20/2008
Posts: 612
Location: Cheshire, United Kingdom.
Ok it is more clear now Smile

For a Value symbol, there is no start/end time because it displays the value for the tag/dataset at a specific time. It uses the Display's EndTime property - to set this you use ThisDisplay.SetTimeRange method. What you set as the end time will be used for the Value symbols.

If on a Trend you want to display the average, you can do this using PI Calculation Columns. Example, if you have 'sinusoid' as one trace then you can create a PI Calculation Dataset and set the Expression to be 'sinusoid'. Then when you add a new trace to a trend, instead of selecting PI Point select Calculation, select the Dataset you created and select the "Average" column. Just make sure you set the Interval you want the average for (typically "1h").

Principal Consultant
Real-Time Data Management @ Wipro Technologies
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.