Remote debugging C# code

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.

How to

cookie

Note: Tutorial videos are embedded from the Phoenix Contact Technical Support YouTube channel.  When you start playing an embedded YouTube video, you accept the YouTube Terms & Conditions. That includes cookies for marketing purposes which will remain on your device and will be used to provide video suggestions and advertisements based on your browsing habits and may be sold to other parties. 

Prepare your station for C# remote debugging

Duration:  3m:16s   Audio Language: English  Subtitles: English  Resolution: max. 1280 x 720px (HD)

How to prepare your station for a remote debugging session for C# programming with Microsoft® Visual Studio®.

Debug your code - one iteration through all steps

Duration:  3m:31s   Audio Language: English  Subtitles: English  Resolution: max. 1280 x 720px (HD)

How to debug your C# code on your station with Microsoft® Visual Studio®.

Step-by-step instructions

Preconditions for these instructionsShow preconditions for this instructions 

Hardware used here

  • AXC F 2152 Starterkit
  • Computer connected via Ethernet LAN

Software used here

  • Microsoft® Windows® 10
  • Internet browser
  • WinSCP
  • Microsoft® Visual Studio® 2015 and 2017
  • PLCnext Technology Development Tools for Visual Studio
  • PLCnext Engineer

Additional instructions

For further information on the debug functions in PLCnext Engineer and in Microsoft® Visual Studio®, please refer to their associated documentation.

Note: All steps in the following description are based on the default settings. Consider all changes made by the user.

Currently, the C# debugging function does not feature an interface for logging on to the controller. To debug the C# code, you have to deactivate the user authentication in the WBM on the controller (for additional information, please refer to the WBM section).

 

  1. Disable the user authentication

    Note iconNotice

    Risk of unauthorized access

    To debug the C# code, you have to deactivate the user authentication on the controller.

    → With security functions switched off, the controller must not be used for live operation.

    → Make sure to switch on security functions after debugging.

    • Log in to the Web-based Management on your PLCnext Control via a browser.
    • Disable the user authentication:
      User authentication
    • Apply the changes and close the browser.
  2. Open a port and deactivate TLS
    • In WinSCP, establish a connection to the IP address of the controller with root privileges:
      establish connection
    • Open this directory: /etc/plcnext/device/System/RscGateway/
    • Open the RscGateway.settings file:
      Directory with RscGateway.settings file
    • Scroll to the line with <TcpGatewaySettings...>
    • Insert this line of code:
      <TcpGatewaySettings gatewayId="0" tcpPort="41101" sessionTimeout="300000” encrypted="false" />
      as shown here:
      RscGateway.settings insertion
    • Save and close the file
    • Restart the controller
  3. Prepare a project
  4. Activate debug mode

    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.

    • 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
  5. Attach Visual Studio to the process
    • In Visual Studio open the DebugAttach to Process... menu
    • From the Transport drop-down list, select the eCLR Device entry
    • Click on the Find... button
    • In the Attach to eCLR dialog that opens, enter the IP address of the controller and port number (e.g., 192.168.1.10:41101).
    • Select the *.img binary image under the following path:
      C:\users\Public\Documents\PLCnext Engineer\Version\Binaries\PROJECT1@binary\eCLR\
      Note: A shortcut to this path is available in the Select Image File dialog. It can be found under Microsoft Visual Studio 2015Binaries.
      Debugging VS Settings
    • Choose the image currently running on the controller.
    • Confirm your selection with OK.
    • Click on the Attach button.
    • Then add breakpoints in Visual Studio and execute the code.
    • Execution of the code will stop at the breakpoint. You can now 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
  6. Make changes to the code while debugging

    If you want to make changes to the code within the framework of debugging, you have to disconnect (detach) the process connection:

    • In Visual Studio, choose Debug → Detach All from the menu:
      Detach All
    • 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
    • PLCnext Engineer 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.
    • Transfer the changed project to the controller
    • Then, reconnect Visual Studio to the process (see step 5 above) and continue debugging your code
  7. Revert to secure mode

    When finished with debugging, revert the security functions before using the controller in live operation:

    • Remove or encrypt the unencrypted TCP port.
    • Enable user authentication in the WBM.