林豪 左 hace 2 años
padre
commit
d0db103ded

+ 3 - 3
WCS.Core/DataBlock.cs

@@ -193,10 +193,10 @@ namespace WCS.Core
         {
             if (Entity.PLCInfo.Type == PLCType.Siemens)
             {
-                var data = ReadBytes(ref bitStart, (ushort)(strLen + 2));
+                var data = ReadBytes(ref bitStart, (ushort)(strLen));
 
-                var len = data[1];
-                data = data.Skip(2).Take(len).ToArray();
+                //var len = data[1];
+                //data = data.Skip(2).Take(len).ToArray();
                 var str = Configs.StringEncoding.GetString(data);
                 return str;
             }

+ 1 - 1
WCS.Core/PlcItem.cs

@@ -63,7 +63,7 @@ namespace WCS.Core
             else if (type.IsEnum)
                 return Marshal.SizeOf(type.GetEnumUnderlyingType()) * 8;
             else if (type == typeof(string))
-                return (StringLength + 2) * 8;
+                return (StringLength) * 8;
             else
             {
                 if (typeof(IList).IsAssignableFrom(type))

+ 1 - 1
WCS.Entity.Protocol/BCR/IBCR80.cs

@@ -10,7 +10,7 @@ namespace WCS.Entity.Protocol.BCR
         /// <summary>
         /// 内容
         /// </summary>
-        [StringLength(130)]
+        [StringLength(20)]
         string Content { get; set; }
     }
 }

+ 1 - 1
WCS.Entity.Protocol/BCR/IBCR81.cs

@@ -10,7 +10,7 @@ namespace WCS.Entity.Protocol.BCR
         /// <summary>
         /// 内容
         /// </summary>
-        [StringLength(8)]
+        [StringLength(20)]
         string Content { get; set; }
     }
 }

+ 1 - 1
WCS.Entity.Protocol/DataStructure/SRMData.cs

@@ -25,6 +25,6 @@ namespace WCS.Entity.Protocol.DataStructure
         ///  DB523
         /// </summary>
         [DataMember(Order = 5)]
-        public WCS_SRM537 D523 { get; set; } = null!;
+        public WCS_SRM537 D537 { get; set; } = null!;
     }
 }

+ 1 - 4
WCS.Service/PLCAccessors/SiemensS7PLC.cs

@@ -25,10 +25,7 @@ namespace WCS.Service.PLCAccessors
 
             if (!plc.Connected)
                 plc.Connect();
-            if (db == 81)
-            {
-                var aa = 0;
-            }
+           
             var res = plc.ReadArea(AreaType.DB, db, address, length, DataType.Byte);
             if (res == null)
                 throw new Exception("读取DB块数据失败");

+ 6 - 4
WCS.WorkEngineering/Extensions/BCRExtension.cs

@@ -26,6 +26,7 @@ namespace WCS.WorkEngineering.Extensions
         public string GetBCRCode()
         {
             var barcode = Data.Content.Trim('\r');
+
             if (barcode.IsNullOrWhiteSpace()) throw new KnownException($"{Entity.Code}--扫码失败,内容为空", LogLevelEnum.High);
 
             return barcode;
@@ -35,17 +36,18 @@ namespace WCS.WorkEngineering.Extensions
     /// <summary>
     ///  BCR扩展
     /// </summary>
-    public class BCRList : List<BCR>
+    public static class BCRExtension
     {
         /// <summary>
         ///  获取BCR码
         /// </summary>
-        /// <param name="Code">BCR对应站点设备号</param>
+        /// <param name="bs"></param>
+        /// <param name="code">BCR对应站点设备号</param>
         /// <returns></returns>
-        public string GetBCRCode(string code)
+        public static string GetBCRCode(this List<BCR> bs, string code)
         {
             code = "BCR" + code;
-            var bcr = this.FirstOrDefault(p => p.Entity.Code == code) ?? throw new KnownException($"未找到扫码器{code}", LogLevelEnum.High);
+            var bcr = bs.FirstOrDefault(p => p.Entity.Code == code) ?? throw new KnownException($"未找到扫码器{code}", LogLevelEnum.High);
             return bcr.GetBCRCode();
         }
     }

+ 16 - 1
WCS.WorkEngineering/Extensions/DeviceExtension.cs

@@ -24,6 +24,20 @@ namespace WCS.WorkEngineering.Extensions
 
         #endregion 设备类型
 
+        #region 标签判断
+
+        public static bool HasFlag(this Device device, params DeviceFlags[] flag)
+        {
+            foreach (var item in flag)
+            {
+                if (device.HasFlag(item)) continue;
+                return false;
+            }
+            return true;
+        }
+
+        #endregion 标签判断
+
         #region 协议操作扩展
 
         public static void AddProtocol<T>(this Device device, int position, ushort db, string ip)
@@ -40,7 +54,7 @@ namespace WCS.WorkEngineering.Extensions
                         Port = 102,
                         Rack = 0,
                         Slot = 1,
-                        Type = PLCType.Siemens
+                        //Type = PLCType.Siemens
                     }
                 }
             };
@@ -56,6 +70,7 @@ namespace WCS.WorkEngineering.Extensions
     /// </summary>
     [Flags]
     public enum DeviceFlags
+
     {
         扫码 = 1 << 0,
         称重 = 1 << 1,

+ 1 - 1
WCS.WorkEngineering/Extensions/StationExtension.cs

@@ -5,7 +5,7 @@ using WCS.WorkEngineering.Worlds.Logs;
 
 namespace WCS.WorkEngineering.Extensions
 {
-    public class Station : Device<IStation523, IStation521, IStation523>
+    public class Station : Device<IStation520, IStation521, IStation523>
     {
         public Station(Device device, World world) : base(device, world)
         {

+ 63 - 2
WCS.WorkEngineering/ProtocolProxy.cs

@@ -1,18 +1,79 @@
 using WCS.Core;
-using WCS.Service.Systems;
+using WCS.Entity.Protocol.BCR;
+using WCS.Entity.Protocol.DataStructure;
+using WCS.Entity.Protocol.SRM;
+using WCS.Entity.Protocol.Station;
 
 namespace WCS.Service
 {
     public class ProtocolProxy : ProtocolProxyBase
     {
+        public static DeviceDataPack DataPack { get; set; } = new DeviceDataPack();
+
         public ProtocolProxy(Device dev, ProtocolInfo info, Type protocolType, World world) : base(dev, info, protocolType, world)
         {
         }
 
         protected override void DataChanged()
         {
+            //if (Device.HasProtocol(typeof(IStation520)))
+            //{
+            //    if (DataPack.StationDatas == null)
+            //    {
+            //        DataPack.StationDatas = new DeviceDataCollection<StationData>();
+            //    }
+            //    DataPack.StationDatas.Datas.Append(new StationData()
+            //    {
+            //        Code = Device.Code,
+            //        D520 = Copy(this, typeof(IStation520).Assembly.GetTypes().Where(v => v.IsClass).Where(v => v.GetInterface(typeof(IStation520).Name) != null && v != this.GetType()).First()) as WCS_Station520,
+            //        D521 = Copy(this, typeof(IStation521).Assembly.GetTypes().Where(v => v.IsClass).Where(v => v.GetInterface(typeof(IStation521).Name) != null && v != this.GetType()).First()) as WCS_Station521,
+            //        D523 = Copy(this, typeof(IStation523).Assembly.GetTypes().Where(v => v.IsClass).Where(v => v.GetInterface(typeof(IStation523).Name) != null && v != this.GetType()).First()) as WCS_Station523,
+            //    }); ;
+            //    DataPack.StationDatas.Frame = DateTime.Now;
+            //}
+            //else if (Device.HasProtocol(typeof(ISRM520)))
+            //{
+            //    if (DataPack.SRMDatas == null)
+            //    {
+            //        DataPack.SRMDatas = new DeviceDataCollection<SRMData>();
+            //    }
+            //    DataPack.SRMDatas.Datas.Append(new SRMData()
+            //    {
+            //        Code = Device.Code,
+            //        D520 = Copy(this, typeof(ISRM520).Assembly.GetTypes().Where(v => v.IsClass).Where(v => v.GetInterface(typeof(ISRM520).Name) != null && v != this.GetType()).First()) as WCS_SRM520,
+            //        D521 = Copy(this, typeof(ISRM521).Assembly.GetTypes().Where(v => v.IsClass).Where(v => v.GetInterface(typeof(ISRM521).Name) != null && v != this.GetType()).First()) as WCS_SRM521,
+            //        D537 = Copy(this, typeof(ISRM537).Assembly.GetTypes().Where(v => v.IsClass).Where(v => v.GetInterface(typeof(ISRM537).Name) != null && v != this.GetType()).First()) as WCS_SRM537,
+            //    });
+            //    DataPack.SRMDatas.Frame = DateTime.Now;
+            //}
+            //else if (Device.HasProtocol(typeof(IBCR81)))
+            //{
+            //    if (DataPack.BcrDatas == null)
+            //    {
+            //        DataPack.BcrDatas = new DeviceDataCollection<BCRData>();
+            //    }
+            //    DataPack.BcrDatas.Datas.Append(new BCRData()
+            //    {
+            //        Code = Device.Code,
+            //        Bcr81 = Copy(this, typeof(IBCR81).Assembly.GetTypes().Where(v => v.IsClass).Where(v => v.GetInterface(typeof(IBCR81).Name) != null && v != this.GetType()).First()) as WCS_BCR81,
+            //    });
+            //    DataPack.BcrDatas.Frame = DateTime.Now;
+            //}
+            //DataPack.Frame = DateTime.Now;
+        }
 
-            Console.WriteLine($"{Device.Code} Changed");
+        private object Copy(object obj, Type type)
+        {
+            var res = Activator.CreateInstance(type);
+            foreach (var p in type.GetProperties())
+            {
+                var p2 = obj.GetType().GetProperty(p.Name);
+                if (p2 != null && p2.PropertyType == p.PropertyType)
+                {
+                    p.SetValue(res, p2.GetValue(obj));
+                }
+            }
+            return res;
         }
     }
 }

+ 2 - 33
WCS.WorkEngineering/Systems/DataCollectionSysyem.cs

@@ -1,14 +1,7 @@
-using Newtonsoft.Json;
-using ServiceCenter;
-using ServiceCenter.Helpers;
-using ServiceCenter.SqlSugars;
-using System.ComponentModel;
+using System.ComponentModel;
 using WCS.Core;
-using WCS.Entity;
 using WCS.Entity.Protocol.DataStructure;
-using WCS.Entity.Protocol.Station;
 using WCS.Service.Worlds;
-using WCS.WorkEngineering.Extensions;
 
 namespace WCS.Service.Systems
 {
@@ -19,37 +12,13 @@ namespace WCS.Service.Systems
     [Description("数据采集系统")]
     public class DataCollectionSysyem : ServiceSystem<bool, bool>
     {
-        public List<Station> ConvList;
-
         public DataCollectionSysyem()
         {
-            ConvList = Device.All.Where(v => v.HasProtocol(typeof(IStation523))).Select(v => new Station(v, this.World)).ToList();
         }
 
         protected override bool Do(bool obj)
         {
-            SqlSugarHelper.Do(db =>
-            {
-                DeviceDataPack pack = new DeviceDataPack();
-                pack.Frame = DateTime.Now;
-                //pack.
-
-                //byte[] bytes = System.Text.Encoding.Default.GetBytes(JsonConvert.SerializeObject(ConvList, null, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }));
-
-                var plcData = new WCS_PlcData()
-                {
-                    AddWho = "WCS",
-                    WAREHOUSE = ServiceHub.WarehouseName,
-                    CONTENT = JsonConvert.SerializeObject(ConvList, null, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }),
-                };
-
-                var a = TypeConversionHelper.SerializeRedisValue(ConvList);
-
-                //对bytes进行数据压缩
-                //plcData.CONTENT = bytes.Compress();
-
-                db.Default.Insertable(plcData).ExecuteCommand();
-            });
+            DeviceDataPack pack = new DeviceDataPack();
 
             return true;
         }

+ 5 - 4
WCS.WorkEngineering/Systems/InboundSiteInteractionSystem.cs

@@ -2,6 +2,7 @@
 using System.ComponentModel;
 using WCS.Core;
 using WCS.Entity;
+using WCS.Entity.Protocol.BCR;
 using WCS.WorkEngineering.Extensions;
 using WCS.WorkEngineering.Worlds;
 using WCS.WorkEngineering.Worlds.Logs;
@@ -12,7 +13,7 @@ namespace WCS.WorkEngineering.Systems
     /// <summary>
     ///  入站站点交互系统
     /// </summary>
-    //[BelongTo(typeof(MainWorld))]
+    [BelongTo(typeof(MainWorld))]
     [Description("入站站点交互系统")]
     public class InboundSiteInteractionSystem : DeviceSystem<Station>
     {
@@ -20,11 +21,11 @@ namespace WCS.WorkEngineering.Systems
 
         protected override bool SaveLogsToFile => true;
 
-        private BCRList BCRS = new BCRList();
+        private List<BCR> BCRS = new List<BCR>();
 
         public InboundSiteInteractionSystem()
         {
-            BCRS = Device.All.Where(v => v.HasFlag(DeviceFlags.扫码)).Select(v => new BCR(v, World)).ToList() as BCRList;
+            BCRS = Device.All.Where(v => v.HasProtocol<IBCR81>()).Select(v => new BCR(v, World)).ToList();
         }
 
         public override void Do(Station obj)
@@ -58,7 +59,7 @@ namespace WCS.WorkEngineering.Systems
 
         public override bool Select(Device dev)
         {
-            return dev.HasFlag(DeviceFlags.巷道口) && dev.HasFlag(DeviceFlags.入库);
+            return dev.HasFlag(DeviceFlags.巷道口, DeviceFlags.入库, DeviceFlags.扫码);
         }
     }
 }

+ 13 - 3
WCS.WorkEngineering/WebApi/Controllers/AgvApi.cs

@@ -68,10 +68,10 @@ namespace WCS.WorkEngineering.WebApi.Controllers
         /// <returns></returns>
         public static GenAgvSchedulingTaskResponse 机台补空(string position, string taskCode, string priority)
         {
-            return GenAgvSchedulingTask("iWMS", "", "1", new List<positionCodeClass>()
+            return GenAgvSchedulingTask("iWMS", "", "4", new List<positionCodeClass>()
             {
                 new positionCodeClass(){ //合金库空区域
-                    positionCode="4",
+                    positionCode="21",
                     type="04"
                 },
                 new positionCodeClass(){ //目标机台
@@ -81,6 +81,17 @@ namespace WCS.WorkEngineering.WebApi.Controllers
             }, priority, taskCode, "ZTGT03", "0");
         }
 
+        /// <summary>
+        ///  缓存架补空
+        /// </summary>
+        /// <param name="taskCode">任务号</param>
+        /// <param name="nextPositionCode">取货地址</param>
+        /// <returns></returns>
+        public static ContinueTaskResponse 缓存架补空(string taskCode, string nextPositionCode)
+        {
+            return ContinueTask(taskCode, nextPositionCode);
+        }
+
         /// <summary>
         ///  机台补满
         /// </summary>
@@ -133,7 +144,6 @@ namespace WCS.WorkEngineering.WebApi.Controllers
                 taskTyp = taskType,
                 hjTaskTy = hjTaskTy,
                 tokenCode = "56898661ea976b748f328cefa6960434",
-                agvCode = "2047"
             });
             if (res.code != AgvResponseCode.Success)
             {

+ 26 - 8
WCS.WorkEngineering/WebApi/Controllers/AgvController.cs

@@ -29,7 +29,7 @@ namespace WCS.WorkEngineering.WebApi.Controllers
                 switch (type)
                 {
                     case 1:
-                        //AgvApi.机台补空();
+                        AgvApi.机台补空(pos, code, "1");
                         break;
 
                     case 2:
@@ -76,26 +76,44 @@ namespace WCS.WorkEngineering.WebApi.Controllers
                     }
                     switch (reqDto.method)
                     {
-                        case "巷道分配":
-                            agvTask.Status = AGVTaskStatus.RequestOrPermission1;//表示请求巷道
+                        case "applyContinue": //表示请求巷道
+
+                            agvTask.Status = AGVTaskStatus.RequestOrPermission1;
+                            break;
+
+                        case "applySecurity": //表示请求放货或取货
+                            //agvTask.Status = AGVTaskStatus.RequestOrPermission2;
+                            AgvApi.ContinueTask(reqDto.taskCode, "1015");
                             break;
 
-                        case "安全检测":
-                            agvTask.Status = AGVTaskStatus.RequestOrPermission2;//表示请求放货或取货
+                        case "hjend_2": //补空任务完成
+                            agvTask.Status = AGVTaskStatus.MissionCompleted;
                             break;
 
-                        case "出库任务完成":
+                        case "endhjBM": //取满任务完成
                             agvTask.Status = AGVTaskStatus.MissionCompleted;
                             break;
 
-                        case "入库任务完成":
+                        case "applyEmpty": //申请补空任务
+                            //db.Default.Insertable(new WCS_AgvTaskInfo()
+                            //{
+                            //    AgvID = reqDto.taskCode,
+                            //    TaskType = AGVTaskType.CallForMaterial,
+                            //    Status = AGVTaskStatus.NewBuild,
+                            //}).AddQueue();
+                            AgvApi.缓存架补空(reqDto.taskCode, "1016");
+
+                            break;
+
+                        case "exc_end": //异常信息上抛-值不匹配
                             agvTask.Status = AGVTaskStatus.MissionCompleted;
                             break;
 
                         default:
                             break;
                     }
-                    db.Default.Updateable(agvTask).ExecuteCommand();
+                    db.Default.Updateable(agvTask).AddQueue();
+                    db.Default.SaveQueues();
                 });
             }
             catch (Exception ex)

+ 39 - 29
WCS.WorkEngineering/WorkStart.cs

@@ -30,8 +30,10 @@ namespace WCS.WorkEngineering
 
             #region 基本信息
 
-            List<StationSegmentInfo> segmentInfo = new List<StationSegmentInfo>();
-            segmentInfo.Add(new StationSegmentInfo(1011, 1026, "10.30.36.51"));
+            List<StationSegmentInfo> segmentInfo = new List<StationSegmentInfo>
+            {
+                new StationSegmentInfo(1011, 1026, "10.30.36.51")
+            };
 
             foreach (var item in segmentInfo)
             {
@@ -39,7 +41,7 @@ namespace WCS.WorkEngineering
                 {
                     var conv = new Device(i.ToString());
                     conv.AddFlag(DeviceFlags.输送机);
-                    conv.AddProtocol<IStation523>((i - item.Start) * 14, 520, item.IP);
+                    conv.AddProtocol<IStation520>((i - item.Start) * 14, 520, item.IP);
                     conv.AddProtocol<IStation521>((i - item.Start) * 16, 521, item.IP);
                     conv.AddProtocol<IStation523>((i - item.Start) * 12, 523, item.IP);
                 }
@@ -49,8 +51,10 @@ namespace WCS.WorkEngineering
 
             #region 扫码器
 
-            List<BcrInfo> bcrInfo = new List<BcrInfo>();
-            bcrInfo.Add(new BcrInfo(new int[] { 1011, 1013, 1015 }, "10.30.36.51"));
+            List<BcrInfo> bcrInfo = new List<BcrInfo>
+            {
+                new BcrInfo(new int[] { 1011, 1013, 1015 }, "10.30.36.51")
+            };
 
             foreach (var item in bcrInfo)
             {
@@ -58,7 +62,7 @@ namespace WCS.WorkEngineering
                 {
                     var conv = new Device("BCR" + item.DeviceNo[i]);
                     conv.AddFlag(DeviceFlags.扫码);
-                    int pos = i * 8;
+                    int pos = i * 20;
                     conv.AddProtocol<IBCR81>(pos, 81, item.IP);
                 }
             }
@@ -67,8 +71,10 @@ namespace WCS.WorkEngineering
 
             #region 外检信息
 
-            List<ShapeInfo> shapeInfo = new List<ShapeInfo>();
-            shapeInfo.Add(new ShapeInfo(new int[] { 1012, 1014, 1016, 1025 }, "10.30.36.51"));
+            List<ShapeInfo> shapeInfo = new List<ShapeInfo>
+            {
+                new ShapeInfo(new int[] { 1012, 1014, 1016, 1025 }, "10.30.36.51")
+            };
 
             foreach (var item in shapeInfo)
             {
@@ -106,22 +112,24 @@ namespace WCS.WorkEngineering
 
             #region 配置路径信息
 
-            List<RouteInfo> routeInfos = new List<RouteInfo>();
-            routeInfos.Add(new RouteInfo("SRM1", new string[] { "TY1" }));
-            routeInfos.Add(new RouteInfo("SRM2", new string[] { "TY2" }));
-            routeInfos.Add(new RouteInfo("SRM3", new string[] { "TY3" }));
-            routeInfos.Add(new RouteInfo("TY1", new string[] { "SRM1" }));
-            routeInfos.Add(new RouteInfo("TY2", new string[] { "SRM2" }));
-            routeInfos.Add(new RouteInfo("TY3", new string[] { "SRM3" }));
-            routeInfos.Add(new RouteInfo("TY1", new string[] { "1012", "1021" }));
-            routeInfos.Add(new RouteInfo("TY2", new string[] { "1014", "1023" }));
-            routeInfos.Add(new RouteInfo("TY3", new string[] { "1016", "1025" }));
-            routeInfos.Add(new RouteInfo("1011", new string[] { "TY1" }));
-            routeInfos.Add(new RouteInfo("1022", new string[] { "TY1" }));
-            routeInfos.Add(new RouteInfo("1013", new string[] { "TY2" }));
-            routeInfos.Add(new RouteInfo("1024", new string[] { "TY2" }));
-            routeInfos.Add(new RouteInfo("1015", new string[] { "TY3" }));
-            routeInfos.Add(new RouteInfo("1026", new string[] { "TY3" }));
+            List<RouteInfo> routeInfos = new List<RouteInfo>
+            {
+                new RouteInfo("SRM1", new string[] { "TY1" }),
+                new RouteInfo("SRM2", new string[] { "TY2" }),
+                new RouteInfo("SRM3", new string[] { "TY3" }),
+                new RouteInfo("TY1", new string[] { "SRM1" }),
+                new RouteInfo("TY2", new string[] { "SRM2" }),
+                new RouteInfo("TY3", new string[] { "SRM3" }),
+                new RouteInfo("TY1", new string[] { "1012", "1021" }),
+                new RouteInfo("TY2", new string[] { "1014", "1023" }),
+                new RouteInfo("TY3", new string[] { "1016", "1025" }),
+                new RouteInfo("1011", new string[] { "TY1" }),
+                new RouteInfo("1022", new string[] { "TY1" }),
+                new RouteInfo("1013", new string[] { "TY2" }),
+                new RouteInfo("1024", new string[] { "TY2" }),
+                new RouteInfo("1015", new string[] { "TY3" }),
+                new RouteInfo("1026", new string[] { "TY3" })
+            };
 
             foreach (var item in routeInfos)
             {
@@ -133,11 +141,13 @@ namespace WCS.WorkEngineering
 
             #region 标签配置
 
-            Dictionary<DeviceFlags, List<string>> devices = new Dictionary<DeviceFlags, List<string>>();
-
-            devices.Add(DeviceFlags.巷道口, new List<string>() { "1011", "1012", "1013", "1014", "1015", "1016", "1021", "1022", "1023", "1024", "1025", "1026" });
-            devices.Add(DeviceFlags.入库, new List<string>() { "1011", "1013", "1015", "1022", "1024", "1026" });
-            devices.Add(DeviceFlags.出库, new List<string>() { "1012", "1014", "1016", "1021", "1023", "1025" });
+            Dictionary<DeviceFlags, List<string>> devices = new Dictionary<DeviceFlags, List<string>>
+            {
+                { DeviceFlags.巷道口, new List<string>() { "1011", "1012", "1013", "1014", "1015", "1016", "1021", "1022", "1023", "1024", "1025", "1026" } },
+                { DeviceFlags.入库, new List<string>() { "1011", "1013", "1015", "1022", "1024", "1026" } },
+                { DeviceFlags.出库, new List<string>() { "1012", "1014", "1016", "1021", "1023", "1025" } },
+                { DeviceFlags.扫码, new List<string>() { "1011", "1013", "1015" } }
+            };
 
             devices.ForEach(item =>
             {