1
czw
2025-06-19 0fdee7bc3b061e62052047019330ffa705df7085
2025Äê6ÔÂ12ÈÕ/AuxAllWCS/Build/Project/´úÂë/½çÃæÊ¼þ.cs
@@ -28,154 +28,156 @@
using GZ.DB.Repository.OIDATABASE;
using GZ.DB.IRepository.OIDATABASE;
using GZ.DB.Entity.OIDATABASE;
using GZ.Modular.Redis;
namespace GZ.Projects.AuxAllWCS
{
   /// <summary>
   /// äº‹ä»¶
   /// </summary>
   public partial class ViewModel : System.ComponentModel.INotifyPropertyChanged
   {
    /// <summary>
    /// äº‹ä»¶
    /// </summary>
    public partial class ViewModel : System.ComponentModel.INotifyPropertyChanged
    {
        bool IsExitApp = false;
        ConcurrentStack<int> ExitJudgeStack = new ConcurrentStack<int>();
      System.Net.HttpListener HttpSvcHost = null;
      #region View1事件
      /// <summary>
        System.Net.HttpListener HttpSvcHost = null;
        #region View1事件
        /// <summary>
        /// View1打开事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
      public void View1_LoadEvent(object sender, RoutedEventArgs e)
      {
         try
         {
            HttpSvcHost = new System.Net.HttpListener();
            HttpSvcHost.AuthenticationSchemes = System.Net.AuthenticationSchemes.Anonymous;
            HttpSvcHost.Prefixes.Add("http://10.221.55.116:8808/");
            HttpSvcHost.Start();
            HttpSvcHost.BeginGetContext(HttpSvcListenerCallback, null);
         }
         catch(Exception ex)
         {
            Conn.默认日志.Error(ex.ToString());
         }
         View1_Init(sender, e);
         /// <summary>
         /// ç¨‹åºç‰‡æ®µ:初始化配置
         /// æè¿°:
         /// </summary>
         System.Threading.Tasks.Task.Factory.StartNew(() =>
         {
            System.Threading.Thread.CurrentThread.IsBackground = true;
            ExitJudgeStack.Push(0);
         //一直执行,直到满足结束条件
         while(true)
         {
            if (IsExitApp) { break; }
         try
         {
            #region    [脚本][20250323111613779][业务逻辑.初始化配置]
             if (Tag.Global.SettingsOver == 0)
        public void View1_LoadEvent(object sender, RoutedEventArgs e)
        {
            try
            {
                HttpSvcHost = new System.Net.HttpListener();
                HttpSvcHost.AuthenticationSchemes = System.Net.AuthenticationSchemes.Anonymous;
                HttpSvcHost.Prefixes.Add("http://10.221.55.116:8808/");
                HttpSvcHost.Start();
                HttpSvcHost.BeginGetContext(HttpSvcListenerCallback, null);
            }
            catch (Exception ex)
            {
                Conn.默认日志.Error(ex.ToString());
            }
            View1_Init(sender, e);
            /// <summary>
            /// ç¨‹åºç‰‡æ®µ:初始化配置
            /// æè¿°:
            /// </summary>
            System.Threading.Tasks.Task.Factory.StartNew(() =>
            {
                System.Threading.Thread.CurrentThread.IsBackground = true;
                ExitJudgeStack.Push(0);
                //一直执行,直到满足结束条件
                while (true)
                {
                    if (IsExitApp) { break; }
                    try
                    {
                        #region    [脚本][20250323111613779][业务逻辑.初始化配置]
                        if (Tag.Global.SettingsOver == 0)
                        {
                            SettingInit();
                            Tag.Global.SettingsOver = 1;
                        }
                        else if(Settings.deviceInfos.Count == 0)
                        else if (Settings.deviceInfos.Count == 0)
                        {
                            Tag.Global.SettingsOver = 0;
                        }
            #endregion [脚本][20250323111613779][业务逻辑.初始化配置]
         }
         catch(Exception ex)
         {
            Conn.默认日志.Error(ex.ToString());
         }
         finally
         {
            System.Threading.Thread.Sleep(10000);
         }
         }
            ExitJudgeStack.TryPop(out int exitJudgeVal);
});
         //执行多次
         for(int iii=0;iii<1;iii++)
         {
            if (IsExitApp) { break; }
         try
         {
            #region    [脚本][20250323151832119][业务逻辑.Program4]
            //Conn.默认Redis.SetValue("西门子2.Param3","300","西门子2Queue");
//return;
if(false){
                    List<string> locs = new List<string>() { "vxr1l", "vx1r", "vxr1c1", "vxr1c2", "vxr2l", "vxr2r", "vxr2c1", "vxr2c2" };
                    List<string> sites = new List<string>() { "196365BB283162", "193841BB283149", "198756BB287300", "198767BB286133", "206987BB282931", "204460BB282975", "209405BB287057", "209377BB285899" };
                    LocRepository locservice = new LocRepository();
                    for (int i = 0; i < locs.Count; i++)
                    {
                        string loccode = locs[i];
                        string sitesss = sites[i];
                        var loc = locservice.FindEntity(x => x.S_LOC_CODE == loccode);
                        if (loc == null)
                        {
                            locservice.Insert(new LocEntity
                            {
                                S_ID = Guid.NewGuid().ToString(),
                                S_STATE = "编辑",
                                T_CREATE = DateTime.Now,
                                T_MODIFY = DateTime.Now,
                                S_DEEP = "vxr",
                                S_LOC_CODE = loccode,
                                S_AGV_SITE = sitesss,
                                S_LOCK_STATE = "无",
                                N_ROW = 1,
                                N_COL = 1,
                                N_AGV_CODE = 0,
                                N_AGV_SITE_LAYER = 0,
                                N_CAPACITY = 1,
                                N_CURRENT_NUM = 0,
                                S_TYPE = "",
                            });
                        }
                        #endregion [脚本][20250323111613779][业务逻辑.初始化配置]
                    }
                   // TaskProcess.CreateTask("", locs[6], locs[7], "test", 9, new List<string> { "test" }, 1, 1, 1);
                   }
                    catch (Exception ex)
                    {
                        Conn.默认日志.Error(ex.ToString());
                    }
                    finally
                    {
                        System.Threading.Thread.Sleep(10000);
                    }
                }
                ExitJudgeStack.TryPop(out int exitJudgeVal);
            });
            //执行多次
            for (int iii = 0; iii < 1; iii++)
            {
                if (IsExitApp) { break; }
                try
                {
                    #region    [脚本][20250323151832119][业务逻辑.Program4]
                    //Conn.默认Redis.SetValue("西门子2.Param3","300","西门子2Queue");
                    //return;
                    if (false)
                    {
                        List<string> locs = new List<string>() { "vxr1l", "vx1r", "vxr1c1", "vxr1c2", "vxr2l", "vxr2r", "vxr2c1", "vxr2c2" };
                        List<string> sites = new List<string>() { "196365BB283162", "193841BB283149", "198756BB287300", "198767BB286133", "206987BB282931", "204460BB282975", "209405BB287057", "209377BB285899" };
            #endregion [脚本][20250323151832119][业务逻辑.Program4]
         }
         catch(Exception ex)
         {
            Conn.默认日志.Error(ex.ToString());
         }
         finally
         {
            System.Threading.Thread.Sleep(3000);
         }
         }
         /// <summary>
         /// ç¨‹åºç‰‡æ®µ:捷瞬抓臂1
         /// æè¿°:
         /// </summary>
         System.Threading.Tasks.Task.Factory.StartNew(() =>
         {
            System.Threading.Thread.CurrentThread.IsBackground = true;
            ExitJudgeStack.Push(0);
         //一直执行,直到满足结束条件
         while(true)
         {
            if (IsExitApp) { break; }
         try
         {
            #region    [脚本][20250325083325390][业务逻辑.第三标段.捷瞬抓臂1]
            var VERX = Settings.deviceInfos?.Find(x =>x.deviceType==2&& x.deviceName == "Js捷顺1");
                        LocRepository locservice = new LocRepository();
                        for (int i = 0; i < locs.Count; i++)
                        {
                            string loccode = locs[i];
                            string sitesss = sites[i];
                            var loc = locservice.FindEntity(x => x.S_LOC_CODE == loccode);
                            if (loc == null)
                            {
                                locservice.Insert(new LocEntity
                                {
                                    S_ID = Guid.NewGuid().ToString(),
                                    S_STATE = "编辑",
                                    T_CREATE = DateTime.Now,
                                    T_MODIFY = DateTime.Now,
                                    S_DEEP = "vxr",
 if (VERX != null)
                                    S_LOC_CODE = loccode,
                                    S_AGV_SITE = sitesss,
                                    S_LOCK_STATE = "无",
                                    N_ROW = 1,
                                    N_COL = 1,
                                    N_AGV_CODE = 0,
                                    N_AGV_SITE_LAYER = 0,
                                    N_CAPACITY = 1,
                                    N_CURRENT_NUM = 0,
                                    S_TYPE = "",
                                });
                            }
                        }
                        // TaskProcess.CreateTask("", locs[6], locs[7], "test", 9, new List<string> { "test" }, 1, 1, 1);
                    }
                    #endregion [脚本][20250323151832119][业务逻辑.Program4]
                }
                catch (Exception ex)
                {
                    Conn.默认日志.Error(ex.ToString());
                }
                finally
                {
                    System.Threading.Thread.Sleep(3000);
                }
            }
            /// <summary>
            /// ç¨‹åºç‰‡æ®µ:捷瞬抓臂1
            /// æè¿°:
            /// </summary>
            System.Threading.Tasks.Task.Factory.StartNew(() =>
            {
                System.Threading.Thread.CurrentThread.IsBackground = true;
                ExitJudgeStack.Push(0);
                //一直执行,直到满足结束条件
                while (true)
                {
                    if (IsExitApp) { break; }
                    try
                    {
                        #region    [脚本][20250325083325390][业务逻辑.第三标段.捷瞬抓臂1]
                        var VERX = Settings.deviceInfos?.Find(x => x.deviceType == 2 && x.deviceName == "Js捷顺1");
                        if (VERX != null)
                        {
                            if (tag.Js1.D1212_LAST == 0 && TcpServer.GetBitdata(tag.Js1.D1212, 2) == 1)
                            {
@@ -187,59 +189,66 @@
                                LogHelper.Info($"{VERX.location[0]}申请mes任务结果{str}");
                                if (str.Contains("true"))
                                {
                                    tag.Js1.D1212_LAST = 1;
                                    //tag.Js1.D1212_LAST = 1;
                                    RedisHelper.Add($"Js捷顺1.D1212_LAST", "1", out string msg);
                                }
                            }
                            if(tag.Js1.D1212_LAST == 1 &&TcpServer.GetBitdata(tag.Js1.D1212, 2) == 0){
                        tag.Js1.D1212_LAST = 0;
                            if (tag.Js1.D1212_LAST == 1 && TcpServer.GetBitdata(tag.Js1.D1212, 2) == 0)
                            {
                                //tag.Js1.D1212_LAST = 0;
                                RedisHelper.Add($"Js捷顺1.D1212_LAST", "0", out string msg);
                            }
                     if (tag.Js1.D1213_LAST == 0 && TcpServer.GetBitdata(tag.Js1.D1212, 3) == 1)
                     {
                        var str = Settings.apiHelper.Post(Settings.WMSbaseUrl + "mom-basic/dataTransmission/json/service/200", JsonConvert.SerializeObject(new
                        {
                           requestType = 4,
                           endBit = VERX.location[1]
                        }));
                        LogHelper.Info($"{VERX.location[1]}申请mes任务结果{str}");
                        if (str.Contains("true"))
                        {
                           tag.Js1.D1213_LAST = 1;
                        }
                     }if(tag.Js1.D1213_LAST == 1 &&TcpServer.GetBitdata(tag.Js1.D1212, 3) == 0){
                        tag.Js1.D1213_LAST = 0;
                            if (tag.Js1.D1213_LAST == 0 && TcpServer.GetBitdata(tag.Js1.D1212, 3) == 1)
                            {
                                var str = Settings.apiHelper.Post(Settings.WMSbaseUrl + "mom-basic/dataTransmission/json/service/200", JsonConvert.SerializeObject(new
                                {
                                    requestType = 4,
                                    endBit = VERX.location[1]
                                }));
                                LogHelper.Info($"{VERX.location[1]}申请mes任务结果{str}");
                                if (str.Contains("true"))
                                {
                                    //tag.Js1.D1213_LAST = 1;
                                    RedisHelper.Add($"Js捷顺1.D1213_LAST", "1", out string msg);
                                }
                            }
                            if (tag.Js1.D1213_LAST == 1 && TcpServer.GetBitdata(tag.Js1.D1212, 3) == 0)
                            {
                                //tag.Js1.D1213_LAST = 0;
                                RedisHelper.Add($"Js捷顺1.D1213_LAST", "0", out string msg);
                            }
                        }
            #endregion [脚本][20250325083325390][业务逻辑.第三标段.捷瞬抓臂1]
         }
         catch(Exception ex)
         {
            Conn.默认日志.Error(ex.ToString());
         }
         finally
         {
            System.Threading.Thread.Sleep(3000);
         }
         }
            ExitJudgeStack.TryPop(out int exitJudgeVal);
});
         /// <summary>
         /// ç¨‹åºç‰‡æ®µ:捷瞬抓臂2
         /// æè¿°:
         /// </summary>
         System.Threading.Tasks.Task.Factory.StartNew(() =>
         {
            System.Threading.Thread.CurrentThread.IsBackground = true;
            ExitJudgeStack.Push(0);
         //一直执行,直到满足结束条件
         while(true)
         {
            if (IsExitApp) { break; }
         try
         {
            #region    [脚本][20250325083326611][业务逻辑.第三标段.捷瞬抓臂2]
            //jsz2捷瞬抓臂2
                        #endregion [脚本][20250325083325390][业务逻辑.第三标段.捷瞬抓臂1]
                    }
                    catch (Exception ex)
                    {
                        Conn.默认日志.Error(ex.ToString());
                    }
                    finally
                    {
                        System.Threading.Thread.Sleep(3000);
                    }
                }
                ExitJudgeStack.TryPop(out int exitJudgeVal);
            });
            /// <summary>
            /// ç¨‹åºç‰‡æ®µ:捷瞬抓臂2
            /// æè¿°:
            /// </summary>
            System.Threading.Tasks.Task.Factory.StartNew(() =>
            {
                System.Threading.Thread.CurrentThread.IsBackground = true;
                ExitJudgeStack.Push(0);
                //一直执行,直到满足结束条件
                while (true)
                {
                    if (IsExitApp) { break; }
                    try
                    {
                        #region    [脚本][20250325083326611][业务逻辑.第三标段.捷瞬抓臂2]
                        //jsz2捷瞬抓臂2
                       var VERX = Settings.deviceInfos?.Find(x =>x.deviceType==2&& x.deviceName == "Js捷顺2");
                        var VERX = Settings.deviceInfos?.Find(x => x.deviceType == 2 && x.deviceName == "Js捷顺2");
                        if (VERX != null)
                        {
@@ -253,10 +262,16 @@
                                LogHelper.Info($"{VERX.location[0]}申请mes任务结果{str}");
                                if (str.Contains("true"))
                                {
                                    tag.Js2.D1212_LAST = 1;
                                    //tag.Js2.D1212_LAST = 1;
                                    RedisHelper.Add($"Js捷顺1.D1212_LAST", "1", out string msg);
                                }
                            } if(tag.Js2.D1212_LAST == 1 &&TcpServer.GetBitdata(tag.Js2.D1212, 2) == 0){
                        tag.Js2.D1212_LAST = 0;
                            }
                            if (tag.Js2.D1212_LAST == 1 && TcpServer.GetBitdata(tag.Js2.D1212, 2) == 0)
                            {
                                //tag.Js2.D1212_LAST = 0;
                                RedisHelper.Add($"Js捷顺1.D1212_LAST", "0", out string msg);
                            }
                            if (tag.Js2.D1213_LAST == 0 && TcpServer.GetBitdata(tag.Js2.D1212, 3) == 1)
                            {
@@ -268,74 +283,80 @@
                                LogHelper.Info($"{VERX.location[1]}申请mes任务结果{str}");
                                if (str.Contains("true"))
                                {
                                    tag.Js2.D1213_LAST = 1;
                                    //tag.Js2.D1213_LAST = 1;
                                    RedisHelper.Add($"Js捷顺1.D1213_LAST", "1", out string msg);
                                }
                            }if(tag.Js2.D1213_LAST == 1 &&TcpServer.GetBitdata(tag.Js2.D1213, 2) == 0){
                        tag.Js2.D1213_LAST = 0;
                            }
                            if (tag.Js2.D1213_LAST == 1 && TcpServer.GetBitdata(tag.Js2.D1213, 2) == 0)
                            {
                                //tag.Js2.D1213_LAST = 0;
                                RedisHelper.Add($"Js捷顺1.D1213_LAST", "0", out string msg);
                            }
                        }
            #endregion [脚本][20250325083326611][业务逻辑.第三标段.捷瞬抓臂2]
         }
         catch(Exception ex)
         {
            Conn.默认日志.Error(ex.ToString());
         }
         finally
         {
            System.Threading.Thread.Sleep(3000);
         }
         }
            ExitJudgeStack.TryPop(out int exitJudgeVal);
});
         /// <summary>
         /// ç¨‹åºç‰‡æ®µ:自流转流程
         /// æè¿°:
         /// </summary>
         System.Threading.Tasks.Task.Factory.StartNew(() =>
         {
            System.Threading.Thread.CurrentThread.IsBackground = true;
            ExitJudgeStack.Push(0);
         //一直执行,直到满足结束条件
         while(true)
         {
            if (IsExitApp) { break; }
         try
         {
            #region    [脚本][20250325085810885][业务逻辑.第三标段.自流转流程]
            //foreach(var di in Settings.deviceInfos)
//   if (di.deviceType == 2 || di.deviceType == 1)
//   RunafterMac(di,true);
   /// TODO  mes ä¸‹å‘。   æ”¹æˆæœºæ¢°è‡‚监控 -  ç›‘控空的还是满的 - è”动mes ä»»åŠ¡ã€‚
            #endregion [脚本][20250325085810885][业务逻辑.第三标段.自流转流程]
         }
         catch(Exception ex)
         {
            Conn.默认日志.Error(ex.ToString());
         }
         finally
         {
            System.Threading.Thread.Sleep(3000);
         }
         }
            ExitJudgeStack.TryPop(out int exitJudgeVal);
});
         /// <summary>
         /// ç¨‹åºç‰‡æ®µ:维希尔抓臂1L
         /// æè¿°:
         /// </summary>
         System.Threading.Tasks.Task.Factory.StartNew(() =>
         {
            System.Threading.Thread.CurrentThread.IsBackground = true;
            ExitJudgeStack.Push(0);
         //一直执行,直到满足结束条件
         while(true)
         {
            if (IsExitApp) { break; }
         try
         {
            #region    [脚本][20250325083149366][业务逻辑.第三标段.维系尔1号.维希尔抓臂1L]
var VERX = Settings.deviceInfos?.Find(x => x.deviceType == 1 && x.deviceName.Contains("1"));
                        #endregion [脚本][20250325083326611][业务逻辑.第三标段.捷瞬抓臂2]
                    }
                    catch (Exception ex)
                    {
                        Conn.默认日志.Error(ex.ToString());
                    }
                    finally
                    {
                        System.Threading.Thread.Sleep(3000);
                    }
                }
                ExitJudgeStack.TryPop(out int exitJudgeVal);
            });
            /// <summary>
            /// ç¨‹åºç‰‡æ®µ:自流转流程
            /// æè¿°:
            /// </summary>
            System.Threading.Tasks.Task.Factory.StartNew(() =>
            {
                System.Threading.Thread.CurrentThread.IsBackground = true;
                ExitJudgeStack.Push(0);
                //一直执行,直到满足结束条件
                while (true)
                {
                    if (IsExitApp) { break; }
                    try
                    {
                        #region    [脚本][20250325085810885][业务逻辑.第三标段.自流转流程]
                        //foreach(var di in Settings.deviceInfos)
                        //   if (di.deviceType == 2 || di.deviceType == 1)
                        //   RunafterMac(di,true);
                        /// TODO  mes ä¸‹å‘。   æ”¹æˆæœºæ¢°è‡‚监控 -  ç›‘控空的还是满的 - è”动mes ä»»åŠ¡ã€‚
                        #endregion [脚本][20250325085810885][业务逻辑.第三标段.自流转流程]
                    }
                    catch (Exception ex)
                    {
                        Conn.默认日志.Error(ex.ToString());
                    }
                    finally
                    {
                        System.Threading.Thread.Sleep(3000);
                    }
                }
                ExitJudgeStack.TryPop(out int exitJudgeVal);
            });
            /// <summary>
            /// ç¨‹åºç‰‡æ®µ:维希尔抓臂1L
            /// æè¿°:
            /// </summary>
            System.Threading.Tasks.Task.Factory.StartNew(() =>
            {
                System.Threading.Thread.CurrentThread.IsBackground = true;
                ExitJudgeStack.Push(0);
                //一直执行,直到满足结束条件
                while (true)
                {
                    if (IsExitApp) { break; }
                    try
                    {
                        #region    [脚本][20250325083149366][业务逻辑.第三标段.维系尔1号.维希尔抓臂1L]
                        var VERX = Settings.deviceInfos?.Find(x => x.deviceType == 1 && x.deviceName.Contains("1"));
                        if (VERX != null)
                        {
@@ -353,7 +374,7 @@
                                    LogHelper.Info($"{VERX.location[0]}申请mes任务结果{str}");
                                    if (str.Contains("true"))
                                    {
                                        tag.wxr1.R44_LAST = true;
                                        tag.wxr1.R44_LAST = true;
                                    }
                                }
                                else
@@ -363,14 +384,15 @@
                            }
                            else
                            {
                               //TaskRepository ts = new TaskRepository();
                                //TaskRepository ts = new TaskRepository();
                                if (tag.wxr1.R10_LAST) //托盘放置信号。。
                                {
                                   if (tag.wxr1.R10)
                           {
                           tag.wxr1.R10_LAST=false;
                           } else
                                    if (TcpServer.TrayIps.TryGetValue(VERX.deviceNo[0],out string traycode))
                                    if (tag.wxr1.R10)
                                    {
                                        tag.wxr1.R10_LAST = false;
                                    }
                                    else
                                    if (TcpServer.TrayIps.TryGetValue(VERX.deviceNo[0], out string traycode))
                                    {
                                        //上报校验。
                                        ///var str = Settings.apiHelper.Post(Settings.MESbaseUrl + "mom-basic/dataTransmission/json/service/202", requestJson);
@@ -394,35 +416,35 @@
                                }
                            }
                        }
            #endregion [脚本][20250325083149366][业务逻辑.第三标段.维系尔1号.维希尔抓臂1L]
         }
         catch(Exception ex)
         {
            Conn.默认日志.Error(ex.ToString());
         }
         finally
         {
            System.Threading.Thread.Sleep(3000);
         }
         }
            ExitJudgeStack.TryPop(out int exitJudgeVal);
});
         /// <summary>
         /// ç¨‹åºç‰‡æ®µ:维希尔抓臂1R
         /// æè¿°:
         /// </summary>
         System.Threading.Tasks.Task.Factory.StartNew(() =>
         {
            System.Threading.Thread.CurrentThread.IsBackground = true;
            ExitJudgeStack.Push(0);
         //一直执行,直到满足结束条件
         while(true)
         {
            if (IsExitApp) { break; }
         try
         {
            #region    [脚本][20250610002047005][业务逻辑.第三标段.维系尔1号.维希尔抓臂1R]
            var VERX = Settings.deviceInfos?.Find(x => x.deviceType == 1 && x.deviceName.Contains("1"));
                        #endregion [脚本][20250325083149366][业务逻辑.第三标段.维系尔1号.维希尔抓臂1L]
                    }
                    catch (Exception ex)
                    {
                        Conn.默认日志.Error(ex.ToString());
                    }
                    finally
                    {
                        System.Threading.Thread.Sleep(3000);
                    }
                }
                ExitJudgeStack.TryPop(out int exitJudgeVal);
            });
            /// <summary>
            /// ç¨‹åºç‰‡æ®µ:维希尔抓臂1R
            /// æè¿°:
            /// </summary>
            System.Threading.Tasks.Task.Factory.StartNew(() =>
            {
                System.Threading.Thread.CurrentThread.IsBackground = true;
                ExitJudgeStack.Push(0);
                //一直执行,直到满足结束条件
                while (true)
                {
                    if (IsExitApp) { break; }
                    try
                    {
                        #region    [脚本][20250610002047005][业务逻辑.第三标段.维系尔1号.维希尔抓臂1R]
                        var VERX = Settings.deviceInfos?.Find(x => x.deviceType == 1 && x.deviceName.Contains("1"));
                        if (VERX != null)
                        {
@@ -440,7 +462,7 @@
                                    LogHelper.Info($"{VERX.location[1]}申请mes任务结果{str}");
                                    if (str.Contains("true"))
                                    {
                                        tag.wxr1.R46_LAST = true;
                                        tag.wxr1.R46_LAST = true;
                                    }
                                }
                                else
@@ -452,11 +474,12 @@
                            {
                                if (tag.wxr1.R11_LAST) //托盘放置信号。。
                                {
                                   if (tag.wxr1.R11)
                           {
                           tag.wxr1.R11_LAST=false;
                           } else
                                    if (TcpServer.TrayIps.TryGetValue(VERX.deviceNo[1],out string traycode))
                                    if (tag.wxr1.R11)
                                    {
                                        tag.wxr1.R11_LAST = false;
                                    }
                                    else
                                    if (TcpServer.TrayIps.TryGetValue(VERX.deviceNo[1], out string traycode))
                                    {
                                        //上报校验。
                                        ///var str = Settings.apiHelper.Post(Settings.MESbaseUrl + "mom-basic/dataTransmission/json/service/202", requestJson);
@@ -480,36 +503,36 @@
                                }
                            }
                        }
            #endregion [脚本][20250610002047005][业务逻辑.第三标段.维系尔1号.维希尔抓臂1R]
         }
         catch(Exception ex)
         {
            Conn.默认日志.Error(ex.ToString());
         }
         finally
         {
            System.Threading.Thread.Sleep(3000);
         }
         }
            ExitJudgeStack.TryPop(out int exitJudgeVal);
});
         /// <summary>
         /// ç¨‹åºç‰‡æ®µ:维希尔抓臂2L
         /// æè¿°:
         /// </summary>
         System.Threading.Tasks.Task.Factory.StartNew(() =>
         {
            System.Threading.Thread.CurrentThread.IsBackground = true;
            ExitJudgeStack.Push(0);
         //一直执行,直到满足结束条件
         while(true)
         {
            if (IsExitApp) { break; }
         try
         {
            #region    [脚本][20250325083315503][业务逻辑.第三标段.维系尔2号.维希尔抓臂2L]
var VERX = Settings.deviceInfos?.Find(x => x.deviceType == 1 && x.deviceName.Contains("2"));
                        #endregion [脚本][20250610002047005][业务逻辑.第三标段.维系尔1号.维希尔抓臂1R]
                    }
                    catch (Exception ex)
                    {
                        Conn.默认日志.Error(ex.ToString());
                    }
                    finally
                    {
                        System.Threading.Thread.Sleep(3000);
                    }
                }
                ExitJudgeStack.TryPop(out int exitJudgeVal);
            });
            /// <summary>
            /// ç¨‹åºç‰‡æ®µ:维希尔抓臂2L
            /// æè¿°:
            /// </summary>
            System.Threading.Tasks.Task.Factory.StartNew(() =>
            {
                System.Threading.Thread.CurrentThread.IsBackground = true;
                ExitJudgeStack.Push(0);
                //一直执行,直到满足结束条件
                while (true)
                {
                    if (IsExitApp) { break; }
                    try
                    {
                        #region    [脚本][20250325083315503][业务逻辑.第三标段.维系尔2号.维希尔抓臂2L]
                        var VERX = Settings.deviceInfos?.Find(x => x.deviceType == 1 && x.deviceName.Contains("2"));
                        if (VERX != null)
                        {
@@ -527,7 +550,7 @@
                                    LogHelper.Info($"{VERX.location[0]}申请mes任务结果{str}");
                                    if (str.Contains("true"))
                                    {
                                        tag.wxr2.R44_LAST = true;
                                        tag.wxr2.R44_LAST = true;
                                    }
                                }
                                else
@@ -539,11 +562,12 @@
                            {
                                if (tag.wxr2.R10_LAST) //托盘放置信号。。
                                {
                                   if (tag.wxr2.R10)
                           {
                              tag.wxr2.R10_LAST=false;
                           } else
                                    if (TcpServer.TrayIps.TryGetValue(VERX.deviceNo[0],out string traycode))
                                    if (tag.wxr2.R10)
                                    {
                                        tag.wxr2.R10_LAST = false;
                                    }
                                    else
                                    if (TcpServer.TrayIps.TryGetValue(VERX.deviceNo[0], out string traycode))
                                    {
                                        //上报校验。
                                        ///var str = Settings.apiHelper.Post(Settings.MESbaseUrl + "mom-basic/dataTransmission/json/service/202", requestJson);
@@ -567,35 +591,35 @@
                                }
                            }
                        }
            #endregion [脚本][20250325083315503][业务逻辑.第三标段.维系尔2号.维希尔抓臂2L]
         }
         catch(Exception ex)
         {
            Conn.默认日志.Error(ex.ToString());
         }
         finally
         {
            System.Threading.Thread.Sleep(3000);
         }
         }
            ExitJudgeStack.TryPop(out int exitJudgeVal);
});
         /// <summary>
         /// ç¨‹åºç‰‡æ®µ:维希尔抓臂2R
         /// æè¿°:
         /// </summary>
         System.Threading.Tasks.Task.Factory.StartNew(() =>
         {
            System.Threading.Thread.CurrentThread.IsBackground = true;
            ExitJudgeStack.Push(0);
         //一直执行,直到满足结束条件
         while(true)
         {
            if (IsExitApp) { break; }
         try
         {
            #region    [脚本][20250610002647095][业务逻辑.第三标段.维系尔2号.维希尔抓臂2R]
            var VERX = Settings.deviceInfos?.Find(x => x.deviceType == 1 && x.deviceName.Contains("2"));
                        #endregion [脚本][20250325083315503][业务逻辑.第三标段.维系尔2号.维希尔抓臂2L]
                    }
                    catch (Exception ex)
                    {
                        Conn.默认日志.Error(ex.ToString());
                    }
                    finally
                    {
                        System.Threading.Thread.Sleep(3000);
                    }
                }
                ExitJudgeStack.TryPop(out int exitJudgeVal);
            });
            /// <summary>
            /// ç¨‹åºç‰‡æ®µ:维希尔抓臂2R
            /// æè¿°:
            /// </summary>
            System.Threading.Tasks.Task.Factory.StartNew(() =>
            {
                System.Threading.Thread.CurrentThread.IsBackground = true;
                ExitJudgeStack.Push(0);
                //一直执行,直到满足结束条件
                while (true)
                {
                    if (IsExitApp) { break; }
                    try
                    {
                        #region    [脚本][20250610002647095][业务逻辑.第三标段.维系尔2号.维希尔抓臂2R]
                        var VERX = Settings.deviceInfos?.Find(x => x.deviceType == 1 && x.deviceName.Contains("2"));
                        if (VERX != null)
                        {
@@ -613,7 +637,7 @@
                                    LogHelper.Info($"{VERX.location[1]}申请mes任务结果{str}");
                                    if (str.Contains("true"))
                                    {
                                        tag.wxr2.R46_LAST = true;
                                        tag.wxr2.R46_LAST = true;
                                    }
                                }
                                else
@@ -623,13 +647,14 @@
                            }
                            else
                            {
                               if (tag.wxr2.R11_LAST) //托盘放置信号。。
                                if (tag.wxr2.R11_LAST) //托盘放置信号。。
                                {
                                   if (tag.wxr2.R11)
                           {
                              tag.wxr2.R11_LAST=false;
                           } else
                                    if (TcpServer.TrayIps.TryGetValue(VERX.deviceNo[1],out string traycode))
                                    if (tag.wxr2.R11)
                                    {
                                        tag.wxr2.R11_LAST = false;
                                    }
                                    else
                                    if (TcpServer.TrayIps.TryGetValue(VERX.deviceNo[1], out string traycode))
                                    {
                                        //上报校验。
                                        ///var str = Settings.apiHelper.Post(Settings.MESbaseUrl + "mom-basic/dataTransmission/json/service/202", requestJson);
@@ -653,115 +678,395 @@
                                }
                            }
                        }
            #endregion [脚本][20250610002647095][业务逻辑.第三标段.维系尔2号.维希尔抓臂2R]
         }
         catch(Exception ex)
         {
            Conn.默认日志.Error(ex.ToString());
         }
         finally
         {
            System.Threading.Thread.Sleep(3000);
         }
         }
            ExitJudgeStack.TryPop(out int exitJudgeVal);
});
         /// <summary>
         /// ç¨‹åºç‰‡æ®µ:任务下发
         /// æè¿°:
         /// </summary>
         System.Threading.Tasks.Task.Factory.StartNew(() =>
         {
            System.Threading.Thread.CurrentThread.IsBackground = true;
            ExitJudgeStack.Push(0);
         //一直执行,直到满足结束条件
         while(true)
         {
            if (IsExitApp) { break; }
         try
         {
            #region    [脚本][20250325085542733][业务逻辑.任务下发]
            #endregion [脚本][20250325085542733][业务逻辑.任务下发]
         }
         catch(Exception ex)
         {
            Conn.默认日志.Error(ex.ToString());
         }
         finally
         {
            System.Threading.Thread.Sleep(3000);
         }
         }
            ExitJudgeStack.TryPop(out int exitJudgeVal);
});
         /// <summary>
         /// ç¨‹åºç‰‡æ®µ:ResolveMesTask
         /// æè¿°:
         /// </summary>
         System.Threading.Tasks.Task.Factory.StartNew(() =>
         {
            System.Threading.Thread.CurrentThread.IsBackground = true;
            ExitJudgeStack.Push(0);
         //一直执行,直到满足结束条件
         while(true)
         {
            if (IsExitApp) { break; }
         try
         {
            #region    [脚本][20250531163716255][业务逻辑.处理MES任务线程.ResolveMesTask]
            //mes ä»»åŠ¡æ‹†åˆ†ã€‚ä¸€æ®µä»»åŠ¡å’Œ å¤šæ®µä»»åŠ¡ã€‚
ToWMSMES.ResMesTask();
            #endregion [脚本][20250531163716255][业务逻辑.处理MES任务线程.ResolveMesTask]
         }
         catch(Exception ex)
         {
            Conn.默认日志.Error(ex.ToString());
         }
         finally
         {
            System.Threading.Thread.Sleep(3000);
         }
         }
            ExitJudgeStack.TryPop(out int exitJudgeVal);
});
         try
         {
            #region    [脚本][20250605212104026][业务逻辑.SocketServer]
            var host = System.Net.Dns.GetHostEntry(System.Net.Dns.GetHostName());
foreach (var ip in host.AddressList)
{
    if (ip.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
    {
        Console.WriteLine($"ip= {ip.ToString()}");
        new TcpServer(ip.ToString());
    }
}
            #endregion [脚本][20250605212104026][业务逻辑.SocketServer]
         }
         catch(Exception ex)
         {
            Conn.默认日志.Error(ex.ToString());
         }
         finally
         {
         }
         /// <summary>
         /// ç¨‹åºç‰‡æ®µ:光栅处理
         /// æè¿°:
         /// </summary>
         System.Threading.Tasks.Task.Factory.StartNew(() =>
         {
            System.Threading.Thread.CurrentThread.IsBackground = true;
            ExitJudgeStack.Push(0);
         //一直执行,直到满足结束条件
         while(true)
         {
            if (IsExitApp) { break; }
         try
         {
            #region    [脚本][20250611223832523][业务逻辑.光栅处理]
            // - å…‰æ …交互处理。。
                        #endregion [脚本][20250610002647095][业务逻辑.第三标段.维系尔2号.维希尔抓臂2R]
                    }
                    catch (Exception ex)
                    {
                        Conn.默认日志.Error(ex.ToString());
                    }
                    finally
                    {
                        System.Threading.Thread.Sleep(3000);
                    }
                }
                ExitJudgeStack.TryPop(out int exitJudgeVal);
            });
            /// <summary>
            /// ç¨‹åºç‰‡æ®µ:任务下发
            /// æè¿°:
            /// </summary>
            System.Threading.Tasks.Task.Factory.StartNew(() =>
            {
                System.Threading.Thread.CurrentThread.IsBackground = true;
                ExitJudgeStack.Push(0);
                //一直执行,直到满足结束条件
                while (true)
                {
                    if (IsExitApp) { break; }
                    try
                    {
                        #region    [脚本][20250325085542733][业务逻辑.任务下发]
                        ITaskRepository taskservice = new TaskRepository();
                        var tklist = taskservice.FindList(x => x.S_B_STATE == "未执行" && x.S_WORK_MODE == "AGV");
                        if (tklist.Any())
                            foreach (var tk in tklist.GroupBy(item =>
                            {
                                var ticks = item.T_CREATE.Ticks;
                                return new DateTime(ticks - ticks % (10 * TimeSpan.TicksPerMinute));
                            }).OrderBy(x => x.Key))
                            {
                                var ts = tk.OrderByDescending(x => x.N_PRIORITY).ToList();
                                foreach (var t in ts)
                                {
                                    var b = false;
                                    b = RunTask(t);
                                    if (b)
                                    {
                                        t.S_B_STATE = "已推送";
                                        taskservice.Update(t);
                                    }
                                }
                                break;
                            }
                        //foreach (var tk in tklist.GroupBy(item =>
                        //{
                        //    var ticks = item.T_CREATE.Ticks;
                        //    return new DateTime(ticks - ticks % (10 * TimeSpan.TicksPerMinute));
                        //}).OrderBy(x => x.Key))
                        //if (tklist.Any())
                        //{
                        try
                        {
                            #region Rgv
                            LogHelper.Info($"查看RGV ç”µé‡ï¼šã€{tag.RGV.R当前电量}】 å……电状态:【{tag.RGV.R充电状态}】 æ•…障代码:【{tag.RGV.RgvrunError}】");
                            var task1Isrun = false;
                            if (tag.RGV.ReadTask1No > 0 && tag.RGV.bit1taskOver != 1)
                            {
                                task1Isrun = true;
                                if (tag.RGV.bit1taskOver_LAST == 1)
                                    RedisHelper.Add($"RGV.bit1taskOver_LAST", "0", out string msg);
                            }
                            var task2Isrun = false;
                            if (tag.RGV.ReadTask2No > 0 && tag.RGV.bit2taskOver != 1)
                            {
                                task2Isrun = true;
                                if (tag.RGV.bit2taskOver_LAST == 1)
                                    RedisHelper.Add($"RGV.bit2taskOver_LAST", "0", out string msg);
                            }
                            if (task1Isrun || task2Isrun)
                            {
                                string mes = "";
                                if (task1Isrun)
                                    mes += tag.RGV.ReadTask1No + "执行中...";
                                if (task2Isrun)
                                    mes += tag.RGV.ReadTask2No + "执行中...";
                                LogHelper.Info($"{mes} ä¸èƒ½ä¸‹å‘新任务。");
                                throw new Exception($"{mes} ä¸èƒ½ä¸‹å‘新任务。");
                            }
                            var thisOver = 0;
                            TaskEntity task1 = null;
                            TaskEntity task2 = null;
                            LogHelper.Info($"查看RGV 1工位任务》");
                            if (tag.RGV.ReadTask1No > 0 && tag.RGV.bit1taskOver == 1)
                            {
                                var taskno = tag.RGV.ReadTask1No;
                                LogHelper.Info($"RGV 1工位任务{tag.RGV.ReadTask1No}");
                                string tno = "TN" + (DateTime.Now.ToString("yy")) + ((taskno.ToString()).PadLeft(8, '0'));
                                task1 = taskservice.FindEntity(x => x.S_TASK_NO == tno);
                                LogHelper.Info($"RGV 1工位任务{JsonConvert.SerializeObject(task1)}.bit1taskOver_LAST:{tag.RGV.bit1taskOver_LAST}");
                                if (tag.RGV.bit1taskOver_LAST == 0 && task1 != null)
                                {
                                    if (task1.S_B_STATE != "完成")
                                    {
                                        thisOver = 1;
                                        if (task1.S_B_STATE == "取货完成")
                                        {
                                            task1.S_B_STATE = "完成";
                                        }
                                        else
                                        {
                                            task1.S_B_STATE = "取货完成";
                                        }
                                        LogHelper.Info($"RGV 1工位任务{task1.S_TASK_NO} çŠ¶æ€åˆ‡æ¢ä¸º{task1.S_B_STATE}");
                                        //tag.RGV.bit1taskOver_LAST = 1;
                                        RedisHelper.Add($"RGV.bit1taskOver_LAST", "1", out string msg);
                                        LogHelper.Info($"RGV 1工位任务写处理");
                                        taskservice.Update(task1);
                                        LogHelper.Info($"RGV 1工位任务更新。");
                                    }
                                    else
                                    {
                                        LogHelper.Info("RGV1工位任务已经完成。");
                                    }
                                }
                            }
                            else if (tag.RGV.ReadTask1No == 0)
                            {
                                LogHelper.Info($"RGV 1工位没有任务》");
                            }
                            LogHelper.Info($"查看RGV 2工位任务》");
                            if (tag.RGV.ReadTask2No > 0 && tag.RGV.bit2taskOver == 1)
                            {
                                var taskno = tag.RGV.ReadTask2No;
                                LogHelper.Info($"RGV 2工位任务{tag.RGV.ReadTask2No}");
                                string tno = "TN" + (DateTime.Now.ToString("yy")) + ((taskno.ToString()).PadLeft(8, '0'));
                                task2 = taskservice.FindEntity(x => x.S_TASK_NO == tno);
                                LogHelper.Info($"RGV2工位任务{JsonConvert.SerializeObject(task2)}.bit2taskOver_LAST:{tag.RGV.bit2taskOver_LAST}");
                                if (tag.RGV.bit2taskOver_LAST == 0 && task2 != null)
                                {
                                    if (task2.S_B_STATE != "完成")
                                    {
                                        thisOver = 2;
                                        if (task2.S_B_STATE == "取货完成")
                                        {
                                            task2.S_B_STATE = "完成";
                                        }
                                        else
                                        {
                                            task2.S_B_STATE = "取货完成";
                                        }
                                        LogHelper.Info($"RGV 2工位任务{task2.S_TASK_NO} çŠ¶æ€åˆ‡æ¢ä¸º{task2.S_B_STATE}");
                                        RedisHelper.Add($"RGV.bit2taskOver_LAST", "1", out string msg);
                                        LogHelper.Info($"RGV 2工位任务写处理");
                                        taskservice.Update(task2);
                                        LogHelper.Info($"RGV 2工位任务更新。");
                                    }
                                    else
                                    {
                                        LogHelper.Info("RGV2工位任务已经完成。");
                                    }
                                }
                            }
                            else if (tag.RGV.ReadTask2No == 0)
                            {
                                LogHelper.Info($"RGV 2工位没有任务》");
                            }
                            //if (thisOver > 0)
                            {
                                var v2 = RedisHelper.Get<WriteGroupEntity>("RGVQueue", out string rev);
                                if (v2 != null)
                                {
                                    LogHelper.Info($"RGVQueue è¯»åˆ°ç»“æžœ-{JsonConvert.SerializeObject(v2)}  \n ä¸‹å‘前进行清除。");
                                    var b = RedisHelper.Remove("RGVQueue", out rev);
                                }
                            }
                            ///1 æœ‰è´§  å°±2 å–。  1 æ²¡è´§ å°±2 å¸è´§ï¼Œ éƒ½æœ‰è´§  å°±1卸货。 éƒ½æ²¡è´§ å°±1卸
                            tklist = taskservice.FindList(x => x.S_B_STATE == "未执行" && x.S_WORK_MODE == "RGV").OrderBy(x => x.T_CREATE).ToList();
                            if (task1 != null && task1.S_B_STATE != "完成") //1有任务
                            {
                                if (task2 != null && task2.S_B_STATE != "完成")// 1 æœ‰ä»»åŠ¡  2 æœ‰ä»»åŠ¡ã€‚
                                {
                                    LogHelper.Info($"查看RGV1 æœ‰ä»»åŠ¡{task1.S_TASK_NO},工位2 ä¹Ÿæœ‰ä»»åŠ¡{task2.S_TASK_NO}。 å¼€å§‹å·¥ä½1 å¸è´§ã€‚");
                                    tag.RGV.workMod = 1;
                                    tag.RGV.taskmod = 2;
                                    tag.RGV.taskno1 = Convert.ToUInt32(task1.S_TASK_NO.Substring(4));
                                    tag.RGV.task1do = Convert.ToUInt16(task1.S_END_LOC);
                                    System.Threading.Thread.Sleep(750);
                                    RedisHelper.Add($"RGV.bit1taskOver_LAST", "0", out string msg);
                                    tag.RGV.taskend = 125;
                                }
                                else //1有任务  2 æ²¡ä»»åŠ¡ã€‚
                                {
                                    LogHelper.Info($"查看RGV1 æœ‰ä»»åŠ¡{task1.S_TASK_NO},工位2 æ²¡ä»»åŠ¡ã€‚ æ‰¾åŒä¾§å–货任务。");
                                    //1 å¦‚果有同侧取货任务。就取。没有
                                    var leftSide = new List<string> { "1023", "1020" };
                                    var RightSide = new List<string> { "1002", "1008", "1010", "1016" };
                                    bool creT2 = false;
                                    if (leftSide.Contains(task1.S_START_LOC))
                                    {
                                        leftSide.Remove(task1.S_START_LOC);
                                        var lsde = leftSide.FirstOrDefault();
                                        var t2 = tklist.Find(x => x.S_START_LOC == lsde && x.S_END_LOC != "1017");
                                        if (t2 != null) //同侧取货任务。
                                        {
                                            LogHelper.Info($"查看RGV1 æœ‰ä»»åŠ¡{task1.S_TASK_NO},工位2 æ²¡ä»»åŠ¡ã€‚ æ‰¾åŒä¾§å–货任务{t2.S_TASK_NO}。");
                                            tag.RGV.workMod = 2;
                                            tag.RGV.taskmod = 1;
                                            tag.RGV.taskno2 = Convert.ToUInt32(t2.S_TASK_NO.Substring(4));
                                            tag.RGV.task2do = Convert.ToUInt16(t2.S_START_LOC);
                                            t2.S_B_STATE = "已推送";
                                            taskservice.Update(t2);
                                            creT2 = true;
                                            System.Threading.Thread.Sleep(750);
                                            RedisHelper.Add($"RGV.bit2taskOver_LAST", "0", out string msg);
                                            tag.RGV.taskend = 125;
                                        }
                                    }
                                    else if (RightSide.Contains(task1.S_START_LOC))
                                    {
                                        RightSide.Remove(task1.S_START_LOC);
                                        var t2 = tklist.Find(x => RightSide.Contains(x.S_START_LOC) && x.S_END_LOC != "1017");
                                        if (t2 != null) //同侧取货任务。
                                        {
                                            LogHelper.Info($"查看RGV1 æœ‰ä»»åŠ¡{task1.S_TASK_NO},工位2 æ²¡ä»»åŠ¡ã€‚ æ‰¾åŒä¾§å–货任务{t2.S_TASK_NO}。");
                                            tag.RGV.workMod = 2;
                                            tag.RGV.taskmod = 1;
                                            tag.RGV.taskno2 = Convert.ToUInt32(t2.S_TASK_NO.Substring(4));
                                            tag.RGV.task2do = Convert.ToUInt16(t2.S_START_LOC);
                                            t2.S_B_STATE = "已推送";
                                            taskservice.Update(t2);
                                            creT2 = true;
                                            System.Threading.Thread.Sleep(750);
                                            RedisHelper.Add($"RGV.bit2taskOver_LAST", "0", out string msg);
                                            tag.RGV.taskend = 125;
                                        }
                                    }
                                    //else //1 ç›´æŽ¥å¸è´§ã€‚
                                    if (!creT2)
                                    {
                                        LogHelper.Info($"查看RGV1 æœ‰ä»»åŠ¡{task1.S_TASK_NO},工位2 æ²¡ä»»åŠ¡ã€‚ æ²¡æœ‰åŒä¾§å–货任务 1工位卸货。");
                                        tag.RGV.workMod = 1;
                                        tag.RGV.taskmod = 2;
                                        tag.RGV.taskno1 = Convert.ToUInt32(task1.S_TASK_NO.Substring(4));
                                        tag.RGV.task1do = Convert.ToUInt16(task1.S_END_LOC);
                                        System.Threading.Thread.Sleep(750);
                                        RedisHelper.Add($"RGV.bit1taskOver_LAST", "0", out string msg);
                                        tag.RGV.taskend = 125;
                                    }
                                }
                            }
                            else
                            {
                                if (task2 != null && task2.S_B_STATE != "完成")// 1 æ²¡ä»»åŠ¡  2 æœ‰ä»»åŠ¡ã€‚
                                {
                                    LogHelper.Info($"查看RGV 1工位没任务,工位2 æœ‰ä»»åŠ¡{task2.S_TASK_NO}。工位2卸货。。");
                                    //2 å¸è´§ã€‚
                                    tag.RGV.workMod = 2;
                                    tag.RGV.taskmod = 2;
                                    tag.RGV.taskno2 = Convert.ToUInt32(task2.S_TASK_NO.Substring(4));
                                    tag.RGV.task2do = Convert.ToUInt16(task2.S_END_LOC);
                                    System.Threading.Thread.Sleep(750);
                                    RedisHelper.Add($"RGV.bit2taskOver_LAST", "0", out string msg);
                                    tag.RGV.taskend = 125;
                                }
                                else //1mei ä»»åŠ¡  2 æ²¡ä»»åŠ¡ã€‚
                                {
                                    LogHelper.Info($"查看RGV 1工位没任务,工位2 ä¹Ÿæ²¡ä»»åŠ¡ã€‚ä¼˜å…ˆ1工位终点1017任务。。");
                                    //、下 1017任务 ç»™1号工位。
                                    var lss = tklist.Take(2).ToList();
                                    var e1017first = lss.Find(x => x.S_END_LOC == "1017");
                                    if (e1017first == null)
                                    {
                                        e1017first = lss.FirstOrDefault();
                                    }
                                    if (e1017first != null)
                                    {
                                        LogHelper.Info($"查看RGV 1工位没任务,工位2 ä¹Ÿæ²¡ä»»åŠ¡ã€‚1工位下任务{e1017first.S_TASK_NO}> ç»ˆç‚¹{e1017first.S_END_LOC}。");
                                        tag.RGV.workMod = 1;
                                        tag.RGV.taskmod = 1;
                                        uint tno = Convert.ToUInt32(e1017first.S_TASK_NO.Substring(4));
                                        LogHelper.Info($"{e1017first.S_TASK_NO}> è½¬æ¢åŽä»»åŠ¡å·{tno} å¼€å§‹å†™å…¥ã€‚");
                                        tag.RGV.taskno1 = tno;
                                        LogHelper.Info($"{e1017first.S_TASK_NO}>开始写入 task1do>>{e1017first.S_START_LOC}。");
                                        tag.RGV.task1do = Convert.ToUInt16(e1017first.S_START_LOC);
                                        LogHelper.Info($"{e1017first.S_TASK_NO}> taskend 125");
                                        e1017first.S_B_STATE = "已推送";
                                        taskservice.Update(e1017first);
                                        System.Threading.Thread.Sleep(750);
                                        RedisHelper.Add($"RGV.bit1taskOver_LAST", "0", out string msg);
                                        tag.RGV.taskend = 125;
                                    }
                                }
                            }
                            #endregion
                        }
                        catch (Exception ex)
                        {
                            LogHelper.Error(ex.Message, ex);
                            //throw ex;
                        }
                        #endregion [脚本][20250325085542733][业务逻辑.任务下发]
                    }
                    catch (Exception ex)
                    {
                        Conn.默认日志.Error(ex.ToString());
                    }
                    finally
                    {
                        System.Threading.Thread.Sleep(3000);
                    }
                }
                ExitJudgeStack.TryPop(out int exitJudgeVal);
            });
            /// <summary>
            /// ç¨‹åºç‰‡æ®µ:ResolveMesTask
            /// æè¿°:
            /// </summary>
            System.Threading.Tasks.Task.Factory.StartNew(() =>
            {
                System.Threading.Thread.CurrentThread.IsBackground = true;
                ExitJudgeStack.Push(0);
                //一直执行,直到满足结束条件
                while (true)
                {
                    if (IsExitApp) { break; }
                    try
                    {
                        #region    [脚本][20250531163716255][业务逻辑.处理MES任务线程.ResolveMesTask]
                        //mes ä»»åŠ¡æ‹†åˆ†ã€‚ä¸€æ®µä»»åŠ¡å’Œ å¤šæ®µä»»åŠ¡ã€‚
                        ToWMSMES.ResMesTask();
                        #endregion [脚本][20250531163716255][业务逻辑.处理MES任务线程.ResolveMesTask]
                    }
                    catch (Exception ex)
                    {
                        Conn.默认日志.Error(ex.ToString());
                    }
                    finally
                    {
                        System.Threading.Thread.Sleep(3000);
                    }
                }
                ExitJudgeStack.TryPop(out int exitJudgeVal);
            });
            try
            {
                #region    [脚本][20250605212104026][业务逻辑.SocketServer]
                var host = System.Net.Dns.GetHostEntry(System.Net.Dns.GetHostName());
                foreach (var ip in host.AddressList)
                {
                    if (ip.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
                    {
                        Console.WriteLine($"ip= {ip.ToString()}");
                        new TcpServer(ip.ToString());
                    }
                }
                #endregion [脚本][20250605212104026][业务逻辑.SocketServer]
            }
            catch (Exception ex)
            {
                Conn.默认日志.Error(ex.ToString());
            }
            finally
            {
            }
            /// <summary>
            /// ç¨‹åºç‰‡æ®µ:光栅处理
            /// æè¿°:
            /// </summary>
            System.Threading.Tasks.Task.Factory.StartNew(() =>
            {
                System.Threading.Thread.CurrentThread.IsBackground = true;
                ExitJudgeStack.Push(0);
                //一直执行,直到满足结束条件
                while (true)
                {
                    if (IsExitApp) { break; }
                    try
                    {
                        #region    [脚本][20250611223832523][业务逻辑.光栅处理]
                        // - å…‰æ …交互处理。。
                        var taskCOdes = new List<string> { "Sarrive", "Srelease", "Earrive", "Erelease" };
                        TaskActRepository taskActRepository = new TaskActRepository();
                        TaskRepository taskRepository = new TaskRepository();
@@ -784,62 +1089,62 @@
                            else
                            {
                                loc = item.S_END_LOC;
                            }
                     if (loc == null) continue; else loc = loc.Trim();
                            }
                            if (loc == null) continue; else loc = loc.Trim();
                            bool goin = tin % 2 == 0;
                            bool continuuuuu =false;
                            bool continuuuuu = false;
                            var dev = Settings.deviceInfos.Find(x => x.location.Contains(loc));
                            if (dev != null)
                            {
                                var V = dev.location.ToList().FindIndex(x => x == loc) == 0;
                        //车走了  å¼€å…‰æ …
                                //车走了  å¼€å…‰æ …
                                if (!goin)
                                {
                                    if (dev.deviceType == 1)
                                    {
                                        LogHelper.Info($"{dev.deviceName}{(V ? "å·¦" : "右")} å…‰æ …{(goin?"关闭":"开启")} ç”³è¯·ã€‚"+string.Format("{0}{1}{2}", dev.deviceName + "." + (V ? "R02" : "R04"), "true", dev.deviceName + "Queue"));
                                        LogHelper.Info($"{dev.deviceName}{(V ? "å·¦" : "右")} å…‰æ …{(goin ? "关闭" : "开启")} ç”³è¯·ã€‚" + string.Format("{0}{1}{2}", dev.deviceName + "." + (V ? "R02" : "R04"), "true", dev.deviceName + "Queue"));
                                        Conn.默认Redis.SetValue(dev.deviceName + "." + (V ? "R02" : "R04"), "true", dev.deviceName + "Queue");
                                    }
                                    else if (dev.deviceType == 2)
                                    {
                                        LogHelper.Info($"{dev.deviceName}{(V ? "å·¦" : "右")} å…‰æ …{(goin?"关闭":"开启")} ç”³è¯·ã€‚"+string.Format("{0}{1}{2}", dev.deviceName + "." + (V ? "D1222" : "D1223"), "1", dev.deviceName + "Queue"));
                                        LogHelper.Info($"{dev.deviceName}{(V ? "å·¦" : "右")} å…‰æ …{(goin ? "关闭" : "开启")} ç”³è¯·ã€‚" + string.Format("{0}{1}{2}", dev.deviceName + "." + (V ? "D1222" : "D1223"), "1", dev.deviceName + "Queue"));
                                        Conn.默认Redis.SetValue(dev.deviceName + "." + (V ? "D1222" : "D1223"), "1", dev.deviceName + "Queue");
                                    }
                                   item.N_CREATEMETHOD = 1;
                                   taskActRepository.Update(item);
                        }
                                    item.N_CREATEMETHOD = 1;
                                    taskActRepository.Update(item);
                                }
                                //车要进入交互。
                        else
                        {
                                else
                                {
                                    if (dev.deviceType == 1)
                                    {
                              var tf = Conn.默认Redis.GetValue(dev.deviceName + "." + (V ? "R50" : "R52"));//读关闭状态
                              if (tf?.ToLower() == "true")
                              {
                                 LogHelper.Info($"{dev.deviceName}{(V ? "å·¦" : "右")} å…‰æ …{(goin?"关闭":"开启")} ç”³è¯·ã€‚ å·²ç»å…³é—­ï¼");
                                 continuuuuu = true;
                              }
                              else
                              {
                                 LogHelper.Info($"{dev.deviceName}{(V ? "å·¦" : "右")} å…‰æ …{(goin?"关闭":"开启")} ç”³è¯·ã€‚"+string.Format("{0}{1}{2}", dev.deviceName + "." + (V ? "R01" : "R03"), "true", dev.deviceName + "Queue"));
                                 Conn.默认Redis.SetValue(dev.deviceName + "." + (V ? "R01" : "R03"), "true", dev.deviceName + "Queue");
                              }
                                        var tf = Conn.默认Redis.GetValue(dev.deviceName + "." + (V ? "R50" : "R52"));//读关闭状态
                                        if (tf?.ToLower() == "true")
                                        {
                                            LogHelper.Info($"{dev.deviceName}{(V ? "å·¦" : "右")} å…‰æ …{(goin ? "关闭" : "开启")} ç”³è¯·ã€‚ å·²ç»å…³é—­ï¼");
                                            continuuuuu = true;
                                        }
                                        else
                                        {
                                            LogHelper.Info($"{dev.deviceName}{(V ? "å·¦" : "右")} å…‰æ …{(goin ? "关闭" : "开启")} ç”³è¯·ã€‚" + string.Format("{0}{1}{2}", dev.deviceName + "." + (V ? "R01" : "R03"), "true", dev.deviceName + "Queue"));
                                            Conn.默认Redis.SetValue(dev.deviceName + "." + (V ? "R01" : "R03"), "true", dev.deviceName + "Queue");
                                        }
                                    }
                                    else if (dev.deviceType == 2)
                                    {
                                        var tf = Conn.默认Redis.GetValue(dev.deviceName + ".D1202");
                              int numm = int.Parse(string.IsNullOrEmpty(tf) ? "0" : tf);
                                        if (TcpServer.GetBitdata(numm,(V?0:1))==1)
                                        int numm = int.Parse(string.IsNullOrEmpty(tf) ? "0" : tf);
                                        if (TcpServer.GetBitdata(numm, (V ? 0 : 1)) == 1)
                                        {
                                 LogHelper.Info($"{dev.deviceName}{(V ? "å·¦" : "右")} å…‰æ …{(goin?"关闭":"开启")} ç”³è¯·ã€‚ å·²ç»å…³é—­ï¼");
                                            LogHelper.Info($"{dev.deviceName}{(V ? "å·¦" : "右")} å…‰æ …{(goin ? "关闭" : "开启")} ç”³è¯·ã€‚ å·²ç»å…³é—­ï¼");
                                            continuuuuu = true;
                                        }
                                        else
                                        {
                                            LogHelper.Info($"{dev.deviceName}{(V ? "å·¦" : "右")} å…‰æ …{(goin?"关闭":"开启")} ç”³è¯·ã€‚"+string.Format("{0}{1}{2}", dev.deviceName + "." + (V ? "D1220" : "D1221"), dev.deviceName + "Queue"));
                                            LogHelper.Info($"{dev.deviceName}{(V ? "å·¦" : "右")} å…‰æ …{(goin ? "关闭" : "开启")} ç”³è¯·ã€‚" + string.Format("{0}{1}{2}", dev.deviceName + "." + (V ? "D1220" : "D1221"), dev.deviceName + "Queue"));
                                            Conn.默认Redis.SetValue(dev.deviceName + "." + (V ? "D1220" : "D1221"), "1", dev.deviceName + "Queue");
                                        }
                                    }
@@ -849,7 +1154,7 @@
                            }
                            if (continuuuuu)
                            {
                        LogHelper.Info($"{item.S_TASK_NO}{item.S_ACTION_CODE} è½¦è¾†å‘送继续任务!");
                                LogHelper.Info($"{item.S_TASK_NO}{item.S_ACTION_CODE} è½¦è¾†å‘送继续任务!");
                                continueTask(new HaiKangOrderInfo
                                {
                                    reqCode = item.S_ID.Replace("-", ""),
@@ -876,904 +1181,922 @@
                                Conn.默认Redis.SetValue(dev.deviceName + ".D1223", "0", dev.deviceName + "Queue");
                            }
                        }
                        // å‘那科下料光栅。
            #endregion [脚本][20250611223832523][业务逻辑.光栅处理]
         }
         catch(Exception ex)
         {
            Conn.默认日志.Error(ex.ToString());
         }
         finally
         {
            System.Threading.Thread.Sleep(3000);
         }
         }
            ExitJudgeStack.TryPop(out int exitJudgeVal);
});
         /// <summary>
         /// ç¨‹åºç‰‡æ®µ:1020空框下线
         /// æè¿°:
         /// </summary>
         System.Threading.Tasks.Task.Factory.StartNew(() =>
         {
            System.Threading.Thread.CurrentThread.IsBackground = true;
            ExitJudgeStack.Push(0);
         //一直执行,直到满足结束条件
         while(true)
         {
            if (IsExitApp) { break; }
         try
         {
            #region    [脚本][20250616094224396][业务逻辑.流程2热处理炉进出.1020空框下线]
            foreach (var Bssx in new string[] { "1020", "1023" })
{
    var RtaskState = (System.UInt16)System.Convert.ChangeType(Conn.默认Redis.GetValue($"S{Bssx}Read.RtaskState"), typeof(System.UInt16));
    var RtaskState_LAST = (System.UInt16)System.Convert.ChangeType(Conn.默认Redis.GetValue($"S{Bssx}Read.RtaskState_LAST"), typeof(System.UInt16));
    var R托盘码 = (System.String)System.Convert.ChangeType(Conn.默认Redis.GetValue($"S{Bssx}Read.R托盘码"), typeof(System.String));
    Console.WriteLine($"{Bssx} ç©ºä¸‹æ£€æµ‹ï¼šä»»åŠ¡ç”³è¯·ï¼š{RtaskState}- æ˜¯å¦å·²å¤„理:{RtaskState_LAST}- æ‰˜ç›˜ç ï¼š{R托盘码}");
    if (RtaskState == 3 && RtaskState_LAST == 0)
    {
        try
        {
            foreach (var item in new string[] { "1004", "1006", "1012", "1014" })
            {
                var R5 = (System.UInt16)System.Convert.ChangeType(Conn.默认Redis.GetValue($"S{item}Read.R5空闲"), typeof(System.UInt16));
                var R5空闲_LAST = (System.UInt16)System.Convert.ChangeType(Conn.默认Redis.GetValue($"S{item}Read.R5空闲_LAST"), typeof(System.UInt16));
                if (R5 == 5 && R5空闲_LAST == 0)
                {
                    var b = TaskProcess.CreateTask("", Bssx, item, "空上RGV", 5, new List<string> { R托盘码 }, "RGV");
                    if (b)
                        #endregion [脚本][20250611223832523][业务逻辑.光栅处理]
                    }
                    catch (Exception ex)
                    {
                        LogHelper.Debug($"输送线RGV空托任务 from:{Bssx}>to {item}开始创建成功");
                        Modular.Redis.RedisHelper.Add($"S{Bssx}Read.RtaskState_LAST", "1", out string msg);
                        //Conn.默认Redis.SetValue($"S{Bssx}Read.RtaskState_LAST", "1", $"S{Bssx}ReadQueue");
                        Modular.Redis.RedisHelper.Add($"S{item}Read.R5空闲_LAST", "1", out string msg1);
                        //Conn.默认Redis.SetValue($"S{item}Read.R5空闲_LAST", "1", $"S{item}ReadQueue");
                        break;
                        Conn.默认日志.Error(ex.ToString());
                    }
                    finally
                    {
                        System.Threading.Thread.Sleep(3000);
                    }
                }
                else if (R5 != 5 && R5空闲_LAST == 1)
                ExitJudgeStack.TryPop(out int exitJudgeVal);
            });
            /// <summary>
            /// ç¨‹åºç‰‡æ®µ:1020空框下线
            /// æè¿°:
            /// </summary>
            System.Threading.Tasks.Task.Factory.StartNew(() =>
            {
                System.Threading.Thread.CurrentThread.IsBackground = true;
                ExitJudgeStack.Push(0);
                //一直执行,直到满足结束条件
                while (true)
                {
                    Modular.Redis.RedisHelper.Add($"S{item}Read.R5空闲_LAST", "0", out string msg);
                    //Conn.默认Redis.SetValue($"S{item}Read.R5空闲_LAST", "0", $"S{item}ReadQueue");
                    if (IsExitApp) { break; }
                    try
                    {
                        #region    [脚本][20250616094224396][业务逻辑.流程2热处理炉进出.1020空框下线]
                        //1020  1023 ç©ºæ¡†ä¸‹çº¿
                        foreach (var Bssx in new string[] { "1020", "1023" })
                        {
                            var RtaskState = (System.UInt16)System.Convert.ChangeType(Conn.默认Redis.GetValue($"S{Bssx}Read.RtaskState"), typeof(System.UInt16));
                            var RtaskState_LAST = (System.UInt16)System.Convert.ChangeType(Conn.默认Redis.GetValue($"S{Bssx}Read.RtaskState_LAST"), typeof(System.UInt16));
                            var R托盘码 = (System.String)System.Convert.ChangeType(Conn.默认Redis.GetValue($"S{Bssx}Read.R托盘码"), typeof(System.String));
                            Console.WriteLine($"{Bssx} ç©ºä¸‹æ£€æµ‹ï¼šä»»åŠ¡ç”³è¯·ï¼š{RtaskState}- æ˜¯å¦å·²å¤„理:{RtaskState_LAST}- æ‰˜ç›˜ç ï¼š{R托盘码}");
                            if (RtaskState == 3 && RtaskState_LAST == 0)
                            {
                                try
                                {
                                    foreach (var item in (Bssx == "1020" ? new string[] { "1004", "1012" } : new string[] { "1006", "1014" }))
                                    {
                                        var R5 = (System.UInt16)System.Convert.ChangeType(Conn.默认Redis.GetValue($"S{item}Read.R5空闲"), typeof(System.UInt16));
                                        var R5空闲_LAST = (System.UInt16)System.Convert.ChangeType(Conn.默认Redis.GetValue($"S{item}Read.R5空闲_LAST"), typeof(System.UInt16));
                                        if (R5 == 5 && R5空闲_LAST == 0)
                                        {
                                            var b = TaskProcess.CreateTask("", Bssx, item, "空上RGV", 5, new List<string> { R托盘码 }, "RGV");
                                            if (b)
                                            {
                                                LogHelper.Debug($"输送线RGV空托任务 from:{Bssx}>to {item}开始创建成功");
                                                RedisHelper.Add($"S{Bssx}Read.RtaskState_LAST", "1", out string msg);
                                                //Conn.默认Redis.SetValue($"S{Bssx}Read.RtaskState_LAST", "1", $"S{Bssx}ReadQueue");
                                                RedisHelper.Add($"S{item}Read.R5空闲_LAST", "1", out string msg1);
                                                //Conn.默认Redis.SetValue($"S{item}Read.R5空闲_LAST", "1", $"S{item}ReadQueue");
                                                break;
                                            }
                                        }
                                        else if (R5 != 5 && R5空闲_LAST == 1)
                                        {
                                            RedisHelper.Add($"S{item}Read.R5空闲_LAST", "0", out string msg);
                                            //Conn.默认Redis.SetValue($"S{item}Read.R5空闲_LAST", "0", $"S{item}ReadQueue");
                                        }
                                    }
                                    System.Threading.Thread.Sleep(1000);
                                }
                                catch (Exception ex)
                                {
                                    LogHelper.Error(ex.Message, ex);
                                    Console.WriteLine(ex.Message + ex.StackTrace);
                                }
                            }
                            else if (RtaskState != 3 && RtaskState_LAST == 1)
                            {
                                RedisHelper.Add($"S{Bssx}Read.RtaskState_LAST", "0", out string msg);
                                //Conn.默认Redis.SetValue($"S{Bssx}Read.RtaskState_LAST", "0", $"S{Bssx}ReadQueue");
                            }
                            System.Threading.Thread.Sleep(2000);
                        }
                        #endregion [脚本][20250616094224396][业务逻辑.流程2热处理炉进出.1020空框下线]
                    }
                    catch (Exception ex)
                    {
                        Conn.默认日志.Error(ex.ToString());
                    }
                    finally
                    {
                        System.Threading.Thread.Sleep(3000);
                    }
                }
            }
            System.Threading.Thread.Sleep(1000);
        }
        catch (Exception ex)
        {
            LogHelper.Error(ex.Message, ex);
            Console.WriteLine(ex.Message + ex.StackTrace);
        }
    }
    else if (RtaskState != 3 && RtaskState_LAST == 1)
    {
        Modular.Redis.RedisHelper.Add($"S{Bssx}Read.RtaskState_LAST", "0", out string msg);
        //Conn.默认Redis.SetValue($"S{Bssx}Read.RtaskState_LAST", "0", $"S{Bssx}ReadQueue");
    }
    System.Threading.Thread.Sleep(2000);
}
            #endregion [脚本][20250616094224396][业务逻辑.流程2热处理炉进出.1020空框下线]
         }
         catch(Exception ex)
         {
            Conn.默认日志.Error(ex.ToString());
         }
         finally
         {
            System.Threading.Thread.Sleep(3000);
         }
         }
            ExitJudgeStack.TryPop(out int exitJudgeVal);
});
         /// <summary>
         /// ç¨‹åºç‰‡æ®µ:1023空框下线
         /// æè¿°:
         /// </summary>
         System.Threading.Tasks.Task.Factory.StartNew(() =>
         {
            System.Threading.Thread.CurrentThread.IsBackground = true;
            ExitJudgeStack.Push(0);
         //一直执行,直到满足结束条件
         while(true)
         {
            if (IsExitApp) { break; }
         try
         {
            #region    [脚本][20250616094226654][业务逻辑.流程2热处理炉进出.1023空框下线]
            //1023 ç©ºæ¡†ä¸‹çº¿
            #endregion [脚本][20250616094226654][业务逻辑.流程2热处理炉进出.1023空框下线]
         }
         catch(Exception ex)
         {
            Conn.默认日志.Error(ex.ToString());
         }
         finally
         {
            System.Threading.Thread.Sleep(3000);
         }
         }
            ExitJudgeStack.TryPop(out int exitJudgeVal);
});
         /// <summary>
         /// ç¨‹åºç‰‡æ®µ:定子满下线
         /// æè¿°:
         /// </summary>
         System.Threading.Tasks.Task.Factory.StartNew(() =>
         {
            System.Threading.Thread.CurrentThread.IsBackground = true;
            ExitJudgeStack.Push(0);
         //一直执行,直到满足结束条件
         while(true)
         {
            if (IsExitApp) { break; }
         try
         {
            #region    [脚本][20250616094632985][业务逻辑.流程2热处理炉进出.定子满下线]
            foreach (var Bssx in new string[] { "1008", "1016" })
{
    var RtaskState = (System.UInt16)System.Convert.ChangeType(Conn.默认Redis.GetValue($"S{Bssx}Read.RtaskState"), typeof(System.UInt16));
    var RtaskState_LAST = (System.UInt16)System.Convert.ChangeType(Conn.默认Redis.GetValue($"S{Bssx}Read.RtaskState_LAST"), typeof(System.UInt16));
    var R托盘码 = (System.String)System.Convert.ChangeType(Conn.默认Redis.GetValue($"S{Bssx}Read.R托盘码"), typeof(System.String));
    Console.WriteLine($"{Bssx} æ»¡ä¸‹æ£€æµ‹ï¼šä»»åŠ¡ç”³è¯·ï¼š{RtaskState}- æ˜¯å¦å·²å¤„理:{RtaskState_LAST}- æ‰˜ç›˜ç ï¼š{R托盘码}");
    if (RtaskState == 3 && RtaskState_LAST == 0)
    {
        var item = "1026";
        var R5 = (System.UInt16)System.Convert.ChangeType(Conn.默认Redis.GetValue($"S{item}Read.R5空闲"), typeof(System.UInt16));
        var R5空闲_LAST = (System.UInt16)System.Convert.ChangeType(Conn.默认Redis.GetValue($"S{item}Read.R5空闲_LAST"), typeof(System.UInt16));
        if (R5 == 5 && R5空闲_LAST == 0)
        {
            var b = TaskProcess.CreateTask("", Bssx, item, "满转1026", 5, new List<string> { R托盘码 }, "RGV");
            if (b)
                ExitJudgeStack.TryPop(out int exitJudgeVal);
            });
            /// <summary>
            /// ç¨‹åºç‰‡æ®µ:1023空框下线
            /// æè¿°:
            /// </summary>
            System.Threading.Tasks.Task.Factory.StartNew(() =>
            {
                Modular.Redis.RedisHelper.Add($"S{Bssx}Read.RtaskState_LAST", "1", out string msg);
                Modular.Redis.RedisHelper.Add($"S{item}Read.R5空闲_LAST", "1", out string msg2);
                //Conn.默认Redis.SetValue($"S{Bssx}Read.RtaskState_LAST", "1", $"S{Bssx}ReadQueue");
                //Conn.默认Redis.SetValue($"S{item}Read.R5空闲_LAST", "1", $"S{item}ReadQueue");
                break;
            }
        }
        else if (R5 != 5 && R5空闲_LAST == 1)
        {
            Modular.Redis.RedisHelper.Add($"S{item}Read.R5空闲_LAST", "0", out string msg2);
        }
    }
    else if (RtaskState != 3 && RtaskState_LAST == 1)
    {
        Modular.Redis.RedisHelper.Add($"S{Bssx}Read.RtaskState_LAST", "0", out string msg);
        //Conn.默认Redis.SetValue($"S{Bssx}Read.RtaskState_LAST", "0", $"S{Bssx}ReadQueue");
    }
    System.Threading.Thread.Sleep(2000);
}
            #endregion [脚本][20250616094632985][业务逻辑.流程2热处理炉进出.定子满下线]
         }
         catch(Exception ex)
         {
            Conn.默认日志.Error(ex.ToString());
         }
         finally
         {
            System.Threading.Thread.Sleep(3000);
         }
         }
            ExitJudgeStack.TryPop(out int exitJudgeVal);
});
         /// <summary>
         /// ç¨‹åºç‰‡æ®µ:转子满下线
         /// æè¿°:
         /// </summary>
         System.Threading.Tasks.Task.Factory.StartNew(() =>
         {
            System.Threading.Thread.CurrentThread.IsBackground = true;
            ExitJudgeStack.Push(0);
         //一直执行,直到满足结束条件
         while(true)
         {
            if (IsExitApp) { break; }
         try
         {
            #region    [脚本][20250616094511322][业务逻辑.流程2热处理炉进出.转子满下线]
            //转子满下线  1002  1010   - RGV2工位不可到 1017 ä¸å¯ä¸‹å‘2工位任务。
foreach (var Bssx in new string[] { "1002", "1010" })
{
    var RtaskState = (System.UInt16)System.Convert.ChangeType(Conn.默认Redis.GetValue($"S{Bssx}Read.RtaskState"), typeof(System.UInt16));
    var RtaskState_LAST = (System.UInt16)System.Convert.ChangeType(Conn.默认Redis.GetValue($"S{Bssx}Read.RtaskState_LAST"), typeof(System.UInt16));
    var R托盘码 = (System.String)System.Convert.ChangeType(Conn.默认Redis.GetValue($"S{Bssx}Read.R托盘码"), typeof(System.String));
    Console.WriteLine($"{Bssx} æ»¡ä¸‹æ£€æµ‹ï¼šä»»åŠ¡ç”³è¯·ï¼š{RtaskState}- æ˜¯å¦å·²å¤„理:{RtaskState_LAST}- æ‰˜ç›˜ç ï¼š{R托盘码}");
    if (RtaskState == 3 && RtaskState_LAST == 0)
    {
        var item = "1017";
        var R5 = (System.UInt16)System.Convert.ChangeType(Conn.默认Redis.GetValue($"S{item}Read.R5空闲"), typeof(System.UInt16));
        var R5空闲_LAST = (System.UInt16)System.Convert.ChangeType(Conn.默认Redis.GetValue($"S{item}Read.R5空闲_LAST"), typeof(System.UInt16));
        if (R5 == 5 && R5空闲_LAST == 0)
        {
            var b = TaskProcess.CreateTask("", Bssx, item, "满转1017", 5, new List<string> { R托盘码 }, "RGV");
            if (b)
                System.Threading.Thread.CurrentThread.IsBackground = true;
                ExitJudgeStack.Push(0);
                //一直执行,直到满足结束条件
                while (true)
                {
                    if (IsExitApp) { break; }
                    try
                    {
                        #region    [脚本][20250616094226654][业务逻辑.流程2热处理炉进出.1023空框下线]
                        //1023 ç©ºæ¡†ä¸‹çº¿
                        #endregion [脚本][20250616094226654][业务逻辑.流程2热处理炉进出.1023空框下线]
                    }
                    catch (Exception ex)
                    {
                        Conn.默认日志.Error(ex.ToString());
                    }
                    finally
                    {
                        System.Threading.Thread.Sleep(3000);
                    }
                }
                ExitJudgeStack.TryPop(out int exitJudgeVal);
            });
            /// <summary>
            /// ç¨‹åºç‰‡æ®µ:定子满下线
            /// æè¿°:
            /// </summary>
            System.Threading.Tasks.Task.Factory.StartNew(() =>
            {
                Modular.Redis.RedisHelper.Add($"S{Bssx}Read.RtaskState_LAST", "1", out string msg);
                Modular.Redis.RedisHelper.Add($"S{item}Read.R5空闲_LAST", "1", out string msg1);
                //Conn.默认Redis.SetValue($"S{Bssx}Read.RtaskState_LAST", "1", $"S{Bssx}ReadQueue");
                //Conn.默认Redis.SetValue($"S{item}Read.R5空闲_LAST", "1", $"S{item}ReadQueue");
                break;
            }
        }
        else if (R5 != 5 && R5空闲_LAST == 1)
        {
            Modular.Redis.RedisHelper.Add($"S{item}Read.R5空闲_LAST", "0", out string msg1);
        }
    }
    else if (RtaskState != 3 && RtaskState_LAST == 1)
    {
        Modular.Redis.RedisHelper.Add($"S{Bssx}Read.RtaskState_LAST", "0", out string msg);
    }
    System.Threading.Thread.Sleep(2000);
}
            #endregion [脚本][20250616094511322][业务逻辑.流程2热处理炉进出.转子满下线]
         }
         catch(Exception ex)
         {
            Conn.默认日志.Error(ex.ToString());
         }
         finally
         {
            System.Threading.Thread.Sleep(3000);
         }
         }
            ExitJudgeStack.TryPop(out int exitJudgeVal);
});
         /// <summary>
         /// ç¨‹åºç‰‡æ®µ:下料位检测
         /// æè¿°:
         /// </summary>
         System.Threading.Tasks.Task.Factory.StartNew(() =>
         {
            System.Threading.Thread.CurrentThread.IsBackground = true;
            ExitJudgeStack.Push(0);
         //一直执行,直到满足结束条件
         while(true)
         {
            if (IsExitApp) { break; }
         try
         {
            #region    [脚本][20250616095605911][业务逻辑.流程2热处理炉进出.下料位检测]
            //下料位检测。  1003  åˆ°ä½æ—¶ å†™ æ ‡è¯†ä¿¡å· å¹¶ ç»™æœºæ¢°æ‰‹ä¿¡å·ã€‚
foreach (var ssx in new string[] { "1003", "1005", "1011", "1013" })
{
    var RArrive = (System.UInt16)System.Convert.ChangeType(Conn.默认Redis.GetValue($"FNK1003051113.RArrive{ssx}"), typeof(System.UInt16));
    var RArriveLast = (System.UInt16)System.Convert.ChangeType(Conn.默认Redis.GetValue($"FNK1003051113.RArrive{ssx}_LAST"), typeof(System.UInt16));
    if (RArrive == 1 && RArriveLast == 0)
    {
        if (ssx == "1005")
        {
            tag.FNK1.D2210 = 1;
            tag.SF下料位.RArrive1005_LAST = 1;
                System.Threading.Thread.CurrentThread.IsBackground = true;
                ExitJudgeStack.Push(0);
                //一直执行,直到满足结束条件
                while (true)
                {
                    if (IsExitApp) { break; }
                    try
                    {
                        #region    [脚本][20250616094632985][业务逻辑.流程2热处理炉进出.定子满下线]
                        //定子满下线  1008  1016   ->  1026
                        foreach (var Bssx in new string[] { "1008", "1016" })
                        {
                            var RtaskState = (System.UInt16)System.Convert.ChangeType(Conn.默认Redis.GetValue($"S{Bssx}Read.RtaskState"), typeof(System.UInt16));
                            var RtaskState_LAST = (System.UInt16)System.Convert.ChangeType(Conn.默认Redis.GetValue($"S{Bssx}Read.RtaskState_LAST"), typeof(System.UInt16));
                            var R托盘码 = (System.String)System.Convert.ChangeType(Conn.默认Redis.GetValue($"S{Bssx}Read.R托盘码"), typeof(System.String));
                            Console.WriteLine($"{Bssx} æ»¡ä¸‹æ£€æµ‹ï¼šä»»åŠ¡ç”³è¯·ï¼š{RtaskState}- æ˜¯å¦å·²å¤„理:{RtaskState_LAST}- æ‰˜ç›˜ç ï¼š{R托盘码}");
                            if (RtaskState == 3 && RtaskState_LAST == 0)
                            {
                                var item = "1026";
                                var R5 = (System.UInt16)System.Convert.ChangeType(Conn.默认Redis.GetValue($"S{item}Read.R5空闲"), typeof(System.UInt16));
                                var R5空闲_LAST = (System.UInt16)System.Convert.ChangeType(Conn.默认Redis.GetValue($"S{item}Read.R5空闲_LAST"), typeof(System.UInt16));
                                if (R5 == 5 && R5空闲_LAST == 0)
                                {
                                    var b = TaskProcess.CreateTask("", Bssx, item, "满转1026", 5, new List<string> { R托盘码 }, "RGV");
                                    if (b)
                                    {
                                        RedisHelper.Add($"S{Bssx}Read.RtaskState_LAST", "1", out string msg);
                                        RedisHelper.Add($"S{item}Read.R5空闲_LAST", "1", out string msg2);
                                        //Conn.默认Redis.SetValue($"S{Bssx}Read.RtaskState_LAST", "1", $"S{Bssx}ReadQueue");
                                        //Conn.默认Redis.SetValue($"S{item}Read.R5空闲_LAST", "1", $"S{item}ReadQueue");
                                        break;
                                    }
                                }
                                else if (R5 != 5 && R5空闲_LAST == 1)
                                {
                                    RedisHelper.Add($"S{item}Read.R5空闲_LAST", "0", out string msg2);
                                }
                            }
                            else if (RtaskState != 3 && RtaskState_LAST == 1)
                            {
                                RedisHelper.Add($"S{Bssx}Read.RtaskState_LAST", "0", out string msg);
                                //Conn.默认Redis.SetValue($"S{Bssx}Read.RtaskState_LAST", "0", $"S{Bssx}ReadQueue");
                            }
                            System.Threading.Thread.Sleep(2000);
                        }
                        #endregion [脚本][20250616094632985][业务逻辑.流程2热处理炉进出.定子满下线]
                    }
                    catch (Exception ex)
                    {
                        Conn.默认日志.Error(ex.ToString());
                    }
                    finally
                    {
                        System.Threading.Thread.Sleep(3000);
                    }
                }
                ExitJudgeStack.TryPop(out int exitJudgeVal);
            });
            /// <summary>
            /// ç¨‹åºç‰‡æ®µ:转子满下线
            /// æè¿°:
            /// </summary>
            System.Threading.Tasks.Task.Factory.StartNew(() =>
            {
                System.Threading.Thread.CurrentThread.IsBackground = true;
                ExitJudgeStack.Push(0);
                //一直执行,直到满足结束条件
                while (true)
                {
                    if (IsExitApp) { break; }
                    try
                    {
                        #region    [脚本][20250616094511322][业务逻辑.流程2热处理炉进出.转子满下线]
                        //转子满下线  1002  1010   - RGV2工位不可到 1017 ä¸å¯ä¸‹å‘2工位任务。
                        foreach (var Bssx in new string[] { "1002", "1010" })
                        {
                            var RtaskState = (System.UInt16)System.Convert.ChangeType(Conn.默认Redis.GetValue($"S{Bssx}Read.RtaskState"), typeof(System.UInt16));
                            var RtaskState_LAST = (System.UInt16)System.Convert.ChangeType(Conn.默认Redis.GetValue($"S{Bssx}Read.RtaskState_LAST"), typeof(System.UInt16));
                            var R托盘码 = (System.String)System.Convert.ChangeType(Conn.默认Redis.GetValue($"S{Bssx}Read.R托盘码"), typeof(System.String));
                            Console.WriteLine($"{Bssx} æ»¡ä¸‹æ£€æµ‹ï¼šä»»åŠ¡ç”³è¯·ï¼š{RtaskState}- æ˜¯å¦å·²å¤„理:{RtaskState_LAST}- æ‰˜ç›˜ç ï¼š{R托盘码}");
                            if (RtaskState == 3 && RtaskState_LAST == 0)
                            {
                                var item = "1017";
                                var R5 = (System.UInt16)System.Convert.ChangeType(Conn.默认Redis.GetValue($"S{item}Read.R5空闲"), typeof(System.UInt16));
                                var R5空闲_LAST = (System.UInt16)System.Convert.ChangeType(Conn.默认Redis.GetValue($"S{item}Read.R5空闲_LAST"), typeof(System.UInt16));
                                if (R5 == 5 && R5空闲_LAST == 0)
                                {
                                    var b = TaskProcess.CreateTask("", Bssx, item, "满转1017", 5, new List<string> { R托盘码 }, "RGV");
                                    if (b)
                                    {
                                        RedisHelper.Add($"S{Bssx}Read.RtaskState_LAST", "1", out string msg);
                                        RedisHelper.Add($"S{item}Read.R5空闲_LAST", "1", out string msg1);
                                        //Conn.默认Redis.SetValue($"S{Bssx}Read.RtaskState_LAST", "1", $"S{Bssx}ReadQueue");
                                        //Conn.默认Redis.SetValue($"S{item}Read.R5空闲_LAST", "1", $"S{item}ReadQueue");
                                        break;
                                    }
                                }
                                else if (R5 != 5 && R5空闲_LAST == 1)
                                {
                                    RedisHelper.Add($"S{item}Read.R5空闲_LAST", "0", out string msg1);
                                }
                            }
                            else if (RtaskState != 3 && RtaskState_LAST == 1)
                            {
                                RedisHelper.Add($"S{Bssx}Read.RtaskState_LAST", "0", out string msg);
                            }
                            System.Threading.Thread.Sleep(2000);
                        }
                        #endregion [脚本][20250616094511322][业务逻辑.流程2热处理炉进出.转子满下线]
                    }
                    catch (Exception ex)
                    {
                        Conn.默认日志.Error(ex.ToString());
                    }
                    finally
                    {
                        System.Threading.Thread.Sleep(3000);
                    }
                }
                ExitJudgeStack.TryPop(out int exitJudgeVal);
            });
            /// <summary>
            /// ç¨‹åºç‰‡æ®µ:下料位检测
            /// æè¿°:
            /// </summary>
            System.Threading.Tasks.Task.Factory.StartNew(() =>
            {
                System.Threading.Thread.CurrentThread.IsBackground = true;
                ExitJudgeStack.Push(0);
                //一直执行,直到满足结束条件
                while (true)
                {
                    if (IsExitApp) { break; }
                    try
                    {
                        #region    [脚本][20250616095605911][业务逻辑.流程2热处理炉进出.下料位检测]
                        //下料位检测。  1003  åˆ°ä½æ—¶ å†™ æ ‡è¯†ä¿¡å· å¹¶ ç»™æœºæ¢°æ‰‹ä¿¡å·ã€‚
                        foreach (var ssx in new string[] { "1003", "1005", "1011", "1013" })
                        {
                            var RArrive = (System.UInt16)System.Convert.ChangeType(Conn.默认Redis.GetValue($"FNK1003051113.RArrive{ssx}"), typeof(System.UInt16));
                            var RArriveLast = (System.UInt16)System.Convert.ChangeType(Conn.默认Redis.GetValue($"FNK1003051113.RArrive{ssx}_LAST"), typeof(System.UInt16));
                            if (RArrive == 1 && RArriveLast == 0)
                            {
                                if (ssx == "1005")
                                {
                                    tag.FNK1.D2215 = 1;
                                    //tag.SF下料位.RArrive1005_LAST = 1;
                                    RedisHelper.Add($"FNK1003051113.RArrive1005_LAST", "1", out string msg);
            tag.SF下料位.WRelease1005 = 0;
            tag.SF下料位.WSafe0305 = 0;
        }
        else if (ssx == "1003")
        {
            tag.FNK2.D2215 = 1;
            tag.SF下料位.RArrive1003_LAST = 1;
                                    tag.SF下料位.WRelease1005 = 0;
                                    tag.SF下料位.WSafe0305 = 0;
                                }
                                else if (ssx == "1003")
                                {
                                    tag.FNK2.D2210 = 1;
                                    //tag.SF下料位.RArrive1003_LAST = 1;
            tag.SF下料位.WRelease1003 = 0;
            tag.SF下料位.WSafe0305 = 0;
        }
        else if (ssx == "1013")
        {
            tag.FNK2.D2210 = 1;
            tag.SF下料位.RArrive1013_LAST = 1;
                                    RedisHelper.Add($"FNK1003051113.RArrive1003_LAST", "1", out string msg);
                                    tag.SF下料位.WRelease1003 = 0;
                                    tag.SF下料位.WSafe0305 = 0;
                                }
                                else if (ssx == "1013")
                                {
                                    tag.FNK2.D2215 = 1;
                                    //tag.SF下料位.RArrive1013_LAST = 1;
                                    RedisHelper.Add($"FNK1003051113.RArrive1013_LAST", "1", out string msg);
            tag.SF下料位.WRelease1013 = 0;
            tag.SF下料位.WSafe1113 = 0;
        }
        else if (ssx == "1011")
        {
            tag.FNK2.D2215 = 1;
            tag.SF下料位.RArrive1011_LAST = 1;
                                    tag.SF下料位.WRelease1013 = 0;
                                    tag.SF下料位.WSafe1113 = 0;
                                }
                                else if (ssx == "1011")
                                {
                                    tag.FNK2.D2210 = 1;
                                    //tag.SF下料位.RArrive1011_LAST = 1;
                                    RedisHelper.Add($"FNK1003051113.RArrive1011_LAST", "1", out string msg);
            tag.SF下料位.WRelease1011 = 0;
            tag.SF下料位.WSafe1113 = 0;
        }
    }
    else if (RArrive == 0 && RArriveLast == 1)
    {
                                Modular.Redis.RedisHelper.Add($"FNK1003051113.RArrive{ssx}_LAST", "0", out string msg);
    }
}
            #endregion [脚本][20250616095605911][业务逻辑.流程2热处理炉进出.下料位检测]
         }
         catch(Exception ex)
         {
            Conn.默认日志.Error(ex.ToString());
         }
         finally
         {
            System.Threading.Thread.Sleep(3000);
         }
         }
            ExitJudgeStack.TryPop(out int exitJudgeVal);
});
         /// <summary>
         /// ç¨‹åºç‰‡æ®µ:1号FNK机械手完成
         /// æè¿°:
         /// </summary>
         System.Threading.Tasks.Task.Factory.StartNew(() =>
         {
            System.Threading.Thread.CurrentThread.IsBackground = true;
            ExitJudgeStack.Push(0);
         //一直执行,直到满足结束条件
         while(true)
         {
            if (IsExitApp) { break; }
         try
         {
            #region    [脚本][20250616095709155][业务逻辑.流程2热处理炉进出.1号FNK机械手完成]
            if (tag.FNK1.D2212 == 1 && tag.FNK1.D2212_LAST == 0)
{
    tag.FNK1.D2210 = 0;
    tag.FNK1.D2212_LAST = 1;
                                    tag.SF下料位.WRelease1011 = 0;
                                    tag.SF下料位.WSafe1113 = 0;
                                }
                            }
                            else if (RArrive == 0 && RArriveLast == 1)
                            {
                                RedisHelper.Add($"FNK1003051113.RArrive{ssx}_LAST", "0", out string msg);
                                //Conn.默认Redis.SetValue($"FNK1003051113.RArrive{ssx}_LAST", "0", $"FNK1003051113Queue");
                            }
                        }
                        #endregion [脚本][20250616095605911][业务逻辑.流程2热处理炉进出.下料位检测]
                    }
                    catch (Exception ex)
                    {
                        Conn.默认日志.Error(ex.ToString());
                    }
                    finally
                    {
                        System.Threading.Thread.Sleep(3000);
                    }
                }
                ExitJudgeStack.TryPop(out int exitJudgeVal);
            });
            /// <summary>
            /// ç¨‹åºç‰‡æ®µ:1号FNK机械手完成
            /// æè¿°:
            /// </summary>
            System.Threading.Tasks.Task.Factory.StartNew(() =>
            {
                System.Threading.Thread.CurrentThread.IsBackground = true;
                ExitJudgeStack.Push(0);
                //一直执行,直到满足结束条件
                while (true)
                {
                    if (IsExitApp) { break; }
                    try
                    {
    tag.SF下料位.WRelease1005 = 1;
    tag.SF下料位.WSafe0305 = 1;
}
else if (tag.FNK1.D2212 == 0 && tag.FNK1.D2212_LAST == 1)
{
    tag.FNK1.D2212_LAST = 0;
}
if (tag.FNK1.D2217 == 1 && tag.FNK1.D2217_LAST == 0)
{
    tag.FNK1.D2215 = 0;
    tag.FNK1.D2217_LAST = 1;
                        ////2217 - 1003
                        #region    [脚本][20250616095709155][业务逻辑.流程2热处理炉进出.1号FNK机械手完成]
                        if (tag.FNK1.D2217 == 1 && tag.FNK1.D2217_LAST == 0)
                        {
                            tag.FNK1.D2215 = 0;
                            //tag.FNK1.D2212_LAST = 1;
                            RedisHelper.Add($"p发那科1下线.D2217_LAST", "1", out string msg);
    tag.SF下料位.WRelease1003 = 1;
    tag.SF下料位.WSafe0305 = 1;
}
else if (tag.FNK1.D2217 == 0 && tag.FNK1.D2217_LAST == 1)
    tag.FNK1.D2217_LAST = 0;
                            tag.SF下料位.WRelease1005 = 1;
                            tag.SF下料位.WSafe0305 = 1;
                        }
                        else if (tag.FNK1.D2217 == 0 && tag.FNK1.D2217_LAST == 1)
                            //tag.FNK1.D2217_LAST = 0;
                            RedisHelper.Add($"p发那科1下线.D2217_LAST", "0", out string msg);
            #endregion [脚本][20250616095709155][业务逻辑.流程2热处理炉进出.1号FNK机械手完成]
         }
         catch(Exception ex)
         {
            Conn.默认日志.Error(ex.ToString());
         }
         finally
         {
            System.Threading.Thread.Sleep(3000);
         }
         }
            ExitJudgeStack.TryPop(out int exitJudgeVal);
});
         /// <summary>
         /// ç¨‹åºç‰‡æ®µ:2号FNK机械手完成
         /// æè¿°:
         /// </summary>
         System.Threading.Tasks.Task.Factory.StartNew(() =>
         {
            System.Threading.Thread.CurrentThread.IsBackground = true;
            ExitJudgeStack.Push(0);
         //一直执行,直到满足结束条件
         while(true)
         {
            if (IsExitApp) { break; }
         try
         {
            #region    [脚本][20250616095733680][业务逻辑.流程2热处理炉进出.2号FNK机械手完成]
             if (tag.FNK2.D2212 == 1 && tag.FNK2.D2212_LAST == 0)
 {
     tag.FNK2.D2210 = 0;
     tag.FNK2.D2212_LAST = 1;
                        if (tag.FNK1.D2212 == 1 && tag.FNK1.D2212_LAST == 0)
                        {
                            tag.FNK1.D2210 = 0;
                            //tag.FNK1.D2217_LAST = 1;
     tag.SF下料位.WRelease1013 = 1;
     tag.SF下料位.WSafe1113 = 1;
 }
 else if (tag.FNK2.D2212 == 0 && tag.FNK2.D2212_LAST == 1)
 {
     tag.FNK2.D2212_LAST = 0;
 }
 if (tag.FNK2.D2217 == 1 && tag.FNK2.D2217_LAST == 0)
 {
     tag.FNK2.D2215 = 0;
     tag.FNK2.D2217_LAST = 1;
                            RedisHelper.Add($"p发那科1下线.D2212_LAST", "1", out string msg);
                            tag.SF下料位.WRelease1003 = 1;
                            tag.SF下料位.WSafe0305 = 1;
                        }
                        else if (tag.FNK1.D2212 == 0 && tag.FNK1.D2212_LAST == 1)
                        {
                            //tag.FNK1.D2212_LAST = 0;
                            RedisHelper.Add($"p发那科1下线.D2212_LAST", "1", out string msg);
                        }
     tag.SF下料位.WRelease1011 = 1;
     tag.SF下料位.WSafe1113 = 1;
 }
 else if (tag.FNK2.D2217 == 0 && tag.FNK2.D2217_LAST == 1)
     tag.FNK2.D2217_LAST = 0;
            #endregion [脚本][20250616095733680][业务逻辑.流程2热处理炉进出.2号FNK机械手完成]
         }
         catch(Exception ex)
         {
            Conn.默认日志.Error(ex.ToString());
         }
         finally
         {
            System.Threading.Thread.Sleep(3000);
         }
         }
            ExitJudgeStack.TryPop(out int exitJudgeVal);
});
         /// <summary>
         /// ç¨‹åºç‰‡æ®µ:Program1
         /// æè¿°:
         /// </summary>
         System.Threading.Tasks.Task.Factory.StartNew(() =>
         {
            System.Threading.Thread.CurrentThread.IsBackground = true;
            ExitJudgeStack.Push(0);
         //一直执行,直到满足结束条件
         while(true)
         {
            if (IsExitApp) { break; }
         try
         {
            #region    [脚本][20250617085708084][业务逻辑.流程2热处理炉进出.1019转满出输送线.Program1]
 Console.WriteLine($"1019任务状态:{tag.SA1019.RtaskState}- barcode:{tag.SA1019.R托盘码}- ç©ºé—²{tag.SA1019.R5空闲}");
            #endregion [脚本][20250617085708084][业务逻辑.流程2热处理炉进出.1019转满出输送线.Program1]
         }
         catch(Exception ex)
         {
            Conn.默认日志.Error(ex.ToString());
         }
         finally
         {
            System.Threading.Thread.Sleep(3000);
         }
         }
            ExitJudgeStack.TryPop(out int exitJudgeVal);
});
         /// <summary>
         /// ç¨‹åºç‰‡æ®µ:Program1
         /// æè¿°:
         /// </summary>
         System.Threading.Tasks.Task.Factory.StartNew(() =>
         {
            System.Threading.Thread.CurrentThread.IsBackground = true;
            ExitJudgeStack.Push(0);
         //一直执行,直到满足结束条件
         while(true)
         {
            if (IsExitApp) { break; }
         try
         {
            #region    [脚本][20250617085712101][业务逻辑.流程2热处理炉进出.1025agv上空.Program1]
                        #endregion [脚本][20250616095709155][业务逻辑.流程2热处理炉进出.1号FNK机械手完成]
                    }
                    catch (Exception ex)
                    {
                        Conn.默认日志.Error(ex.ToString());
                    }
                    finally
                    {
                        System.Threading.Thread.Sleep(3000);
                    }
                }
                ExitJudgeStack.TryPop(out int exitJudgeVal);
            });
            /// <summary>
            /// ç¨‹åºç‰‡æ®µ:2号FNK机械手完成
            /// æè¿°:
            /// </summary>
            System.Threading.Tasks.Task.Factory.StartNew(() =>
            {
                System.Threading.Thread.CurrentThread.IsBackground = true;
                ExitJudgeStack.Push(0);
                //一直执行,直到满足结束条件
                while (true)
                {
                    if (IsExitApp) { break; }
                    try
                    {
                        #region    [脚本][20250616095733680][业务逻辑.流程2热处理炉进出.2号FNK机械手完成]
                        if (tag.FNK2.D2217 == 1 && tag.FNK2.D2217_LAST == 0)
                        {
                            tag.FNK2.D2215 = 0;
                            //tag.FNK2.D2212_LAST = 1;
                            RedisHelper.Add($"p发那科2下线.D2217_LAST", "1", out string msg);
                            tag.SF下料位.WRelease1013 = 1;
                            tag.SF下料位.WSafe1113 = 1;
                        }
                        else if (tag.FNK2.D2217 == 0 && tag.FNK2.D2217_LAST == 1)
                            //tag.FNK2.D2217_LAST = 0;
                            RedisHelper.Add($"p发那科2下线.D2217_LAST", "0", out string msg);
                        if (tag.FNK2.D2212 == 1 && tag.FNK2.D2212_LAST == 0)
                        {
                            tag.FNK2.D2210 = 0;
                            //tag.FNK2.D2217_LAST = 1;
                            RedisHelper.Add($"p发那科2下线.D2212_LAST", "1", out string msg);
                            tag.SF下料位.WRelease1011 = 1;
                            tag.SF下料位.WSafe1113 = 1;
                        }
                        else if (tag.FNK2.D2212 == 0 && tag.FNK2.D2212_LAST == 1)
                        {
                            //tag.FNK2.D2212_LAST = 0;
                            RedisHelper.Add($"p发那科2下线.D2212_LAST", "0", out string msg);
                        }
                        #endregion [脚本][20250616095733680][业务逻辑.流程2热处理炉进出.2号FNK机械手完成]
                    }
                    catch (Exception ex)
                    {
                        Conn.默认日志.Error(ex.ToString());
                    }
                    finally
                    {
                        System.Threading.Thread.Sleep(3000);
                    }
                }
                ExitJudgeStack.TryPop(out int exitJudgeVal);
            });
            /// <summary>
            /// ç¨‹åºç‰‡æ®µ:Program1
            /// æè¿°:
            /// </summary>
            System.Threading.Tasks.Task.Factory.StartNew(() =>
            {
                System.Threading.Thread.CurrentThread.IsBackground = true;
                ExitJudgeStack.Push(0);
                //一直执行,直到满足结束条件
                while (true)
                {
                    if (IsExitApp) { break; }
                    try
                    {
                        #region    [脚本][20250617085708084][业务逻辑.流程2热处理炉进出.1019转满出输送线.Program1]
                        Console.WriteLine($"1019任务状态:{tag.SA1019.RtaskState}- barcode:{tag.SA1019.R托盘码}- ç©ºé—²{tag.SA1019.R5空闲}");
                        #endregion [脚本][20250617085708084][业务逻辑.流程2热处理炉进出.1019转满出输送线.Program1]
                    }
                    catch (Exception ex)
                    {
                        Conn.默认日志.Error(ex.ToString());
                    }
                    finally
                    {
                        System.Threading.Thread.Sleep(3000);
                    }
                }
                ExitJudgeStack.TryPop(out int exitJudgeVal);
            });
            /// <summary>
            /// ç¨‹åºç‰‡æ®µ:Program1
            /// æè¿°:
            /// </summary>
            System.Threading.Tasks.Task.Factory.StartNew(() =>
            {
                System.Threading.Thread.CurrentThread.IsBackground = true;
                ExitJudgeStack.Push(0);
                //一直执行,直到满足结束条件
                while (true)
                {
                    if (IsExitApp) { break; }
                    try
                    {
                        #region    [脚本][20250617085712101][业务逻辑.流程2热处理炉进出.1025agv上空.Program1]
                        Console.WriteLine($"SA1025 ä»»åŠ¡çŠ¶æ€ï¼š{tag.SA1025.RtaskState}- ç©ºé—²{tag.SA1025.R5空闲}");
            #endregion [脚本][20250617085712101][业务逻辑.流程2热处理炉进出.1025agv上空.Program1]
         }
         catch(Exception ex)
         {
            Conn.默认日志.Error(ex.ToString());
         }
         finally
         {
            System.Threading.Thread.Sleep(3000);
         }
         }
            ExitJudgeStack.TryPop(out int exitJudgeVal);
});
         /// <summary>
         /// ç¨‹åºç‰‡æ®µ:Program1
         /// æè¿°:
         /// </summary>
         System.Threading.Tasks.Task.Factory.StartNew(() =>
         {
            System.Threading.Thread.CurrentThread.IsBackground = true;
            ExitJudgeStack.Push(0);
         //一直执行,直到满足结束条件
         while(true)
         {
            if (IsExitApp) { break; }
         try
         {
            #region    [脚本][20250617085750712][业务逻辑.流程2热处理炉进出.1022agv上空.Program1]
                        #endregion [脚本][20250617085712101][业务逻辑.流程2热处理炉进出.1025agv上空.Program1]
                    }
                    catch (Exception ex)
                    {
                        Conn.默认日志.Error(ex.ToString());
                    }
                    finally
                    {
                        System.Threading.Thread.Sleep(3000);
                    }
                }
                ExitJudgeStack.TryPop(out int exitJudgeVal);
            });
            /// <summary>
            /// ç¨‹åºç‰‡æ®µ:Program1
            /// æè¿°:
            /// </summary>
            System.Threading.Tasks.Task.Factory.StartNew(() =>
            {
                System.Threading.Thread.CurrentThread.IsBackground = true;
                ExitJudgeStack.Push(0);
                //一直执行,直到满足结束条件
                while (true)
                {
                    if (IsExitApp) { break; }
                    try
                    {
                        #region    [脚本][20250617085750712][业务逻辑.流程2热处理炉进出.1022agv上空.Program1]
                        Console.WriteLine($"SA1022 ä»»åŠ¡çŠ¶æ€ï¼š{tag.SA1022.RtaskState}- ç©ºé—²{tag.SA1022.R5空闲}");
            #endregion [脚本][20250617085750712][业务逻辑.流程2热处理炉进出.1022agv上空.Program1]
         }
         catch(Exception ex)
         {
            Conn.默认日志.Error(ex.ToString());
         }
         finally
         {
            System.Threading.Thread.Sleep(3000);
         }
         }
            ExitJudgeStack.TryPop(out int exitJudgeVal);
});
         /// <summary>
         /// ç¨‹åºç‰‡æ®µ:Program1
         /// æè¿°:
         /// </summary>
         System.Threading.Tasks.Task.Factory.StartNew(() =>
         {
            System.Threading.Thread.CurrentThread.IsBackground = true;
            ExitJudgeStack.Push(0);
         //一直执行,直到满足结束条件
         while(true)
         {
            if (IsExitApp) { break; }
         try
         {
            #region    [脚本][20250617085800942][业务逻辑.流程2热处理炉进出.1030下母托.Program1]
                        #endregion [脚本][20250617085750712][业务逻辑.流程2热处理炉进出.1022agv上空.Program1]
                    }
                    catch (Exception ex)
                    {
                        Conn.默认日志.Error(ex.ToString());
                    }
                    finally
                    {
                        System.Threading.Thread.Sleep(3000);
                    }
                }
                ExitJudgeStack.TryPop(out int exitJudgeVal);
            });
            /// <summary>
            /// ç¨‹åºç‰‡æ®µ:Program1
            /// æè¿°:
            /// </summary>
            System.Threading.Tasks.Task.Factory.StartNew(() =>
            {
                System.Threading.Thread.CurrentThread.IsBackground = true;
                ExitJudgeStack.Push(0);
                //一直执行,直到满足结束条件
                while (true)
                {
                    if (IsExitApp) { break; }
                    try
                    {
                        #region    [脚本][20250617085800942][业务逻辑.流程2热处理炉进出.1030下母托.Program1]
                        Console.WriteLine($"SA1030 ä»»åŠ¡çŠ¶æ€ï¼š{tag.SA1030.RtaskState}- ç©ºé—²{tag.SA1030.R5空闲}-->对应终点2001>空闲5:{tag.SA2001.R5空闲}");
            #endregion [脚本][20250617085800942][业务逻辑.流程2热处理炉进出.1030下母托.Program1]
         }
         catch(Exception ex)
         {
            Conn.默认日志.Error(ex.ToString());
         }
         finally
         {
            System.Threading.Thread.Sleep(3000);
         }
         }
            ExitJudgeStack.TryPop(out int exitJudgeVal);
});
         /// <summary>
         /// ç¨‹åºç‰‡æ®µ:Program1
         /// æè¿°:
         /// </summary>
         System.Threading.Tasks.Task.Factory.StartNew(() =>
         {
            System.Threading.Thread.CurrentThread.IsBackground = true;
            ExitJudgeStack.Push(0);
         //一直执行,直到满足结束条件
         while(true)
         {
            if (IsExitApp) { break; }
         try
         {
            #region    [脚本][20250617085809982][业务逻辑.流程2热处理炉进出.2030输送线下定子.Program1]
                        #endregion [脚本][20250617085800942][业务逻辑.流程2热处理炉进出.1030下母托.Program1]
                    }
                    catch (Exception ex)
                    {
                        Conn.默认日志.Error(ex.ToString());
                    }
                    finally
                    {
                        System.Threading.Thread.Sleep(3000);
                    }
                }
                ExitJudgeStack.TryPop(out int exitJudgeVal);
            });
            /// <summary>
            /// ç¨‹åºç‰‡æ®µ:Program1
            /// æè¿°:
            /// </summary>
            System.Threading.Tasks.Task.Factory.StartNew(() =>
            {
                System.Threading.Thread.CurrentThread.IsBackground = true;
                ExitJudgeStack.Push(0);
                //一直执行,直到满足结束条件
                while (true)
                {
                    if (IsExitApp) { break; }
                    try
                    {
                        #region    [脚本][20250617085809982][业务逻辑.流程2热处理炉进出.2030输送线下定子.Program1]
                        Console.WriteLine($"SA2030 ä»»åŠ¡çŠ¶æ€ï¼š{tag.SA2030.RtaskState}- ç©ºé—²{tag.SA2030.R5空闲} - barcode:{tag.SA2030.R托盘码}");
            #endregion [脚本][20250617085809982][业务逻辑.流程2热处理炉进出.2030输送线下定子.Program1]
         }
         catch(Exception ex)
         {
            Conn.默认日志.Error(ex.ToString());
         }
         finally
         {
            System.Threading.Thread.Sleep(3000);
         }
         }
            ExitJudgeStack.TryPop(out int exitJudgeVal);
});
      }
      /// <summary>
                        #endregion [脚本][20250617085809982][业务逻辑.流程2热处理炉进出.2030输送线下定子.Program1]
                    }
                    catch (Exception ex)
                    {
                        Conn.默认日志.Error(ex.ToString());
                    }
                    finally
                    {
                        System.Threading.Thread.Sleep(3000);
                    }
                }
                ExitJudgeStack.TryPop(out int exitJudgeVal);
            });
        }
        /// <summary>
        /// View1关闭事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
      public void View1_CloseEvent(object sender, System.ComponentModel.CancelEventArgs e)
      {
         try
         {
                System.Threading.Tasks.Task.Factory.StartNew(() => { MessageBox.Show("程序正在关闭,请等待..."); });
         }
         catch(Exception ex)
         {
            Conn.默认日志.Error(ex.ToString());
         }
         try
         {
            Conn.默认日志.Debug("[关闭处理][Start]关闭Http服务");
            if(HttpSvcHost!=null)
            {
               HttpSvcHost.Stop();
            }
         }
         catch(Exception ex)
         {
            Conn.默认日志.Error(ex.ToString());
         }
         finally
         {
            Conn.默认日志.Debug("[关闭处理][End]关闭Http服务");
         }
        public void View1_CloseEvent(object sender, System.ComponentModel.CancelEventArgs e)
        {
         try
         {
            Conn.默认日志.Debug("[关闭处理][Start]判断业务处理状态");
            IsExitApp = true;
            //int exitCnt = 0;
            while
            (
               ExitJudgeStack.Count > 0
            )
            {
               System.Threading.Thread.Sleep(100);
               //++exitCnt;
               //10秒未结束则强制关闭
               //if (exitCnt >= 100)
               //{
               //   break;
               //}
            }
         }
         catch (Exception ex)
         {
            Conn.默认日志.Error(ex.ToString());
         }
         finally
         {
            Conn.默认日志.Debug("[关闭处理][End]判断业务处理状态");
         }
            try
            {
                System.Threading.Tasks.Task.Factory.StartNew(() => { MessageBox.Show("程序正在关闭,请等待..."); });
            }
            catch (Exception ex)
            {
                Conn.默认日志.Error(ex.ToString());
            }
            try
            {
                Conn.默认日志.Debug("[关闭处理][Start]关闭Http服务");
                if (HttpSvcHost != null)
                {
                    HttpSvcHost.Stop();
                }
            }
            catch (Exception ex)
            {
                Conn.默认日志.Error(ex.ToString());
            }
            finally
            {
                Conn.默认日志.Debug("[关闭处理][End]关闭Http服务");
            }
            try
            {
                Conn.默认日志.Debug("[关闭处理][Start]判断业务处理状态");
                IsExitApp = true;
                //int exitCnt = 0;
                while
                (
                    ExitJudgeStack.Count > 0
                )
                {
                    System.Threading.Thread.Sleep(100);
                    //++exitCnt;
                    //10秒未结束则强制关闭
                    //if (exitCnt >= 100)
                    //{
                    //   break;
                    //}
                }
            }
            catch (Exception ex)
            {
                Conn.默认日志.Error(ex.ToString());
            }
            finally
            {
                Conn.默认日志.Debug("[关闭处理][End]判断业务处理状态");
            }
            e.Cancel = true;
         System.Threading.Tasks.Task.Factory.StartNew(() =>
         {
                  try
         {
            Conn.默认日志.Debug("[关闭处理][Start]关闭PLC");
            Device.维希尔抓臂1?.Stop();
            Device.维希尔抓臂2?.Stop();
            Device.Js捷顺1?.Stop();
            Device.Js捷顺2?.Stop();
            Device.p发那科1下线?.Stop();
            Device.A1025放货交互?.Stop();
            Device.A1022放货交互?.Stop();
            Device.A1019取货交互?.Stop();
            Device.A1030取货交互?.Stop();
            Device.SSXReadTemp?.Stop();
            Device.S1019Read?.Stop();
            Device.S1022Read?.Stop();
            Device.S1025Read?.Stop();
            Device.S1017Read?.Stop();
            Device.S1023Read?.Stop();
            Device.S1020Read?.Stop();
            Device.S1002Read?.Stop();
            Device.S1004Read?.Stop();
            Device.S1006Read?.Stop();
            Device.S1008Read?.Stop();
            Device.S1010Read?.Stop();
            Device.S1012Read?.Stop();
            Device.S1014Read?.Stop();
            Device.S1016Read?.Stop();
            Device.FNK1003051113?.Stop();
            Device.SSX1003051113?.Stop();
            Device.S1026Read?.Stop();
            Device.S1030Read?.Stop();
            Device.S2001Read?.Stop();
            Device.S2030Read?.Stop();
            Device.A2001放货交互?.Stop();
            Device.A2030取货交互?.Stop();
            Device.RGV?.Stop();
            Device.p发那科2下线?.Stop();
            Device.p发那科3上线?.Stop();
         }
         catch(Exception ex)
         {
            Conn.默认日志.Error(ex.ToString());
         }
         finally
         {
            Conn.默认日志.Debug("[关闭处理][End]关闭PLC");
         }
         try
         {
            Conn.默认日志.Debug("[关闭处理][Start]判断PLC状态");
            //int exitCnt = 0;
            while
            (
               false
               || (Device.维希尔抓臂1 == null ? false : Device.维希尔抓臂1.State != GZ.Device.PLC.PlcRunState.Stoped)
               || (Device.维希尔抓臂2 == null ? false : Device.维希尔抓臂2.State != GZ.Device.PLC.PlcRunState.Stoped)
               || (Device.Js捷顺1 == null ? false : Device.Js捷顺1.State != GZ.Device.PLC.PlcRunState.Stoped)
               || (Device.Js捷顺2 == null ? false : Device.Js捷顺2.State != GZ.Device.PLC.PlcRunState.Stoped)
               || (Device.p发那科1下线 == null ? false : Device.p发那科1下线.State != GZ.Device.PLC.PlcRunState.Stoped)
               || (Device.A1025放货交互 == null ? false : Device.A1025放货交互.State != GZ.Device.PLC.PlcRunState.Stoped)
               || (Device.A1022放货交互 == null ? false : Device.A1022放货交互.State != GZ.Device.PLC.PlcRunState.Stoped)
               || (Device.A1019取货交互 == null ? false : Device.A1019取货交互.State != GZ.Device.PLC.PlcRunState.Stoped)
               || (Device.A1030取货交互 == null ? false : Device.A1030取货交互.State != GZ.Device.PLC.PlcRunState.Stoped)
               || (Device.SSXReadTemp == null ? false : Device.SSXReadTemp.State != GZ.Device.PLC.PlcRunState.Stoped)
               || (Device.S1019Read == null ? false : Device.S1019Read.State != GZ.Device.PLC.PlcRunState.Stoped)
               || (Device.S1022Read == null ? false : Device.S1022Read.State != GZ.Device.PLC.PlcRunState.Stoped)
               || (Device.S1025Read == null ? false : Device.S1025Read.State != GZ.Device.PLC.PlcRunState.Stoped)
               || (Device.S1017Read == null ? false : Device.S1017Read.State != GZ.Device.PLC.PlcRunState.Stoped)
               || (Device.S1023Read == null ? false : Device.S1023Read.State != GZ.Device.PLC.PlcRunState.Stoped)
               || (Device.S1020Read == null ? false : Device.S1020Read.State != GZ.Device.PLC.PlcRunState.Stoped)
               || (Device.S1002Read == null ? false : Device.S1002Read.State != GZ.Device.PLC.PlcRunState.Stoped)
               || (Device.S1004Read == null ? false : Device.S1004Read.State != GZ.Device.PLC.PlcRunState.Stoped)
               || (Device.S1006Read == null ? false : Device.S1006Read.State != GZ.Device.PLC.PlcRunState.Stoped)
               || (Device.S1008Read == null ? false : Device.S1008Read.State != GZ.Device.PLC.PlcRunState.Stoped)
               || (Device.S1010Read == null ? false : Device.S1010Read.State != GZ.Device.PLC.PlcRunState.Stoped)
               || (Device.S1012Read == null ? false : Device.S1012Read.State != GZ.Device.PLC.PlcRunState.Stoped)
               || (Device.S1014Read == null ? false : Device.S1014Read.State != GZ.Device.PLC.PlcRunState.Stoped)
               || (Device.S1016Read == null ? false : Device.S1016Read.State != GZ.Device.PLC.PlcRunState.Stoped)
               || (Device.FNK1003051113 == null ? false : Device.FNK1003051113.State != GZ.Device.PLC.PlcRunState.Stoped)
               || (Device.SSX1003051113 == null ? false : Device.SSX1003051113.State != GZ.Device.PLC.PlcRunState.Stoped)
               || (Device.S1026Read == null ? false : Device.S1026Read.State != GZ.Device.PLC.PlcRunState.Stoped)
               || (Device.S1030Read == null ? false : Device.S1030Read.State != GZ.Device.PLC.PlcRunState.Stoped)
               || (Device.S2001Read == null ? false : Device.S2001Read.State != GZ.Device.PLC.PlcRunState.Stoped)
               || (Device.S2030Read == null ? false : Device.S2030Read.State != GZ.Device.PLC.PlcRunState.Stoped)
               || (Device.A2001放货交互 == null ? false : Device.A2001放货交互.State != GZ.Device.PLC.PlcRunState.Stoped)
               || (Device.A2030取货交互 == null ? false : Device.A2030取货交互.State != GZ.Device.PLC.PlcRunState.Stoped)
               || (Device.RGV == null ? false : Device.RGV.State != GZ.Device.PLC.PlcRunState.Stoped)
               || (Device.p发那科2下线 == null ? false : Device.p发那科2下线.State != GZ.Device.PLC.PlcRunState.Stoped)
               || (Device.p发那科3上线 == null ? false : Device.p发那科3上线.State != GZ.Device.PLC.PlcRunState.Stoped)
            )
            {
               System.Threading.Thread.Sleep(1000);
               //++exitCnt;
               //10秒未结束则强制关闭
               //if (exitCnt >= 100)
               //{
               //   break;
               //}
            }
         }
         catch (Exception ex)
         {
            Conn.默认日志.Error(ex.ToString());
         }
         finally
         {
            Conn.默认日志.Debug("[关闭处理][End]判断PLC状态");
         }
         Application.Current.Dispatcher.Invoke(() => { Environment.Exit(0); });
         });
         //System.Windows.Application.Current.Shutdown();
      }
      /// <summary>
            System.Threading.Tasks.Task.Factory.StartNew(() =>
            {
                try
                {
                    Conn.默认日志.Debug("[关闭处理][Start]关闭PLC");
                    Device.维希尔抓臂1?.Stop();
                    Device.维希尔抓臂2?.Stop();
                    Device.Js捷顺1?.Stop();
                    Device.Js捷顺2?.Stop();
                    Device.p发那科1下线?.Stop();
                    Device.A1025放货交互?.Stop();
                    Device.A1022放货交互?.Stop();
                    Device.A1019取货交互?.Stop();
                    Device.A1030取货交互?.Stop();
                    Device.SSXReadTemp?.Stop();
                    Device.S1019Read?.Stop();
                    Device.S1022Read?.Stop();
                    Device.S1025Read?.Stop();
                    Device.S1017Read?.Stop();
                    Device.S1023Read?.Stop();
                    Device.S1020Read?.Stop();
                    Device.S1002Read?.Stop();
                    Device.S1004Read?.Stop();
                    Device.S1006Read?.Stop();
                    Device.S1008Read?.Stop();
                    Device.S1010Read?.Stop();
                    Device.S1012Read?.Stop();
                    Device.S1014Read?.Stop();
                    Device.S1016Read?.Stop();
                    Device.FNK1003051113?.Stop();
                    Device.SSX1003051113?.Stop();
                    Device.S1026Read?.Stop();
                    Device.S1030Read?.Stop();
                    Device.S2001Read?.Stop();
                    Device.S2030Read?.Stop();
                    Device.A2001放货交互?.Stop();
                    Device.A2030取货交互?.Stop();
                    Device.RGV?.Stop();
                    Device.p发那科2下线?.Stop();
                    Device.p发那科3上线?.Stop();
                }
                catch (Exception ex)
                {
                    Conn.默认日志.Error(ex.ToString());
                }
                finally
                {
                    Conn.默认日志.Debug("[关闭处理][End]关闭PLC");
                }
                try
                {
                    Conn.默认日志.Debug("[关闭处理][Start]判断PLC状态");
                    //int exitCnt = 0;
                    while
                    (
                        false
                        || (Device.维希尔抓臂1 == null ? false : Device.维希尔抓臂1.State != GZ.Device.PLC.PlcRunState.Stoped)
                        || (Device.维希尔抓臂2 == null ? false : Device.维希尔抓臂2.State != GZ.Device.PLC.PlcRunState.Stoped)
                        || (Device.Js捷顺1 == null ? false : Device.Js捷顺1.State != GZ.Device.PLC.PlcRunState.Stoped)
                        || (Device.Js捷顺2 == null ? false : Device.Js捷顺2.State != GZ.Device.PLC.PlcRunState.Stoped)
                        || (Device.p发那科1下线 == null ? false : Device.p发那科1下线.State != GZ.Device.PLC.PlcRunState.Stoped)
                        || (Device.A1025放货交互 == null ? false : Device.A1025放货交互.State != GZ.Device.PLC.PlcRunState.Stoped)
                        || (Device.A1022放货交互 == null ? false : Device.A1022放货交互.State != GZ.Device.PLC.PlcRunState.Stoped)
                        || (Device.A1019取货交互 == null ? false : Device.A1019取货交互.State != GZ.Device.PLC.PlcRunState.Stoped)
                        || (Device.A1030取货交互 == null ? false : Device.A1030取货交互.State != GZ.Device.PLC.PlcRunState.Stoped)
                        || (Device.SSXReadTemp == null ? false : Device.SSXReadTemp.State != GZ.Device.PLC.PlcRunState.Stoped)
                        || (Device.S1019Read == null ? false : Device.S1019Read.State != GZ.Device.PLC.PlcRunState.Stoped)
                        || (Device.S1022Read == null ? false : Device.S1022Read.State != GZ.Device.PLC.PlcRunState.Stoped)
                        || (Device.S1025Read == null ? false : Device.S1025Read.State != GZ.Device.PLC.PlcRunState.Stoped)
                        || (Device.S1017Read == null ? false : Device.S1017Read.State != GZ.Device.PLC.PlcRunState.Stoped)
                        || (Device.S1023Read == null ? false : Device.S1023Read.State != GZ.Device.PLC.PlcRunState.Stoped)
                        || (Device.S1020Read == null ? false : Device.S1020Read.State != GZ.Device.PLC.PlcRunState.Stoped)
                        || (Device.S1002Read == null ? false : Device.S1002Read.State != GZ.Device.PLC.PlcRunState.Stoped)
                        || (Device.S1004Read == null ? false : Device.S1004Read.State != GZ.Device.PLC.PlcRunState.Stoped)
                        || (Device.S1006Read == null ? false : Device.S1006Read.State != GZ.Device.PLC.PlcRunState.Stoped)
                        || (Device.S1008Read == null ? false : Device.S1008Read.State != GZ.Device.PLC.PlcRunState.Stoped)
                        || (Device.S1010Read == null ? false : Device.S1010Read.State != GZ.Device.PLC.PlcRunState.Stoped)
                        || (Device.S1012Read == null ? false : Device.S1012Read.State != GZ.Device.PLC.PlcRunState.Stoped)
                        || (Device.S1014Read == null ? false : Device.S1014Read.State != GZ.Device.PLC.PlcRunState.Stoped)
                        || (Device.S1016Read == null ? false : Device.S1016Read.State != GZ.Device.PLC.PlcRunState.Stoped)
                        || (Device.FNK1003051113 == null ? false : Device.FNK1003051113.State != GZ.Device.PLC.PlcRunState.Stoped)
                        || (Device.SSX1003051113 == null ? false : Device.SSX1003051113.State != GZ.Device.PLC.PlcRunState.Stoped)
                        || (Device.S1026Read == null ? false : Device.S1026Read.State != GZ.Device.PLC.PlcRunState.Stoped)
                        || (Device.S1030Read == null ? false : Device.S1030Read.State != GZ.Device.PLC.PlcRunState.Stoped)
                        || (Device.S2001Read == null ? false : Device.S2001Read.State != GZ.Device.PLC.PlcRunState.Stoped)
                        || (Device.S2030Read == null ? false : Device.S2030Read.State != GZ.Device.PLC.PlcRunState.Stoped)
                        || (Device.A2001放货交互 == null ? false : Device.A2001放货交互.State != GZ.Device.PLC.PlcRunState.Stoped)
                        || (Device.A2030取货交互 == null ? false : Device.A2030取货交互.State != GZ.Device.PLC.PlcRunState.Stoped)
                        || (Device.RGV == null ? false : Device.RGV.State != GZ.Device.PLC.PlcRunState.Stoped)
                        || (Device.p发那科2下线 == null ? false : Device.p发那科2下线.State != GZ.Device.PLC.PlcRunState.Stoped)
                        || (Device.p发那科3上线 == null ? false : Device.p发那科3上线.State != GZ.Device.PLC.PlcRunState.Stoped)
                    )
                    {
                        System.Threading.Thread.Sleep(1000);
                        //++exitCnt;
                        //10秒未结束则强制关闭
                        //if (exitCnt >= 100)
                        //{
                        //   break;
                        //}
                    }
                }
                catch (Exception ex)
                {
                    Conn.默认日志.Error(ex.ToString());
                }
                finally
                {
                    Conn.默认日志.Debug("[关闭处理][End]判断PLC状态");
                }
                Application.Current.Dispatcher.Invoke(() => { Environment.Exit(0); });
            });
            //System.Windows.Application.Current.Shutdown();
        }
        /// <summary>
        /// View1初始化
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
      public void View1_Init(object sender, RoutedEventArgs e)
      {
      }
      #endregion
      #region åˆ‡æ¢tab页
      public void tab_SelectionChanged(object sender, EventArgs e)
      {
         //TabItem ti = (sender as TabControl).SelectedItem as TabItem;
         //MessageBox.Show(ti.Name);
      }
      #endregion
      #region Http服务监听
      private void HttpSvcListenerCallback(IAsyncResult ar)
      {
         try
         {
            HttpSvcHost.BeginGetContext(HttpSvcListenerCallback, null);
            System.Net.HttpListenerContext context = HttpSvcHost.EndGetContext(ar);
            System.Net.HttpListenerRequest request = context.Request;
            System.Net.HttpListenerResponse response = context.Response;
            switch(request.LocalEndPoint.ToString())
            {
               case "10.221.55.116:8808":
               {
                  using (var reader = new System.IO.StreamReader(request.InputStream, System.Text.Encoding.UTF8))
                  {
                     string requestJson = reader.ReadToEnd();
        public void View1_Init(object sender, RoutedEventArgs e)
        {
        }
        #endregion
                     string respstr = HttpSvcListenerCallback_he(request.HttpMethod,request.Url.AbsolutePath,requestJson,out System.Net.HttpStatusCode statusCode);
        #region åˆ‡æ¢tab页
        public void tab_SelectionChanged(object sender, EventArgs e)
        {
            //TabItem ti = (sender as TabControl).SelectedItem as TabItem;
            //MessageBox.Show(ti.Name);
        }
        #endregion
                     string logContent="";
                     logContent += $"\r\n[{request.HttpMethod}]{request.Url.AbsolutePath}";
                     logContent += $"\r\n[request]{requestJson}";
                     logContent += $"\r\n[response]{respstr}";
                     Conn.默认日志?.Info(logContent);
                     byte[] bytstr = Encoding.UTF8.GetBytes(respstr);
                     response.StatusCode = (int)statusCode;
                     response.SendChunked = false;
                     response.ContentLength64 = bytstr.Length;
                     response.OutputStream.Write(bytstr, 0, bytstr.Length);
                     response.Close();
                  }
                  break;
               }
            }
         }
         catch(Exception ex)
         {
            Conn.默认日志.Error(ex.ToString());
         }
      }
      private System.String HttpSvcListenerCallback_he(System.String method,System.String path,System.String requestJson,out System.Net.HttpStatusCode statusCode)
      {
         try
         {
            switch(method)
            {
               case "POST":
               {
                  switch(path)
                  {
                     case "/agv/agvCallbackService/agvCallback":
                     {
                        statusCode = System.Net.HttpStatusCode.OK;
        #region Http服务监听
        private void HttpSvcListenerCallback(IAsyncResult ar)
        {
            try
            {
                HttpSvcHost.BeginGetContext(HttpSvcListenerCallback, null);
                System.Net.HttpListenerContext context = HttpSvcHost.EndGetContext(ar);
                System.Net.HttpListenerRequest request = context.Request;
                System.Net.HttpListenerResponse response = context.Response;
                switch (request.LocalEndPoint.ToString())
                {
                    case "10.221.55.116:8808":
                        {
                            using (var reader = new System.IO.StreamReader(request.InputStream, System.Text.Encoding.UTF8))
                            {
                                string requestJson = reader.ReadToEnd();
                                string respstr = HttpSvcListenerCallback_he(request.HttpMethod, request.Url.AbsolutePath, requestJson, out System.Net.HttpStatusCode statusCode);
                                string logContent = "";
                                logContent += $"\r\n[{request.HttpMethod}]{request.Url.AbsolutePath}";
                                logContent += $"\r\n[request]{requestJson}";
                                logContent += $"\r\n[response]{respstr}";
                                Conn.默认日志?.Info(logContent);
                                byte[] bytstr = Encoding.UTF8.GetBytes(respstr);
                                response.StatusCode = (int)statusCode;
                                response.SendChunked = false;
                                response.ContentLength64 = bytstr.Length;
                                response.OutputStream.Write(bytstr, 0, bytstr.Length);
                                response.Close();
                            }
                            break;
                        }
                }
            }
            catch (Exception ex)
            {
                Conn.默认日志.Error(ex.ToString());
            }
        }
        private System.String HttpSvcListenerCallback_he(System.String method, System.String path, System.String requestJson, out System.Net.HttpStatusCode statusCode)
        {
            try
            {
                switch (method)
                {
                    case "POST":
                        {
                            switch (path)
                            {
                                case "/agv/agvCallbackService/agvCallback":
                                    {
                                        statusCode = System.Net.HttpStatusCode.OK;
                                        LogHelper.Info("ExecuteState Request-haikang:" + requestJson);
                                        var model = JsonConvert.DeserializeObject<HaiKangOrderInfo>(requestJson);
                                        OperateHKTaskStatus(model);
                                        return JsonConvert.SerializeObject(new HkReturnResult { reqCode = model.reqCode });
                     }
                     case "/api/Wcs/CreateTask":
                     {
                        statusCode = System.Net.HttpStatusCode.OK;
                                    }
                                case "/api/Wcs/CreateTask":
                                    {
                                        statusCode = System.Net.HttpStatusCode.OK;
                                        LogHelper.Info("/api/Wcs/CreateTask:" + requestJson);
                                        var model = JsonConvert.DeserializeObject<ToWMSMES.CreateTask>(requestJson);
                                        var res = ToWMSMES.CreateTask.CreatemesTask(model);
                                        return JsonConvert.SerializeObject(res);
                     }
                     case "/api/Wcs/TestRequestTask":
                     {
                        statusCode = System.Net.HttpStatusCode.OK;
                        LogHelper.Info("/api/Wcs/TestRequestTask:" + requestJson);
var str = Settings.apiHelper.Post(Settings.WMSbaseUrl + "mom-basic/dataTransmission/json/service/200", requestJson);
return str;
                     }
                     case "/api/Wcs/updateStatus":
                     {
                        statusCode = System.Net.HttpStatusCode.OK;
                        LogHelper.Info("/api/Wcs/updateStatus:" + requestJson);
var str = Settings.apiHelper.Post(Settings.WMSbaseUrl + "mom-basic/dataTransmission/json/service/201", requestJson);
return str;
                     }
                     case "/api/Wcs/toMes":
                     {
                        statusCode = System.Net.HttpStatusCode.OK;
                                    }
                                case "/api/Wcs/TestRequestTask":
                                    {
                                        statusCode = System.Net.HttpStatusCode.OK;
                                        LogHelper.Info("/api/Wcs/TestRequestTask:" + requestJson);
                                        var str = Settings.apiHelper.Post(Settings.WMSbaseUrl + "mom-basic/dataTransmission/json/service/200", requestJson);
                                        return str;
                                    }
                                case "/api/Wcs/updateStatus":
                                    {
                                        statusCode = System.Net.HttpStatusCode.OK;
                                        LogHelper.Info("/api/Wcs/updateStatus:" + requestJson);
                                        var str = Settings.apiHelper.Post(Settings.WMSbaseUrl + "mom-basic/dataTransmission/json/service/201", requestJson);
                                        return str;
                                    }
                                case "/api/Wcs/toMes":
                                    {
                                        statusCode = System.Net.HttpStatusCode.OK;
                                        LogHelper.Info("/api/Wcs/toMes:" + requestJson);
                                        var str = Settings.apiHelper.Post(Settings.MESbaseUrl + "mom-basic/dataTransmission/json/service/202", requestJson);
                                        return str;
                     }
                     case "/api/Wcs/CreatePointTask":
                     {
                        statusCode = System.Net.HttpStatusCode.OK;
                                    }
                                case "/api/Wcs/CreatePointTask":
                                    {
                                        statusCode = System.Net.HttpStatusCode.OK;
                                        LogHelper.Info("/api/Wcs/CreatepointTask:" + requestJson);
                                        var model = JsonConvert.DeserializeObject<ToWMSMES.CreateTask>(requestJson);
                                        var res = ToWMSMES.CreateTask.CreatePointTask(model);
                                        return JsonConvert.SerializeObject(res);
                     }
                  }
                  break;
               }
               case "GET":
               {
                  switch(path)
                  {
                     case "/inddddddddddddddddd":
                     {
                        statusCode = System.Net.HttpStatusCode.OK;
                        // å¤åˆ¶åˆ°case ä¸Š
//var _ when System.Text.RegularExpressions.Regex.IsMatch(path, @"\.(html|ico|js|css)(\?.*)?$", System.Text.RegularExpressions.RegexOptions.IgnoreCase)
var filePath = System.IO.Path.Combine("Static", path.Substring(1));
return File.ReadAllText(filePath);
                     }
                  }
                  break;
               }
            }
            statusCode = System.Net.HttpStatusCode.NotFound;
            return "";
         }
         catch(Exception ex)
         {
            Conn.默认日志.Error(ex.ToString());
            statusCode = System.Net.HttpStatusCode.InternalServerError;
            return "";
         }
      }
      #endregion
   }
                                    }
                            }
                            break;
                        }
                    case "GET":
                        {
                            switch (path)
                            {
                                case "/inddddddddddddddddd":
                                    {
                                        statusCode = System.Net.HttpStatusCode.OK;
                                        // å¤åˆ¶åˆ°case ä¸Š
                                        //var _ when System.Text.RegularExpressions.Regex.IsMatch(path, @"\.(html|ico|js|css)(\?.*)?$", System.Text.RegularExpressions.RegexOptions.IgnoreCase)
                                        var filePath = System.IO.Path.Combine("Static", path.Substring(1));
                                        return File.ReadAllText(filePath);
                                    }
                            }
                            break;
                        }
                }
                statusCode = System.Net.HttpStatusCode.NotFound;
                return "";
            }
            catch (Exception ex)
            {
                Conn.默认日志.Error(ex.ToString());
                statusCode = System.Net.HttpStatusCode.InternalServerError;
                return "";
            }
        }
        #endregion
    }
}