calling Function Block in another Function Block.

rahilansari

Member
Join Date
Jul 2008
Location
INDIA
Posts
103
Hello all experts:D

I made two function blocks FB332 and FB 333(please see attached archived program) using SCL source code. Now I want to call FB 332 in FB 333 and pass the parameters like" Available_pumps" and "Pump_Duties_Input" and "Ready_Pumps_to_Run". and then i will call FB 333 only in my rest Functions etc wherever I need it.
Could someone please tell me how to call a function block into another and pass the parameters. I read the manuals and followed but getting these errors;

1. Can not find / copy block FB332.
2. Function not defined.
3. Invalid or missing function type.

Please guide me, i have attached the archived program.

Thanks and best regards
rahil
 
You need to specify an instance DB. Parameter passing rules requires that the in_out from FB333 cannot be passed to FB332
Changed to stat to allow compilation.
Code:
FUNCTION_BLOCK FB333

VAR_INPUT
    Duty1_Requested:BOOL;
    Duty2_Requested:BOOL;
    Duty3_requested:BOOL;
    Duty4_Requested:BOOL;
    Duty5_Requested:BOOL;
    Duty6_Requested:BOOL;
    Number_Of_Pumps_To_Run:INT;
    Number_Of_Running_Pumps:INT;
END_VAR

VAR_OUTPUT
    start_P1:BOOL;
    start_p2:BOOL;
    start_p3:BOOL;
    start_p4:BOOL;
    start_p5:BOOL;
    start_p6:BOOL;
    stop_P1:BOOL;
    stop_p2:BOOL;
    stop_p3:BOOL;
    stop_p4:BOOL;
    stop_p5:BOOL;
    stop_p6:BOOL;
END_VAR

VAR
Running_pump:ARRAY[0..3] OF INT;
Available_Pumps:ARRAY[0..3] OF BOOL;
Pump_Duties_Input:ARRAY[0..3] OF INT;
Ready_Pumps_To_Run:ARRAY[0..3] OF INT;

END_VAR

Number_Of_Running_Pumps:= Running_pump[0] + Running_pump[1] + Running_pump[2] + Running_pump[3];

FB332.DB332(Available_Pumps := Available_Pumps // INOUT: ARRAY
       ,Pump_Duties_Input := Pump_Duties_Input // INOUT: ARRAY
              ); 
  Ready_Pumps_To_Run := DB332.Ready_Pumps_To_Run; // OUT: ARRAY
 

start_P1:=0;
start_p2:=0;
start_p3:=0;
start_p4:=0;
start_p5:=0;
start_p6:=0;
stop_P1:=1;
stop_p2:=1;
stop_p3:=1;
stop_p4:=1;
stop_p5:=1;
stop_p6:=1;



IF Duty1_Requested AND Number_Of_Pumps_To_Run>=1 THEN
CASE Ready_Pumps_To_Run[0] OF
    
        1:
         start_p1:=1;
         stop_p1:=0;
           
        2:
         start_p2:=1;
         stop_p2:=0;
        
        3:
         start_p3:=1;
         stop_p3:=0;
           
        4:
         start_p4:=1;
         stop_p4:=0;
           
END_CASE;
END_IF;

IF Duty2_Requested AND Number_Of_Pumps_To_Run>=2 THEN
CASE Ready_Pumps_To_Run[1] OF
    
        1:
         start_p1:=1;
         stop_p1:=0;
           
        2:
         start_p2:=1;
         stop_p2:=0;
        
        3:
         start_p3:=1;
         stop_p3:=0;
           
        4:
         start_p4:=1;
         stop_p4:=0;

END_CASE;
END_IF;

IF Duty3_Requested AND Number_Of_Pumps_To_Run>=3 THEN
CASE Ready_Pumps_To_Run[2] OF
    
        1:
         start_p1:=1;
         stop_p1:=0;
           
        2:
         start_p2:=1;
         stop_p2:=0;
        
        3:
         start_p3:=1;
         stop_p3:=0;
           
        4:
         start_p4:=1;
         stop_p4:=0;
 
END_CASE;
END_IF;

IF Duty4_Requested AND Number_Of_Pumps_To_Run>=4 THEN
CASE Ready_Pumps_To_Run[3] OF
    
        1:
         start_p1:=1;
         stop_p1:=0;
           
        2:
         start_p2:=1;
         stop_p2:=0;
        
        3:
         start_p3:=1;
         stop_p3:=0;
           
        4:
         start_p4:=1;
         stop_p4:=0;
           
END_CASE;
END_IF;

//  Stopping the duty pumps

IF NOT Duty4_Requested AND Number_Of_Running_Pumps=4 THEN
CASE Ready_Pumps_To_Run[3] OF
    
        1:
         start_p1:=0;
         stop_p1:=1;
           
        2:
         start_p2:=0;
         stop_p2:=1;
           
        3:
         start_p3:=0;
         stop_p3:=1;
           
        4:
         start_p4:=0;
         stop_p4:=1;
           
END_CASE;
END_IF;                  

IF NOT Duty3_Requested AND Number_Of_Running_Pumps=3 THEN
CASE Ready_Pumps_To_Run[2] OF
    
        1:
         start_p1:=0;
         stop_p1:=1;
           
        2:
         start_p2:=0;
         stop_p2:=1;
           
        3:
         start_p3:=0;
         stop_p3:=1;
           
        4:
         start_p4:=0;
         stop_p4:=1;
           
END_CASE;
END_IF;        

IF NOT Duty2_Requested AND Number_Of_Running_Pumps=2 THEN
CASE Ready_Pumps_To_Run[1] OF
    
        1:
         start_p1:=0;
         stop_p1:=1;
           
        2:
         start_p2:=0;
         stop_p2:=1;
           
        3:
         start_p3:=0;
         stop_p3:=1;
           
        4:
         start_p4:=0;
         stop_p4:=1;
           
END_CASE;
END_IF;

IF NOT Duty1_Requested AND Number_Of_Running_Pumps=1 THEN
CASE Ready_Pumps_To_Run[0] OF
    
        1:
         start_p1:=0;
         stop_p1:=1;
           
        2:
         start_p2:=0;
         stop_p2:=1;
           
        3:
         start_p3:=0;
         stop_p3:=1;
           
        4:
         start_p4:=0;
         stop_p4:=1;
           
END_CASE;
END_IF;

END_FUNCTION_BLOCK
 
Dear sir

I have completed my blocks and after i download PLC is running with "SF" led. when I checked diagnostic buffer I am getting "area length error" relating to FB332. can you please help me out of this, I can send you the archived program if you want.

thanks
RA
 
Area length error

Hi sir,

I am getting Area length error when I downloaded the attached program into PLC.
Could you help me out of this.

regards
RA
 
Dear Sir

i have loaded all my blocks and the diagnostic buffer is full with following errors.
1. Area length error when reading
2.Area length error when writing

please see attached program in my last post and help me out .

thanks
RA
 
I have no intention of loading and decoding your program.

You must look closely into the diagnostic buffer. There you will find where the error is located.

If you get too confused, post the diagnostic buffer contents here.

And if you remove the error OB's (OB>=80), the CPU will stop at the point of failure.


Kalle
 
Dear Kalle

i resolved the issue but in different way and achieved what I want. However the problem was calling the function block into another function block. I created the DB for the function block which I want to call. when I run the program it is giving

1. Area length error when reading
2.Area length error when writing

there is no error except this in the buffer and it is related to DB(instance) I created for the FB which is called.
 

Similar Topics

"Function block call requires a function instance" when calling action in Codesys Using Codesys 2.3, I'm getting the following error: "A...
Replies
9
Views
9,897
This is the first time I am working with Simatic Manager Step7 as I started my siemens journey with TIA which is pretty easy and do a lot of stuff...
Replies
3
Views
118
I am looking to get an AB series 1774 (PLC1) from the 1970's up and running. I have all the parts, and it powers up just fine without errors if I...
Replies
12
Views
2,316
Hello all, I’ve recently begun using Automation Studio on my own time to boost my knowledge of controllers beyond AB/Siemens. To ease myself into...
Replies
0
Views
896
Hello I'm new to PLC programming and I'm programing in ST. Programming envirement is GX works 3. I can't figure out how to jump to subprogram or...
Replies
1
Views
1,451
Back
Top Bottom