From 291185b6c286ab72f3b90208a61cbed78fdbd9ce Mon Sep 17 00:00:00 2001
From: zxx <Zxx@HanInfo>
Date: 星期三, 04 六月 2025 17:17:32 +0800
Subject: [PATCH] jushi

---
 HH.WCS.Mobox3/HH.WCS.Mobox3.JuShi/process/TaskProcess.cs |   98 ++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 77 insertions(+), 21 deletions(-)

diff --git a/HH.WCS.Mobox3/HH.WCS.Mobox3.JuShi/process/TaskProcess.cs b/HH.WCS.Mobox3/HH.WCS.Mobox3.JuShi/process/TaskProcess.cs
index 20db7c6..5c14bb5 100644
--- a/HH.WCS.Mobox3/HH.WCS.Mobox3.JuShi/process/TaskProcess.cs
+++ b/HH.WCS.Mobox3/HH.WCS.Mobox3.JuShi/process/TaskProcess.cs
@@ -26,6 +26,7 @@
 using System.ComponentModel;
 using Newtonsoft.Json.Linq;
 using S7.Net;
+using System.Threading.Tasks;
 
 namespace HH.WCS.JuShi.process
 {
@@ -806,7 +807,7 @@
             {
                 //鏌ヨ杩欎釜搴撳尯鐨勭┖鎵樼洏涓庢弧鎵樼洏
                 var list = db.Queryable<Location>().Where(a => a.S_AREA_CODE.Trim() == area).OrderByDescending(a => a.N_ROW).ToList();
-                LogHelper.Info($"鏌ヨ杩欎釜搴撳尯鐨勭┖鎵樼洏涓庢弧鎵樼洏锛歿JsonConvert.SerializeObject(list)}");
+                //LogHelper.Info($"鏌ヨ杩欎釜搴撳尯鐨勭┖鎵樼洏涓庢弧鎵樼洏锛歿JsonConvert.SerializeObject(list)}");
                 if (list.Count > 0)
                 {
                     List<string> loca = new List<string>();
@@ -823,6 +824,37 @@
                     {
                         list.RemoveAll(s => loca.Contains(s.S_CODE));
                     }
+                    // 3. 濡傛灉鏄珛搴撳叆搴撳尯锛屾鏌�PLC 鏄惁鍏佽鍗歌浇
+                    var reservoirs = Settings.ReservoirAreas.FirstOrDefault(s => s.areaName == "绔嬪簱鍏ュ簱鍖�);
+                    if (reservoirs != null && reservoirs.areaCode.Equals(area))
+                    {
+                        var plcDeviceTable = S7Helper.plcDeviceTables;
+                        // 鍏堟敹闆嗚绉婚櫎鐨勮揣浣嶏紝閬垮厤鍦ㄩ亶鍘嗘椂淇敼闆嗗悎
+                        List<Location> locationsToRemove = new List<Location>();
+
+                        foreach (var location in list)
+                        {
+                            var safeInteraction = Settings.SafeInteractions.FirstOrDefault(s => s.location == location.S_CODE);
+                            if (safeInteraction != null)
+                            {
+                                // 妫�煡 PLC 鏄惁鍏佽鍗歌浇锛堝彇绗簩浣嶆暟瀛楋紝鍒ゆ柇鏄惁涓�1锛�+                                string allowUnloadStr = plcDeviceTable.RGVAllowUnload[safeInteraction.code].ToString();
+                                int allowUnload = int.Parse(allowUnloadStr.Substring(1, 1));
+
+                                if (allowUnload != 1)
+                                {
+                                    locationsToRemove.Add(location); // 涓嶅厑璁稿嵏杞斤紝鍔犲叆寰呯Щ闄ゅ垪琛�+                                }
+                            }
+                        }
+
+                        // 閬嶅巻缁撴潫鍚庯紝鍐嶇粺涓�Щ闄や笉绗﹀悎鏉′欢鐨勮揣浣�+                        foreach (var locToRemove in locationsToRemove)
+                        {
+                            list.Remove(locToRemove);
+                        }
+                    }
+
                     //绗﹀悎鏉′欢鐨勬帓搴忛�绗竴涓� 鍏堟壘绗竴涓�                     if (list.Count > 0)
                     {
@@ -1658,6 +1690,7 @@
         {
             var db = new SqlHelper<Location>().GetInstance();
 
+            LogHelper.Info($"tcpOffline=====鍙傛暟:璧风偣璐т綅{startLoc}缁堢偣搴撳尯{endArea}");
             try
             {
                 //鏍¢獙璧风偣璐т綅鏄惁瀛樺湪/閿佷綇
@@ -1693,6 +1726,11 @@
                 //    itemCode = model.S_ITEM_CODE;
                 //    wlName = db.Queryable<TN_Material>().Where(b => b.S_ITEM_CODE == model.S_ITEM_CODE).First().S_ITEM_NAME;
                 //}
+                if (OutLoc==null)
+                {
+                    LogHelper.Info($"缁堢偣璐т綅涓嶅瓨鍦�, "鎸夐挳鐩掍笅绾�);
+                    return false;
+                }
                 ContainerHelper.BindLocCntrs(OutLoc.S_CODE, trayCode, itemCode, wlName);
                 //鍒涘缓浠诲姟
                 LogHelper.Info($"鍒涘缓浠诲姟 璧风偣:{startLoc}缁堢偣:{OutLoc.S_CODE}", "鎸夐挳鐩掍笅绾�);
@@ -1701,8 +1739,8 @@
             }
             catch (Exception ex)
             {
-                Console.WriteLine("materialOffline:" + ex.Message + ex.StackTrace);
-                LogHelper.Error("materialOffline:" + ex.Message, ex);
+                Console.WriteLine("tcpOffline:" + ex.Message + ex.StackTrace);
+                LogHelper.Error("tcpOffline:" + ex.Message, ex);
                 throw;
             }
         }
@@ -1761,10 +1799,10 @@
                     if (reservoirs.type.Equals("RGV"))
                     {
                         LogHelper.Info($"RGV瀹夊叏浜や簰  璇锋眰鐐逛綅锛歿model.STATION_NAME}璇锋眰鐮侊細{model.APPLY_CODE}");
-                        //鏍规嵁ip璇荤姸鎬�-                        LogHelper.Info($"RGV瀹夊叏浜や簰缂撳瓨淇″彿{JsonConvert.SerializeObject(plcDeviceTable.RGVAllowUnload)}");
                         //澶勭悊淇″彿
-                        var res = plcDeviceTable.RGVAllowUnload[reservoirs.code];
+                        var res = int.Parse(plcDeviceTable.RGVAllowUnload[reservoirs.code].ToString().Substring(1, 1));
+                        //鏍规嵁ip璇荤姸鎬�+                        LogHelper.Info($"RGV瀹夊叏浜や簰缂撳瓨淇″彿{res}锛寋JsonConvert.SerializeObject(plcDeviceTable.RGVAllowUnload)}");
                         //鍗歌揣璇锋眰杩涘叆
                         if (model.APPLY_CODE.Equals("5"))
                         {
@@ -1778,7 +1816,21 @@
                         //鍗歌揣鍚庡凡绂诲紑
                         else if (model.APPLY_CODE.Equals("8"))
                         {
-                            safeAssistant(reservoirs.code,res);
+                            //鍙戦�鍗歌揣瀹屾垚銆佸浣嶄俊鍙�+                            //鍗歌揣瀹屾垚淇″彿
+                            S7Helper.WriteInt(50, reservoirs.code * 2 - 2, (short)(reservoirs.code * 10 + 1));
+
+                            // 鍚姩鍚庡彴浠诲姟澶勭悊寤惰繜澶嶄綅
+                            Task.Run(async () =>
+                            {
+                                //10绉掑悗澶嶄綅
+                                await Task.Delay(10000);
+                                S7Helper.WriteInt(50, reservoirs.code * 2 - 2, (short)(reservoirs.code * 10));
+                                LogHelper.Info($"RGV瀹夊叏浜や簰 澶嶄綅瀹屾垚");
+                            });
+                            //10绉掑悗澶嶄綅
+                            //S7Helper.WriteInt(50, reservoirs.code * 2 - 2, (short)(reservoirs.code * 10));
+                            //safeAssistant(reservoirs.code, res);
                             LogHelper.Info($"RGV瀹夊叏浜や簰 鍗歌揣瀹屾垚");
                             return new safeResult() { code = "0", msg = "success" };
                         }
@@ -1860,20 +1912,24 @@
                 throw;
             }
         }
-
-        private static void safeAssistant(int code,int res) {
-            //2鍗歌揣瀹屾垚纭
-            if (res != 2)
-            {
-                //鍗歌揣瀹屾垚淇″彿
-                S7Helper.WriteInt(50, 0, (short)(code * 10 + 1));
-                Thread.Sleep(3000);
-                safeAssistant(code,res);
-            }
-            else
-            {
-                S7Helper.WriteInt(50, 0, (short)(code * 10));
-            }
+        //寰幆鍙戦�淇″彿
+        private static void safeAssistant(int code, int res)
+        {
+            Thread.Sleep(10000);
+            S7Helper.WriteInt(50, code * 2 - 2, (short)(code * 10));
+            LogHelper.Info($"RGV瀹夊叏浜や簰 澶嶄綅瀹屾垚");
+            ////2鍗歌揣瀹屾垚纭
+            //if (res != 2)
+            //{
+            //    //鍗歌揣瀹屾垚淇″彿
+            //    S7Helper.WriteInt(50, code * 2 - 2, (short)(code * 10 + 1));
+            //    Thread.Sleep(3000);
+            //    safeAssistant(code, res);
+            //}
+            //else
+            //{
+            //    S7Helper.WriteInt(50, code * 2 - 2, (short)(code * 10));
+            //}
 
         }
 

--
Gitblit v1.9.1