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.




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:




Here's what this app will use instead:






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


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:






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.





Reference links:


AFSDK Development


Not all PI Digital State Sets can map to an AFEnumerationSet


StateSets to EnumerationSets


Using AF SDK RDA to write to tags


General .NET Development


Best practices for using strings in PI Tags