Csharp coding TCP communications

Hi, In PLCnext engineer I have experimented with the TCP functies send and recieve in combination with a siemens S7-300. I got it to work (see figure). So I’m trying to do make the same example in c# and later in c++ or vise versa depending on the answer on some of the questions I have.

                                               * When I try to debug the C# code and try to follow the chapter of Remote debugging C# code in the manual, my PLCnext 2152 F won't boot normaly after and the D led stays orange. 

Insert this line of code:
* After some investigation on how to impliment those functions I got stuck on some things:
* I made a functionblock in visual studio 2017 via the plcnext library.
I got my inspiration with for the code via this link: https://docs.microsoft.com/en-us/dotnet/api/system.net.sockets.tcplistener?view=netframework-4.8
* In other system you can call System.Runtime.InteropServices.Marshal.SizeOf(Your struct), but in the code for the PLCnext this is not possible. Is there a way to see the size of a struct?
* Is there also a way to have a struct as input but is not defined in the C# code?
* So I was wondering if it is possible to convert the struct to a byte array?
Best regards, Arne

Hi Arne, first of all, the steady yellow/orange D-LED isn’t an issue. Its just the Axioline status LED and tells you the Axioline F station is ready for operation and no data is being exchanged. Please try the debugging with a very simple project first. Your second issue looks like a job for our Eclr.TypeInfo Class. For more information take a look into the eCLR-Programming-Reference.chm attached to your Visual Studio project. Regards Marcel -----------------

Edit:

Your TcpListener will block the whole controller if you programmed it like in the example. Your FB runs in a realtime task = already cyclic task and the example is using a while(true) loop. So as long as your application waits for response, the whole task is waiting and blocking with a very high priority real time task. Programming for real time is different to normal C#. Consider to use a C# user thread (this will run in a much lower priority but it’s still a real time task and will block non real time applications from running. https://github.com/PLCnext/CSharpExamples/blob/master/PLCnext_CSharpExamples/12_Threads/