Ok … I know what I am attempting to do is very, very stupid, and should not be done in 99.999% of applications. But I am working in the realm of the remaining 0.001%
What I am attempting to do is to create a momentary push button in Perspective. I tried this by writing True/False values on various mouse events.
- On Mouse Down => Write True
- On Mouse Up => Write False
But I know that events can get lost somewhere, so I added
- On Mouse Leave => Write False
- On Mouse Out => Write False
I also have the cursor change shape when it is over the button.
When connected to a real PLC, what I am finding is that if I click and release slowly, the button behaves as expected. And if I click and release fast then the False value never gets written, and the tag in the PLC latches up with True.
OK, I was expecting to have issues with losing events, which was why I was guarding things with the Mouse Leave/Out events. But while I can see the mouse cursor changing when I leave the button, and it is looking like those events are firing (as seen in wrapper log print statements), the write of the False value isn’t even being written to the tag itself in Ignition.
(and my testing involves a fast press/release, then hovering over the button for a significant amount of time, then moving the mouse away from the button)
So what am I missing in my stupidity and/or how can I improve the reliability of system?
Note that I am writing to a custom parameter on the view (which the button is defined in) and I am two-way binding from an embedded instance of that view to the OPC UA tag that has read/write defined on it.
Event => custom view parameter => OPC UA tag => PLC
And the False value is not even getting to the OPC UA tag
I would recommend reading through Momentary Pushbutton Latching On and Very Concerning Read Write Issues. Both of these threads should provide some decent insight to Momentary buttons and possible pitfalls of using them. This comment from the first link might point you in the right direction for what to do on the PLC side to prevent latching.
I haven’t read through all of that, but I believe I am seeing a pattern that is indicating part of where the issue might be.
If the tag is false I press the button, Ignition issues an OPC UA write to the tag. But when I release, if Ignition hasn’t yet gotten the confirmation back, it still thinks the tag is false and perhaps suppresses the write of the false.
But if I click, wait for the confirmation back and then release, it all works fine.
However, this doesn’t explain why when I click/release, hover and then move away from the button and expect the Move/Out event to clean up the status, that the false isn’t being written even though the event is logged.
I did discover if I click and hold, wait for the status back from the PLC and then slide the mouse off the button while still clicked the tag gets written with false.
Are you testing this in designer? In my testing the mouse motion events did not fire in designer but worked as expected when in perspective. I would strongly consider taking @ryan.white advice though.
I’m launching a Perspective session, clicking about in there and monitoring the PLC separately. But as per my logging with print statements to the wrapper log, the events are firing. It’s the writes that seem to be missing in action.
And I am well aware of the pitfalls of momentary buttons. That’s why I have that disclaimer at the top of my original post
Is this for something like a jog button? While generally not a good idea, but if we’re throwing caution to the wind, you could include a small sleep in your mouse up event before the write operation =x
Basically it is a jog button. But I am not sure a simple delay would actually work. But it’s an idea … lol
In my rudimentary tests it worked, but i guess it depends on how responsive the device is and how long the sleep is. I seem to remember sleep not being as bad in perspective, i could be totally wrong though.
Chalk another one up to user error.
I designed by button in separate view so that I could have a master copy in a library and just instantiate via embedded views wherever I needed it. And there was a parameter on the view that I could bind to a PLC tag for writing the command.
When binding to the PLC tag I ensured that the binding was bi-directional, but I overlooked that that the view parameter also needed to be bidirectional. Once I made that change the Mouse Leave event seemed to write the correct value.