PLCnext Technology integrates programming of different languages, and enables users to create real time components in C# using their familiar Microsoft® Visual Studio® as the integrated development environment. For More information please visit our Community.
The CSharpExamples
repository is a collection of various examples for PLCnext Technology controllers. It is assumed that the reader has basic knowledge about C# programming in general and has read the User Manual and the PLCnext Technology Quick Start Guide. Each example explains one or more topics. Specific explanations can be found in the ExampleName.md
file located next to the ExampleName.cs
# | Topic | Content |
---|---|---|
01 | Basics | Implements a basic counter. (Basics.cs) |
02 | ANY | Function and function block with "ANY" parameter. (FunWithANY_BIT.cs, FunWithANY_NUM.cs, FB1WithANY_BIT.cs, FB1WithANY_NUM.cs, FB2WithANY_BIT.cs, FB2WithANY_NUM.cs) |
03 | User Struct | Function block with a user struct. (FBWithUserStruct.cs) |
04 | User Array | Function block with a user array. (FBWithUserArray.cs) |
05 | IEC String | Use type IecStringEx for strings in PLCnext Engineer. (FBWithString.cs) |
05.1 | IEC WString | Use type IecWString for wide character strings in PLCnext Engineer. (FBWithWString.cs) |
06 | Complex Data Types | Complex data type as function's return value. (FUWithComplexDataType.cs) |
07 | Methods | An example for providing Methods written in C# that can be used in IEC language. (FBWithMethods.cs) |
08 | File Handling | Use "File" in namespace System.IO (WriteFile.cs, ReadFile.cs) |
09 | DateTime | Getting UTC ticks and conversion into a string. (FBWithDateTime.cs) |
10 | User Enumeration | Shows how to add and use user enumeration. (UserEnumeration.cs) |
11 | Programs | Provides a template for programs in C#. (Program.cs) |
12 | Threads | Functionblock to start a thread. (Threads.cs) |
12.1 | Background Threads | Functionblock to start a thread. (BackgroundThread.cs) |
13 | EN/ENO | Using EN/ENO in PLCnext C# FU/FBs. (FU_ENENO.cs, FB_ENENO.cs) |
14 | Dowload Change | Make your C# code Download Change capable. (DCG_example1.cs, DCG_example2.cs, DCG_example3.cs) |
99 | MiscAttributes | Making data visible in OPC UA and when to use explicit IEC data type definition. (MiscAttributes) |
Find all information how to start coding C# for PLCnext Technology in our Community or watch the Youtube Playlist on our Technical Support Channel
Most of the examples in the PLCnext_CSharpExamples
folder are ready to build and try with the PLCnext Toolchain C# Extension for Visual Studio. Follow the steps to get started:
- Make sure you have all the required installations.
- Start a new Visual Studio project (only step 1 is needed).
- Copy all files from the
PLCnext_CSharpExamples
folder to your project folder. - In Visual Studio Solution Explorer enable "Show All Files" (see red square in the picture)
- Select all added files and add them to the project via right click "Include in Project".
- To be able to build, enable unsafe code in the Project --> Properties --> Build and select "Allow unsafe code"
Note: There will be some Warnings and Massages from the Code Analyzer which can be ignored or will be suppressed via the
GlobalSuppressions.cs
file.
You can participate in this project by submitting bugs and feature requests. Furthermore you can help us by discussing issues and let us know where you have problems or where others could struggle.
You can give feedback to this project in different ways:
- Ask a question in our Forum.
- Request a new feature 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.