This repository provides self-contained and reproducible samples of basic operations using AF SDK. The aim is to provide an accessible hands-on experience with the PI AF SDK using code examples that are portable and easy to follow.
Each example demonstrates a basic operation within the PI AF SDK. These examples present PI AF SDK as a set of basic "building blocks", rather than an entire "pre-packaged solution". The goal is to enable the user to learn the basic operations of PI AF SDK so they then have the tools to build more specific applications and a foundation to learn more advanced PI AF SDK concepts.
ExamplesLibrary
contains the examples. Each example is a separate class and outputs to the Console.
PI-AF-SDK-Basic-Samples
contains the Console application that runs the examples.
- AF Client 2.5+
- .NET Framework 4+
- Visual Studio 2012+
- AF Server and PI Data Archive
Many of the examples uses the NuGreen database. To use the NuGreen database, follow these steps:
- Create an AF Database named "NuGreen".
- Import the database from the provided NuGreen.xml via PI System Explorer>File>Import from File.
- Verify that a root element "NuGreen" is created inside the NuGreen database.
- Check in the changes if not done so already.
The code examples come with simple placeholders such as <AFSERVER>
and <PISERVER>
.
Please replace these with your server names before starting.
Some examples depend on having run prior examples successfully. This is because these dependent examples require AF objects and/or PI Points to have been created by the prior examples. The comments in the code above each class will explicitly list out the dependencies of each example. For instance,
/// <prerequisite-examples>
/// BuildSimpleDatabaseExample, CreateEventFramesExample
/// </prerequisite-examples>
Examples are executed by the Console application. To run a particular example, simply instantiate a new object of the desired example type and call its Run() method.
To run the AFConnectionExample, for instance, use:
IExample example = new AFConnectionExample();
example.Run()
It is recommended that for each example, the user finds the corresponding PI AF SDK method in the [online guide] (https://techsupport.osisoft.com/Documentation/PI-AF-SDK/html/1a02af4c-1bec-4804-a9ef-3c7300f5e2fc.htm). This will provide further context and reinforcement of the presented concepts.
A recommended learning path for going through the examples is as follows:
- AFElementExamples/FindElementsExample
- AFElementExamples/PartialLoadElementsExample
- AFElementExamples/LoadElementsExample
- AFAttributeExamples/FindAttributeWalkDownExample
- AFAttributeExamples/FindAttributesByPathExample
- AFAttributeExamples/FindElementAttributesExample
##Licensing
Copyright 2015 OSIsoft, LLC.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Please see the file named LICENSE.md.