Debugging Cicode
- Last UpdatedJul 18, 2023
- 4 minute read
To help you locate Cicode errors, you can switch the Cicode Editor to debug mode to analyze running Cicode. You can toggle debugging on and off as required, but Plant SCADA needs to be running for the debugger to work.
Note: The Cicode Editor cannot debug foreground Cicode. A break in a foreground Cicode will result in the Foreground Cicode cannot break message.
To switch to debug mode:
-
Run the Cicode Editor.
-
From the Debug menu, select Start Debugging.
Or:
Click the Toggle Debug button on the toolbar.
Or:
To start a debugging session without the project being recompiled, select Start Debugging Without Compile from the Debug menu. You can only use this option if you have already compiled the project at least once.
|
|
|
UNINTENDED EQUIPMENT OPERATION Do not use the following command to start Plant SCADA if you have uncompiled project changes that are necessary for the safe operation of your plant and process.
This option is only intended to assist debugging an already compiled project. Failure to follow these instructions can result in death, serious injury, or equipment damage. |
If the current project is not running, Plant SCADA will automatically launch it. The bug icon in the bottom right-hand corner is green when debugging.
Note: You can use the parameter [Debug]CodeDebug to enable Cicode debugging for a specific server process. You cannot debug a process that is running as a Windows™ service.
Debugging a Function
To debug a function:
-
Run the Cicode Editor.
-
Open the file containing the function you wish to debug.
-
Switch to debug mode (see above).
If the current project is not running, Plant SCADA will automatically launch it. The bug icon in the bottom right-hand corner is green when debugging.
-
Insert a breakpoint where you want to start debugging.
-
From the View menu, select any debug windows you want to use. If you are unsure, you can use them all.
-
Initiate the thread by calling the function. You can do this directly from the Cicode window in the Kernel, or by using a function, etc.
The function will break at the specified breakpoint. You can then use the step tools to step through and trace your function.
-
Click the Toggle Debug button to stop debugging, or choose Debug | Stop Debugging.
Using Breakpoints
To debug a function, you need to first be able to stop it at a particular point in the code. You can place a breakpoint on any line in the source code functions. Breakpoints may be inserted or removed while editing or debugging without the need for them to be saved with the file.
To insert/remove a breakpoint:
-
Open the Cicode Editing window.
-
Position the cursor on the line where you want the breakpoint to be placed or removed.
-
Click the Debug indicator bar. Alternatively, you can press F9 or choose Debug | Insert/Remove Breakpoint.
The breakpoint appears as a large red dot at the beginning of the line.
You can also enable or disable breakpoints you have inserted into your Cicode.
To enable/disable a breakpoint:
-
Open the Cicode Editing Window.
-
Position the cursor on the line where the breakpoint is located.
-
Press Ctrl + F9, or choose Debug | Enable/Disable Breakpoint.
A disabled breakpoint appears as a large dark gray (disabled) dot at the beginning of the line.
Note: You can also use the DebugBreak Cicode function to halt a process thread.
Start Debugging on Hardware Error
For a detected hardware error to halt a function, you need to have the following options enabled:
-
Break on all hardware errors.
Or:
-
Break on hardware errors in active thread.
These are available on the Options tab of the Cicode Editor Options dialog (Debug | Options).
When the break occurs, the default Cicode Editor will be launched (if it is not open already), with the correct code file, function, and break point line displayed. To launch the debugger in this case, you also need to have the Plant SCADA will start debugger on hardware errors option set.
Function Error Handling
Once you have halted a thread, the debugger marks the position in the code with an arrow. Now you can step through the function, line by line, and watch what happens in the debug window (see below). The following tools are provided in the Cicode Editor, to control stepping through functions.
|
Step Into |
Advances the current Cicode thread by one statement. If the statement is a user defined function, the debugger steps into it (the pointer jumps to the first line of the source code). |
|
Step Over |
Advances the current Cicode thread by one statement. If the statement is a user defined function, the debugger steps over it (the function is not expanded). |
|
Step Out |
Advances to the end of the current function and return. If there is no calling function, the thread terminates. |
|
Continue |
Re-starts normal execution of the current Cicode thread. If there are no more breaks, the thread terminates normally. |
