You are not registered yet. Please click here to register!


 
 
plc storereviewsdownloads
This board is for PLC Related Q&A ONLY. Please DON'T use it for advertising, etc.
 
Try our online PLC Simulator- FREE.  Click here now to try it.

---------->>>>>Get FREE PLC Programming Tips

New Here? Please read this important info!!!


Go Back   PLCS.net - Interactive Q & A > PLCS.net - Interactive Q & A > LIVE PLC Questions And Answers

Reply
 
Thread Tools Display Modes
Old November 26th, 2014, 03:47 PM   #1
Lare
Member
Finland

Lare is offline
 
Join Date: Jan 2006
Location: Finland
Posts: 1,335
Siemens step7 copy pointer pointing address to ANY variable?

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 by Lare; November 26th, 2014 at 03:54 PM.
  Reply With Quote
Old November 26th, 2014, 04:39 PM   #2
L D[AR2,P#0.0]
Lifetime Supporting Member
United Kingdom

L D[AR2,P#0.0] is offline
 
Join Date: Nov 2006
Location: UK
Posts: 5,861
Example call:
Attached Images
File Type: jpg myany.jpg (65.6 KB, 256 views)
  Reply With Quote
Old November 26th, 2014, 04:40 PM   #3
L D[AR2,P#0.0]
Lifetime Supporting Member
United Kingdom

L D[AR2,P#0.0] is offline
 
Join Date: Nov 2006
Location: UK
Posts: 5,861
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
  Reply With Quote
Old November 27th, 2014, 04:32 PM   #4
Lare
Member
Finland

Lare is offline
 
Join Date: Jan 2006
Location: Finland
Posts: 1,335
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)
Attached Images
File Type: jpg Working.jpg (26.8 KB, 59 views)
File Type: jpg Not_work.jpg (13.4 KB, 28 views)
File Type: jpg Working2.jpg (15.7 KB, 34 views)
File Type: jpg UDT.jpg (28.5 KB, 20 views)

Last edited by Lare; November 27th, 2014 at 05:10 PM.
  Reply With Quote
Old November 27th, 2014, 04:35 PM   #5
Lare
Member
Finland

Lare is offline
 
Join Date: Jan 2006
Location: Finland
Posts: 1,335
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?

Quote:

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






  Reply With Quote
Old November 27th, 2014, 04:37 PM   #6
Lare
Member
Finland

Lare is offline
 
Join Date: Jan 2006
Location: Finland
Posts: 1,335
Source for FC200:

Quote:

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






  Reply With Quote
Old November 28th, 2014, 02:01 AM   #7
L D[AR2,P#0.0]
Lifetime Supporting Member
United Kingdom

L D[AR2,P#0.0] is offline
 
Join Date: Nov 2006
Location: UK
Posts: 5,861
If you want to pass an anypointer that is computed at run time, you have to use a temp variable of type any.
  Reply With Quote
Old November 28th, 2014, 04:36 AM   #8
Lare
Member
Finland

Lare is offline
 
Join Date: Jan 2006
Location: Finland
Posts: 1,335
^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)
  Reply With Quote
Old November 28th, 2014, 10:31 AM   #9
L D[AR2,P#0.0]
Lifetime Supporting Member
United Kingdom

L D[AR2,P#0.0] is offline
 
Join Date: Nov 2006
Location: UK
Posts: 5,861
Quote:
Originally Posted by Lare View Post
^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.
  Reply With Quote
Old November 28th, 2014, 01:18 PM   #10
L D[AR2,P#0.0]
Lifetime Supporting Member
United Kingdom

L D[AR2,P#0.0] is offline
 
Join Date: Nov 2006
Location: UK
Posts: 5,861
Example attached.
Attached Files
File Type: zip Lpp.zip (19.9 KB, 62 views)
  Reply With Quote
Old December 3rd, 2014, 09:59 AM   #11
Lare
Member
Finland

Lare is offline
 
Join Date: Jan 2006
Location: Finland
Posts: 1,335
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...)
  Reply With Quote
Old December 3rd, 2014, 11:51 AM   #12
L D[AR2,P#0.0]
Lifetime Supporting Member
United Kingdom

L D[AR2,P#0.0] is offline
 
Join Date: Nov 2006
Location: UK
Posts: 5,861
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.
Attached Images
File Type: png beef.png (24.1 KB, 160 views)
  Reply With Quote
Old December 3rd, 2014, 12:34 PM   #13
Lare
Member
Finland

Lare is offline
 
Join Date: Jan 2006
Location: Finland
Posts: 1,335
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=...icks&Itemid=30

https://support.automation.siemens.c...ard&viewreg=WW
  Reply With Quote
Old December 4th, 2014, 10:32 PM   #14
RRobbins
Lifetime Supporting Member
United States

RRobbins is offline
 
RRobbins's Avatar
 
Join Date: Dec 2002
Location: Richmond, VA
Posts: 405
I have attached a source file that does exactly what you want.
Attached Files
File Type: zip Data_Move.zip (660 Bytes, 52 views)
__________________
I'd rather be 1 hour early, than 5 minutes late.
  Reply With Quote
Old December 5th, 2014, 10:50 AM   #15
Lare
Member
Finland

Lare is offline
 
Join Date: Jan 2006
Location: Finland
Posts: 1,335
^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.
  Reply With Quote
Reply
Jump to Live PLC Question and Answer Forum

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Topics
Thread Thread Starter Forum Replies Last Post
Siemens Diagnostic Address JDCROCKETT724 LIVE PLC Questions And Answers 19 December 7th, 2015 11:13 AM
Siemens Simatic Step7 cannot tracing address by "Go To Location" ifnul LIVE PLC Questions And Answers 5 February 15th, 2014 07:35 PM
Siemens S7 - begin address of FC or FB code darekk0000 LIVE PLC Questions And Answers 11 February 27th, 2007 02:01 PM
Siemens S7 -> Copy RAM to ROM ? doowahdiddy LIVE PLC Questions And Answers 0 June 30th, 2005 04:29 AM
Copy blocks of data with Siemens S7-300 Werner LIVE PLC Questions And Answers 5 June 10th, 2005 02:07 AM


All times are GMT -4. The time now is 10:39 PM.


.