1
czw
2025-07-08 03746e288fc02c6d2780aeac4cab42299e6b27c4
2025Äê6ÔÂ12ÈÕ/AuxAllWCS/Build/Project/´úÂë/VS×Ô¶¨ÒåÀà/AutoThread.cs
@@ -78,8 +78,8 @@
            }
            // æ‰§è¡Œå§”托
            if (methodName != "TaskEverythingRun")
                return null;
            //if (methodName != "TaskEverythingRun")
            //    return null;
            return methodDelegate.DynamicInvoke(args);
        }
@@ -126,6 +126,41 @@
            }
        }
        public void ThreaTotal(Tag tag)
        {
            List<Task> tasks = new List<Task>();
            tasks.Add(GetTask(ThreadMXC3, tag, 3000));
            tasks.Add(GetTask(ThreadMXC4, tag, 3000));
            tasks.Add(GetTask(ResetGats, tag, 3000));
            Task.WaitAll(tasks.ToArray());
        }
        private Task GetTask(Action<Tag> action, Tag tag, int i = 2500)
        {
            var task = Task.Run(() =>
            {
                while (true)
                {
                    try
                    {
                        action(tag);
                    }
                    catch (Exception ex)
                    {
                        LogHelper.Error(ex.Message, ex);
                    }
                    Thread.Sleep(i);
                }
            });
            return task;
        }
        public string WriteLine(string value = "")
        {
@@ -167,6 +202,7 @@
                {
                    //tag.Js1.D1212_LAST = 0; 
                    RedisHelper.Add($"Js捷顺1.D1202_LAST", "0", out string msg);
                    //Conn.默认Redis.SetValue(VERX.deviceName + ".D1224", "0", VERX.deviceName + "Queue");
                }
                if (tag.Js1.D1213_LAST == 0 && TcpServer.GetBitdata(tag.Js1.D1212, 3) == 1)
@@ -188,6 +224,7 @@
                {
                    //tag.Js1.D1213_LAST = 0;
                    RedisHelper.Add($"Js捷顺1.D1203_LAST", "0", out string msg);
                    //Conn.默认Redis.SetValue(VERX.deviceName + ".D1225", "0", VERX.deviceName + "Queue");
                }
            }
        }
@@ -650,7 +687,7 @@
                {
                    LogHelper.Info($"RGV æœ‰125命令未执行。 ");
                    LogHelper.Info($"RGV125命令未执行 ä»»åŠ¡æ•°æ® workmode:{tag.RGV.workMod}\n taskmod{tag.RGV.taskmod} \n t1No:{tag.RGV.taskno1}\n t1do:{tag.RGV.task1do} \n t2No:{tag.RGV.taskno2}\n t2do:{tag.RGV.task2do}\n taskend:{tag.RGV.taskend} ");
                    if (tag.RGV.workMod == 0 && tag.RGV.taskmod == 0 && tag.RGV.taskno1 == tag.RGV.ReadTask1No && tag.RGV.taskno2 == tag.RGV.ReadTask2No)
                    {
                        LogHelper.Info($"RGV125命令未执行 tag.RGV.workMod == 0 && tag.RGV.taskmod == 0 && tag.RGV.taskno1 == tag.RGV.ReadTask1No && tag.RGV.taskno2 == tag.RGV.ReadTask2No  è‡ªåŠ¨æ¸…é™¤125");
@@ -1069,6 +1106,12 @@
                            Conn.默认Redis.SetValue(dev.deviceName + "." + (V ? "D1220" : "D1221"), "0", dev.deviceName + "Queue");
                            Conn.默认Redis.SetValue(dev.deviceName + "." + (V ? "D1222" : "D1223"), "1", dev.deviceName + "Queue");
                        }
                        else if (dev.deviceType == 5)
                        {
                            LogHelper.Info($"ThreadGrats {item.S_TASK_NO} >{item.S_ACTION_CODE} è®¾å¤‡æ˜¯{dev.deviceName} å¼€å¯å…‰æ …处理 =================> ");
                            Conn.默认Redis.SetValue(dev.deviceName + "." + (V ? "D2211" : "D2216"), "1", dev.deviceName + "Queue");
                            Conn.默认Redis.SetValue(dev.deviceName + "." + (V ? "D2212" : "D2217"), "0", dev.deviceName + "Queue");
                        }
                        LogHelper.Info($"ThreadGrats {item.S_TASK_NO} >{item.S_ACTION_CODE} è®¾å¤‡æ˜¯{dev.deviceName} å¼€å¯å…‰æ …处理完成 =================> ");
                        item.N_CREATEMETHOD = 1;
@@ -1078,49 +1121,70 @@
                    //车要进入交互。
                    else
                    {
                        if (dev.deviceType == 1)
                        if (dev.deviceType == 4)
                        {
                            LogHelper.Info($"ThreadGrats {item.S_TASK_NO} >{item.S_ACTION_CODE} è®¾å¤‡æ˜¯{dev.deviceName} å…³é—­å…‰æ …处理 =================> ");
                            var tf = Conn.默认Redis.GetValue(dev.deviceName + "." + (V ? "R50" : "R52"));//读关闭状态
                            LogHelper.Info($"ThreadGrats {item.S_TASK_NO} >{item.S_ACTION_CODE} è®¾å¤‡æ˜¯{dev.deviceName} å…‰æ …关闭信号{tf}");
                            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", false);
                            }
                            LogHelper.Info($"ThreadGrats {item.S_TASK_NO} >{item.S_ACTION_CODE} è®¾å¤‡æ˜¯{dev.deviceName} å…³é—­å…‰æ …处理完成 =================> ");
                            LogHelper.Info($"ThreadGrats {item.S_TASK_NO} >{item.S_ACTION_CODE} è®¾å¤‡æ˜¯{dev.deviceName} SSX AGV äº¤äº’。。。");
                            //tag.SA1019.Sagverr
                        }
                        else if (dev.deviceType == 2)
                        else
                        {
                            LogHelper.Info($"ThreadGrats {item.S_TASK_NO} >{item.S_ACTION_CODE} è®¾å¤‡æ˜¯{dev.deviceName} å…³é—­å…‰æ …处理 =================> ");
                            var tf = Conn.默认Redis.GetValue(dev.deviceName + ".D1202");
                            int numm = int.Parse(string.IsNullOrEmpty(tf) ? "0" : tf);
                            int close = TcpServer.GetBitdata(numm, (V ? 0 : 1));
                            LogHelper.Info($"ThreadGrats {item.S_TASK_NO} >{item.S_ACTION_CODE} è®¾å¤‡æ˜¯{dev.deviceName} å…‰æ …关闭信号{close}");
                            if (close == 1)
                            if (dev.deviceType == 1)
                            {
                                LogHelper.Info($"{dev.deviceName}{(V ? "å·¦" : "右")} å…‰æ …{(goin ? "关闭" : "开启")} ç”³è¯·ã€‚ å·²ç»å…³é—­ï¼");
                                continuuuuu = true;
                                var tf = Conn.默认Redis.GetValue(dev.deviceName + "." + (V ? "R50" : "R52"));//读关闭状态
                                LogHelper.Info($"ThreadGrats {item.S_TASK_NO} >{item.S_ACTION_CODE} è®¾å¤‡æ˜¯{dev.deviceName} å…‰æ …关闭信号{tf}");
                                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", false);
                                }
                            }
                            else
                            else if (dev.deviceType == 2)
                            {
                                LogHelper.Info($"{dev.deviceName}{(V ? "å·¦" : "右")} å…‰æ …{(goin ? "关闭" : "开启")} ç”³è¯·ã€‚" + string.Format("{0}{1}{2}", dev.deviceName + "." + (V ? "D1220" : "D1221"), "1", dev.deviceName + "Queue"));
                                Conn.默认Redis.SetValue(dev.deviceName + "." + (V ? "D1222" : "D1223"), "0", dev.deviceName + "Queue");
                                Conn.默认Redis.SetValue(dev.deviceName + "." + (V ? "D1220" : "D1221"), "1", dev.deviceName + "Queue");
                                var tf = Conn.默认Redis.GetValue(dev.deviceName + ".D1202");
                                int numm = int.Parse(string.IsNullOrEmpty(tf) ? "0" : tf);
                                int close = TcpServer.GetBitdata(numm, (V ? 0 : 1));
                                LogHelper.Info($"ThreadGrats {item.S_TASK_NO} >{item.S_ACTION_CODE} è®¾å¤‡æ˜¯{dev.deviceName} å…‰æ …关闭信号{close}");
                                if (close == 1)
                                {
                                    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"), "1", dev.deviceName + "Queue"));
                                    Conn.默认Redis.SetValue(dev.deviceName + "." + (V ? "D1222" : "D1223"), "0", dev.deviceName + "Queue");
                                    Conn.默认Redis.SetValue(dev.deviceName + "." + (V ? "D1220" : "D1221"), "1", dev.deviceName + "Queue");
                                string d12201 = RedisHelper.Get<string>(dev.deviceName + "." + (V ? "D1220" : "D1221"), out string msg);
                                LogHelper.Info($"ThreadGrats å†™{(dev.deviceName + "." + (V ? "D1220" : "D1221"))}为 1 ï¼Œ åŽè¯»{d12201}");
                                    string d12201 = RedisHelper.Get<string>(dev.deviceName + "." + (V ? "D1220" : "D1221"), out string msg);
                                    LogHelper.Info($"ThreadGrats å†™{(dev.deviceName + "." + (V ? "D1220" : "D1221"))}为 1 ï¼Œ åŽè¯»{d12201}");
                                }
                            }
                            else if (dev.deviceType == 3)
                            {
                                var close = (System.UInt16)System.Convert.ChangeType(Conn.默认Redis.GetValue(dev.deviceName + "." + (V ? "D2220" : "D2225")), typeof(System.UInt16));
                                if (close == 1)
                                {
                                    LogHelper.Info($"{dev.deviceName}{(V ? "å·¦" : "右")} å…‰æ …{(goin ? "关闭" : "开启")} ç”³è¯·ã€‚ å·²ç»å…³é—­ï¼");
                                    continuuuuu = true;
                                }
                                else
                                {
                                    Conn.默认Redis.SetValue(dev.deviceName + "." + (V ? "D2212" : "D2217"), "1", dev.deviceName + "Queue");
                                    Conn.默认Redis.SetValue(dev.deviceName + "." + (V ? "D2211" : "D2216"), "0", dev.deviceName + "Queue");
                                }
                            }
                            LogHelper.Info($"ThreadGrats {item.S_TASK_NO} >{item.S_ACTION_CODE} è®¾å¤‡æ˜¯{dev.deviceName} å…³é—­å…‰æ …处理完成 =================> ");
                        }
                    }
                }
                if (continuuuuu)
                {
                    LogHelper.Info($"{item.S_TASK_NO}{item.S_ACTION_CODE} è½¦è¾†å‘送继续任务!");
@@ -1135,6 +1199,9 @@
                }
            }
            System.Threading.Thread.Sleep(3000);
        }
        public void ResetGats(Tag tag)
        {
            LogHelper.Info($"ThreadGrats deviceType2光栅写入位重置 =================> ");
            //重置信号
            foreach (var dev in Settings.deviceInfos.FindAll(x => x.deviceType == 2))
@@ -1164,6 +1231,20 @@
                }
            }
            LogHelper.Info($"ThreadGrats deviceType2光栅写入位重置完成。 =================> ");
            LogHelper.Info($"ThreadGrats deviceType5光栅写入位重置 =================> ");
            //重置信号
            //foreach (var dev in Settings.deviceInfos.FindAll(x => x.deviceType == 5))
            {
                if (tag.DZ1.D2211 == 1 && tag.DZ1.D2220 == 1)
                    tag.DZ1.D2211 = 0;
                if (tag.DZ1.D2216 == 1 && tag.DZ1.D2225 == 1)
                    tag.DZ1.D2216 = 0;
                if (tag.DZ2.D2211 == 1 && tag.DZ2.D2220 == 1)
                    tag.DZ2.D2211 = 0;
                if (tag.DZ2.D2216 == 1 && tag.DZ2.D2225 == 1)
                    tag.DZ2.D2216 = 0;
            }
            LogHelper.Info($"ThreadGrats deviceType5光栅写入位重置完成。 =================> ");
        }
        /// <summary>
        /// 1020  1023空框下线
@@ -1994,12 +2075,12 @@
                                {
                                    if (device2.deviceName.Contains("Js捷顺"))
                                    {
                                        Task.Run(() =>
                                        {
                                            var inde = device2.location.ToList().FindIndex(x => x == wcsTask.S_END_LOC) == 0;
                                            string V = inde ? "D1224" : "D1225";
                                            Conn.默认Redis.SetValue(device2.deviceName + "." + V, "1", device2.deviceName + "Queue");
                                        });
                                        //Task.Run(() =>
                                        //{
                                        var inde = device2.location.ToList().FindIndex(x => x == wcsTask.S_END_LOC) == 0;
                                        string V = inde ? "D1224" : "D1225";
                                        Conn.默认Redis.SetValue(device2.deviceName + "." + V, "1", device2.deviceName + "Queue");
                                        //});
                                        var str = Settings.apiHelper.Post(Settings.WMSbaseUrl + "mom-basic/dataTransmission/json/service/202", JsonConvert.SerializeObject(new
                                        {
@@ -2028,6 +2109,31 @@
                                        }));
                                        LogHelper.Info($"{ssloc}申请mes任务结果{str}");
                                    }
                                }
                                switch (device2.deviceType)
                                {
                                    case 4:
                                        {
                                            if (wcsTask.S_END_LOC == "2001")
                                            {
                                            }
                                        }
                                        break;
                                    case 5:
                                        {
                                            var inde = device2.location.ToList().FindIndex(x => x == wcsTask.S_END_LOC) == 0;
                                            string V = inde ? "D2210" : "D2215";
                                            Conn.默认Redis.SetValue(device2.deviceName + "." + V, "1", device2.deviceName + "Queue");
                                        }
                                        break;
                                    case 6:
                                        {
                                            //var inde = device2.location.ToList().FindIndex(x => x == wcsTask.S_END_LOC) == 0;
                                            //string V = inde ? "D2210" : "D2215";
                                            //Conn.默认Redis.SetValue(device2.deviceName + "." + V, "1", device2.deviceName + "Queue");
                                        }
                                        break;
                                }
                            }
@@ -2151,18 +2257,129 @@
            }
        }
        /// <summary>
        /// å®šå­1号线。
        /// 1.增加下线逻辑。   2. æœ‰å–筐信号就写,没信号嫑写
        /// </summary>
        /// <param name="tag"></param>
        public void ThreadMXC3(Tag tag)
        {
            var VERX = Settings.deviceInfos.Find(x => x.deviceType == 5 && x.deviceName.Contains("1号"));
            if (VERX == null)
            {
                LogHelper.Info("定子1号线 deviceType 5 æ²¡æœ‰é…ç½®ã€‚");
                return;
            }
            LogHelper.Info($" {VERX.deviceName} D2221>{tag.DZ1.D2221} D2221_LAST>{tag.DZ1.D2221_LAST}  D2226>{tag.DZ1.D2226}  D2226_LAST>{tag.DZ1.D2226_LAST}");
            if (tag.DZ1.D2221 == 1 && tag.DZ1.D2221_LAST == 0)
            {
                var str = Settings.apiHelper.Post(Settings.WMSbaseUrl + "mom-basic/dataTransmission/json/service/200", JsonConvert.SerializeObject(new
                {
                    requestType = 7,
                    startBit = VERX.location[0],
                    unLockStartBitOutbin = true
                }));
                LogHelper.Info($"{VERX.location[0]}申请mes任务结果{str}");
                var strr = JsonConvert.DeserializeObject<Messss>(str);
                if (strr != null && strr.success && strr.data?.state == 0)
                    RedisHelper.Add($"D定子1号机械手.D2221_LAST", "1", out string msg);
            }
            else if (tag.DZ1.D2221 == 0 && tag.DZ1.D2221_LAST == 1)
            {
                LogHelper.Info($"重置 D定子1号机械手.D2221_LAST > 0");
                RedisHelper.Add($"D定子1号机械手.D2221_LAST", "0", out string msg);
                string V = 0 == 0 ? "D2210" : "D2215";
                Conn.默认Redis.SetValue(VERX.deviceName + "." + V, "0", VERX.deviceName + "Queue");
            }
            if (tag.DZ1.D2226 == 1 && tag.DZ1.D2226_LAST == 0)
            {
                var str = Settings.apiHelper.Post(Settings.WMSbaseUrl + "mom-basic/dataTransmission/json/service/200", JsonConvert.SerializeObject(new
                {
                    requestType = 7,
                    startBit = VERX.location[1],
                    unLockStartBitOutbin = true
                }));
                LogHelper.Info($"{VERX.location[0]}申请mes任务结果{str}");
                var strr = JsonConvert.DeserializeObject<Messss>(str);
                if (strr != null && strr.success && strr.data?.state == 0)
                    RedisHelper.Add($"D定子1号机械手.D2226_LAST", "1", out string msg);
            }
            else if (tag.DZ1.D2226 == 0 && tag.DZ1.D2226_LAST == 1)
            {
                LogHelper.Info($"重置 D定子1号机械手.D2226_LAST > 0");
                RedisHelper.Add($"D定子1号机械手.D2226_LAST", "0", out string msg);
                string V = 1 == 0 ? "D2210" : "D2215";
                Conn.默认Redis.SetValue(VERX.deviceName + "." + V, "0", VERX.deviceName + "Queue");
            }
        }
        /// <summary>
        /// å®šå­2号线。
        /// </summary>
        /// <param name="tag"></param>
        public void ThreadMXC4(Tag tag)
        {
            var VERX = Settings.deviceInfos.Find(x => x.deviceType == 5 && x.deviceName.Contains("2号"));
            if (VERX == null)
            {
                LogHelper.Info("定子2号线 deviceType 5 æ²¡æœ‰é…ç½®ã€‚");
                return;
            }
            LogHelper.Info($" {VERX.deviceName} D2221>{tag.DZ1.D2221} D2221_LAST>{tag.DZ1.D2221_LAST}  D2226>{tag.DZ1.D2226}  D2226_LAST>{tag.DZ1.D2226_LAST}");
            if (tag.DZ2.D2221 == 1 && tag.DZ2.D2221_LAST == 0)
            {
                var str = Settings.apiHelper.Post(Settings.WMSbaseUrl + "mom-basic/dataTransmission/json/service/200", JsonConvert.SerializeObject(new
                {
                    requestType = 7,
                    startBit = VERX.location[0],
                    unLockStartBitOutbin = true
                }));
                LogHelper.Info($"{VERX.location[0]}申请mes任务结果{str}");
                var strr = JsonConvert.DeserializeObject<Messss>(str);
                if (strr != null && strr.success && strr.data?.state == 0)
                    RedisHelper.Add($"D定子2号机械手.D2221_LAST", "1", out string msg);
            }
            else if (tag.DZ2.D2221 == 0 && tag.DZ2.D2221_LAST == 1)
            {
                LogHelper.Info($"重置 D定子2号机械手.D2221_LAST > 0");
                RedisHelper.Add($"D定子2号机械手.D2221_LAST", "0", out string msg);
                string V = 0 == 0 ? "D2210" : "D2215";
                Conn.默认Redis.SetValue(VERX.deviceName + "." + V, "0", VERX.deviceName + "Queue");
            }
            if (tag.DZ2.D2226 == 1 && tag.DZ2.D2226_LAST == 0)
            {
                var str = Settings.apiHelper.Post(Settings.WMSbaseUrl + "mom-basic/dataTransmission/json/service/200", JsonConvert.SerializeObject(new
                {
                    requestType = 7,
                    startBit = VERX.location[1],
                    unLockStartBitOutbin = true
                }));
                LogHelper.Info($"{VERX.location[0]}申请mes任务结果{str}");
                var strr = JsonConvert.DeserializeObject<Messss>(str);
                if (strr != null && strr.success && strr.data?.state == 0)
                    RedisHelper.Add($"D定子2号机械手.D2226_LAST", "1", out string msg);
            }
            else if (tag.DZ2.D2226 == 0 && tag.DZ2.D2226_LAST == 1)
            {
                LogHelper.Info($"重置 D定子2号机械手.D2226_LAST > 0");
                RedisHelper.Add($"D定子2号机械手.D2226_LAST", "0", out string msg);
                string V = 1 == 0 ? "D2210" : "D2215";
                Conn.默认Redis.SetValue(VERX.deviceName + "." + V, "0", VERX.deviceName + "Queue");
            }
        }
    }
    public class HttpServer
    {
        System.Net.HttpListener HttpSvcHost = null;