Makers Blog

How to debug C++ components and programs in Visual Studio

Martin PLCnext Team 10 March 2022 min. read
964 views 0 comments

This article describes how to debug custom C++ components and programs on a PLCnext Control device using Microsoft Visual Studio.The example in this article uses: 

  • AXC F 2152 with firmware version 2022.0.3.
  • Microsoft Visual Studio 2019.
  • PLCnext Toolchain version 2022.0 for Windows, with the Visual Studio extension.
  • Software Development Kit for AXC F 2152 version 2022.0.3 for Windows.

Procedure

On the PLC: 

In Visual Studio: 

  • Create a PLCnext PLM project (e.g. PLCnextPLMProject1) with one component (e.g. MyComponent) and one program (e.g. MyProgram), for the target device.
  • Make sure the “Solution Configuration” is set to Debug.
  • Build the project.

In PLCnext Engineer: 

  • Add the user library and create an instance of the C++ program in an ESM task.
  • Disable the ESM task watchdog by setting the Watchdog value to zero.
  • Send the project to the PLC.

In Visual Studio, perform the following one-off configuration: 

  • Select Tools > Options > Cross Platform > Connection Manager and click the Add button.
Connection dialog

In the dialog box, enter the following details:

Host name: The IP Address of the PLCnext Control device.

Port: Unless you’re using a special SSH configuration, the port should be the default 22.

User name: root

Authentication type: If you have not set up Private Key access for the root user, then select Password and enter the password for the root user on the PLCnext Control device.Now you are ready to debug your C++ program. In Visual Studio: 

  • Select Debug > Attach to Process…
Attach to process

Select the Connection target that you configured earlier, and the other options as shown in the screen shot. In the Available processes frame, select the Arp.System.Application process that contains –main=true in the title.  Click the Attach button, and you will enter debug mode.  You can now debug in the usual way – set breakpoints, add variables to the Watch window etc.  To stop debugging, don’t click the “Stop” button – that will stop the PLCnext Runtime process. Instead, select Detach all from the Debug menu.

Note:

The Makers Blog shows applications and user stories of community members that are not tested or reviewed by Phoenix Contact. Use them at your own risk.

Discussion

Please login/register to comment

Login/Register

Leave a Reply

Newsletter
Never miss a new article
Sign up for the newsletter
Never miss news about PLCnext Technology
Get interesting content via newsletter four times a year
Receive exclusive information before all other users