Skip to main content

Implicit Variables

Every SFC object supplies implicit variables for you to monitor the status of steps and IEC actions at runtime. These implicit variables are automatically declared for each step and each IEC action.

The implicit variables are structure instances of the type SFCStepType for steps and type SFCActionType for actions. The variables have the same names as their elements, for example "step1" variable name for "step1" step name. The structure members describe the status of a step or action or the currently elapsed time in an active step.

Tip

In the SFC Element Properties, you can define whether or not CODESYS should export a symbol definition for this flag to the symbol configuration.

Step and action status

Important

You can use the variables above to force a specific status value for a step in order to activate a step. However, note that this can cause an unstable status in the SFC.

Syntax for the implicit variable declaration:

<step name>:SFCStepType;

_<action name>:SFCActionType;

Table 2. The following implicit variables are available for step or IEC action status:

Step

<step name>.x

Shows the activation status in the current cycle

If <step name>.x = TRUE, then the step is processed in the current cycle.

<step name>._x

Shows the activation status for the next cycle

If <step name>.x = TRUE and <step name>._x = FALSE, then the step is processed in the current cycle. This means that the <step name>._x variable is copied at the beginning of a cycle in <step name>.x.

<step name>.t

The flag t yields the current time span since the step was activated. This applies only to steps, regardless of whether a minimum time has been defined or not in the step properties.

For more information, see: SFC flags

<step name>._t

For internal use only

<POU name>._MetaStep

Entry point for obtaining information about the ISFC elements in the linked list when the "MetaStep" feature is activated (see below).

IEC action

_<action name>.x

TRUE when the action is being executed

_<action name>._x

TRUE when the action is active



Linked list of elements in the SFC chart, implicit variable _MetaStep

Important

The "MetaStep" feature generates a lot of additional implicit code to allow for the linking of elements. Enable it only if it is really needed.

The implicit variable _MetaStep identifies the element belonging to the initial step (Init Step) of an SFC chart. When the "MetaStep" feature is enabled, additional implicit variables are created which represent a linked list for the elements in an SFC chart. As of the initial step, all transitions, steps, and jumps are linked by references to other ISFCElement objects (from the IecSfc.library, >= V4.4.0.0). An ISFCElement always has a predecessor, successor, a name, and the number of elements in the linking according to the interface. Depending on the type of ISFCElement object, a more specific sub-interface with additional attributes may be implemented.

The variable <POU name>._MetaStep is used as the entry point. The IQueryInterface function can be used to determine information about the predecessor and successor elements in the linked list of ISFC elements.

Restrictions: In the current version of the feature, the names of transitions within an SFC program must be unique. Otherwise, a warning is issued and the additional data in the linked list is not generated.

To enable the MetaStep functionality, you need to perform the following steps:

  1. In the Project Information dialog, on the Properties tab, set the UseMetaStepsEnabled (BOOL) property to True.

  2. In the Properties dialog of the object, on the SFC Settings tab, enable the use of the SFCMetaSteps variable for each SFC object which requires the functionality.

Access to implicit variables

Syntax for access

Within the POU, you assign the implicit variable directly:

<variable name>:=<step name>.<implicit variable> or <variable name>:=_<action name>.<implicit variable>

Example 6. Example

status:=step1._x;



From another POU with the name:  

  • <variable name>:=<POU name>.<step name>.<implicit variable>

  • <variable name>:=<POU name>._<action name><implicit variable>

Example 7. Example:

status:=SFC_prog.step1._x;



Symbol generation

In the element properties of a step or action, you define whether CODESYS should add a symbol definition for the step or action flag. In the Properties view, you need to select the necessary access rights in the Symbol column.