Advanced C++ programming features

Note: Some of these features have become available with newer toolchain releases over time. Check the availability note at each heading bar

Features:

Connecting ports

Available from 2022.0 LTS

The Port Wizard helps to have all necessary attributes at hand, and builds the comment for the port generator around your selected variable.

The C++ project templates already provides some information about ports and their desired location as comments in the *.hpp files. If you want more information about ports, see the description for program ports and for component ports

Using the Port Wizard

  • In your IDE interface, move your cursor to the line of the variable your want to link to a port.
    Note: The Port Wizard does not verify the selected line. The comment can be created anywhere. So be sure to add it to the proper line.
  • Right click on the worksheet area and select mark as port

The Port Wizard opens.

  • Give your port a name.
    If the Port Name text box stays empty the name of the field is used by default.
  • Set attributes according to your needs.
    Tip: Mouse over the attribute names to see a tooltip information, or see the according topics in this Info Center for more details.
    port wizard
  • Check the comment that will be created In the Preview area. 
  • To apply the previewed setting, click Finish or OK (depending on your IDE).

 

Adding an ACF library version and description

Available from 2022.0 LTS 

While mousing over a library name in the PLCnext Engineer COMPONENTS panel, a large tooltip pops up. This tooltip also provides version information and a brief description:

PLCnext Engineer Library Information

This ACF library version, the description and other information is always set via an XML configuration file. If you're working with Eclipse® or Visual Studio® IDE, the regarding PLCnext Technology add-in/extension provides a dialog for adding the information to the XML configuration file. If you prefer working with another IDE or without any, you need to add the XML configuration file and its information manually. Here are the steps needed for all three ways:

Adding the information with an IDE plug-in

  • To show the dialog box in Visual Studio, right-click on your project in the Solution Explorer and select PLCnext Technology → Project Configuration;
    show a screenshotshow a screenshot
    in Eclipse open Project → Properties, then navigate to PLCnext Configuration 
    show a screenshotshow a screenshot

    project configuration
    Project Configuration
  • Write your description and version into the fields, and set the minimum PLCnext Engineer version to use with this project.

  • To apply the setting, click Save & Close (Visual Studio) or Apply and Close (Eclipse).

Adding the information without an IDE

  • Create a file named PLCnextSettings.xml in your project's root folder.
  • Add the following template content to it:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ProjectConfiguration xmlns="http://www.phoenixcontact.com/schema/projectconfiguration">
    <EngineerVersion>2022.6</EngineerVersion>
    <LibraryDescription>Library Description</LibraryDescription>
    <LibraryVersion>Library Version</LibraryVersion>
</ProjectConfiguration>
  • Change the template settings  to your needs:
    • EngineerVersion sets the minimum PLCnext Engineer version to use with this library; the entry must be in the format 202#.# or 202#.#.#.
    • LibraryVersion and LibraryDescription are format-free text entries.

 

Using multiple namespaces

Available from 2022.0 LTS

It is possible to use multiple namespaces. That means that helper classes e.g. from external libraries can be in a completely different namespace than the actual components or programs which use them. No special treatment is required in order to work with multiple namespaces, but there are a few constraints to that feature:

  • All components and programs must be in one root namespace. Meaning, if there is a component A::Component then all other components and programs must be in the namespace A or any subordinate namespace of A.
  • Structures for ports can be in a different namespace than the class which defines the port, but each structure name must be unique.
    • Not allowed: a structure A::B::Struct and a structure A::C::Struct
    • Allowed: a structure A::B::BStruct and a structure A::C::CStruct

 

Using multiple source folders

Available from 2022.0 LTS

It is possible to use multiple source folders in a build configuration. Each source folder can contain helper classes as well as components, programs and port structures. In addition to the configuration in the Eclipse or Visual Studio IDE, or using the PLCnext CLI option, it is necessary to adapt the CMakeLists.txt accordingly.

Adapting the CMake configuration

The following folder structure will be used as an example:
example structure

In the above example there are two source folders second_src and src. To work with these two source folders, do the following changes to the CMakeLists.txt:

  • Find the following lines:

    file(GLOB_RECURSE Headers src/*.h src/*.hpp src/*.hxx intermediate/code/*.h intermediate/code/*.hpp intermediate/code/*.hxx)
    file(GLOB_RECURSE Sources src/*.cpp intermediate/code/*.cpp)

    and add second_src/*.h second_src/*.hpp second_src/*.hxx for the header files,
    and add second_src/*.cpp for the source files:

    file(GLOB_RECURSE Headers src/*.h src/*.hpp src/*.hxx intermediate/code/*.h intermediate/code/*.hpp intermediate/code/*.hxx second_src/*.h second_src/*.hpp second_src/*.hxx)
    file(GLOB_RECURSE Sources src/*.cpp intermediate/code/*.cpp second_src/*.cpp)
  • Using this example:

    target_include_directories(ExternalSourceIncludeTest
        PUBLIC
        $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/intermediate/code>
        $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>)
    

    ...add the following section:

    PRIVATE
    $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/second_src>

    ...resulting in:

    target_include_directories(ExternalSourceIncludeTest
        PUBLIC
        $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/intermediate/code>
        $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
        PRIVATE
        $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/second_src>
    )

Configuring Eclipse for multiple source folders

There is also an option added for the Eclipse IDE, which have to be set in case an additional folder should be used. This sets automatically the --sources in all generate steps.

  • To add a source folder select FileNewSource Folder.
  • Enter your new folder name or Browse... for an existing one.
    Add new source folder wizard
Note: New source folders still have to be added to the CMakeList.txt as described above.

Configuring Visual Studio for multiple source folders

You can add another source folder with Visual Studio® IDE as well. This sets automatically the --sources in all generate steps.

Multiple source folders are set in the project's Configuration Properties at the PLCnext Technology branch, which comes with the Visual Studio extension.  If the option contains a value, the entered folders will then be used as source folders during a build.

  • Right-click your project in the Solution Explorer and select Properties.
    Add new source folder wizard
  • In the left-side menu of the dialog box, navigate to PLCnext TechnologyPLCnCLI Build.
  • At Source Folders , enter the source folders as a comma-separated list.
    Note: Do not forget to add src to the list if you want to keep the default source folder.

Using the PLCnext CLI --sources option

The --sources option is available with the plcncli generate commands (code, config, all, library). Working with more than a single source folder, the --sources option must be used to pass each source folder to the commands.

This would be the PLCnext CLI option with both source folders:

plcncli generate all -p "C:/Temp/ExternalSourcesTest" --sources "second_src,src"

Note: New source folders still have to be added to the CMakeList.txt as described in the section above.

Additional build, deploy, or generate options

Available from 2022.0 LTS

There are several options which can be activated or deactivated to meet special requirements in the development process for PLCnext Technology.

Note: New source folders still have to be added to the CMakeList.txt as described above.

Additional build, deploy or generate options

These options are part of the project properties in the Eclipse® add-in as well as in the Visual Studio® extension. Those properties can be 

Working with Eclipse®

  • Open up the Project Properties
  • In the left-side menu navigate to C/C++ BuildSettings  and there to the Tool Settings tab of the selected build configuration.

Working with Visual Studio®

  • Right-click your project in the Solution Explorer and select Properties.
  • In the left-side menu of the dialog box, navigate to PLCnext TechnologyPLCnCLI Build.

Note: These additional options are added to the end of the CLI command sent by the IDE. They are only meant for workarounds, or in case of issues.

Disabling build steps

Available from 2022.0 LTS

The build action of the IDEs always perform the whole sequence generate allbuild all and deploy all. If the generate step is active it always generates the datatype worksheet. That can be deactivated separately. If it is necessary to skip a step, the following options can be used.

Working with Eclipse®

  • Open up the Project Properties
  • In the left-side menu navigate to C/C++ BuildSettings  and there to the Tool Settings tab of the selected build configuration.
  • In the PLCnCLI - Metadata Generation --> Meta Generation Settings it is possible to just uncheck the Generate IEC datatype worksheet step.

disable worksheet generation

To edit the order of steps, to remove or add build steps in Eclipse you have to navigate to C/C++ BuildTool Chain Editor. There you can open up a wizard via the Select Tools... Button on the right of the Used tools list.

Select tools wizard

  • Check the box to Allow all changes and configure the tools as necessary.

Working with Visual Studio®

In Visual Studio open up the project properties and navigate on the left side menu to PLCnext Technology --> PLCnCLI Build. Here you can set the options Disable Generate Step (default value No), Disable Deploy Step (default value No) or Generate Datatype Worksheet (default value Yes).

 

Custom CMake flags

Available from 2021.6

To make use of additional CMake options, you can add a CMakeFlags.txt file to the project's root folder.

Note: There is no validation mechanism, so any text can be saved. It is the your responsibility to enter valid flags.

Working with Eclipse®

With the Eclipse® PLCnext Technology add-in, go to ProjectProperties and navigate on the left side menu to C/C++ BuildSettings. In the dialog on the right, go to the PLCnext Cmake Flags tab:

Custom Cmake Flags

Working with Visual Studio®

The same file can be edited via the Visual Studio extension. If you need to add CMake flags to your build, right click on your project in the Solution Explorer, select PLCnext Technology → CMake Flags:

VS CMake Settings

Working with another or without IDE

Add one additional option per line, for example:

-G "Unix Makefiles"
-DCMAKE_MAKE_PROGRAM="mymakepath"

 

 

 


•  Web browser recommendation: Chrome/Edge 88 or newer, Firefox ESR 90 or neweror Safari • 
• Published/reviewed: 2022-09-14 • Revision 046 •