Sfc20

Thim

Member
Join Date
Mar 2008
Location
Belgium
Posts
392
Hello,

Does someone know out of experience if you can use SFC20 to move different types of DataTypes.

Lets say i have a DB with mix of INT's and Real's i want to copy this DB to another DB. Can that be done in one function or should i move them seperated?

If this can be done in one go, is it wrong to do it? and what is the best way to specify the datatype from the Source anypointer and destination anypointer?


Thx
 
Use a structure definition to collate them into a named area, or use a UDT

A structure or UDT will be copied as an area of bytes when using SFC20
 
This DB is a UDT with some array's of values Reals and Ints.
So are you saying i can take one complete Array out of there if i know the start adress?

Never done it before so i check the manual but can't find the Hex code to specify the complex data type Array or Struct, or do i need to change the construction of the any pointer?

Thx
 
Why don't you post a cut down version of the project which shows the DB's in question and which areas you are trying to copy ?
 
Hi,

At this moment i do it with load and transfers.
But since someone told me it would be best to do the job with SFC20 i was looking in to do it with SFC20.

Notice that MW0 must be higher then 0 and lower then 100

Did a quick test with the code normally no errors if so i'm sorry

If for any purpose i need to change the UDT of DestinationDB "array 20 to 21" that is no problem
 
Hi,
I'll post two solutions: one fixed and straightforward, one with parameters.

Simple:

CALL SFC 20
SRCBLK :=P#DB1.DBX0.0 BYTE 60
RET_VAL:=MW10
DSTBLK :=P#DB3.DBX12.0 BYTE 60

With parameters:

LAR1 P##Origin
L B#16#10 //CODE FOR S7
T LB [AR1,P#0.0]
L B#16#2
T LB [AR1,P#1.0] //DATA TYPE BYTE
L 10 //NUMBER OF BYTES TO TRANSFER
T LW [AR1,P#2.0]
L 1 //DATA BLOCK NUMBER
T LW [AR1,P#4.0]
L W#16#8400 //DB AREA CODE
T LW [AR1,P#6.0]
L 12 //DBB NUMBER (BYTE NUMBER)
SLW 3
T LW [AR1,P#8.0]
LAR2 P##Destination
L B#16#10 //CODE FOR S7
T LB [AR2,P#0.0]
L B#16#2
T LB [AR2,P#1.0] //DATA TYPE BYTE
L 10 //NUMBER OF BYTES TO TRANSFER
T LW [AR2,P#2.0]
L 3 //DATA BLOCK NUMBER
T LW [AR2,P#4.0]
L W#16#8400 //DB AREA CODE
T LW [AR2,P#6.0]
L 24 //DBB NUMBER (BYTE NUMBER)
SLW 3
T LW [AR2,P#8.0]

CALL SFC 20
SRCBLK :=#Origin
RET_VAL:=#DIAG
DSTBLK :=#Destination


Origin and Destination are temporal parameters of the type any for the FC or FB.

I hope it helps.
 
Hi,
I'll post two solutions: one fixed and straightforward, one with parameters.

Simple:

CALL SFC 20
SRCBLK :=P#DB1.DBX0.0 BYTE 60
RET_VAL:=MW10
DSTBLK :=P#DB3.DBX12.0 BYTE 60

With parameters:

LAR1 P##Origin
L B#16#10 //CODE FOR S7
T LB [AR1,P#0.0]
L B#16#2
T LB [AR1,P#1.0] //DATA TYPE BYTE
L 10 //NUMBER OF BYTES TO TRANSFER
T LW [AR1,P#2.0]
L 1 //DATA BLOCK NUMBER
T LW [AR1,P#4.0]
L W#16#8400 //DB AREA CODE
T LW [AR1,P#6.0]
L 12 //DBB NUMBER (BYTE NUMBER)
SLW 3
T LW [AR1,P#8.0]
LAR2 P##Destination
L B#16#10 //CODE FOR S7
T LB [AR2,P#0.0]
L B#16#2
T LB [AR2,P#1.0] //DATA TYPE BYTE
L 10 //NUMBER OF BYTES TO TRANSFER
T LW [AR2,P#2.0]
L 3 //DATA BLOCK NUMBER
T LW [AR2,P#4.0]
L W#16#8400 //DB AREA CODE
T LW [AR2,P#6.0]
L 24 //DBB NUMBER (BYTE NUMBER)
SLW 3
T LW [AR2,P#8.0]

CALL SFC 20
SRCBLK :=#Origin
RET_VAL:=#DIAG
DSTBLK :=#Destination


Origin and Destination are temporal parameters of the type any for the FC or FB.

I hope it helps.


Thx so the anwser is Datatype "Byte".

Small remark
Maybe little arrogant after your nice explaination, but for other readers, Shouldn't you normally need to save/load the original area back to AR2 before/after loading L 10.0 in it?
Offcourse this is just an example

Greetings
 
Thx so the anwser is Datatype "Byte".

Small remark
Maybe little arrogant after your nice explaination, but for other readers, Shouldn't you normally need to save/load the original area back to AR2 before/after loading L 10.0 in it?
Offcourse this is just an example

Greetings

You're right, it should be done for AR1 and AR2. But the main objective of the example was explaining how to use the SFC20.

Regards
 
If you call an FC from an FB, the editor automatically inserts code "behind the scenes" to save AR2 prior to the call to the FC, and restore AR2 after the call. You are thus free to use AR1 and AR2 as you wish inside FC's. Here's the code the editor generates for a simple call to an FC:

bert00a.JPG
 
Is this the same for FB ?
Allways good to learn new stuff

Maybe stupid question is this the same when you do the call in STL??

thx
 
Is this the same for FB ?

AR2 is used to point to the instance data for FB's - you should only modify AR2 inside an FB if you save it first, perform your processing without referencing any interface variables, then restore it.
 

Similar Topics

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,951
Hello everyone! I'm moving string value from DB to Q area for displaying it at WinCC. I see some value is presented in DB in Variable Table...
Replies
16
Views
5,677
Hello all, IN S7-300 Does anyone know if its possible to address sfc20 source and destination with variable addresses? ie Indirect addresses...
Replies
10
Views
2,995
In one network SFC20(BLkMOV) is used to transfer 8 byte data from P#DB500.DBX8.0(SRC BLK) to P#DB20.DBX4.0(DST BLK). I would like to change...
Replies
2
Views
4,299
Hi all, i have learned siemens sample code by using sfc 20 for data move. but i don't know how i can adapt this sample code if i would like to...
Replies
0
Views
2,009
Back
Top Bottom