So, in short I am new to ignition and python(what a baptism of fire). I am doing a replica scada screen of my workplace to familiarize myself with the system before even going near the already working one.
On previous scada systems I have used the same code to read the value and depending on conditions, set a Boolean value. the exact situation is a tank. If the level of the tank should go above 90%, a Boolean tag should be made true. I had specific tags made for this but since starting this nothing seems to work. Am i even putting the script in the right place? the code seems ok and have verified with Pycharm but nothing comes of it. I have tried the code in the event gateway under the timer section and it was enabled. since then i have retreated back to writeable tags.
Any help would be greatly appreciated and any recommendations on someone who does videos for this would be incredible.
Thank you and apologies
Hi,
Why you are not using currentValue
in the condition?
and tagPath and value should be of list type.
I had used currentvalue previous to this and it did not. Should this code not work by itself? It applies with no errors and nothing happens when the integer value goes above the 90 setpoint. The tagpath is just one tag. So there wont be a list? Again very new to this
Make lists of length == one for your tag path and corresponding value.
system.tag.writeBlocking - Ignition User Manual 8.1 - Ignition Documentation.
Check the example also
I removed the first line and changed line 3 to match Learner_Ignition suggestion. It worked and I am not sure why the first line would have caused an issue. Thanks for you for the help. Sometimes browsing the manuals and the DOC81 just confuses me more
Did you change tagPath and value to be of list??
No. Should I? I dont quite understand why? Can you show me the code or explain the benefit?
system.tag.readBlocking
unconditionally returns a list. So even if you only read one tag, you still have to unpack the values by retrieving the QualifiedValue
at the 0th index, then retrieve the .value
attribute of the QualifiedValue
:
value = system.tag.readBlocking("someTagPath")[0].value
But as pointed out, using currentValue.value
is significantly more performant and a bit nicer to read.
As an additional point of confusion (sorry) for everyone:
system.tag.writeBlocking
and system.tag.readBlocking
can accept single input parameters, but are intended to be used with lists (and you should probably get in the habit of using lists). (The rationale was that it was going to be easier to gloss over this point in training classes, rather than getting hung up on the list inputs. In practice it may not have been worth the headaches )
So, functionally, these two are equivalent:
system.tag.readBlocking("someTagPath")
system.tag.readBlocking(["someTagPath"])
As well as these two:
system.tag.writeBlocking("someTagPath", someValue)
system.tag.writeBlocking(["someTagPath"], [someValue])
They are not the same semantically, and there is absolutely a difference in terms of Jython. But the system functions are just "smart" enough to automatically wrap a single input into a list "under the hood" - that's why you can get away with your writeBlocking usages.
As a further aside, you can simplify your script a fair amount by reducing the comparison to a single boolean expression.
That is:
if condition:
doSomething(True)
else:
doSomething(False)
Could be just as well written as:
doSomething(condition)
As in:
system.tag.writeBlocking(["[default]_Sample_Device_/Writeable/WriteableBoolean2"], [currentValue.value >= 90])
Is exactly equivalent to your current code, but has the benefit of making it immediately obvious that no matter which branch is hit, you're always writing to the same output tag.
Also...
I believe you don't need a script at all.
If you make your writeableboolean2
tag an expression tag instead, you can bind its value to an expression using writeableinteger1
.
A very simple expression is enough:
[.]writeableinteger1 >= 90
Note the dot in the brackets: it means it uses a relative path. That's very neat if you need to repeat the same thing, like in a UDT.
edit: example:
Definitely true in the general case, but these are OPC tags from the simulator device, so it's not quite so straightforward.
Thank you! I think i need to start an actual training course on this. As I will be eventually taking values from a Siemens s7-1200 plc