How do breakpoints work in C.

Use breakpoints

  1. PLC
  2. Test the PLC project and correct errors
  3. Use breakpoints

Breakpoints are usually used for troubleshooting in the program. You can set breakpoints at certain positions in the program in order to force an execution stop there and to monitor the variable values. TwinCAT 3 PLC supports breakpoints in all IEC editors.

The stop at the breakpoint can be linked to additional conditions. You can also redefine breakpoints as execution points at which the program does not stop, but rather certain code is processed.

The view Breakpoints (Menu PLC> window) gives an overview of all defined breakpoints. There are additional commands available for changing several breakpoints at the same time.

In the editor, the status of breakpoints and execution points is marked with the following symbols:

See also:

Breakpoints in PLC projects with several tasks

If a breakpoint is reached while executing a PLC project, no more code will be executed by any task in this PLC project. Code that is outside of this PLC project will still be executed.

If the program is at a breakpoint on the PLC, an online change or download causes all tasks to be stopped. That means a stop of the PLC. In this case, TwinCAT displays a corresponding message and you can decide whether you want to continue with the login or not.

Setting a simple breakpoint (example ST editor)

  • The project is online.
1. Open a POU in the ST language in the editor.
2. Place the cursor in the line in which a breakpoint is to be set.
3. Select in the menu Debug or the command in the context menu Toggle breakpoint or press the key [F9].
4. Select in the menu PLC or in the toolbar TwinCAT PLC toolbar options the command begin or press the key [F5].
5. Set further breakpoints and check the values ​​of tags at the breakpoints.
6. Place the cursor on a line in which a breakpoint is to be deleted.
7. Select in the menu Debug or the command in the context menu Toggle breakpoint or press the key [F9].
  • The mark disappears. The breakpoint is deleted.

See also:

Defining a breakpoint condition (example ST editor)

  • The project is online.
1. Open a POU in the ST language in the editor.
2. Select in the menu PLC> window the command Breakpoints.
3. Choose the command New in the toolbar.
4. Select the POU and the position of the new breakpoint.
5. Select the tab condition.
6. Select in the section Hit count the option Stop when the number of hits is a multiple of and enter the value 5 in the field to the right of it.
7. In addition, define a Boolean condition for when the breakpoint should be active. To do this, activate the option Stop if TRUE. Enter a Boolean variable in the field to the right.
8. Activate the option Activate breakpoint immediately.
9. Close the dialog.
  • The line is marked in red and with the icon marked.

Now watch the running program. As long as the Boolean variable for the condition is FALSE, the condition for the breakpoint is not met and the program runs. If you set the variable to TRUE, the condition is fulfilled and the program stops at this breakpoint every 5th pass.

See also:

Specifying an execution point (example ST editor)

  • The project is online.
1. Open a POU in the ST language in the editor.
2. Select in the menu PLC> window the command Breakpoints.
3. Choose the command New in the toolbar.
4. Select the POU and the location of the execution point.
5. Select the tab Execution point settings.
6. Activate the option Execution point.
Enter in the field Run the following code Enter the instructions you want to be executed when the execution point is reached. For example, if the variable nCounter is available.
7. Close the dialog.
  • The line is marked red and with the icon marked

When the program reaches the execution point, it does not stop, but the code defined above is executed.

See also:

© 2021 Beckhoff Automation