Closed LucaPannozzo closed 2 years ago
There are some factors that could have an effect on this. Depending on the interval/how often you are opening and closing the connection to the PLC, you could be consuming multiple connections internally into the PLC. From your code, it is possible you are opening "new" instances, but have not necessarily closed and disposed of previous ones.
The Siemens S7-1200 has a maximum number of external connections available, and once those are reached, it cannot accept any more. When you terminate your program, the TCP Sockets itself will terminate and release in the Siemens. Again, this is merely a possibility. If you have access to the Siemens PLC via TIA Portal, you can monitor the number of connections taken and available to see if this is actually occurring.
As an aside, you could make your PLC object a factory and hold the instance connection open and then close it only when you dispose of the factory instance. This would be a cleaner approach.
I used to believe you can actually only have a single connection open for the specified local and remote TSAP, but I recently had a situation where multiple connections using the default TSAP actually seemed to work. Nevertheless @Jason-Jelks is absolutely right, you should manage your connection in whatever way to ensure they're not dangling.
Hi @Jason-Jelks and thank you for your reply. I polling the with an interval of 1sec. I see the Plc Class have Dispose methods but not accessible for other classes. What do you think to create an extended class like these:
` internal class MyS7Plc : S7.Net.Plc { public MyS7Plc(CpuType cpu, string ip, short rack, short slot) : base(cpu, ip, rack, slot) { }
public void Dispose()
{
Dispose(true);
}
}`
So before create a new istance of Client i can call the Dispose method to the previous one.
Hello everyone,
I developed a Consolle App in c#. The app polling 7 siemens s7 1200. during the polling i update my classes properties and waiting some bits switch true for execute my job and the write a feedback bit to the plcs. I build a polling class like these:
`
`
I use this class for multiple drivers like Omron and Siemes. Siemens Service is like :
`using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; using System.Timers;
namespace Tracker_GUI.Controller.PLC.SIEMENS { public class ServizioPlcSiemens : ServizioPlc {
} `
My client contains the Driver s7.net:
`public class S7Client { public Plc Plc { get; set; } public string IndirizzoIp { get; } public CpuType CpuType { get; } public short Rack { get; } public short Slot { get; }
Now, the main class works on these way:
`using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Tracker_GUI.Controller.PLC.SIEMENS;
namespace Tracker_GUI.Controller.PLC { public class ServizioPlcPac200 : ServizioPlcSiemens {
} `
NOW, the main problems is, after a long periodo maybe one hour, my classes no update the properties with plc values and i need to restart the application. After do that, system start to works properly. i suppose the problem is with connection /socket the application/GC dispose something or i don't know. I'm not a .NET expert so probably I'm not write correctly the code but with Omron Drivers works well, only with s7.net I have these issues! Please, someone understand what is happening?
Best regards everyone Thank you