xu.lu 11 mesiacov pred
rodič
commit
1887f337b8
3 zmenil súbory, kde vykonal 48 pridanie a 8 odobranie
  1. 1 1
      WCS.Core/DataBlock.cs
  2. 13 3
      WCS.Core/PLC.cs
  3. 34 4
      WCS.Core/World.cs

+ 1 - 1
WCS.Core/DataBlock.cs

@@ -39,7 +39,7 @@ public class DataBlock : EntityEx<DBInfo>
             var plc = Entity.PLCInfo.Ex(World);
             if (Entity.PLCInfo.Type != PLCType.VitrualRedisPLC)
                 if (Failed)
-                    if (!plc.Ping)
+                    if (!plc.Ping())
                     {
                         if (Entity.PLCInfo.IP == "1") throw new Exception($"{Entity.PLCInfo.IP}无法访问");
                         Console.ForegroundColor = ConsoleColor.Red;

+ 13 - 3
WCS.Core/PLC.cs

@@ -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;

+ 34 - 4
WCS.Core/World.cs

@@ -31,14 +31,28 @@ public abstract class World : DescriptionClass
         if (sys == null) throw new Exception($"世界{GetType().Name}中不存在系统{typeof(T).Name}");
         return sys;
     }
-
+    static ConcurrentDictionary<World, WorkTimes> WorldsInfo = new ConcurrentDictionary<World, WorkTimes>();
     protected virtual void FrameInfo(WorkTimes wt)
     {
-        if (wt.Total > Interval) Console.ForegroundColor = ConsoleColor.Red;
-        Console.WriteLine(wt.GetInfo());
-        Console.ResetColor();
+        WorldsInfo[this] = wt;
+        //if (wt.Total > Interval) Console.ForegroundColor = ConsoleColor.Red;
+        //Console.WriteLine(wt.GetInfo());
+        //Console.ResetColor();
     }
+    static string LastInfo = "";
+    static void Print()
+    {
+        var info = "\n" + string.Join("\n", WorldsInfo.Values.Select(v => v.GetInfo().PadRight(200))).PadRight(1000);
 
+        if (info != LastInfo)
+        {
+            Console.CursorVisible = false;
+            Console.WriteLine(info);
+            Console.SetCursorPosition(0, 0);
+            LastInfo = info;
+        }
+
+    }
     public void Log<T>(T log) where T : ILog
     {
         var channel = Ltc.GetChannel();
@@ -140,6 +154,22 @@ public abstract class World : DescriptionClass
         }
 
         IsStart = true;
+
+        Task.Run(() =>
+        {
+
+            var i = 0;
+            while (IsStart)
+            {
+                i++;
+                if (i % 30 == 1)
+                {
+                    Console.Clear();
+                }
+                Print();
+                Task.Delay(100).Wait();
+            }
+        });
     }
 
     public static void StopAll()