Creating a new C++ project in Eclipse®

This section describes the general approach to C++ programming on PLCnext Technology with Eclipse® IDE. Of course, you might use any other IDE or code editor instead.

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 digital "cookies" for marketing purposes which will remain on your device. The data gained through this will be used to provide video suggestions and advertisements based on your browsing habits, and may be sold to other parties. 

Duration:  05m:20s   Audio Language: none Subtitles: none Resolution: max. 1280 x 720px (HD)

How to start programming for PLCnext Technology in C++.
Prerequisites: Eclipse® IDE with PLCnext Technology Add-in is already installed

Creating a new C++ project

  • Select the desired controller and firmware status for the project. 
    Note: You can also choose more than one firmware version and several targets to be supported by the project. The PLCnext CLI will build your project for all of them automatically and put them into a single PLCnext Engineer library.
    Hide screenshotClick to see the screenshot

    Supported_Targets

 

You can also change the selection of the desired controller and the corresponding firmware status after the project has been created.

Change the settings:Click here to see how

  • Open the Project → Properties menu.
  • Select the PLCnext Targets option.
  • Remove controllers or add new controllers and their firmware version.
  • Click the Finish button.

You can now Finish the wizard and start creating the program.

Creating a C++ program

To create a C++ program using Eclipse®, which can be imported as a library into PLCnext Engineer, you must first prepare a new project in accordance with the description above.

The created project has a defined structure in which the C++ program is created as seen in this example: 

Project_Explorer

To create a program, proceed as follows:

  • Open the *.cpp source file.
  • Program the code to be executed during each ESM task cycle in the Execute() function (see this comment: //TODO implement program).

For additional information on programming in C++, please refer to the other C++ topics in this manual.

After instantiation of a program, the assigned ESM task calls the Execute() function of the program instance in each cycle.

Note: Example projects and the associated documentation can be downloaded at github.com/plcnext.

Adding or removing components or programs

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 digital "cookies" for marketing purposes which will remain on your device. The data gained through this will be used to provide video suggestions and advertisements based on your browsing habits, and may be sold to other parties. 

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

How to add or remove components or programs in a C++ project for PLCnext Technology:

  • 00m:33s – Add a component
    Hide descriptionClick to view a description
    • Right click on the project. 
    • Select New → PLCnext C++ Component.

    New_component

    • Give the component a name. The namespace is by default the project namespace.
    • Assign the component to a project and click Finish.

    New_component

  • 01m:10s – Add a program 
    Hide descriptionClick to view a description
    • Right click on the project.
    • Select New → PLCnext C++ Program.

    New_program 

    • Give the program a name. The namespace is by default the project namespace.
    • Assign the program to a project and select a parent component.
    • Click Finish and you will get the program source and header file.

    New_program

  • 01m:55s – Delete a program 
    Hide descriptionClick to view a description
    • To delete a program simply delete the corresponding source and header file.
    • Select the two files, right click on them and choose delete in the menu.

    Delete_program

  • 02m:07s – Delete a component, consisting of 3 steps:
    • 0:02:11 – Delete the component itself
    • 0:02:22 – Reassign all programs of the deleted component
    • 0:03:19 – Delete all intermediate files of the deleted component 
      Hide descriptionClick to view a description
      1. Delete the corresponding source and header file of your component.

      Delete_component

      1. Delete all programs assigned to this component or reassign them to another existing component.
        To reassign a program, open the header file of the program and change the references to the component that owns this program. Use the Find/Replace function of Eclipse and search and replace all references by the new component name.

      Find/Replace

      1. Remove all intermediate files from previous builds.
        For this simply right click on your project and select Clean Project.

       Clean_Project

Compiling the project

Note: PLCnext Engineer recommends to make the following setting so that your files are saved automatically before you execute the Build Project option:

  • In Eclipse®, open the Window → Preferences menu.
  • Select General → Workspace → Build.
  • Enable the Save automatically before build check box.
  • Make this setting separately for each workspace.

Procedure

  • Switch to the Project Explorer to compile the project.
  • Right-click to open the context menu for the project folder
    (in the example: FirstProject1).
  • In the context menu, click on the Build Project option (Screenshot belowshow that) or click on the  Schaltfläche_Build4Targets.PNG button in the tool bar (Screenshot belowshow that)

    Eclipse_BuildProject.png

    Eclipse_Build4Targets.PNG

Successful compilation of the project or possible error messages are displayed on the Console tab.
Hide exampleClick to see an example

Eclipse_Console.png

 
Note regarding the compiler warning:

For each defined port, you receive the compiler warning:
offsetof within non-standard-layout type

E.g.:

[cmake]: /home/user/Workspace/Counters/intermediate/code/Counters Library.meta.cpp:22:47: warning: offsetof within non-standard-layout type ‘Counters::CppRetain’ is undefined [-Winvalid-offsetof]

To suppress the warning you have to add the following line to your project's CMakeLists.txt:

target_compile_options(NameOfYourLibrary PRIVATE $<$<CXX_COMPILER_ID:GNU>:-Wno-invalid-offsetof>)

(replace NameOfYourLibrary with the name of your library)

Successful compilation

If compilation was successful, a shared object (*.so) is generated.

Generating a PLCnext Engineer library

To be able to use the program in PLCnext Engineer, you need the *.pcwlx library, which was generated during compilation. The Library Builder automatically generates the *.pcwlx library within the process of compilation ("Build Project"). The files are located in the project folder, e.g., C:/Users/<username>/eclipse-workspace/FirstProject/Bin. Import the library into your PLCnext Engineer project and assign the programs to a task.  Click here for a description how to import libraries in PLCnext Engineer.

 

 

 

 


 • Published/reviewed: 2020-07-29 • Revision 35 •