Users of this guide should be familiar with:
-
Creating C++ programs for PLCnext Control devices, and using those programs in PLCnext Engineer projects. There is extensive information on this topic in the PLCnext Info Center.
-
Transferring files from a PC to the PLC using (for example)
scp
or WinSCP. -
Using a Linux shell.
When using C++ programs in a PLCnext Control project, the typical development process includes the following steps:
- Package the C++ component(s) and program(s) into a PLCnext Engineer library.
- Add the library to a PLCnext Engineer project.
- In PLCnext Engineer's "Tasks and Events" window, create one or more C++ program instances in ESM tasks.
- In PLCnext Engineer's "Port List" window, connect GDS ports to/from the C++ program instances.
In cases where the project does not include any IEC 61131 programs, it is possible to eliminate steps 1 and 2 above, and to complete steps 3 and 4 without using PLCnext Engineer. This guide demonstrates how to do this, using a simple example.
Description | Value |
---|---|
Created | 2.06.2021 |
Last modified | 7.10.2021 |
Controller | AXC F 2152 |
FW | 2021.6 |
Arpversion | 21.6.0.46 |
SDK | 2021.6 (21.6.0.46) |
PLCnext CLI | 21.0.0 LTS (21.0.0.489) |
- PLCnext Runtime configuration files, in the PLCnext Info Center.
In this example, a PLCnext Control device is configured as a Profinet device (slave). A real-time C++ program instance, running in an Execution and Synchronisation Manager (ESM) task, uses Global Data Space (GDS) variables to exchange data with the two Profinet Device (PND) system variables PND_S1_INPUTS
and PND_S1_OUTPUTS
. The complete project is configured without the use of PLCnext Engineer.
-
Configure the PLC System Services
This application example uses a PLC that must have the IEC feature disabled, and the PROFINET DEVICE feature enabled. Other applications that use the principles demonstrated in this example may not require these settings.
Using the PLCs Web Based Management interface, disable the IEC system feature, and enable the PROFINET DEVICE feature. The PLC must be rebooted for changes to take effect.
-
Create the C++ program.
Using your C++ tool of choice (Eclipse, Visual Studio or the PLCnext CLI), create a new PLCnext C++ project of type "Project". This type of project includes one PLM component and one C++ Program. Name the project “Pnd”, and leave the Component and Program names as the suggested defaults.
-
Create GDS port variables.
In the PndProgram.hpp file, create the following two port variables:
//#port //#attributes(Input) uint8 PND_S1_INPUTS[512] = {0}; //#port //#attributes(Output) uint8 PND_S1_OUTPUTS[512] = {0};
-
Build the C++ project.
-
Copy the C++ library and metadata to the PLC.
Recursively copy the entire contents of the project “Release” directory to the following directory on the PLC:
/opt/plcnext/projects/Pnd
The Pnd directory on the PLC should now contain the following directories and files:
|-auto-deployed-external-libraries |-Pnd.libmeta |-PndComponent | |-PndComponent.compmeta | |-PndProgram | | |-PndProgram.progmeta |-Pnd.typemeta |-lib | |-libPnd.so
You don’t need the
auto-deployed-external-libraries
directory, so you can delete that:rm -r /opt/plcnext/projects/Pnd/auto-deployed-external-libraries
Move the library file up one directory in the tree:
mv /opt/plcnext/projects/Pnd/lib/libPnd.so /opt/plcnext/projects/Pnd && rm -r /opt/plcnext/projects/Pnd/lib
This is required because some of the following configuration files assume this relative path.
-
Program Library Manager (PLM) configuration.
Copy the
pnd.plm.config
file from this repository to the following directory on the PLC:/opt/plcnext/projects/Default/Plc/Plm
This file will automatically be loaded by the PLM component of the PLCnext Runtime, and it contains instructions for loading your Pnd library and creating an instance of your PndComponent.
-
ESM configuration.
Copy the
pnd.esm.config
file from this repository to the following directory on the PLC:/opt/plcnext/projects/Default/Plc/Esm
This file will automatically be loaded by the ESM component of the PLCnext Runtime, and it contains instructions for creating an ESM task, assigning that task to ESM1, and creating an instance of your PndProgram in that task.
-
Library metadata configuration.
Copy the
pnd.meta.config
file from this repository to the following directory on the PLC:/opt/plcnext/projects/Default/Plc/Meta
This file will automatically be loaded by the PLCnext Runtime, and it contains type information for your library.
-
GDS configuration.
Copy the
pnd.gds.config
file from this repository to the following directory on the PLC:/opt/plcnext/projects/Default/Plc/Gds
This file will automatically be loaded by the GDS component of the PLCnext Runtime, and it contains the GDS port connection information between your program instance and the PND system variables in the PLC.
-
Activate the configuration.
Restart the PLCnext Runtime.
sudo /etc/init.d/plcnext restart
Check the
Output.log
file for any errors - there should be no errors!
The C++ program is now running and exchanging data with the system variables PND_S1_INPUTS
and PND_S1_OUTPUTS
. At the moment this data is all zeroes, which is not very interesting.
The next steps are left up to the user:
-
Write non-zero data to
PND_S1_OUTPUTS
.Change the code in the C++ program's
Execute
method, e.g. increment one or more elements of thePND_S1_OUTPUTS
array, and rebuild the C++ project. If there are no changes to the C++ GDS port definitions, you can simply replace the libPnd.so file on the PLC after every build and restart the PLCnext Runtime. -
Configure a Profinet controller.
Using another PLC as a Profinet controller, set up your device on the Profinet network. If required, the GSDML file for your device can be downloaded from the Phoenix Contact website.
The data written to
PND_S1_OUTPUTS
on the device can now be observed in the Profinet controller. -
Extend the application.
For example - use the techniques demonstrated in the BusConductor example to enable your C++ component to dynamically configure connected Axioline I/O modules, without using PLCnext Engineer. Your C++ program(s) can then exchange I/O data via GDS port variables.