|
@@ -1,4 +1,5 @@
|
|
|
using System.Net.NetworkInformation;
|
|
|
+using System.Threading;
|
|
|
|
|
|
namespace WCS.Core;
|
|
|
|
|
@@ -15,18 +16,27 @@ public class PLC : EntityEx<PLCInfo>
|
|
|
{
|
|
|
while (true)
|
|
|
{
|
|
|
- Ping = ping();
|
|
|
+ _Ping = Ping();
|
|
|
Task.Delay(1000).Wait();
|
|
|
}
|
|
|
// ReSharper disable once FunctionNeverReturns
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- public bool Ping { get; private set; }
|
|
|
+ public bool _Ping { get; private set; }
|
|
|
+
|
|
|
+ public bool Ping()
|
|
|
+ {
|
|
|
+ if (_Ping) return _Ping;
|
|
|
+ var p = new Ping();
|
|
|
+ if (Entity.IP == "1") return false;
|
|
|
+ var res = p.Send(Entity.IP, 300);
|
|
|
+ return res.Status == IPStatus.Success;
|
|
|
+ }
|
|
|
|
|
|
public IPLCAccessor Accessor { get; private set; }
|
|
|
|
|
|
- private bool ping(int timeout = 300)
|
|
|
+ private bool Ping(int timeout = 300)
|
|
|
{
|
|
|
var p = new Ping();
|
|
|
if (Entity.IP == "1") return false;
|