Skip to content

Instantly share code, notes, and snippets.

@jrsconfitto
Created January 23, 2012 14:18
Show Gist options
  • Save jrsconfitto/1663361 to your computer and use it in GitHub Desktop.
Save jrsconfitto/1663361 to your computer and use it in GitHub Desktop.
Programming PI AF

Programming PI AF

Just a few things that i'm learning

Event Frame Reference:

  • Built into the AF SDK.
  • Uses packages:
    • OSIsoft.AF.UI
    • OSIsoft.AFSDK
  • The AF Programming reference and AF User Interface components reference should contain the documentation for these things

Enumeration Sets

When choosing the simplest way to think about it, i think that these are the same thing as digital states.

Categories

i think categories exist to... wait for it... categorize. i dont see much else to them besides creating a category and then being able to link EventFrames, ElementTemplates, and other AFObject objects to them. i'm guessing it allows for easier searching of AF Objects within the system by filtering by Category.

In my examples, i'm assigning Categories to EventFrame Templates when i create them.

Events

It's possible to receive events through the AF SDK. i think that the events will fire on any change to an element, category, attribute, or any other AF Database change in the current application space, but refreshing the database is required to register events that aren't in the current application space. This is why the code example in the SDK reference seems strange due to the refresh timer firing allowing for events to come through.

Attributes that are fed from PI tags will not register events in AF. You must use EventPipes on the specific tags in order to get event information.

It looks like any attribute change events are reported back under their parent Element. Therefore to the system, it looks like the Element itself has changed (which i guess it has). The event argument passed back as type AFChangedEventArgs. Also, attribute changes are reported back to the application under their parent element if they are affected by AF.

It looks like Events can be registered for any AF object in the system. i'm not sure if there are any exceptions to that but i'm testing it now. i'm still not sure how to get Events for a specific object registered though :(

AFNotification Namespace

Looks like this is the place to sign up for notifications based on changes in the PI System. i think this is mostly the notifications that deal with stuff similar to TopView. i think that this is the mechanism for emailing people issues.

Make sure to import or use the OSIsoft.AF.Notification package.

Nice coding tips

  • Need to find all the elements that use your template?
Dim afDatabase As AFDatabase 'Instantiate this
Dim template As AFElementTemplate = afDatabase.ElementTemplates("Your template name here")
Dim elements As AFNamedCollectionList(Of Asset.AFBaseElement) = template.FindInstantiatedElements(False, AFSortField.Name, AFSortOrder.Ascending, 100) 'Only loads the given number  of elements into memory

JavaScript?

There's always a JavaScript block in the examples. What's up with this? Is there a way to communicate with the PI Server via JavaScript? Can i load this crap into nodejs?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment