Writing user-defined FUs/FBs with EN/ENO - Best Practice
When writing user-defined POUs, observe the rules and recommendations listed below.
User-defined IEC 61131-3 function POUs
- The formal parameters EN and ENO are available by default. It is not necessary to declare them as input/output variables. The initial value for EN is TRUE. This value is used by default, if EN remains unconnected.
- The evaluation of EN and writing of ENO are implemented by default. No coding or explicit processing of these formal parameters is required inside the POU. This includes that the compiler sets ENO = FALSE if EN = FALSE.
- Define a default return value of the function. This value must be applied to the output if the function is not executed because EN = FALSE.
Normally this value should be the default value of the data type of the return value. The return value should also be set to the default value, if ENO is set to TRUE due to internal checks. (Arrays and Structs should not be reset to the default value due to performance reasons.) - Within the function code, it is possible to set ENO = FALSE on specific conditions.
User-defined C# function POUs
In addition to the above-mentioned points for IEC functions, the following applies to C# user functions:
- If access to ENO inside the C# user function is required, i.e., the C# function must be able to write the ENO output, ENO is handled as return value inside the function (the function result is returned as OUTPUT parameter).
- The EN/ENO feature is handled by the IEC compiler if internal handling of ENO is not required (no use of ENO inside the function). The function will not be called in case of EN = FALSE.
User-defined IEC 61131-3 function block POUs
- The formal parameters EN and ENO must be declared as follows in the FB prototype:
- Declare EN (with 'Usage = Input) as first and ENO ('Usage = Output') as second parameter in the local 'Variables' table. (Use capital letters for the variables names.) Both variables must be of the type BOOL.
- Implement the evaluation of EN. The FB must only be executed if EN = TRUE.
- Implement the writing of ENO in the FB code:
- Mandatory: Set ENO = FALSE if EN = FALSE.
- Optional: Set ENO = FALSE on specific conditions.
- Consider the default behavior of the other outputs than ENO. These values must be applied if the FB is not executed because EN = FALSE.
Normally the outputs should be set to the default value of its data type in case of ENO = FALSE. (Arrays and Structs should not be reset to the default value due to performance reasons.)
User-defined C# function blocks
Analog to the IEC FB, the C# FB must define the EN/ENO parameters (as first parameters, in capital letters).
Example for a C# function block with internal EN/ENO handling