1 of 1 people found this helpful
I believe this issue arises when a float or int tag has a digital state over the entire time period of the TimeEQ evaluation. So in this case, when the error occurred, the tag had a digital state from *-1h to *. I believe this issue also arises in Performance Equations, as the TimeEQ from ACE and TimeEQ from PE's all boil down to the same native methods. If the above condition arises, then the state "Calc Failed" will be returned to ACE and it tries to be cast to a Double. Hence, there is an InvalidCastException thrown as you saw.
If the tag has a good value at any time during the requested range in TimeEQ, then the method will return the correct result. The behavior looks to be an issue with the calculation libraries. I'll try to find further details and get back to you.
In the meantime, a workaround is to use a Try/Catch pattern and handle the InvalidCastException. You may just have to return the entire time range (in seconds) in the Catch block for now as a workaround.
Try time = tag.TimeEQ("*-1h", "*", "Comm Fail") Catch ex As InvalidCastException 'Handle exception here End Try
I coding more function to skip that error as below then it 's work .
If tag.PctGood("*-1h", "*") = 0 Then
temp = 3600
temp = tag.TimeEQ("*-1h", "*", "I/O Timeout")