4 Replies Latest reply on Jun 13, 2014 4:52 PM by Gregor

    How get "questionable" attribute?

    Matheuses

      I'm using C#  and I didn't get attribute "Questionable" in tag.

       

      Could anyone help me?

        • Re: How get "questionable" attribute?

          Hello Matheus,

           

          PI SDK Help (%PIHOME%\Help\pisdk.chm) has an example titled "ArcValue / RetrievalAttributes Example" that includes value attribute retrieval for Annotated, Substituted and Questionable flags. Can you please see if you can take the required information from that example?

            • Re: How get "questionable" attribute?
              Matheuses

              Gregor,

               

              I did based that example and didn't work

               

              I'm using c# and the valueattributes don't have values, but when I search by process book, there are values in tag.

               

              Code:

               

              tagSaida.DataSource.Data.Snapshot.ValueAttributes;

               

              I need get value "questionable" in tag.

                • Re: How get "questionable" attribute?
                  bperry

                  Hi Matheus,

                   

                  You must explicitly request that the data call return attributes such as Questionable. The pisdk.chm entry for RetrievalAttributes has a code snippet:

                   

                   

                   
                  dim nvs as NamedValues
                  set nvs = new NamedValues
                  nvs.add "Questionable", TRUE
                  set srv.pipoints("sinusoid").pidata.retrievalAttributes = nvs
                  

                   

                   

                  Then, subsequent data calls to that PIPoint or PointList will include the value of the Questionable flag. Does this work for you?

                   

                  Brandon

                    • Re: How get "questionable" attribute?

                      Hello Matheus,

                       

                      late but finally I found the time creating an example. I found Charlie's post very useful. The following code is a console application and has a reference to OSIsoft.PISDK, OSIsoft.PISDKCommon and OSIsoft.PITimeServer version 1.4.0 

                       
                      using System;
                      using System.Collections.Generic;
                      using System.Linq;
                      using System.Text;
                      using PISDK;
                      using PISDKCommon;
                      using PITimeServer;
                      
                      namespace AnQuSu
                      {
                          class Program
                          {
                              static void Main(string[] args)
                              {
                                  try
                                  {
                                      PISDK.PISDK mySDK = new PISDK.PISDK();
                                      PISDK.Server mySrv = mySDK.Servers.DefaultServer;
                                      mySrv.Open();
                                      if (mySrv.Connected)
                                      {
                                          NamedValues myNVS = new NamedValues();
                                          Boolean bFlag = true;
                                          object tmpobj = bFlag;
                                          myNVS.Add("Questionable", ref tmpobj);
                                          myNVS.Add("Annotated", ref tmpobj);
                                          myNVS.Add("Substituted", ref tmpobj);
                                          PointList myPoints = mySrv.GetPoints("tag = 'SINUSOID'");
                                          foreach (PIPoint myPoint in myPoints)
                                          {
                                              Console.ForegroundColor = ConsoleColor.Green;
                                              Console.WriteLine(myPoint.Name);
                                              myPoint.Data.RetrievalAttributes = myNVS;
                                              PIValues myValues = myPoint.Data.RecordedValues("*-2h", "*", BoundaryTypeConstants.btInside, "", FilteredViewConstants.fvShowFilteredState, null);
                                              foreach (PIValue myValue in myValues)
                                              {
                                                  Console.ForegroundColor = ConsoleColor.Yellow;
                                                  Console.WriteLine("   Value {0} at {1}", myValue.Value.ToString(), myValue.TimeStamp.LocalDate.ToShortTimeString());
                                                  foreach (NamedValue myNV in myValue.ValueAttributes)
                                                  {
                                                      Console.ForegroundColor = ConsoleColor.White;
                                                      Console.WriteLine("      Attribute {0} has value {1}", myNV.Name, myNV.Value.ToString()); 
                                                  }
                                              }
                                              Console.WriteLine();
                                          }
                                      }
                                      else
                                      {
                                          Console.WriteLine("Not connected to {0}", mySrv.Name);
                                      }
                                  }
                                  catch (Exception ex)
                                  {
                                      Console.ForegroundColor = ConsoleColor.Red;
                                      Console.WriteLine(ex.Message);
                                  }
                                  finally
                                  {
                                      Console.ForegroundColor = ConsoleColor.Gray;
                                      Console.Write("Done. Press any key to quit...");
                                      Console.ReadKey();
                                  }
                              }
                          }
                      }
                      

                      If you want to make your life easier and also create a future proof solution, the recommendation is to go with the recent release (2.6) or a later one of the Rich Data Access (RDA) AF SDK. Please download and install the latest bits from vCampus Download Center -> PI Asset Framework

                       

                      The 32-bit assembly can be found at %PIHOME%\AF\PublicAssemblies\4.0\
                      The 64-bit assembly is installed to %PIHOME64%Assemblies\4.0\

                       

                      Please note that you need to build against .NET Framework 4.5 what requires to use Visual Studio 2012 or later. The following example is equivalent to the above posted PI SDK example.

                       

                       

                       
                      using System;
                      using System.Collections.Generic;
                      using System.Linq;
                      using System.Text;
                      using System.Threading.Tasks;
                      using OSIsoft.AF.PI;
                      using OSIsoft.AF.Time;
                      using OSIsoft.AF.Asset;
                      
                      namespace AnQuSu
                      {
                          class Program
                          {
                              static void Main(string[] args)
                              {
                                  try
                                  {
                                      PIServer mySrv = new PIServers().DefaultPIServer;
                                      mySrv.Connect();
                                      PIPoint myPoint = PIPoint.FindPIPoint(mySrv, "SINUSOID");
                                      Console.ForegroundColor = ConsoleColor.Green;
                                      Console.WriteLine(myPoint.Name);
                                      AFTimeRange myTimeRange = new AFTimeRange("*-2h", "*");
                                      AFValues myValues = myPoint.RecordedValues(myTimeRange, OSIsoft.AF.Data.AFBoundaryType.Inside, "", false);
                                      foreach (AFValue myValue in myValues)
                                      {
                                          Console.ForegroundColor = ConsoleColor.Yellow;
                                          Console.WriteLine("   Value {0} at {1}", myValue.Value, myValue.Timestamp.LocalTime.ToShortTimeString());
                                          Console.ForegroundColor = ConsoleColor.White;
                                          Console.WriteLine("      Attribute Annotated has value {0}", myValue.Annotated.ToString());
                                          Console.WriteLine("      Attribute Questionable has value {0}", myValue.Questionable.ToString());
                                          Console.WriteLine("      Attribute Substituted has value {0}", myValue.Substituted.ToString());
                                          Console.WriteLine();
                                      }
                                  }
                                  catch (Exception ex)
                                  {
                                      Console.ForegroundColor = ConsoleColor.Red;
                                      Console.WriteLine(ex.Message);
                                  }
                                  finally
                                  {
                                      Console.ForegroundColor = ConsoleColor.Gray;
                                      Console.Write("Done. Press any key to quit...");
                                      Console.ReadKey();
                                  }
                              }
                          }
                      }