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

Rapid PI - AF Element Templates Options · View
RJK Solutions
#1 Posted : Monday, July 27, 2009 12:59:11 PM
Rank: Administration

Groups: Administration

Joined: 6/20/2008
Posts: 612
Location: Cheshire, United Kingdom.
Following on from our previous post on manipulating the PI Point Data Reference, we will now make life a little easier by creating an Element Template with Attribute Templates. We will use a simple quick view of data for the PIPoint, which consists of:
- Present Value (the current/snapshot value)
- Hourly Average
- Daily Average
- Midnight Value (interpolated)

Once we are connected to our AFDatabase...

Code:

Dim MyAFDB As OSIsoft.AF.AFDatabase = New OSIsoft.AF.PISystems().DefaultPISystem.Databases("MDB")


...we need to add an AFElementTemplate:

Code:

' Add the Element Template
Dim MyET As OSIsoft.AF.Asset.AFElementTemplate = MyAFDB.ElementTemplates.Add("MyDataQuickView")
MyET.Description = "This is my template for quickly looking at data."


Next, we will show how to add an AFAttributeTemplate and set the ConfigString using the AF substitution text.
Code:

' Now add Attribute Templates for each "quick view" of data
Dim MyAt As OSIsoft.AF.Asset.AFAttributeTemplate

' Present value (current/snapshot)
MyAt = MyET.AttributeTemplates.Add("Present Value")
MyAt.Description = "Display the snapshot value for PI Point."
MyAt.DataReferencePlugIn = MyAFDB.PISystem.DataReferencePlugIns("PI Point")
MyAt.ConfigString = "\\%Server%\%Element%" ' Substitution text for AF


The important property to note here is the ConfigString, which uses substituted text. %server% will become the relevant PI server name for any Elements derived from this template. The %element% means that the name of the PI Point is the same name as the derived element name, so if we call the Element "SINUSOID" the ConfigString becomes "\\localhost\SINUSOID" for the derived element.

We can continue to configure the other Attribute Templates for our Element Template to provide our quick view of data.

Code:


MyAt = MyET.AttributeTemplates.Add("Midnight Value")

MyAt.Description = "Display the midnight value for PI Point."

MyAt.DataReferencePlugIn = MyAFDB.PISystem.DataReferencePlugIns("PI Point")

MyAt.ConfigString = "\\%Server%\%Element%;TimeMethod=Interpolated;RelativeTime=t" ' Substitution text for AF


MyAt = MyET.AttributeTemplates.Add("Hourly Average")

MyAt.Description = "Display the current hourly average for PI Point."

MyAt.DataReferencePlugIn = MyAFDB.PISystem.DataReferencePlugIns("PI Point")

MyAt.ConfigString = "\\%Server%\%Element%;TimeMethod=TimeRange;RelativeTime=*-1h;TimeRangeMethod=Average" ' Substitution text for AF


MyAt = MyET.AttributeTemplates.Add("Daily Average")

MyAt.Description = "Display the snapshot value for PI Point."

MyAt.DataReferencePlugIn = MyAFDB.PISystem.DataReferencePlugIns("PI Point")

MyAt.ConfigString = "\\%Server%\%Element%;TimeMethod=TimeRange;RelativeTime=*-1d;TimeRangeMethod=Average" ' Substitution text for AF

MyAFDB.CheckIn()


There we have it, our Element Template is ready. Obviously, it is just as easy to use the PISystemExplorer to build the template, but it your templates form part of an application then coding them reduces any repetive work.

Now let's create an Element named "SINUSOID" based on the "MyDataQuickView" Element Template to see our data.

Code:

Dim MyEmnt As OSIsoft.AF.Asset.AFElement = MyAFDB.Elements.Add("SINUSOID", MyAFDB.ElementTemplates("MyDataQuickView"))
MyAFDB.CheckIn()


Yes, it really is that simple.
Have a look at your newly created element to see the different views of data for the PI Point "SINUSOID". You will see the ConfigStrings have been resolved from the substitution text.

You can check this by retrieving the value of one of the Attributes:
Code:

Dim sConfigString As String = MyEmnt.Attributes("Present Value").ConfigString


Principal Consultant
Real-Time Data Management @ Wipro Technologies
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.
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.