This is part of a series of articles that demonstrate how to create a runtime application for PLCnext Control. Each article builds on tasks that were completed in earlier articles, so it is recommended to follow the series in sequence.
In the previous article, a simple "Hello World" application was run on a PLCnext Control device.
In order for a runtime application to access PLCnext Control services like Axioline I/O, a specific set of Automation Runtime Platform (ARP - i.e. PLCnext) components must be running. Most of these components are started automatically by the ARP, but two additional components - required for ANSI-C access - must be started in our application process.
Using an Application Component Framework (ACF) configuration file, we will instruct the PLCnext to automatically start and stop our runtime application with the ARP, and to load the required application-specific PLCnext components.
Then, using an ACF settings file, we will specify a directory where we want application log files to be created and stored.
The required files will be created automatically using a new PLCnext CLI project template.
-
Install the "runtime" PLCnext CLI project template
Copy the
RuntimeTemplate
directory and its contents from this repository to the PLCnext CLI Templates directory on your development machine, e.g.cp -r RuntimeTemplate ~/plcncli/Templates
-
Include the new template in a CLI Templates file
For example, create a file called
CustomTemplates.xml
in the PLCnext CLITemplates
directory, containing the following:<?xml version="1.0" encoding="utf-8"?> <Templates xmlns="http://www.phoenixcontact.com/schema/clitemplates"> <Include type="Template">RuntimeTemplate/TemplateDescription.xml</Include> </Templates>
-
If a new Templates file was created, register it with the PLCnext CLI
plcncli set setting TemplateLocations ./Templates/CustomTemplates.xml --add
-
Check that the new template has been installed correctly.
plcncli new
You should see
runtime_project
listed as an option:plcncli 22.0.0 LTS (22.0.0.952) Copyright (c) 2018 PHOENIX CONTACT GmbH & Co. KG ERROR(S): No verb selected. : runtime_project Create a new runtime project. :
-
Create a new project called
Runtime
cd ~ plcncli new runtime_project --name Runtime
This will automatically create a number of files, including:
data/Runtime.acf.config
In this configuration file, the
Processes
element tells the Application Component Framework (ACF) to start and stop ourRuntime
application with the plcnext process. TheLibraries
andComponents
elements tell the ACF to start special PLCnext Control components that our application will use to (for example) access Axioline I/O through an ANSI-C interface.data/Runtime.acf.settings
This file gives the ACF additional information in order to run our application.
The value of the
logDir
attribute in theLogSettings
element is the path where log files for this application will be created, relative to the application's working directory.src/Runtime.cpp
-
Runtime applications must call the PLCnext Control function
ArpSystemModule_Load
, which notifies the ACF that the runtime application has started successfully. Through this call, the application also provides the path to an.acf.settings
file. If this function is not called, the runtime application will not be able to access any PLCnext services, and it will be stopped after a short timeout period. -
The template assumes that the name of the
.acf.settings
file is passed as a command-line argument. The absolute path to this file is added by the code. -
Runtime applications must never end. The PLCnext Control expects runtime applications to keep working until it tells them to stop. This template includes an infinite loop that simply sleeps for 1 second while waiting for the PLCnext Control to kill the runtime process.
-
Like all other PLCnext Control functions, the logging function is not available until after the call to
ArpSystemModule_Load
, and until then this template usessyslog
to log messages.
-
-
Set the application target(s)
cd ~/Runtime plcncli set target --name AXCF2152 --version 2022.0 --add
-
Build the project to generate the
Runtime
executable.plcncli build
-
Deploy the executable to the PLC.
ssh [email protected] 'mkdir -p projects/Runtime' scp bin/AXCF2152_22.0.4.144/Release/Runtime [email protected]:~/projects/Runtime
Note: If you receive a "Text file busy" message in response to this command, then the file is probably locked by the PLCnext Control. In this case, stop the plcnext process on the PLC with the command
sudo /etc/init.d/plcnext stop
before copying the file. -
Deploy the
Runtime.acf.settings
file to your project directory on the PLC.scp data/Runtime.acf.settings [email protected]:~/projects/Runtime
The destination directory is the one we specified in the call to
ArpSystemModule_Load
. -
Deploy the
Runtime.acf.config
file to the PLC'sDefault
project directory.scp data/Runtime.acf.config [email protected]:~/projects/Default
All
.acf.config
files in this directory are processed by the ACF when the plcnext process starts up, via theDefault.acf.config
file in the same directory. -
Open a secure shell session on the PLC:
-
Create the
logs
directory for our application:mkdir /opt/plcnext/projects/Runtime/logs
-
Restart the plcnext process:
sudo /etc/init.d/plcnext restart
-
Give the plcnext process a short time to start our application, and then check that our application has started successfully by examining the plcnext log file:
cat /opt/plcnext/logs/Output.log | grep Runtime
The result should be something like:
12.05.22 13:35:28.218 Arp.System.Acf.Internal.Sm.ProcessesController INFO - Process 'Runtime' started successfully. 12.05.22 13:35:33.577 Arp.System.Acf.Internal.Sm.ProcessesController INFO - Library 'Arp.Plc.AnsiC.Library' in process 'Runtime' loaded. 12.05.22 13:35:33.583 Arp.System.Acf.Internal.Sm.ProcessesController INFO - Library 'Arp.Plc.Domain.Library' in process 'Runtime' loaded. 12.05.22 13:35:33.594 Arp.System.Acf.Internal.Sm.ProcessesController INFO - Library 'Arp.System.UmRscAuthorizator.Library' in process 'Runtime' loaded. 12.05.22 13:35:33.734 Arp.System.Acf.Internal.Sm.ComponentsController INFO - Component 'Arp.Plc.AnsiC' in process 'Runtime' created. 12.05.22 13:35:33.735 Arp.System.Acf.Internal.Sm.ComponentsController INFO - Component 'Arp.Plc.DomainProxy.IoAnsiCAdaption' in process 'Runtime' created. 12.05.22 13:35:33.737 Arp.System.Acf.Internal.Sm.ComponentsController INFO - Component 'Arp.System.UmRscAuthorizator@Runtime' in process 'Runtime' created.
-
Check the contents of the application log file:
cat /opt/plcnext/projects/Runtime/logs/Runtime.log
You should see a number of formatted output messages, including a message similar to the following:
12.05.22 13:35:27.719 root INFO - Hello PLCnext
Copyright © 2020-2022 Phoenix Contact Electronics GmbH
All rights reserved. This program and the accompanying materials are made available under the terms of the MIT License which accompanies this distribution.