rdavin

StateSets to EnumerationSets Project

Discussion created by rdavin Employee on Feb 12, 2013

I have attached a VS 2010 Windows Form project written in C# to export PI state sets into AF. That plus for fun it dumps the AFSystemStateCode enumeration to an AFEnumerationSet. Also uses .NET 4.0, PISDK, AFSDK, and AF.UI. Even though working with state sets requires using PISDK.Server, the AF.UI is used for the PIServer pick list for 2 reasons: (1) I only need one UI reference in the project, and (2) the AF.UI has a handy SelectionChange event.  All it takes is small bit of code to switch gears from AF.PI.PIServer to PISDK.Server.

 

1207.app-window.png

 

The safest thing to do is create a new AFDatabase and export the objects into it. The default is to prefix the enumeration sets with “ds”. My intent here was that if you were doing the export into an older database that the prefix would make it less likely to bump up against something that already exists, plus it would group the enum sets together.

 

Export to Enumeration Set

 

Given the an AFEnumerationValue must be not be empty and must be unique within its AFEnumerationSet, I cautiously generate my own unique name before attempting to use the actual name from the PI digital state. In case of empty strings or duplicates, the generated unique name will be used and the description will be flagged accordingly.

 

Here's original PI State Set with both empty and duplicate names:

 

6888.Bad-AF-Enum-Set.png

 

Here's what this app will use instead:

 

1614.fudged-digital-state-set.png

 

 

 

My original thought was to assign a “PI Digital State” category to the AFEnumerationSets, but this is not currently possible. So for Alex Brodskiy, you get my up vote for this feature request.

 

Enumeration Sets Categories
http://vcampus.osisoft.com/discussion_hall/development_with_osisoft_sdks/f/28/t/3707.aspx

 

Export to AFTable

 

The “PI Digital States” table honors exact names and duplicates by fully exporting the entire state set collection. However, if you have duplicates you are not guaranteed a 1:1 lookup of a Code based on its StateSet and Name.

 

Example snippet:

 

0245.digital-states-table.png

 

 

 

Create Standard System Set

 

There are 51 items in what I call the Standard State Set which is derived from the AFSystemStateCode enumeration set. This differs from the 318 items in the actual SYSTEM state set on the PI server. Note the AFSystemStateCode enum does not come from a PI server. I include it merely for comparison but also to underscore that it has a fewer choices than the actual SYSTEM set.

 

8053.standard-state-set.png

 


 

Reference links:

 

AFSDK Development

 

Not all PI Digital State Sets can map to an AFEnumerationSet
http://vcampus.osisoft.com/discussion_hall/development_with_osisoft_sdks/f/28/t/3817.aspx

 

StateSets to EnumerationSets
http://vcampus.osisoft.com/discussion_hall/development_with_osisoft_sdks/f/28/p/882/4231.aspx#4231

 

Using AF SDK RDA to write to tags
http://vcampus.osisoft.com/discussion_hall/development_with_osisoft_sdks/f/28/t/3806.aspx

 

General .NET Development

 

Best practices for using strings in PI Tags
http://vcampus.osisoft.com/discussion_hall/generic_forums/f/7/t/3797.aspx

Outcomes