tag.writeSynchronous not reflected immediately?

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
system.tag.writeSynchronous("DoTask", 0)

#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.

Am I misunderstanding how this should work?

writeSynchronous can’t be used in the foreground. take a look at this thread:

I believe the writeSynchronous should work like you want, but it doesn’t block other writes to that tag while your round trip is busy.

How often, or on what triggers is other code writing to that tag?

Does it always fail, or only intermittent? And what happens if you sleep for a second before reading the tag again?

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.


Thanks Jordan,

You were right. I assumed that since it was on the gateway it was already a background task. Clearly that was a wrong assumption. It works as I expected now.