I am trying to read a tag's previous value and associated time stamp. Business requirement is to find if a tag's value is constant/stale for a configurable time period (let’s assume 30 mins, this is user configurable threshold and is being configured in ModuleDb property). In my code (please refer Complete listing of function provided below) I am using ExeTime to set current time in ACE (I am not sure if it is right way of doing though I followed a few other posts.).
I have two questions:
Q1: Why am I getting previous, current value and associated time stamps always same in debug mode (please refer following two lines of code taken from overall function listing.)?
prevTimeStamp = tag.PrevEvent(currentTimeInUTCSeconds) ' I was hoping it to get time stamp associated with previous value but in fact it gives me current time stamp preValue = tag.PrevVal(currentTimeInUTCSeconds) ' To get previous value currValue = tag.Value(currentTimeInUTCSeconds) ' To get currenet value
Q2: What is the difference between ExeTime and "*" if I use them in ACE? Or in other words what is the difference between following two function calls?
Thanks and Regards,
Thanks and Regards,
Complete listing of function.
Private Function CheckIfDataIsStale(ByVal tag As PIACEPoint) As Boolean Dim prevTimeStamp As PITime Dim preValue As Double Dim currValue As Double Dim prevTimeInUTCSeconds As Double Dim currentTimeInUTCSeconds As Double currentTimeInUTCSeconds =ExeTime 'Actually this gets passed as a parameter by calling function and I am setting this as ExeTime prevTimeStamp = tag.PrevEvent(currentTimeInUTCSeconds) ' I was hoping it to get time stamp associated with previous value prevTimeInUTCSeconds = prevTimeStamp.UTCSeconds Try preValue = tag.PrevVal(currentTimeInUTCSeconds) ' To get previous value currValue = tag.Value(currentTimeInUTCSeconds) ' To get currenet value 'StaleDataTimeLimitInSeconds is user defined number and currently defined as ModuleDb property If (currentTimeInUTCSeconds - prevTimeInUTCSeconds) >= StaleDataTimeLimitInSeconds Then 'Prev time is out of time limit threshold If (preValue = currValue) Then Return True Else Return False End If 'Prev time is within the time limit threshold, if this value is equal to current value then get one more prev value to make sure that data is stale ElseIf (currentTimeInUTCSeconds - prevTimeInUTCSeconds) < StaleDataTimeLimitInSeconds Then CheckIfDataIsStale(tag, prevTimeInUTCSeconds) 'Using recursion to execute same function End If Catch ex As Exception LogPIACEMessage(OSIsoft.PI.ACE.MessageLevel.mlUserMessage, ModuleName + ": CheckIfDataIsStale: " + ex.InnerException.Message, Context) Throw ex End Try End Function