S7: Pointer offset as variabel

It can be done like this

Code:
L     P#6.0                       // Load ACCU 1 with pointer value.     
      T     MD     2                    // Transfer pointer into MD2.
      OPN   DB     1                    // Open datablock 1
      L     10
      T     DBW [MD 2]                  // Transfer value 10 to db1.dbw6 
      L     P#2.0                       // Increase pointervalue in md2 with 2 bytes
      L     MD     2
      +D    
      T     MD     2
      L     25
      T     DBW [MD 2]                  // Transfer value 25 to db1.dbw8
 
See the line 3 below the one you circled.

+AR1 P#2.0

This is changing the offset by 2 bytes, or the next word.

3 lines before the circled code, is where AR1 is originally set

LAR1 P#DBX0.0

If you want to vary the start point, you could use the +AR1 instruction after the LAR1 instruction and use a variable to do the offset.

i.e. prior to the code you can see have something like

L 2 <== could be variable
SLD 3
T MD500

Then after the LAR1 put

L MD500
+AR1
 
The variable name suggests you are looping through a number of reals yet you are loading/transferring words - might be a bit confusing in the future.
 
Hi again.

It's a cut from other program... and of coarse it will be changed to "No_of_Words"

I try to make the same function as TI505 - MWI Move With Index
 
Do you require two indexes, one for the source and one for the destination ?
What format do the indexes take, ints specifying the byte offset or pointers so you can specify DBW60 (for example) as the parameter ?
 
Last edited:
Do you require two indexes, one for the source and one for the destination ? Yes, just what i want
icon14.gif
fx. 60 for "read from DB60" and 61 for "write to DB61"

What format do the indexes take, ints specifying the byte offset or: Yes, like offset from DB62.dbw0 Same offset for both indexes.. :p
pointers so you can specify DBW60 (for example) as the parameter ?
 
Wow, Siemens must be proud of the URLs, they are sooooo long

http://www.google.com/url?sa=t&sour...Ve0ZBJ9wYLtAcLcRg&sig2=dNNhnQHStTxI_LXW6iqcjw

On page 6-104 the MWI instruction clearly shows that there is a source pointer, destination pointer and a count.

On page 6-90 there is the MOVE instructions that has a pointer and index for both the source and destination as well as a count.

If Bill is trying to emulate the MOVE instruction then one more parameter would be needed to scale the index into bit, byte, words and dwords offsets.
 
Code:
FUNCTION FC 1 : VOID
TITLE =
VERSION : 0.1


VAR_INPUT
  i_DB_Read_from : INT ;    
  i_Offset_read : INT ;    
  i_DB_Write_to : INT ;    
  i_Offset_write : INT ;    
  iNoofWords : INT ;    
END_VAR
VAR_TEMP
  iLoopCount : INT ;    
  iDB : INT ;    
END_VAR
BEGIN
NETWORK
TITLE =

      L     #i_DB_Read_from; 
      T     #iDB; 
      OPN   DB [#iDB]; 
      L     #i_DB_Write_to; 
      T     #iDB; 
      OPN   DI [#iDB]; 
      LAR1  P#DBX 0.0; 
      L     #i_Offset_read; 
      SLD   4; 
      +AR1  ; 
      LAR2  P#DIX 0.0; 
      L     #i_Offset_write; 
      SLD   4; 
      +AR2  ; 

      L     #iNoofWords; 
LA:   T     #iLoopCount; 
      L     W [AR1,P#0.0]; 
      T     W [AR2,P#0.0]; 
      +AR1  P#2.0; 
      +AR2  P#2.0; 
      L     #iLoopCount; 
      LOOP  LA; 
      SET   ; 
      SAVE  ; 
END_FUNCTION
 

Similar Topics

Hello Folks! I have an application where I need to copy a string into various locations within a DB. So, I've set up a Function Block to accept...
Replies
3
Views
4,956
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
533
I am trying to access the value of a pointer via OPC UA in Codesys. I can share it directly and in a struct but I cant access the value of it when...
Replies
5
Views
1,612
Why does my deconstruction of the input pointer only work with its own instance DB not inside the multi instance FB...See .doc The pointer at the...
Replies
8
Views
2,342
Hi All, in many library function of TiaPortal some data must be write using the pointer format........ eg.: P#DB90.DBX0.0 WORD 10 is it...
Replies
5
Views
2,818
Back
Top Bottom