Skip to content

Repository files navigation

PLCnext Technology - C# Examples

Feature RequestsBugsLicenseWebCommunity

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

Table of Content

#TopicContent
01BasicsImplements a basic counter. (Basics.cs)
02ANYFunction and function block with "ANY" parameter. (FunWithANY_BIT.cs, FunWithANY_NUM.cs, FB1WithANY_BIT.cs, FB1WithANY_NUM.cs, FB2WithANY_BIT.cs, FB2WithANY_NUM.cs)
03User StructFunction block with a user struct. (FBWithUserStruct.cs)
04User ArrayFunction block with a user array. (FBWithUserArray.cs)
05IEC StringUse type IecStringEx for strings in PLCnext Engineer. (FBWithString.cs)
05.1IEC WStringUse type IecWString for wide character strings in PLCnext Engineer. (FBWithWString.cs)
06Complex Data TypesComplex data type as function's return value. (FUWithComplexDataType.cs)
07MethodsAn example for providing Methods written in C# that can be used in IEC language. (FBWithMethods.cs)
08File HandlingUse "File" in namespace System.IO (WriteFile.cs, ReadFile.cs)
09DateTimeGetting UTC ticks and conversion into a string. (FBWithDateTime.cs)
10User EnumerationShows how to add and use user enumeration. (UserEnumeration.cs)
11ProgramsProvides a template for programs in C#. (Program.cs)
12ThreadsFunctionblock to start a thread. (Threads.cs)
12.1Background ThreadsFunctionblock to start a thread. (BackgroundThread.cs)
13EN/ENOUsing EN/ENO in PLCnext C# FU/FBs. (FU_ENENO.cs, FB_ENENO.cs)
14Dowload ChangeMake your C# code Download Change capable. (DCG_example1.cs, DCG_example2.cs, DCG_example3.cs)
99MiscAttributesMaking data visible in OPC UA and when to use explicit IEC data type definition. (MiscAttributes)

Getting Started

Find all information how to start coding C# for PLCnext Technology in our Community or watch the Youtube Playlist on our Technical Support Channel

Creating C# Example Project

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:

  1. Make sure you have all the required installations.
  2. Start a new Visual Studio project (only step 1 is needed).
  3. Copy all files from the PLCnext_CSharpExamples folder to your project folder.
  4. In Visual Studio Solution Explorer enable "Show All Files" (see red square in the picture) Add2VS
  5. Select all added files and add them to the project via right click "Include in Project".
  6. 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.

Contributing

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.

Feedback

You can give feedback to this project in different ways:

License

Copyright (c) Phoenix Contact Gmbh & Co KG. All rights reserved.

Licensed under the MIT License.

About

Collection of various C# sample code for PLCnext Technology controllers.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

21 stars

Watchers

7 watching

Forks

Releases

Packages

Used by

Contributors

Languages