Lesson 5: Working with AF event frames
- Last UpdatedMay 16, 2023
- 2 minute read
- PI System
- AF SDK 2.10
- PI Server
After completing this lesson you will be able to:
-
Use AF SDK to manage event frames
-
Create an event frame template
-
Create and work with event frames
Help for methods and data types used in this lesson
Introduction
An Event Frame represents a time period defined by a start time and end time. Each Event Frame typically references one or more PI AF elements to associate the event with an asset. An Event Frame can also have a collection of child Event Frames, which represent child events that make up the larger event.
When creating AFEventFrame objects, the following properties should usually be set: StartTime, EndTime, and PrimaryReferencedElement.
AFEventFrame ef = new AFEventFrame(database, "*", eventFrameTemplate);
ef.SetStartTime(startTime);
ef.SetEndTime(endTime);
ef.PrimaryReferencedElement = meter;
When creating Event Frame templates in code, you might be surprised to discover there is no such object as AFEventFrameTemplate. Instead, an Event Frame template is a simply an AFElementTemplate with its InstanceType property set to typeof(AFEventFrame).
AFElementTemplate eventFrameTemplate =
database.ElementTemplates["Name of Template"];
if (eventFrameTemplate == null)
AFElementTemplate eventFrameTemplate =
database.ElementTemplates.Add("Name of Template");
eventFrameTemplate.InstanceType = typeof(AFEventFrame);
To find existing PI AF Event Frames, use the AFEventFrameSearch.FindEventFrames() method. You can search by name, start time, end time, duration, template, category, and a variety of other fields. Note that unlike elements, event frames cannot be accessed directly as a property under the AFDatabase object. For more information, see the online AF SDK reference AFEventFrameSearch.FindEventFrames().
Note that AFEventFrameSearch is analogous to AFElementSearch from Lesson 2.
AFEventFrameSearch eventFrameSearch =
new AFEventFrameSearch(database, "EventFrame Captures", AFEventFrameSearchMode.ForwardFromStartTime,
startTime, queryString);
Because Event Frames typically represent historical time ranges, attribute values of event frames typically do not change over time and can be cached to improve performance. In AF SDK, you can call the CaptureValues() method on an event frame instance to capture and save attribute values to the PI AF server for faster subsequent retrieval. Updating the start or end time of the event frame will automatically recapture the values. For more information, see the online AF SDK reference CaptureValues().
foreach (AFEventFrame item in eventFrameSearch.FindEventFrams())
{
item.CaptureValues();
}