Skip to content

Latest commit

 

History

History

CppDataTypeTest

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

Table of contents

  1. Introduction
  2. Example details
  3. Preconditions
  4. Project compiling in Eclipse
  5. PLCnext Engineer project
  6. Start-Up instructions

Introduction

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.

Example details

Description Value
Controller AXC F 2152
FW 2021.9
SDK 2021.9
PLCnext CLI 2021.6
PLCnext Engineer 2021.9

Preconditions

  • PLCnext Control AXC F 2152 with firmware 2021.6 or later
  • PLCnext Engineer 2021.6 or later
  • Eclipse® IDE "Photon" or later

Project compiling in Eclipse

  1. In Eclipse create a project "CppDataTypeTest" with component "CppDataTypeTestComponent" and program "CppDataTypeTestProgram".
  2. 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.
  3. Compile the Eclipse project.
  4. 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".

PLCnext Engineer project

  1. In PLCnext Engineer create a new project and add the user library "CppDataTypeTest.pcwlx" to the project.

  2. Instantiate the program "CppDataTypeTestProgram" under a previously defined task.

  3. 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
    
  4. 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.

  5. Connect the C++ port variables and IEC 61131 port variables under the "PLCnext" node in the "PLANT" area of PLCnext Engineer.

  6. Download the PLCnext Engineer project to the PLCnext Control.

Start-up instructions

  • 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