Sign in to follow this  
Followers 0
evanmars

How To Clear Boolean Array?

9 posts in this topic

I have an array of BOOL (My_Bool_Array[32]). How to I set all elements to 0? RSLogix 5000 Compact Logix Edited by evanmars

Share this post


Link to post
Share on other sites
One at a time unfortunately

Share this post


Link to post
Share on other sites
Thanks, that's what I figured. So I just did this: LES Clr_Index 32 BST OTU My_Bool_Array[Clr_Index] NXB XIO My_Bool_Array[Clr_Index] ADD Clr_Index 1 Clr_Index BND Edited by evanmars

Share this post


Link to post
Share on other sites
That didn't work because RSLogix5000 evidently doesn't use short-circuiting. Although I only wanted to execute the rung when Clr_Index < 32, it still tried to read into My_Bool_Array when Clr_Index = 32, so threw the PLC into a major fault. So I did this instead: BST OTU My_Bool_Array[Clr_Index] NXB XIO My_Bool_Array[Clr_Index] LEQ Clr_Index 30 ADD Clr_Index 1 Clr_Index BND

Share this post


Link to post
Share on other sites
Would it not be possible to convert the 32 bit bool array into a single DINT and change the address of the bits to DINT.X ? Then you could just write a zero to the DINT and be done.

Share this post


Link to post
Share on other sites
Thanks. Yeah I figured that out a bit ago and that is what I ultimately went with.

Share this post


Link to post
Share on other sites
The only way I know of doing this is to make your BOOL Array a member of a tag of a User-Defined Data-Type, then you can use COP CPS and FLL Before toggling Clear_BOOLs After toggling Clear_BOOLs Note that a Length of 1 for the FLL instruction clears all 1024 BOOLS in the array Edited by daba

Share this post


Link to post
Share on other sites
If it makes you feel better, a bool and a DINT both use 32 bits of memory. So you are being more efficient !

Share this post


Link to post
Share on other sites

You can masquerade the BOOL array data type as a DINT array data type while passing it to a subroutine as a parameter. Pass the BOOL array through a JSR as a parameter. Inside the subroutine, receive the parameter as a DINT array. In your case, a single DINT. Inside the subroutine, FLL the DINT array with zeros. In your case, MOV a zero into the DINT. When the JSR returns, the BOOL array will be zeros.

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
Sign in to follow this  
Followers 0