Static Variables - VAR_STAT

This functionality is an extension with regard to the IEC 61131-3 standard.

You declare static variables locally between the keywords VAR_STAT and END_VAR. TwinCAT initializes the static variables when the respective function block is first called.

You can access static variables only within the namespace where the variables are declared (as is the case with static variables in C). However, static variables retain their value when the application exits the function block. You can use static variables, as counters for function calls, for example.

You can extend static variables with an attribute keyword.

Static variables only exist once. This also applies to static variables of a function block or a function block method, even if the function block is instantiated multiple times.

Example:

VAR_STAT
    nVarStat1 : INT;
END_VAR

See also: