CLX Boolean Array Size

PLCNoob

Member
Join Date
May 2008
Location
Cedar Rapids, IA
Posts
8
I am using a bit of indirect addressing and I have always made it a point to check the array size and compare it to the "index" before I execute an instruction with the index tag inside the array. I'm pretty sure it still faults the processor if you try to indirectly reference an array element that doesn't exist. If not a major fault, it will definitely fill up your minor fault log, possibly making other things harder to troubleshoot.

Anyway, the "SIZE" instruction doesn't work on boolean arrays. How can I find out the array size of my boolean array through code? Granted I could hard code it, but then it is up to the diligence of future engineers to realize this indirect addressing is taking place and update this code if the array size is ever changed.

Any suggestions?
 
I am using a bit of indirect addressing and I have always made it a point to check the array size and compare it to the "index" before I execute an instruction with the index tag inside the array. I'm pretty sure it still faults the processor if you try to indirectly reference an array element that doesn't exist. If not a major fault, it will definitely fill up your minor fault log, possibly making other things harder to troubleshoot.

Anyway, the "SIZE" instruction doesn't work on boolean arrays. How can I find out the array size of my boolean array through code? Granted I could hard code it, but then it is up to the diligence of future engineers to realize this indirect addressing is taking place and update this code if the array size is ever changed.

Any suggestions?

Create a constant tag that will contain the array size, and don't allow external access to it either. Set the constant value using RSLogix5000, and use the tag in your limit checking instead of a literal value.

Future expansion or reduction will just need the value of the constant tag changing, when the array size is modified, and it will ripple throughout your logic.
 
Daba, thank you for the timely reply.

That method does save future engineers from doing an online edit to change a literal value, but it doesn't alleviate my fear of someone changing the size of the actual array and then not updating either the literal or the constant register.
 
Of course it doesn't help when the BOOL array will "snap" to the nearest higher 32-bit multiple, e.g. BOOL[20] will automatically be created as BOOL[32].

The only course of action I can currently think of is to use a Fault Routine in your Programs to trap for "Array Bounds Violation", clear the fault, and set an alarm bit that prevents the process continuing until the index is once again within the array bounds.
 
As an aside, I've always avoided using BOOL arrays, as there isn't much you can do with them ....

When I've needed to use a BOOL array, I've made the array the sole member of a UDT. In doing so, I can use COP, or CPS, to copy the array into a DINT array, manipulate the data there, and COP or CPS it back again. All very messy, but a useful work-around in many cases.

Oh - and welcome to the forum !!
 
Yes, boolean arrays aren't very friendly in CLX. I thought about trying to leverage the fact that you can't create a boolean array that isn't a multiple of 32. But I haven't come up with anything yet. To you point about boolean arrays being troublesome, I have thought about just using an integer array and being done with it, but when I am only interested if it is true or false I would prefer to use bools.

I'm about to give up and just create a tag to house the constant like you mentioned in your first reply.

If anyone has any further suggestions I am still interested in hearing them.

Thank you for the warm welcome. Long time reader, first time poster.
 
Yes, boolean arrays aren't very friendly in CLX. I thought about trying to leverage the fact that you can't create a boolean array that isn't a multiple of 32. But I haven't come up with anything yet. To you point about boolean arrays being troublesome, I have thought about just using an integer array and being done with it, but when I am only interested if it is true or false I would prefer to use bools.

I'm about to give up and just create a tag to house the constant like you mentioned in your first reply.

If anyone has any further suggestions I am still interested in hearing them.

Thank you for the warm welcome. Long time reader, first time poster.

You can test none of the 32-bits of a "boolean-style" array, encoded in a DINT array, with a simple EQU 0

Have you considered the error trapping I posted in post #5 ?
 
My apologies, I somehow missed that post (#5). That could possibly work. However, I have no experience with fault routines. The real goal is to determine the array size and then have code that will never produce a fault due to having this accurate information. I imagine that even if you clear the fault immediately, the fault still occurs and the outputs are all sent to their "fault" state, even if only for a fraction of time.

I just hard-coded it; if the index is less than 32, the code is executed. I'm honestly not that concerned with a fault occurring in the future due to someone messing with this code. I had a need to detect a boolean array size and couldn't.

I appreciate your feedback. I still find it baffling that I can use the SIZE command on an array of a UDT, but it won't work on a boolean array nor is there any other method to determine a boolean array size.
 
It has occurred to me that you could determine the size of the array on first scan by executing a routine that successively increments (by 32) an index, and attempting to address that location. A fault routine would eventually be executed, and the index would be the size.

The code is fairly easy, see the attached file (V20).... I made a BOOL array of 20000 bools, which the iterative loop discovered in about 2mS.
 
This may or may not help you. It is a very advanced programming technique. Logix5000 supports something called a bit overlay. It is a special kind of UDT that lets you name bits in a word and use them as booleans but also use the word as an integer. There are a few threads on the subject. A search on "bit overlay" will turn them up. If you made your array a DINT array and then used SIZE and multiplied by 32 you would know how many bits you have available.

I posted an example of a bit overlay here:

http://www.plctalk.net/qanda/showpost.php?p=397545&postcount=4

If it doesn't help you then don't sweat it, overlays aren't for everyone.

I like DABA's solution to find it on first scan as well.
 
I like DABA's solution to find it on first scan as well.

Thanks, TConnolly, I quite like it as well, and I don't think the scan time overhead will be an issue in most, if not all, projects, as it is only executed on the first scan.

It might look like a "brute-force" method, but since it only executes once each power-up or mode change, it won't have a scan-time impact on the users logic.

I've looked at programming the same code into the Power-Up Handler task, but have a problem that the "fault" can't be trapped there ???
 

Similar Topics

Controller: 1756-L84E v.35 Prosoft MVI56E-MNETC for ModbusTCP/IP I'm having an issue with some of my write commands. The write command that...
Replies
0
Views
186
I have several Avery scale units and they are configured as Generic Ethernet modules, and I am actually reading the data fine for the weight...
Replies
2
Views
399
What's the best way to move a tag value from the panelview+7 to the clx plc. We display amps from a power meter on the panelview screen, read in...
Replies
1
Views
393
I'm running into an issue migrating a PLC-5 using the newer Logix Designer Export when opening a saved .ACD from RSLogix-5. It has multiple RIO...
Replies
2
Views
609
We have two sites that are stranded with no line of site, they are handled by phone/modem with a chain that includes: Stranded site (client)...
Replies
5
Views
897
Back
Top Bottom