Skip to content

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

License

Notifications You must be signed in to change notification settings

PLCnext/CSharpExamples

Repository files navigation

PLCnext Technology - C# Examples

Feature Requests Bugs License Web Community

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

# 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)

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

License

Code of conduct

Security policy

Stars

Watchers

Forks

Packages

No packages published

Languages