0

I connected my PC to a Siemens PLC with S7.NET library in a C# WPF app. There is a property, isConnected. If I connect to the PLC with plc.Open() the property return value becomes true. But, If I disconnect the PLC cable, the property value still true. Why?

 private void checkPlcConnection()
    {
        Plc plc = new Plc(CpuType.S71200, "192.168.0.1", 0, 1);
        plc.Open(); // Cable was connected when method called

        while(true)
        {
            Thread.Sleep(1000);
            Trace.WriteLine(plc.IsConnected); // True, after remove the cable still true
        }
    }
RBarryYoung
  • 55,398
  • 14
  • 96
  • 137

1 Answers1

1

I googled (actually duckduckgoed) s7.net "isconnected" and found this document:

http://www.ad.siemens.com.cn/club/bbs/upload/file/20181129/6367911382823920496914596.pdf

I would recommend you use the method IsAvailable instead of IsConnected. It actively determines if you are still connected by ping-ing.

Actually, you probably need to do both, IsConnected && IsAvailable

franji1
  • 3,088
  • 2
  • 23
  • 43