Debugging an ST Program

You can use the Debug feature to debug your ST program. The debugging feature allows you to check that your program provides the expected Logic functions. It is particularly useful when you need to check separate parts of large programsyou can step through each section of the program and view its effect on the variables. To view the variables, you need to use the Variables Window. This helps you to determine which parts of your ST programs are not working as intended (if any).

A Logic program can only be debugged by one user at a time. When a user has a Logic program in debug mode, it cannot be executed manually or by schedules.

There are two ways to start the debugging process:

Typically, you will need to use the debugging feature to debug separate sections of an ST program. For example, if a complex ST program is not returning the values you expected, you will need to debug each calculation within the program separately, this allows you to determine the sections of the ST program that are incorrect.

To debug parts of a program, you need to use the commands in the Debug group on the Logic tab:

Start

The debugger runs the program until it reaches a breakpoint or the program completes.

Stop

Stops the debugging feature. The debugger will not run again until you select the Restart command.

Restart

Starts the debugging feature again (after it has been stopped).

Step Over

Sets the debugger to ignore any further statements in a function block that is contained within the ST program. If the debugger is set to Step Into when you select this command, it will execute the current statement in the function block and then return to the main part of the ST program. It will not execute the remaining calculations in the function block (unlike the Step Out command).

The debugger is set to Step Over by default.

Step Into

When a program is being debugged, the debugger ignores the code in any function blocks that are contained within the program. You can set the debugger to run the function block code as well as the rest of the program code by selecting the Step Into command.

The Step Into command is useful when investigating function blocks within an ST program. If the function blocks have already been debugged, there is no need to use the Step Into command.

Step Out

Sets the debugger to ignore any further statements in a function block that is contained within the ST program. If the debugger is set to Step Into when you select this command, it will execute the remaining statements in the function block and then return to the main part of the ST program.

Run to Cursor

Sets the debugger to execute the program statements up to the cursor position. When you select this command, the position of the cursor acts like a breakpoint.

Show Next Statement

Positions the cursor at the line of the next statement that is to be executed.

Rerun on Completion

By default, when the debugger has executed every statement successfully, it waits a short time before starting the debugging process again. You can use the following options from this command's drop-down menu to control how long the debugger waits and whether it will repeat the debugging process:

Break on Error

The debugger will execute each statement in the program (up to a breakpoint if a breakpoint is defined). If there is an error in the program, the debugger will stop at the line in which the error occurs.

After 1s, 2s, 5s, 10s, 30s, 60s

Defines the amount of time the debugger will wait after successfully executing each statement before it starts again. The options correspond to 1 second, 2 seconds, 5 seconds, 10 seconds, 30 seconds, and 60 seconds respectively.

To use breakpoints while debugging,use the commands in the Breakpoints group on the Logic tab:

Insert/Remove

Inserts or removes a break point at a selected position. You need to use this command to divide your program into sections.

To insert a breakpoint, position the cursor in the line of code that you want to use as a breakpoint, then select the Insert/Removet command.

The debugger will only run up to the breakpoint—it does not run the parts of the program that are after the breakpoint. By using the Variables window (see Viewing the Variables in your ST Program), you can view the values that are created by the program up until the breakpoint. By examining the values, you can determine whether the code in the section before the breakpoint is causing unexpected results.

If the code up to the breakpoint is working as expected, you can remove the breakpoint using the Insert/Remove command. Alternatively, you can disable it by selecting the Enable/Disable command.

Remove All

Deletes each of the breakpoints in the program.

Enable/Disable

You can use the Enable/Disable command to turn a breakpoint on or off without having to insert or delete it. This is useful when you want the debugger to run past a breakpoint you have inserted, but you do not want to remove the breakpoint (because you need to use it again at some point).

The Enable/Disable command works as a toggle. When you first select it, you disable a breakpoint so that the debugger ignores it. When you select it again, the breakpoint is enabled and the debugger will stop running the program at the breakpoint.

To view the Variables Window while debugging a program,use the Variables command in theView group on the Logic tab.

You need to use the Variables window to view the values that are being produced by each section of the ST program. By examining the values that are produced, you can determine which values are unexpected (and therefore which parts of the ST code may be incorrect). For more information, see Viewing the Variables in your ST Program.


Disclaimer

Geo SCADA Expert 2022