I am having an issue where system.perspective.sendMessage seems to stop execution of a change script.
def valueChanged(self, previousValue, currentValue, origin, missedEvents):
from time import sleep
def confirm_reset():
sleep(5)
if self.custom.timingActive or self.custom.interruptFlag:
self.custom.timingActive = False
system.perspective.sendMessage('changeMessage', payload={'text': 'script', 'instanceId': self.view.custom.instanceId}, scope='page')
self.custom.interruptFlag = True
if currentValue.value:
system.util.invokeAsynchronous(confirm_reset, [], "Confirm Delay")
I have split the 2 properties interruptFlag and timingActive to help me see what was going on. As posted, interruptFlag does not get set. As soon as I comment out the system.perspective.sendMessage, interruptFlag will be set as expected. I have been over and over this code to see what I may have fat fingered and can't find anything.
Any help would be greatly appreaciated.
Unless your version of Ignition is really recent, system.util.invokeAsynchronous()
does not inherit the Perspective environment needed by system.perspective.sendMessage()
. So that call will fail.
I don't recall what version has that enhancement, and it is not showing in the v8.1 changelogs. I recall @PGriffith making a comment that it was added.
You have self
in your closure, so you should be able to extract explicit session and page information from that to use in system.perspective.sendMessage()
.
I tried sending the sessionID to it but it still didn't work. As a workaround, I've moved the sendMessage outside of the called function and leveraged the second call of the change script (false transition) to send the message.
When using page scope for your message, you must supply both session and page IDs.
2 Likes
I thought I had made that change too, but git blame suggests not. I think I intended to, but wasn't able to with the fragile ScriptContext
API in 8.1 (the change has been made to inherit ScriptContext
in 8.3).
However, Perspective's session info is in a dedicated ThreadLocal
and therefore not part of ScriptContext
anyways, so it's a moot point.
2 Likes