learning more about expressions; can someone explain why this doesn't work? i have used the same variable construction elsewhere in a script and it chooched just fine. it just isn't as an expression.
if ("{Assets/"+{session.custom.assetName}+"/ONLINE}", \
"Assets/"+{session.custom.assetName}+"/Voltage".value/100, \
0)
i just get an Error_Configuration error. which does not surprise me, i am a n00b.
EDIT: just tweaked to more accurately reflect what i'm trying to do so i get a better response.
You can't reference tags or properties like this. If you need to build their path dynamically, you'll need to use the tag and property functions. Or work around it using temporary properties and such.
expressions evaluate faster than scripts, not necessarily bindings. Tag bindings are also pre-compiled, so are just as fast if not faster than expressions.
If you want to work directly with tags in expressions, you can use the tag() expression. This allows you to provide a string as the path, and returns the value.
For best performance you should prefer indirect bindings over a tag() expression.
i'm not married to the expression idea, i was under the impression they were just faster. but since a tag-tranform-script is precompiled and just as fast: pfft. whatever i can get to work in a streamlined way gets the win. i just don't know how to access a tag's property directly from within a script. which i why i went with indirect expression. so... yeah. this is where i'm at right now.
# indirect binding to Assets/{assetName}/ONLINE, a boolean flag
if value:
newValue = Assets/{assetName}/superImportantValue + 20
return newValue
else:
return 0
Note, that if this is going to be a popup, embedded view, or docked view where you want to send the asset name, you should make that a view parameter. The rest would still be applicable you would just need to change the paths to assetName.
Bindings, throughout Ignition user interfaces, deliver values to session/view/window/page properties, custom or otherwise. All bindings are "set up" when a Perspective view or subview or Vision window or template is opened. The setup yields a java collection of objects tightly integrated with each other and with the target component. With the exception of any jython involved, everything is effectively pre-compiled during setup. Information flows from element to element in handsfuls of microseconds or less.
While some bindings are "once and done", like expression bindings that yield constants, or non-polling queries, most bindings are intended to monitor some source of data and deliver updates through the binding. When a source reports a change, the binding completely re-executes.
Transforms are a Perspective-only enhancement to bindings that create a chain of consecutive operations, with one result feeding the next, with the final operation's result providing the value for the target property. {Perspective desperately needed transforms because its complex components' architectures have a severe "impedance mismatch" with Ignition's internal object types, particularly dataset objects.} Transforms, for some unclear reason, introduce substantial overhead, on the order of high tens to low hundreds of microseconds.
Jython, meanwhile, whether invoked in a binding by runScript() or by a script transform, adds considerable additional overhead. Again, tens to hundreds of microseconds per invocation, plus the performance penalty of an interpreted language.
For some timing comparisons between script transforms and pure expressions for some common Perspective UI tasks, look at my Integration Toolkit module's topic for some of the testing shown there:
For some benchmarks on transform overhead versus runScript versus no script at all, check out this topic:
When you split a binding into separate custom properties, you are essentially constructing a sub-expression that only has to re-evaluate when one of its dependencies changes. If used in an outer expression, and its dependencies haven't changed, then its usage is nearly free--just the lookup of its latest value.
Tag indirect bindings have some asynchronous delivery advantages over the use of tag() functions, on top of eliminating the unnecessary re-evaluation of the tag path expression.