- Introduction
- Example details
- Preconditions
- Project compiling in Eclipse
- PLCnext Engineer project
- Start-Up instructions
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 Info Center.
Description | Value |
---|---|
Controller | AXC F 2152 |
FW | 2021.9 |
SDK | 2021.9 |
PLCnext CLI | 2021.6 |
PLCnext Engineer | 2021.9 |
- PLCnext Control AXC F 2152 with firmware 2021.6 or later
- PLCnext Engineer 2021.6 or later
- Eclipse® IDE "Photon" or later
- 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 "COMPONENT" area under "Programming" -> "Datatypes" create an new datatype worksheet and include the following user-defined datatypes:
TYPE STRING420:STRING[420]; WSTRING420:WSTRING[420]; bool_array: ARRAY[0..9] OF BOOL; //8Bit sint_array: ARRAY[0..9] OF SINT; usint_array: ARRAY[0..9] OF USINT; //16Bit int_array: ARRAY[0..9] OF INT; uint_array: ARRAY[0..9] OF UINT; //32Bit dint_array: ARRAY[0..9] OF DINT; udint_array: ARRAY[0..9] OF UDINT; //64Bit lint_array: ARRAY[0..9] OF LINT; ulint_array: ARRAY[0..9] OF ULINT; //8Bit byte_array: ARRAY[0..9] OF BYTE; //16Bit word_array: ARRAY[0..9] OF WORD; //32Bit doubleword_array: ARRAY[0..9] OF DWORD; //64Bit Lword_array: ARRAY[0..9] OF LWORD; //xx digit precision real_array: ARRAY[0..9] OF REAL; //xx digit precision Lreal_array: ARRAY[0..9] OF LREAL; //Strings String_array: ARRAY[0..9] OF STRING; Wide_string_array: ARRAY[0..9] OF WSTRING; END_TYPE
-
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 Info Center.
-
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.
- 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 see the error messages in Output.log file on the PLCnext target: /opt/plcnext/logs/Output.log