4 Using SCL
4.10 Debugging the Created Programs
4.10.1 The SCL Debugging Functions
Using the SCL debugging functions, you can check the execution of a program on the CPU and locate any errors in the program. Syntax errors are indicated by the compiler. Runtime errors occurring during the execution of the program are also indicated, in this case, by system interrupts. You can locate logical programming errors using the debugging functions.
SCL Debugging Functions
In SCL, you can start the following test functions:
• Monitor (S7-300/400-CPUs)
With this function, you can display the names and current values of variables in the SCL source file. During the test, the values of the variables and the
parameters are displayed in chronological order and updated cyclically.
• Debug with Breakpoints/Single Step (S7-400 CPUs only)
With this function, you can set breakpoints and then debug in single steps. You can execute the program algorithm, for example statement by statement and can see how the values of the variables change.
!
CautionRunning a test while your plant is in operation can lead to serious injury to personnel or damage to equipment if the program contains errors!
Always make sure that no dangerous situations can occur before activating debugging functions.
Requirements for Debugging
• The program must be compiled with the options "Create object code" and
"Create debug info". You can select the options in the "Compiler" tab of the
"Customize" dialog box. You can display this dialog with the menu command Options > Customize.
• There must be an online connection from the programming device/PC to the CPU.
• The program must also be loaded on the CPU. You can do this with the menu command PLC > Download.
S7-SCL V5.3 for S7-300/400
4-24 A5E00290611-01
4.10.2 The "Monitor" Debugging Function
Using the continuous monitoring function, you can debug a group of statements.
This group of statements is also known as the monitoring range. During the test, the values of the variables and the parameters of this range are displayed in chronological order and updated cyclically. If the monitoring range is in a program section that is executed in every cycle, the values of the variables cannot normally be obtained from consecutive cycles.
Values that have changed in the current cycle and values that have not changed can be distinguished by their color.
The range of statements that can be tested depends on the performance of the connected CPU. After compilation, the SCL statements in the source code produce different numbers of statements in machine code so that the length of the
monitoring range is variable and is determined and indicated by the SCL debugger when you select the first statement of the required monitoring range.
Remember the following restrictions for the "Monitor" function:
• Variables of a higher data type cannot be displayed in their entirety. The elements of these variables can be monitored providing they are not of an elementary data type.
• Variables of the type DATE_AND_TIME and STRING and parameters of the type BLOCK_FB, BLOCK_FC, BLOCK_DB, BLOCK_SDB, TIMER and COUNTER are not displayed.
• Access to data blocks with the format <symbol>.<absoluteaddress> are not displayed (for example data.DW4).
Querying this information usually extends the length of the cycle times. To allow you to influence the extent to which the cycle time is extended, SCL provides two different modes of operation.
Operating Mode
Explanation
Test Operation In the "Test Operation" mode, the monitoring range is only limited by the performance of the connected CPU. All the debugging functions can be used without restrictions. The CPU cycle time can be extended
considerably since the status of statements, for example, in programmed loops is queried in each iteration.
Process Operation
In the "Process Operation" mode, the SCL debugger restricts the maximum monitoring range so that the cycle times during testing do not exceed the real runtimes of the process or only insignificantly.
4.10.3 Debugging with Breakpoints/Single Step Mode"
If you test with breakpoints, the program is tested step by step. You can execute the program algorithm statement by statement and can see how the values of the variables change.
After setting breakpoints, you can allow the program to be executed as far as a breakpoint and then start step-by-step monitoring at this breakpoint.
Single Step Functions:
When the "Debugging with Breakpoints" function is active, you can use the following functions:
• Next Statement
The currently selected statement is executed.
• Resume
Resume until the next active breakpoint.
• To Cursor
Resume as far as the cursor position you have selected in the source file.
• Execute Call
Jump to or call an SCL block lower down the call hierarchy.
Breakpoints
You can define breakpoints at any point in the statement section of the source text.
The breakpoints are only transferred to the programmable controller and activated when you select the menu command Debug > Breakpoints Active. The program is then executed as far as the first breakpoint.
The maximum number of active breakpoints depends on the CPU.
CPU 416 maximum of 4 active breakpoints possible CPU 414 maximum of 4 active breakpoints possible S7-300 CPUs no active breakpoints possible
Requirements:
The opened source file was not modified previously in the editor.
S7-SCL V5.3 for S7-300/400
4-26 A5E00290611-01
4.10.4 Steps in Monitoring
Once you have downloaded the compiled program to the programmable controller, you can test it in the "Monitor" mode.
Follow the steps outlined below:
1. Make sure that the requirements for debugging are satisfied and that the CPU is in the RUN or RUN-P mode.
2. Select the window containing the source file of the program to be tested.
3. If you want to change the default mode (process operation), select the menu command Debug > Operation > Test Operation.
4. Position the cursor in the line of the source text containing the first statement of the range to be tested.
5. Make sure that no dangerous situations can result from running the program and then select the menu command Debug > Monitor.
Result: The largest possible monitoring range is calculated and indicated by a gray bar at the left edge of the window. The window is split and the names and current values of the variables in the monitoring range are displayed line by line in the right-hand half of the window.
6. Select the menu command View > Symbolic Representation to toggle the symbolic names from the symbol table on and off in your program.
7. Select the menu command Options > Customize, open the "Format" tab, and make the settings for the colors in which the values will be displayed.
8. Select the menu command Debug > Monitorto halt debugging.
9. Select the menu command Debug > Finish Debugging to quit the debugging function.
Note
The number of statements that you can debug (monitoring range) depends on the performance of the connected CPU.
4.10.5 Steps for Debugging with Breakpoints 4.10.5.1 Defining Breakpoints
To set and define breakpoints:
1. Open the source file you want to debug.
2. Display the toolbar for breakpoint editing with the menu command View >
Breakpoint Bar.
3. Position the cursor at the required point and select the menu command Test >
Set Breakpoint or the button in the breakpoint bar. The breakpoints are displayed at the left edge of the window as a red circle.
4. If required, select Debug > Edit Breakpoints and define a call environment.
The call environment decides whether or not a breakpoint is only active when the block in which it is located
- is called by a specific higher-level block and/or - is called with a specific data block.
4.10.5.2 Starting the Test with Breakpoints
Once you have downloaded the compiled program to the programmable controller and set breakpoints, you can debug it in the "Test with Breakpoints" mode.
Follow the steps outlined below:
1. Open the SCL source file of the program you want to debug.
2. Make sure that no dangerous situations can result from running the program and that the CPU is in the RUN-P mode. Select the menu command Debug >
Breakpoints Active and then Debug > Monitor.
Result: The window is split vertically into two halves. The program is executed as far as the next breakpoint. When this is reached, the CPU changes to HOLD and the red breakpoint is marked by a yellow arrow.
3. Continue with one of the following commands:
- Select the menu command Debug > Resume or click the "Resume"
button.
The CPU changes to the RUN mode. When the next active breakpoint is reached, it changes to hold again and displays the breakpoint in the right-hand window.
- Select the menu command Debug > Next Statement or click the "Next Statement" button.
The CPU changes to RUN. After processing the selected statement it changes to hold again and displays the contents of the currently processed variables in the right-hand window.
- Select the menu command Debug > To Cursor or click the "To Cursor"
button.
The CPU changes to the RUN mode. When the selected point in the program is reached, it changes to hold again.
S7-SCL V5.3 for S7-300/400
4-28 A5E00290611-01
- Select the menu command Debug > Execute call, if the program stops in a line containing a block call.
If the lower block in the call hierarchy was created with SCL, it is opened and executed in the test mode. After it is processed, the program jumps back again to the call point.
If the block was created in another language, the call is skipped and the program line that follows is selected.
Note
The menu commands Debug > Next Statement or Debug > To Cursor set and activate a breakpoint implicitly. Make sure that you have not used the maximum number of active breakpoints for your particular CPU when you select these functions.
4.10.5.3 Stopping the Test with Breakpoints
To return to normal program execution:
• Deactivate the Debug > Breakpoints Active menu command to interrupt debugging or
• Select the menu command Debug > Finish Debugging to quit debugging.
4.10.5.4 Activating, Deactivating and Deleting Breakpoints
You can activate/deactivate and delete set breakpoints individually:
1. Select the menu command Debug > Edit Breakpoints. 2. In the dialog, you can
- activate and deactivate selected breakpoints with a check mark.
- delete individual breakpoints.
To delete all breakpoints, select the menu command Debug > Delete All Breakpoints.
4.10.5.5 Debugging in the Single Step Mode
Follow the steps outlined below:
1. Set a breakpoint before the statement line from which you want to debug your program in the single step mode.
2. Select the menu command Debug > Breakpoints Active. 3. Run the program until it reaches this breakpoint.
4. To execute the next statement, select the menu command Debug > Next Statement or click the button in the toolbar.
- If the statement is a block call, the call is executed and the program jumps to the first statement after the block call.
- With the Debug > Execute Call menu command, you jump to the block.
Here, you can then continue debugging in the single step mode or you can set breakpoints. At the end of the block, you return to the statement after the block call.
4.10.6 Using the STEP 7 Debugging Functions 4.10.6.1 Creating and Displaying Reference Data
You can create and evaluate reference data to help you when debugging and modifying your user program.
You can display the following reference data:
• The user program structure
• The cross reference list
• The assignment list
• The list of unused addresses
• The list of addresses without symbols
Creating reference data
You can create reference data in the following ways:
• Using the menu command Options > Reference Data > Display, you can create or update and display the data as required.
• By filtering, you can restrict the amount of reference data displayed and speed up the creation and display of the data considerably. Select the Options >
Reference Data > Filter menu command.
• Using menu command Options > Customize, you can decide whether or not the reference data are created automatically when the source file is compiled. If you want the reference data compiled automatically, enter a check mark beside
“Create Reference Data" in the “Create Block" tab.
Remember that creating reference data automatically will increase the time
S7-SCL V5.3 for S7-300/400
4-30 A5E00290611-01
4.10.6.2 Monitoring and Modifying Variables
When you test your program with the "monitoring and modifying variables" function, you can do the following:
• Display the current values of global data contained in your user program (monitor)
• Assign fixed values to the variables used in your user program (modify) Follow the steps outlined below:
• Select the menu command PLC > Monitor/Modify Variables.
• Create the variable table (VAT) in the displayed window. If you want to modify variables, enter the new values for the variables.
• Specify the trigger points and conditions.
!
CautionRunning a test while your plant is in operation can lead to serious injury to personnel or damage to equipment if the program contains errors! Before running the debugging functions, make sure that no dangerous situations can occur!