External Variables - VAR_EXTERNAL

External variables are global variables that are "imported" into a function block.

You can declare the variables between the keywords VAR_EXTERNAL and END_VAR. If the global variable does not exist, an error message is issued.

External Variables - VAR_EXTERNAL 1:

In TwinCAT 3 PLC it is not necessary for variables to be declared as external to use them in a POU. The keyword exists in order to maintain compatibility with IEC 61131-3.

Syntax:

<POU keyword> <POU name>
VAR_EXTERNAL
    <variable name> : <data type>;
END_VAR

Initialization is not allowed.

External Variables - VAR_EXTERNAL 2:

Make sure that you address the allocated variables (with AT %I or AT %Q) only in the global variable list. Additional addressing of the local variables instances would result in duplications in the process image.

Sample:

FUNCTION_BLOCK FB_Sample
VAR_EXTERNAL
    nVarExt1 : INT;     // 1st external variable
END_VAR

See also: