c607590
(Carl-Heinrich Grabez-Pracht)
December 20, 2024, 6:52am
1
I want to use an Expression resp. an ExpressionType to set the style of an svg image based on an OPC UA variable.
This is basically working if the operation is as simple as a pure string, eg. “green”. But what would the operation have to look like to do the following? The code is not working, but it should show the idea.
<?xml version="1.0" encoding="utf-8"?>
<ExpressionTypeSet id="expressiontype_1" xmlns="http://www.br-automation.com/iat2016/expressionType/v1">
<ExpressionTypes>
<ExpressionType name="checkGreen" datatype="ANY_STRING">
<Operands>
<Operand name="inState" datatype="ANY_INT" />
</Operands>
<Operation>
inState > 0 ? "red" : "green"
</Operation>
</ExpressionType>
</ExpressionTypes>
</ExpressionTypeSet>
Hi Carl,
I don’t know how exactly to do this with expressions.
But I can suggest an alternative solution using ListBindings.
First of all you have to define two SessionVars for different colors “red” and “green”:
<Variable name="MyVarRed" xsi:type="ANY_STRING" value="red" />
<Variable name="MyVarGreen" xsi:type="ANY_STRING" value="green" />
You can bin these vars directly to target via list binding using your instate as selector:
<Binding mode="oneWay"> <!-- -->
<Source xsi:type="listElement">
<Selector xsi:type="session" refId="inState" attribute="value" />
<be:List xmlns:be="http://www.br-automation.com/iat2015/bindingListEmbedded/engineering/v2" xsi:type="be:session" attribute="value">
<bt:Element index="0" refId="MyVarGreen" />
<bt:Default refId="MyVarRed" /> <!-- if <> 0 -->
</be:List>
</Source>
<Target xsi:type="session" refId="YourTargetString" attribute="value" />
</Binding>
I think this way is (a little) easier than working with expressions.
Note: default switch only works for value <> 0 not for values > 0
Is this a solution for you?
Sincerly Simon
c607590
(Carl-Heinrich Grabez-Pracht)
December 20, 2024, 7:40am
3
Hello Simon,
thank you for your quick response. What I didn’t mention is that the inState is bitwise interpreted and needs to be compared to a bitmask, i.e. I need to check if certain bits are set.
Do you have idea how to accomplish that?
Sincerely
Carl
Hmm. In mappView (as far I know) it’s only posible to compare equal = / not equal <>.
Often it’s easier to do such comparisons in the PLC and bind the result (string in your case) via OPC UA to mappView.
Maybe someone else can give some input
c607590
(Carl-Heinrich Grabez-Pracht)
December 20, 2024, 10:22am
5
Thank you again. I will implement it in the PLC.
Have a nice weekend!
1 Like