Pesk Siemens indirect addressing with arrays

Gnook

Member
Join Date
Jan 2007
Location
Wales(UK)
Posts
20
I have seen many posts relating to indirectly addressing arrays but none seem to fully explain how to do it simply. At the moment I have an application where I would like to dynamically set the size of an array then access the individual elements using an 'index'. So far I have tried the following in SCL but it does not compile:-



VAR_Input

nElements:int; // number of elements in array

End_Var



VAR_Temp

myArray:array[1..nElements] of dint; //my dynamic array

myElement:int; //my pointer to a specific element

myValue:dint; // a temporary place holder for this example

End_Var



The declaration for the array fails because 'nElements' is an invalid constant, if I declare a constant it works but my array is no longer dynamic. Does anyone know why I can't use the input as the constant?



The next problem is stepping through the array. I would like to use a loop with an expression like: -

myElement:=myElement+1;

myValue:=myArray[myElement];



Again this does not compile saying I have an invalid constant. I could use an old piece of code I got from Siemens Tech. support years ago to get a solution but it would not be as flexible or elegant as being able use indirect addressing and dynamic array sizing.



Has anyone got any suggestions?
 
You cannot declare a dynamic array. If you want to use SCL array accesses you will have to declare the size of the array at the maximum you will need. If the array is going to be larger than say 50 elements, I would declare it as a static variable in a function block rather than as a temp.
Note that temp variables do not retain their values after a function or function block has finished executing.
 
From what I have gathered of 61131, the array sizes are established when the program compiles, so you have to have a static length for this to work.
 
Thank you, I take your point regarding fixed array size and have modified my code to suit. I don't suppose you know how to calulate the average for an array range in SCL?
 
Do you mean something like this ?

Code:
FUNCTION_BLOCK FB10
VAR
Range:INT;	
Index:INT;
Sum:REAL;	
Average:REAL;
Data :ARRAY[1..50] OF REAL;	
END_VAR
BEGIN
Range:=10;
Sum:=0.0;
FOR Index:=1 TO Range DO
Sum:=Sum+Data[Index];
END_FOR;
Average:=Sum/Range;
END_FUNCTION_BLOCK
 
Last edited:

Similar Topics

The past week we received a new piece of equipment from Germany which utilizes siemens controls. Typically in our company we use A.B. controls for...
Replies
6
Views
94
Hello I have a s7-1200 and I would like to read the tags present in this controller with my controllogix controller. The two controllers don't use...
Replies
5
Views
126
Hi need help why this “failure 5 emergency stop “ appears at every startup in the morning ? Have to shut off main switch at least 10 times on...
Replies
19
Views
286
i have two plc 1. s7-1212dc/dc/dc ip; 192.168.0.1 2. s7-1500 1513-1pn ip; 192.168.3.2 i need to get data from plc1 to plc2. any idea how to do...
Replies
5
Views
106
Hi everyone hope you'll well. Is it possible for me to download a Crack version of tia portal v13..sorry to say this but the software is very...
Replies
5
Views
198
Back
Top Bottom