Yep, the Calculate method returns values (at minimum) for your passed Start Time and End Time, even if they are the same time - hence 2 values.
If you pass the same start/end time you will just have to build in logic to take the first element in the PIValues colleciton as your returned value.
Note, for your example you don't have to specify the time in your expression, it will use your start/end time, which will return
"18-Aug-2009 09:19:00" 3
"18-Aug-2009 09:20:00" 3
BTW, any reason your not using PIData.ArcValue() method with RetrievalTypeConstants.rtBefore for this?
Agreed with Rhys: given the information you provided, it seems like using PIData.ArcValue() with RetrievalTypeConstants.rtBefore would be the right thing to do.
That said, I would like to add a little something on the "IPICalculation.Calculate() returning 2 at least 2 values" issue: you can work around this behaviour by executing the method with SampleTypeConstants.stInterval (rather than stRecordedValues) and specifying an interval that's bigger than the interval defined by the specified start and end times. As an example:
PICalc.Calculate('18-Aug-2009 09:20:00', '18-Aug-2009 09:20:00', 'PrevVal(''cimahi'', ''18-Aug-2009 09:20:00'')', stInterval, '1s', nil, PIVals2)
or, in C#
PIVals2 = PICalc.Calculate("18-Aug-2009 09:20:00", "18-Aug-2009 09:20:00", "PrevVal('cimahi', '18-Aug-2009 09:20:00')", PISDK.SampleTypeConstants.stInterval, "1s", null);
Hi Rhys and Steve,
The two workarounds seem reasonable for me.
I will have a play with the data and proceed with your suggestion.
Appreciate for your quick response.