瀏覽代碼

优化设备协议添加方案

林豪 左 2 年之前
父節點
當前提交
f45291fd35

+ 0 - 0
WCS.Entity.Protocol/Station/IStation523.cs → WCS.Entity.Protocol/Station/IStation522.cs


+ 24 - 40
WCS.Service/Worker.cs

@@ -168,6 +168,8 @@ namespace WCS.Service
 
             #endregion 创建虚拟PLC
 
+            var a = typeof(IStation520);
+
             //日志发布事件s
             Configs.PublishEvent += () =>
             {
@@ -195,34 +197,9 @@ namespace WCS.Service
                     var dbProtocols = db.Default.Queryable<WCS_DEVICEPROTOCOL>().Includes(v => v.DB, p => p.PLC).ToList();
                     foreach (var dbProtocol in dbProtocols)
                     {
-                        if (dbProtocol.DEVICECODE.Contains("SRM"))
-                        {
-                        }
-                        else if (dbProtocol.DEVICECODE.Contains("RGV"))
-                        {
-                        }
-                        else if (dbProtocol.DEVICECODE.Contains("BCR"))
-                        {
-                        }
-                        else
-                        {
-                            if (dbProtocol.DB.CODE.Contains("520"))
-                            {
-                                Add<IStation520>(dbProtocol.DEVICECODE, dbProtocol.POSITION, (ushort)dbProtocol.DB.NO, dbProtocol.DB.PLC.IP);
-                            }
-                            else if (dbProtocol.DB.CODE.Contains("521"))
-                            {
-                                Add<IStation521>(dbProtocol.DEVICECODE, dbProtocol.POSITION, (ushort)dbProtocol.DB.NO, dbProtocol.DB.PLC.IP);
-                            }
-                            else if (dbProtocol.DB.CODE.Contains("523"))
-                            {
-                                Add<IStation522>(dbProtocol.DEVICECODE, dbProtocol.POSITION, (ushort)dbProtocol.DB.NO, dbProtocol.DB.PLC.IP);
-                            }
-                            else
-                            {
-                                continue;
-                            }
-                        }
+#pragma warning disable CS8604 // 引用类型参数可能为 null。
+                        Add(Type.GetType(dbProtocol.DB.PROTOCOL), dbProtocol.DEVICECODE, dbProtocol.POSITION, dbProtocol.DB, dbProtocol.DB.PLC);
+#pragma warning restore CS8604 // 引用类型参数可能为 null。
                     }
                 });
 
@@ -252,30 +229,37 @@ namespace WCS.Service
         /// <summary>
         ///  添加协议
         /// </summary>
-        /// <typeparam name="T"></typeparam>
-        /// <param name="code"> </param>
-        /// <param name="position"> </param>
-        /// <param name="db"></param>
-        /// <param name="ip"></param>
-        public static void Add<T>(string code, int position, ushort db, string ip)
+        /// <param name="type">协议类型</param>
+        /// <param name="code">设备号</param>
+        /// <param name="position">地址</param>
+        /// <param name="db">db</param>
+        /// <param name="plc">PLC</param>
+        public static void Add(Type type, string code, int position, WCS_DATABLOCK db, WCS_PLC plc)
         {
             var info = new ProtocolInfo
             {
                 Position = position,
                 DBInfo = new DBInfo
                 {
-                    No = db,
+                    No = (ushort)db.NO,
                     PLCInfo = new PLCInfo
                     {
-                        IP = ip,
-                        Port = 102,
-                        Rack = 0,
-                        Slot = 1,
+                        IP = plc.IP,
+                        Port = plc.PORT,
+                        Rack = plc.RACK,
+                        Slot = plc.SLOT,
                         Type = Core.PLCType.Siemens
                     }
                 }
             };
-            Protocols<T>.Add(code, info);
+            try
+            {
+                Protocols.Add(type, code, info);
+            }
+            catch (Exception ex)
+            {
+                var a = ex;
+            }
         }
     }
 }

+ 2 - 9
WCS.Service/Worlds/DataCollectionWorld.cs

@@ -1,6 +1,5 @@
 using System.ComponentModel;
-using WCS.Core;
-using WCS.Service.Systems;
+using WCS.WorkEngineering.Worlds;
 
 namespace WCS.Service.Worlds
 {
@@ -9,19 +8,13 @@ namespace WCS.Service.Worlds
     ///  该世界不进行任何的交互处理,仅进行硬件数据采集
     /// </summary>
     [Description("数据采集世界")]
-    public class DataCollectionWorld : World
+    public class DataCollectionWorld : MainWorld
     {
         /// <summary>
         /// 构造函数
         /// </summary>
         public DataCollectionWorld()
         {
-            Interval = 300;
-        }
-
-        protected override void AfterUpdate()
-        {
-            //Ltc.GetSystem<DataCollectionSysyem>().Invoke(true);
         }
     }
 }

+ 8 - 7
WCS.WorkEngineering/Systems/MainLineScanCode.cs

@@ -1,14 +1,15 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
+using System.ComponentModel;
 using WCS.Core;
 using WCS.Entity.Protocol.Station;
+using WCS.WorkEngineering.Worlds;
 
 namespace WCS.WorkEngineering.Systems
 {
-
+    /// <summary>
+    ///  主线扫码
+    /// </summary>
+    [BelongTo(typeof(SortingMainLineWorld))]
+    [Description("主线扫码")]
     public class MainLineScanCode : DeviceSystem<Device<IStation520, IStation521, IStation522>>
     {
         protected override bool ParallelDo => throw new NotImplementedException();
@@ -22,7 +23,7 @@ namespace WCS.WorkEngineering.Systems
 
         public override bool Select(Device dev)
         {
-            return new int[] { 1701, 2101,1717, 2117}.Contains(int.Parse(dev.Code));
+            return new int[] { 1701, 2101, 1717, 2117 }.Contains(int.Parse(dev.Code));
         }
     }
 }