S7-300 Array indexing in stl

Roamingoat

Member
Join Date
Oct 2007
Location
Basildon
Posts
3
As a relative newcomer to the S7-300 its driving me crazy. Can anyone tell me how I simply address an array item in the form:
Array[index] where Array is declared as a single dimension array of integers and index is an integer variable? I am working in LAD/STL and can't get the syntax right.

L "DB3".CIP_STEPTIME["DB3".CIP_STEP]....X
L "DB3".CIP_TIM_ACC
+I
T "DB3".CIP_TIM_ACC
 
Last edited:
It wont be simple in STL and it is impossible in LAD.
Array indexing in STL requires you to create a pointer, and there are many variants depending on what type of data and what you want to do with it.

This thread has a generalised example of array indexing (L D[AR2, P#0.0]'s post):
http://www.plctalk.net/qanda/showthread.php?p=230787
It is generalised so much that it may be too complex for your use. But you can cut it down to what you really need.

Do you have SCL ? If you have it I strongly recommend it for array indexing with S7.
In SCL you can really write data.Array1[22]:=(data.iArray2[iIndexVar1] + data.iArray3[iIndexVar2]) for example.
To achieve the same line of code in STL will take lots more work.
 
Here's a cut down version of the generalised array access FC that will read a value from an array of integers.

Code:
FUNCTION FC 7 : VOID
TITLE =Read an integer from an array;
VERSION : 0.1

VAR_INPUT
  aiArray : ANY ; 
  iArrayIndex : INT ; 
END_VAR
VAR_OUTPUT
  iResult : INT ; 
END_VAR
VAR_TEMP
  iType : INT ; 
  iDBNumber : INT ; 
  dwAreaPointer : DWORD ; 
  iSize : INT ; 
  bBOOL : BOOL ; 
  wWORD : WORD ; 
  dwDWORD : DWORD ; 
  byBYTE : BYTE ; 
END_VAR
BEGIN
NETWORK
TITLE =de-construct any pointer for input array
	  L	 P##aiArray; 
	  LAR1  ; 
	  L	 B [AR1,P#0.0]; 
	  L	 B [AR1,P#1.0]; 
	  T	 #iType; 
	  L	 W [AR1,P#2.0]; 
	  T	 #iSize; 
	  L	 W [AR1,P#4.0]; 
	  T	 #iDBNumber; 
	  L	 D [AR1,P#6.0]; 
	  LAR1  ; 
NETWORK
TITLE =read integer from array
//open db if required
	  L	 #iDBNumber; 
	  L	 0; 
	  ==I   ; 
	  JC	indb; 
	  OPN   DB [#iDBNumber]; 
indb: L	 #iArrayIndex; 
	  SLD   4; 
	  +AR1  ; 
	  L	 W [AR1,P#0.0]; 
	  T	 #iResult; 
	  SET   ; 
	  SAVE  ; 
END_FUNCTION

Here's an example in use:

array002.JPG
 

Similar Topics

Dear All , I have written a small program in SCL as below . ///////////////////////////////////////////////////////////// FUNCTION FC1:VOID...
Replies
6
Views
2,429
Hi, I am useless at STL and not fortunate enough to have SCL. I am trying to do the following; MW1 := 6 MW2 := 400 DB100.DBW[MW1] := MW2 So store...
Replies
3
Views
1,676
Looking for some help with an array of strings in SCL. I have an array of 99 string[98] I also have an array of 99 INT My first 4 chars of the...
Replies
9
Views
2,488
Hi Guys: See attached figure. This is my UDT. Is there any way to populate my array using excel and then copying it to my program, instead of...
Replies
8
Views
2,727
Hello, Using LAD, how can I generate an array of 50 numbers and then calculate an average of them? I don't know how to define an array as a...
Replies
29
Views
11,462
Back
Top Bottom