Copy one DB to another? (S7)

M

Thread Starter

Markus

Hello,

I'm working with a project where I need to move a DB (and all it's content) to another DB. The DBs are exactly the same except for the values.

I have tried with SFC 20 (blkmov) and just give the name of the datablocks as parameters (like "Datablock1"). The compile goes through but it doesn't seem to work, and I get a value on the RET_VAL (dec: 32476 -> hex: 7EDC) so what I can understand it's not an error...

I guess I could make an anypointer ("P#DB100.DBX0.0 BYTE 10") but I havn't figured out the syntax if I wish to enter names instead (ie. P#"Datablock1".DBX0.0 BYTE 10). And more important, what if I only know through o variable (int) how large the DB is? (That sounds a little strange but in my case that will be possible.)

Hope someone can help me with this, thanks.

/Markus
 
Hello Markus;

Here is code from another forum (by a much better STL programmer than I am, I must admit) you could look at.

http://www.plctalk.net/qanda/showpost.php?p=157624&postcount=7

On that same site there are frequent discussions on the dynamic generation and use of ANY pointers, so you could use the Search function of that forum and look for more threads on ANY pointers.

Look at the code, compile it in a source file to import it into a Step 7 project as is. But mostly take the time to understand it, and how it uses area-pointers (LAR/TAR) instructions in combination with the inner structure of the ANY pointer to create a flexible call of SFC20. This way, you can change the size of the source and destination pointers on the fly.

Hope this helps,
Daniel Chartier
 
<pre>
FUNCTION "DataCopy" : VOID
TITLE =Any data copy
AUTHOR : HAG
VERSION : 0.1

VAR_INPUT
SRC_BLK : ANY ;
DST_BLK : ANY ;
END_VAR
VAR_OUTPUT
RETVAL : INT ;
END_VAR
VAR_TEMP
T_Src : ANY ;
T_Dest : ANY ;
Src_DB_Nr : WORD ;
Src_DW_Nr : DWORD ;
Dest_DB_Nr : WORD ;
T_AR1 : DWORD ;
T_AR2 : DWORD ;
T_SrcBlk : ANY ;
T_DstBlk : ANY ;
S_DB_Len : WORD ;
D_DB_Len : WORD ;
T_Bool : BOOL ;
T_Case1 : BOOL ;
T_Case2 : BOOL ;
END_VAR
BEGIN
NETWORK
TITLE =

TAR1 #T_AR1;
TAR2 #T_AR2;

// Check data type
L P##SRC_BLK; // Source field
LAR1 ;

L B [AR1,P#1.0]; // Data type
L B#16#19;
==I ;
= #T_Case1;

L P##DST_BLK; // Source field
LAR2 ;

L B [AR2,P#1.0]; // Data type
L B#16#19;
==I ;
= #T_Case2;

// Case1: Copy data blocks

A #T_Case1;
A #T_Case2;
JCN Jmp1;

L W [AR1,P#8.0]; // DB number
T #Src_DB_Nr;

L W [AR2,P#8.0]; // DB number
T #Dest_DB_Nr;

OPN DB [#Src_DB_Nr];
L DBLG;
T #S_DB_Len; // Length

OPN DB [#Dest_DB_Nr];
L DBLG;
T #D_DB_Len; // Lenght

LAR1 P##T_Src;

L W#16#1002; // Type
T LW [AR1,P#0.0];

L #S_DB_Len; // Length
T LW [AR1,P#2.0];

L #Src_DB_Nr; //DB number
T LW [AR1,P#4.0];

L DW#16#84000000; //DW number
T LD [AR1,P#6.0];

LAR2 P##T_Dest;

L W#16#1002; // Type
T LW [AR2,P#0.0];

L #D_DB_Len; // Length
T LW [AR2,P#2.0];

L #Dest_DB_Nr; // DB Number
T LW [AR2,P#4.0];

L DW#16#84000000; // DW Number
T LD [AR2,P#6.0];

JU Copy;

// Case2: Copy data block to data field

Jmp1: A #T_Case1;
AN #T_Case2;
JCN Jmp2;

L W [AR1,P#8.0]; // DB number
T #Src_DB_Nr;

OPN DB [#Src_DB_Nr];
L DBLG;
T #S_DB_Len; // Length

LAR1 P##T_Src;

L W#16#1002; // Type
T LW [AR1,P#0.0];

L #S_DB_Len; // Length
T LW [AR1,P#2.0];

L #Src_DB_Nr; // DB number
T LW [AR1,P#4.0];

L DW#16#84000000; // DW number
T LD [AR1,P#6.0];

L P##DST_BLK;
LAR1 ;
LAR2 P##T_Dest;

L W [AR1,P#0.0]; // Type
T LW [AR2,P#0.0];

L W [AR1,P#2.0]; // Length
T LW [AR2,P#2.0];

L W [AR1,P#4.0]; // DB Number
T LW [AR2,P#4.0];

L D [AR1,P#6.0]; // DW Number
T LD [AR2,P#6.0];

JU Copy;

// Case3: Copy data field to data block
Jmp2: AN #T_Case1;
A #T_Case2;
JCN Jmp3;

L W [AR2,P#8.0]; // DB number
T #Dest_DB_Nr;

OPN DB [#Dest_DB_Nr];
L DBLG;
T #D_DB_Len; // Lenght
L P##SRC_BLK;
LAR1 ;
LAR2 P##T_Src;

L W [AR1,P#0.0]; // Type
T LW [AR2,P#0.0];

L W [AR1,P#2.0]; // Length
T LW [AR2,P#2.0];

L W [AR1,P#4.0]; // DB Number
T LW [AR2,P#4.0];

L D [AR1,P#6.0]; // DW Number
T LD [AR2,P#6.0];

LAR2 P##T_Dest;

L W#16#1002; // Type
T LW [AR2,P#0.0];

L #D_DB_Len; // Length
T LW [AR2,P#2.0];

L #Dest_DB_Nr; // DB Number
T LW [AR2,P#4.0];

L DW#16#84000000; // DW Number
T LD [AR2,P#6.0];

JU Copy;

// Case4: Copy data fields

Jmp3: AN #T_Case1;
AN #T_Case2;
JCN Copy;

L P##SRC_BLK;
LAR1 ;
LAR2 P##T_Src;

L W [AR1,P#0.0]; // Type
T LW [AR2,P#0.0];

L W [AR1,P#2.0]; // Lenght
T LW [AR2,P#2.0];

L W [AR1,P#4.0]; // DB Number
T LW [AR2,P#4.0];

L D [AR1,P#6.0]; // DW Number
T LD [AR2,P#6.0];

L P##DST_BLK;
LAR1 ;
LAR2 P##T_Dest;

L W [AR1,P#0.0]; // Type
T LW [AR2,P#0.0];

L W [AR1,P#2.0]; // Lenght
T LW [AR2,P#2.0];

L W [AR1,P#4.0]; // DB Number
T LW [AR2,P#4.0];

L D [AR1,P#6.0]; // DW Number
T LD [AR2,P#6.0];

Copy: CALL "BLKMOV" (
SRCBLK := #T_Src,
RET_VAL := #RETVAL,
DSTBLK := #T_Dest);

LAR1 #T_AR1;
LAR2 #T_AR2;

END_FUNCTION
</pre>
 
Top