5 Replies Latest reply on Jun 20, 2017 4:33 PM by JánosPetró

    PI questionable flag


      How could I set/get the questionable flag using c# and PISDK?

        • Re: PI questionable flag
          Rick Davin

          Hi Kenneth,


          If this is new development work, you should read Deprecating the PI SDK.


          Regrettably the LiveLibrary Help for PI SDK is limited to VBA examples.  Here's an example for writing the Questionable flag.


              PISDK.PISDK sdk = new PISDK.PISDK();
              Server mySrv = sdk.Servers.DefaultServer;
              PIPoint myTag = mySrv.PIPoints["TEST"];
              PIData myData = myTag.Data;
              PITime myTS = new PITime();
              myTS.LocalDate = DateTime.Now;
              PIValue myVal = new PIValue();
              myVal.Value = 1;
              myVal.TimeStamp = myTS;
              myVal.ValueAttributes.Add("Questionable", true);
              myData.UpdateValue(myVal, myTS);



          Reading an existing Questionable flag can be done 1 of 2 ways:

          1. using the IPIValueAttribute Interface, which is a secondary interface to PIValue, OR
          2. using the PIData.RetrievalAttributes method


          Assuming you have a PIValue variable named pv, something like this could be used to read Questionable:


          IPIValueAttribute pvFlags = pv;
          if (pvFlags.Questionable)
             // Questionable is true logic here



          BTW, it's so simple to do this with AF SDK as the Questionable flag is always a part of the AFValue object.  See the AFValue.Questionable property.  Also refer to PI SDK Equivalents.  The pertinent section for RetrievalAttributes states:


          This property is no longer necessary. Status bits (Questionable, Substituted, and Annotated) are always retrieved. Annotations are retrieved via AFValue.GetAnnotation

          • Re: PI questionable flag
            Guilherme Ferreira

            Hi Kenneth!


            EDIT: Hadn't seen Rick's answer...


            Which version of the PI System are you working with? For most recent versions, it is recommended to use the AFSDK instead of PISDK.

            PISDK is deprecated!


            From AFSDK help file (%pihome%\help\AFSDK.chm):


            AFValueStatus Enumeration


            This is an enumeration that defines the possible AFValue indicators when you retrieve the value of an AFAttribute.


            Namespace: OSIsoft.AF.Asset

            Assembly: OSIsoft.AFSDK (in OSIsoft.AFSDK.dll) Version:




            public enum AFValueStatus




            Member nameValueDescription
            Bad0Indicates the value is bad.
            Questionable64The value has been identified as irregular in some way by an application.
            Good192Indicates the value is good.
            QualityMask192Mask for Bad, Questionable (Uncertain), and Good quality status.
            SubstatusMask60Mask for quality substatus bits. The only substatus bit defined is Substituted.
            BadSubstituteValue60A Bad quality substatus value which indicates the value has been substituted with a bad value.
            UncertainSubstituteValue8A Questionable quality substatus value which indicates the value has been substituted.
            Substituted24A Good quality substatus value which indicates the value has been replaced after it was originally written. If the value is obtained from an AFCase and is adjusted, this flag will be set.
            Constant3Indicates the value contains an constant value which is not expected to change at runtime.
            Annotated32768Indicates the value contains an annotation. For values retrieved from the PI Archive, use the underlying PIPoint to obtain the value of the annotation.



            When obtaining the value of an attribute, the AFValue.Status property will indicate the status of the value. You can also use the AFValue.IsGood, AFValue.Substituted, AFValue.Questionable, and AFValue.Annotated properties directly. When obtaining large numbers of values, it is more efficient to access the values and status using the AFValues.GetValueArrays method which returns the status information as flags.

            The quality bit field, obtained with the QualityMask, may be one of three values: Bad, Questionable, or Good. The sub-status bits, SubstatusMask, contain additional information of the quality, based on the overall quality.




            • Re: PI questionable flag

              Hello Kenneth,


              I had a simple C# code using PIValue.ValueAttributes similar to this below. (It is working with PI SDK yet... ) :


                        _pisdk = new PISDK.PISDK();


                        PISDK.Server piServer = _pisdk.Servers["piserver"];






                        PointList pointList = piServer.GetPoints("tag='sinusoid'");




                        foreach (PIPoint mypoint in pointList) 




                              string tagName = mypoint.Name;         


                              if (tagName == "sinusoid".ToUpper())




                                  DateTime dtn = DateTime.UtcNow;


                                  double curTime = dtn.Ticks/TimeSpan.TicksPerSecond;


                                  //double curTime = (double)TimeZoneInfo.ConvertTimeToUtc(DateTime.Now);


                                  double myValue = 104;




                                  PIValue pvo = mypoint.Data.Snapshot;


                                  pvo.Value = myValue;


                                  pvo.TimeStamp = new PITimeClass();


                                  pvo.ValueAttributes.Add("QUESTIONABLE", true);  


                                  mypoint.Data.UpdateValue(pvo, 0DataMergeConstants.dmInsertDuplicates, null);