Hello, this should be the series for beginners in using PI AF SDK with C#.

Today we will be creating a new project in the Visual Studio (VS).

 

After installation

First most important thing. If you have VS 2010, uninstall it, delete it, burn it and never ever use it again.

Second thing, not so important. We are cool programmers so we know, that we can use dark version of VS. It is so cool to have it.

     Tools --> Options --> Environment --> General --> Color theme: Dark

Create a new project

Now we can create new project for our PI AF SDK application.

1. Start a project creation

     You have more options

          a) File --> New --> Project

         

          b) New Project... on the start screen:

              

2. Configure new project

Now we should see the New Project window.

     a)We need to choose language of the project. We will be working in the C# so choose C# from the tree on the left.

     b) Now we need to choose type of the project. For purpose of this series we will be using Console Application type:

     c) Fill the project name on the bottom of the window

     d) Hit OK

If you didn't change location, you should have new folder in ...Documents\Visual Studio XXXX\Projects\Name_of_your_project.

 

Add PI AF SDK library reference

You should have Solution Explorer window on the right.

If you don't see it you need to open it.

View-->Solution Explorer

1. You should see tree structure with References item in it.

2. Right click on it and choose Add Reference...

3. Now you need to choose Browse in the tree on the left and then Browse button on the bottom.

4. Browse to the %pihome%\AF\PublicAssemblies\4.0 and choose OSIsoft.AFSDK.dll, hit Add and OK. If your library is already listed in Browse --> Recent, just check the check box next to it and hit OK.

5. Now you should see this library in the References

This is just base library, but it will be enough for now.

 

Reference the library in the code

Main file of your code is Program.cs. You should see it opened in the main window and in the tree structure in the Solution Explorer.

C# is object oriented programming language and it use the 'dots' syntax. If you want to use some object from AF SDK library, just write OSIsoft.AF. and you should obtain the list of objects in the library.

Example:

OSIsoft.Af.PiSystem

 

Usually we don't want to write OSIsoft.AF. each time when we want to put some object, because it makes code messy and messy code is the enemy.

So we need to add OSIsoft.AF to the using list at the beginning of Porgram.cs

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OSIsoft.AF;

 

 

Now you are able to write just objects names.

Example:

PISystem

 

HINT FOR VS: If you start writing, VS is suggesting list of what you want to put there. You can see this list any time by hitting Ctrl+Space.

 

End

This is end of this chapter. In the next chapter we should look on how to choose a PI Server and print some information.