CompactLogix - Max size of string array?

Friedrich

Member
Join Date
May 2014
Location
Swedistan
Posts
52
Hi all!


I have a controller (L38-ERM) where I had a one dimensional array of strings with 1028 elements in it. I expanded this to 2048 because I needed to store more strings in the array.


When I did this the controller faulted, saying the array was too big. I didn't find any limitations mentioned in the manual/help file, so is there actually a limit on the size?
 
Just a guess until someone with more knowledge shows up but is it related to the memory in the controller?
 
Not to be pedantic, but default strings are 88 bytes each (82 chr +2 to byte align, +4 for length), still though, less than 2MB

Edit: Tried it, you can create an array of standard strings with a length of 2048. The only limiting factory is whether you have enough memory left in the controller. I believe JeremyM has the correct answer since the controller faulted. Trying to create an array too large wouldn't fault the controller, the software would just prevent you from creating it.

Edit2: I wonder why strings are 82 characters? If they were 84 characters, they would still take up the same 88 bytes of memory. Must be some legacy thing.
 
Last edited:
Edit2: I wonder why strings are 82 characters? If they were 84 characters, they would still take up the same 88 bytes of memory. Must be some legacy thing.

Legacy from 80-character TTY terminals perhaps. The other 2 are for CR and LF
 
Not to be pedantic, but default strings are 88 bytes each (82 chr +2 to byte align, +4 for length), still though, less than 2MB

Edit: Tried it, you can create an array of standard strings with a length of 2048. The only limiting factory is whether you have enough memory left in the controller. I believe JeremyM has the correct answer since the controller faulted. Trying to create an array too large wouldn't fault the controller, the software would just prevent you from creating it.

Edit2: I wonder why strings are 82 characters? If they were 84 characters, they would still take up the same 88 bytes of memory. Must be some legacy thing.


There's no "alignment bytes"....

Create a new STRING1 data-type, with string-length 1, you will consume 8 bytes of memory - that's 4 bytes for the (DINT) string length, and 4 bytes for the strings "Data" array. Even though that would only need 1 byte, the minimum data allocation on the Logix5000 platform is 32-bits (4 bytes) because of its 32-bit processor architecture.

So it progresses from there, there will always be a 4-byte DINT for the string length, even though a STRING is limited to 1 to 1 to 65535 characters. It had to be a DINT, because an INT only goes up to +32767 (remember, always signed integers in A-B).

From there, add 4 bytes for every 4 characters. The string data is declared as a SINT array, so will pack 4 characters into a single 32-bit memory location.

Perhaps the attached spreadsheet may help to explain my clumsy wording ....

2020-12-23_215030.jpg
 
First a question, did you try to redimension the array online while the PLC was running ?
You can’t do that, you have to go offline make the change and re-download it.
Trying to change the dimensions of array while it running may generate that error message the processor may not be able to allocate memory for it while it running.
That’s similar to what happens in Windows if you open an application in Windows the system allocates the necessary memory for it but when you close the app the memory is still allocated for that incident of the app. Then if you open the same app again the system allocates additional memory for it while leaving the original memory allocation unused. They recommend that if you run multiple apps on your computer that you power it down every day to flush the buffers and memory allocations.

Some programming languages allow you to change the dimensions of an array within the code but I have never heard of one where you can do it from outside the code while it’s running .


I think it’s important that we understand the structure of data types and I hop this helps.
Now let’s look at the structure I know this should be review for most of us but a little review is always good for everybody.
I think we all understand that all programs and data in a computer or PLC are nothing but 1’s and 0’s
It how we and the computer translate them and that’s why we have different data types.
A few shown here
A single 1 or 0 is a BIT
As groups
4 BITs are a NIBBLE
8 BITs are a Byte it’s also in a PLC a SINT Data Type at one time these 8 bit’s were considered a word
16 BITs are INT also INT(13) In a PLC is and INT Data Type for many years this was the standard word
This 16 BIT word has 2 BYTE’s
32 BITs are a DINT also INT(32) In a PLC it is also a DINT and again for years this was the standard word
This 32 BIT word has 4 BYTE’s
64 BITs are LINT (Long Integer) while they are not yet common in PLCs I would think they are coming soon
Most PCs are already using them (Windows 10 is 64 Bits )
A 64 BIT word will have 8 BYTE’s
128 BIT computers are already designed and will soon be common place
These data types are all Integer numbers with no Decimal places
Then you have Float or Real Data type the use the IEEE standard data format to read them

Now let’s look at the structure of the STRING Data Type in Logix processors
Data in a STRING data type are displayed as ASCII characters. Each ASCII character uses a 1 Byte word, 8 Bits
The String Data type is actually 2 data types together known as properties the
.LEN is a DINT data type 32 BITs or 4 BYTEs
.Data has a fixed length of 82 BYTEs
These cannot be changed
So the memory required to store a String data type is 82 Bytes + 4 Bytes or 86 Bytes no matter how many characters are entered in the string.
The .LEN is the number of Bytes used for the string or the number of characters you want to display or use
And as we know there are no blank spaces in a computer just “00” in ASCII is Null but it still takes up space (Bits) when stored
As simple 2 character string “OK”without the .LEN data would be displayed as 82 characters long the .LEN value in this case would be 2
The system would read and display only the first 2 characters “OK” the remaining 80 characters would not be read or displayed.
But to store the string the system would still store the 4 bytes of .LEN and 82 Bytes of the .Data
Again to store a string data type it always take up 86 bytes for each for each string
Now if you create an array of string data types each elements will have both the .LEN and the .DATA Properties
In addition you need an index or reference for each element and here again Logix processors use a DINT data type for that so you need to add an additional 4 bytes to total bytes for each element of the array for a total of 86 + 4 = 90 Bytes for each element
An array of 1024 would be 1024 * 90 = 92,10 bytes for that array
An array of 2048 would be 2048 * 90 = 184,320 bytes for that array
That’s far below the 2 MB limit

You need to keep in mind that if you have a multidimensional array then you will need to add up all bytes of the data types

You should expand the structure of a string data type yourself you can actually access any of the Bits
 
Hi all!


I have a controller (L38-ERM) where I had a one dimensional array of strings with 1028 elements in it. I expanded this to 2048 because I needed to store more strings in the array.


When I did this the controller faulted, saying the array was too big. I didn't find any limitations mentioned in the manual/help file, so is there actually a limit on the size?

You cannot change the size of an array online, even in Program Mode ....



The limit in elements for an array of the standard STRING data-type (82 character, but you can make your own string data-types with less, or more, character lengths), can easily be discovered by dividing 2 MB (2 * 1024^2 bytes), by the size of one STRING tag, which is 88 bytes.

This works out to 23,831.2723...

You can create, therefore, an array tag STRING[23831], and the software will pop-up a window warning you the tag is over 1.5 MB, but the tag is created when you hit OK.

If you try to create STRING[23832], you get an error pop-up that says the tag is greater than 2 MB, and the tag is not created.

See the pictures ....

To calculate how many bytes a string array tag will consume, use the following formula in Excel ...

=ArraySize*(4+(CEILING(StringLength,4)))

This is a useful formula when working with lots of string data, at different number of characters per string. If the result is greater than 2*1024^2, the tag cannot be created.

2020-12-24_100159.jpg 2020-12-24_100237.jpg
 

Similar Topics

I have a project where I will need around 20 IO cards. I'll probably have 5 on a compactlogix L320ER and 15 or 20 on a Point IO AENTR module. The...
Replies
4
Views
981
While trying to download produced and consumed tags with a new controller on the same network I get this error: The maximum number of nodes on...
Replies
8
Views
4,269
ok guys i know i have been blowing this forum up a lot here lately but i am venturing into some unknown waters for me. ok the situation is i have...
Replies
5
Views
1,512
So basically i have 2 queries : 1. I have a program file of S7-300 PLC which i want to migrate in RSLogix500.In short i want to convert my simatic...
Replies
15
Views
252
Hi everyone, i have a compact logic 1769-L18 PLC and I'm using FTalk View ME for the display. I wanted to do some visualization on Grafana. At...
Replies
1
Views
113
Back
Top Bottom