Please ensure Javascript is enabled for purposes of website accessibility
Powered by Zoomin Software. For more details please contactZoomin

AF SDK Getting Started

Lesson 5 exercises

  • Last UpdatedMay 16, 2023
  • 2 minute read

Your next task is to develop an energy reporting system for the PI AF database Green Power Company. You should familiarize yourself with the PI AF database using PI System Explorer before starting the exercise.

The Green Power Company database contains 12 electric meters deployed to different buildings. Your task is to create PI AF Event Frames to track average energy usage per day. Each PI AF Event Frame is created using a PI AF Event Frame Template. The template should have one attribute configured to report the average of the Energy Usage attribute of a meter over the event frame time range.

Please implement the following methods inside Program5.cs and run the application with the arguments provided for each of the following methods in Main().

For each of the following exercises, your task is to add the logic to each method. Add the methods to your console application and test each one by writing output to the console.

  • Exercise 1

    Create an AF Event Frame template called Daily Usage. Event frame names created from this template should include the event frame template name, referenced element name, and start date. For example: Usage Tracker-Meter002-2016-02-01 00:00:00.

    Create a PI AF Attribute Template under the event frame template called Average Energy Usage. Configure the AFAttributeTemplate properties such that the event frame attribute reports the average value of the referenced Energy Usage attribute over the event frame time range. See Lesson 5 hints and tips for an example configuration string to use.

    AFElementTemplate CreateEventFrameTemplate(AFDatabase database)

  • Exercise 2

    For each meter and for each day within February 1 - 5, 2016, create an AFEventFrame based off of the "Daily Usage" template. Set the PrimaryReferencedElement to the appropriate meter.

    void CreateEventFrames(AFDatabase database, AFElementTemplate eventFrameTemplate)

  • Exercise 3

    Save the value of Average Energy Usage attribute to the PI AF server for each event frame using CaptureValues() on the event frame instance. You will first need to find all event frames using the AFEventFrameSearch.FindEventFrames() method.

    void CaptureValues(AFDatabase database, AFElementTemplate eventFrameTemplate)

  • Exercise 4

    Find all of the event frames referencing Meter003. Use the AFEventFrameSearch.FindEventFrames() method. Then print to the console the event frame name, primary referenced element name, and value of the Average Energy Usage attribute.

    void PrintReport(AFDatabase database, AFElementTemplate eventFrameTemplate)

    When the method is run, it should product the following output:

    Daily Usage-Meter003-2017-06-29-EF, Meter003, 306.564053292511
    Daily Usage-Meter003-2017-06-29-EF1, Meter003, 306.564053292511
    Daily Usage-Meter003-2017-06-30-EF, Meter003, 296.339212218409
    Daily Usage-Meter003-2017-06-30-EF1, Meter003, 296.339212218409
    Daily Usage-Meter003-2017-07-01-EF, Meter003, 297.125675030912
    Daily Usage-Meter003-2017-07-01-EF1, Meter003, 297.125675030912
    Daily Usage-Meter003-2017-07-02-EF, Meter003, 303.961577200124
    Daily Usage-Meter003-2017-07-02-EF1, Meter003, 303.961577200124
    Daily Usage-Meter003-2017-07-03-EF, Meter003, 296.181190443142
    Daily Usage-Meter003-2017-07-03-EF1, Meter003, 296.181190443142
    Daily Usage-Meter003-2017-07-04-EF, Meter003, 296.944001749179
    Daily Usage-Meter003-2017-07-04-EF1, Meter003, 296.944001749179
    Daily Usage-Meter003-2017-07-05-EF, Meter003, 294.295850664074
    Daily Usage-Meter003-2017-07-05-EF1, Meter003, 294.295850664074

TitleResults for “How to create a CRG?”Also Available in