3 Replies Latest reply on Aug 27, 2009 4:08 PM by spilon

    All possible digital states given one state (.net)?




      I'm new to the PI SDK so please forgive me if this is a trivial question or I've got things completely wrong, however...


      I'm trying to get a collection of all the digital states (believe this is a state set) for a tag (given a PIValue object that is a DigitalState). Essentially I would like the StateSet object which contains the DigitalState code I have. I got as far as using the Server.StateSets.Find method, however given this takes named values is this only going to search by name? What if two digital states have the same name - how will I know that I get the correct stateset?


      My code so far is this (c#):

      PISDK.Server server = SDK.Servers["myservername"];
      PISDK.PIPoints pointObject = server.PIPoints;
      PISDK.PIPoint snapPoint = pointObject["mytagname"];
      PISDK.PIValue snapShot = snapPoint.Data.Snapshot;
      //here I ensure this is a DigitalState object - omitted for brevity
      PISDK.DigitalState digitalState = (PISDK.DigitalState)snapShot.Value;
      String valueString = myDigState.Name;
      Object digitalStateObject = myDigState;
      PISDKCommon.NamedValues nvs = new PISDKCommon.NamedValues();
      nvs.Add(myDigState.Name, ref digitalStateObject);
      nvs = _server.StateSets.Find(nvs, PISDK.ContainsConstants.cntnsAll);
      //now nvs holds all my possible states... Right?

      Any and all help is appreciated, thank you for your time.

        • Re: All possible digital states given one state (.net)?

          Hi Graham,


          I am not sure that I understand what you are looking for. The digital states that a tag can usually have are the system states and the digital states from a particular state set that is defined in the point attributes.


          If you want to find out the states a digital tag can have, you access the point attributes, find the digitalset and use this stateset:

          PISDK.PIPoint snapPoint = server.PIPoints["CDM158"];

          PISDKCommon.NamedValues _nvs;
          _nvs = snapPoint.PointAttributes.GetAttributes();

          object _o = "digitalset";
          PISDKCommon.NamedValue _nv;
          _nv = _nvs.get_Item(ref _o);

          PISDK.StateSet _stateset;
          _stateset = server.StateSets[_nv.Value.ToString()];

          In addition, all tags an have a state from the SYSTEM digital state set as a value, for example "I/O Timeout"