6 Replies Latest reply on Jul 18, 2011 5:07 PM by rzandvliet

    AFAttribute GetValues




      The GetValues() method returns all the data for an attribute for the time range. Is there any method that returns values for the attribute but in specified intervals?




      An AF Attribute references a PI Point that is collecting data every 2 seconds. When we call GetValues() for this attribute for a time range, it gives all the data collected. Is there a function that can return values for the same attribute but for 1 hour interval for the given date range.



        • Re: AFAttribute GetValues



          You can try the following:

          AFAttribute a = c.Attributes["point1"];

          AFTime st = new AFTime(DateTime.Today);
          AFTime et = new AFTime(DateTime.Today.AddHours(2));

          AFTimeRange tr = new AFTimeRange(st, et);

          AFValues vals = a.GetValues(tr, -3, a.DefaultUOM);

          foreach (AFValue val in vals)
              Console.WriteLine(val.Timestamp.LocalTime.ToString() + val.Value.ToString());

          The important thing to note is that we are using the overload of "AFAttribute.GetValues(AFTimeRange timerange, int numberofvalues, UOM)" here. A negative number would get you a fixed number of interpolated results, supported by PI Point DR.


          So in my example, start time is 12 am today, end time is 2 am, setting -3 will give me the result of 3 interpolated values:


          12/1/2009 12:00:00 AM 168.1097
          12/1/2009 1:00:00 AM 167.5027
          12/1/2009 2:00:00 AM 161.7574


          You would probably need to add on additional method to translate a fixed interval to a number of intervals before passing to AFAttributes.GetValues(). =)