From 815139c15ba938d79ad2ba14ddae6f635c37b085 Mon Sep 17 00:00:00 2001
From: lss <Lss@HanInfo>
Date: 星期四, 12 六月 2025 17:33:10 +0800
Subject: [PATCH] 优化

---
 HH.WCS.Mobox3/HH.WCS.Mobox3.JiaTong/process/DeviceProcess.cs |   69 +++++++++++++++++++++++++++++-----
 1 files changed, 58 insertions(+), 11 deletions(-)

diff --git a/HH.WCS.Mobox3/HH.WCS.Mobox3.JiaTong/process/DeviceProcess.cs b/HH.WCS.Mobox3/HH.WCS.Mobox3.JiaTong/process/DeviceProcess.cs
index e5c5e4f..80989df 100644
--- a/HH.WCS.Mobox3/HH.WCS.Mobox3.JiaTong/process/DeviceProcess.cs
+++ b/HH.WCS.Mobox3/HH.WCS.Mobox3.JiaTong/process/DeviceProcess.cs
@@ -7,6 +7,7 @@
 using S7.Net;
 using System;
 using System.Collections.Generic;
+using System.IO;
 using System.Linq;
 using System.Threading;
 using static HH.WCS.JiaTong.LISTA.process.HttpModel;
@@ -104,8 +105,8 @@
                         var cntr = db.Queryable<LocCntrRel>().Where(a => a.S_LOC_CODE.Trim() == item.S_CODE).ToList();
                         if (cntr.Count > 0)
                         {
-                            var cntrcodes = cntr.Select(a => a.S_CNTR_CODE).ToArray();
-                            cntrcode = string.Join(",", cntrcodes);
+                             cntrcode = cntr.OrderBy(a=>a.T_CREATE).First().S_CNTR_CODE;
+                           // cntrcode = string.Join(",", cntrcodes);
                         }
 
                         //鍒涘缓杩囨湭瀹屾垚鐨勪换鍔′笉鍙戣捣璇锋眰
@@ -155,6 +156,8 @@
             }
         }
 
+
+        public static Dictionary<string, DpjErrorInfo> DpjInfoDirectory = new Dictionary<string, DpjErrorInfo>();
         /// <summary>
         /// 浜曟澗鍙犵洏鏈哄彔鐩樺洖搴�         /// </summary>
@@ -169,9 +172,30 @@
                 {
                     foreach (var device in devices)
                     {
-                        var IsDp = S7Helper.ReadDpj(device.address,2001, S7.Net.VarType.Byte);
-                        var value = S7Helper.ReadDpj(device.address,2014, S7.Net.VarType.Int);
-
+                        var IsDp = S7Helper.ReadDpj(device.address, 2001, S7.Net.VarType.Byte);
+                        var value = S7Helper.ReadDpj(device.address, 2014, S7.Net.VarType.Int);
+                        var ErrorCode = S7Helper.ReadDpj(device.address, 2016, S7.Net.VarType.Int);
+                        //璁板綍鍙犵洏鏈烘姤閿欎俊鎭�+                        if (DpjInfoDirectory.ContainsKey(device.address))
+                        {
+                            DpjInfoDirectory[device.address].Address = device.address;
+                            DpjInfoDirectory[device.address].DeviceName = device.deviceName;
+                            var ErrorInfo = Settings.dpjErrorInfos.Where(a => a.ErrorCode == ErrorCode).First();
+                            if (ErrorInfo != null)
+                            {
+                                DpjInfoDirectory[device.address].ErrorInfo = ErrorInfo.ErrorInfo;
+                            }
+                        }
+                        else
+                        {
+                            string errorinfo = "";
+                            var ErrorInfo = Settings.dpjErrorInfos.Where(a => a.ErrorCode == ErrorCode).First();
+                            if (ErrorInfo != null)
+                            {
+                                errorinfo = ErrorInfo.ErrorInfo;
+                            }
+                            DpjInfoDirectory.Add(device.address, new DpjErrorInfo() { Address = device.address, DeviceName = device.deviceName, ErrorInfo = errorinfo });
+                        }
                         if (value >= 1 && IsDp == 1)
                         {
                             //var cntr = db.Queryable<LocCntrRel>().Where(a => a.S_LOC_CODE.Trim() == item.S_CODE).ToList();
@@ -182,16 +206,30 @@
                             //}
 
                             //鍒涘缓杩囨湭瀹屾垚鐨勪换鍔′笉鍙戣捣璇锋眰
-                            var mst = WCSHelper.GetTaskByStartloc(device.TN_Location);
-                            if (mst == null)
+                            //var mst = WCSHelper.GetTaskByStartloc(device.TN_Location);
+                            //if (mst == null)
+                            //{
+                            //    Traystacker(device.TN_Location, value, 2);
+                            //}
+                            //else
+                            //{
+                            //    LogHelper.Info($"鏈夋墽琛屼腑鐨勫彔鐩樺洖搴撲换鍔mst.S_CODE}锛屼笉瑙﹀彂鍙犵洏浠诲姟");
+                            //}
+                            var loc = LocationHelper.GetLocByLoc(device.TN_Location);
+                            if (loc != null)
                             {
-                                Traystacker(device.TN_Location, value, 2);
+                                if (loc.N_LOCK_STATE == 0) {
+                                    Traystacker(device.TN_Location, value, 2);
+                                }
+                                else
+                                {
+                                    LogHelper.Info($"璁惧璧风偣锛歿device.TN_Location}鏈夐攣锛屼笉鐢熸垚浠诲姟");
+                                }
                             }
                             else
                             {
-                                LogHelper.Info($"鏈夋墽琛屼腑鐨勫彔鐩樺洖搴撲换鍔mst.S_CODE}锛屼笉瑙﹀彂鍙犵洏浠诲姟");
+                                LogHelper.Info($"鏍规嵁璁惧锛歿device.deviceName}锛岃捣鐐癸細{device.TN_Location},鏈壘鍒拌揣浣�);
                             }
-
                         }
                         else
                         {
@@ -200,10 +238,11 @@
                         Thread.Sleep(8000);
                     }
                 }
-               
+
             }
             catch (Exception ex)
             {
+               
                 LogHelper.Error($"ReadDpj DpjTraffic:{ex}", ex);
 
             }
@@ -245,5 +284,13 @@
                 LogHelper.Info($"绌烘墭杩斿洖  Error=>{ex.ToString()}");
             }
         }
+
+        public class DpjErrorInfo
+        {
+
+            public string Address { get; set; }
+            public string DeviceName { get; set; }
+            public string ErrorInfo { get; set; }
+        }
     }
 }

--
Gitblit v1.9.1