Remote debugging of C# code

Works for PLCnext Control devices running firmware 2023.0 LTS or newer -
for former firmware see Remote debugging pre-2023

Because PLCnext Technology includes an implementation of eCLR, you have the option to establish a C# remote session on a PLCnext Control.

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®

Prerequisites

  • Microsoft® Visual Studio® 2019 and 2022
  • PLCnext Toolchain C# extension for Visual Studio, version 2023.0 LTS
  • PLCnext Engineer 2023.0 LTS or newer

What should be done before:

Risk of personal injury or damage to equipment

Using the debugging function can result in an unsafe process interruption.

Ensure that there is no risk of personal injury or damage to the equipment.

How to debug

  1. Activate debug mode
    • Connect PLCnext Engineer to the controller.
    • In the PLANT area, right-click on the controller.
    • In the context menu, select Debug On/Off:
      Switch Debug On or Off
  2. Attach Visual Studio to the process
    • In Visual Studio® open the DebugAttach to Process... menu.
    • From the Transport drop-down list, select the PLCnext Device entry.
    • From the Connection target drop-down list, select the <Current_Controller_IP>:41101 (Last PlcNext Engineer connect) entry. This will take the settings of your last debug session with the PLCnext Engineer and a PLCnext Control.
      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 PLCnext Device dialog that opens, click Load to get the settings of a recent PLCnext 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\Public\Documents\PLCnext Engineer\Version\Binaries\PROJECT1@binary\eCLR\
        Debugging VS Settings
      • 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.
    • Evaluate the current variable values:
      Breakpoint
    • Use the functions in the Visual Studio toolbar to jump to the next breakpoint or continue processing of the code:
      continue after breakpoint
      Alternatively you can also use the debugging controls in PLCnext Engineer.  
Tip: If you want to stop debugging your C# code right here, simply select DebugStop Debugging from the menu bar. If the program stays still stopped on a breakpoint in Visual Studio®, just press Continue the execution in the debugging menu of the PLCnext Engineer.
  1. 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 PLCnext 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 PLCnext Engineer. If necessary, correct them in PLCnext Engineer, too.
    • Write and start the changed project to the controller.
    • In Visual Studio® use DebugReattach to Process... to reconnect Visual Studio®, enter your credentials if necessary and continue debugging your code.

 

 


• Published/reviewed: 2024-10-30   ☀  Revision 074 •