1 Reply Latest reply on Jul 25, 2017 12:50 PM by Rick Davin

    How to get the StateNo of an Enum Set using AF sdk ?


      Problem Description :

      I have a particular Enumeration Set "XYZ" applied to an AF attribute, enum set as below:


      StateNo   Value

      0               True

      1               False


      The AF attribute value shows as True/false. However, i need to get the state no, how it needs to be done using AF SDK code ?

      (Similar functionality is available using PI PE with the help of function "StateNo"-gets the code number of a digital state. How to do this using AF SDK ?)

        • Re: How to get the StateNo of an Enum Set using AF sdk ?
          Rick Davin

          An AFEnumerationSet does not have a StateNo.  Neither would a PI StateSet. Both are collections.  Just like a StateSet is a collecton of DigitalState(s), and each DigitalState has a Code property, an AFEnumerationSet is a collection of AFEnumerationValue(s) with each of them having a Value property.


          The way its done with AFEnumerationValue is the similar to how one would check an AFValue.Value to see if it's a DigitalState or a Timestamp or Blob.  That is you check the type of the AFValue.Value, then cast accordingly.


          if (value.Value is AFEnumerationValue)
              var state = (AFEnumerationValue)value.Value;
              // Use state.Name for text, e.g. "True"
              // Use state.Value for number, e.g. 0



          Here is Live Library Help on AFEnumerationValue.


          That should point you in right direction.