Forcing and Writing Variables

In CODESYS, variable values in the PLC can be changed in online mode. Here we make a distinction between forcing and writing.

When forcing, CODESYS writes the value in each cycle to hold the variable permanently at the forced value.

Hint

Please note that forced values must be lifted explicitly by the user. A dialog will appear if forced variables still exist when logging out.

When writing, CODESYS sets the value one time. Therefore, the value can be overwritten by the program at any time.

Forcing in the declaration part

Requirement: Your application includes a POU with declarations. The application is in online mode.

  1. Open the POU in the editor by choosing the command Project ‣ Edit Object .

  2. In the declaration part of the editor, double-click in column (1) Prepared value of a variable.

    ⇒ The field can be edited and a value can be entered.

  3. Perform step 2 for other variables.

  4. Click Debug ‣ Force values .

    ⇒ The variable values are overwritten with the prepared values. The values are marked with the symbol .

Note

You can also force the variable values in the view Watch.

Forcing in the implementation part

Requirement: The application is in online mode.

  1. Open the POU in the editor by choosing the command Project ‣ Edit Object .

  2. In the implementation part of the editor, double-click an inline monitoring field (1).

    ⇒ The dialog Prepare Value opens.

  3. Enter the new value in the field Prepare a new value for the next write or force operation.

    ⇒ The prepared value appears in the inline monitoring field.

  4. Click Debug ‣ Force values .

    ⇒ The value of the variables is overwritten with the prepared values. The values are marked with the symbol .

View and edit all forced variables 1 list

Requirement: The application is in online mode. Several variables are forced.

  1. Click View ‣ Watch ‣ Show all forces .

    ⇒ The Show all forces view opens. It contains all currently forced variables of the application in the form of a watch list.

  2. Select all lines in the list and click Unforce ‣ Unforce and keep all selected values in the drop-down list in the upper left part of the view.

    ⇒ The variables are unforced and they get the values that they had before forcing.

Forcing a function block input in CFC

Requirement: An application has a CFC POU that contains a function block, and the application is in offline mode.

Hint

This kind of forcing uses a data breakpoint internally and is therefore different from forcing with the Force values command or F7.

Values that were forced by the command Force FB input do not respond to the commands Show all forces or Unforce values.

  1. Open the editor of the CFC POU by double-clicking the object in the tree.

  2. Activate the forceability for the desired function block. Select the POU element in CFC and click CFC ‣ Prepare POU element for forcing .

  3. Login to the application on the target device. In CFC, select the input of the POU and click Force FB input in the context menu.

    ⇒ The Force value dialog opens.

  4. Set a new value for the input. Example in the case of a TON POU: FALSE for the Boolean input IN, or t#4s for the PT input (TIME). Click OK to confirm.

    ⇒ The set value is forced immediately. A green circle is displayed at the upper left of the POU element and the name of the input in the element is highlighted in green. For a Boolean value, a small monitoring view with the value also opens at the input. In the monitoring views, the forced value is displayed, for example in the Value column, as in the declaration part.

  5. To remove the forced value, click Force FB input again. In the Force value dialog, select the Remove value option.

    ⇒ Forcing is canceled. The input gets the current value from the controller.

See also