.NET Socket Function Block stop PLCnext Controller

PLCnext 2152 FW 2020.6.1 C# Application Visual Studio 2017 Using: System.Net.Sockets I have 3 questions: Q1: I will test C# function blocks and for that I developed a small TCPClient. Currently it seems, that I can send one times string over this socket. My TCPServer (Listener) received the string. Perfect. (By the way: A similar prog I have tested without PLCnext Engineer on the PLCnext Controller and it works without any errors. Perfect ?) But after using the C# FB the PLCnext controller is stopped. The PLCnext Program is not refreshing values (online values of the instance ‘Robot’ where I have placed the C# FB). It seems that it is frozen. After that it is very difficult, to get this system running again. You need to reboot the system and then I can try again. With 'tail -n 20 -F -s 2 /opt/plcnext/logs/Output.log’ I monitored the Output.log file. Maybe this helps. It shows me the following content: 15.01.21 17:00:23.791 Arp.Device.Interface.Internal.DeviceStatus WARN - DeviceStatus: Ident "Status.Interfaces.Ethernet.2.1.Link" not found

15.01.21 17:00:23.816 Arp.Device.Interface.Internal.DeviceStatus WARN - DeviceStatus: Ident "Status.Interfaces.Ethernet.2.1.Duplex" not found
15.01.21 17:00:23.839 Arp.Device.Interface.Internal.DeviceStatus WARN - DeviceStatus: Ident "Status.Interfaces.Ethernet.2.1.Baudrate" not found
15.01.21 17:01:11.974 CommonRemoting INFO - Accepted connection #1: connectionId=AF2E42CF, 192.168.10.71 -> 0.0.0.0:41101
15.01.21 17:01:37.807 Arp.Plc.Esm.Internal.Tasks.TaskBase ERROR - Exception in task 'Cyclic100' occured: Exception of type 'Arp::System::Commons::Plc::UnhandledException' was thrown
at System.Net.Sockets.TcpClient.GetStream : 142
at EclrFirmwareLibraryApp.FBTCPClient.SendMessage : 122
at EclrFirmwareLibraryApp.FBTCPClient.__Process : 116
at ProConOS_eCLR.Robot.__Process : 198
at Arp::Plc::Esm::Internal::Tasks::TaskBase::ExecuteTask()
at Arp::Plc::Esm::Internal::Tasks::TaskBase::Execute()
at Arp::Plc::Esm::Internal::Tasks::CyclicTask::SpecializedRun()
at Arp::Plc::Esm::Internal::Tasks::TaskBase::ThreadRun(void*)
at Arp::System::Commons::Threading::Thread::RunThread(Arp::System::Commons::Threading::ThreadBinaryCompatibilityExtensions*)
at Arp::System::Commons::Threading::Thread::RunInternal(void*)
at Arp::System::Ve::Internal::Linux::ThreadService::RunInternal(void*)
15.01.21 17:01:38.314 Arp.Plc.Domain.Internal.PlcManager ERROR - Exception occured: stopping Plc asynchronously.
15.01.21 17:01:38.315 Arp.Services.ProfiCloud.Internal.ProficloudTSDAdapter INFO - Stopped Proficloud TSD service
15.01.21 17:01:39.294 Arp.Services.ProfiCloud.Internal.ProficloudAppAdapter INFO - Check for next install/uninstall process was terminated
15.01.21 17:01:39.295 Arp.Services.ProfiCloud.Internal.ProficloudAppAdapter INFO - Stopped Proficloud AppStore service
15.01.21 17:01:39.296 Arp.Plc.Gds.Internal.Subscription.SubscriptionImpl WARN - Unable to create subscription 1 ('InvalidConfig').
15.01.21 17:01:39.316 Arp.Io.EthernetIP.EthernetIPComponent INFO - StopPlc
15.01.21 17:01:39.317 Arp.Io.EthernetIP.EthernetIPComponent INFO - 2954879680 OnPlcStopped
15.01.21 17:01:39.317 Arp.Io.Axioline.Internal.AxioDataExchange INFO - AxioDataExchange: PD disabled
15.01.21 17:01:39.321 Arp.Services.Ehmi.EhmiComponent INFO - 2679612096 EhmiComponent: OnPlcStopped I think it depends on my example, but how I could find out what happens? I seems for me, that I have some trouble with Threading and this cause very strange effects ? I´am connected with Debug Mode in Visual Studio, but no Error occurs there. Q2: //clientReceiveThread.IsBackground = true; The property is not available. Could this maybe the reason for that? Q3: If I use Input datatype string, then the FB returns an internal error, after I have binded a local PLCnext string variable to this Input field. Why? C# code: [Input] public string IN_send_Text; I hope you can help me. Thanks a lot. Alex



Hello Alex,

about Q1 first of all you should try {} catch(){ } the exception thrown by the TCP commands in your FBs thread.
You can then process those and forward them as error codes to the outputs of your FunctionBlock.
There is a lot that might go wrong when setting up a TCP connection. (socket is occupied, bound port is already taken, timouts ect…) With the latest patch of eCLR 3.3 a lot of fuctions regarding threading have been added so if you update to 2021.0 SDK / Plugins ect. it might be available.
(And change the template of your C# Project in the properties.)
Strings in C# and eCLR are quite different as they are static in the IEC environment so it is not that easy to couple them to from C# to IEC.
Please have a look at these example how to setup a string or customstrings to communicated between C# and IEC.
https://github.com/PLCnext/CSharpExamples/tree/master/PLCnext_CSharpExamples[

](CSharpExamples/PLCnext_CSharpExamples at master · PLCnext/CSharpExamples · GitHub)I hope this helps.

Kind regards,
Oliver