Makers Blog Archive

How to use the .Net Core on a PLCnext Control

gbreder@phoenixcontact.com 27 August 2018 min. read
564 views 0 comments

If you’re a C# programmer working with a PLCnext Control then you might want to use the Microsoft® .NET Core runtime. Here’s how to install it on an AXC F 2152 control.

Set up the runtime on the PLC

  1. Download the Dotnetcore Runtime Binaries (Microsoft .NET Core download site);
    for the AXC F 2152 it is Linux ARM 32bit.
     Note: You may also use a newer version, e.g. 3.0
  2. Unzip the Runtime .zip file
  3. Unzip the Data folder
  4. Copy the unzipped files (host, shared and dotnet binary) to the controller at /opt/DotnetRT
  5. Create a symlink to the binary (as root user):
    ln -s /opt/DotnetRT/dotnet /usr/local/bin/dotnet
  6. Check if the link is setup correctly:
    lrwxrwxrwx 1 admin plcnext 20 Nov 27 12:50 dotnet -> /opt/DotnetRT/dotnet
  7. Check if installation was succesful with dotnet --info
admin@axcf2152:/opt/plcnext$ dotnet --info Host (useful for support): Version: 2.1.1 Commit: 6985b9f684 .NET Core SDKs installed: No SDKs were found. .NET Core runtimes installed: Microsoft.NETCore.App 2.1.1 [/opt/DotnetRT/shared/Microsoft.NETCore.App 

Create a project

  1. Switch to a PC for development and building of your .Net Core apps
  2. Install .Net Core SDK
  3. Create a new application dotnet new console -o MyFirstTestProgram
  4. Switch to the folder MyFirstTestProgram
  5. Write your code at Program.cs – by default there is a “Hello World!” program
  6. Build it with dotnet build
  7. Switch to MyFirstTestProgram/bin/Debug/netcoreappX.X/
  8. Modify MyFirstTestProgram.runtimeconfig.json and set "System.Globalization.Invariant": true
{ "runtimeOptions": { "tfm": "netcoreapp2.1", "framework": { "name": "Microsoft.NETCore.App", "version": "2.1.0" }, "configProperties": { "System.Globalization.Invariant": true } } } 

Deploy and run your application

  1. Copy MyFirstTestProgram/bin/Debug/netcoreappX.X/ to the controller at /opt/MyFirstTestProgram
  2. Execute the .Net application with
    dotnet MyFirstTestProgram/netcoreapp2.1/MyFirstTestProgram.dll
Hello World!

Access I/O data from a C# application running on the .Net Core

To access the GDS and the I/Os, use .Net sockets, Modbus or a REST implementation in a C++ ESM program.

Note:

The Makers Blog shows applications and user stories of community members that are not tested or reviewed by Phoenix Contact. Use them at your own risk.

Discussion

Please login/register to comment

Login/Register

Leave a Reply

Newsletter
Never miss a new article
Sign up for the newsletter
Never miss news about PLCnext Technology
Get interesting content via newsletter four times a year
Receive exclusive information before all other users