Help with Expression

I need help understanding what this expression is doing. specifically the (&8192) portion. This is in a visibility animation on a label in RSView SE. I'm trying to rebuild this into a visible property on a label in Ignition but its not working and i don't understand what its trying to do.

I understand it up until ({#4\ConfigWord} & 8192) but I don't use bitwise operators enough to understand what its doing.

Can anyone help me understand this?

ParmType is a Integer (0-INT, 1-BOOL, 2-REAL, 3-STRING, 4-LIST)
ConfigWord is a Integer

ParmTyp is currently 2 and ConfigWord is 21634 and the label is NOT Visible

if ({#4\ParmType}==2)  AND ({#4\ConfigWord} & 8192) then
1
else
0

It's checking if the 13th bit of ConfigWord is set.

8192 == 0x2000 == 0b0010_0000_0000_0000

Thanks. This is the expression i built in Ignition to replace it. Could you help me troubleshoot it?

Error:
ExpressionException: Unsupported types for BAnd: 'null' and 'java.lang.Long'

if(({Root Container.Parm0.ParmType}=2 && {Root Container.Parm0.ConfigWord} & 8192),1,0)

Doesn't look like anything is wrong with your expression, just that {Root Container.Parm0.ConfigWord} is either not resolving or is resolving to a null value. Make sure you've got a value set for that parameter and that there's no typos.

You really don't need an if expression IMO. Either did the one in FactoryTrash SE.

2 Likes

I have ConfigWord set as a custom property, the type as integer and its value is loading, screenshot is below.

configword

Ok, how should it be done?

({#4\ParmType}==2)  AND ({#4\ConfigWord} & 8192)
({Root Container.Parm0.ParmType}=2) && ({Root Container.Parm0.ConfigWord} & 8192)

These will evaluate true or false

1 Like

Thanks for your help.

1 Like

It might be worth breaking that out into its own boolean tag where you add .13 to the OPC Item path.

1 Like

Every time you see an expression using a pattern like if boolean = true, true, false, there are 2 things you can simplify.

  • First, comparing a boolean to true is not needed. All it does is make the same boolean out of a boolean.
    You're not doing it there, but I see it often enough, and it's related (basically the same thing actually) to the next point,
  • you don't need to return true or false after evaluating a boolean. The boolean is itself true or false, you can just return it directly. No need to involve another layer there.

Another thing I would suggest, is using hexadecimal format in bitwise operations. It's easier to read - IMO.
I have no idea what 8192 is. But 0x2000 is super easy to decompose:
each character corresponds to 4 bits, so you can already see the 12 first (rightmost) bits are 0.
You only need to deal with the 2, which is 0010.
Easy to see what bit is on in 0x2000.

4 Likes