With
To use programs and program parts created in C++ within the scope of the
Recommended: Use the freely available Eclipse® software with
To use C++ programs in the same way as IEC 61131-3 applications in
If you quickly create a program with Eclipse® and want to make it available by using the Eclipse® add-in for
4.1Installing
|
|
An Internet connection is required for installing the components. |
|
|
A description of the |
•Before starting the installation, ensure that the system requirements are met and download the necessary software.
Operating system
–Microsoft® Windows® 7 or
–Microsoft® Windows® 10
Phoenix Contact software
–
The SDK contains all of the important tool chains and libraries required for creating a program.
–
The add-in for Eclipse® supports you during the creation of metafiles as well as IN and OUT ports.
–EngineeringLibraryBuilder:
The LibraryBuilder generates a library from the C++ program which can be read by
Software packages required for programming in C++ with Eclipse are to be found in the download area of the AXC F 2152 controller at phoenixcontact.net/products (order no.: 2404267)in the following categories:
–“Configuration software”: You will find the
–“Software”: You will find the Phoenix Contact LibraryBuilder for creating a library from Eclipse® for use in
Some sample applications for the AXC F 2152, programmed in C++, are available in the “Sample applications” category for downloading.
C++ development environment
–Eclipse® Neon 3 / Eclipse IDE for C/C++ Developers
•Download the Eclipse Neon 3 software with the package “Eclipse IDE for C/C++ Developers” from https://www.eclipse.org.
Java Runtime Environment
–Oracle® Java™ Runtime Environment
•Download the Java Runtime Environment from https://java.com/de.
.NET Framework
–Microsoft® .NET Framework 4.6.1
•Download the .NET Framework from https://www.microsoft.com.
|
|
If you use |
Installing the Java™ Runtime Environment
The Java™ Runtime Environment is required for the Eclipse® development environment.
•Install the Java™ Runtime Environment.
•Follow the instructions of the installation wizard.
Installing the
.NET Framework
The .Net Framework 4.6.1 is required for the
•Install the .Net Framework.
•Follow the instructions of the installation wizard.
Installing and configuring
Eclipse®
A development environment is required for programming in C++. Phoenix Contact recommends Eclipse® Neon 3. The
•Execute the installation file for the Eclipse® Neon 3 software.
•In the dialog that opens, select the integrated development environment for C/C++ developers (Eclipse IDE for C/C++ Developers).
Figure 4-1 Selecting IDE for C/C++ Developers
•Then install the development environment.
•Follow the instructions of the installation wizard.
Installing the
Phoenix Contact SDK
•Unzip the downloaded SDK file into a directory of your choice. Please note that the directory name may not contain spaces.
•After unzipping, ensure that the directory contains all files displayed in Figure 4-2.
Figure 4-2 Unzipped Phoenix Contact SDK directory
The SDK is accessed during the creation of a new C++ project (see 4.2 “Creating a new project”).
Updating the SDK
Recommended:
Always use the latest version of the SDK. Uninstall earlier SDK versions. This is the only way to ensure that the various versions are not mixed.
Installing the
•Unzip the add-in.
•Open the Eclipse® software.
•In Eclipse®, open the menu “Help, Install New Software”.
•Select the path to the directory of the add-in. To do so, click on “Add” in the dialog that opens.
•In the dialog “Add Repository”, click on “Local” and select the directory of the add-in.
Figure 4-3 Selecting the path to the add-in directory
•In the next dialog, select the components displayed in Figure 4-4.
Figure 4-4 Selecting
•Click on the “Next” button.
•Read and accept the licence agreements.
•Click “Finish” to complete the installation.
•Restart Eclipse®.
Performing the add-in update for Eclipse®
To perform any necessary updates, proceed as follows:
•Update the
You can also copy the update file to the existing directory. Start the update as follows:
•In Eclipse®, open the menu “Help, Check for Updates” or “Help, Install New Software”.
Installing the
LibraryBuilder
•Unzip the downloaded LibraryBuilder file into a directory of your choice. Please note that the directory name may not contain spaces.
Now integrate the LibraryBuilder into Eclipse®. This is necessary to import C++ programs. as libraries in C++ into
•In Eclipse®, open the menu “Window, Preferences”.
•Then select “PLCnext”.
•Click on “PCWLX Export”.
•Click on the “Browse” button.
•Select the path to the LibraryBuilder.
•Click on the “Apply” button to apply the path.
Figure 4-5 Selecting the LibraryBuilder
•Then click on “OK”.
This section describes how to create a new C++ project in Eclipse®.
•Open the Eclipse® software.
•Open the menu “File, New, C++ Project”.
Figure 4-6 Creating a new C++ project
•Enter a project name in the “Project name:” input field.
•In the “Project type” field, select a project type (In the example in Figure 4-7 “ Entering a project name and selecting a project type”).
Figure 4-7 Entering a project name and selecting a project type
•Click on the “Next” button.
•If necessary, adapt the basic settings of the C++ project.
Figure 4-8 Basic settings of the C++ project
•Click on the “Next” button.
•In the “Configurations” area, activate the “Debug” and “Release” check boxes:
Figure 4-9 Activating the “Debug” and “Release” check boxes
•Click on the “Browse” button.
•Select the path to the directory “sysroots” of the unzipped Phoenix Contact SDK.
•Confirm your selection with “OK”.
•Click the “Finish” button to finish creating the project.
Figure 4-10 Selecting the path to the “sysroots” directory
•To start creating the C++ program, now switch to the “Workbench” view.
Figure 4-11 “Workbench” view in Eclipse®
To create a C++ program using Eclipse® which can be imported into
Ensure that the correct path to the “sysroots” directory of the unzipped
The created project has a defined structure in which the C++ program is created. Figure 4-12 shows an example.
Figure 4-12 Sample structure of a C++ project
Creating variables
The header file of your program (e.g. CPP_Counter_p.hpp) must contain the variable definition.
•Define the variables required for the C++ program as well as their initial values here. Some of the variables are used as IN or OUT ports. You will find further information on the IN and OUT ports and GDS in section GDS (Global Data Space).
•Create the variables necessary for your project.
Figure 4-13 Sample variable declaration wit initial values in the header file
•Save the changes to the header file.
Adding IN and OUT ports
Now register the IN and OUT ports for the GDS of the
To do so, proceed as follows:
•Switch from the header file (*.hpp) to the source file (*.cpp).
•Right-click in the line behind the comment “//TODO AddPortInfo”.
Figure 4-14 Inserting IN and OUT ports in the source file (*.cpp) (1)
•In the context menu that opens, select the entry “PLCnext, Insert Program Ports at position”.
Figure 4-15 Inserting IN and OUT ports in the source file (*.cpp) (2)
The add-in now generates a list of all available variables from the header file. You can define all variables of the list as IN or OUT ports.
Figure 4-16 List of all available variables is being created
•From the list, select the variables that you wan to use as IN or OUT ports.
Figure 4-17 Example: List of all available variables
•Confirm your selection with “OK”.
The IN and OUT ports are created at the respective location in the source file with the required syntax. You can furnish these with individual comments if necessary (e.g. “//Inports”).
Figure 4-18 Sample IN and OUT ports in the source file *.cpp
The definition of IN and OUT ports consists of two parameters:
–Parameter 1: Name of the IN port or OUT port. The name is used to create the reference to the GDS configuration and to the *.progmeta file. The name must match in all three positions. However, the name can deviate from the variable name (see Notes on designating GDS ports).
–Parameter 2: Reference to the variable to be used as port. The data direction (IN or OUT port) is determined in the *.progmeta file.
•Save the changes to the source file.
Generating the
*.progmeta file
If you defined the variables as IN and OUT ports in the source file, you have to add and configure the IN and OUT ports in the *.progmeta file. You can also perform this task with the add-in. Generate the IN and OUT ports in the *.progmeta file using the
To generate the file, proceed as follows:
•Right-click anywhere in the open editor of the *.cpp file (* = file name).
•In the context menu that opens, select the entry “PLCnext, Generate .progmeta Metaconfig”.
Figure 4-19 Generating the *.progmeta file
The *.progmeta file is being generated. Now define whether the generated ports are IN or OUT ports (INTERNAL ports are intended for a later extension).
•Open the newly generated *.progmeta file.
•Open the “Design” tab.
•In the “Node” column, navigate to the “Ports” entry.
•In the “Content” column, right-click to open the context menu in the “kind” line of a port.
•Choose the type of the desired port.
•Repeat this procedure for all IN and OUT ports used.
The add-in enters the data type in the “type” line.
•Inspect the data type in the “type” input field.
Figure 4-20 Example *.progmeta file in the “Design” tab
All settings made in the “Design” tab are applied to the source text of the *.progmeta file. You can also edit directly in the source text.
•Switch to the “Source” tab to view the settings in the source code of the *.progmeta file.
Figure 4-21 Sample settings in the source code of the *.progmeta file on the tab “Source”
Creating a C++ program
•Open the *.cpp source file.
•Program the code to be executed in each ESM task pass in the “Execute()” function (see “//TODO implement program”).
After the instantiation of a program, the assigned ESM task calls up the “Execute()” function of the program instance in each cycle.
|
|
Sample projects and the associated documentation are available for downloading on the AXC F 2152 controller page (order no.: 2404267): phoenixcontact.net/products. |
Compiling a project
•Switch to the “Project Explorer” to compile the project.
Figure 4-22 Project folder in the “Project Explorer”
•Right-click to open the context menu for the project folder (in the example: “CPP_Counter”).
•In the context menu, click on “Build Project”.
To view whether the compilation of the project was successful or to view possible error messages, switch to the “Console” tab.
Figure 4-23 Example: “Console”
If the compilation was successful, a shared object (*.so) is generated. You will find this in the “Release” folder of the Project Explorer.
Figure 4-24 Example: Shared object (*.so) in the Project Explorer
Generating a
In order that you can use the C++ project in
•Right-click to open the context menu for the project folder (in the example:
“CPP_Counter”).
•Select “PLCnext, Export PCWLX”.
Figure 4-25 Generating a
•Click on the “Browse” button.
•Select the path to the directory to which the *.pcwlx library is to be stored.
Recommended: Standard path for storing
C:\Users\Public\Documents\PC Worx Engineer\Libraries
Figure 4-26 Selecting a memory path for the *.pcwlx library to be generated
•Click on the “Finish” button to generate the *.pcwlx library.
4.4Importing generated libraries into
|
|
You will find additional information on |
Once you have generated a library from a C++ program, import this library into the
To import a library into
•Open your
•In the “COMPONENTS” section, click on “References”.
•Right-click on “Libraries”.
Adding a library
•Right-click to open the “Add Library” context menu.
Figure 4-27 “Add library” context menu
•In the dialog that opens, select the desired *.pcwlx library.
•Click on “Open”.
If you have created the *.pcwlx library in Linux
Components and programs are now available in the section “COMPONENTS” under “References”.
Figure 4-28
Instantiating a program
To instantiate the program contained in the library, proceed as follows:
•In the section “PLANT”, select the node “PLCnext”.
•Open the “Tasks and Events” editor.
Figure 4-29 Opening the “Tasks and Events” editor
•In the editor, create a new task or open an existing task.
•Drag and drop the library from the section “COMPONENTS, References” to the “ESMX” column of the task. This way you generate a program instance.
Figure 4-30 Example: Program instance CPP_Counter_P1 in the “Task and Event” editor
Assigning IN/OUT ports
•In the section “PLANT”, select the node “PLCnext”.
•Open the “Data List” editor.
In the “Data List” editor, all IN and OUT ports saved to the GDS of the controller are displayed. The IN and OUT ports of the newly instantiated program are displayed. To use the IN/OUT ports of the imported library, you must assign the IN and OUT ports of the imported libraries to the IN and OUT ports of other program instances so that consistent data exchange can take place.
Assigning an IN port to an OUT port
•In order to assign an IN port to an OUT port, click on “Select IN Port here” in the “IN Port” column.
The role picker opens. Only the IN ports that you can actually assign to the respective OUT port are displayed in the role picker.
•Select the IN port that you want to assign to the relevant OUT port in the role picker.
•The IN port is assigned to the OUT port.
•Proceed as described for other IN ports.
Assigning several IN ports to an OUT port
•Assign an IN port to an OUT port as described in the previous section.
•To assign further IN ports to an OUT port, duplicate it.
•Right-click on the OUT port and select the option “Duplicate Out port” in the context menu.
Figure 4-31 Duplicating an output port
•To assign an IN port to the duplicated OUT port, proceed as described in the previous section.
Assigning an OUT port to an IN port
•In order to assign an OUT port to an IN port, click on “Select OUT Port here” in the “OUT Port” column.
The role picker opens. Only the OUT ports that you can actually assign to the respective IN port are displayed in the role picker.
•Select the OUT port that you want to assign to the relevant IN port in the role picker.
The OUT port is assigned to the IN port.
•Proceed as described for other OUT ports.
•Observe the instructions in section 2.6.2 “Supported data types”.
Figure 4-32 “Data List” editor
Once you have assigned all IN and OUT ports to be used, transfer the
A description on how to set up a remote debugging session for a running process is available in the PLCnext Community.
Several example programs created with Eclipse® and the Phoenix Contact add-in for Eclipse® are available in the download area of the AXC F 2152 controller under the address phoenixcontact.net/products (Order No.: 2404267). The examples illustrate aspects of programming with C++ within the framework of the