Skip to content

Collection of various C++ sample code for PLCnext Technology controllers.

License

Notifications You must be signed in to change notification settings

PLCnext/CppExamples

Repository files navigation

PLCnext Technology - CppExamples

Feature Requests Bugs License Web Community

The CppExamples repository is a collection of various sample code for PLCnext Technology controllers. It is assumed that the reader has basic know-how of C++ programming and has read the key parts of the PLCnext Info Center.
Each example explains one or more topics on how to use C++11 with PLCnext Technology. Explanations are given in the README.md document and via comments in the example code. Each example holds separate user components which can be instantiated on a PLCnext Control.

This project aims to supply, over time, examples and best practices of PLCnext Technology functions regarding C++11.

Table of Contents

# Topic Content SourceCode
01 E-Learning: InternalFunctionExtensions This describes how to use the Internal Function Extensions. SourceCode
02 Data Type Exchange Example This example shows how to transfer data from a C++ project to the GDS by declaring Port variables in C++. Variables published to the GDS can be accessed by other programs (IEC/C++/Simulink/C#) or the IOs SourceCode
03 Dynamic GDS ports example This example shows how to create and use dynamic GDS ports on a C++ program. SourceCode
04 ComponentPorts This example shows how to initialize ComponentPorts using PLC events like Cold/Warm/Hot-Start similar to ProgramPorts. SourceCode
05 Program Component Interaction This example shows two PLCnext programs interacting with a PLCnext component by getting or setting variables through reference. SourceCode
06 Thread Example This describes how to implement Threads in a component of C++ project. SourceCode
07 BufferedExchange Example This example shows how to communicate larger amounts of data between a Program and a Component and how to process these data using a Thread SourceCode
08 Data Access Example This example shows how to read and write GDS variables using the Data Access service. SourceCode
09 Subscription Example This example shows how to read GDS variables using the Subscription service. SourceCode
10 Force Example This example shows how GDS variables can be forced using the Force service. SourceCode
11 Notification Example This example shows how to use the Notification Manager. SourceCode
12 Trace Control Example This example shows how to use the Trace Controller service. SourceCode
13 Commons::Io::FileStream Example This Example shows how to use a File Stream to check the binary generation timestamp whenever a Component is reinitialized. SourceCode
14 Include an Open Source Library This describes how to use a third-party open-source library in a C++ project that is built for PLCnext Control using Eclipse
15 OPC UA Methods This example shows how to use OPC UA methods to execute functions in an ACF component written in C++. SourceCode
16 PLM/ESM/GDS Configuration without PLCnext Engineer This example shows how to configure C++ programs to run on a PLC without using PLCnext Engineer.

Getting started

Compiling an example

There are different ways to build your code:

Compile the code with the PLCnext CLI

  1. Install Eclipse IDE, CLI, SDK and Eclipse Add-in (how-to guide: see links in the "Getting started" section above)
  2. Clone this repository
  3. Navigate to the project you want to test, e.g. cd Examples/ProgramComponentInteraction
  4. Execute plcncli new project -c DummyC -p DummyP && ls -la src && rm src/Dummy* or plcncli new acfproject -c DummyC && ls -la src && rm src/Dummy* for acf projects
  5. Execute plcncli set target --add --name AXCF2152 --version 2020.6 to specify details of the build target
  6. Execute plcncli generate all to generate intermediate code and Config files
  7. Execute plcncli build to build the code.
  8. Execute plcncli deploy to generate a .pcwlx file that can be included in PLCnext Engineer

Compile using the Eclipse Add-in

  1. Create a new empty project named like the example you want to test
  2. Remove the source files located at ProjectName/src
  3. Move the source files from the example you want to use into your workspace at ProjectName/src
  4. Build the project

Compile using build.sh script

  1. Clone this Repository
  2. Modify the build.sh script to fit your needs
    1. select hardware
    2. select project
    3. rename folder to fit namespace name (e.g. mv Examples/OpcUaMethodExample Examples/OpcPlcManager)
    4. switch between acfproject and project command if necessary
  3. Make sure it is executable for example with chmod +x tools/build.sh
  4. Execute the script ./tools/build.sh or sh tools/build.sh

Contributing

You can participate in this project by submitting bugs and feature requests.
Furthermore you can help us by discussing issues and letting us know where you have problems or where others could struggle.

Feedback

License

Copyright (c) Phoenix Contact GmbH & Co KG. All rights reserved.

Licensed under the MIT License.

About

Collection of various C++ sample code for PLCnext Technology controllers.

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages