Programming in SFC

Creating a POU in SFC

  1. Select an application in the device tree.

  2. Click Project ‣ Add Object ‣ POU .

    ⇒ The Add POU dialog opens.

  3. Specify a name and select the Sequential Function Chart (SFC) implementation language.

    Click Add.

    ⇒ CODESYS adds the POU to the device tree and opens it in the editor.

Adding a step-transition

  1. Select the transition after the initial step.

    ⇒ The transition is marked in red.

  2. Click SFC ‣ Insert Step-Transition After .

    ⇒ CODESYS inserts the Step0 step and the Trans0 transition.

  3. Select the Trans0 transition and click SFC ‣ Insert Step-Transition .

    ⇒ CODESYS inserts the Trans1 transition and the Step1 step before the Trans0 transition.

You can also drag the Step and Transition elements into the diagram from the Toolbox view.

See also

Adding an entry action

  1. Select the Step0 step.

  2. Click SFC ‣ Add Entry Action .

    ⇒ By default, you are prompted to select the duplication mode for the step actions. You decide whether the reference information about the existing step action objects is copied when the step is copied, or the objects are embedded. Embedding results in new step action objects being created when the step is copied. The duplication mode is defined in the Duplicate when copying step property. When this property is deactivated, the copied steps call the same actions as the current step.

    You can deactivate the prompt completely in the SFC properties.

    The display of embedded objects in the Devices and POUs views can be deactivated by means of a menu command.

  3. For this example, accept the Copy reference default setting and click OK to confirm.

    ⇒ The Add Entry Action dialog opens.

  4. Enter the name “Step0_entry” and select the Structured Text (ST) implementation language. Click Add.

    ⇒ CODESYS inserts the Step0_entry action below the POU in the device tree and opens the action in the editor.

    In the Step0_entry entry action, you program statements to be executed one time when the Step0 step becomes active.

  5. Close the editor of Step0_entry.

    ⇒ The Step0 step is now marked with an E in the lower left corner. Double-click this marker to open the editor.

    The entry action Step0_entry is now available in the properties of the step in Entry action. Other actions can also be selected there as needed.

  6. Select the Step0 step. Press Ctrl+V to copy the step.

    ⇒ The same entry actions inserted above are available In the inserted copy of the step. The new step then calls the same exact action.

See also

Adding an exit action

  1. Select the Step0 step.

  2. Click SFC ‣ Insert Exit Action .

    ⇒ By default, you are prompted to select the duplication mode for the step actions of the step. See above for adding an entry action. Then the Insert Exit Action dialog opens.

  3. Enter the name “Step0_exit” and select the Structured Text (ST) implementation language. Click Add.

    ⇒ CODESYS inserts the Step0_exit action below the POU in the device tree and opens the action in the editor.

    In the Step0_exit exit action, you program statements to be executed one time before the Step0 step becomes inactive.

  4. Close the editor of Step0_exit.

    ⇒ The Step0 step is now marked with an X in the lower right corner. Double-click this marker to open the editor.

You can define the exit action in the properties of the step in Exit action. Other actions can also be selected there.

See also

Adding an action

  1. Double-click the Step0 step.

    ⇒ By default, you are prompted to select the duplication mode for the step actions of the step. See above for adding an entry action. The Add Action dialog opens.

  2. Type in the name “Step0_active” and select the Structured Text (ST) implementation language. Click Add.

    ⇒ CODESYS inserts the Step0_active action below the POU in the device tree and opens the action in the editor.

    In the Step0_active step action, you program statements to be executed as long as the step is active.

  3. Close the editor of Step0_active.

    ⇒ The Step0 step is now marked with a black triangle in the upper right corner.

You can define the action in the properties of the step in Step action. Other actions can also be selected there.

See also

Adding an alternative branch

  1. Select the Step1 step.

  2. Click SFC ‣ Insert Branch Right .

    ⇒ CODESYS inserts the Step2 step to the right of Step1. The steps are connected as a parallel branch signified by two pairs of double lines.

  3. Select one of the double lines.

    ⇒ The double line is marked red.

  4. Click SFC ‣ Alternative

    ⇒ CODESYS converts the branch into an alternative branch. The double lines change into a single line.

You can click SFC ‣ Parallel to convert an alternative branch into a parallel branch.

See also

Adding a jump

  1. Select the Step2 step.

  2. Click SFC ‣ Insert Jump After .

    ⇒ CODESYS inserts the Step jump after the Step2 step.

  3. Select the Step jump destination.

    ⇒ You can type the jump destination manually or select it by using the Input Assistant|PNG72/_cds_icon_button_threedots.png0|. Select Step0.

See also

Adding a macro

  1. Select the Step1 step.

  2. Click SFC ‣ Insert Macro After .

    ⇒ CODESYS inserts the Macro0 macro after the Step1 step.

  3. Double-click the Macro0 element.

    ⇒ The macro opens in the implementation section of the editor. The name “Macro0” is displayed in the caption.

  4. Click SFC ‣ Insert Step-Transition .

    ⇒ CODESYS inserts a step-transition combination.

  5. Click SFC ‣ Zoom out of Macro .

    ⇒ The implementation section returns to the main diagram.

See also

Adding an association

  1. Select the Step2 step.

  2. Click SFC ‣ Insert Action Association .

    ⇒ CODESYS inserts an association to the right of the Step2 step.

  3. Click in the left field of the association to select the qualifier.

    ⇒ You can enter the qualifier manually or use the Input Assistant|PNG72/button_threedots.png.png|. Select “P”.

  4. Click in the right field of the association to select the action.

    ⇒ You can type the action or select it by using the Input Assistant .

See also

Using the library ‘analyzation.library’ for the analyzation of expressions

The library analyzation.library allows for the analyzation of expressions. It can be used, for example, in the SFC diagram to examine the result of the flag SFCError. This flag is used to monitor timeouts in the SFC diagram.

See also

See also