SCF20 in scl

BNA

Member
Join Date
Sep 2003
Location
Give
Posts
117
Hi'

Can anyone tell me why this works.

Code:
FUNCTION_BLOCK FB10
VAR_INPUT
    // Imput Variables
    Prg_No : INT;
    SRC : ANY;
    DST : ANY;
END_VAR
VAR_OUTPUT
    // Imput Variables
    SFCError : int;
END_VAR
    // Statement Section
    SFCError:=SFC20(SRCBLK:=db101,DSTBLK:=db100);
    ;
END_FUNCTION_BLOCK

And This don't

Code:
FUNCTION_BLOCK FB10
VAR_INPUT
// Imput Variables
Prg_No : INT;
SRC : ANY;
DST : ANY;
END_VAR
VAR_OUTPUT
// Imput Variables
SFCError : int;
END_VAR
// Statement Section
SFCError:=SFC20(SRCBLK:=SRC,DSTBLK:=DST);
;
END_FUNCTION_BLOCK

Thanks, Brian
 
As you have not shown how you are calling the block, here's my guess.

In the first example, your are relying on a feature of the SCL compiler to automatically determine the length of DB100 and DB101 to generate the correct ANY pointers to pass to SFC20.

In the second example, I assume you are calling the FB and passing DB100 and DB101 as the ANY pointer parameters - this will generate the data type BLOCK_DB (19) and this make no sense to pass on to SFC20

For example, if DB100 & DB101 have been created as an array of integers named aiData then the correct syntax for passing the ANY pointer would be DB100.aiData and DB101.aiData

If the DBs are a mix of data types and you want to copy the whole DB, you will have to build the ANY pointer dynamically before calling the FB
 
Thanks, You are right... I changed the input on my block to P#DB101.DBX0.0 BYTE 30 and the it works.

The only problem is that it ruins my plan at bit :unsure:

I was hoping that i could change my source according to the INT from Prg_No, is it possible to build an anypointer that changes ?

Regards Brian
 
UPDATE :

I solved the problem, found an example on the Siemens website, changed a few parameters and now it works.

The Solution was to define my pointer with the AT command and change the source DB by a variable, and this looks as follows :

Code:
DATA_BLOCK DB100  //Define data block DB100
STRUCT                 
    data: ARRAY[1..50] OF TIME;
END_STRUCT
BEGIN
END_DATA_BLOCK
DATA_BLOCK db101  //Define data block DB101
STRUCT                 
    data: ARRAY[1..50] OF TIME;
END_STRUCT
BEGIN
END_DATA_BLOCK
DATA_BLOCK db102  //Define data block DB102
STRUCT                 
    data: ARRAY[1..50] OF TIME;
END_STRUCT
BEGIN
END_DATA_BLOCK
 
FUNCTION FC10: VOID
VAR_INPUT
Prg : INT;
END_VAR    
VAR
    Source: STRUCT  //Define ANY structure 1          
        ANY_id: BYTE;  
        Source_DataType: BYTE;
        Source_Lenght: WORD;
        Source_DB_Nummer: INT;
        Source_Byte_Pointer: DWORD;
        END_STRUCT;
    Destination: STRUCT  //Define ANY structure 2
        ANY_id: BYTE;  
        Destin_DataType: BYTE;
        Destin_Lenght: WORD;
        Destin_DB_Nummer: INT;
        Destin_Byte_Pointer: DWORD;
        END_STRUCT;
    //Declaring ANY pointer of source DB
    pAny_source AT Source: ANY;  
   //Declaring ANY pointer of target DB
    pAny_destin AT Destination: ANY;  
    erg: INT;  //Return value
END_VAR
Source.ANY_id:= 16#10;  
Source.Source_DataType:= 16#0B;  //Assign values for source pointer
Source.Source_Lenght:= 16#0a;
Source.Source_DB_Nummer:= Prg;
Source.Source_Byte_Pointer:= dw#16#84000000;
Destination.ANY_id:= 16#10;  
Destination.Destin_DataType:= 16#0B;  //Assign values for destination pointer
Destination.Destin_Lenght:= 16#0a;
Destination.Destin_DB_Nummer:= 100;
Destination.Destin_Byte_Pointer:= dw#16#84000000;
//Calling SFC20 and programming of ANY pointer variables
erg:= SFC20(srcblk:= pAny_source, dstblk:= pAny_destin);
END_FUNCTION
// Datatypes for Any Pointer
// 16#01=BOOL, 16#02=BYTE, 16#03=CHAR, 16#04=WORD, 16#05=INT, 16#06=DWORD, 16#07=DINT, 16#08=REAL, 16#09=DATE, 16#0A=TOD, 16#0B=TIME, 16#0C=S5TIME, 16#0E=DT, 16#13=STRING

Regards, Brian
 

Similar Topics

HI i would like to know how to get a variable that will store the amount of times a program has been executed. The issue is I have 3 DBs for 1 FB...
Replies
2
Views
63
Hi, I have an intermediate-advance knowledge of programming with TIA Porta in Ladder, would you recommend me to start learning SCL for it to...
Replies
11
Views
551
Hello nice to meet you, im new in here, I'm currently trying to convert code written in STL for a S7-400 to SCL for an S7-1500, because when i run...
Replies
5
Views
314
Hi everyone, I am new to this amazing world of PLC, well... I mean, in practice, since I already knew electronics, programming languages, IT, and...
Replies
7
Views
650
Hi all, This is my first post; I am new to PLC Controls stuff and English is not my native language, so I apologize in advance if something is...
Replies
4
Views
510
Back
Top Bottom