Let's continue our journey through the PI Analysis Framework by looking at a few examples of how to use the Data Reference (DR) PlugIn "PI Point".
The "PI Point" DR is supplied with AF and developed by OSISoft thus it is highly optimised to work with a PI server for retrieving PI Points, after all who knows a PI server better than OSISoft!
To start we will add an AFAttribute object to an AFElement object, which we retrieve from the AFDatabase connection.
Get the AFElement:
Code:
Dim MyAFDB As OSIsoft.AF.AFDatabase = New OSIsoft.AF.PISystems().DefaultPISystem.Databases("MyDatabase")
Dim AFEmnt As OSIsoft.AF.Asset.AFElement = MyAFDB.Elements("MyElement")
Simples!
Now we need to add a new AFAttribute to the AFAttributes collection of the AFElement. The method overload we will use simply requires a name for the AFAttribute.
Code:
' Add an AFAttribute to an AFElement.
Dim AFAtt As OSIsoft.AF.Asset.AFAttribute = AFEmnt.Attributes.Add("MyAttribute")
Could this get any easier?
There are a number of options to set for an AFAttribute but we will concentrate on 4 items:
- Description
- DefaultUOM (UOM = Unit Of Measurement)
- DataReferencePlugIn
- ConfigString (Used by each Data Reference to configure behaviour)
In our example we will use the PI Point "sinusoid".
Code:
' Add a description for the attribute.
AFAtt.Description = "This is an attribute we added via AFSDK."
' Set the default Unit Of Measure, e.g. degree Celcius. Refer to your PI systems UOM.
AFAtt.DefaultUOM = MyAFDB.PISystem.UOMDatabase.UOMs("percent") ' We can access the PISystem object from the AFDatabase object
' Set the data reference. Registered plugins belong to the PI system.
AFAtt.DataReferencePlugIn = MyAFDB.PISystem.DataReferencePlugIns("PI Point") ' We can access the PISystem object from the AFDatabase object
' Set the config string. For the PIPoint plugin, this refers the the PIServer & PIPoint
AFAtt.ConfigString = "\\localhost\sinusoid"
MyAFDB.CheckIn()
-
Description is simple, a string that describes the purpose for the AFAttribute.
-
DefaultUOM uses the available UOMs for the PI System, this has no relation to the EngUnits PointAttribute of a PI server. The PISystem object is availble from the AFDatabase object. If you are in doubt of what is available for a PI system, either iterate through all UOMs via code or use the PISystemExplorer to review.
-
DataReferencePlugIn are again availble for a PI system. Use code or the PISystemExplorer to see what is available. As the PI Point DR is shipped with AF we have no need to check for its availability.
-
ConfigString is a string that represents the configuration for the ehaviour of a data reference. In the case of the PI Point DR in the simplest form, this is just the PI server and PI Point.
-
CheckIn() is called to ensure changes (our newly added AFAttribute) are saved.
The AFAttribute "MyAttribute" is now configured to retrieve the current value for the PI Point "sinusoid" from the PI server "localhost". This is very nice but let's take a look at a couple more examples to see how we can leverage the PI Point DR:
Setting a Data Retrieval Mode and Relative Time - Interpolated Value at Midnight of the current day.
Code:
' Now lets set some more information in the ConfigString that is understood by the PI Point DR
' Here we will ge the Interpolated Value for the PI Point at midnight.
AFAtt.ConfigString = "\\localhost\SINUSOID;TimeMethod=Interpolated;RelativeTime=t"
Make the AFAttribute Read/Write i.e. ReadOnly=False
Code:
' If we want to be able to update the PI Point via this AFAttribute, then we need to mark ReadOnly as False
AFAtt.ConfigString = "\\localhost\SINUSOID;TimeMethod=Interpolated;RelativeTime=t;ReadOnly=False"
Current hourly average
Code:
' Configure the attribute to show a current hourly average - we want an average if the % good >= 50%
AFAtt.ConfigString = "\\localhost\SINUSOID;TimeMethod=TimeRange;RelativeTime=*-1h;TimeRangeMethod=Average;TimeRangeMinPercentGood=50"
Use another AFAttribute configured as using the PI Point DR to supply the PI Point to be used.
Code:
AFAtt.ConfigString = "|MyOtherAttribute;TimeMethod=TimeRange;RelativeTime=*-1h;TimeRangeMethod=Average;TimeRangeMinPercentGood=50"
Note the bar "|" character denotes the PI Point DR to reference an AFAttribute rather than a PI server "\\".
If you wanted to use an AFAttribute that is a child attribute, then you follow the same bar "|" syntax.
Code:
AFAtt.ConfigString = "|MyParentAttribute|MyOtherAttribute;TimeMethod=TimeRange;RelativeTime=*-1h;TimeRangeMethod=Average;TimeRangeMinPercentGood=50"
Now hopefully you start to see the usefulness of the PI Point DR and how with some configuration you can create a very powerful AFDatabase with very little effort.
Next we will expand upon this theory and create some Element Templates to make life even easier.
OSIsoft PI System SpecialistsPI consultancy on PI Systems, PISDK, AFSDK, OLEDB etc and PI custom developments. Well pretty much anything to do with PI!