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

I'm using the Siemens PRONETA software to do some IO testing currently. I love the simplicity and fast testing capability. Does anyone know about...
Replies
0
Views
70
Hi, First time user of S5 Siemens. Is there any solution on how to solve this kind of error. HMI OP7 $613 DB-error No. 11 (0: 15) Siemens PLC...
Replies
9
Views
163
Hello, I have an issue where I want to simulate an Siemens HMI panel, through NAT connection to a PLC. I have the possibility through extended...
Replies
5
Views
159
Hi all! Please inform me if i can make programing of the HMI SIEMENS IPC477D from TIA Portal software or not? I do not have WINCC software but...
Replies
1
Views
105
I have never had the pleasure of working with a "Thermistor" until now and have a question. The Thermistor is a 10KOhm 4-20mA 2-wire device and I...
Replies
4
Views
142
Back
Top Bottom