However, I'm trying to figure out how I can add a 'reset' function that will allow the operator to reset the runtime counter to 0 if the button is pushed.
Additionally, sometimes the operator will need to manually update the runtime counter and then the system will continue to count up from that number.
Can anyone point me in the right direction?
This particular request was a runtime counter for a motor. The client is used to being able to reset the counter at will. It scans at a fixed 1,000 ms rate.
This is the way I did it:
if ({[~]P1_RT_Reset.value}, 0,
if ({[~]P1_RI.value},
{[~]P1_RT.value} + 1,
{[~]P1_RT.value}))
It'll just increment the runtime (RT) counter (displayed in hours) every 1 second that the run indicator (RI) is turned on.
Whatever script you are using to write to your reset tag, change to simply write the current timestamp (from system.date.now()) to the memory tag.
Precise, zero gateway workload, simple reset. Even "counts" during gateway restarts.
Edit: Hmmm. The above doesn't handle the run indicator. A more complicated solution is needed for accuracy and robustness for such:
A memory tag of type double to hold "Prior Runtime Seconds"
Two memory tags of type datetime to hold the last "On" and "Off" timestamps of the run indicator.
A valueChange event script on the run indicator tag to intelligently update those memory tags (presumably all in the same tag folder). Something like this:
def valueChange(....):
prior, onTS, offTS = [x.value for x in readBlocking(['[.]PriorSeconds', '[.]OnTimestamp', '[.]OffTimestamp'])]
if currentValue.value:
# Run Indicator is ON
if offTS.after(onTS):
# Really is transition to ON
system.tag.writeBlocking(['[.]OnTimestamp'], [system.date.now()])
else:
# Run Indicator is OFF
if not offTS.after(onTS):
# Really is transition to OFF
now = system.date.now()
interval = 0.001 * (now.time - onTS.time)
system.tag.writeBlocking([['[.]PriorSeconds', '[.]OffTimestamp'], [prior + interval, now])
Your reset operation simultaneously writes now() to the OnTimestamp and 0.0 to the PriorSeconds tags.
I'm now getting errors that readBlocking, , .after, and .time are not valid attributes. I put this script into the tag editor > value changed script editor. Is this correct?
def valueChange(....):
prior, onTS, offTS = [x.value for x in system.tag.readBlocking(['[.]PriorSeconds', '[.]OnTimestamp', '[.]OffTimestamp'])]
if currentValue.value:
# Run Indicator is ON
if offTS.after(onTS):
# Really is transition to ON
system.tag.writeBlocking(['[.]OnTimestamp'], [system.date.now()])
else:
# Run Indicator is OFF
if not offTS.after(onTS):
# Really is transition to OFF
now = system.date.now()
interval = 0.001 * (now.time - onTS.time)
system.tag.writeBlocking([['[.]PriorSeconds', '[.]OffTimestamp'], [prior + interval, now]])
I am now getting no error in the tag diagnostics, however, the OnTimestamp and OffTimestamp are not being written to at all.