Join us today!

FB_init with derive...
 
Notifications
Clear all

FB_init with derived function blocks

2 Posts
2 Users
3 Likes
261 Views
twinControls
Posts: 114
Admin
Topic starter
(@twincontrols)
Member
Joined: 2 years ago

If you are using FB_Init method for a function block and implementing inheritance, FB_Init of the child function blocks must have the same parameters as the parent of FB_Init. Otherwise, you would get the error below: 

doesntmatchdeclaration

 

We will create 3 function blocks in this tutorial. The first function block will be FB_Base which will be requiring the initialization of sPath in its FB_init method. We will then add FB_Motion function block which will derive from FB_Base. In the FB_init of FB_Motion, we will need to initialize the fSpeed. Lastly, we will create FB_Motion_Extended which will derive FB_Motion and we will add an input called 'fTemperature 'its FB_init.  

Inheritance
Inheritancefb

FB init of FB_Base: 

METHOD FB_init : BOOL
VAR_INPUT
	bInitRetains : BOOL; // if TRUE, the retain variables are initialized (warm start / cold start)
	bInCopyCode : BOOL;  // if TRUE, the instance afterwards gets moved into the copy code (online change)
	sPath : STRING;
END_VAR
_sPath := sPath;

 

FB init of FB_Motion: 

METHOD FB_init : BOOL
VAR_INPUT
	bInitRetains : BOOL; // if TRUE, the retain variables are initialized (warm start / cold start)
	bInCopyCode : BOOL;  // if TRUE, the instance afterwards gets moved into the copy code (online change)
	sPath : STRING;
	fSpeed : REAL;
END_VAR
_fSpeed := fSpeed;

With the addition of fSpeed, we have overwritten the parent's FB_Init method. If sPath is not included here, you would get the error mentioned above. The order of the parameters have to match the order in the FB_Init of parent function block. If you declare the sPath after fSpeed, you would get the same error again. 

 

FB_Init of FB_Motion_Extended: 

METHOD FB_init : BOOL
VAR_INPUT
	bInitRetains : BOOL; // if TRUE, the retain variables are initialized (warm start / cold start)
	bInCopyCode : BOOL;  // if TRUE, the instance afterwards gets moved into the copy code (online change)
	sPath : STRING;
	fSpeed : REAL;
	fTemperature : REAL;
END_VAR
_fTemperature := fTemperature;

Again, notice that we are following the same parameter order. 

 

When declaring these function blocks, you would have to initialize all the required parameters. FB_init method of the parent function blocks will be called implicitly. 

fbBase : FB_Base(sPath:='path_base');
fbMotion : FB_Motion(sPath:= 'path_motion',fSpeed := 25);
fbMotionExt : FB_Motion_Extended(sPath:='path from extended motion',fSpeed:= 15,fTemperature:= 36);

 

When you go online and try to monitor the FB_Base function block, if you choose the fbMotionExt option, you would see that sPath has been initialized with 'path from extended motion' value. 

fbBase

 

 

spath

 

Reply
1 Reply
1 Reply
runtimevictor
(@runtimevictor)
Joined: 2 years ago

Estimable Member
Posts: 156

@twincontrols ,

Hello, here is very well explained and detailed FB_init:

https://stefanhenneken.net/2019/07/26/iec-61131-3-parameter-transfer-via-fb_init/

Reply
Share: