



CAUTION

Unusual changes to variable values in an application currently running on the controller can lead to undesired behavior of the controlled machinery.
Evaluate possible dangers before forcing variable values. Take the respective safety precautions. Depending on the controlled machinery, the result may lead to damage to machinery and equipment or injury to health and life of personnel.
In CODESYS, variable values in the PLC can be changed in online mode. Here we make a distinction between forcing and writing a previously prepared value.
Writing is done with the “Write Values” command ([Ctrl]+[F7]) and sets the variable to the prepared value one time. In this way, the value can be overwritten again by the program at any time.
Forcing is done with the “Force Values” command ([F7]) and sets the prepared value permanently. For more information, see below.
The preparation of a value for forcing or writing is possible at different places:
-
Declaration part: “Prepared value” field
-
Implementation part of the FBD/LD/IL editor: inline monitoring field
-
Watch view: “Prepared value” field
For instructions about this, see below. In the case that you want to prepare a value again for an already forced value, the “Prepare Value” dialog opens with options for handling the current force value.
Functionality of forcing
The prepared value is set to the respective variable at the beginning and end of a task cycle (or of a processing loop in the case of other task types).
The processing order in each cycle of a task is as follows:
1. Read the inputs
2. Force: Before the first program call, all prepared values are written to the variables by the runtime system, regardless of whether or not they are used by the task.
3. Process the IEC code
4. Force: After the last program call, all prepared values are written to the variables by the runtime system, regardless of whether or not they are used by the task.
5. Write the outputs
Note: It is possible that a forced variable temporarily gets a different value in the cycle while the code is being processed because the IEC code performs an assignment. Then the variable receives the forced value again only at the end of the cycle. The variable value can also be overwritten by the write access of a client to symbols of the application in mid-cycle. For this case, see the “Access variables in sync with IEC tasks” option in the “Properties” of the device object, or the “Configure synchronization with IEC tasks” setting in the symbol configuration. In this way, a PLC handler-supported synchronization of the write accesses by clients can be enabled with the task cycle.




NOTICE

Forced values are marked with the symbol. CODESYS does the forcing until the user lifts it explicitly by one of the following actions:
-
Executing the “Cancel forcing for all values” command
-
Lifting the force operation in the “Prepare Value” dialog
-
Logging out of the application
If forced variables still exist when logging out, then a dialog opens, prompting whether or not forcing should be lifted for all variables. If you respond by clicking “No”, then the forced values are applied again at the next login.
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 “Project Edit Object”.
-
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. When it is a Boolean value, you change the value by clicking in the field.
-
Perform Step 2 for other variables.
-
Click “Debug Force Values”.
The variable values are overwritten with the prepared values. The values are marked with the
symbol.
You can also force the variable values in the “Watch” view.
Forcing in the implementation part
Requirement: The application is in online mode.
-
Open the POU in the editor by choosing the command “Project Edit Object”.
-
In the implementation part of the editor, double-click an inline monitoring field (1).
The “Prepare Value” dialog 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 “Debug Force Values”.
The value of the variables is overwritten with the prepared values. The values are marked with the
symbol.
Viewing and editing all forced variables one list
Requirement: The application is in online mode. Multiple variables are forced.
-
Click “View Watch Watch all Forces”.
The “Watch 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 “Unforce Unforce and Keep All Selected Values” in the list box 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.




NOTICE

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”.
-
Open the editor of the CFC POU by double-clicking the object in the tree.
-
When using compiler version 3.5.11.x or 3.5.12.x, enable the "forceability" for the desired function block. Select the POU element in CFC and click “CFC Prepare Box for Forcing”.
-
Log in to the application on the target device. In CFC, select the input of the POU and click “Force Function Block 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. In the case of 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 Function Block Input” again. In the “Force Value” dialog, select the “Remove value” option.
Forcing is canceled. The input gets the current value from the controller.