System.Tag.Toggle?

Hi All,

Hoping someone could advise on whether there is any sort of ‘system.tag.toggle’ function that exists, similar to system.tag.write ? Basically, i want to write a tag to ‘1’ and then back to ‘0’ a second or two after via the script editor on the button.

Below is how I am currently accomplishing it, but i don’t believe this is best practice. If anyone could advise a better solution it would be appreciated.

Many Thanks

Try this (this is ‘real’ toggle):

system.tag.write("MYTAG_1", not system.tag.read("MYTAG_1").value)
1 Like

Hi @zxcslo - that is a really useful negate function, however, we need to write from 0 to 1, and then from 1 to 0, all in one button click. Sort of like what a momentary pushbutton would do. I might explore the ‘invoke later’ function.

InvokeLater will execute the function after the defined time.

You can probably do something like :

import time
system.tag.write('[Testing]Trial.value', 1)
# sleep(timeInSecond)
time.sleep(1)
system.tag.write('[Testing]Trial.value', 0)

if this is used more often :
create a function and just pass the tagPath to the function.

1 Like

Thanks for sharing this! We want about a 3 second delay before resetting it, so InvokeLater might be the solution. I have saved this example code for future use though.

Cheers.

Yes, you’ll want to use invokeLater–not sleep–for the second write, as in this example:

1 Like

Super. Thanks for sharing this.

1 Like