Hi everyone,
I’m working on Ignition 8.1 and would appreciate some expert advice for tag change event design and database operations. Whether using “Value Changed” tag value event is a viable alternative to a “Tag Change” gateway event script
We have a UDT that’s instantiated around 40 times across different machines.
Each instance includes a Reset tag and a RuntimeHours tag.
When maintenance is performed, the operator sets the Reset = True.
We are in charge of setting the Reset = False.
At that moment, we need to store the current runtime hours into a database table before the counter is resets.
Right now, I’m handling this using a Gateway Tag Change script that monitors all 40+ tags.
I’m wondering if a more maintainable approach would be to use a Tag Value Change script directly on the Reset tag, something like this:
from com.inductiveautomation.ignition.common.tags.paths.parser import TagPathParser
if not initialChange and previousValue.value==0 and currentValue.value==1:
value = system.tag.readBlocking(["[.]RuntimeHours"])[0].value
if value>0:
query = 'INSERT INTO IOT.maintenance_log (tag_path, runtime_hours, maintenance_date) VALUES (?, ?, ?)'
tag_path = TagPathParser.parse(tagPath)
parent_path = tag_path.getParentPath().toStringFull()
args = [parent_path, value, system.date.now()]
datasources = ['IoT_Wind']
system.db.runSFPrepUpdate(query, args, datasources)
system.tag.writeBlocking(["[.]RuntimeHours"], [0])
system.tag.writeBlocking(["[.]Reset"], [False])
I understand the general recommendation is to avoid performing slow operations (like DB writes) inside tag change events, since this can block the tag event thread pool.
So I’d like to know what the best practice would be here:
- Wrap the DB call in system.util.invokeAsynchronous() so the tag thread returns immediately
- Use the Store & Forward system with runSFPrepUpdate() (since it handles temporary DB outages safely)
- Continue using a single Gateway Tag Change script
Thanks in advance for any insights or recommendations!
