Interfacing Union to NA alarm expression.

6 posts in this topic

I have a union that I am using for my faults, but when I attempt to set the NA alarm expression to the union BOOL I get a compile error.  The union is an array of 64 BOOL and a long word.

I assume the NA can't process the array portion?  IE: FLT.Bit[0]  

Is there any work around to this?  I hate going back to using standard tags, because then there isn't an easy way for me to identify if an alarm is active (so I have to use a bunch of contacts in parallel)- that or just write a value to an INT and lose the ability to show multiple alarms. 

Share this post

Link to post
Share on other sites

Posted (edited)


I dont know if this answers your question... but maybe you can manage by having an array of bool, where each element is an alarm, and just use a for loop to check if any of the bits in the array is true. A bad thing about this would be that the code is not self explained since you have to know what array index corresponds to different alarms.

Another approach could be to create your own struct with boolean members (one for each alarm). And then make a check if any of the bits in the struct is true. I attached a picture showing how that could be made.


Edited by Solheim95
1 person likes this

Share this post

Link to post
Share on other sites

Solheim95,  I played around a bit with your second example and made a function block that handles all of it, and then nested that function block inside of another one that handles a lot of machine status and common logic.  It works perfectly!

Thank you!


Share this post

Link to post
Share on other sites

I had no problem creating the Union in the controller and then creating the same union in the HMI.

Created Union in the controller:


Created global variable in controller:


Created Union in the HMI:


Created variable in HMI:


Mapped the variables together in in the variable map (in HMI):


Used the bit level function on a screen (note that it uses parentheses, not brackets):

Used the LWORD (ULONG) variable for a display:


It builds without any errors.

Share this post

Link to post
Share on other sites

I didn't realize to specify arrays on the NA you had to parentheses instead of brackets... that is most likely the cause of my problems.  When I tried to specify ".BitLeve[0]" in the user alarm setup, that is what was causing the compile error.

Well, using  Solheim9's solution I've already finished programming the alarm section, and I don't want to spend the time going back and changing all of my outputs now.  At least I know for the future.

Share this post

Link to post
Share on other sites

All Array index accessor in the NA usese parentheses since it's based on Visual Basic script.
I really hope they used C# for a better script consistency with PLCs ST Language, but I guess VB is easier for most users :(

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now