4 Replies Latest reply on Mar 14, 2014 2:57 PM by schutcw

    AFAttributeList.GetValue(AFTimeRange) Question

    schutcw

      Hi,

       

      I have a quick question about the the GetValue(AFTimeRange) method in the AFAttributeList class. The method returns an AFValues object, one AFValue for each AFAttribute in the list. My question is what does this AFValue represent? The documentation says it returns:

       

      "the value of each AFAttribute in this list. The index or order of each value in the returned collection corresponds to the index or order of the attributes in this list."

       

      I am a bit confused what the "value" of each AFAttribute represents. Is it max, min, avg?  If it is the current value, why would I supply an AFTimeRange?

       

      My goal is to get all the compressed values for about 250 attributes within the past 2 days. I wanted to use the GetValues method of a list for efficiency.

       

      Thanks in advance for your comments.

        • Re: AFAttributeList.GetValue(AFTimeRange) Question
          pkaiser

          When calling AFAttributeList.GetValue, each Attribute dictates what its returned value represents; in other words, it depends on the data reference of the Attribute. It's possible that you have an Attribute that knows how to make use of a timerange when requesting a single value. However, in the case of the PI Point data reference, if you check the SupportedContexts for the Attribute or its DataReference you will find that TimeRange is not supported -- the only supported context is the Time context. There is an AFAttributeList.GetValue overload that accepts an AFTime instead of AFTimeRange, but the help for the GetValue overload that takes an AFTimeRange says "If the time range context is not supported by this attribute's configuration, as indicated by the SupportedContexts property, then the context will be changed to an AFTime context at the end of the time range." So, for Attributes that use the PI Point data reference, GetValue(AFTimeRange) and GetValue(AFTime) do the same thing.

           

          I think what you're looking for is AFAttributeList.Data.RecordedValues() available in AF 2.6 Beta.

            • Re: AFAttributeList.GetValue(AFTimeRange) Question
              schutcw

              Paul,

               

              Thanks for the quick reply. Your explanation was very helpful. Also, The RecordedValues method for AFdata is exactly what I was looking for. Spent my time looking in the wrong place...

               

              Thanks again. I really appreciate it.

                • Re: AFAttributeList.GetValue(AFTimeRange) Question
                  Marcos Vainer Loeff

                  Hello Cory,

                   

                  Here is a code snippet for you. It shows that you can connect to the PI Server and to the AF Server using PI AF SDK and get the recorded values. 

                   
                      class Program
                      {
                          
                          static void Main(string[] args)
                          {
                              Console.WriteLine("\nRetrieving values from the PI Server \n");
                              PIServers myPIServers = new PIServers();
                              PIServer myPIServer = myPIServers["MARC-PI2010"];
                              PIPoint myPIPoint = PIPoint.FindPIPoint(myPIServer, "sinusoid");
                              AFValues myValuesPI = myPIPoint.RecordedValues(new AFTimeRange(new AFTime(DateTime.Now),new AFTime(DateTime.Now.AddHours(-2))),OSIsoft.AF.Data.AFBoundaryType.Inside,"",false);
                              foreach (AFValue myVal in myValuesPI)
                              { 
                                  Console.WriteLine(myVal.Value + "," + myVal.Timestamp.LocalTime.ToLocalTime());               
                              }
                  
                              Console.WriteLine("\nRetrieving values from the AF Server \n");
                              AFAttribute mySinusoidAttribute = AFObject.FindObject(@"\\MARC-PI2014\AFSDK Test\Cdt158|Sinusoid") as AFAttribute;
                              AFValues myValuesAF = mySinusoidAttribute.Data.RecordedValues(new AFTimeRange(new AFTime(DateTime.Now), new AFTime(DateTime.Now.AddHours(-2))), OSIsoft.AF.Data.AFBoundaryType.Inside,null, "", false);           
                              
                              foreach (AFValue myVal in myValuesAF)
                              {
                                  Console.WriteLine(myVal.Value + "," + myVal.Timestamp.LocalTime.ToLocalTime());
                                
                              }                      
                              Console.ReadKey();
                          }
                      }
                  

                   Hope this helps you!