AnsweredAssumed Answered

We have a problem with an IPICalculation for an expression.

Question asked by andrew_Inwood on Feb 3, 2015
Latest reply on Apr 10, 2015 by gregor

We inherited some PI SDK code ion a VB6 program.  It has worked reliably for a long time, but now appears to be giving an error.  We suspect that the cause of the error may be related to some changes we made "in the field", where we have some daily totalisers that a flow computer writes to PI periodically, and we reset the time clock on that totaliser.... but that is not what I want to focus on / ask.


The code we inherited is as follows:


Function CalcPIexpression(expr1, StartTime, EndTime)

'This Function returns a Performance Equation result

'which you'd normally be calculating as a DATASET in a PI Display

Dim srv As Server

Dim ipiCalc As IPICalculation

Dim vals1 As PIValues

Set srv = Servers("our server")

Set ipiCalc = srv

Set vals1 = ipiCalc.Calculate(StartTime, EndTime, expr1,
stRecordedValues, "")


CalcPIexpression = vals1.Summary(StartTime, EndTime, astAverage).Value


End Function


The function is working in some cases, but failing with this code:

DataArray(10, 6) = Format(CalcPIexpression("('KFTR-6000DA'-'KFQI-6000DA')/(86400-DaySec('*'))*1000000/TagAvg('KCVIR-6000A', '*-3600s', '*')", "*-1m", "*"), "0.0")


Now:  The purpose of this calculation is to determine the required gas flow rate for the day.  The first part is working out the energy required to be delivered.  'KFTR-6000DA' is the daily total we must deliver; 'KFQI-6000DA' is the volume so far.  The difference between them is the remaining energy for the day.  (86400-DaySec('*') is working out the number of seconds remaining in the day to flow this gas, and then we divide through by the average of 'KCVIR-6000A', which is the gas calorific value.  The method is interesting (using an expression calculation), but OK for what we want to do.


The "problem" is that it is failing with the error:

"Runtime error '-2147024809 (8070057) Requested summary range outside Pivalues time range by: 270000000 micro seconds".


The error is reasonably consistent, althoughthe number of microseconds varies.  Can someone please explain this error to me, including possible causes and what we may try to resolve it?  If we have to, we will implement a more robust calculation (get tag values and do the math outside an expression), but I really would like to understand the error and see if we can fix it without changing the code too drastically (this function is called elsewhere, and seems to work on other tags OK).