Multi State Indicator using 3 tags for 7 states

Hello. i am trying to create a Multi States Indicator for alarms States with 3 States out of 7 possibilities using 3 tags as bits.
The 3 tags are: ActiveUnacked, ActiveAcked, Shelved.
The 7 possibilities are Bit 0 Bit1 Bit2
000 Would return 0
001 Would return 3
010 Would return 2
011 Would return 2
100 Would return 1
101 Would return 1
110 Would return 1
111 Would return 1
I’ve try this expression using the switch function but it doesn’t seem to work most of the time it return 4 or 1 never 2 or 3
Expression:
switch({Root Container.Container Alarmes.Multi-State Indicator 6.AlarmState},
(!{CLX_PLASTIQUE/Alarmes/ActiveUnacknoledged} && !{CLX_PLASTIQUE/Alarmes/ActiveAcknoledged} && !{CLX_PLASTIQUE/Alarmes/Shelved}), // 000
(!{CLX_PLASTIQUE/Alarmes/ActiveUnacknoledged} && !{CLX_PLASTIQUE/Alarmes/ActiveAcknoledged} && {CLX_PLASTIQUE/Alarmes/Shelved}), // 001
(!{CLX_PLASTIQUE/Alarmes/ActiveUnacknoledged} && {CLX_PLASTIQUE/Alarmes/ActiveAcknoledged} && !{CLX_PLASTIQUE/Alarmes/Shelved}), // 010
(!{CLX_PLASTIQUE/Alarmes/ActiveUnacknoledged} && {CLX_PLASTIQUE/Alarmes/ActiveAcknoledged} && {CLX_PLASTIQUE/Alarmes/Shelved}), // 011
({CLX_PLASTIQUE/Alarmes/ActiveUnacknoledged} && !{CLX_PLASTIQUE/Alarmes/ActiveAcknoledged} && !{CLX_PLASTIQUE/Alarmes/Shelved}), // 100
({CLX_PLASTIQUE/Alarmes/ActiveUnacknoledged} && !{CLX_PLASTIQUE/Alarmes/ActiveAcknoledged} && {CLX_PLASTIQUE/Alarmes/Shelved}), // 101
({CLX_PLASTIQUE/Alarmes/ActiveUnacknoledged} && !{CLX_PLASTIQUE/Alarmes/ActiveAcknoledged} && !{CLX_PLASTIQUE/Alarmes/Shelved}), // 110
({CLX_PLASTIQUE/Alarmes/ActiveUnacknoledged} && !{CLX_PLASTIQUE/Alarmes/ActiveAcknoledged} && {CLX_PLASTIQUE/Alarmes/Shelved}), // 111
0, // 000
3, // 001
2, // 010
2, // 011
1, // 100
1, // 101
1, // 110
1, // 111
0)
Whats wrong?

Is this where you are trying to write to or? By what I understand of the switch function, this would be your input value. Is then your checking it against your lines below it for which one matches. The one that matches will return your numbers from the bottom.

Now if for your top value you use:

binEnum({CLX_PLASTIQUE/Alarmes/ActiveUnacknoledged},{CLX_PLASTIQUE/Alarmes/ActiveAcknoledged},{CLX_PLASTIQUE/Alarmes/Shelved})

This would return an int equal to what the binary represents from the 3 values. Then where you have these tags shown, you list of which binary numbers you are looking for. Then below that list what you want to return if it meets one of those.

It would be something like:

switch(binEnum({CLX_PLASTIQUE/Alarmes/ActiveUnacknoledged},{CLX_PLASTIQUE/Alarmes/ActiveAcknoledged},{CLX_PLASTIQUE/Alarmes/Shelved}),
0, // 000
1, // 001
2, // 010
3, // 011
4, // 100
5, // 101
6, // 110
7, // 111
0, // 000
3, // 001
2, // 010
2, // 011
1, // 100
1, // 101
1, // 110
1, // 111
0)

Yes This is the tag where i want to write the value But i guess the switch function is not the right function to do it… What would be the best way to do that?

From an expression you are only going to write it back into the tag you are running the expression in. Expressions aren’t meant to write to other tags or locations. They just return their results to where ever you have them set up. I’m assuming AlarmState is a custom property on the Multi-State indicator. If so you should be able to use an expression binding on that property to run the switch() function that I showed above. If you don’t want to do that, then you would need to use a python script to take it from the location your running it and write to to where you need it but I would assume you should just be able to use that binding.

Thanks for the answer. I think i found an easy way to do it.

binEnum({CLX_PLASTIQUE/Alarmes/ActiveUnacknoledged},{CLX_PLASTIQUE/Alarmes/ActiveAcknoledged},{CLX_PLASTIQUE/Alarmes/Shelved})

Placed in correct order, the bits priority works just fine) Bit0>Bit1>Bit2
so an Unacknoledge Alarm will return 1 an Acknoledge Alarm will return 2 and a Shelved Alarm will return 2 which is exactly what i need.

1 Like