I’m trying to get to grips with ignition and I’m using maker edition in docker.
I’m trying to get a gateway tag changed script to run and write to the diagnostic log. In Gateway scripts it says my scripts are running. However I cannot get the script to log anywhere. Just wondering if I’m bumping up against a limitation of maker edition.
def valueChanged(tag, tagPath, previousValue, currentValue, initialChange, missedEvents):
logger = system.util.getLogger("TagChangeScript")
logger.info("Tag changed")
system.util.sendMessage("DEBUG", "Script executing - any change detected")
print("TAG CHANGED")
Any help would be appreciated.
Thanks
Steve
You said 'gateway tag changed script' but you've copied and pasted a handleMessage
snippet, indicating a message handler. Which are you actually using? handleMessage
will only be called in response to...an outgoing script message, such as from system.util.sendMessage
.
I've changed it to valueChanged, is that correct? The method signature was the same, is the method name important? It's still not working.
Thanks
Steve
Gateway tag change events do not use function format. Details are passed as local variables in the outer scope. Take a closer look at the documentation. (And no, the local variables are not an exact match for an event on the tag itself.)
Rephrased :
Whatever code you write in the text editor for a gateway tag change script will be directly executed.
If all you're doing is defining a function, the scripting engine will happily do that, and then nothing will happen, because all you've done is define a function, not actually called it.
Theoretically, you could (but there is literally no reason to) do something like this:
def myCoolFunction():
# do something
myCoolFunction()
Besides being totally pointless, for complicated, legacy reasons this likely won't work, or at least won't work the way you'd want it to.
If you strongly want the encapsulation of a function (generally a good idea; not needed just for the sake of testing here in my opinion) then you should write that function in your project library and call into it from the tag change script.
In summary:
All that you should have in your tag change script body is the code you want to execute.
Don't:
def valueChanged(tag, tagPath, previousValue, currentValue, initialChange, missedEvents):
logger = system.util.getLogger("TagChangeScript")
logger.info("Tag changed")
system.util.sendMessage("DEBUG", "Script executing - any change detected")
print("TAG CHANGED")
Do:
logger = system.util.getLogger("TagChangeScript")
logger.info("Tag changed")
system.util.sendMessage("DEBUG", "Script executing - any change detected")
print("TAG CHANGED")
1 Like
Thankyou it's now working, the documentation makes more sense to me now.
I guess what was throwing me was there are normally errors in the logs when scripts fail but as you say the script executed correctly. RTM!
logger = system.util.getLogger("SecurityDevicesMonitor")
logger.info("Tag changed")
logger.info("Tag Path: {}".format(event.getTagPath(), newValue.getValue()))
logger.info("Prev: {} New: {}".format(previousValue.getValue(), newValue.getValue()))
1 Like