Parcourir la source

重构和优化代码,添加新设备协议

重构 `Update` 方法,移除不再使用的代码,改进数据处理逻辑。添加 `conv9` 和 `conv10` 设备协议,修改数据库初始化部分。使 `VitrualRedisPLC` 的 Redis 连接字符串可配置。
林豪 左 il y a 1 an
Parent
commit
584cd48517

+ 4 - 2
WCS.Service/PLCAccessors/PLCAccessorsCreater.cs

@@ -8,6 +8,8 @@ namespace WCS.Service.PLCAccessors
     /// </summary>
     public class PLCAccessorsCreater : IPLCAccessorCreater
     {
+        public static string RedisConnStr = default;
+
         /// <summary>
         ///  创建PLC访问器
         /// </summary>
@@ -22,8 +24,8 @@ namespace WCS.Service.PLCAccessors
                     return new SiemensS7PLC(data.IP, data.Port, data.Rack, data.Slot);
 
                 default:
-                    return new VitrualRedisPLC(data, "127.0.0.1,database=1,prefix=Sorting:");
+                    return new VitrualRedisPLC(data, RedisConnStr);
             }
         }
     }
-}
+}

+ 7 - 1
WCS.Service/Worker.cs

@@ -11,6 +11,8 @@ using WCS.Core;
 using WCS.WorkEngineering;
 using MessagePack.ImmutableCollection;
 using MessagePack.Resolvers;
+using ServiceCenter.Virtual_PLC;
+using WCS.Service.PLCAccessors;
 
 namespace WCS.Service
 {
@@ -82,6 +84,10 @@ namespace WCS.Service
                     case "WMS":
                         RedisHub.SetWMSContextType(redisConnection.Key);
                         break;
+
+                    case "Virtual_PLC":
+                        PLCAccessorsCreater.RedisConnStr = redisConnection.ConnectionString;
+                        break;
                 }
             }
 
@@ -172,4 +178,4 @@ namespace WCS.Service
             LogHub.init();
         }
     }
-}
+}

+ 327 - 433
WCS.WorkEngineering/Systems/MainSysyem.cs

@@ -1,15 +1,18 @@
 using RestSharp;
 using ServiceCenter.Redis;
 using ServiceCenter.SqlSugars;
+using ServiceCenter.WebApi;
 using SqlSugar;
 using System.ComponentModel;
 using System.Diagnostics;
-using System.Reflection;
 using System.Text;
 using WCS.Core;
+using WCS.Entity.Protocol.BCR;
 using WCS.Entity.Protocol.DataStructure;
+using WCS.Entity.Protocol.RGV;
 using WCS.Entity.Protocol.Robot;
 using WCS.Entity.Protocol.SRM;
+using WCS.Entity.Protocol.Station;
 using WCS.Entity.Protocol.Truss;
 using WCS.WorkEngineering.Extensions;
 using WCS.WorkEngineering.Worlds;
@@ -27,16 +30,330 @@ namespace WCS.WorkEngineering.Systems
         {
             try
             {
-                var sw = Stopwatch.StartNew();
-                var number = new List<int> { 1, 2, 3, 4, 5 };
-                var db = new SqlSugarHelper().PLC; // 提前创建数据库连接
-                var pack = RedisHub.Monitor.LPop<DeviceDataPack>("DataCollectionpacks");
+                var sw = new Stopwatch();
+                sw.Start();
 
-                if (pack == null) return;
+                var number = new List<int>();
+                number.AddRange(new[] { 1, 2, 3, 4, 5 });
 
-                Parallel.ForEach(number, n =>
+                var sql1 = "";
+
+                Parallel.ForEach(number, i =>
                 {
-                    ProcessPack(db, pack); // 将处理逻辑提取到单独的方法中
+                    var db = new SqlSugarHelper().PLC;
+                    var pack = RedisHub.Monitor.LPop<DeviceDataPack>("DataCollectionpacks");
+                    ;
+                    if (pack == null) return;
+
+                    Parallel.ForEach(pack.GetType().GetProperties().OrderBy(x => x.Name), ps =>
+                    {
+                        var sw10 = new Stopwatch();
+                        sw10.Start();
+                        var typeName = "";
+                        try
+                        {
+                            if (ps.PropertyType == typeof(ProtocolData<WCS_BCR80>[]))
+                            {
+                                if (pack.BCR80.Any())
+                                {
+                                    var value = pack.BCR80.Select(x => x.Data).ToList();
+                                    var sql = db.Insertable(value).ToSqlString();
+                                    db.Ado.ExecuteCommand(sql);
+                                    typeName = typeof(WCS_BCR80).Name;
+                                }
+                            }
+                            else if (ps.PropertyType == typeof(ProtocolData<WCS_BCR81>[]))
+                            {
+                                if (pack.BCR81.Any())
+                                {
+                                    var value = pack.BCR81.Select(x => x.Data).ToList();
+                                    var sql = db.Insertable(value).ToSqlString();
+                                    db.Ado.ExecuteCommand(sql);
+                                    typeName = typeof(WCS_BCR81).Name;
+                                }
+                            }
+                            //else if (ps.PropertyType == typeof(ProtocolData<WCS_BCR83>[]))
+                            //{
+                            //    if (pack.BCR83.Any())
+                            //    {
+                            //        var value = pack.BCR83.Select(x => x.Data).ToList();
+                            //        var sql = db.Insertable(value).ToSqlString();
+                            //        db.Ado.ExecuteCommand(sql);
+                            //        typeName = typeof(WCS_BCR83).Name;
+                            //    }
+                            //}
+                            else if (ps.PropertyType == typeof(ProtocolData<WCS_RGV520>[]))
+                            {
+                                if (pack.RGV520.Any())
+                                {
+                                    var value = pack.RGV520.Select(x => x.Data).ToList();
+                                    var sql = db.Insertable(value).ToSqlString();
+                                    db.Ado.ExecuteCommand(sql);
+                                    typeName = typeof(WCS_RGV520).Name;
+                                }
+                            }
+                            else if (ps.PropertyType == typeof(ProtocolData<WCS_RGV521>[]))
+                            {
+                                if (pack.RGV521.Any())
+                                {
+                                    var value = pack.RGV521.Select(x => x.Data).ToList();
+                                    var sql = db.Insertable(value).ToSqlString();
+                                    db.Ado.ExecuteCommand(sql);
+                                    typeName = typeof(WCS_RGV521).Name;
+                                }
+                            }
+                            else if (ps.PropertyType == typeof(ProtocolData<WCS_RGV523>[]))
+                            {
+                                if (pack.RGV523.Any())
+                                {
+                                    var value = pack.RGV523.Select(x => new QuestDb_RGV523()
+                                    {
+                                        Alarm = Convert.ToString(x.Data.Alarm),
+                                        Code = x.Data.Code,
+                                        Frame = x.Data.Frame.ToLocalTime()
+                                    }).ToList();
+                                    var sql = db.Insertable(value).ToSqlString();
+                                    db.Ado.ExecuteCommand(GetString(sql));
+                                    typeName = typeof(WCS_RGV523).Name;
+                                }
+                            }
+                            else if (ps.PropertyType == typeof(ProtocolData<WCS_Robot520>[]))
+                            {
+                                if (pack.Robot520.Any())
+                                {
+                                    var value = pack.Robot520.Select(x => x.Data).ToList();
+                                    var sql = db.Insertable(value).ToSqlString();
+                                    db.Ado.ExecuteCommand(sql);
+                                    typeName = typeof(WCS_Robot520).Name.Length.ToString();
+                                }
+                            }
+                            else if (ps.PropertyType == typeof(ProtocolData<WCS_Robot521>[]))
+                            {
+                                if (pack.Robot521.Any())
+                                {
+                                    var value = pack.Robot521.Select(x => x.Data).ToList();
+                                    var sql = db.Insertable(value).ToSqlString();
+                                    db.Ado.ExecuteCommand(sql);
+                                    typeName = typeof(WCS_Robot521).Name;
+                                }
+                            }
+                            else if (ps.PropertyType == typeof(ProtocolData<WCS_Station5>[]))
+                            {
+                                if (pack.Station5.Any())
+                                {
+                                    var value = pack.Station5.Select(x => x.Data).ToList();
+                                    var sql = db.Insertable(value).ToSqlString();
+                                    db.Ado.ExecuteCommand(sql);
+                                    typeName = typeof(WCS_Station5).Name;
+                                }
+                            }
+                            else if (ps.PropertyType == typeof(ProtocolData<WCS_Robot522>[]))
+                            {
+                                if (pack.Robot522.Any())
+                                {
+                                    var value = pack.Robot522.Select(x => new QuestDb_Robot522()
+                                    {
+                                        Alarm = Convert.ToString(x.Data.Alarm),
+                                        Code = x.Data.Code,
+                                        Frame = x.Data.Frame.ToLocalTime()
+                                    }).ToList();
+                                    var sql = db.Insertable(value).ToSqlString();
+                                    db.Ado.ExecuteCommand(sql);
+                                    typeName = typeof(WCS_Robot522).Name;
+                                }
+                            }
+                            else if (ps.PropertyType == typeof(ProtocolData<WCS_Robot530>[]))
+                            {
+                                if (pack.Robot530.Any())
+                                {
+                                    var value = pack.Robot530.Select(x => x.Data).ToList();
+                                    var sql = db.Insertable(value).ToSqlString();
+                                    db.Ado.ExecuteCommand(sql);
+                                    typeName = typeof(WCS_Robot530).Name;
+                                }
+                            }
+                            else if (ps.PropertyType == typeof(ProtocolData<WCS_Robot531>[]))
+                            {
+                                if (pack.Robot531.Any())
+                                {
+                                    var value = pack.Robot531.Select(x => x.Data).ToList();
+                                    var sql = db.Insertable(value).ToSqlString();
+                                    db.Ado.ExecuteCommand(sql);
+                                    typeName = typeof(WCS_Robot531).Name;
+                                }
+                            }
+                            else if (ps.PropertyType == typeof(ProtocolData<WCS_SRM520>[]))
+                            {
+                                if (pack.SRM520.Any())
+                                {
+                                    var value = pack.SRM520.Select(x => x.Data).ToList();
+                                    var sql = db.Insertable(value).ToSqlString();
+                                    db.Ado.ExecuteCommand(sql);
+                                    typeName = typeof(WCS_SRM520).Name;
+                                }
+                            }
+                            else if (ps.PropertyType == typeof(ProtocolData<WCS_SRM521>[]))
+                            {
+                                if (pack.SRM521.Any())
+                                {
+                                    var value = pack.SRM521.Select(x => x.Data).ToList();
+                                    var sql = db.Insertable(value).ToSqlString();
+                                    db.Ado.ExecuteCommand(sql);
+                                    typeName = typeof(WCS_SRM521).Name;
+                                }
+                            }
+                            else if (ps.PropertyType == typeof(ProtocolData<WCS_SRM523>[]))
+                            {
+                                if (pack.SRM523.Any())
+                                {
+                                    var value = pack.SRM523.Select(x => new QuestDb_SRM523()
+                                    {
+                                        Alarm = $"{Convert.ToString(x.Data.Alarm1)},{Convert.ToString(x.Data.Alarm1)}",
+                                        Code = x.Data.Code,
+                                        Frame = x.Data.Frame.ToLocalTime()
+                                    }).ToList();
+                                    var sql = db.Insertable(value).ToSqlString();
+                                    db.Ado.ExecuteCommand(GetString(sql));
+                                    typeName = typeof(WCS_SRM523).Name;
+                                }
+                            }
+                            else if (ps.PropertyType == typeof(ProtocolData<WCS_Station520>[]))
+                            {
+                                if (pack.Station520.Any())
+                                {
+                                    var value = pack.Station520.Select(x => x.Data).ToList();
+                                    var sql = db.Insertable(value).ToSqlString();
+                                    db.Ado.ExecuteCommand(sql);
+                                    typeName = typeof(WCS_Station520).Name;
+                                }
+                            }
+                            else if (ps.PropertyType == typeof(ProtocolData<WCS_Station521>[]))
+                            {
+                                if (pack.Station521.Any())
+                                {
+                                    var value = pack.Station521.Select(x => x.Data).ToList();
+                                    var sql = db.Insertable(value).ToSqlString();
+                                    db.Ado.ExecuteCommand(sql);
+                                    typeName = typeof(WCS_Station521).Name;
+                                }
+                            }
+                            else if (ps.PropertyType == typeof(ProtocolData<WCS_Station523>[]))
+                            {
+                                if (pack.Station523.Any())
+                                {
+                                    var value = pack.Station523.Select(x => x.Data).ToList();
+                                    var sql = db.Insertable(value).ToSqlString();
+                                    db.Ado.ExecuteCommand(sql);
+                                    typeName = typeof(WCS_Station523).Name;
+                                }
+                            }
+                            else if (ps.PropertyType == typeof(ProtocolData<WCS_Station524>[]))
+                            {
+                                if (pack.Station524.Any())
+                                {
+                                    var value = pack.Station524.Select(x => x.Data).ToList();
+                                    var sql = db.Insertable(value).ToSqlString();
+
+                                    db.Ado.ExecuteCommand(sql);
+                                    typeName = typeof(WCS_Station524).Name;
+                                }
+                            }
+                            else if (ps.PropertyType == typeof(ProtocolData<WCS_Station525>[]))
+                            {
+                                if (pack.Station525.Any())
+                                {
+                                    var value = pack.Station525.Select(x => x.Data).ToList();
+                                    var sql = db.Insertable(value).ToSqlString();
+                                    db.Ado.ExecuteCommand(sql);
+                                    typeName = typeof(WCS_Station525).Name;
+                                }
+                            }
+                            else if (ps.PropertyType == typeof(ProtocolData<WCS_Station90>[]))
+                            {
+                                if (pack.Station90.Any())
+                                {
+                                    var value = pack.Station90.Select(x => x.Data).ToList();
+                                    var sql = db.Insertable(value).ToSqlString();
+                                    db.Ado.ExecuteCommand(sql);
+                                    typeName = typeof(WCS_Station90).Name;
+                                }
+                            }
+                            else if (ps.PropertyType == typeof(ProtocolData<WCS_Station91>[]))
+                            {
+                                if (pack.Station91.Any())
+                                {
+                                    var value = pack.Station91.Select(x => x.Data).ToList();
+                                    var sql = db.Insertable(value).ToSqlString();
+                                    db.Ado.ExecuteCommand(sql);
+                                    typeName = typeof(WCS_Station91).Name;
+                                }
+                            }
+                            else if (ps.PropertyType == typeof(ProtocolData<WCS_Truss520>[]))
+                            {
+                                if (pack.Truss520.Any())
+                                {
+                                    var value = pack.Truss520.Select(x => x.Data).ToList();
+                                    var sql = db.Insertable(value).ToSqlString();
+                                    db.Ado.ExecuteCommand(sql);
+                                    typeName = typeof(WCS_Truss520).Name;
+                                }
+                            }
+                            else if (ps.PropertyType == typeof(ProtocolData<WCS_Truss521>[]))
+                            {
+                                if (pack.Truss521.Any())
+                                {
+                                    var value = pack.Truss521.Select(x => x.Data).ToList();
+                                    var sql = db.Insertable(value).ToSqlString();
+                                    db.Ado.ExecuteCommand(sql);
+                                    typeName = typeof(WCS_Truss521).Name;
+                                }
+                            }
+                            else if (ps.PropertyType == typeof(ProtocolData<WCS_Truss523>[]))
+                            {
+                                if (pack.Truss523.Any())
+                                {
+                                    var value = pack.Truss523.Select(x => new QuestDb_Truss523()
+                                    {
+                                        Alarm = Convert.ToString(x.Data.Alarm),
+                                        Code = x.Data.Code,
+                                        Frame = x.Data.Frame.ToLocalTime()
+                                    }).ToList();
+                                    var sql = db.Insertable(value).ToSqlString();
+                                    db.Ado.ExecuteCommand(sql);
+                                    typeName = typeof(WCS_Truss523).Name;
+                                }
+                            }
+                            else if (ps.PropertyType == typeof(ProtocolData<WCS_Truss530>[]))
+                            {
+                                if (pack.Truss530.Any())
+                                {
+                                    var value = pack.Truss530.Select(x => x.Data).ToList();
+                                    var sql = db.Insertable(value).ToSqlString();
+                                    db.Ado.ExecuteCommand(sql);
+                                    typeName = typeof(WCS_Truss530).Name;
+                                }
+                            }
+                            else if (ps.PropertyType == typeof(ProtocolData<WCS_Truss531>[]))
+                            {
+                                if (pack.Truss531.Any())
+                                {
+                                    var value = pack.Truss531.Select(x => x.Data).ToList();
+                                    var sql = db.Insertable(value).ToSqlString();
+                                    db.Ado.ExecuteCommand(sql);
+                                    typeName = typeof(WCS_Truss531).Name;
+                                }
+                            }
+                        }
+                        catch (Exception e)
+                        {
+                            World.Log($"错误内容:{e.Message}");
+                        }
+                        finally
+                        {
+                            sw10.Stop();
+                            World.Log($"执行耗时:{typeName}:{sw10.ElapsedMilliseconds}");
+                        }
+                    });
                 });
 
                 sw.Stop();
@@ -48,429 +365,6 @@ namespace WCS.WorkEngineering.Systems
             }
         }
 
-        // 提取逻辑到单独的方法中
-        private void ProcessPack(SqlSugarScopeProvider db, DeviceDataPack pack)
-        {
-            var properties = pack.GetType().GetProperties().OrderBy(x => x.Name);
-            foreach (var ps in properties)
-            {
-                var sw10 = Stopwatch.StartNew();
-                var typeName = "";
-
-                try
-                {
-                    var typeHandled = HandleDataType(db, pack, ps, ref typeName);
-                    if (!typeHandled) continue; // 如果没有匹配的类型,则跳过
-                }
-                catch (Exception e)
-                {
-                    World.Log($"错误内容:{e.Message}");
-                }
-                finally
-                {
-                    sw10.Stop();
-                    World.Log($"执行耗时:{typeName}:{sw10.ElapsedMilliseconds}");
-                }
-            }
-        }
-
-        // 根据类型处理数据,返回是否成功处理该类型
-        private bool HandleDataType(SqlSugarScopeProvider db, DeviceDataPack pack, PropertyInfo ps, ref string typeName)
-        {
-            if (ps.PropertyType == typeof(ProtocolData<WCS_Robot520>[]))
-            {
-                return ProcessSpecificType(db, pack.Robot520, ref typeName);
-            }
-            if (ps.PropertyType == typeof(ProtocolData<WCS_Robot521>[]))
-            {
-                return ProcessSpecificType(db, pack.Robot521, ref typeName);
-            }
-            if (ps.PropertyType == typeof(ProtocolData<WCS_SRM520>[]))
-            {
-                return ProcessSpecificType(db, pack.SRM520, ref typeName);
-            }
-            if (ps.PropertyType == typeof(ProtocolData<WCS_SRM521>[]))
-            {
-                return ProcessSpecificType(db, pack.SRM521, ref typeName);
-            }
-            if (ps.PropertyType == typeof(ProtocolData<WCS_Truss520>[]))
-            {
-                return ProcessSpecificType(db, pack.Truss520, ref typeName);
-            }
-            if (ps.PropertyType == typeof(ProtocolData<WCS_Truss521>[]))
-            {
-                return ProcessSpecificType(db, pack.Truss521, ref typeName);
-            }
-            //if (ps.PropertyType == typeof(ProtocolData<WCS_Station222>[]))
-            //{
-            //    return ProcessSpecificType(db, pack.Station222, ref typeName);
-            //}
-            //if (ps.PropertyType == typeof(ProtocolData<WCS_Station5>[]))
-            //{
-            //    return ProcessSpecificType(db, pack.Station5, ref typeName);
-            //}
-            // 添加更多类型处理...
-
-            return false;
-        }
-
-        // 处理具体类型的数据,并执行数据库操作
-        private bool ProcessSpecificType<T>(SqlSugarScopeProvider db, ProtocolData<T>[] data, ref string typeName) where T : class
-        {
-            if (data == null || data.Length == 0) return false;
-
-            var value = data.ToList().Select(x => x.Data).ToList();
-            var sql = db.Insertable(value).ToSqlString();
-            var res = QuestDbInsert(sql);
-            typeName = typeof(T).Name;
-            return true;
-        }
-
-        //private bool ProcessSpecificTypeAlarm<T>(SqlSugarScopeProvider db, ProtocolData<T>[] data, ref string typeName) where T : class
-        //{
-        //    if (data == null || data.Length == 0) return false;
-
-        //    typeName = typeof(T).Name;
-        //    var value = pack.RGV523.Select(x => new QuestDb_RGV523()
-        //    {
-        //        Alarm = Convert.ToString(x.Data.Alarm),
-        //        Code = x.Data.Code,
-        //        Frame = x.Data.Frame.ToLocalTime()
-        //    }).ToList();
-        //    var sql = db.Insertable(value).ToSqlString();
-        //    var res = QuestDbInsert(GetString(sql));
-        //    typeName = typeof(WCS_RGV523).Name;
-        //    return true;
-        //}
-
-        //public override void Update(List<WorkTimes> list)
-        //{
-        //    try
-        //    {
-        //        var sw = new Stopwatch();
-        //        sw.Start();
-
-        //        var number = new List<int>();
-        //        number.AddRange(new[] { 1, 2, 3, 4, 5 });
-
-        //        var sql1 = "";
-
-        //        foreach (var n in number)
-        //        {
-        //            var db = new SqlSugarHelper().PLC;
-        //            var pack = RedisHub.Monitor.LPop<DeviceDataPack>("DataCollectionpacks"); ;
-        //            if (pack == null) return;
-
-        //            Parallel.ForEach(pack.GetType().GetProperties().OrderBy(x => x.Name), ps =>
-        //            {
-        //                var sw10 = new Stopwatch();
-        //                sw10.Start();
-        //                var typeName = "";
-        //                try
-        //                {
-        //                    //if (ps.PropertyType == typeof(ProtocolData<WCS_BCR80>[]))
-        //                    //{
-        //                    //    if (pack.BCR80.Any())
-        //                    //    {
-        //                    //        var value = pack.BCR80.Select(x => x.Data).ToList();
-        //                    //        var sql = db.Insertable(value).ToSqlString();
-        //                    //        db.Ado.ExecuteCommand(sql);
-        //                    //        typeName = typeof(WCS_BCR80).Name;
-        //                    //    }
-        //                    //}
-        //                    //else if (ps.PropertyType == typeof(ProtocolData<WCS_BCR81>[]))
-        //                    //{
-        //                    //    if (pack.BCR81.Any())
-        //                    //    {
-        //                    //        var value = pack.BCR81.Select(x => x.Data).ToList();
-        //                    //        var sql = db.Insertable(value).ToSqlString();
-        //                    //        db.Ado.ExecuteCommand(sql);
-        //                    //        typeName = typeof(WCS_BCR81).Name;
-        //                    //    }
-        //                    //}
-        //                    //else if (ps.PropertyType == typeof(ProtocolData<WCS_BCR83>[]))
-        //                    //{
-        //                    //    if (pack.BCR83.Any())
-        //                    //    {
-        //                    //        var value = pack.BCR83.Select(x => x.Data).ToList();
-        //                    //        var sql = db.Insertable(value).ToSqlString();
-        //                    //        db.Ado.ExecuteCommand(sql);
-        //                    //        typeName = typeof(WCS_BCR83).Name;
-        //                    //    }
-        //                    //}
-        //                    if (ps.PropertyType == typeof(ProtocolData<WCS_RGV520>[]))
-        //                    {
-        //                        if (pack.RGV520.Any())
-        //                        {
-        //                            var value = pack.RGV520.Select(x => x.Data).ToList();
-        //                            var sql = db.Insertable(value).ToSqlString();
-        //                            var res = QuestDbInsert(sql);
-        //                            typeName = typeof(WCS_RGV520).Name;
-        //                        }
-        //                    }
-        //                    else if (ps.PropertyType == typeof(ProtocolData<WCS_RGV521>[]))
-        //                    {
-        //                        if (pack.RGV521.Any())
-        //                        {
-        //                            var value = pack.RGV521.Select(x => x.Data).ToList();
-        //                            var sql = db.Insertable(value).ToSqlString();
-        //                            var res = QuestDbInsert(sql);
-        //                            typeName = typeof(WCS_RGV521).Name;
-        //                        }
-        //                    }
-        //                    else if (ps.PropertyType == typeof(ProtocolData<WCS_RGV523>[]))
-        //                    {
-        //                        if (pack.RGV523.Any())
-        //                        {
-        //                            var value = pack.RGV523.Select(x => new QuestDb_RGV523()
-        //                            {
-        //                                Alarm = Convert.ToString(x.Data.Alarm),
-        //                                Code = x.Data.Code,
-        //                                Frame = x.Data.Frame.ToLocalTime()
-        //                            }).ToList();
-        //                            var sql = db.Insertable(value).ToSqlString();
-        //                            var res = QuestDbInsert(GetString(sql));
-        //                            typeName = typeof(WCS_RGV523).Name;
-        //                        }
-        //                    }
-        //                    else if (ps.PropertyType == typeof(ProtocolData<WCS_Robot520>[]))
-        //                    {
-        //                        if (pack.Robot520.Any())
-        //                        {
-        //                            var value = pack.Robot520.Select(x => x.Data).ToList();
-        //                            var sql = db.Insertable(value).ToSqlString();
-        //                            var res = QuestDbInsert(sql);
-        //                            typeName = typeof(WCS_Robot520).Name;
-        //                        }
-        //                    }
-        //                    else if (ps.PropertyType == typeof(ProtocolData<WCS_Robot521>[]))
-        //                    {
-        //                        if (pack.Robot521.Any())
-        //                        {
-        //                            var value = pack.Robot521.Select(x => x.Data).ToList();
-        //                            var sql = db.Insertable(value).ToSqlString();
-        //                            var res = QuestDbInsert(sql);
-        //                            typeName = typeof(WCS_Robot521).Name;
-        //                        }
-        //                    }
-        //                    else if (ps.PropertyType == typeof(ProtocolData<WCS_Robot522>[]))
-        //                    {
-        //                        if (pack.Robot522.Any())
-        //                        {
-        //                            var value = pack.Robot522.Select(x => new QuestDb_Robot522()
-        //                            {
-        //                                Alarm = Convert.ToString(x.Data.Alarm),
-        //                                Code = x.Data.Code,
-        //                                Frame = x.Data.Frame.ToLocalTime()
-        //                            }).ToList();
-        //                            var sql = db.Insertable(value).ToSqlString();
-        //                            var res = QuestDbInsert(sql);
-        //                            typeName = typeof(WCS_Robot522).Name;
-        //                        }
-        //                    }
-        //                    //else if (ps.PropertyType == typeof(ProtocolData<WCS_Robot530>[]))
-        //                    //{
-        //                    //    if (pack.Robot530.Any())
-        //                    //    {
-        //                    //        var value = pack.Robot530.Select(x => x.Data).ToList();
-        //                    //        var sql = db.Insertable(value).ToSqlString();
-        //                    //        db.Ado.ExecuteCommand(sql);
-        //                    //        typeName = typeof(WCS_Robot530).Name;
-        //                    //    }
-        //                    //}
-        //                    //else if (ps.PropertyType == typeof(ProtocolData<WCS_Robot531>[]))
-        //                    //{
-        //                    //    if (pack.Robot531.Any())
-        //                    //    {
-        //                    //        var value = pack.Robot531.Select(x => x.Data).ToList();
-        //                    //        var sql = db.Insertable(value).ToSqlString();
-        //                    //        db.Ado.ExecuteCommand(sql);
-        //                    //        typeName = typeof(WCS_Robot531).Name;
-        //                    //    }
-        //                    //}
-        //                    else if (ps.PropertyType == typeof(ProtocolData<WCS_SRM520>[]))
-        //                    {
-        //                        if (pack.SRM520.Any())
-        //                        {
-        //                            var value = pack.SRM520.Select(x => x.Data).ToList();
-        //                            var sql = db.Insertable(value).ToSqlString();
-        //                            var res = QuestDbInsert(sql);
-        //                            typeName = typeof(WCS_SRM520).Name;
-        //                        }
-        //                    }
-        //                    else if (ps.PropertyType == typeof(ProtocolData<WCS_SRM521>[]))
-        //                    {
-        //                        if (pack.SRM521.Any())
-        //                        {
-        //                            var value = pack.SRM521.Select(x => x.Data).ToList();
-        //                            var sql = db.Insertable(value).ToSqlString();
-        //                            var res = QuestDbInsert(sql);
-        //                            typeName = typeof(WCS_SRM521).Name;
-        //                        }
-        //                    }
-        //                    else if (ps.PropertyType == typeof(ProtocolData<WCS_SRM523>[]))
-        //                    {
-        //                        if (pack.SRM523.Any())
-        //                        {
-        //                            var value = pack.SRM523.Select(x => new QuestDb_SRM523()
-        //                            {
-        //                                Alarm = $"{Convert.ToString(x.Data.Alarm1)},{Convert.ToString(x.Data.Alarm1)}",
-        //                                Code = x.Data.Code,
-        //                                Frame = x.Data.Frame.ToLocalTime()
-        //                            }).ToList();
-        //                            var sql = db.Insertable(value).ToSqlString();
-        //                            var res = QuestDbInsert(GetString(sql));
-        //                            typeName = typeof(WCS_SRM523).Name;
-        //                        }
-        //                    }
-        //                    //else if (ps.PropertyType == typeof(ProtocolData<WCS_Station520>[]))
-        //                    //{
-        //                    //    if (pack.Station520.Any())
-        //                    //    {
-        //                    //        var value = pack.Station520.Select(x => x.Data).ToList();
-        //                    //        var sql = db.Insertable(value).ToSqlString();
-        //                    //        db.Ado.ExecuteCommand(sql);
-        //                    //        typeName = typeof(WCS_Station520).Name;
-        //                    //    }
-        //                    //}
-        //                    //else if (ps.PropertyType == typeof(ProtocolData<WCS_Station521>[]))
-        //                    //{
-        //                    //    if (pack.Station521.Any())
-        //                    //    {
-        //                    //        var value = pack.Station521.Select(x => x.Data).ToList();
-        //                    //        var sql = db.Insertable(value).ToSqlString();
-        //                    //        db.Ado.ExecuteCommand(sql);
-        //                    //        typeName = typeof(WCS_Station521).Name;
-        //                    //    }
-        //                    //}
-        //                    //else if (ps.PropertyType == typeof(ProtocolData<WCS_Station523>[]))
-        //                    //{
-        //                    //    if (pack.Station523.Any())
-        //                    //    {
-        //                    //        var value = pack.Station523.Select(x => x.Data).ToList();
-        //                    //        var sql = db.Insertable(value).ToSqlString();
-        //                    //        db.Ado.ExecuteCommand(sql);
-        //                    //        typeName = typeof(WCS_Station523).Name;
-        //                    //    }
-        //                    //}
-        //                    //else if (ps.PropertyType == typeof(ProtocolData<WCS_Station524>[]))
-        //                    //{
-        //                    //    if (pack.Station524.Any())
-        //                    //    {
-        //                    //        var value = pack.Station524.Select(x => x.Data).ToList();
-        //                    //        var sql = db.Insertable(value).ToSqlString();
-
-        //                    //        db.Ado.ExecuteCommand(sql);
-        //                    //        typeName = typeof(WCS_Station524).Name;
-        //                    //    }
-        //                    //}
-        //                    //else if (ps.PropertyType == typeof(ProtocolData<WCS_Station525>[]))
-        //                    //{
-        //                    //    if (pack.Station525.Any())
-        //                    //    {
-        //                    //        var value = pack.Station525.Select(x => x.Data).ToList();
-        //                    //        var sql = db.Insertable(value).ToSqlString();
-        //                    //        db.Ado.ExecuteCommand(sql);
-        //                    //        typeName = typeof(WCS_Station525).Name;
-        //                    //    }
-        //                    //}
-        //                    //else if (ps.PropertyType == typeof(ProtocolData<WCS_Station90>[]))
-        //                    //{
-        //                    //    if (pack.Station90.Any())
-        //                    //    {
-        //                    //        var value = pack.Station90.Select(x => x.Data).ToList();
-        //                    //        var sql = db.Insertable(value).ToSqlString();
-        //                    //        db.Ado.ExecuteCommand(sql);
-        //                    //        typeName = typeof(WCS_Station90).Name;
-        //                    //    }
-        //                    //}
-        //                    else if (ps.PropertyType == typeof(ProtocolData<WCS_Station91>[]))
-        //                    {
-        //                        if (pack.Station91.Any())
-        //                        {
-        //                            var value = pack.Station91.Select(x => x.Data).ToList();
-        //                            var sql = db.Insertable(value).ToSqlString();
-        //                            var res = QuestDbInsert(sql);
-        //                            typeName = typeof(WCS_Station91).Name;
-        //                        }
-        //                    }
-        //                    else if (ps.PropertyType == typeof(ProtocolData<WCS_Truss520>[]))
-        //                    {
-        //                        if (pack.Truss520.Any())
-        //                        {
-        //                            var value = pack.Truss520.Select(x => x.Data).ToList();
-        //                            var sql = db.Insertable(value).ToSqlString();
-        //                            var res = QuestDbInsert(sql);
-        //                            typeName = typeof(WCS_Truss520).Name;
-        //                        }
-        //                    }
-        //                    else if (ps.PropertyType == typeof(ProtocolData<WCS_Truss521>[]))
-        //                    {
-        //                        if (pack.Truss521.Any())
-        //                        {
-        //                            var value = pack.Truss521.Select(x => x.Data).ToList();
-        //                            var sql = db.Insertable(value).ToSqlString();
-        //                            var res = QuestDbInsert(sql);
-        //                            typeName = typeof(WCS_Truss521).Name;
-        //                        }
-        //                    }
-        //                    else if (ps.PropertyType == typeof(ProtocolData<WCS_Truss523>[]))
-        //                    {
-        //                        if (pack.Truss523.Any())
-        //                        {
-        //                            var value = pack.Truss523.Select(x => new QuestDb_Truss523()
-        //                            {
-        //                                Alarm = Convert.ToString(x.Data.Alarm),
-        //                                Code = x.Data.Code,
-        //                                Frame = x.Data.Frame.ToLocalTime()
-        //                            }).ToList();
-        //                            var sql = db.Insertable(value).ToSqlString();
-        //                            var res = QuestDbInsert(sql);
-        //                            typeName = typeof(WCS_Truss523).Name;
-        //                        }
-        //                    }
-        //                    //else if (ps.PropertyType == typeof(ProtocolData<WCS_Truss530>[]))
-        //                    //{
-        //                    //    if (pack.Truss530.Any())
-        //                    //    {
-        //                    //        var value = pack.Truss530.Select(x => x.Data).ToList();
-        //                    //        var sql = db.Insertable(value).ToSqlString();
-        //                    //        db.Ado.ExecuteCommand(sql);
-        //                    //        typeName = typeof(WCS_Truss530).Name;
-        //                    //    }
-        //                    //}
-        //                    //else if (ps.PropertyType == typeof(ProtocolData<WCS_Truss531>[]))
-        //                    //{
-        //                    //    if (pack.Truss531.Any())
-        //                    //    {
-        //                    //        var value = pack.Truss531.Select(x => x.Data).ToList();
-        //                    //        var sql = db.Insertable(value).ToSqlString();
-        //                    //        db.Ado.ExecuteCommand(sql);
-        //                    //        typeName = typeof(WCS_Truss531).Name;
-        //                    //    }
-        //                    //}
-        //                }
-        //                catch (Exception e)
-        //                {
-        //                    World.Log($"错误内容:{e.Message}");
-        //                }
-        //                finally
-        //                {
-        //                    sw10.Stop();
-        //                    World.Log($"执行耗时:{typeName}:{sw10.ElapsedMilliseconds}");
-        //                }
-        //            });
-        //        }
-
-        //        sw.Stop();
-        //        World.Log($"数据处理耗时:{sw.ElapsedMilliseconds}");
-        //    }
-        //    catch (Exception e)
-        //    {
-        //        World.Log($"错误内容:{e.Message}");
-        //    }
-        //}
-
         private Type GetProtocolType(Type source)
         {
             var t = source.GetInterfaces().FirstOrDefault(v => v.GetInterfaces().Any(d => d.Name == "IProtocol"));
@@ -511,8 +405,8 @@ namespace WCS.WorkEngineering.Systems
                 .AddParameter("query", query)
                 .AddParameter("timings", "true");
             var response = client.Get<QuestDbResponse>(request);
-            //Console.WriteLine(response.ddl);
-            //var res = APICaller.CallApi1<QuestDbResponse>("http://10.30.37.2:9000" + "/exec", $"?limit=0,1000&explain=true&count=true&src=con&query={query}&timings=true", "GET");
+            Console.WriteLine(response.ddl);
+            var res = APICaller.CallApi1<QuestDbResponse>("http://10.30.37.2:9000" + "/exec", $"?limit=0,1000&explain=true&count=true&src=con&query={query}&timings=true", "GET");
             return true;
         }
     }

+ 27 - 21
WCS.WorkEngineering/WorkStart.cs

@@ -1,14 +1,7 @@
-using PlcSiemens.Core.Extension;
-using ServiceCenter;
-using ServiceCenter.Logs;
-using ServiceCenter.Redis;
+using ServiceCenter;
 using ServiceCenter.SqlSugars;
-using System.Diagnostics;
 using WCS.Core;
-using WCS.Entity.Protocol;
 using WCS.Entity.Protocol.BCR;
-using WCS.Entity.Protocol.DataStructure;
-using WCS.Entity.Protocol.HUB;
 using WCS.Entity.Protocol.RGV;
 using WCS.Entity.Protocol.Robot;
 using WCS.Entity.Protocol.SRM;
@@ -186,6 +179,12 @@ namespace WCS.WorkEngineering
                 }
             }
 
+            var conv9 = Device.All.FirstOrDefault(x => x.Code == "1");
+            conv9.AddProtocol<IStation5>(32, 5, "10.30.37.166");
+
+            var conv10 = Device.All.FirstOrDefault(x => x.Code == "101");
+            conv10.AddProtocol<IStation5>(32, 5, "10.30.37.198");
+
             #endregion 520、521 交互线体会有520、521
 
             #region 满轮扫码器
@@ -459,23 +458,30 @@ namespace WCS.WorkEngineering
 
                             _db.CodeFirst.InitTables<WCS_SRM520>();
                             _db.CodeFirst.InitTables<WCS_SRM521>();
-                            //_db.CodeFirst.InitTables<QuestDb_SRM523>();
-                            //_db.CodeFirst.InitTables<WCS_RGV520>();
-                            //_db.CodeFirst.InitTables<WCS_RGV521>();
-                            //_db.CodeFirst.InitTables<QuestDb_RGV523>();
-                            //_db.CodeFirst.InitTables<WCS_BCR80>();
-                            //_db.CodeFirst.InitTables<WCS_BCR81>();
-                            //_db.CodeFirst.InitTables<WCS_Station520>();
-                            //_db.CodeFirst.InitTables<WCS_Station521>();
-                            //_db.CodeFirst.InitTables<WCS_Station523>();
-                            //_db.CodeFirst.InitTables<WCS_Station524>();
-                            //_db.CodeFirst.InitTables<WCS_Station91>();
                             _db.CodeFirst.InitTables<WCS_Truss520>();
                             _db.CodeFirst.InitTables<WCS_Truss521>();
-                            //_db.CodeFirst.InitTables<QuestDb_Truss523>();
                             _db.CodeFirst.InitTables<WCS_Robot520>();
                             _db.CodeFirst.InitTables<WCS_Robot521>();
-                            //_db.CodeFirst.InitTables<QuestDb_Robot522>();
+                            _db.CodeFirst.InitTables<WCS_Station5>();
+                            _db.CodeFirst.InitTables<QuestDb_Robot522>();
+                            _db.CodeFirst.InitTables<QuestDb_SRM523>();
+                            _db.CodeFirst.InitTables<WCS_RGV520>();
+                            _db.CodeFirst.InitTables<WCS_RGV521>();
+                            _db.CodeFirst.InitTables<QuestDb_RGV523>();
+                            _db.CodeFirst.InitTables<WCS_BCR80>();
+                            _db.CodeFirst.InitTables<WCS_BCR81>();
+                            _db.CodeFirst.InitTables<WCS_Station520>();
+                            _db.CodeFirst.InitTables<WCS_Station521>();
+                            _db.CodeFirst.InitTables<WCS_Station523>();
+                            _db.CodeFirst.InitTables<WCS_Station524>();
+                            _db.CodeFirst.InitTables<WCS_Station91>();
+                            _db.CodeFirst.InitTables<WCS_Station90>();
+                            _db.CodeFirst.InitTables<QuestDb_Truss523>();
+                            _db.CodeFirst.InitTables<WCS_Robot530>();
+                            _db.CodeFirst.InitTables<WCS_Robot531>();
+                            _db.CodeFirst.InitTables<WCS_Station525>();
+                            _db.CodeFirst.InitTables<WCS_Truss530>();
+                            _db.CodeFirst.InitTables<WCS_Truss531>();
                             break;
 
                         default: //其他库