Debugging Code: Forcing/Overwriting
Note
This topic only applies to the standard (non-safety-related) controller. The steps for the Safety PLC are described in the help chapter "". |
To supplement the function test, the editors provide several debug features in
debug mode. For example, instead of pressing a button at the machine, you can force the corresponding input variable/port in the graphical editor. This enables monitoring the reaction of the application.
Debug functions are only available while PLCnext Engineer is attached to the application process, i.e., switched to
debug mode.
In
debug mode, the system provides the possibility of
-
overwriting local and global variables without assigned process data item (marker variables) and ports (even in non-IEC-61131-3-programs).
- forcing the following data items:
Note
Depending on the controller type used, forcing may not be supported in the current version. |
- setting breakpoints.
Unintended machine operation
- Prior to forcing/overwriting variables during runtime, make certain that suitable organizational measures (according to applicable sector standards) have been taken to avoid hazardous situations if the application logic functions in an unintended or incorrect way.
- Verify the impact of forcing or overwriting variables.
- Do not enter the zone of operation while the machine is operating.
- Ensure that no other persons can access the zone of operation while the machine is operating.
- Observe the regulations given by relevant sector standards while the machine is running in any other operating mode than "operational".
- Use appropriate safety interlocks where personnel and/or equipment hazards exist.
|
Forcing and overwriting variables in debug mode
Both, forcing and overwriting means assigning a new value to a variable. Both operations are only possible while the software runs in debug mode.
What is the difference between forcing and overwriting?
-
Overwriting is possible for local and global variables (marker variables without assigned process data item) as well as for I/O variables (assigned to process data items). The value is overwritten (set) only once at the beginning of the task execution cycle. Then, the variable is processed normally. Thus, the new value of the variable remains until a write access is performed. A write access can be performed by a programmed store operation or by remote access (e.g., by the OPC server) or by initializing the variable in case of a controller cold start.
-
Forcing is possible for variables and ports which are connected to process data items, i.e., I/O variables/ports. Forcing means setting the I/O variable/port permanently to the force value until forcing is reset by the user.Forcing takes place at the beginning and at the end of a program cycle. Within a cycle, the application may change the variable value by a write access. In this case, it is set to the force value again at the end of the cycle (until you unforce it).
Example
The variable xForce1 is forced to TRUE. During the program cycle, the application writes the value FALSE to it. In the online worksheet, the AND function returns the result FALSE although both inputs show TRUE.
Note
Depending on the controller type used, forcing may not be supported in the current version. |
Forcing/overwriting can be done in online code worksheets, online variables tables/Data Lists/Port Lists, and in the WATCHES window.
To modify a force value or unforce variables/ports, additionally the FORCELIST window can be used.
What do you want to do?
Force/overwrite a variable in an online code worksheet
- Activate the debug mode by attaching PLCnext Engineer to the running application process.Select the POU instance where a variable is to be forced/overwritten ('Go to Instance Editor' or double-click on the instance icon in PLANT) and open the desired worksheet.
- In graphical code: left-click on the name of the variable to be forced/overwritten and select the 'Force' in-place button:

Note
Instead of clicking the in-place button, you can double-click the variable or select the command from the context menu. |
The available debug commands are now displayed (depending on the variable type).
In textual code: left-click the value (not the name) to be forced/overwritten.
- In case of a Boolean value, click the desired value (TRUE/FALSE) to which the variable is to be set. In case of other data types, enter the desired value.
- Click
to overwrite the variable with the entered value or click
to force it.If the 'Force' command is not available, the current variable is a variable without assigned process data item (marker) and can only be overwritten.In online worksheets, forced values are shown with a color gradient. Examples:
Contact forced to TRUE: |  |
Contact forced to FALSE: |  |
Boolean variable in ST forced to TRUE: |  |
Boolean variable in ST forced to FALSE: |  |
Forced variables are added to the FORCELIST window in the Cross Function Area (see below).
- To change the forced value, double-click the variable (in graphical code) or left-click the value (in textual code), modify the value to be set and click the 'Force again' icon:
Force/overwrite a variable in an online variables table or Data List
The following steps are to be done while debug mode is activated.
- Open the desired table.
- Data List: double-click the
appropriate PLANT node and open the Data List editor. Or
- Local variables table: select the POU instance where a variable is to be forced/overwritten ('Go to Instance Editor' or double-click on the instance icon in PLANT) and open the variables table.
- In the table, double-click the value of the variable to be forced/overwritten. The available debug commands are now displayed (depending on the variable type).
- In case of a Boolean value, click the desired value to which the variable is to be set. In case of other data types, enter the desired value.
- Click
to overwrite the variable with the entered value or click
to force it.If the 'Force' command is not available, the current variable is a variable without assigned process data item (marker) and can only be overwritten.The value of a forced variable now appears with a color gradient background, indicating the forcing. Examples:
or
- To change the forced value, double-click the value again, modify the value to be set and click the 'Force again' icon:
Forced variables are added to the FORCELIST window in the Cross Function Area (see below).
Force/overwrite a variable in the WATCHES window
The following steps are to be done while debug mode is activated.
- Insert variables from online code worksheets or variables tables into the WATCHES window (for example by drag & drop).
- In the WATCHES window, double-click the 'Value' of the variable to be forced/overwritten.
Alternatively, right-click the table line and select 'Force/Overwrite' from the context menu or left-click the table line and press the shortcut <Ctrl> + <Alt> + <2>.The available debug commands are now displayed (depending on the variable type).
- In case of a Boolean value, click the desired value to which the variable is to be set. In case of other data types, enter the desired value.
- Click
to overwrite the variable with the entered value or click
to force it.If the 'Force' command is not available, the current variable is a variable without assigned process data item (marker) and can only be overwritten.The value of a forced variable now appears with a color gradient background, indicating the forcing. Examples:
or
- To change the forced value, double-click the value again, modify the value to be set and click the 'Force again' icon:
Forced variables are added to the FORCELIST window in the Cross Function Area (see below).
Force/unforce a variable in the FORCELIST window
Forced variables are added to the FORCELIST window in the Cross Function Area at the lower screen border. This way, forced variables are collected in one list and can be seen and handled centrally.
The FORCELIST provides commands for modifying force values or unforce variables.
 | Force the currently selected variable to a new value. |
 | Unforces the currently selected variable. After resetting the variable to its "normal" value, it is removed from the FORCELIST. |
 | Unforces all variables. After resetting the variables to their "normal" values, they are removed from the FORCELIST. |
Unforce (reset) a forced variable
To unforce all forced variables, open the FORCELIST window in the Cross Function Area at the lower screen border and click the 'Unforce All' icon in the FORCELIST window toolbar.
To unforce a particular forced I/O variable,
- open the FORCELIST window in the Cross Function Area at the lower screen border and select the variable, or
- double-click the variable in the graphical code, or
- left-click the value in the textual code, or
- double-click the value in a variables table, or
- right-click the value in the WATCHES window
and select the 'Unforce' command:
Note
Variables which are forced when running the 'Write and Start Project Changes' command are automatically unforced (the force list is reset and a corresponding desktop alert is issued). |