Check if any BOOL in a 3D array of BOOLs is true in ladder logic

Hi,
Let’s say I had a variable called “alarms”, with the data-type BOOL[5,5]. Is there a function block that can check every BOOL in that 3D array and return a TRUE if any of them are TRUE?

I specifically want to do this in ladder logic. I understand that this can easily be done with a custom function block in libraries, but I’m curious if this can already be done with the function blocks AS comes with.

Thanks!

Hello @c589717 JackLin,

Welcome to the B&R Community!

If you don’t need to know which alarm is true, you can use a simple brsmemcmp function to compare against 0 to determine if any values are true. brsmemcmp will indicate if there is a difference between IN1 and IN2. By comparing against a constant of false of the same size (125 x FALSE), the brsmemcmp will indicate if there are any true values, the only other value possible for BOOL. The DINT_TO_BOOL is there to provide a usable BOOL value with the answer.

An example ladder rung is below. NO_ALARMS is a constant of the same type as AlarmArray, 125(FALSE).


AS Help Links:
brsmemcmp - B&R Online Help (br-automation.com)
DINT_TO_BOOL - B&R Online Help (br-automation.com)

2 Likes

Dear JackLin,

directly a function block, is from my understanding not needed.
I understood that you want to check if any variable of the array has the value “TRUE”.

A fast, but maybe not the prettiest, solution would be the usage of the OR-Link.
Simply make each variable a contact and set them in parallel.

Simple logic structures - B&R online help

that’s right. But in case of 1000 alarms he would need 1000 ORs.
So Austin’s solution looks very nice to me !

1 Like

Definitly, i’d say aswell that the provided solution from @austin.carpenter is the proper one.
(Especially with bigger arrays)

I would go even a step further and would capsulate the solution into a own made function block. Then i can re-use the solution multiple times.

2 Likes

Oh wow, that’s interesting. This isn’t a very aesthetic solution, but alas I gotta avoid structure text wherever possible for this project this might be the best I got. Thank you Austin

1 Like

And here the last but not least variant, which gives you also the Index of the First found Alarm. Creating a loop in LD and go over the Array. Create an Exit if one TRUE was found.


image

I did it only for a one Dimension, but you can extend it with an second Loop.

It spares the additional Compare Memory in comparison to the first proposed solution. But it is less readable.

Greetings
Michael

1 Like

Oh nice, you’re looping ladder logic like structure text lol. Unfortunately my goal here is to base this logic off of an AB template, so readability from a ladder-logic point of view is my top priority. The first solution wasn’t pretty but it did it in one line, so I find that preferable. I didn’t know about the “jump” and “return” functions though, I’ll keep that in mind

Honestly I would prefer something like this:

image

and program the whole thing in ST:

MyBoolLib.zip (1.8 KB)