Bool Arrays - 16 bool limit?

169 views
Skip to first unread message

twos...@googlemail.com

unread,
Oct 26, 2021, 11:59:24 AM10/26/21
to libplctag
Hello o/

I seem to be having issues with bool arrays (lol, yes.. it's probably an odd thing to do).
In my PLC (Logix L75) I have a UDT with 3 sub member arrays.
5000 DINT's
500 REAL's
512 Bool's

Reading the other items seems fine, when it comes to the bool array I can read the first 16 bools.. if I increase that, I get a -19 Tag not found.

Using.. protocol=ab_eip&gateway=192.168.1.1&path=1,0&cpu=LGX&elem_count=512&name=MDS2.B&debug=4

Running in a little test program with debug turned on I see that i get a..
thread(1) tag(0) WARN plc_tag_create:735 Error PLCTAG_ERR_OUT_OF_BOUNDS while trying to create tag!

Now, its not a big issue (I can do a work around) but was wondering if there is a tweak to get around this?

Or could this be down to some kind of conversion going on somewhere, as 512/32 = 16?

Cheers,

Twoshrubs :)

Kyle

unread,
Oct 27, 2021, 12:14:33 AM10/27/21
to libplctag
Hi,

Bool arrays are handling differently in Rockwell PLCs.   Internally they are stored as DINT values (which is why you can only have arrays that are a multiple of 32 bit in length).  That means that the element count value needs to be divided by 32 and rounded up to the nearest full word.  Your math at the end is correct: 512/32 is 16 elements.   So set elem_count=16 and you will be able to read the entire array.   Note that the bit accessor functions (plc_tag_get_bit, plc_tag_set_bit) only support up to 256 bits.   That is in my code, so it can be changed.  I seem to remember that I thought that the size could only be up to 256 for some reason.   Clearly not if you have a boolean array of 512 bits!  I raised issue 291 to track this.

It would be nice to make this easier to use.  I will think about what might work to allow bit sizes of elements.  

Thanks for bringing this up!

Best,
Kyle

twos...@googlemail.com

unread,
Oct 27, 2021, 2:46:13 AM10/27/21
to libplctag
Hello Kyle,

Thank you for clearing that up for me :)

Cheers,

Twoshrubs

Kyle

unread,
Oct 27, 2021, 8:19:24 PM10/27/21
to libplctag
What would make more sense?
  1. adding a new attribute, elem_size_bits, for used when using bit-sized elements (I suppose someone somewhere has used elements of 3 bits in a PLC).   For a bit array you would use elem_size_bits=1.  Internally I can convert elem_size to bits via elem_size_bits=elem_size * 8 and keep my code simple.
  2. use the elem_type attribute, which already exists but is underdocumented, to note that the value is a boolean array.
I am leaning toward the first option.

Best,
Kyle
Reply all
Reply to author
Forward
0 new messages