DB to DB in S7 (any pointer)

userxyz

Member
Join Date
May 2002
Location
any
Posts
2,768
Any Pointer, what a beast...

I wrote this:

L P##Bron
LAR1
L P##Doel
LAR2
L B#16#10
T LB [AR1,P#0.0]
T LB [AR2,P#0.0]
L B#16#2
T LB [AR1,P#1.0]
T LB [AR2,P#1.0]
L #Lengte_Bytes
T LW [AR1,P#2.0]
T LW [AR2,P#2.0]
L #BronDB
T LW [AR1,P#4.0]
L #DoelDB
T LW [AR2,P#4.0]
L #BronByte
SLD 3
L DW#16#84000000
OW
T LW [AR1,P#6.0]
L #DoelByte
SLD 3
L DW#16#84000000
OW
T LW [AR2,P#6.0]


CALL SFC 20
SRCBLK :=#Bron
RET_VAL:=#RET
DSTBLK :=#Doel



I entered DB30 As Bron (Source) and DB40 as Doel (destination DB).

But the DB30 data is not given to DB40 ??

ANy ideas why ?
 
Code:
L P##Bron
LAR1 
L P##Doel
LAR2 
L B#16#10
T LB [AR1,P#0.0]
T LB [AR2,P#0.0]
L B#16#2
T LB [AR1,P#1.0]
T LB [AR2,P#1.0]
L #Lengte_Bytes
T LW [AR1,P#2.0]
T LW [AR2,P#2.0]
L #BronDB
T LW [AR1,P#4.0]
L #DoelDB
T LW [AR2,P#4.0]
L #BronByte
SLD 3
[b]L P#DBX0.0 //suggested change[/b]
[b]+D //correction here [/b]
[b]T LD [AR1,P#6.0] //correction here[/b]
L #DoelByte
SLD 3
[b]L P#DBX0.0 //suggested change here[/b]
[b]+D //correction here [/b]
[b]T LD [AR2,P#6.0] //correction here[/b]
 
 
CALL SFC 20
SRCBLK :=#Bron
RET_VAL:=#RET
DSTBLK :=#Doel

I haven't run this code, so the corrections are just from eyeballing. Why not post the whole FC in source code - then we don't have to guess what the variable types are.
 
Last edited:
Hey

I had to send to DW, not LW, that's the good correction you gave, thanks:

source:

FUNCTION "DB TO DB" : VOID
TITLE =DB TO DB
VERSION : 0.1

VAR_INPUT
BronDB : INT ;
BronByte : INT ;
DoelDB : INT ;
DoelByte : INT ;
Lengte_Bytes : INT ;
END_VAR
VAR_OUTPUT
Fout : BOOL ;
END_VAR
VAR_TEMP
Bron : ANY ;
Doel : ANY ;
RET : INT ;
END_VAR
BEGIN
NETWORK
TITLE =Samenstelling Any Pointer

L P##Bron;
LAR1 ;
L P##Doel;
LAR2 ;
L B#16#10;
T LB [AR1,P#0.0];
T LB [AR2,P#0.0];
L B#16#2;
T LB [AR1,P#1.0];
T LB [AR2,P#1.0];
L #Lengte_Bytes;
T LW [AR1,P#2.0];
T LW [AR2,P#2.0];
L #BronDB;
T LW [AR1,P#4.0];
L #DoelDB;
T LW [AR2,P#4.0];
L #BronByte;
SLD 3;
L DW#16#84000000;
OW ;
T LD [AR1,P#6.0];
L #DoelByte;
SLD 3;
L DW#16#84000000;
OW ;
T LD [AR2,P#6.0];
NETWORK
TITLE =Transfereer Data van Bron naar Doel

CALL "BLKMOV" (
SRCBLK := #Bron,
RET_VAL := #RET,
DSTBLK := #Doel);
END_FUNCTION
 
The area pointer uses the bottom 19 bits for the byte/bit address. By using the OW instruction, you will only incorporate the bottom 16 bits of the byte pointer address and thus limit the start byte for your DB to DBB8191. If you try to access DBB8192 it will actually access DBB0.
 
..;

But DBB8191 as a startbyte ? isn't that a lot of bytes in a DB allready ?

But you're right, it's not 100% safe what I'm doing


L D[AR2 said:
The area pointer uses the bottom 19 bits for the byte/bit address. By using the OW instruction, you will only incorporate the bottom 16 bits of the byte pointer address and thus limit the start byte for your DB to DBB8191. If you try to access DBB8192 it will actually access DBB0.
 
[QUOTE='L D[AR2,P#0.0]By using the OW instruction, you will only incorporate the bottom 16 bits of the byte pointer address..[/QUOTE]

I think Simon was 'pointing' you towards a modification....

Code:
FUNCTION "DB TO DB" : VOID
TITLE =DB TO DB
VERSION : 0.1
 
VAR_INPUT
BronDB : INT ; 
BronByte : INT ; 
DoelDB : INT ; 
DoelByte : INT ; 
Lengte_Bytes : INT ; 
END_VAR
VAR_OUTPUT
Fout : BOOL ; 
END_VAR
VAR_TEMP
Bron : ANY ; 
Doel : ANY ; 
RET : INT ; 
END_VAR
BEGIN
NETWORK
TITLE =Samenstelling Any Pointer
 
L P##Bron; 
LAR1 ; 
L P##Doel; 
LAR2 ; 
L B#16#10; 
T LB [AR1,P#0.0]; 
T LB [AR2,P#0.0]; 
L B#16#2; 
T LB [AR1,P#1.0]; 
T LB [AR2,P#1.0]; 
L #Lengte_Bytes; 
T LW [AR1,P#2.0]; 
T LW [AR2,P#2.0]; 
L #BronDB; 
T LW [AR1,P#4.0]; 
L #DoelDB; 
T LW [AR2,P#4.0]; 
L #BronByte; 
SLD 3; 
[color=black]L DW#16#84000000; 
[color=red][b]OD[/b] [/color]; 
[b]T LD [AR1,P#6.0];[/b] 
L #DoelByte; 
SLD 3; 
L DW#16#84000000; 
[color=red][b]OD[/b][/color] ; 
[b]T LD [AR2,P#6.0];[/b] 
NETWORK
[/color]TITLE =Transfereer Data van Bron naar Doel
 
CALL "BLKMOV" (
SRCBLK := #Bron,
RET_VAL := #RET,
DSTBLK := #Doel);
END_FUNCTION
 
Last edited:
Combo, you should definitely be using a dint for the byte address. Otherwise, sooner or later you will be bitten by a dynamically generated pointer.

Also, another tip: I always "OR" the address with a variable in pointer format. It just makes it a little more clear for others that read your code in case they aren't familiar with the hex equivelents. For instance:


L LD[AR1,P#6.0]
L P#DIX0.0
OD
T LD[AR1,P#6.0]

That would be the same as ORing with a HEX 85000000. This works for any pointer type (P#M0.0, P#Q0.0, etc).

edit. Saw that Simon implied the same thing above.
 
Last edited:
..

So OD instead of OW
Okay

Thanks a lot


S7Guy said:
Combo, you should definitely be using a dint for the byte address. Otherwise, sooner or later you will be bitten by a dynamically generated pointer.

Also, another tip: I always "OR" the address with a variable in pointer format. It just makes it a little more clear for others that read your code in case they aren't familiar with the hex equivelents. For instance:


L LD[AR1,P#6.0]
L P#DIX0.0
OD
T LD[AR1,P#6.0]

That would be the same as ORing with a HEX 85000000. This works for any pointer type (P#M0.0, P#Q0.0, etc).

edit. Saw that Simon implied the same thing above.
 

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
534
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,617
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,349
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
I have a very strange issue and I cannot figure out why it is not working. I read input of type pointer and store it to local temp type any. I...
Replies
4
Views
1,932
Back
Top Bottom