This example demonstrates the creation and usage of port variables in PLCnext Engineer and C++ applications for data exchange via elementary data types. All supported elementary data types are documented in the PLCnext Technology Info Center.
| Description | Value |
|---|---|
| Controller | AXC F 2152 |
| FW | 2025.0 |
| SDK | 2025.0 |
| Toolchain | 2025.0 |
| PLCnext Engineer | 2025.0 |
- PLCnext Control AXC F 2152 with firmware 2025.0
- PLCnext Engineer 2025.0
- Eclipse® IDE for C/C++ Developers version 2025-03
- In Eclipse create a project "CppDataTypeTest" with component "CppDataTypeTestComponent" and program "CppDataTypeTestProgram".
- In the project replace the files "CppDataTypeTestProgram.cpp" and "CppDataTypeTestProgram.hpp" with files from this repository. Alternatively you can create your own project with component and programs and include the source code of "CppDataTypeTestProgram.cpp" and "CppDataTypeTestProgram.hpp" in your source code files.
- Compile the Eclipse project.
- After successful project compilation, the PLCnext Engineer .pcwlx library will be created automatically. You can find it in the Eclipse workspace folder; e.g.: "workspace\CppDataTypeTest\bin\CppDataTypeTest.pcwlx".
-
In PLCnext Engineer create a new project and add the user library "CppDataTypeTest.pcwlx" to the project.
-
Instantiate the program "CppDataTypeTestProgram" under a previously defined task.
-
In the "COMPONENTS" area, under "Programming" -> "Local" -> "Data Types", create a new datatype worksheet and include the following user-defined datatypes:
TYPE byte_array : ARRAY[0..9] OF BYTE; word_array : ARRAY[0..9] OF WORD; doubleword_array : ARRAY[0..9] OF DWORD; Lword_array : ARRAY[0..9] OF LWORD; END_TYPE(all other custom types are generated automatically).
-
Declare one IN port variable for each of the user-defined and elementary datatypes in a program, e.g. "Main". Find a table of elementary datatypes in the PLCnext Technology Info Center. To make this easier, a .csv file containing these variable definitions is included in this repository, which you can import into a Variable Table in the PLCnext Engineer project.
-
Connect the C++ port variables and IEC 61131 port variables under the "PLCnext" node in the "PLANT" area of PLCnext Engineer.
-
Download the PLCnext Engineer project to the PLCnext Control device.
- If the project is successfully implemented and downloaded, you can follow the data exchange in PLCnext Engineer running in debug mode and/or in the watch window of PLCnext Engineer.
- If the project did not start successfully, please check for error messages in the diagnostic log files on the PLCnext Control device.