plcnext / csharpexamples Goto Github PK
View Code? Open in Web Editor NEWCollection of various C# sample code for PLCnext Technology controllers.
License: MIT License
Collection of various C# sample code for PLCnext Technology controllers.
License: MIT License
It would be interesting to see an example showing how to define and use enumerations.
On this page:
https://github.com/PLCnext/CSharpExamples/blob/master/PLCnext_CSharpExamples/02_Any/Any.md
... there is a link to a file named Readme.txt, which does not exist.
The User Arrays example causes an Index Out of Range error.
In this for/next statement:
... the comparison operator should be <
, not <=
.
I can see HTTP libs arent currently supported, not sure if there is a way around this? Looking to speak out to Azure with using C# on the device. Thanks, Ash.
Reported in the PLCnext Community, here:
https://www.plcnext-community.net/forum/#/discussion/3308/file-handling-c
The C# code in the following file (part of the File Handling example) references a Utils
class, which is not part of the example.
This appears to be referring to the Utils
class defined here:
https://github.com/PLCnext/CSharpExamples/blob/master/PLCnext_CSharpExamples/Utils.cs
Please update the File Handling example(s) to make it clear how to include the Utils
class in this example.
Thanks!
How to make use of threads inside a FunktionBlock.
Asynchronous (non blocking)
Handling asynchronous functions in a thread.
Synchronous Functions
Some FunctionBlocks may need to handle synchronous processes or blocking functions in general.
For those functions it is neccessary to have a way to avoid trigering Watchdogs.
Please provide an exmaple how to handle those cases.
Use Case:
Listening TCP Socket
Visual Studio 2022 is now used in many organizations and projects, but for PLCnext only Visual Studio 2019 is officially supported. Please consider support of Visual Studio 2022.
It is possible to declare Arrays of Struct by combining the UserArray and UserStruct example.
You have to carefully calculate the length of your struct.
ArrayAttribute = the Dimensions! not the number of elements (at the moment only 1 Dimension allowed)
ArrayDimensionAttribute = Sets
Please add an example for this usecase.
We're getting occasional SocketExceptions when trying to listen on a TCP port from Eclr.
Jan 2 19:35:22 axcf3152 Arp.System.Application: Eclr INFO - Loaded IO config 'GS0'. 264 sensors, 95 actuators.
Jan 2 19:35:22 axcf3152 Arp.System.Application: Eclr INFO - Loaded 0 sequences. Basic sequence validation passed.
Jan 2 19:35:22 axcf3152 Arp.System.Application: Eclr INFO - Validating seq config IO channels...
Jan 2 19:35:22 axcf3152 Arp.System.Application: Eclr INFO - IO config references following channels: ai04-3-2, ai04-2-1, ai04-6-4, ai04-6-5, ai04-6-3, ai04-6-2, ai04-6-6, ai10-4-5, ai10-3-5, ai10-2-8, ai10-4-7, ai10-2-6, ai10-2-4, ai10-2-4, ai04-4-5, ai04-4-3, ai04-3-1, ai04-3-3, ai04-3-7, ai04-3-5, ai04-6-1, ai07-2-7, rtd-iol2-1, rtd-iol2-2, ai10-1-2, ai10-1-1, ai10-4-2, ai10-4-4, rtd-iol1-1, ai10-3-7, ai10-4-8, ai10-4-1, ai10-4-3, rtd-iol1-2, ai10-4-4, ai10-4-6, ai10-3-2, ai10-3-4, ai07-5-2, ai07-2-1, ai07-2-3, ai07-2-2, ai07-2-4, ai07-3-2, ai07-3-1, ai07-6-1, ai07-6-2, ai04-4-4, ai04-2-7, ai04-1-1, ai04-1-3, ai04-1-5, ai04-1-7, ai04-1-2, ai04-1-4, ai13-1-3, ai10-6-1, ai10-6-6, ai10-6-6, ai10-6-2, ai10-6-7, ai10-6-5, ai04-5-1, ai04-5-3, ai13-1-1, ai04-5-5, ai13-1-5, ai04-1-6, rtd-iol3-1, ai13-1-7, ai13-1-2, rtd-iol3-2, rtd-iol3-3, ai13-1-4, ai10-6-4, rtd-iol3-4, ai13-1-6, ai10-6-3, dio05-5-1-4, dio05-5-1-2, dio06-2-3-4, dio06-2-3-2, dio06-2-1-4, dio06-2-1-2, dio09-2-4-2, dio09-2-4-4, dio09-4-1-4, dio09-4-1-2, dio09-4-3-4, dio09-4-3-2, dio03-3-4-4, dio03-3-4-2, dio03-5-3-4, dio03-5-3-2, dio03-2-1-2, dio03-2-1-4, dio03-2-2-2, dio03-2-2-4, dio03-2-3-2, dio03-2-3-4, dio09-1-4-4, dio09-1-4-2, dio08-4-1-4, dio08-4-1-2, dio08-5-2-4, dio08-5-2-2, dio09-3-3-4, dio09-3-3-2, dio09-2-1-4, dio09-2-1-2, dio08-5-3-4, dio08-5-3-2, dio08-5-1-4, dio08-5-1-2, dio06-3-2-4, dio06-3-2-2, dio06-2-2-4, dio06-2-2-2, dio06-5-4-4, dio06-5-4-2, dio06-6-3-4, dio06-6-3-2, dio08-1-1-4, dio08-1-1-2, dio06-6-4-4, dio06-6-4-2, dio08-1-2-4, dio08-1-2-2, dio06-4-2-4, dio06-4-2-2, dio06-4-3-4, dio06-4-3-2, dio06-3-3-4, dio06-3-3-2, dio06-4-1-4, dio06-4-1-2, dio06-4-4-4, dio06-4-4-2, dio05-1-4-4, dio05-1-4-2, dio05-1-1-4, dio05-1-1-2, dio05-2-2-4, dio05-2-2-2, dio03-5-2-4, dio03-5-2-2, dio03-4-3-4, dio03-4-3-2, dio05-1-3-4, dio05-1-3-2, dio05-2-3-4, dio05-2-3-2, dio05-1-2-4, dio05-1-2-2, dio05-2-4-4, dio05-2-4-2, dio05-2-1-4, dio05-2-1-2, dio09-4-2-4, dio09-4-2-2, dio09-4-4-4, dio09-4-4-2, dio09-1-2-2, dio09-1-2-4, dio09-1-3-2, dio09-1-3-4, dio03-5-1-4, dio03-5-1-2, dio03-5-4-4, dio03-5-4-2, dio09-1-1-4, dio09-1-1-2, dio09-3-1-4, dio09-3-1-2, dio09-3-4-4, dio09-3-4-2, dio08-4-2-4, dio08-4-2-2, dio09-2-3-4, dio09-2-3-2, dio09-3-2-4, dio09-3-2-2, dio08-4-4-4, dio08-4-4-2, dio08-6-2-4, dio08-6-2-2, dio03-6-3-4, dio03-6-3-2, dio05-6-1-4, dio05-6-1-2, dio05-6-2-4, dio05-6-2-2, dio03-6-4-4, dio03-6-4-2, dio03-6-1-4, dio03-6-1-2, dio06-6-1-4, dio06-6-1-2, dio05-4-3-4, dio05-4-3-2, dio05-4-4-4, dio05-4-4-2, dio03-6-2-4, dio03-6-2-2, dio05-6-3-4, dio05-6-3-2, dio06-6-2-4, dio06-6-2-2, dio05-5-2-4, dio05-5-2-2, dio06-5-1-4, dio06-5-1-2, dio06-5-2-4, dio06-5-2-2, dio06-2-4-4, dio06-2-4-2, dio03-3-2-4, dio03-3-2-2, dio03-4-1-4, dio03-4-1-2, dio08-2-3-4, dio08-2-3-2, dio06-5-3-4, dio06-5-3-2, dio08-1-3-4, dio08-1-3-2, dio08-2-2-4, dio08-2-2-2, dio08-1-4-4, dio08-1-4-2, dio08-2-1-4, dio08-2-1-2, dio08-6-1-4, dio08-6-1-2, dio08-6-3-4, dio08-6-3-2, dio03-3-1-4, dio03-3-1-2, dio05-3-1-4, dio05-3-1-2, dio05-3-3-4, dio05-3-3-2, dio05-3-2-4, dio05-3-2-2, dio05-4-1-4, dio05-4-1-2, dio05-3-4-4, dio05-3-4-2, dio05-4-2-4, dio05-4-2-2, dio06-3-4-4, dio06-3-4-2, dio06-3-1-4, dio06-3-1-2, dio09-2-2-4, dio09-2-2-2, dio08-4-3-4, dio08-4-3-2, dio03-3-3-4, dio03-3-3-2, ai13-1-8, ai10-6-6, ai13-1-4, ai13-1-6, dio05-1-7, dio05-2-7, dio05-1-6, dio05-2-8, dio05-2-5, dio05-1-8, dio05-2-6, dio05-1-5, dio06-3-7, dio06-4-5, dio06-4-8, dio06-4-6, dio06-4-7, dio06-3-6, dio06-2-6, dio06-3-8, dio06-3-5, dio06-2-8, dio06-5-5, dio06-5-6, dio03-6-7, dio03-6-5, dio03-5-6, dio03-4-7, dio03-6-8, dio03-6-6, dio05-5-5, dio06-2-7, dio06-2-5, dio06-5-7, dio08-1-7, dio08-2-7, dio08-1-8, dio08-2-6, dio08-2-5, dio06-5-8, dio06-6-7, dio06-6-8, dio08-1-5, dio08-1-6, dio06-6-5, dio06-6-6, dio05-3-5, dio05-3-7, dio05-3-8, dio05-3-6, dio05-4-5, dio05-4-6, dio05-4-7, dio05-4-8, dio05-5-6, dio05-6-5, dio05-6-6, dio05-6-7, dio03-3-6, dio03-4-5, dio03-2-5, dio03-2-6, dio03-2-7, dio03-3-5, dio03-3-7, dio09-1-8, dio09-2-6, dio08-6-5, dio08-4-7, dio08-6-7, dio09-2-5, ai07-1-1, dio08-4-5, dio08-5-7, dio08-5-6, ai07-1-3, dio09-3-7, dio08-5-5, dio09-4-5, dio09-4-7, dio09-2-8, dio09-4-6, dio09-4-8, dio09-1-7, dio09-1-6, dio03-3-8, dio03-5-5, dio03-5-7, dio03-5-8, dio09-2-7, dio09-1-5, dio09-3-6, ai07-1-4, dio09-3-5, dio08-4-8, dio09-3-8, ai07-1-2, dio08-4-6, dio08-6-6
Jan 2 19:35:22 axcf3152 Arp.System.Application: Eclr INFO - Initializing state...
Jan 2 19:35:22 axcf3152 plc-proxy[2692]: plc-proxy 2021/01/02 19:35:22.159447 dial error: dial tcp4 127.0.0.1:1999: connect: connection refused
Jan 2 19:35:22 axcf3152 plc-proxy[2692]: plc-proxy 2021/01/02 19:35:22.159518 error detected, closing TCP connection to Seq Eng
Jan 2 19:35:22 axcf3152 Arp.System.Application: Eclr INFO - Connecting to PLC Proxy via TCP/UDP...
Jan 2 19:35:22 axcf3152 Arp.System.Application: Eclr INFO - Init complete. 02.01.2021 19:35:22
Jan 2 19:35:22 axcf3152 Arp.System.Application: Eclr INFO - Listening on tcp://127.0.0.1:1999
Jan 2 19:35:22 axcf3152 Arp.System.Application: Eclr FATAL - System.Net.Sockets.SocketException: Exception of type 'System.Net.Sockets.SocketException' was thrown.
at System.Net.Sockets.Socket.Bind : offset 001A3
at System.Net.Sockets.TcpListener.Start : offset 0010F
at System.Net.Sockets.TcpListener.Start : offset 0002E
at Abl.SequenceEngine.PlcProxyConn.Listen : offset 0007C
at Abl.SequenceEngine.SeqEng.InitAndConnect : offset 00085
Jan 2 19:35:22 axcf3152 plc-proxy[2692]: plc-proxy 2021/01/02 19:35:22.209824 dial error: dial tcp4 127.0.0.1:1999: connect: connection refused
Jan 2 19:35:22 axcf3152 plc-proxy[2692]: plc-proxy 2021/01/02 19:35:22.209893 error detected, closing TCP connection to Seq Eng
Very hard to know where to proceed--no indication what the specific error was. Nothing else should be listening on tcp:1999, just this PLCnext program.
Note that this usually works and sometimes fails, not reassuring.
Surrounding code in C#:
tcpListenerRecvCmd = new TcpListener(IPAddress.Parse("127.0.0.1"), 1999);
Log(string.Format("Listening on tcp://{0}", tcpListenerRecvCmd.LocalEndpoint));
tcpListenerRecvCmd.Start();
Advice appreciated
In the Visual Studio extension for C# (version 2022.6), when a new C# Program is added to a project, the template includes this code section:
[Program]
public class Program1
{
// Use the attributes [Global] and either [InputPort] or [OutputPort] to mark fields,
// that should exchange data with other IEC- or C#-Programs
[Global, OutputPort]
public int a = 1;
[Global, InputPort]
public int b = 2;
public int c = 3;
:
This gives the impression that the variables b
and c
are both InputPort
variables, when in fact only b
is an input port variable.
Perhaps this could be made clearer in the template, maybe with a comment after the declaration of variable c
.
Missing "eclrlib" reference is leading to missing type or namespace error on build.
Hi all
I have started working on a c# communication layer for plc to plc communication.
In this context, I have found out that only the Thread class is available and not Task and await/async. By nature, the Receive method is blocking, which means that the code needs to use Threads.
It could be nice to have an example with Threads and UDP or TCP communication, especially a Listener example. I have set Thread priority to Lowest mentioned in the community.
Kindly regards
Ole Haagensen, Denmark
The link is this page is broken.
https://github.com/PLCnext/CSharpExamples/blob/master/PLCnext_CSharpExamples/03_UserStruct/UserStruct.md
Request for an example that shows the best way to access Global variables from C# code:
https://www.plcnext-community.net/forum/#/discussion/2864/iec-global-variable-from-c-program
On this page:
... the hyperlink in the table is broken.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.