Momentary Button with Confirmation Pop-up

Good day all,

I'm trying to make a momentary button but with a confirmation pop-up.

I noticed the option for the confirmation pop-up is only inherent to a few components (2-State Toggle, One-Shot Button). I tried using the one-shot button but it does not work how I expected and don't want my OPC client to have to send a response back after receiving the one-shot.

That being said, I was trying to be clever and use the following script on a momentary button but neither attempts have worked.

ATTEMPT #1: Reading and writing direct with custom template parameter. Template parameter bound to OPC tag.
RESULT: Works inconsistently. Sometimes the OPC tag changes, sometimes it does not. Sometimes gets latched on.

if (system.gui.confirm('Are you sure?', 'Confirm')):
	event.source.parent.Copy_PB = 1
	
	if (event.source.parent.Copy_PB == 1):
		event.source.parent.Copy_PB = 0
	else:
		event.source.parent.Copy_PB = 0

ATTEMPT #2: Reading and writing direct with OPC tags.
RESULT: Allows writing to the tag but then script crashes after that.

if (system.gui.confirm('Are you sure?', 'Confirm')):
	system.tag.writeBlocking('X', 1)

	if system.tag.readBlocking('X', 1):
		system.tag.writeBlocking('X', 0)
	else:
		system.tag.writeBlocking('X', 0)

What other alternatives came I look into to get the functionality I'm looking for?

Since I think my first attempt was failing because of timing, I considered using some kind of delay script but I heard horror stories about that causing problems.

Thanks!

How can this possibly work? The user would have to release the momentary button to click on the confirmation, so the button isn't pressed any more. Are you sure you want a momentary button?

I think he might be trying to write a 1 then a 0 in quick succession after confirmation, unless I'm mis-understanding the code.

1 Like

Maybe, but confirmation is before any action, so that can't work.

Ah, I see what you mean, I was thinking from using a momentary button as a one off click, not holding it.

@Derek_Lyons If you need confirmation on a button that needs to be held, have some other component that enables/disables the actual momentary button that will be held. That toggle can be completely on ignition side, its just so operators have that extra step to confirm that yes they want to hold this button. You can also have a timer that resets the toggle after a certain period of the button not being pressed if needed.

2 Likes

@ryan.white Your first comment was spot on. I want a momentary button to pulse a boolean OPC tag. If the operator presses the button, a confirmation window will pop up. If the user intended on pressing the button, the operator presses "YES", and the boolean is pulsed hi then lo. If the button press was a mistake, the operator presses "NO" and nothing happens.

Based on your second comment, it sounds like my best option is a toggle button with a delay timer to reset the toggle back lo after a period of time. Is that correct?

No, your UI cannot reliably ensure that the reset to low will be delivered. If you need to ensure it is low except when desired, run a gateway timer event that constantly writes to it based on timestamp (in a memory tag). The ordinary button's actionPerformed event would set that timestamp to now() + desired pulse duration. The timer event would compute now() < {timstamp tag} and write the result if it doesn't match the signal's current value.

This ensures the signal gets reset if your client freezes just when the button is clicked.

1 Like

@pturmel Thanks Phil! That's a clever idea. Thank you for this solution!

Another option is set on the confirmation and have the OPC device reset when it receives the signal. Can't get much simpler than that.

Just wanted to pop in again and say I was able to get the momentary button to work the way I was looking for with the following script.

if system.gui.confirm('Are you sure?', 'Confirm'):
	event.source.parent.Copy_PB = 1
	
	def setLoRecipeCopyPB():
		event.source.parent.Copy_PB = 0
		
	system.util.invokeLater(setLoRecipeCopyPB,1000)

@pturmel I think this was kind of what you were suggesting but, instead, setting it up as a gateway event script that would execute the function when it sees the appropriate boolean go Hi. That way if my client crashes mid button press, it doesn't get latched Hi.

Thanks @jlandwerlen. Was considering that option also if all else failed.