This tutorial shows how to create a simple “Hello World” console application for a PLCnext Control device. The application is written in C# and targets .NET (formerly known as ".NET Core").
Note that this tutorial is intended for C# applications that run entirely outside the PLCnext Runtime. For C# applications that target the eCLR, please refer to the eCLR section of the PLCnext Info Center.
The Installation tutorial showed how to install .NET on a PLC. In that case, multiple applications targeting .NET can be run on the PLC, with minimum duplication of common .NET dlls.
As an alternative, it is possible to run a .NET application on a PLC that does not have the .NET framework installed. In this case, all the .NET dependencies required for the application are deployed with the application. This may be suitable for projects that require only one .NET application on the PLC. Microsoft refer to this type of application as a Self-Contained Deployment.
This tutorial creates a simple self-contained console application for an AXC F 2152 PLCnext Control device.
This tutorial uses:
- AXC F 2152 with firmware 2025.6. .NET does not need to be installed on the device.
- Visual Studio 2022 with the .NET Desktop Development workload. No PLCnext Technology add-ins or SDKs are required in this case.
Procedure
-
In Visual Studio 2022, create a new project using the template C# Console App. This type of project can run on .NET on Windows, Linux and macOS.
Choose the latest Long Term Support version of the .NET Framework.
-
Add a file to the project root directory called
runtimeconfig.template.json, containing the following:{ "configProperties": { "System.Globalization.Invariant": true } }The reason for this property setting is described in the “Background Information” section of the Installation tutorial.
-
In Solution Explorer, right-click on the C# Project and select "Publish..."
-
In the Publish dialog, select the following:
Target: Folder
Specific Target: Folder
Location: (the default location is fine)
... then press "Finish" and "Close". A publish profile has now been created.
-
Edit the publish profile by selecting one of the pencil icons next to one of the settings. Change the following settings:
Deployment mode: Self-contained
Target runtime: linux-arm
File publish options: Produce single file
Save the new settings.
-
At the top of the window, press the "Publish" button.
-
When publishing is complete, select the "Navigate" link.
-
Copy the published file to the PLC using (for example) WinSCP.
-
Open a shell session on the PLC using (for example) PuTTY or ssh.
-
Check the format of the executable:
file /opt/plcnext/ConsoleApp1 ConsoleApp1: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-armhf.so.3, for GNU/Linux 2.6.32, BuildID[sha1]=887a06cd9735de5da4b686517f69d68779571cec, strippedThis confirms that the application has been built for the correct platform.
-
Make sure that the executable has execute privileges:
chmod a+x /opt/plcnext/ConsoleApp1 -
Run the application:
/opt/plcnext/ConsoleApp1 Hello World!
Leave a Reply
You must be logged in to post a comment.