Attribute 'no_explicit_call'

Add the pragma to a POU to prevent any direct call of this POU.

This is relevant, for example, for object-oriented function blocks, which can be controlled exclusively via methods (method function blocks) and properties (property function blocks). In this case, calls of the FB body would have no function or would not be allowed. If the body of a function block, which is declared with the attribute 'no_explicit_call', is nevertheless called directly, the compiler issues a compile error to indicate the incorrect use of the function block.

Syntax: {attribute 'no_explicit_call' := '<text value>'}

Insertion location: First line in the declaration part of a function block.

Example:

In the following example a function block is declared, whose FB body can be called directly ("FB_DirectCallAllowed"). A further function block is declared, whose FB body may not be called directly (FB_DirectCallNotAllowed). This function block is therefore declared with the attribute 'no_explicit_call'; the comment text: 'do not call this POU directly' is added to the attribute. In addition, an exemplary method is added to both function blocks.

Each of the two function blocks is instantiated once and called directly. The example methods are also called for the FB instances.

During compilation of this program, a compilation error is generated if the instance fbDirectCallNotAllowed is called directly (in this case: "do not call this POU directly"). The compiler does not block the three other calls.

Function block FB_DirectCallAllowed:

FUNCTION_BLOCK FB_DirectCallAllowed
VAR
END_VAR
 
METHOD SampleMethod
VAR_INPUT
END_VAR

Function block FB_DirectCallNotAllowed:

{attribute 'no_explicit_call' := 'do not call this POU directly'} 
FUNCTION_BLOCK FB_DirectCallNotAllowed
VAR
END_VAR
METHOD SampleMethod
VAR_INPUT
END_VAR

Program MAIN:

PROGRAM MAIN
VAR
    fbDirectCallAllowed     : FB_DirectCallAllowed;
    fbDirectCallNotAllowed  : FB_DirectCallNotAllowed;
END_VAR
fbDirectCallAllowed();                  // => OK
fbDirectCallAllowed.SampleMethod();     // => OK
 
fbDirectCallNotAllowed();               // => NOK: generates compile error “do not call this POU directly”
fbDirectCallNotAllowed.SampleMethod();  // => OK