2 Replies Latest reply on Jul 2, 2018 12:48 AM by John Messinger

    How to retrieve a digital state set


      I would like to know: How can I retrieve a point's digital state set using AF-SDK? Not only the state set name,  but the whole set object.

        • Re: How to retrieve a digital state set
          Rick Davin

          There's several little calls that must wrapped together to make this happen.  I offer the following as a extension method.  You can convert to a regular method by omitting the word this in the signature:


          Normally I would offer comments to explain what's going on, but really the code is straightforward enough.


          public static AFEnumerationSet GetStateSet(this PIPoint tag)
              if (tag == null || tag.PointType != PIPointType.Digital)
                  return null;
              if (!tag.IsAttributeLoaded(PICommonPointAttributes.DigitalSetName))
              string digitalSetName = tag.GetAttribute(PICommonPointAttributes.DigitalSetName).ToString();
              return tag.Server.StateSets[digitalSetName];


          Line 11 could be done in many ways.  The key is that GetAttribute returns a System.Object.  Getting the digital set name would naturally be a string, but the PIServer casts it as an Object for GetAttribute, which you want to be cast back to String again.  Besides using ToString(), either of these 2 would also work:


          • string digitalSetName = (string)tag.GetAttribute(PICommonPointAttributes.DigitalSetName);
          • string digitalSetName = tag.GetAttribute(PICommonPointAttributes.DigitalSetName) as string;



          Helpful AF SDK links to learn more.


          PIPoint Class


          PointType Property


          PICommonPointAttributes enum


          PIPoint.IsAttributeLoaded property


          PIPoint.LoadAttributes method


          PIPoint.GetAttribute method

          PIPoint.GetAttributes (bulk) method


          PIServer.StateSets property


          Note the returned "state set" is actually an AFEnumerationSet.  You may be curious to ask more about how to get values from this, but I would encourage you to learn to read how to do this on your own.

          1 of 1 people found this helpful