Working with Visual Studio
This topic describes the general approach to C++ programming with Microsoft® Visual Studio® IDE using the iCube Engineer C++ Extension. Of course, you might use also the Eclipse® IDE, or any other IDE or code editor instead.
Creating a C++ project from a iCube Engineer Toolchain project template
- Start a new project either via the Startup Wizard, or use the menu: File → New → Project...
- Search for iCube Engineer in the dialog box to show only the iCube Engineer Toolchain project templates
-
Select the project template that fits your needs; then click
Next:
-
In the next dialog box, configure your basic project data, then click
Create:
-
In the pop-up dialog, select the target device(s) and firmware version(s) for the project, then click
OK:
If several SDKs are installed on your computer, you can select multiple targets and firmware versions to be supported by the project. The PLCnext CLI will build your project for all of them automatically and put them into a single iCube Engineer library.
Creating a C++ program
To create a C++ program which can be imported as a library into iCube Engineer, you must first prepare a new project in accordance with the description above.
The new project has a defined structure in which the C++ program is created as shown in this example:
The new project has a defined structure in which the C++ program is created as shown in this example:
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 (search for this comment:
//TODO implement program).
↪ After instantiation of a program, the assigned ESM task calls the Execute() function of the program instance in each cycle.
Importing an existing toolchain project
To import an existing toolchain project, which wasn't created by Visual Studio (e.g. via command line or Eclipse)
- Open Visual Studio® without opening an existing code sheet
- In the menu, go to Select File → New → Project from existing PLCnCLI project...
-
Browse for the .proj file of your existing toolchain project, then click
Continue
↪ Visual Studio is now adding all missing files and opening the generated project.
Adding or removing components and programs
Adding a component
- Right-click on the project.
- Select Add → New Item... from the context menu.
-
In the pop-up dialog box, search for iCube Engineer in the search field on the upper right side:
- Select the iCube Engineer Component item.
- Give the component a name and click Add.
-
In the next step, select a namespace; by default it is the project namespace.
The component is added to your C++ project.
Adding a program
- Right-click on the project.
- Select Add → New Item... from the context menu.
-
In the pop-up dialog box, search for iCube Engineer in the search field on the upper right side:
- Select the iCube Engineer PLM Program item.
- Give the component a name and click Add.
-
In the next step, select a
Parent Component
to use, and a namespace; by default it is the project namespace.
- The program is added to your C++ project.
Removing a component
Removing a C++ component from your project requires three steps in this order:
- Delete the corresponding source file and header file of your component. Make sure to permanently remove them.
- Delete all programs assigned to this component, or reassign them to another existing component.
- Remove all intermediate files from previous builds. For this, simply right-click on your project and select Clean.
The component is properly removed from your C++ project.
Removing a program
To remove a program, simply delete the corresponding source file and header file.
- Select the two files, right-click on the selection, and choose Remove from the context menu (or simply press Del)
- In the dialog box, click Delete to delete the files permanently from the file system.
The program is properly removed from your C++ project.
Using a C++ program with iCube Engineer
To be able to use your C++ program in iCube Engineer, you need it compiled into a
*.pcwlx
library for use with iCube Engineer. The LibraryBuilder (which is part of the C++ toolchain) automatically generates the library within the process of compilation. The file is located in the project folder, e.g.
C:/Users//workspace/FirstProject/Bin
.
- Import the library into your iCube Engineer project.
- Assign the C++ program to a task.