I am new to ignition and I am trying to make a simple thing to control two widgets with a slider. I have a toggle switch to switch what tag to set
The toggle switch is bound to a tag called
SetTemp
I have the same code running on the switch's onActionPreformed and onClick event. I also have it on the tag's change event but still not running.
The code is
print("Event Fired")
Test.GetTagValue("Temp") # My Code
The console has no output. No error. Nothing.
The tag's value does change with the toggle switch
The toggle switch is set bound to a tag called SetTemp
.
print("Event Fired")
This should be
system.perspective.print("Event Fired")
if you want it to appear in Designer Console.
Test.GetTagValue("Temp") # My Code
That won't work. To write to a tag use
https://docs.inductiveautomation.com/display/DOC81/system.tag.writeBlocking
You're going to have difficulty switching stuff. I'd recommend using a coordinate container, put two sliders on top of each other and toggle their visibility using the toggle switch. Bind one gauge to each slider.
Why won't it. It is a function I defined where I do my logic and write to the tags
I want a challenge to get used to scripting in ignition
Edit: I will probably change the name of the function
That wasn't clear from your post and you didn't supply the code for that function.
I put a comment saying # My Code
Also the print wasn't running. I didn't think that the code for that function mattered.
I am new to these fourms so I don't know what info needs to be provided but the code for the function right now is
def GetTagValue(name=""):
system.perspective.print("Running")
tags = system.tag.browse("/")[1:]
tag = None
for i in tags:
if i["name"] == name:
tag = i
if tag == None:
return None
system.perspective.print(tag)
It doesn't write for right now because I want to see if it can get a tag but it doesn't run. Even with system.perspective.print
there is nothing in the logs
I set the code to write False
to the tag whenever the tag changes and that works. So now it turns into why is system.perspective.print
not working
Edit: Code
system.tag.writeBlocking([tagPath], [False])
system.perspective.print("Event Fired")
Because your script is running on the gateway. Designer Console can't see it. You need to use a logger.
https://docs.inductiveautomation.com/display/DOC81/system.util.getLogger
A quick and easy way to debug is to create a debug string tag and write to that from the script.
That still wasn't showing in the console. I have 0 idea of what I am doing
I did that and that works.
This isn't accurate. The system.perspective.print()
usage should be printing to the Designer Console when used from events. If it is not, then something else is going on. The original print()
command will NOT be printed in the Designer Console, as generic print()
invocations go to the... wrapper.log
(?) file.
The most likely cause is this piece of the snippet:
if tag == None:
return None
system.perspective.print(tag)
In the result the tag
variable is indeed None
, the final system.perspective.print()
invocation will not be reached.
This part of the provided code can be entirely replaced as it is redundant; you've already set tag
to be None
, and only overwritten that value in the event the name is found.
# Change all of this....
if tag == None:
return None
system.perspective.print(tag)
# to this:
system.perspective.print("Tag: {0}".format(str(tag)))
return tag
2 Likes