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.
# | 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. |
There are different ways to build your code:
- Install Eclipse IDE, CLI, SDK and Eclipse Add-in (how-to guide: see links in the "Getting started" section above)
- Clone this repository
- Navigate to the project you want to test, e.g.
cd Examples/ProgramComponentInteraction
- Execute
plcncli new project -c DummyC -p DummyP && ls -la src && rm src/Dummy*
orplcncli new acfproject -c DummyC && ls -la src && rm src/Dummy*
for acf projects - Execute
plcncli set target --add --name AXCF2152 --version 2020.6
to specify details of the build target - Execute
plcncli generate all
to generate intermediate code and Config files - Execute
plcncli build
to build the code. - Execute
plcncli deploy
to generate a .pcwlx file that can be included in PLCnext Engineer
- Create a new empty project named like the example you want to test
- Remove the source files located at
ProjectName/src
- Move the source files from the example you want to use into your workspace at
ProjectName/src
- Build the project
Compile using build.sh script
- Clone this Repository
- Modify the build.sh script to fit your needs
- select hardware
- select project
- rename folder to fit namespace name (e.g. mv Examples/OpcUaMethodExample Examples/OpcPlcManager)
- switch between
acfproject
andproject
command if necessary
- Make sure it is executable for example with
chmod x tools/build.sh
- Execute the script
./tools/build.sh
orsh tools/build.sh
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.
- Ask a question in the PLCnext Community's Forum
- Request a new feature or example to be added on GitHub
- Vote for Popular Feature Requests
- File a bug in GitHub Issues
Copyright (c) Phoenix Contact GmbH & Co KG. All rights reserved.
Licensed under the MIT License.