I have a UDT query tag that on a value change I am hoping to write to a UDT OPC tag. However it doesn't seem to be working...
Here is the value changed tag event script I am running below:
path = "[default]Keyence Laser Marker MD-X2000/" + self.session.custom.IP_MachineID + "/" + self.session.custom.IP_MachineID + "_KeyenceLaserMarker/PartNumberOPC"
I had this working before when I was not using a UDT
Thanks for any help!
Have you confirmed your path and current value are correct before attempting to write to the tag? Namely those
MachineID pieces of it. With these smaller scripts I've found it's pretty easy to mess around in the script console to identify where a weird issue might be hiding.
What do you mean it isn't working exactly -- the tag just isn't being written when you expect it to be?
I'm not very experienced with Perspective but i believe the issue lies with the
+ self.session.custom.IP_MachineID part of the tag change script, since it runs at the gateway scope, i don`t think a tag change script has acces to the self.session method, for example, if you had multiple sessions open, how would the tag script know which one to get the IP_MachineID value from?
Under Status->Logs what erros are you getting when the value changes and the script fires?
What @leonardo.godoi said. Tag event do not have any access to variables that are part of a user interface session.
com.inductiveautomation.ignition.common.script.JythonExecException: NameError: global name 'self' is not defined
Looks like it's not happy with me using a variable from the user interface session like @pturmel mentioned.
How then would I be able to reference the machineID I am pulling from a different query based on the IP address of the device?
Do the query in gateway scope (timer script to memory tag, query tag, whatever) so the result is reachable by a tag script. If the UI is providing something global, bidirectionally bind that UI field to a memory tag.
I ended up just using a reference tag that is sourced from the query tag and then an event script on the reference tag that writes to an OPC tag. Thanks for the help!