Group OPC Tag in the same condition

Hello

I have the following situation,

I have 4 boolean OPC tags that are activated when the PLC goes into error and when it is restored it turns off.

for this I am grouping it with a case

In the case that they are not activated the status would be = 1 but if some or all are activated the status would be = 3

but it is not respecting the second condition even if it is met

case(true,{[.]On_Off_FBW}&&(!{[.]Falla safety fance open 1}||!{[.]AreaSafety Fence Open2}||!{[.]Emergency Stop}||!{[.]PLC Errror}),1,
({[.]Falla safety fance open 1}||{[.]AreaSafety Fence Open2}||{[.]Emergency Stop}||{[.]PLC Errror})&&{[.]On_Off_FBW},3,10)

In some cases, two or one can be turned on, or all the tags can be turned on.

I don’t believe you are using a case correctly. The spot that you have ‘true’ would need to be a value of some sort that you are matching to. That could be a string. Then the spot where your trying to test your bool’s would be a corresponding value that your looking for to match where you have ‘true’. the 1 or 3 is what would then be returned.

In this example it would return ‘five’:

case(5
	,1,'one'
	,2,'two'
	,3,'three'
	,4,'four'
	,5,'five'
	,'error')

This one would return ‘error’:

case(6
	,1,'one'
	,2,'two'
	,3,'three'
	,4,'four'
	,5,'five'
	,'error')

I’m returning a string but you can also return an integer or other value.

I’d look into using binEnc(). Your bools that you want to test you can put into there. That will return a value based on which bools are true. Then you can use that where you have ‘true’ in your case and have it return the 1 or 3 your looking for based on the value returned from the binEnc().

1 Like

Putting everything on a single line is also asking for trouble, as it becomes incredibly difficult to read and work out exactly what the conditions are. Code for your future self who has forgotten what the project does

If(
    {[.]On_Off_FBW} && 
    (
     !{[.]Falla safety fance open 1} || 
     !{[.]AreaSafety Fence Open2} || 
     !{[.]Emergency Stop} ||
     !{[.]PLC Errror}
    ), 
    1,
If(
    (
     {[.]Falla safety fance open 1} ||
     {[.]AreaSafety Fence Open2} ||
     {[.]Emergency Stop} ||
     {[.]PLC Errror}
    ) &&
    {[.]On_Off_FBW}, 
    3,
// else
    10
)) 
1 Like

Thank you very much for the advice, only that testing the code does not change when the condition is met, it remains at 1 only.

it only changes from condition 1 to condition 10 but condition 3 does not take it when it meets it

case(
	true,{[.]On_Off_FBW}&&
	(
	 !{[.]Falla safety fance open 1}||
	 !{[.]AreaSafety Fence Open2}||
	 !{[.]PLC Errror}||
	 !{[.]Emergency Stop}||
	 !{[.]Boton_paro_Rim}
	),
	1,
(
	 {[.]Falla safety fance open 1}||
	 {[.]AreaSafety Fence Open2}||
	 {[.]PLC Errror}||
	 {[.]Emergency Stop}||
	 {[.]Boton_paro_Rim}
	)&&
	{[.]On_Off_FBW},
	3,
//else
	10
)

If(
	{[.]On_Off_FBW}&&
	(
	 !{[.]Falla safety fance open 1}||
	 !{[.]AreaSafety Fence Open2}||
	 !{[.]PLC Errror}||
	 !{[.]Emergency Stop}||
	 !{[.]Boton_paro_Rim}
	),
	1,
If(
	(
	 {[.]Falla safety fance open 1}||
	 {[.]AreaSafety Fence Open2}||
	 {[.]PLC Errror}||
	 {[.]Emergency Stop}||
	 {[.]Boton_paro_Rim}
	)&&
	{[.]On_Off_FBW},
	3,
//else
	10
))

Looking at it again, the logic is flawed and could be simplified. I assume the condition with the fault tags being True has higher precedence than when they’re off? Currently if any of them are off, that condition will win. I think it should be the other way around. You should also try to group conditions together if they have a common element such as the running tag condition. Try this instead:

If({[.]On_Off_FBW}, 
    If(
         {[.]Falla safety fance open 1} || 
         {[.]AreaSafety Fence Open2} || 
         {[.]Emergency Stop} ||
         {[.]PLC Errror}
       , 3
       , 1
    )
   // else
   , 10
)