3 Replies Latest reply on Aug 24, 2009 12:21 AM by kevintmoon

    IPICalculation.Calculate() method always returns two values




      FYI, I use PI Server v3.4.375.80 , and PI SDK v1.3.6 build 361.


      The following is the screenshot of the pi tag








       I extract the data using IPICalculation.Calculate() method as the code below (The Pascal Delphi code…)


        PIVals2    : PIValues;      // IPICalculation interface declaration
        PICalc    : IPICalculation; // the collection of PI Value declaration


      // some code…

      PICalc.Calculate('18-Aug-2009 09:19:00', '18-Aug-2009 09:20:00', 'PrevVal(''cimahi'', ''18-Aug-2009 09:20:00'')', stRecordedValues, '', nil, PIVals2);

      // some code…



      PIVals2 returns two value, and both of them are 3.
      The PIVals2 always returns two values, no matter what the input is. Is it correct? Or was it me who gave the incorrect input?
      My client needs only one value to be returned. FYI, this is also happen with “NextValue”, and “TagVal” expression. 


      Thanks in advance for your support and I look forward for your response.

        • Re: IPICalculation.Calculate() method always returns two values

          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?

            • Re: IPICalculation.Calculate() method always returns two values

              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);