Coder Social home page Coder Social logo

csharpexamples's People

Contributors

g-breder avatar juergentoelke avatar mluhmann avatar owarneke avatar pxcsw-afbuild avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

csharpexamples's Issues

Add support of Visual Studio 2022

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.

Example request: How to use threads

How to make use of threads inside a FunktionBlock.

  1. Asynchronous (non blocking)
    Handling asynchronous functions in a thread.

  2. 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

Enums

It would be interesting to see an example showing how to define and use enumerations.

Program template could be clearer

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.

UDP/TCP communication example

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

PcosDomain methods

For what are the PcosDomain Methods intended to be used?

image

An example of how to use these methods would be useful.

Array Of Struct Example

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

  1. Define a Structure "YourStruct" (with structureAttribute)
  2. Create Array after the UserArray Pattern of Type "YourStruct"

Please add an example for this usecase.

Non-descriptive SocketException

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

WriteFile example seems to be missing a class reference

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.

https://github.com/PLCnext/CSharpExamples/blob/master/PLCnext_CSharpExamples/08_FileHandling/WriteFile.cs

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!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.