How could I set/get the questionable flag using c# and PISDK?
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();
mypoint.Data.UpdateValue(pvo, 0, DataMergeConstants.dmInsertDuplicates, null);
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;
Reading an existing Questionable flag can be done 1 of 2 ways:
Assuming you have a PIValue variable named pv, something like this could be used to read Questionable:
IPIValueAttribute pvFlags = pv;
// 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
Thanks for the info. I've make a little change to enable the casting for reading the flag
IPIValueAttribute pvFlags = pv as PISDK.IPIValueAttribute;
Makes sense. I was translating in my head from VBA and casting is done automatically by VB.
If you feel your question has been answered, please mark it as Answered.
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):
This is an enumeration that defines the possible AFValue indicators when you retrieve the value of an AFAttribute.
Assembly: OSIsoft.AFSDK (in OSIsoft.AFSDK.dll) Version: 22.214.171.12459
public enum AFValueStatus
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.
Retrieving data ...