OSIsoft.SDK.Controls.PIAnnotationEditor Tutorial


In this example we illustrate the use of the PIAnnotationEditor control by adding it to a Visual Studio.Net project. The example demonstrates how the application can set the editor up for editing.

  1. STEP 1. Set up the project

Start Visual Studio and select a new "Visual C# - Windows Application" project. Follow the instructions described earlier in this chapter on how to add the PIAnnotationEditor to the ToolBox.

This example uses PISDK but you don't need to add any references, just insert the editor into the form and the refrences will be cre3ated for you.

  1. STEP 2. Insert controls

From the toolbox, select and place the following controls onto the form

See the screen capture later in this chapter for placement and sizing details.

  1. STEP 3. Set control properties

Set the Text property of each label control to match the screen capture (Tagname, start time and end time).

Set the Text property of each textbox to a reasonable initial value (tagname, start time and end time).

Set the Text property of the button to RUN/Update/Refresh etc.

  1. STEP 4. Add the event handlers for the form_load and button_click

Double-click on an "empty" spot on the form and also on the button. The system will create empty events handler for you.

  1. STEP 5. Add initialization code

Add a namespace usage definition in the "using" section:

 

using OSIsoft.PISDK;

using OSIsoft.PISDK.Controls;

 

Add the following private class variables:

 

private PISDK.PISDK piSDK; // PISDK class

private PISDK.Server server; // PI Server

private PISDKCommon.NamedValues retrAttributes; // data retrieval attributes

 

Replace the Form_Load event with

 

  1. STEP 6. Add event handler code

Replace the event handler stubs that were created by the Designer with the following:

//---------------------------------------------------------

// FORM_LOAD EVENT:

/// <summary>

/// Form load event - setup the Annotation Editor.

/// Try to get some events for "sinusoid" and pass the newest one to

/// annotation editor

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>

private void Form1_Load(object sender, System.EventArgs e)

{

    try

    {

        // set the properties (setting defaults for demonstration purposes)

        piAnnotationEditor1.UpdateArchValue = true; // allow the editor to save the changes

        piAnnotationEditor1.ReadOnly = false; // allow edits

        piAnnotationEditor1.IsOldStyle = false; // use structured annotations

        // get the default server

        piSDK = new PISDK.PISDKClass(); // create pisdk class interface

        server = piSDK.Servers.DefaultServer; // get default server

        // set attribute retrieval properties

        object attVal = 1;

        retrAttributes = new

        PISDKCommon.NamedValuesClass();

        retrAttributes.Add("All", ref attVal); // always get all attributes

    }

    catch (Exception ex)

    {

        MessageBox.Show(this, "Load error: " + ex.Message, "Initialization Failure");

    }

}

 

// BUTTON_CLICK EVENT:

/// <summary>

/// Get archive events for the selected tag and timerange.

/// Setup annotation editor (selected tag, newest value)

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>

private void button1_Click(object sender, System.EventArgs e)

{

    try

    {

        PISDK.PIPoint pPoint; // The tag we use

        pPoint = server.PIPoints[textBox1.Text]; // get specified tag

        PISDK.PIData pData = pPoint.Data; // data object of the point

        pData.RetrievalAttributes = retrAttributes; // get all attributes

        // Now get data - MODIFY THE SEARCH IF NO DATA COMES BACK

        PISDK.PIValues piValues = pData.RecordedValues(textBox2.Text, textBox3.Text,

        PISDK.BoundaryTypeConstants.btInside, "",

        PISDK.FilteredViewConstants.fvUseExpressionTimes ,null);

        if (piValues.Count == 0)

            MessageBox.Show(this, "No events returned, please modify call args", "No Data");

        else

        {

            piAnnotationEditor1.resetAll(); // reset editor settings...

            PISDK.PIValue pValue = piValues[piValues.Count]; // get last event

            piAnnotationEditor1.PITag = pPoint; // set tag

            piAnnotationEditor1.CurrentValue = pValue; // set value

        }   

    }

    catch (Exception ex)

    {

        MessageBox.Show(this, "Update error: " + ex.Message, "Get events Failure");

    }

}

 

  1. STEP 7. Test the control

Save the project and run it. Set the tagname and timerange variables properly and press RUN. The informational fields/properties of the annotation editor will be filled with tag/event data if the call returned at least one event. You should be able to add annotations and modify/delete existing annotations.

This is how the completed form should appear:

 

Enabling Operational Intelligence