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.
Attention
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.
Open the POU in the editor by choosing the command
.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.
Perform step 2 for other variables.
Click
.- ⇒
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.
Open the POU in the editor by choosing the command
.In the implementation part of the editor, double-click an inline monitoring field (1).
- ⇒
The dialog Prepare Value opens.
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.
Click
.- ⇒
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.
Click
.- ⇒
The Show all forces view opens. It contains all currently forced variables of the application in the form of a watch list.
Select all lines in the list and click
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.
Attention
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 or Unforce values.
Open the editor of the CFC POU by double-clicking the object in the tree.
Activate the forceability for the desired function block. Select the POU element in CFC and click
.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.
Set a new value for the input. Example in the case of a
TON
POU:FALSE
for the Boolean inputIN
, ort#4s
for thePT
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.
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