|
|
Rank: Newbie Groups: Member
Joined: 8/17/2010 Posts: 7 Location: mississippi
|
Hi PI people,
I'm working in VBA and need to pull in the last value for a given time period.
Right now I am pulling back all of the pivalues for a month. Then I am looping thru each value and comparing the timestamps to determine with timestamp is the last one for that month.
Is there an easier way to do this?
Thank you.
|
|
|
|
|
OSIsoft vCampus is a subscription-based, online offering that consists of providing everything people need to develop applications on the PI System. We invite you to take a "tour" of the OSIsoft Virtual Campus - also feel free to consult the FAQ or contact OSIsoft vCampus for more details.
|
|
|
Rank: Member Groups: Member
Joined: 11/30/2010 Posts: 15 Location: New York, USA
|
i'm sure there is. can't you pull all of the data for the time period of interest (*-1 month to *) and then use the index count property to just reference the very last value, by definition the last value will be the most recent I believe, something like:
Dim PiPt As PISDK.PIPoint Set PiPt = PISDK.Servers("Pi Server").PIPoints("Pi Tag Name")
Dim pivals As PISDK.PIValues Set pivals = PiPt.Data.RecordedValues(StartTime, EndTime, btInside, filterExp, fvRemoveFiltered)
Dim pival As PISDK.PIValue Set pival=pivals(pivals.count).value
'pival references the last value for your tag in interval starttime to endtime
might wanna wait for someone else to give you a better idea
|
|
|
Rank: Advanced Member Groups: Member
Joined: 5/28/2009 Posts: 75 Location: Cheshire, UK
|
sativa, could you not use the VBA equivlaent of PIArcVal(), provide the end time and request the 'previous' value. e.g. PIArcVal(tag,time_end, 1,server,"previous") I don't know the VBA for this but I'm sure it's straight forward. Miles EDIT: Just found an article by Rhys that covers this http://www.rjksolutionsl...nd-Archive-values.aspx.
see "PITag.Data.ArcValue("*-1d", rtAuto)" about half way down the main ReadSinusoid() routine. Just replace 'rtAuto' with 'rtAtOrBefore' or 'rtBefore'. MilesUK ProcessBook v3.0.15.3
|
|
|
Rank: Newbie Groups: Member
Joined: 8/17/2010 Posts: 7 Location: mississippi
|
Thank you both! I went ahead and implemented the method provided by ejyoungone and that seems to be working well. I am curious about mileUK's version. Once I have completed the rest of the work, I'm on a tight schedule, I might try that one out as well. Thanks so much for the replies, they are truly appreciated.
|
|
|
Rank: Advanced Member Groups: Member
Joined: 5/28/2009 Posts: 75 Location: Cheshire, UK
|
sativah, you are welcome. If your working with Excel then the formula: PIArcVal(tag, "01-May-2011", 1, pi_server, "previous only")will return the latest value in PI for 'tag' that is BEFORE "01-May-2011". The timestamp "01-May-2011" is really "01-May-2011 00:00:00" i.e midnight on the morning of the 1st of May. The latest possible value would therefore be for "30-Apr-2011 23:59:59". This method will return only a single value (& it's cooresponding timestamp) rather than retrieve all the data for a month and then have to determine the latest value. Possibly more efficient but that depends on what you are doing with the data elsewhere of course. Miles MilesUK ProcessBook v3.0.15.3
|
|
|
Rank: Member Groups: Member
Joined: 11/30/2010 Posts: 15 Location: New York, USA
|
ended up working out sativah?
|
|
|
Rank: Advanced Member
 Groups: Member
Joined: 11/13/2011 Posts: 77 Location: Middle East
|
I think, you can use built-in function in SDK (but, for C#) Code: PIValues pv1 = point.Data.RecordedValuesByCount(DateTime.Now, 1, DirectionConstants.dReverse);
point = PIPoint object. First argument = StartTime Second argument = how much values you want Third argument = direction in time: forward from StartTime or reverse from StartTime The object, you get is a list of PIValues
|
|
|
|
Guest
|