Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UDP/TCP communication example #8

Open
ghost opened this issue Jan 11, 2021 · 4 comments
Open

UDP/TCP communication example #8

ghost opened this issue Jan 11, 2021 · 4 comments
Labels
feature-request New feature or request

Comments

@ghost
Copy link

ghost commented Jan 11, 2021

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

@ghost ghost added the feature-request New feature or request label Jan 11, 2021
@mluhmann
Copy link
Member

Hi Ole

sorry for the delay. I will try to workout an example. I know its working because our 61131 Library IP_COM (available in the PLCnext Store for free and in the bundle IT_Library), is based on the available C# functions and implements non blocking UDP and TCP communication. For your information, with the runtime profile 3.3 (implemented in FW 2021.0 LTS) the whole namespace Threading regarding to .NET Standard 1.0 is implemented. This does not include convenience features like Tasks and async/await. Probably you can also find an working example online based on .NET Standard 1.0.

@ghost
Copy link
Author

ghost commented Jan 22, 2021 via email

@mluhmann
Copy link
Member

Unfortunately the GitHub project currently only supports C++ development for PLCnext. We are currently working on the release of the 2021.0 LTS Visual Studio extension for C# development. If everything works as planned, it should be available next week. With this the new profile is available as well.

There are two use cases we have to differentiate.
The first one is running your listener non blocking inside the cyclic task. For this you have to implement your own UDP client/server based on the socket class. For sockets a parameter blocking can be set to false. This is the way our 61131 IP function blocks are working. This way the socket buffer is checked every cycle. If lots of data should be send or received this could lead to a watchdog.
The second option is to run the UDP connection inside a Thread. For this you can simply run the UDP communication in a Thread. An example how to use threads is given here:
https://github.com/PLCnext/CSharpExamples/tree/master/PLCnext_CSharpExamples/12_Threads
On top of that you could combine the self build non blocking socket connection and threads. This is the safest and probably most reliable way to avoid watchdogs.

I have got some test code snippets from our internal development. I have to review them and try to build an example out of it. But this will take me at least some weeks.

@AshWhitear
Copy link

hey there, any updates on this? This is exactly what we're after! Thanks, Ash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants