I am a beginner in using/accessing pi, so please excuse me if this has been answered before. I have looked around in the previous posts but was not able find any answers.
I am trying to access averaged database values over a given time range. I am using PISDK to talk to database rather than creating PIDatalink string formulas that can be used to call the values (as has been suggested in several posts), In my view think the former though difficult (for a novice like me) is a cleaner solution to implement.
I am managing to extract single values for a given time stamp using following script (excel VBA):
'*****************************************************************
1 -- Dim Pnt As PISDK.PIPoint
2 -- Dim PntVal As PISDK.PIvalue
3 -- Dim PntVals As PISDK.PIValues
4 --
5 -- 'ConnectToPI - Module to connect to PI
6 -- Set Pnt = PIServer.PIPoints("TagName")
7 -- Set PntVals = Pnt.Data.RecordedValues("*-1h", "*", btInside)
8 --
9 -- irow = 12
10 -- For Each PntVal In PntVals
11 -- 'Debug.Print PntVal.TimeStamp.LocalDate & " " & PntVal.Value
12 -- Cells(irow, 3) = PntVal
13 -- Cells(irow, 2) = PntVal.TimeStamp.LocalDate
14 -- irow = irow + 1
15 -- Next PntVal
16 --
17 -- Set PntVals = Nothing
18 -- Set Pnt = Nothing
19 -- 'DisconnectPI - PI Disconnect module
20 -- End Sub
'*****************************************************************
I tried to replace line 7 with
7 -- Set PntVals = Pnt.Data.RecordedValues("14/11/2009 02:10", "14/11/2009 02:50", btInside, asAverage)"
but this gives me an array of values for the mentioned time interval. I can choose a save it as an array and average it but I would like PI to return only one averaged value over the given interval.
In short I am trying to implement datalink's "PIAdvCalcVal(TagName,EndTime,StartTime,"average","time-weighted",0,1,0,"pi01")" using PISDK. How can I do that? Any help would be greatly appreciated.
many thanks.
Amit