Răsfoiți Sursa

Merge branch '分拣二次码垛' of http://120.77.11.229:3000/zuolinhao/WcsFramework into 分拣二次码垛

xu.lu 1 an în urmă
părinte
comite
4745649171
3 a modificat fișierele cu 27 adăugiri și 11 ștergeri
  1. 1 1
      ServiceCenter/Extensions/LinqExtension.cs
  2. 24 8
      WCS.Core/DataBlock.cs
  3. 2 2
      WCS.Core/PLC.cs

+ 1 - 1
ServiceCenter/Extensions/LinqExtension.cs

@@ -13,7 +13,7 @@
         /// <param name="source">数据源</param>
         /// <param name="keySelector">指定属性的函数表达式</param>
         /// <returns></returns>
-        public static IEnumerable<TSource> DistinctBy<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector)
+        public static IEnumerable<TSource> DistinctItemBy<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector)
         {
             var seenKeys = new HashSet<TKey>();
             foreach (var source1 in source)

+ 24 - 8
WCS.Core/DataBlock.cs

@@ -2,6 +2,7 @@
 using System.Net.NetworkInformation;
 using System.Reflection;
 using System.Runtime.InteropServices;
+using System.Threading.Channels;
 
 namespace WCS.Core
 {
@@ -25,17 +26,17 @@ namespace WCS.Core
             return id.ToString();
         }
 
-        public DataBlock(DBInfo ent,World world) : base(ent)
+        public DataBlock(DBInfo ent, World world) : base(ent)
         {
-            this.World= world;
+            this.World = world;
             DBList.Add(this);
             id = DBList.Count;
         }
 
-        DateTime faildTime = DateTime.MinValue;
+        private DateTime faildTime = DateTime.MinValue;
 
         public void RefreshData()
-        { 
+        {
             try
             {
                 var plc = Entity.PLCInfo.Ex(World);
@@ -45,28 +46,43 @@ namespace WCS.Core
                     {
                         throw new Exception($"{Entity.PLCInfo.IP}无法访问");
                     }
-                } 
+                }
                 Start = (ushort)ProxyList.Min(v => v.Info.Position);
                 var last = ProxyList.OrderBy(v => v.Info.Position).Last();
                 Length = (ushort)(last.Info.Position + last.BytesCount);
                 var data = new byte[0];
+                //Console.ForegroundColor = ConsoleColor.Red;
+                //Console.WriteLine($"{plc.Entity.IP}--{Entity.No}--开始");
+                //Console.ResetColor();
                 lock (plc)
                 {
+                    //Console.ForegroundColor = ConsoleColor.Red;
+                    //Console.WriteLine($"{plc.Entity.IP}--{Entity.No}--读取中");
+                    //Console.ResetColor();
                     data = plc.Accessor.ReadBytes(Entity.No, Start, (ushort)(Length - Start));
+                    //Console.ForegroundColor = ConsoleColor.Red;
+                    //Console.WriteLine($"{plc.Entity.IP}--{Entity.No}--读取结束");
+                    //Console.ResetColor();
                 }
+                //Console.ForegroundColor = ConsoleColor.Red;
+                //Console.WriteLine($"{plc.Entity.IP}--{Entity.No}--处理中");
+                //Console.ResetColor();
                 if (!Data.SequenceEqual(data))
                 {
                     Data = data;
                     DbChanged?.Invoke(Data);
                 }
                 Failed = false;
+                //Console.ForegroundColor = ConsoleColor.Red;
+                //Console.WriteLine($"{plc.Entity.IP}--{Entity.No}--结束");
+                //Console.ResetColor();
             }
             catch (Exception ex)
             {
-                Failed = true; 
+                Failed = true;
                 throw;
             }
-        } 
+        }
 
         public PlcItem<T> Regist<T>(ProtocolProxyBase proxy, string objid, string name, int start, byte arrLen = 1, byte strLen = 0)
         {
@@ -117,7 +133,7 @@ namespace WCS.Core
                 {
                     throw new Exception("只支持一维数组");
                 }
-                var arr = Array.CreateInstance(t, arrLength);   
+                var arr = Array.CreateInstance(t, arrLength);
 
                 for (int i = 0; i < arr.Length; i++)
                 {

+ 2 - 2
WCS.Core/PLC.cs

@@ -25,7 +25,7 @@ namespace WCS.Core
                 while (true)
                 {
                     Ping = ping();
-                    Task.Delay(1000);
+                    Task.Delay(1000).Wait();
                 }
                 // ReSharper disable once FunctionNeverReturns
             });
@@ -33,7 +33,7 @@ namespace WCS.Core
 
         public IPLCAccessor Accessor { get; private set; }
 
-        private bool ping(int timeout = 300)
+        private bool ping(int timeout = 100)
         {
             var p = new Ping();
             if (Entity.IP == "1") return false;