Object Transition

Symbol: Object Transition 1:

A transition is used to specify a condition, under which a subsequent step is to become active. A transition condition can have the value TRUE or FALSE. If it is TRUE, the next step is executed. A transition condition can be specified in the following two ways:

Follow the instructions in section “Access to VAR_IN_OUT variables of the function block”.

Creating an object Transition

1. Select a function block or a program in the Solution Explorer in the PLC project tree.
2. In the context menu select the command Add > Transition…
The Add Transition dialog opens.
3. Enter a name and select an implementation language.
4. Click on Open.
The object is added to the PLC project tree and opens in the editor.

Dialog Add Transition

Name

Name of the transition

Implementation language

Check box for the implementation language

Calling a transition

Syntax:

In contrast to TwinCAT 2 PLC Control, transition condition is treated like a method call. The input is based on the following syntax:

<transition name> := <transition condition>

or

<transition condition>

If a transition contains multiple statements, you must assign the desired expression to the transition variable (first variant of the syntax).

Samples:

Call of transition Trans1 in an ST POU:

PRG_SFC.Trans1:

Trans1 := (nCount<=100);

PRG_SFC:

nCount := nCount+1;
IF Trans1 = TRUE THEN // IF nCount<=100 THEN …
    nVar:=1;
    ELSE
        nVar:=2;
END_IF

Call of transition Trans1 in an SFC POU:

Object Transition 2:

Access to VAR_IN_OUT variables of the function block in a method/transition/property

In principle, the VAR_IN_OUT variables of a function block can be accessed in a method, transition or property of the function block. Note the following for this type of access:

Therefore, the following warning with ID C0371 is issued if the VAR_IN_OUT variables of the FB are accessed in a method, transition or property:

„Warning: Access to VAR_IN_OUT <Var> declared in <POU> from external context <Method/Transition/Property>”

An adequate response to this warning could be to check the VAR_IN_OUT variables within the method/transition/property before it is accessed. The operator __ISVALIDREF can be used for this check, to ascertain whether a reference refers to a valid value. If this check is enabled, it can be assumed that the user is aware of the risk that potentially exists when the VAR_IN_OUT variables of the FB are accessed in a method/transition/property. Checking the reference is regarded as adequate handling of this risk. The corresponding warning can therefore be suppressed via attribute 'warning disable'.

A sample implementation of a method is shown below.

Function block FB_Sample:

FUNCTION_BLOCK FB_Sample
VAR_IN_OUT
    bInOut : BOOL;
END_Var

Methode FB_Sample.MyMethod:

METHOD MyMethod
VAR_INPUT
END_VAR
// The warning can be disabled here as the user is aware of the risk that the reference may not be valid by checking its validity
{warning disable C0371}

// Checking the VAR_IN_OUT reference, leave the current method in case of invalid reference
IF NOT __ISVALIDREF(bInOut) THEN
     RETURN;
END_IF

// Access to VAR_IN_OUT reference (only if the reference was confirmed as valid before)
bInOut := NOT bInOut;

// The warning may be restored at the end of the access area
{warning restore C0371}

See also: