Perspective: Scripting a Momentary Button

I had the same application where I could not alter the PLC code and needed a momentary script. This would write a tag on, delay 1.5 seconds, and then write it off again.

from threading import Timer

def writeOn():
    system.tag.write("[default]Testing Tags/Bool Test", 1)
def delayOff():
    system.tag.write("[default]Testing Tags/Bool Test", 0)

writeOn()
t = Timer(1.5, delayOff)
t.start()

Again, as stated - it is not recommended as there is no way to guarantee it gets written off again. However, it works in a pinch.

2 Likes