Skip to main content

Attribute: hide

Important

Using the pragma {attribute 'hide'} to hide variables and POUs does not have the desired effect in most cases. Instead, you should use the {attribute 'conditionalshow'}. pragma.

The pragma prevents the variables and POUs defined with it from being shown in the CODESYS user interface. As a result, you can intentionally hide these identifiers without restricting the access. This can be useful when you develop libraries.

. Affects features:
  • Library management

  • Debugging

  • Input Assistant

  • "List components" Feature

  • Monitoring

  • Symbol Configuration

The variables or POUs defined with the pragma are neither visible in the Library Manager nor are they suggested in the Input Assistant or in the "List components" function. The pragma prevents those decorated variables from being displayed in the symbol configuration. As a result, you cannot export these kinds of variables as symbols. The variables are also invisible in online mode, and therefore their values cannot be monitored. Moreover, you cannot use any debugging functionalities and you do not have any support when checking for bugs.

If you, the application developer, know the exact instance path of the hidden POUs and variables, then you can access them in the code.

Syntax:

{attribute 'hide'}

Insert location: For variables, above the line with the declaration of the variables. For POUs, in the first line.

Example 268. Hidden variable

The function block FB_MyA contains the attribute pragma {attribute 'hide'} to hide the local variable xInvisibleIn.

FUNCTION_BLOCK FB_MyA
VAR_INPUT
    iInA : INT;
    {attribute 'hide'}
    xInvisibleIn : BOOL;
    xInit: BOOL;
END_VAR
VAR_OUTPUT
    iOutA : INT;
END_VAR
VAR
    iCounter : INT;
END_VAR

Two instances of the function block FB_MyA are defined in the main program.

PROGRAM PLC_PRG
VAR
    fbMyA1, fbMyA2 : FB_MyA;
    xVar2 : BOOL;
    iVar1 : INT;
    iVar2 : INT;
END_VAR
fbMyA1(iInA := 1, xInit := TRUE, xInvisibleIn := TRUE, iOutA => iVar1);
fbMyA2(iInA := 1, xInit := TRUE, iOutA => iVar2);

While an input value for fbMyA1 is now implemented, the 'List components' function, which opens when typing fbMyA1. (in the implementation part of PLC_PRG), displays the variables iInA, xInit, and iOutA, but not the hidden variable xInvisibleIn.



Example 269. Hidden library POU

FB_A is a function block of the library HiddenFunctionality with the default namespace HIDDEN. To hide the identifier and the POU code from application developers, begin the declaration of the POU with the attribute pragma {attribute 'hide'}. To hide the subordinate POUs (actions, methods, properties, and transitions) in the same way, also begin their declarations with {attribute 'hide'}.

{attribute 'hide'}
FUNCTION_BLOCK FB_A
VAR_INPUT
END_VAR
VAR_OUTPUT
END_VAR
VAR
    iA : INT;
    iCount : INT;
    iInvisible : INT;
END_VAR

{attribute 'hide'}
METHOD METH_Count : INT
VAR_INPUT
END_VAR
iCount := iCount + 1;

{attribute 'hide'}
METHOD METH_Invisible : BOOL
VAR_INPUT
END_VAR
iInvisible := iInvisible + 1;

{attribute 'hide'}
PROPERTY PUBLIC prop_iA : INT

For you as the application developer, all POUs are invisible. You can use them only if you know the instance path.

PROGRAM PLC_PRG
VAR
        fbHidden : HIDDEN.FB_A; // Hidden function block from library HiddenFunctionality
        iCounter : INT;
END_VAR
fbHidden.METH_Invisible();
iCounter := fbHidden.iInvisible;

In online mode, no monitoring is performed.

_cds_img_hidden_pous.png


Tip

With the {attribute 'hide_all_locals'} pragma, you can hide all local variables of a POU.