1
czw
2025-07-08 9ca7e0307c853871aa984c25eacee18eee01e02d
2025Äê6ÔÂ12ÈÕ/AuxAllWCS/Build/Project/´úÂë/VS×Ô¶¨ÒåÀà/AutoThread.cs
@@ -25,6 +25,8 @@
using System.Net.WebSockets;
using System.Net;
using System.Threading;
using System.IO;
using GZ.Device.Agv;
namespace GZ.Projects.AuxAllWCS
{
@@ -254,6 +256,8 @@
            if (VERX != null)
            {
                if (tag.wxr1.R44)
                    LogHelper.Info($"{VERX.deviceName} R44>{tag.wxr1.R44} R44LAST>{tag.wxr1.R44_LAST} R10>{tag.wxr1.R10}");
                if (tag.wxr1.R44 && !tag.wxr1.R44_LAST && tag.wxr1.R10)
                {
                    if (TcpServer.TrayIps.TryGetValue(VERX.deviceNo[0], out string traycode) && !string.IsNullOrEmpty(traycode.Trim()))
@@ -292,16 +296,21 @@
                        if (TcpServer.TrayIps.TryGetValue(VERX.deviceNo[0], out string traycode) && !string.IsNullOrEmpty(traycode.Trim()))
                        {
                            //上报校验。
                            LogHelper.Info($"{VERX.deviceNo[0]} ä¸ŠæŠ¥æ ¡éªŒ>{traycode}");
                            ///var str = Settings.apiHelper.Post(Settings.MESbaseUrl + "mom-basic/dataTransmission/json/service/202", requestJson);
                            var str = Settings.apiHelper.Post(Settings.WMSbaseUrl + "mom-basic/dataTransmission/json/service/202", JsonConvert.SerializeObject(new
                            {
                                sceneType = 1,
                                cntrCode = traycode,
                            }));
                            if (str.Contains("true"))
                            var strr = JsonConvert.DeserializeObject<Mesrespone>(str);
                            if (strr != null && strr.success)
                            //if (str.Contains("true"))
                            {
                                //Conn.默认Redis.SetValue("维希尔抓臂1.R10", "true", "维希尔抓臂1Queue");
                                tag.wxr1.R10 = true;
                                //tag.wxr1.R10 = true;
                                Conn.默认Redis.SetValue(VERX.deviceName + ".R10", "true", VERX.deviceName + "Queue");
                                //tag.wxr1.R44_LAST = false;
                                RedisHelper.Add($"维希尔抓臂1.R44_LAST", "false", out string msg);
                            }
@@ -311,6 +320,10 @@
                            }
                        }
                        else { TcpServer.TcpServerSend(VERX.deviceNo[0], GZ.Device.PLC.PlcHelper.Hex2Bin("544F4E")); }
                    }
                    else if (!tag.wxr1.R10)
                    {
                        TcpServer.TrayIps.Remove(VERX.deviceNo[0]);
                    }
                }
            }
@@ -327,6 +340,8 @@
            if (VERX != null)
            {
                if (tag.wxr1.R46)
                    LogHelper.Info($"{VERX.deviceName} R44>{tag.wxr1.R46} R44LAST>{tag.wxr1.R46_LAST} R10>{tag.wxr1.R11}");
                if (tag.wxr1.R46 && !tag.wxr1.R46_LAST && tag.wxr1.R11)
                {
                    if (TcpServer.TrayIps.TryGetValue(VERX.deviceNo[1], out string traycode) && !string.IsNullOrEmpty(traycode.Trim()))
@@ -364,16 +379,20 @@
                        if (TcpServer.TrayIps.TryGetValue(VERX.deviceNo[1], out string traycode) && !string.IsNullOrEmpty(traycode.Trim()))
                        {
                            //上报校验。
                            LogHelper.Info($"{VERX.deviceNo[1]} ä¸ŠæŠ¥æ ¡éªŒ>{traycode}");
                            ///var str = Settings.apiHelper.Post(Settings.MESbaseUrl + "mom-basic/dataTransmission/json/service/202", requestJson);
                            var str = Settings.apiHelper.Post(Settings.WMSbaseUrl + "mom-basic/dataTransmission/json/service/202", JsonConvert.SerializeObject(new
                            {
                                sceneType = 1,
                                cntrCode = traycode,
                            }));
                            if (str.Contains("true"))
                            var strr = JsonConvert.DeserializeObject<Mesrespone>(str);
                            if (strr != null && strr.success)
                            //if (str.Contains("true"))
                            {
                                //Conn.默认Redis.SetValue("维希尔抓臂1.R10", "true", "维希尔抓臂1Queue");
                                tag.wxr1.R11 = true;
                                //tag.wxr1.R11 = true;
                                Conn.默认Redis.SetValue(VERX.deviceName + ".R11", "true", VERX.deviceName + "Queue");
                                //tag.wxr1.R46_LAST = false;
                                RedisHelper.Add($"维希尔抓臂1.R46_LAST", "false", out string msg);
                            }
@@ -383,6 +402,10 @@
                            }
                        }
                        else { TcpServer.TcpServerSend(VERX.deviceNo[1], GZ.Device.PLC.PlcHelper.Hex2Bin("544F4E")); }
                    }
                    else if (!tag.wxr1.R11)
                    {
                        TcpServer.TrayIps.Remove(VERX.deviceNo[1]);
                    }
                }
            }
@@ -399,6 +422,8 @@
            if (VERX != null)
            {
                if (tag.wxr2.R44)
                    LogHelper.Info($"{VERX.deviceName} R44>{tag.wxr2.R44} R44LAST>{tag.wxr2.R44_LAST} R10>{tag.wxr2.R10}");
                if (tag.wxr2.R44 && !tag.wxr2.R44_LAST && tag.wxr2.R10)
                {
                    if (TcpServer.TrayIps.TryGetValue(VERX.deviceNo[0], out string traycode) && !string.IsNullOrEmpty(traycode.Trim()))
@@ -436,16 +461,20 @@
                        if (TcpServer.TrayIps.TryGetValue(VERX.deviceNo[0], out string traycode) && !string.IsNullOrEmpty(traycode.Trim()))
                        {
                            //上报校验。
                            LogHelper.Info($"{VERX.deviceNo[0]} ä¸ŠæŠ¥æ ¡éªŒ>{traycode}");
                            ///var str = Settings.apiHelper.Post(Settings.MESbaseUrl + "mom-basic/dataTransmission/json/service/202", requestJson);
                            var str = Settings.apiHelper.Post(Settings.WMSbaseUrl + "mom-basic/dataTransmission/json/service/202", JsonConvert.SerializeObject(new
                            {
                                sceneType = 1,
                                cntrCode = traycode,
                            }));
                            if (str.Contains("true"))
                            var strr = JsonConvert.DeserializeObject<Mesrespone>(str);
                            if (strr != null && strr.success)
                            //if (str.Contains("true"))
                            {
                                //Conn.默认Redis.SetValue("维希尔抓臂1.R10", "true", "维希尔抓臂1Queue");
                                tag.wxr2.R10 = true;
                                //tag.wxr2.R10 = true;
                                Conn.默认Redis.SetValue(VERX.deviceName + ".R10", "true", VERX.deviceName + "Queue");
                                //tag.wxr2.R44_LAST = false;
                                RedisHelper.Add($"维希尔抓臂2.R44_LAST", "false", out string msg);
                            }
@@ -455,6 +484,10 @@
                            }
                        }
                        else { TcpServer.TcpServerSend(VERX.deviceNo[0], GZ.Device.PLC.PlcHelper.Hex2Bin("544F4E")); }
                    }
                    else if (!tag.wxr2.R10)
                    {
                        TcpServer.TrayIps.Remove(VERX.deviceNo[0]);
                    }
                }
            }
@@ -472,6 +505,8 @@
            if (VERX != null)
            {
                if (tag.wxr2.R46)
                    LogHelper.Info($"{VERX.deviceName} R44>{tag.wxr2.R46} R44LAST>{tag.wxr2.R46_LAST} R10>{tag.wxr2.R11}");
                if (tag.wxr2.R46 && !tag.wxr2.R46_LAST && tag.wxr2.R11)
                {
                    if (TcpServer.TrayIps.TryGetValue(VERX.deviceNo[1], out string traycode) && !string.IsNullOrEmpty(traycode.Trim()))
@@ -510,7 +545,7 @@
                        else
                        if (TcpServer.TrayIps.TryGetValue(VERX.deviceNo[1], out string traycode) && !string.IsNullOrEmpty(traycode.Trim()))
                        {
                            LogHelper.Info($"Threadwxr2R ä¸ŠæŠ¥æ ¡éªŒ>{traycode}");
                            LogHelper.Info($"{VERX.deviceNo[1]} ä¸ŠæŠ¥æ ¡éªŒ>{traycode}");
                            //上报校验。
                            ///var str = Settings.apiHelper.Post(Settings.MESbaseUrl + "mom-basic/dataTransmission/json/service/202", requestJson);
                            var str = Settings.apiHelper.Post(Settings.WMSbaseUrl + "mom-basic/dataTransmission/json/service/202", JsonConvert.SerializeObject(new
@@ -518,12 +553,17 @@
                                sceneType = 1,
                                cntrCode = traycode,
                            }));
                            if (str.Contains("true"))
                            var strr = JsonConvert.DeserializeObject<Mesrespone>(str);
                            if (strr != null && strr.success)
                            {
                                //Conn.默认Redis.SetValue("维希尔抓臂1.R10", "true", "维希尔抓臂1Queue");
                                tag.wxr2.R11 = true;
                                //Conn.默认Redis.SetValue("维希尔抓臂1.R11", "true", "维希尔抓臂1Queue");
                                //tag.wxr2.R11 = true;
                                LogHelper.Info($"Threadwxr2R。。  -写R11 true");
                                Conn.默认Redis.SetValue(VERX.deviceName + ".R11", "true", VERX.deviceName + "Queue");
                                //tag.wxr2.R46_LAST = false;
                                RedisHelper.Add($"维希尔抓臂2.R46_LAST", "false", out string msg);
                                LogHelper.Info($"Threadwxr2R。。 æ ¡éªŒä¸‹æ–™å®Œæˆã€‚");
                            }
                            else
                            {
@@ -535,6 +575,10 @@
                            LogHelper.Info($"Threadwxr2R。。  -发送扫码");
                            TcpServer.TcpServerSend(VERX.deviceNo[1], GZ.Device.PLC.PlcHelper.Hex2Bin("544F4E"));
                        }
                    }
                    else if (!tag.wxr2.R11)
                    {
                        TcpServer.TrayIps.Remove(VERX.deviceNo[1]);
                    }
                }
            }
@@ -604,11 +648,18 @@
                }
                if (tag.RGV.taskend == 125)
                {
                    LogHelper.Info($"RGV æœ‰125命令未执行。");
                    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");
                        Conn.默认Redis.SetValue("RGV.taskend", "0", "RGVQueue", false);
                    }
                    System.Threading.Thread.Sleep(3000);
                    return;
                }
                LogHelper.Info($"任务下发 Rgv ä»»åŠ¡ è¿›å…¥ Rgv信息 W1状态{tag.RGV.w1status} ReadTask1No>{tag.RGV.ReadTask1No} bit1taskOver>{tag.RGV.bit1taskOver} W2状态{tag.RGV.w2status} ReadTask2No>{tag.RGV.ReadTask2No} bit2taskOver>{tag.RGV.bit2taskOver}");
                LogHelper.Info($"任务下发 Rgv ä»»åŠ¡ è¿›å…¥ Rgv信息 W1状态{tag.RGV.w1status} ReadTask1No>{tag.RGV.ReadTask1No} 1工位条码:{tag.RGV.bit1Code} bit1taskOver>{tag.RGV.bit1taskOver} W2状态{tag.RGV.w2status} ReadTask2No>{tag.RGV.ReadTask2No} 2工位条码:{tag.RGV.bit2Code} bit2taskOver>{tag.RGV.bit2taskOver}");
                TaskEntity task1 = null;
                TaskEntity task2 = null;
                var task1Isrun = false;
@@ -670,7 +721,7 @@
                                task1.S_B_STATE = "取货完成";
                            }
                            //tag.RGV.bit1taskOver = 0;
                            LogHelper.Info($"RGV 1工位任务{task1.S_TASK_NO} çŠ¶æ€åˆ‡æ¢ä¸º{task1.S_B_STATE}");
                            LogHelper.Info($"RGV 1工位任务{task1.S_TASK_NO} æ¡ç ï¼š{tag.RGV.bit1Code} çŠ¶æ€åˆ‡æ¢ä¸º{task1.S_B_STATE}");
                            //tag.RGV.bit1taskOver_LAST = 1;
                            RedisHelper.Add($"RGV.bit1taskOver_LAST", "1", out string msg);
                            LogHelper.Info($"RGV 1工位任务写处理");
@@ -712,7 +763,7 @@
                                task2.S_B_STATE = "取货完成";
                            }
                            //tag.RGV.bit2taskOver = 0;
                            LogHelper.Info($"RGV 2工位任务{task2.S_TASK_NO} çŠ¶æ€åˆ‡æ¢ä¸º{task2.S_B_STATE}");
                            LogHelper.Info($"RGV 2工位任务{task2.S_TASK_NO} æ¡ç ï¼š{tag.RGV.bit2Code} çŠ¶æ€åˆ‡æ¢ä¸º{task2.S_B_STATE}");
                            RedisHelper.Add($"RGV.bit2taskOver_LAST", "1", out string msg);
                            LogHelper.Info($"RGV 2工位任务写处理");
                            taskservice.Update(task2);
@@ -850,7 +901,7 @@
                            if (tag.RGV.bit1taskOver == 1)
                                tag.RGV.bit1taskOver = 0;
                            LogHelper.Info($"{task1.S_TASK_NO}> taskend å†™ 0");
                            LogHelper.Info($"{task1.S_TASK_NO}> taskend å†™ 125");
                            Conn.默认Redis.SetValue("RGV.taskend", "125", "RGVQueue", false);
                            LogHelper.Info($"{task1.S_TASK_NO}> bit1taskOver_LAST å†™ 0");
                            RedisHelper.Add($"RGV.bit1taskOver_LAST", "0", out string msg);
@@ -953,7 +1004,18 @@
            var taskCOdes = new List<string> { "Sarrive", "Srelease", "Earrive", "Erelease" };
            TaskActRepository taskActRepository = new TaskActRepository();
            TaskRepository taskRepository = new TaskRepository();
            var requires = taskActRepository.FindList(x => taskCOdes.Contains(x.S_ACTION_CODE) && x.N_CREATEMETHOD == 0).OrderBy(x => x.T_CREATE);
            var requires = taskActRepository.FindList(x => taskCOdes.Contains(x.S_ACTION_CODE) && x.N_CREATEMETHOD == 0).OrderBy(x => x.T_CREATE).ToList();
            var timeMorhours = requires.FindAll(x => DateTime.Now.Subtract(x.T_CREATE).TotalHours > 1);
            if (timeMorhours.Any())
            {
                foreach (var mor in timeMorhours)
                {
                    mor.N_CREATEMETHOD = 2;
                    mor.S_REVIEW_COMMENT = "超时不处理";
                    taskActRepository.Update(mor);
                }
                requires = requires.Except(timeMorhours).ToList();
            }
            foreach (var item in requires)
            {
                LogHelper.Info($"ThreadGrats {item.S_TASK_NO} >{item.S_ACTION_CODE}光栅处理 =================> ");
@@ -961,6 +1023,7 @@
                if (tin == -1)
                {
                    item.N_CREATEMETHOD = -1;
                    item.S_REVIEW_COMMENT = $"信号未知{item.S_ACTION_CODE}不处理";
                    taskActRepository.Update(item);
                    continue;
                }
@@ -968,6 +1031,7 @@
                if (task == null)
                {
                    item.N_CREATEMETHOD = -1;
                    item.S_REVIEW_COMMENT = $"任务丢失不处理";
                    taskActRepository.Update(item);
                    continue;
                }
@@ -1008,6 +1072,7 @@
                        LogHelper.Info($"ThreadGrats {item.S_TASK_NO} >{item.S_ACTION_CODE} è®¾å¤‡æ˜¯{dev.deviceName} å¼€å¯å…‰æ …处理完成 =================> ");
                        item.N_CREATEMETHOD = 1;
                        item.S_REVIEW_COMMENT = $"光栅开启完成";
                        taskActRepository.Update(item);
                    }
                    //车要进入交互。
@@ -1065,6 +1130,7 @@
                        taskCode = item.S_TASK_NO
                    });
                    item.N_CREATEMETHOD = 1;
                    item.S_REVIEW_COMMENT = $"车子继续任务OK";
                    taskActRepository.Update(item);
                }
            }
@@ -1128,7 +1194,7 @@
                        var listtep = new List<string>();
                        if (Bssx == "1020")
                        {
                            if (tag.SF下料位.RArrive1003 == 1)
                            if (!string.IsNullOrEmpty(tag.SFT下料口托盘.R1003Barcode) && string.IsNullOrEmpty(tag.SFT下料口托盘.R1011Barcode))
                            {
                                listtep = new List<string> { "1012", "1004" };
                            }
@@ -1139,7 +1205,8 @@
                        }
                        else
                        {
                            if (tag.SF下料位.RArrive1005 == 1)
                            //if (tag.SF下料位.RArrive1005 == 1)
                            if (!string.IsNullOrEmpty(tag.SFT下料口托盘.R1005Barcode) && string.IsNullOrEmpty(tag.SFT下料口托盘.R1013Barcode))
                            {
                                listtep = new List<string> { "1014", "1006" };
                            }
@@ -1575,7 +1642,7 @@
        }
        public void ResolveMesTask()
        public void ResolveMesTask(Tag tag)
        {
            TaskRepository taskservice = new TaskRepository();
            var tasks = taskservice.FindList(x => (x.S_B_STATE == "MES" || x.S_B_STATE == "People") && x.N_PRIORITY == -88);
@@ -1584,23 +1651,90 @@
            foreach (var task in tasks)
            {
                LogHelper.Info($"解释MES任务 ->{task.S_TASK_NO} ");
                if (task.S_TYPE?.Trim() == "100")
                {
                    LogHelper.Info($"MES任务 S_TYPE 100->{task.S_TYPE} ");
                }
                var sx = VERXs?.Find(x => x.location.Contains(task.S_END_LOC));
                LogHelper.Info($"解释MES任务 ->{task.S_TASK_NO} {(sx == null ? "非" : "是")}总装机器人任务");
                if (sx == null)
                {
                    LogHelper.Info($"解释MES任务 ->{task.S_TASK_NO} ç›´æŽ¥ç”Ÿæˆå¯¹åº”任务");
                    //直接生成对应任务。
                    var res = TaskProcess.CreateTask(task.S_TASK_NO, task.S_START_LOC, task.S_END_LOC, task.S_TYPE, 6, task.S_CNTRS?.Split(',').ToList() ?? new List<string>());
                    LogHelper.Info($"解释MES任务 ->{task.S_TASK_NO} ç›´æŽ¥ç”Ÿæˆå¯¹åº”任务 ç»“果:{res}");
                    if (res)
                    if (string.IsNullOrEmpty(task.S_CNTRS) && !string.IsNullOrEmpty(task.S_INDEX))
                    {
                        LogHelper.Info($"解释MES任务 ->{task.S_TASK_NO} ä¿®æ”¹æ ‡è¯†");
                        //task.N_PRIORITY = 0;
                        taskservice.dbcontext.Set<TaskEntity>().Attach(task);
                        taskservice.dbcontext.Entry(task).Property(x => x.N_PRIORITY).CurrentValue = 0;
                        taskservice.dbcontext.Entry(task).Property(x => x.N_PRIORITY).IsModified = true;
                        taskservice.dbcontext.SaveChanges();
                        // å«æ–™ä»»åŠ¡ã€‚ æŒ‡å®šç‰©æ–™ä¸æŒ‡å®šæ‰˜ç›˜ï¼Œéœ€è¦å‡ºåº“
                        switch (task.S_START_LOC)
                        {
                            case "2030":
                                if (!string.IsNullOrEmpty(tag.SA2030.R托盘码))
                                {
                                    var str = Settings.apiHelper.Post(Settings.MESbaseUrl + "mom-basic/dataTransmission/json/service/224", JsonConvert.SerializeObject(new
                                    {
                                        cntrCode = tag.SA2030.R托盘码,
                                        type = 1
                                    }));
                                    var strr = JsonConvert.DeserializeObject<MES2234>(str);
                                    if (strr.success && strr.data.materialCode == task.S_INDEX)
                                    {
                                        task.S_CNTRS = tag.SA2030.R托盘码;
                                        taskservice.Update(task);
                                    }
                                    else
                                    {
                                        LogHelper.Info($"解释MES任务 ->{task.S_TASK_NO} 2030 å‡ºå£çš„æ‰˜ç›˜ç‰©æ–™ä¸ç¬¦åˆ");
                                    }
                                }
                                else
                                {
                                    //TODO------------------2027  2220   2013.. è¯†åˆ«ä¸€ä¸‹ï¼Œå¼€å§‹åº“
                                }
                                break;
                            case "1019":
                                if (!string.IsNullOrEmpty(tag.SA1019.R托盘码))
                                {
                                    var str = Settings.apiHelper.Post(Settings.MESbaseUrl + "mom-basic/dataTransmission/json/service/224", JsonConvert.SerializeObject(new
                                    {
                                        cntrCode = tag.SA1019.R托盘码,
                                        type = 2
                                    }));
                                    var strr = JsonConvert.DeserializeObject<MES2234>(str);
                                    if (strr.success && strr.data.materialCode == task.S_INDEX)
                                    {
                                        task.S_CNTRS = tag.SA2030.R托盘码;
                                        taskservice.Update(task);
                                    }
                                    else
                                    {
                                        LogHelper.Info($"解释MES任务 ->{task.S_TASK_NO} 1019 å‡ºå£çš„æ‰˜ç›˜ç‰©æ–™ä¸ç¬¦åˆ");
                                    }
                                }
                                break;
                        }
                    }
                    else
                    {
                        if (new List<string> { "2001", "1022", "1025", "3001", "3006" }.Contains(task.S_END_LOC))
                        {
                            //------------------
                        }
                        else if (new List<string> { "1019"/*, "1030"*/, "2030", "3005", "3010" }.Contains(task.S_START_LOC))  //1030 æ˜¯ä¸»åŠ¨ç”³è¯·ï¼Œ ä¸ç”¨åˆ¤æ–­ã€‚
                        {
                        }
                        LogHelper.Info($"解释MES任务 ->{task.S_TASK_NO} ç›´æŽ¥ç”Ÿæˆå¯¹åº”任务");
                        //直接生成对应任务。
                        var res = TaskProcess.CreateTask(task.S_TASK_NO, task.S_START_LOC, task.S_END_LOC, task.S_TYPE, 6, task.S_CNTRS?.Split(',').ToList() ?? new List<string>());
                        LogHelper.Info($"解释MES任务 ->{task.S_TASK_NO} ç›´æŽ¥ç”Ÿæˆå¯¹åº”任务 ç»“果:{res}");
                        if (res)
                        {
                            LogHelper.Info($"解释MES任务 ->{task.S_TASK_NO} ä¿®æ”¹æ ‡è¯†");
                            //task.N_PRIORITY = 0;
                            taskservice.dbcontext.Set<TaskEntity>().Attach(task);
                            taskservice.dbcontext.Entry(task).Property(x => x.N_PRIORITY).CurrentValue = 0;
                            taskservice.dbcontext.Entry(task).Property(x => x.N_PRIORITY).IsModified = true;
                            taskservice.dbcontext.SaveChanges();
                        }
                    }
                }
                else
@@ -2008,7 +2142,7 @@
                if (ip.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
                {
                    Console.WriteLine($"ip= {ip.ToString()}");
                    new HttpServer(ip.ToString()).HttpServerRun();
                    new TcpServer(ip.ToString());
                    var server = new EnhancedWebSocketServer($"http://{ip.ToString()}:8809/").StartAsync();
                    //var client = new WebSocketClient($"http://{ip.ToString()}:8809/").ConnectAsync();
@@ -2026,12 +2160,168 @@
    }
    public class HttpServer
    {
        System.Net.HttpListener HttpSvcHost = null;
        public static string _listenerPrefix = "";
        public HttpServer(string ip)
        {
            _listenerPrefix = $"http://{ip}:8808/";
        }
        public void HttpServerRun()
        {
            HttpSvcHost = new System.Net.HttpListener();
            HttpSvcHost.AuthenticationSchemes = System.Net.AuthenticationSchemes.Anonymous;
            HttpSvcHost.Prefixes.Add(_listenerPrefix);
            HttpSvcHost.Start();
            HttpSvcHost.BeginGetContext(HttpSvcListenerCallback, null);
        }
        private async void HttpSvcListenerCallback(IAsyncResult ar)
        {
            System.Net.HttpListenerContext context = null;
            var data = DateTime.Now;
            string apth = "";
            try
            {
                HttpSvcHost.BeginGetContext(HttpSvcListenerCallback, null);
                context = HttpSvcHost.EndGetContext(ar);
                System.Net.HttpListenerRequest request = context.Request;
                System.Net.HttpListenerResponse response = context.Response;
                using (var reader = new System.IO.StreamReader(request.InputStream, System.Text.Encoding.UTF8))
                {
                    string requestJson = reader.ReadToEnd();
                    System.Net.HttpStatusCode statusCode = 0;
                    apth = request.Url.AbsolutePath;
                    string respstr = HttpSvcListenerCallback_he(request.HttpMethod, request.Url.AbsolutePath, requestJson, out statusCode);
                    string logContent = "";
                    logContent += $"\r\n[{request.HttpMethod}]{request.Url.AbsolutePath}";
                    logContent += $"\r\n[request]{requestJson}";
                    logContent += $"\r\n[response]{respstr}";
                    _ = Task.Run(() =>
                    {
                        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);
                    if (request.Url.AbsolutePath.ToLower().Contains(".js"))
                        response.ContentType = "application/javascript";
                    else if (request.Url.AbsolutePath.ToLower().Contains(".svg"))
                        response.ContentType = "image/svg+xml";
                    // å¼‚步写入响应
                    await response.OutputStream.WriteAsync(bytstr, 0, bytstr.Length);
                }
            }
            catch (Exception ex)
            {
                _ = Task.Run(() =>
                {
                    Conn.默认日志.Error(ex.ToString());
                });
            }
            finally
            {
                context?.Response.Close();
                Console.WriteLine(apth + "<<>>" + DateTime.Now.Subtract(data).TotalMilliseconds);
            }
        }
        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);
                                        AutoThread.Instance.OperateHKTaskStatus(model);
                                        return JsonConvert.SerializeObject(new HkReturnResult { reqCode = model.reqCode });
                                    }
                                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;
                                        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;
                                        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 var _ when System.Text.RegularExpressions.Regex.IsMatch(path, @"\.(html|ico|js|css)(\?.*)?$", System.Text.RegularExpressions.RegexOptions.IgnoreCase):
                                    {
                                        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 = /*Directory.GetCurrentDirectory() + "\\Static" + "\\" + path.Substring(1);*/System.IO.Path.Combine(Directory.GetCurrentDirectory() + "\\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 "";
            }
        }
    }
    class EnhancedWebSocketServer
@@ -2170,8 +2460,6 @@
    }
    internal class WebSocketClient
    {
        private ClientWebSocket _webSocket = new ClientWebSocket();
@@ -2256,6 +2544,24 @@
        public Ddata data { get; set; }
        public object extra { get; set; }
    }
    class Mesrespone
    {
        public bool success { get; set; }
        public string msg { get; set; }
        public object extra { get; set; }
    }
    class MES2234
    {
        public bool success { get; set; }
        public ML data { get; set; }
    }
    public class ML
    {
        public string materialCode { get; set; }
        public int lineNum { get; set; }
    }
    public class Ddata
    {