Siemens Step7 pointer

mitchell2k

Member
Join Date
Apr 2019
Location
Manchester
Posts
10
Hi people. I am having some trouble with siemens Step7, i'm not expert on it by any stretch. I'm more of a Bradley person with some TIA portal experience.

I am trying to use a variable pointer for an array but cannot seem to get it working for the life of me. I have tried making the pointer to types INT, DINT, ANY and WORD but non of them seem to work. I have tried examples in STL where i use the OPN command to open the DB then load an integer into my pointer etc but this doesn't seem to work either.

I have attached a picture of the code below to show what I am trying to achieve, Network 8 is accepted using a direct number for the array but Network 9 is where i try to use a variable and it wont accept it. o_O:angr:

Any help would be greatly appreciated, thanks in advance.

S7Pointer.png
 
Last edited:
In S7-300/400, and in STL, and also in LAD and FBD, you cannot do indirect addressing like that. (In S7-1500 you can but that does not help you.)
In order to do indexing in STL you have to use pointers, but if you have SCL that is by far the easiest way. In SCL you can write
"Report_Data_Complete".Blender_1_Stage_Data[Point1].Start_time := #StageNo ;

edit: Is Point1 defined ?
If it was an external variable it would look like this: "SomeDB".Point1.
If it was an internally declared variable it would look like this: #Point1.
Not that it makes any difference, it is not possible in STL.
 
Last edited:
Hi Jesper, thank you for your reply. Unfortunately i dont have SCL, just STL, LAD and FBD. I have also just realised the code in my original picture is incorrect as i had just deleted and changed it. Below is the true image of what i'm trying to achieve, i will update the OP image now.

I have tried the following too but no joy...

CALL "PointerBuild"
DataBlock :=500
StartByte :=6084
DataLength:=2
D_Pointer :=#M2_StageNo

PointerBuild...

L P##D_Pointer
LAR1

// Any Data Type Length/Type
L W#16#1002
T W [AR1,P#0.0]

// Data Length
L #DataLength
T W [AR1,P#2.0]

// Data Block Number
L #DataBlock
T W [AR1,P#4.0]

// Calculate Pointer
L #StartByte
SLD 3
L DW#16#84000000
OD
T D [AR1,P#6.0]

SAVE

S7Pointer.png
 
Instead of me giving a crash course in pointers, try to describe what you want to achieve.
Also, I am not the correct person to ask, since I try to avoid both pointers and STL. I have some ancient STL code with pointers which if I would ever have to touch it I would convert it to SCL instead.
 
I basically want to write data such as time/date (Integer format HrMinSec) to an array element dependent on the stage.

if say the Stage = 1
write HrMinSec to report_complete_data.blender_1_Stage_Data[ STAGE ].Start_Time

Stage is incremented in a sequence so the one line of code can write the data to all 10 stages.
 
This is lends itself to directly addressing again though. I need the element to be in the array number that corresponds to the stage number.

If the stage is say 1
write the data to the array[stage].element is what i'm trying to achieve
 
Something like this:

#startbyte = #myArrayIndex * 4 + 92 (You have DBD92 as your starting byte in DB4)

#myArrayIndex is your value between 0-9

CALL "PointerBuild"
DataBlock :=4
StartByte :=#startbyte
DataLength:=4
D_Pointer :=#M2_StageNo

This will result in array 1 being at DBD92, array 2 at DBD96 etc.
 
Last edited:
For what it is worth, I would always keep things like this as simple as possible.
So instead of "building" a pointer dynamically, I would merely code it directly.
You are passing the absolute addresses to the "pointer building" block anyway. Any which way, it is a glorified example of absolute addressing.

Here is the principle of how my code would look like:
Code:
OPN DBxx // the DB you want to access
L P#0.0 // the byte address of the first array element. Adapt to your actual case.
T #P_writeadress

L 1234 // load some value
T DBW[#P_writeadress] // write it to the array element

L #P_writeadress // increment to next array element
L P#2.0 // Adapt to the element type. INT type is 2 bytes.
+D
T #P_writeadress // now the pointer points to the next array element.

L 5678 // load some value
T DBW[#P_writeadress] // write it to the array element

// it is possible to use LOOP/NEXT for looping through an array
 
Here's a function that will write to your array:


Code:
FUNCTION FC 7 : VOID
TITLE =
VERSION : 0.1


VAR_INPUT
  FirstArrayElement : ANY ;    
  SecondArrayElement : ANY ;    
  tDataToWrite : TIME ;    
  iArrayIndex : INT ;    
END_VAR
VAR_TEMP
  iType : INT ;    
  iDBNumber : INT ;    
  dwFirstAreaPointer : DWORD ;    
  dwSecondAreaPointer : DWORD ;    
  dwSize : DWORD ;    
  iSize : INT ;    
END_VAR
BEGIN
NETWORK
TITLE =de-construct any pointer for input array

      L     P##FirstArrayElement; 
      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]; 
      T     #dwFirstAreaPointer; 

      L     P##SecondArrayElement; 
      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]; 
      T     #dwSecondAreaPointer; 

      L     #dwSecondAreaPointer; 
      L     #dwFirstAreaPointer; 
      -D    ; 
      T     #dwSize; 

      L     #iArrayIndex; 
      +     -1; 
      L     #dwSize; 
      *D    ; 
      L     #dwFirstAreaPointer; 
      +D    ; 
      LAR1  ; 
      OPN   DB [#iDBNumber]; 
      L     #tDataToWrite; 
      T     D [AR1,P#0.0]; 

END_FUNCTION
 

Similar Topics

I have a word in some DB which I want to load to AR1 and use as a pointer. In order to do this I need to write L DBxy.DBW xy SLD 3 LAR1 I...
Replies
3
Views
540
Hello! Is it possible to copy pointer's pointing address to any variable at Siemens step7? I mean I have pointer address to db block with...
Replies
14
Views
15,550
This is the first time I am working with Simatic Manager Step7 as I started my siemens journey with TIA which is pretty easy and do a lot of stuff...
Replies
3
Views
146
When you download a DB, the values get overwritten by what is in the "actual" column in offline DB. Does this happen at the start of the PLC...
Replies
6
Views
142
Hi, I received a Step7 Backup from my client and tried opening this backup but it won't open as there seems to be files missing from the backup...
Replies
11
Views
3,019
Back
Top Bottom