Perspective: Scripting a Momentary Button

Hey folks,

Ignition 8.0.7

I’m trying to implement a momentary button in Perspective, but the feature doesn’t appear to be available. The One-Shot Button documentation states, “If your PLC expects the HMI to reset the bit, use the Momentary Button.”

Since it seems as though the feature is not yet supported, does anyone have an example script for the button component that can reliably perform the Momentary function? I’m having a hard time replicating the function of the momentary button from Vision, and altering the PLC code is sub-optimal.

Much appreciated!

1 Like

I wouldn’t be using momentary buttons in any SCADA platform. They are inherently flawed, as any comms hiccup will leave the bit high. I’ve seen this on many occasions
I suggest you fix it in the PLC by resetting the bit. If you need push-to-activate, then use a local hardwired input.

EDIT: If you (or rather the customer) really want to do it (which you/they shouldn’t), then you can use the onMouseDown and onMouseUp event handlers to write to the tag

4 Likes

I appreciate the input, and I agree.

Unfortunately, I’ve been asked to port over the vision functionality for a client without affecting the PLC (I do not have access to the PLC currently). So while I agree with your solution, my question still stands.

1 Like

See my edit above

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

i have this issue how can i put it back the way it was ? i wrote this:

import time
system.tag.write("[default]IS15_Overheight_Rst_PB", 1)
time.sleep(1)
system.tag.write("[default]IS15_Overheight_Rst_PB", 0)

```now i want everything back to normal because my plc keep show 1 and that deactivates when the sensor is blocked but activates right way after the sensor is unblock. please advice

Please don't double-post. Persistent Tag Issue and Forced Value in PLC After Script Execution - #5 by Transistor.

2 Likes