S7NetPlus / s7netplus

S7.NET+ -- A .NET library to connect to Siemens Step7 devices
MIT License
1.3k stars 580 forks source link

Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. #471

Open zoaaz21 opened 1 year ago

zoaaz21 commented 1 year ago

Hi, I'm trying to connect to a S7-300 and I'm receiving this error message.

This is my code, i try to replace IsConnected with IsAvailable but i receive the same error

image

mycroes commented 1 year ago

I know I'd get this error with S7 1200 / 1500 when the TSAP's are invalid, they are calculated using rack and slot number I think, so perhaps your error is there? Also, your issue is a bit short on details, the exception stack trace might help.

zoaaz21 commented 1 year ago

image

image

image

S7.Net.PlcException HResult=0x80131500 Message=Couldn't establish the connection to 10.50.73.89. Message: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. Source=S7.Net StackTrace: at S7.Net.Plc.Open() at Trazeability.PlcConnection.Connect(String PlcType, String ip, Int32 plcid) in C:\Users\iyepez\OneDrive - BorgWarner\Documents\OPC Communication - v2\Resources\PlcConnection.vb:line 89 at Trazeability.PlcConnection.LoopConnectionPLC_DoWork(Object sender, DoWorkEventArgs e) in C:\Users\iyepez\OneDrive - BorgWarner\Documents\OPC Communication - v2\Resources\PlcConnection.vb:line 329 at System.ComponentModel.BackgroundWorker.OnDoWork(DoWorkEventArgs e) at System.ComponentModel.BackgroundWorker.WorkerThreadStart(Object argument)

This exception was originally thrown at this call stack: [External Code]

Inner Exception 1: IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.

Inner Exception 2: SocketException: An existing connection was forcibly closed by the remote host

SmackyPappelroy commented 1 year ago

Some CP-modules have a limit of 8 simultaneous connections. You can check in the diagnostics how many active connections the plc has

zoaaz21 commented 1 year ago

image

image I have this configuration in the cpus that I can connect and i try to replicate this config but i have the same error

SmackyPappelroy commented 1 year ago

Try disabling the firewall/antivirus on you computer. Port 102 must be open! Can you ping the CP-module? CP 343-1 lean can have 16 simultaneous connections, where 8 of them are S7-communication. If you exceed 8 s7-communication connections, you get that error message

tokke100 commented 1 year ago

I know I'd get this error with S7 1200 / 1500 when the TSAP's are invalid, they are calculated using rack and slot number I think, so perhaps your error is there? Also, your issue is a bit short on details, the exception stack trace might help.

Just started using this library and running int something similar: SocketException: external host has closed the connection.

It's a S7-1200 I'm trying to communicate with.

zoaaz21 commented 1 year ago

I remove all the reserved connections on the PLC and now is working correctly.