-
Re: AFAttribute GetValues
hanyongDec 1, 2009 6:33 AM (in response to mrai)
Hi,
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.7574You would probably need to add on additional method to translate a fixed interval to a number of intervals before passing to AFAttributes.GetValues(). =)
-
Re: AFAttribute GetValues
mrai Dec 1, 2009 3:47 PM (in response to hanyong)Thank you so much for your help!!
-
Re: AFAttribute GetValues
cescamilla Dec 1, 2009 3:53 PM (in response to hanyong)Good catch Han Yong! I didn't know that feature existed, can you tell us where in the manual did you find it? :)
-
Re: AFAttribute GetValues
hanyongDec 1, 2009 11:30 PM (in response to cescamilla)
If you look into the AF SDK Reference, under OSIsoft.AF.Asset namespace, find AFAttribute and look at the details of GetValues(AFTimeRange timerange, int numberOfValues, UOM desiredUOM). This is one of the 3 overloads for AFAttribute.GetValues() method.
Under the Parameter section of the page, it is mentioned about "the number of values desired. If 0, then all recorded values should be returned. The method may return more values than requested. If the number of values requested is less than zero, then if supported, the Data Reference will return interpolated values across the timeRange."
Of cause "if supported" is an important point to note here, not all Data Reference supports this. Fortunately PI Point Data Reference does. =)
-
Re: AFAttribute GetValues
cescamilla Dec 1, 2009 11:33 PM (in response to hanyong)Great, thanks for the reference!
I'll make sure that I reference your post if this question happens again.
-
Re: AFAttribute GetValues
rzandvliet Jul 18, 2011 5:07 PM (in response to cescamilla)It is also working for me!!
-
-
-
-