C# Remote debugging
This topic describes the basic steps needed for setting up a remote debug session and establishing a direct connection to a running application by means of Microsoft Visual Studio®.
How to debug
-
Activate debug mode
- Connect iCube Engineer to the controller.
- In the PLANT area, right-click on the controller.
-
In the context menu, select
Debug On/Off:
-
Attach Visual Studio to the process
- In Visual Studio® open the Debug → Attach to Process... menu.
- From the Connection type drop-down list, select the iCube Control Device entry.
-
From the
Connection target
drop-down list, select the
<current_controller_ip>:41101
(Last iCube Engineer connect) entry. This will take the settings of your last debug session with the iCube Engineer and a iCube Controller.
If you configuration does not work or has changed recently, you can update it as following:- Click on the Find... button.
- In the Attach to iCube Controller Device dialog that opens, click Load to get the settings of a recent iCube Engineer connection to the controller.
- Press OK to accept the automatically set IP address and path to the image file.
-
If this doesn't work either, you can still set the IP address and port, as well as the path to the binary image manually:
- Enter the IP address of the controller and port number (by default: 192.168.1.10:41100 ).
- Select the
*.img
binary image under the following path:
"C:\Users\\Documents\PLCnext Engineer\Binaries\PROJECT1@binary\eCLR\"
- Choose the image currently running on the controller.
- Confirm your selection with OK .
- Set set IP address with port and the path for the binary image and click the Attach button.
- In case the need for authentication on the device is activated you will be asked for credentials before Login .
-
In Visual Studio®, add breakpoints and execute the code.
↪ Execution of the code will stop at the first breakpoint. - Use the functions in the Visual Studio toolbar to jump to the next breakpoint or continue processing of the code.
-
Make changes to the code while debugging
- In Visual Studio, choose Debug → Stop debugging from the menu.
- Make changes to the code and save them.
- Recompile the project; to do so, open the Build → Rebuild menu and choose your project.
-
Then, switch to iCube Engineer, which will already have recognized the changes and prompts you to save the project.
Note: If the inputs/outputs have been changed in the code, errors might occur in iCube Engineer. If necessary, correct them in iCube Engineer, too. - Write and start the changed project to the controller.
- In Visual Studio® use Debug → Reattach to Process... to reconnect Visual Studio®, enter your credentials if necessary and continue debugging your code.