Write values to a tag on a Tag Change Script

Hello, i’m looking for the best way to write to an OPC boolean when a tag changes. Once ‘true’ is written on the boolean tag, I’d like to wait 1 second and write a ‘false’ value back.
I need this script to run all the time so I tried using a Tag change script (in Gateway Event Script). I know from other posts on this forum that in order to put a delay on a script, time.sleep() must not be used risking the gui to freeze.
However the system.util.invokeLater doesn’t work on the gateway scope, so what is the method to follow in order to do what I want?

There is no official way to run something “later” in the gateway. The closest would be to use a sleep inside of a invokeAsynchronous() thread. If you do this often, consider using a fast timer event script, checking a timestamp to tell it when to write false.

Another possibility would be to use the ‘invokeLater’ emulation from later.py. It uses an unofficial interface, though.

2 Likes

I ran into a similar issue a short time ago. what we did was make an expression tag with dateExtract(now(1000),“second”) as the expression and a tag change script that checked if the other tag = true then write false to the other tag. the only thing with this method is that if the tag changes to true in the middle of a second, you wont get a full second before it turns false again.

Thanks alot pturmel.
I have put the later.py code in a shared script and used the writeTagLater and it works perfect.
Thanks again ! :+1:

1 Like