Structure Text Array Declaration

sterky

Member
Join Date
Jul 2023
Location
ontario
Posts
18
Hey all,

So I've had some experience with C++ style programming and I'm trying to figure out the best way to declare an array of numbers for each recipe that is loaded. Currently have a reference array but its a pain to make adjustments or even see it with all the other attributes in the CASE structured text I'm using.

What I'm trying to replicate from C++
int Array[5] = {2, 4, 5, 3, 1};

but the only way I can figure to do it,
array[0] := 2;
array[1] := 4;
array[2] := 5;
...
etc.

Really hoping someone knows a cleaner way or has some clever tricks I should consider.

Thanks
 
I might be reading this wrong and this carries a risk of overflow but if the 2,4,5,3,1 were in consecutive elements of an existing INT array you could COP the first (or any) element of that array into any position of the second INT array with a length of 5 (or whatever).

The syntax will be wrong but the idea would be:

COP SourceArray[X] DestArray[X] 5
 
I might be reading this wrong and this carries a risk of overflow but if the 2,4,5,3,1 were in consecutive elements of an existing INT array you could COP the first (or any) element of that array into any position of the second INT array with a length of 5 (or whatever).

The syntax will be wrong but the idea would be:

COP SourceArray[X] DestArray[X] 5


Currently the numbers are in an array, its basically pointers for another array to do custom ordering/referencing.

Issue is right now we just populate the info in the controller tags and I'd rather have the in the structured text to keep it getting written to and readable in the same area of structured text.

Simply put, I'm looking to fill an array with simple numbering (1-20) without having 20x "this[1] := 1;"

I'm even considering strings at this point to make it easier to manage. "3,4,2,5,1" with some ladder logic to pull the numbers out
 
Is it a fixed sequence or effectively random?

To my knowledge, there's no standard or extended support for initializer lists in structured text.
 
Is it a fixed sequence or effectively random?

To my knowledge, there's no standard or extended support for initializer lists in structured text.

effectively random, I need to have 4 different ordering. I can just reverse the order from the default to do one of the others but the last 2 arrays will be all over the place with each recipe
 
You can define local arrays in an AOI with default values - this is about as close as you'll get to an initializer list, since Logix punts any and all type/identifier declarations into the tag manager.
 
After a weekend of pondering, I was considering using a string with the max size and comma's to separate the values.
So array[0] = "2,3,1,4,5" but alas I can not define strings that way in structured text, they must be stored in their own string tag and copied. Also not very efficient for space and having to pull the data apart when I wanna use it

I'm gonna go ahead with the following structure and see how big it makes the file
array[0,0] := 2; array[1,0] := 4; ...
array[0,1] := 3; array[1,1] := 3; ...
array[0,2] := 5; array[1,2] := 1; ...
... ...

Might get a little busy with the larger arrays but still fairly readable and hardcoded.
 
If the numbers do not exceed the range [0:256), then you could define them in a hexadecimal immediate value; as many as 8 at a time can be initialized if the environment allows 64-bit integers.

But then you have to write the code to extract the bits.

Six of one ...
 
Or if the range is [0:63), so [2,4,5,3,1] ≡ [B,D,E,C,A], then perhaps this

Code:
char the_data[] = { "BDECA YWVXZ " };
char *p = the_data;
int index;
int array[2][5];

for (p=the_data+(index=0); *p; ++p)
{
  if (*p & 64) { *(array[0]+index++) = *p;
}


could be ported to structured text (without the pointers, of course).
 
Or if the range is [0:63), so [2,4,5,3,1] ≡ [B,D,E,C,A], then perhaps this

Code:
char the_data[] = { "BDECA YWVXZ " };
char *p = the_data;
int index;
int array[2][5];

for (p=the_data+(index=0); *p; ++p)
{
  if (*p & 64) { *(array[0]+index++) = *p;
}


could be ported to structured text (without the pointers, of course).

The poor sucker that has to follow behind for something like that. Hardcoding will be more time on the the front-end, but should be easier to follow.
 

Similar Topics

I'm working with a project that contains some routines in ST but mostly in ladder. Am I correct in assuming this 'rung': DB1001DO._01AV55_OPEN :=...
Replies
4
Views
114
I have quite a large number of recipes in CASE form that I'm writing in structured text. I'm hoping to keep things clean and efficient when...
Replies
13
Views
1,490
Hello Experts, I hope everyone is safe and healthy!! Below mentioned Siemens code is in STL i have to write it in Structure text in Allen...
Replies
4
Views
1,659
Hello everyone, I am a beginner in PLC programming. I want to acquire pressure data from the sensor (water pressure) which give output value 0-5V...
Replies
4
Views
1,702
Hi there, I am currently working on a C# software tool that needs to compile RSLogix 5000 structure text (ST) language (IEC61131-3 + additional...
Replies
11
Views
5,363
Back
Top Bottom