I need to create an expression tag that writes to an OPC location, which is a bit on a PLC connected via OPC UA. I’ve been reading OPC tags (Allen Bradley PLCs) and even writing to them, but not running an expression and writing to it both.
In the expression tag (Boolean), I’m watching a pressure differential and if it crosses a threshold, it returns a TRUE. If not, it returns a FALSE. Simple. Now I want to write that true or false to a bit on a PLC so it turns on a stack light?
In 7.9 there was an option on expression tags to write the value back to an OPC item. If this functionality was removed how is it handled during conversion?
When I trigger the expression tag ([default]Rkn031_900/Atomizer/Atomizer_Open_Check),
the tag it’s supposed to write to (…Atomizer_Open) doesn’t change.
Also, diffSetpoint is not defined, so you’ll need to either assign a value, or hard code a value
diffSetpoint = 100
if newValue.getValue() > diffSetpoint:
or
if newValue.getValue() > 100:
Edit: just thinking through this a bit. If the tag that is triggering this event is an expression tag which results in a bool value then your script can be simplified
if you only want to write to the tag on a true value:
if newValue.getValue():
system.tag.writeBlocking(['[default]_Rkn031_900_/Atomizer/Atomizer_Open'],[newValue.getValue()])
if you want it to write for both then omit the if statement
Thank you everyone. New skill learned that can be applied elsewhere.
Here’s the final (before I saw lrose’s simplified version):
if newValue.getValue() > 0:
system.tag.writeBlocking(["[default]Rkn031_900/Atomizer/Atomizer_Open"],[1])
else:
system.tag.writeBlocking(["[default]Rkn031_900/Atomizer/Atomizer_Open"],[0])
This works, but I will simplify it.
" A designer knows he has achieved perfection not when there is nothing left to add, but when there is nothing left to take away." ~ Antoine de Saint-Exupery.
Just to note, you can also have on change scripts directly on individual tags if it’s more appropriate there. For example for tags within a udt that require it, it’s far easier to use a tag’s on change event than have to add each instance tag into the gateway tag change event
Yes, although I don’t know what kind of performance impact this might have if doing this quickly and with many tags. Keep in mind that you can use relative tag path references within tag change scripts. e.g. use [.]../../Tag to refer to a tag 2 folder parent folders down