Siemens step7 copy pointer pointing address to ANY variable?

Lare

Member
Join Date
Jan 2006
Location
Finland
Posts
2,022
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 starting addreess and lenght.
Something like P#DB1000.DBX0.0 BYTE10, P#DB1100.DBX0.0 BYTE 10, P#DB1200.DBX0.0 BYTE 10 and I want copy these pointing addressed to one place with selection via number.
(0=Copy P#db1000.dbx0.0 byte 10, 1=copy P#db1100..dbx0.0 byte 10, 2=copy P#db1200..dbx0.0 byte 10 pointing addrees...)

I struggling with this now, with blkmove/SFC20 I can copy data areas from one to another, but how I can copy only pointing address (P#DBxx.dbx0.0 byte10 from ANY to another ANY variable, not data itself from data block?
 
Last edited:
Source code for FC1:
Code:
FUNCTION FC 1 : ANY
TITLE =
VERSION : 0.1


VAR_INPUT
  aP0 : ANY ;    
  aP1 : ANY ;    
  aP2 : ANY ;    
  aP3 : ANY ;    
  aP4 : ANY ;    
  aP5 : ANY ;    
  iSelector : INT ;    
END_VAR
BEGIN
NETWORK
TITLE =

      L     #iSelector; 
      JL    case; 
      JU    P0; 
      JU    P1; 
      JU    P2; 
      JU    P3; 
      JU    P4; 
      JU    P5; 
case: JU    P0; 

P0:   L     P##aP0; 
      JU    pop; 
P1:   L     P##aP1; 
      JU    pop; 
P2:   L     P##aP2; 
      JU    pop; 
P3:   L     P##aP3; 
      JU    pop; 
P4:   L     P##aP4; 
      JU    pop; 
P5:   L     P##aP5; 
      JU    pop; 

pop:  L     P##RET_VAL; 
      LAR2  ; 
      TAK   ; 
      LAR1  ; 
      L     W [AR1,P#0.0]; 
      T     W [AR2,P#0.0]; 
      L     W [AR1,P#2.0]; 
      T     W [AR2,P#2.0]; 
      L     W [AR1,P#4.0]; 
      T     W [AR2,P#4.0]; 
      L     D [AR1,P#6.0]; 
      T     D [AR2,P#6.0]; 

      SET   ; 
      SAVE  ; 

END_FUNCTION
 
Thanks, this works, but only if I use local variable (temp variable and do all coding on same fc-block

How I get point address copied to some db-area.

I tryed coping pointer address to UDT datatype, but it doesn't work.

If I copy adress first with fc1 to temp-variable and then with blkmove/FC200 to db-area it starts to work, why?


FC200 is only for testing purpose now, so that I see that pointing address is working, later I try to use communication block with this.




p.s tested more, works only with temp data variable, if I use db-area for saving pointing address, only first 8 words are copied from db's to another (lenght of UDT-datatype come to part somehow)

Working.jpg Not_work.jpg Working2.jpg UDT.jpg
 
Last edited:
Source for FC1: (I addes saving of AR1 amd AR2 datas before and after, maybe not necessary at FC, but at FB's maybe good?

FUNCTION FC 1 : ANY
TITLE =
VERSION : 0.1


VAR_INPUT
aP0 : ANY ;
aP1 : ANY ;
aP2 : ANY ;
aP3 : ANY ;
aP4 : ANY ;
aP5 : ANY ;
iSelector : INT ;
END_VAR
VAR_TEMP
AR1_saved_data : DWORD ;
AR2_saved_data : DWORD ;
END_VAR
BEGIN
NETWORK
TITLE =

TAR1 #AR1_saved_data; //save AR1 to local var (DWORD)
TAR2 #AR2_saved_data; //save AR2 to local var (DWORD)


L #iSelector;
JL case;
JU P0;
JU P1;
JU P2;
JU P3;
JU P4;
JU P5;
case: JU P0;

P0: L P##aP0;
JU pop;
P1: L P##aP1;
JU pop;
P2: L P##aP2;
JU pop;
P3: L P##aP3;
JU pop;
P4: L P##aP4;
JU pop;
P5: L P##aP5;
JU pop;

pop: L P##RET_VAL;
LAR2 ;
TAK ;
LAR1 ;
L W [AR1,P#0.0];
T W [AR2,P#0.0];
L W [AR1,P#2.0];
T W [AR2,P#2.0];
L W [AR1,P#4.0];
T W [AR2,P#4.0];
L D [AR1,P#6.0];
T D [AR2,P#6.0];

LAR1 #AR1_saved_data; //restore AR1
LAR2 #AR2_saved_data; //restore AR2


SET ;
SAVE ;

END_FUNCTION
 
Source for FC200:

FUNCTION "FC_POINTER_TESTI" : VOID



VAR_INPUT
pAny_source : ANY;

END_VAR

VAR_OUTPUT


pAny_dest : ANY;

END_VAR


VAR

erg: INT; //Return value

END_VAR


erg:= SFC20(srcblk:= pAny_source, dstblk:= pAny_dest);






END_FUNCTION
 
If you want to pass an anypointer that is computed at run time, you have to use a temp variable of type any.
 
^So there is no way to count any-pointer in one FC-program (like FC300) and use same counted pointer in another prgram section like FB301 or FC301.

Only way is to use temp-variable at FC-program and use it then in program only in same FC?

Moving counted address to different sub-program with db or MW areas is not possible?
(Of course I can call another FC/FB inside of FC, but only after when I have counted any-temp variable. So I need to take care of network order also in FC, because temp variable don't have same data on another PLC scan anymore/elsewhere at program)
 
^So there is no way to count any-pointer in one FC-program (like FC300) and use same counted pointer in another prgram section like FB301 or FC301.

Yes there is , you have to copy the any pointer generated by the FC to your DB, then, when you want to use the anypointer, copy it from the DB to the anypointer you are going to pass to SFC20 for the block copy.
 
Thanks.

One more question, on example you use AR2 to copy from code to output (FC2 and FC4 blocks)

Is there any reason why copying with AR1 to output don't work? (I Tryed with AR1 but no succees, with AR2 it works)

I'm novice with siemens indirect addressing...)
 
If you access an FC parameter of type UDT or Struct, AR1 is used behind the scenes to access the variable. See the example code being monitored below, AR1 contains V61.0 at the start of the block, but when RET_VAL.byS7 is written, AR1 changes to DB0.0
That is why I've used AR2 inside the FC.

beef.png
 
ok, all starts to be clear now ;)

I readed somewhere that if using AR2 (actually if changing pointer value to different) it can lead to unexpected situations after FB block. (And compiling STL code warns of using AR2 also)

So it maybe good to save AR1/2 value first and restore them at last thing at block when? (I coded this to FC also now, so I don't need to remember if I need to do it with FC or FB, if I code it on both...)

SET SAVE, it puts Blocks EN0-pin to "1" allways, (RLO BIT = "1" and SAVE =>move bit result (RLO) to EN0 )?

p.s: http://s7tools.com/index.php?option...n-block-fb&catid=17:tips-and-tricks&Itemid=30

https://support.automation.siemens....objaction=csview&extranet=standard&viewreg=WW
 
^No, this copies data from one db block to another. I want now to copy only the data pointing addresses to any variable, not whole data from block to block.

(I have one communication block, which I try to make to point different partner CPU's depending of integer value. I can code this also with long way, but only areas and pointing addresses differs now one to other, so I could also program this indirectly way...)

L D[AR2,P#0.0] allready shoewd way for this with FC1 source.
 

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
506
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
2,955
Hi! i'm just wondering did there is any chance to change Set Time(TV) on Siemens plc timer without step 7 using c# or python if timer not set in...
Replies
1
Views
1,217
I'm using a 3rd party USB to MPI adapter cable. I can see 157 blocks of various types listed under Accessible Nodes in Simatic Manager. The Upload...
Replies
28
Views
8,116
I have obtained an older copy of Step7 Basic V11 SP1. I plan to run it on Windows 10 through a virtual machine with a copy of Windows Vista Home...
Replies
2
Views
1,512
Back
Top Bottom