Reinitialize Memory Tag in UDT everyday

What would be the best method for setting a memory tag inside a UDT to 0 at a certain time, like midnight every day. My first thought is to loop through the udt instances and write 0 to each tag in a gateway script. Is there a better way to handle this?

How precise do you need to be? If you have some leeway, a gateway timer event that runs frequently can check a memory tag with the last reset timestamp, compute a “next due” timestamp, and compare against now(). This is practical for accuracy in the seconds to minutes range.

For accuracy within the first second or two of a given minute, consider using unsupported access to Ignition’s gateway scheduler via IgnitionGateway (SRContext in v7.9 and before). You want the fixed-rate delayed scheduler .scheduledExecutorService.scheduleAtFixedRate(). Use an initial delay to set the right time-of-day, and a 24-hour period.

Edit: That method returns a Future that can be used to cancel the scheduled event. You should tuck that into the system.util.getGlobals() dictionary. Use that to cancel a prior schedule if your script module is restarted.


Good deal. I think I remember testing some scripting you posted on doing time specific tasks with a gateway timer script to ensure running once and only once at a certain time. I can’t wait for crontab scheduling. In the meantime, that should work. I just wanted to make sure I wasn’t missing any UDT magic shortcut.