Multiple Tag Event Scripts Running Continuously and Not Breaking a/c to its logic

Hi Everyone,
Hope you all are doing well.

I am facing a weird issue on doing scripting work on 'Tag Event Script (on Value Change)'.
Help and Guide needed for resolving it.

My Task
I have a expression tag of machine's tower light running ON/OFF status. I want to record its ON state duration, like how much time in minutes the light has been in ON state, into a separate memory tag named 'Running_duration'. The duration will be recorded in minutes only if the running light state exceeds more then 10 secs.

Issue Facing
For time recording, I have written a tag event script under the tag value change section. This script calculates the time and store it into another tag.
In the script WHILE loop has been used, but a break condition is also used to avoid infinite running of script. (picture below)

On Gateway the script keeps running, even if the running light is OFF and according to script the loop will be break.

When this technique was used on one machine's running tag, all thing works okay but when I applied this on multiple machines running light the continuous running of scripts and not stopping started.

Kindly guide me on this and also tell if any other technique to calculate the duration of an ON state of a tag.

Don't loop based on a condition or sleep in events. Any event script should execute very quickly--milliseconds. Time-based operations should be executed in a timer event (but those should also execute very quickly).

Your monitoring approach (with sleep and looping) simply cannot be done in events.

Consider historizing your tags and using the historian to compute on-time within desired time frames. If you need high precision, consider recording on and off events into a dedicated DB table, from which you can calculate and sum the deltas using aggregate functions and window (lead/lag) functions.

Some related topics:

https://forum.inductiveautomation.com/search?q=hour%20meter%20order%3Alatest

Just FYI: The tag system, by default, will only run three event scripts simultaneously in its thread pool, for the entire gateway. Your sleeping events tie up threads the pool needs. So when you try to do this with three or more machines, you lock up the tag system.

Actually, I want to record the duration of our packing machines towerlights status (Green, Red, Yellow). Like when the batch started (success count > 200), how much time (in minutes) the machine is currently on the Green Light (running state), or on the Red Light (fault state) or on the Yellow light (standby/stopped by the operator).

As, this duration will help me in the OEE calculation.

Yes, I know you want the durations for your states. Your approach to get them is broken. You need a different approach. Recording downtime is very similar, so related posts have techniques you can apply.

1 Like