I have a gateway tag change script, I wanted to insure only executed once, it sends an email and I don’t want to spam the recipients if we have a network error. So I wrote it like this…
trigger = system.tag.read(“DoTask”)
if trigger.value == 1:
#tell the plc we are good
#check that everything worked
trigger = system.tag.read("DoTask")
if trigger.value == 0:
#do the task
I figured this way I was guaranteeing to only send the message once and I could use the writeSynchonous since I was executing in a gateway script. The code executes, however it seems the writeSynchonous is not really synchronous. In the next read, my trigger.value still returns true.
It is almost always unwise to depend on any synchronization of a piece of data that exists in two places (PLC and Ignition) and can be written from either direction at any time. Consider using two separate integer tags, one that the PLC increments to trigger your code, and another where you write the last triggered value. The latter tag would be a memory tag if the PLC’s trigger is “fire and forget”, or another PLC address if the PLC needs an acknowledgement. Only the PLC writes to the first tag, only Ignition writes to the second tag.