gkj 2 年之前
父節點
當前提交
ed95477cf4

+ 16 - 7
ServiceCenter/LogHub.cs

@@ -2,6 +2,7 @@
 using ServiceCenter.Extensions;
 using ServiceCenter.Redis;
 using System.Collections.Concurrent;
+using System.IO;
 using WCS.Core;
 
 namespace ServiceCenter
@@ -36,29 +37,37 @@ namespace ServiceCenter
         /// <param name="con">内容</param>
         public static void InterfaceProcessLog(string title, string con)
         {
-            Logs.Enqueue(new LogModel
+            RedisHub.Default.RPush("LogHub", JsonConvert.SerializeObject(new LogModel
             {
                 path = $"D:\\WCSLogs\\{DateTime.Now.yyyyMMdd()}\\接口处理日志",
                 Title = $"{title}.txt",
-                Con = con
-            });
+                Con = $"{DateTime.Now.yyyyMMddhhmmssf()}--[{Thread.CurrentThread.ManagedThreadId}]--{con}\n"
+            }));
         }
 
         public static void init()
         {
             while (true)
             {
-                var log = JsonConvert.DeserializeObject<LogModel>(RedisHub.Default.LPop("LogHub"));
+                var logHub = RedisHub.Default.LPop("LogHub");
+                LogModel log = new LogModel();
+
                 try
                 {
-                    if (log != null)
+                    if (logHub != null)
                     {
-                        if (!Directory.Exists(log.path)) Directory.CreateDirectory(log.path);
-                        File.AppendAllText(Path.Combine(log.path, log.Title), log.Con);
+                        log = JsonConvert.DeserializeObject<LogModel>(logHub);
+                        if (log != null)
+                        {
+                            if (!Directory.Exists(log.path)) Directory.CreateDirectory(log.path);
+                            File.AppendAllText(Path.Combine(log.path, log.Title), log.Con);
+                        }
                     }
                 }
                 catch (Exception ex)
                 {
+                    var path = $"D:\\WCSLogs\\{DateTime.Now.yyyyMMdd()}\\日志处理进程";
+                    if (!Directory.Exists(path)) Directory.CreateDirectory(path);
                     File.AppendAllText(Path.Combine($"D:\\WCSLogs\\{DateTime.Now.yyyyMMdd()}\\日志处理进程", "Error.txt"), $"{JsonConvert.SerializeObject(log)}--{ex.Message}--{ex.StackTrace}\n");
                 }
             }

+ 31 - 2
ServiceCenter/Redis/RedisHub.cs

@@ -27,6 +27,11 @@ namespace ServiceCenter.Redis
         /// </summary>
         public static string DebugContextType { get; private set; } = null!;
 
+        /// <summary>
+        /// 默认WMS上下文类类型
+        /// </summary>
+        public static string WMSContextType { get; private set; } = null!;
+
         /// <summary>
         /// 设置默认链接
         /// </summary>
@@ -46,7 +51,7 @@ namespace ServiceCenter.Redis
         }
 
         /// <summary>
-        /// 设置监控链接
+        /// 设置调试链接
         /// </summary>
         /// <param name="key"></param>
         public static void SetDebugContextType(string key)
@@ -54,6 +59,15 @@ namespace ServiceCenter.Redis
             DebugContextType = key;
         }
 
+        /// <summary>
+        /// 设置WMS链接
+        /// </summary>
+        /// <param name="key"></param>
+        public static void SetWMSContextType(string key)
+        {
+            WMSContextType = key;
+        }
+
         /// <summary>
         /// 默认链接
         /// </summary>
@@ -85,7 +99,7 @@ namespace ServiceCenter.Redis
         }
 
         /// <summary>
-        /// 监控连接
+        ///调试连接
         /// </summary>
         public static RedisClient Debug
         {
@@ -99,6 +113,21 @@ namespace ServiceCenter.Redis
             }
         }
 
+        /// <summary>
+        ///调试连接
+        /// </summary>
+        public static RedisClient WMS
+        {
+            get
+            {
+                {
+                    if (WMS == null)
+                        throw new Exception("请先设置WMSRedisDB库,调用静态方法SetWMSContextTypee()");
+                    return Context(WMSContextType);
+                }
+            }
+        }
+
         /// <summary>
         /// 创建一个连接
         /// </summary>

+ 9 - 9
WCS.Core/DataBlock.cs

@@ -20,7 +20,7 @@ namespace WCS.Core
         public ushort Start { get; private set; }
         public ushort Length { get; private set; }
         bool failed = false;
-        byte[] Data=new byte[0];
+        byte[] Data = new byte[0];
         int id = 0;
         public override string ToString()
         {
@@ -46,7 +46,7 @@ namespace WCS.Core
                 var data = new byte[0];
                 lock (Entity.PLCInfo.Ex())
                 {
-                    data= Entity.PLCInfo.Ex().Accessor.ReadBytes(Entity.No, Start, (ushort)(Length-Start));
+                    data = Entity.PLCInfo.Ex().Accessor.ReadBytes(Entity.No, Start, (ushort)(Length - Start));
                 }
                 if (!Data.SequenceEqual(data))
                 {
@@ -55,7 +55,7 @@ namespace WCS.Core
                 }
                 failed = false;
             }
-            catch 
+            catch
             {
                 failed = true;
                 throw;
@@ -283,13 +283,13 @@ namespace WCS.Core
         }
 
         private byte[] ReadBytes(ref int bitStart, ushort length)
-        { 
+        {
             var start = GetByteStart(bitStart);
             if (Data.Length < start + length)
-                throw new Exception("读取数据的位置超出数据总长度");
-            var data = Data.Skip(start).Take(length).ToArray(); 
+                throw new Exception($"读取数据的位置超出数据总长度:Data长度--{Data.Length};总长度--{start + length};Data内容--{Data}");
+            var data = Data.Skip(start).Take(length).ToArray();
             bitStart += length * 8;
-            return data; 
+            return data;
         }
 
         private bool ReadBit(ref int bitStart)
@@ -426,7 +426,7 @@ namespace WCS.Core
                 var start = GetByteStart(bitStart);
 
                 Entity.PLCInfo.Ex().Accessor.WriteBytes(Entity.No, start, data);
-                data.CopyTo(Data, start-Start);
+                data.CopyTo(Data, start - Start);
                 bitStart += data.Length * 8;
             }
         }
@@ -443,7 +443,7 @@ namespace WCS.Core
                 var data = new byte[] { b };
 
                 Entity.PLCInfo.Ex().Accessor.WriteBytes(Entity.No, (ushort)start, data);
-                data.CopyTo(Data, start-Start);
+                data.CopyTo(Data, start - Start);
 
                 bitStart += 1;
             }

+ 5 - 0
WCS.WorkEngineering/ProtocolProxy.cs

@@ -42,8 +42,13 @@ namespace WCS.Service
                         break;
 
                     case "DebugRedisUrl":
+                        RedisHub.SetDebugContextType(redisConnection.Key);
                         Configs.DebugRedisUrl = redisConnection.ConnectionString;
                         break;
+
+                    case "WMS":
+                        RedisHub.SetWMSContextType(redisConnection.Key);
+                        break;
                 }
             }
 

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

@@ -75,6 +75,8 @@ namespace WCS.Service.Systems
                         dev.D81 = TypeExtension.Mapper<WCS_BCR81, IBCR81>(d81.Data);
                     }
 
+                    RedisHub.WMS.Set(item.Entity.Code, item.Data2.Mode.Description);
+
                     DevList.Add(dev);
                 }
                 pack.StationDatas = new DeviceDataCollection<StationData>(DateTime.Now, DevList.ToArray());

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

@@ -1,6 +1,10 @@
 using Microsoft.AspNetCore.Mvc;
+using Newtonsoft.Json;
+using Newtonsoft.Json.Serialization;
 using PlcSiemens.Core.Extension;
+using ServiceCenter;
 using ServiceCenter.SqlSugars;
+using System.Net.Http.Json;
 using WCS.Core;
 using WCS.Entity;
 using WCS.Entity.Protocol.Station;
@@ -68,6 +72,7 @@ namespace WCS.WorkEngineering.WebApi.Controllers
         {
             lock (LockHub.ApplyEmptySpoolLock)
             {
+                LogHub.InterfaceProcessLog("ApplyEmptySpool", JsonConvert.SerializeObject(reqDto));
                 ApplyEmptySpoolResponse agvFill = new ApplyEmptySpoolResponse();
 
                 try
@@ -138,7 +143,7 @@ namespace WCS.WorkEngineering.WebApi.Controllers
                     agvFill.ResCode = Models.WMS.Response.ResponseStatusCodeEnum.DataSaveErr;
                     agvFill.ResMsg = ex.Message;
                 }
-
+                LogHub.InterfaceProcessLog("ApplyEmptySpool", JsonConvert.SerializeObject(agvFill));
                 return agvFill;
             }
         }
@@ -153,6 +158,7 @@ namespace WCS.WorkEngineering.WebApi.Controllers
         {
             lock (LockHub.AgvCallbackLock)
             {
+                LogHub.InterfaceProcessLog("AgvCallback", JsonConvert.SerializeObject(reqDto));
                 var res = new AgvCallbackResponse() { code = AgvResponseCode.Success, message = "成功" };
                 WCS_TaskInfo taskInfo = null;
                 try
@@ -262,6 +268,7 @@ namespace WCS.WorkEngineering.WebApi.Controllers
                     res.code = AgvResponseCode.Error;
                     res.message = ex.Message;
                 }
+                LogHub.InterfaceProcessLog("AgvCallback", JsonConvert.SerializeObject(res));
                 return res;
             }
         }