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 of your project. |
- |
2 |
Create a new function block with name |
![]() |
3 |
Add the call of the base function block using the |
![]() |
4 |
Create a DUT (Data Unit Type) of type enumeration with name |
![]() |
5 |
Add the additional inputs and outputs to the function block |
![]() |
6 |
Add the methods Preparing, Executing, Done, Error, and Clean to the function block |
These methods are inherited from the base function block FB_Execute and are overridden by the ![]() |
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 |
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 |
![]() |