S7NetPlus / s7netplus

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

Reconnecting to S71500 after network broken #525

Open Lekysofar opened 5 months ago

Lekysofar commented 5 months ago

Hi Guys,

I met a problem to re-connect to S71500 after simulating unplug net cable. what I do is to close the connection, wait for few seconds, then open a connection, wait for 10 senconds to check the connection is open or not. will repeat the process of close, wait, open, check try to rebulid the connection.

However the connection could not be established, the worse is that connection instance is increasing to 98.

Any suggestion on my issue? Untitled

Thanks a lot.

Ced-90 commented 2 months ago

Hi all,

I add a similar issue because of power outage on my network device with a program which was continuously reading/writing on a PLC (S7-1500). Once the network was reestablished, I could read my PLC but can not write on it and had no error coming back to me.

I had to close and launch again my program.

From my testing, plc.close() or recreating a new plc did not work to get the connection working again after a network crash simulated by unplugging the RJ45 during more than 30s.

A solution I found is to create a new plc before closing the damaged one.

Plc Working_PLC = new Plc(CPU, IP, rack, slot);

//{… do stuff … }

//{ network crash _ Working_PLC not writing data anymore _ need to reestablish connection}

Plc PLC_buffer = new Plc(CPU, IP, rack, slot);

Working_PLC.Close();

Thread.Sleep(10);

Working_PLC = PLC_buffer;

Depending the application, I either detect the crash by controlling the writed value on the PLC or I recreate a connection at a given time interval, just in case.

It’s probably not the best solution, but it’s working enough for me.