Extending a Base Function Block

You can reuse the behavior models in conjunction with the corresponding common inputs and outputs in your user-defined function blocks by extending the desired base function block.

For further information, refer to Extension of a Function Block.

In the following, an example implementation is provided to illustrate the procedure for implementing a function block which extends the FB_Execute from the CommonPouTypes library.

The task of the function block is to execute a division. Before the division is performed, it is verified if the divisor is unequal to 0. If this is the case, the division is performed, otherwise the function block indicates an error.

Step

Action

Description

1

Add the library CommonPouTypes to the Library Manager of your project.

-

2

Create a new function block with name FB_Div in your project. This function block extends the FB_Execute from the CommonPouTypes library.

3

Add the call of the base function block using the SUPER pointer to the implementation part of FB_Div.

4

Create a DUT (Data Unit Type) of type enumeration with name ET_Result in your project and define the members: Ok, Ready, InProgress, and InputInvalid.

5

Add the additional inputs and outputs to the function block FB_Div.

6

Add the methods Preparing, Executing, Done, Error, and Clean to the function block FB_Div. For adding a method, right-click the function block in the Applications tree and execute the command Add object. In the dialog box, select the method of the extended function block from the drop-down menu.

These methods are inherited from the base function block FB_Execute and are overridden by the FB_Div.

7

Implement the method Preparing. In this example, the divisor is verified to be unequal to 0 and the input values are copied to local variables. The outputs for the diagnostic are also updated.

Upon a rising edge, the method Preparing is executed by the state machine from the base function block. The output q_xBusy is set to TRUE.

8

Implement the method Error. In this example, the output q_rQuotient is set to 0.0.

When another method returns the result Error, the state machine from the base function block executes the method Error. The output q_xError is set to TRUE and q_xBusy is set to FALSE.

9

Implement the method Executing. In this example, the division is performed and the outputs are updated.

10

Implement the method Done. In this example, the outputs are updated.

When the method Executing returns the result Done, the method Done is executed once by the state machine from the base function block. The output q_xDone is set to TRUE and q_xBusy is set to FALSE.

11

Implement the method Clean. In this example, the outputs are updated.

If the input i_xExecute is FALSE and the state is Done or Error, the method Clean is executed once by the state machine from the base function block. The output q_xDone or q_xError is set to FALSE.

12

Implement the function block FB_Div in your application and test it.