I am using motor symbol from components and would like to show the animation. I am changing the state of the motor with the help of text field in the value. Now I want to change the text field from my tags. I have 3 (BOOL) tags and want to configure them to write it to the text field. The 3 Bools are as follows
Run/tag - should write running in the text field
Fault tag - should write faulted in the text field
Then you can use this anywhere you need to show its status rather than having to write this 17 million times (probably an exaggeration). Expression tags only ever update when it’s conditions change
I like to indent for readability, though it doesn’t make much difference here.
I had to recreate some rather nonsensical color animations, and ended up with this nested if:
if({Cam_Angle1.Stat},
if({Cam_Angle1.VCR_Stat},
1, //flashing red
if({Cam_Angle1.Alarm},
2, //Red
if({Cam_Angle1.Manual_Stat},
3, //Yellow
4 //Tan
)
)
),
0 //No Color
)
if i were to remove the indentation it is not easy to tell what’s going on:
if({Cam_Angle1.Stat},
if({Cam_Angle1.VCR_Stat},1, //flashing red
if({Cam_Angle1.Alarm},2, //Red
if({Cam_Angle1.Manual_Stat},3,
4))),0)
On the contrary, I find it more readable if all conditions and results are aligned
However I would indent separate “case statement” if statements, e.g.
if({Cam_Angle1.Stat},
if({Cam_Angle1.VCR_Stat},1, //flashing red
if({Cam_Angle1.Alarm},2, //Red
if({Cam_Angle1.Manual_Stat},3,
4))),
0
)
I prefer the case statement to nested ifs, I don’t have to figure out how many close parenthesis are required and can add another case with copy/paste:
+1 for clean code
-But how will this be executed compared to having the actual condition tag as the first parameter?
-Will this be executed “constantly”, and put unnecessary load the client?
Recall the original question… 3 tags are used to define the 3 states. In a UDT or with expression binding on a window/view the case statement should execute exactly the same number of times as the nested if statement. In Perspective an expression structure with map transform would work as well and would only execute once per tag change per session with the view open.
Expressions will be executed only when any of the inputs change.
The expression is calculated on the gateway, not on the client. Obviously there will be some extra traffic to refresh the data binding on the client component but it shouldn't hurt.
Tip: for bulleted lists the markdown requires a space after the hyphen. - list item.