From 43c6d046302ca075c1f42b0105a5fbad0d889fc5 Mon Sep 17 00:00:00 2001 From: czw <selecti@yeah.net> Date: 星期四, 10 七月 2025 17:52:25 +0800 Subject: [PATCH] 1 --- 2025年6月12日/AuxAllWCS/Build/Project/代码/VS自定义类/AutoThread.cs | 1389 +++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 files changed, 1,293 insertions(+), 96 deletions(-) diff --git "a/2025\345\271\2646\346\234\21012\346\227\245/AuxAllWCS/Build/Project/\344\273\243\347\240\201/VS\350\207\252\345\256\232\344\271\211\347\261\273/AutoThread.cs" "b/2025\345\271\2646\346\234\21012\346\227\245/AuxAllWCS/Build/Project/\344\273\243\347\240\201/VS\350\207\252\345\256\232\344\271\211\347\261\273/AutoThread.cs" index 394ca23..8b6e9c2 100644 --- "a/2025\345\271\2646\346\234\21012\346\227\245/AuxAllWCS/Build/Project/\344\273\243\347\240\201/VS\350\207\252\345\256\232\344\271\211\347\261\273/AutoThread.cs" +++ "b/2025\345\271\2646\346\234\21012\346\227\245/AuxAllWCS/Build/Project/\344\273\243\347\240\201/VS\350\207\252\345\256\232\344\271\211\347\261\273/AutoThread.cs" @@ -26,6 +26,10 @@ using System.Net; using System.Threading; using System.IO; +using GZ.Device.Agv; +using System.Net.NetworkInformation; +using System.Windows.Documents; +using System.Text.RegularExpressions; namespace GZ.Projects.AuxAllWCS { @@ -125,6 +129,137 @@ } } + + public void ThreaTotal(Tag tag, Device device) + { + List<Task> tasks = new List<Task>(); + tasks.Add(GetTask(delegate (Tag tag1, Device device1) + { + try + { + foreach (var ip in new List<string> { + device1.p鍙戦偅绉�涓嬬嚎.Config.IP, + device1.p鍙戦偅绉�涓嬬嚎.Config.IP, + device1.D瀹氬瓙1鍙锋満姊版墜.Config.IP, + device1.D瀹氬瓙2鍙锋満姊版墜.Config.IP, + device1.Js鎹烽『1.Config.IP, + device1.Js鎹烽『2.Config.IP, + device1.缁村笇灏旀姄鑷�.Config.IP, + device1.缁村笇灏旀姄鑷�.Config.IP, + device1.RGV.Config.IP, + device1.S1002Read.Config.IP, + device1.S2001Read.Config.IP, + device1.S3001Read.Config.IP + }) + { + string pattern = @"\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b"; + + var matches = Regex.Match(ip, pattern); + if (matches.Success) + { + var b = IsMachineOnline(matches.Value); + if (!Iponlines.ContainsKey(ip)) + { + Iponlines.TryAdd(ip, b); + } + else + Iponlines[ip] = b; + } + } + } + catch (Exception ex) + { + LogHelper.Error(ex.Message, ex); + } + + }, tag, device, 3000)); + tasks.Add(GetTask(ThreadMXC3, tag, 3000)); + tasks.Add(GetTask(ThreadMXC4, tag, 3000)); + tasks.Add(GetTask(ResetGats, tag, 3000)); + + tasks.Add(GetTask(sa1022, tag, 3000)); + tasks.Add(GetTask(sa1025, tag, 3000)); + tasks.Add(GetTask(sa1030, tag, 3000)); + tasks.Add(GetTask(sa2001, tag, 3000)); + tasks.Add(GetTask(sa2030, tag, 3000)); + tasks.Add(GetTask(sa2008, tag, 3000)); + tasks.Add(GetTask(sa3001, tag, 3000)); + tasks.Add(GetTask(sa3005, tag, 3000)); + tasks.Add(GetTask(sa3006, tag, 3000)); + tasks.Add(GetTask(sa3010, tag, 3000)); + + Task.WaitAll(tasks.ToArray()); + } + + public static ConcurrentDictionary<string, bool> Iponlines = new ConcurrentDictionary<string, bool>(); + public bool IsMachineOnline(string hostNameOrIp, int timeout = 1000) + { + //device.p鍙戦偅绉�涓嬬嚎.Config.IP + LogHelper.Info("妫�祴ip:>" + hostNameOrIp, "IP鍦ㄧ嚎妫�祴"); + bool res = false; + try + { + using (var ping = new Ping()) + { + var reply = ping.Send(hostNameOrIp, timeout); + res = reply.Status == IPStatus.Success; + } + } + catch (PingException) + { + res = false; + } + catch (Exception) + { + // 鍏朵粬寮傚父澶勭悊 + res = false; + } + finally + { + LogHelper.Info("妫�祴ip:>" + hostNameOrIp + " 缁撴灉锛� + (res ? "閫� : "涓嶉�"), "IP鍦ㄧ嚎妫�祴"); + } + return res; + } + + 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; + } + + private Task GetTask(Action<Tag, Device> action, Tag tag, Device dev, int i = 2500) + { + var task = Task.Run(() => + { + while (true) + { + try + { + action(tag, dev); + } + catch (Exception ex) + { + LogHelper.Error(ex.Message, ex); + } + Thread.Sleep(i); + } + }); + return task; + } public string WriteLine(string value = "") { @@ -166,6 +301,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) @@ -187,6 +323,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"); } } } @@ -303,10 +440,13 @@ 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("缁村笇灏旀姄鑷�.R10", "true", "缁村笇灏旀姄鑷�Queue"); - 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($"缁村笇灏旀姄鑷�.R44_LAST", "false", out string msg); } @@ -316,6 +456,10 @@ } } else { TcpServer.TcpServerSend(VERX.deviceNo[0], GZ.Device.PLC.PlcHelper.Hex2Bin("544F4E")); } + } + else if (!tag.wxr1.R10) + { + TcpServer.TrayIps.Remove(VERX.deviceNo[0]); } } } @@ -333,7 +477,7 @@ if (VERX != null) { if (tag.wxr1.R46) - LogHelper.Info($"{VERX.deviceName} R44>{tag.wxr1.R46} R44LAST>{tag.wxr1.R46_LAST} R10>{tag.wxr1.R11}"); + LogHelper.Info($"{VERX.deviceName} R46>{tag.wxr1.R46} R46LAST>{tag.wxr1.R46_LAST} R11>{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())) @@ -378,10 +522,13 @@ 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("缁村笇灏旀姄鑷�.R10", "true", "缁村笇灏旀姄鑷�Queue"); - 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($"缁村笇灏旀姄鑷�.R46_LAST", "false", out string msg); } @@ -391,6 +538,10 @@ } } else { TcpServer.TcpServerSend(VERX.deviceNo[1], GZ.Device.PLC.PlcHelper.Hex2Bin("544F4E")); } + } + else if (!tag.wxr1.R11) + { + TcpServer.TrayIps.Remove(VERX.deviceNo[1]); } } } @@ -453,10 +604,13 @@ 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("缁村笇灏旀姄鑷�.R10", "true", "缁村笇灏旀姄鑷�Queue"); - 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($"缁村笇灏旀姄鑷�.R44_LAST", "false", out string msg); } @@ -466,6 +620,10 @@ } } else { TcpServer.TcpServerSend(VERX.deviceNo[0], GZ.Device.PLC.PlcHelper.Hex2Bin("544F4E")); } + } + else if (!tag.wxr2.R10) + { + TcpServer.TrayIps.Remove(VERX.deviceNo[0]); } } } @@ -484,7 +642,7 @@ if (VERX != null) { if (tag.wxr2.R46) - LogHelper.Info($"{VERX.deviceName} R44>{tag.wxr2.R46} R44LAST>{tag.wxr2.R46_LAST} R10>{tag.wxr2.R11}"); + LogHelper.Info($"{VERX.deviceName} R46>{tag.wxr2.R46} R46LAST>{tag.wxr2.R46_LAST} R11>{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())) @@ -506,7 +664,7 @@ } else { - TcpServer.TcpServerSend(VERX.deviceNo[2], GZ.Device.PLC.PlcHelper.Hex2Bin("544F4E")); + TcpServer.TcpServerSend(VERX.deviceNo[1], GZ.Device.PLC.PlcHelper.Hex2Bin("544F4E")); } } else @@ -531,12 +689,17 @@ sceneType = 1, cntrCode = traycode, })); - if (str.Contains("true")) + var strr = JsonConvert.DeserializeObject<Mesrespone>(str); + if (strr != null && strr.success) { - //Conn.榛樿Redis.SetValue("缁村笇灏旀姄鑷�.R10", "true", "缁村笇灏旀姄鑷�Queue"); - tag.wxr2.R11 = true; + //Conn.榛樿Redis.SetValue("缁村笇灏旀姄鑷�.R11", "true", "缁村笇灏旀姄鑷�Queue"); + //tag.wxr2.R11 = true; + + LogHelper.Info($"Threadwxr2R銆傘� -鍐橰11 true"); + Conn.榛樿Redis.SetValue(VERX.deviceName + ".R11", "true", VERX.deviceName + "Queue"); //tag.wxr2.R46_LAST = false; RedisHelper.Add($"缁村笇灏旀姄鑷�.R46_LAST", "false", out string msg); + LogHelper.Info($"Threadwxr2R銆傘� 鏍¢獙涓嬫枡瀹屾垚銆�); } else { @@ -548,6 +711,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]); } } } @@ -617,11 +784,18 @@ } if (tag.RGV.taskend == 125) { - LogHelper.Info($"RGV 鏈�25鍛戒护鏈墽琛屻�"); + LogHelper.Info($"RGV 鏈�25鍛戒护鏈墽琛屻� "); + 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; @@ -683,7 +857,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宸ヤ綅浠诲姟鍐欏鐞�); @@ -725,7 +899,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); @@ -751,9 +925,22 @@ // var b = RedisHelper.Remove("RGVQueue", out rev); // } //} + var tklistall = taskservice.FindList(x => x.S_B_STATE != "瀹屾垚" && x.S_B_STATE != "鍙栨秷" && x.S_WORK_MODE == "RGV").OrderBy(x => x.T_CREATE).ToList(); + var tklist = tklistall.FindAll(x => x.S_B_STATE == "鏈墽琛�); + var tkunNormal = tklistall.Except(tklist); + if (tkunNormal.Any()) + foreach (var tk in tkunNormal) + { + if (tk.S_TASK_NO != task1?.S_TASK_NO && tk.S_TASK_NO != task2?.S_TASK_NO) + { + tk.S_B_STATE = "鍙栨秷"; + tk.S_NOTE = "涓嶅湪鎵ц闃熷垪涓�鍙栨秷"; + taskservice.Update(tk); + } + } ///1 鏈夎揣 灏� 鍙栥� 1 娌¤揣 灏� 鍗歌揣锛�閮芥湁璐� 灏�鍗歌揣銆�閮芥病璐�灏�鍗�- var tklist = taskservice.FindList(x => x.S_B_STATE == "鏈墽琛� && x.S_WORK_MODE == "RGV").OrderBy(x => x.T_CREATE).ToList(); + // 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 鏈変换鍔°� @@ -863,7 +1050,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); @@ -966,7 +1153,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}鍏夋爡澶勭悊 =================> "); @@ -974,6 +1172,7 @@ if (tin == -1) { item.N_CREATEMETHOD = -1; + item.S_REVIEW_COMMENT = $"淇″彿鏈煡{item.S_ACTION_CODE}涓嶅鐞�; taskActRepository.Update(item); continue; } @@ -981,6 +1180,7 @@ if (task == null) { item.N_CREATEMETHOD = -1; + item.S_REVIEW_COMMENT = $"浠诲姟涓㈠け涓嶅鐞�; taskActRepository.Update(item); continue; } @@ -1004,71 +1204,310 @@ //杞﹁蛋浜� 寮�厜鏍� if (!goin) { - if (dev.deviceType == 1) + if (dev.deviceType == 4) { - LogHelper.Info($"ThreadGrats {item.S_TASK_NO} >{item.S_ACTION_CODE} 璁惧鏄瘂dev.deviceName} 寮�惎鍏夋爡澶勭悊 =================> "); - 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", false); + LogHelper.Info($"杞︾寮�緭閫佺嚎浜や簰> {item.S_TASK_NO} >{item.S_ACTION_CODE} 璁惧鏄瘂dev.deviceName} SSX AGV 浜や簰銆傘�銆�); + switch (loc) + { + case "1019": + { + SetRedistoPlc("A1019鍙栬揣浜や簰.SOver", "true", "A1019鍙栬揣浜や簰Queue", "agv 鍙栬揣瀹屾垚鍐欏畬鎴愪氦浜�); + } + break; + case "1030": + { + SetRedistoPlc("A1030鍙栬揣浜や簰.SOver", "true", "A1030鍙栬揣浜や簰Queue", "agv 鍙栬揣瀹屾垚鍐欏畬鎴愪氦浜�); + } + break; + case "2030": + { + SetRedistoPlc("A2030鍙栬揣浜や簰.SOver", "true", "A2030鍙栬揣浜や簰Queue", "agv 鍙栬揣瀹屾垚鍐欏畬鎴愪氦浜�); + } + break; + case "3005": + { + SetRedistoPlc("A3005鍙栬揣浜や簰.SOver", "true", "A3005鍙栬揣浜や簰Queue", "agv 鍙栬揣瀹屾垚鍐欏畬鎴愪氦浜�); + } + break; + case "3010": + { + SetRedistoPlc("A3010鍙栬揣浜や簰.SOver", "true", "A3010鍙栬揣浜や簰Queue", "agv 鍙栬揣瀹屾垚鍐欏畬鎴愪氦浜�); + } + break; + //} + //switch (loc) + //{ + case "1022": + { + SetRedistoPlc("A1022鏀捐揣浜や簰.SOver", "true", "A1022鏀捐揣浜や簰Queue", "agv 鏀捐揣瀹屾垚鍐欏畬鎴愪氦浜�); + } + break; + case "1025": + { + SetRedistoPlc("A1025鏀捐揣浜や簰.SOver", "true", "A1025鏀捐揣浜や簰Queue", "agv 鏀捐揣瀹屾垚鍐欏畬鎴愪氦浜�); + } + break; + case "2001": + { + SetRedistoPlc("A2001鏀捐揣浜や簰.SOver", "true", "A2001鏀捐揣浜や簰Queue", "agv 鏀捐揣瀹屾垚鍐欏畬鎴愪氦浜�); + tag.SA2001.wTaskNo = 20012007; + tag.SA2001.wEbit = 2007; + tag.SA2001.w鎵樼洏鐮�= TaskProcess.GenerateTaskNo("铏氭嫙鎵樼洏鍙�).Substring(3); + } + break; + case "3001": + { + SetRedistoPlc("A3001鏀捐揣浜や簰.SOver", "true", "A3001鏀捐揣浜や簰Queue", "agv 鏀捐揣瀹屾垚鍐欏畬鎴愪氦浜�); + } + break; + case "3006": + { + SetRedistoPlc("A3006鏀捐揣浜や簰.SOver", "true", "A3006鏀捐揣浜や簰Queue", "agv 鏀捐揣瀹屾垚鍐欏畬鎴愪氦浜�); + } + break; + } } - else if (dev.deviceType == 2) + else { - LogHelper.Info($"ThreadGrats {item.S_TASK_NO} >{item.S_ACTION_CODE} 璁惧鏄瘂dev.deviceName} 寮�惎鍏夋爡澶勭悊 =================> "); - LogHelper.Info($"{dev.deviceName}{(V ? "宸� : "鍙�)} 鍏夋爡{(goin ? "鍏抽棴" : "寮�惎")} 鐢宠銆� + string.Format("{0}{1}{2}", dev.deviceName + "." + (V ? "D1222" : "D1223"), "1", dev.deviceName + "Queue")); + if (dev.deviceType == 1) + { + LogHelper.Info($"ThreadGrats {item.S_TASK_NO} >{item.S_ACTION_CODE} 璁惧鏄瘂dev.deviceName} 寮�惎鍏夋爡澶勭悊 =================> "); + 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", false); + } + else if (dev.deviceType == 2) + { + LogHelper.Info($"ThreadGrats {item.S_TASK_NO} >{item.S_ACTION_CODE} 璁惧鏄瘂dev.deviceName} 寮�惎鍏夋爡澶勭悊 =================> "); + 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 ? "D1220" : "D1221"), "0", dev.deviceName + "Queue"); - Conn.榛樿Redis.SetValue(dev.deviceName + "." + (V ? "D1222" : "D1223"), "1", dev.deviceName + "Queue"); + 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} 寮�惎鍏夋爡澶勭悊瀹屾垚 =================> "); } - LogHelper.Info($"ThreadGrats {item.S_TASK_NO} >{item.S_ACTION_CODE} 璁惧鏄瘂dev.deviceName} 寮�惎鍏夋爡澶勭悊瀹屾垚 =================> "); - item.N_CREATEMETHOD = 1; + item.S_REVIEW_COMMENT = $"鍏夋爡寮�惎瀹屾垚"; taskActRepository.Update(item); } //杞﹁杩涘叆浜や簰銆� 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($"杞﹁姹傝緭閫佺嚎浜や簰> {item.S_TASK_NO} >{item.S_ACTION_CODE} 璁惧鏄瘂dev.deviceName} SSX AGV 浜や簰銆傘�銆�); + //tag.SA1019.Sagverr + switch (loc) { - LogHelper.Info($"{dev.deviceName}{(V ? "宸� : "鍙�)} 鍏夋爡{(goin ? "鍏抽棴" : "寮�惎")} 鐢宠銆�宸茬粡鍏抽棴锛�); - continuuuuu = true; + case "1019": + { + if (tag.SA1019.SreadCan) + { + LogHelper.Info($"1019 璇诲埌杈撻�绾垮厑璁搞�"); + continuuuuu = true; + } + else + { + SetRedistoPlc("A1019鍙栬揣浜や簰.Ssetreq", "true", "A1019鍙栬揣浜や簰Queue", "鍐橝GV鐢宠"); + tag.SA1019.StaskMode = 1; + } + } + break; + case "1030": + { + if (tag.SA1030.SreadCan) + { + LogHelper.Info($"1030 璇诲埌杈撻�绾垮厑璁搞�"); + continuuuuu = true; + } + else + { + SetRedistoPlc("A1030鍙栬揣浜や簰.Ssetreq", "true", "A1030鍙栬揣浜や簰Queue", "鍐橝GV鐢宠"); + tag.SA1030.StaskMode = 1; + } + } + break; + case "2030": + { + if (tag.SA2030.SreadCan) + { + LogHelper.Info($"2030 璇诲埌杈撻�绾垮厑璁搞�"); + continuuuuu = true; + } + else + { + SetRedistoPlc("A2030鍙栬揣浜や簰.Ssetreq", "true", "A2030鍙栬揣浜や簰Queue", "鍐橝GV鐢宠"); + tag.SA2030.StaskMode = 1; + } + } + break; + case "3005": + { + if (tag.ssx杈撻�绾�s3005.SreadCan) + { + LogHelper.Info($"3005 璇诲埌杈撻�绾垮厑璁搞�"); + continuuuuu = true; + } + else + { + SetRedistoPlc("A3005鍙栬揣浜や簰.Ssetreq", "true", "A3005鍙栬揣浜や簰Queue", "鍐橝GV鐢宠"); + tag.ssx杈撻�绾�s3005.StaskMode = 1; + } + } + break; + case "3010": + { + if (tag.ssx杈撻�绾�s3010.SreadCan) + { + LogHelper.Info($"3010 璇诲埌杈撻�绾垮厑璁搞�"); + continuuuuu = true; + } + else + { + SetRedistoPlc("A3010鍙栬揣浜や簰.Ssetreq", "true", "A3010鍙栬揣浜や簰Queue", "鍐橝GV鐢宠"); + tag.ssx杈撻�绾�s3010.StaskMode = 1; + } + } + break; + //} + //switch (loc) + //{ + case "1022": + { + if (tag.SA1022.SreadCan) + { + LogHelper.Info($"1022 璇诲埌杈撻�绾垮厑璁搞�"); + continuuuuu = true; + } + else + { + SetRedistoPlc("A1022鏀捐揣浜や簰.Ssetreq", "true", "A1022鏀捐揣浜や簰Queue", "鍐橝GV鐢宠"); + tag.SA1022.StaskMode = 2; + } + } + break; + case "1025": + { + if (tag.SA1025.SreadCan) + { + LogHelper.Info($"1025 璇诲埌杈撻�绾垮厑璁搞�"); + continuuuuu = true; + } + else + { + SetRedistoPlc("A1025鏀捐揣浜や簰.Ssetreq", "true", "A1025鏀捐揣浜や簰Queue", "鍐橝GV鐢宠"); + tag.SA1025.StaskMode = 2; + } + } + break; + case "2001": + { + if (tag.SA2001.SreadCan) + { + LogHelper.Info($"2001 璇诲埌杈撻�绾垮厑璁搞�"); + continuuuuu = true; + } + else + { + SetRedistoPlc("A2001鏀捐揣浜や簰.Ssetreq", "true", "A2001鏀捐揣浜や簰Queue", "鍐橝GV鐢宠"); + tag.SA2001.StaskMode = 2; + } + } + break; + case "3001": + { + if (tag.ssx杈撻�绾�s3001.SreadCan) + { + LogHelper.Info($"3001 璇诲埌杈撻�绾垮厑璁搞�"); + continuuuuu = true; + } + else + { + SetRedistoPlc("A3001鏀捐揣浜や簰.Ssetreq", "true", "A3001鏀捐揣浜や簰Queue", "鍐橝GV鐢宠"); + tag.ssx杈撻�绾�s3001.StaskMode = 2; + } + } + break; + case "3006": + { + if (tag.ssx杈撻�绾�s3006.SreadCan) + { + LogHelper.Info($"3006 璇诲埌杈撻�绾垮厑璁搞�"); + continuuuuu = true; + } + else + { + SetRedistoPlc("A3006鏀捐揣浜や簰.Ssetreq", "true", "A3006鏀捐揣浜や簰Queue", "鍐橝GV鐢宠"); + tag.ssx杈撻�绾�s3006.StaskMode = 2; + } + } + break; } - 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} 鍏抽棴鍏夋爡澶勭悊瀹屾垚 =================> "); } - 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 == 5) + { + + var close = (System.UInt16)System.Convert.ChangeType(Conn.榛樿Redis.GetValue(dev.deviceName + "." + (V ? "D2220" : "D2225")), typeof(System.UInt16)); + if (close == 0) + { + 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} 杞﹁締鍙戦�缁х画浠诲姟锛�); @@ -1078,10 +1517,14 @@ taskCode = item.S_TASK_NO }); item.N_CREATEMETHOD = 1; + item.S_REVIEW_COMMENT = $"杞﹀瓙缁х画浠诲姟OK"; taskActRepository.Update(item); } } 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)) @@ -1111,6 +1554,33 @@ } } LogHelper.Info($"ThreadGrats deviceType2鍏夋爡鍐欏叆浣嶉噸缃畬鎴愩� =================> "); + LogHelper.Info($"ThreadGrats deviceType5鍏夋爡鍐欏叆浣嶉噸缃�=================> "); + //閲嶇疆淇″彿 + //foreach (var dev in Settings.deviceInfos.FindAll(x => x.deviceType == 5)) + + { + //涓�嚎鍦板潃锛�0.221.55.181 绔彛锛�000 + //if (IsMachineOnline("10.221.55.181")) + { + if (tag.DZ1.D2211 == 1 && tag.DZ1.D2220 == 1) + //tag.DZ1.D2211 = 0; + Conn.榛樿Redis.SetValue("D瀹氬瓙1鍙锋満姊版墜.D2211", "0", "D瀹氬瓙1鍙锋満姊版墜Queue", false); + if (tag.DZ1.D2216 == 1 && tag.DZ1.D2225 == 1) + //tag.DZ1.D2216 = 0; + Conn.榛樿Redis.SetValue("D瀹氬瓙1鍙锋満姊版墜.D2216", "0", "D瀹氬瓙1鍙锋満姊版墜Queue", false); + } + //浜岀嚎鍦板潃锛�0.221.55.179 绔彛锛�000 + //if (IsMachineOnline("10.221.55.179")) + { + if (tag.DZ2.D2211 == 1 && tag.DZ2.D2220 == 1) + //tag.DZ2.D2211 = 0; + Conn.榛樿Redis.SetValue("D瀹氬瓙2鍙锋満姊版墜.D2211", "0", "D瀹氬瓙2鍙锋満姊版墜Queue", false); + if (tag.DZ2.D2216 == 1 && tag.DZ2.D2225 == 1) + //tag.DZ2.D2216 = 0; + Conn.榛樿Redis.SetValue("D瀹氬瓙2鍙锋満姊版墜.D2216", "0", "D瀹氬瓙2鍙锋満姊版墜Queue", false); + } + } + LogHelper.Info($"ThreadGrats deviceType5鍏夋爡鍐欏叆浣嶉噸缃畬鎴愩� =================> "); } /// <summary> /// 1020 1023绌烘涓嬬嚎 @@ -1141,7 +1611,7 @@ var listtep = new List<string>(); if (Bssx == "1020") { - if (tag.SF涓嬫枡浣�RArrive1003 == 1) + if (!string.IsNullOrEmpty(tag.SFT涓嬫枡鍙f墭鐩�R1003Barcode) && string.IsNullOrEmpty(tag.SFT涓嬫枡鍙f墭鐩�R1011Barcode)) { listtep = new List<string> { "1012", "1004" }; } @@ -1152,7 +1622,8 @@ } else { - if (tag.SF涓嬫枡浣�RArrive1005 == 1) + //if (tag.SF涓嬫枡浣�RArrive1005 == 1) + if (!string.IsNullOrEmpty(tag.SFT涓嬫枡鍙f墭鐩�R1005Barcode) && string.IsNullOrEmpty(tag.SFT涓嬫枡鍙f墭鐩�R1013Barcode)) { listtep = new List<string> { "1014", "1006" }; } @@ -1261,6 +1732,19 @@ { RedisHelper.Add($"S{Bssx}Read.RtaskState_LAST", "1", out msg); RedisHelper.Add($"S{item}Read.R5绌洪棽_LAST", "1", out string msg2); + + LogHelper.Info($"{R鎵樼洏鐮亇 瀹氬瓙鐢熶骇瀹屾垚杩涜椴嶅伐锛侊紒"); + var str = Settings.apiHelper.Post(Settings.MESbaseUrl + "mom-basic/dataTransmission/json/service/223", JsonConvert.SerializeObject(new + { + cntrCode = R鎵樼洏鐮� + type = 1, + lineCode = "1002,1008".Contains(Bssx) ? "T01" : "T02" + })); + //var strr = JsonConvert.DeserializeObject<MES2234>(str); + //if (strr.success && strr.data != null) + //{ + + //} //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; @@ -1318,6 +1802,13 @@ { RedisHelper.Add($"S{Bssx}Read.RtaskState_LAST", "1", out msg); RedisHelper.Add($"S{item}Read.R5绌洪棽_LAST", "1", out string msg1); + LogHelper.Info($"{R鎵樼洏鐮亇 杞瓙鐢熶骇瀹屾垚杩涜椴嶅伐锛侊紒"); + var str = Settings.apiHelper.Post(Settings.MESbaseUrl + "mom-basic/dataTransmission/json/service/223", JsonConvert.SerializeObject(new + { + cntrCode = R鎵樼洏鐮� + type = 2, + lineCode = "1002,1008".Contains(Bssx) ? "T01" : "T02" + })); //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; @@ -1340,6 +1831,7 @@ public void Thread涓嬫枡浣嶆娴�Tag tag) { Console.WriteLine($"Thread涓嬫枡浣嶆娴� =====>"); + var lsi = new List<string>(); 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)); @@ -1441,7 +1933,7 @@ if (tag.FNK1.D2217 == 1 && tag.FNK1.D2217_LAST == 0) { //tag.FNK1.D2215 = 0; - tag.FNK1.D2218 = 1; + //tag.FNK1.D2218 = 1; //tag.FNK1.D2212_LAST = 1; RedisHelper.Add($"p鍙戦偅绉�涓嬬嚎.D2217_LAST", "1", out string msg); @@ -1468,7 +1960,7 @@ LogHelper.Info($" FN1 D2212>{tag.FNK1.D2212} D2212LAST>{tag.FNK1.D2212_LAST} D2210>{tag.FNK1.D2210} D2211>{tag.FNK1.D2211} D2213>{tag.FNK1.D2213}"); if (tag.FNK1.D2212 == 1 && tag.FNK1.D2212_LAST == 0) { - tag.FNK1.D2213 = 1; + //tag.FNK1.D2213 = 1; //tag.FNK1.D2210 = 0; //tag.FNK1.D2217_LAST = 1; RedisHelper.Add($"p鍙戦偅绉�涓嬬嚎.D2212_LAST", "1", out string msg); @@ -1503,7 +1995,7 @@ if (tag.FNK2.D2217 == 1 && tag.FNK2.D2217_LAST == 0) { //tag.FNK2.D2215 = 0; - tag.FNK2.D2218 = 1; + //tag.FNK2.D2218 = 1; //tag.FNK2.D2212_LAST = 1; RedisHelper.Add($"p鍙戦偅绉�涓嬬嚎.D2217_LAST", "1", out string msg); @@ -1532,7 +2024,7 @@ if (tag.FNK2.D2212 == 1 && tag.FNK2.D2212_LAST == 0) { //tag.FNK2.D2210 = 0; - tag.FNK2.D2213 = 1; + //tag.FNK2.D2213 = 1; //tag.FNK2.D2217_LAST = 1; RedisHelper.Add($"p鍙戦偅绉�涓嬬嚎.D2212_LAST", "1", out string msg); @@ -1560,35 +2052,211 @@ public void Thread1019Down(Tag tag) { - Console.WriteLine($"1019浠诲姟鐘舵�锛� =====>"); - Console.WriteLine($"1019浠诲姟鐘舵�锛歿tag.SA1019.RtaskState}- barcode:{tag.SA1019.R鎵樼洏鐮亇- 绌洪棽{tag.SA1019.R5绌洪棽}"); + var taggg = tag.SA1019; + string vqu = "A1019鍙栬揣浜や簰"; + Console.WriteLine($"1019浠诲姟鐘舵�锛� =====>浠诲姟鐢宠锛歿taggg.Ssetreq},杈撻�绾垮厑璁革細{taggg.SreadCan} 浠诲姟瀹屾垚锛歿taggg.SOver} 杈撻�绾挎敹鍒板畬鎴愶細{taggg.SreadAgvover}"); + if (taggg.SOver && taggg.SreadSsxOver) + { + SetRedistoPlc(vqu + ".Ssetreq", "false", vqu + "Queue", "鍐橝GV鐢宠"); + SetRedistoPlc(vqu + ".SOver", "false", vqu + "Queue", "鍐橝GV鐢宠"); + } + //Console.WriteLine($"1019浠诲姟鐘舵�锛� =====>"); + //Console.WriteLine($"1019浠诲姟鐘舵�锛歿tag.SA1019.RtaskState}- barcode:{tag.SA1019.R鎵樼洏鐮亇- 绌洪棽{tag.SA1019.R5绌洪棽}"); } + + private void sa2008(Tag tag) + { + var rdisTcode = RedisHelper.Get<string>($"Arrive{2008}BarcodeLast", out string msg); + LogHelper.Info($"2008 鎵樼洏鍙穥tag.SA2030.R鎵樼洏鐮亇 redis Arrive{2008}BarcodeLast鎵樼洏鍙凤細{rdisTcode} 鍖归厤鏍¢獙銆�); + if (!string.IsNullOrEmpty(tag.ssx杈撻�绾�s2008.R鎵樼洏鐮� && rdisTcode != tag.ssx杈撻�绾�s2008.R鎵樼洏鐮� + { + var ntr = tag.ssx杈撻�绾�s2008.R鎵樼洏鐮� + var str = Settings.apiHelper.Post(Settings.MESbaseUrl + "mom-basic/dataTransmission/json/service/224", JsonConvert.SerializeObject(new + { + cntrCode = ntr, + type = 1 + })); + var strr = JsonConvert.DeserializeObject<MES2234>(str); + if (strr.success && strr.data != null) + { + var end = (strr.data.lineNum == 1 ? 2027 + : strr.data.lineNum == 2 ? 2020 : 2013); + tag.ssx杈撻�绾�s2008.wTaskNo = (uint)(20080000 + end); + tag.ssx杈撻�绾�s2008.wEbit = 2027; + tag.ssx杈撻�绾�s2008.R鎵樼洏鐮�= ntr; + RedisHelper.Add<string>($"Arrive{2008}BarcodeLast", ntr, out msg); + } + } + } + + private void sa2030(Tag tag) + { + var taggg = tag.SA2030; + string vqu = "A2030鍙栬揣浜や簰"; + Console.WriteLine($"{vqu}浠诲姟鐘舵�锛� =====>浠诲姟鐢宠锛歿taggg.Ssetreq},杈撻�绾垮厑璁革細{taggg.SreadCan} 浠诲姟瀹屾垚锛歿taggg.SOver} 杈撻�绾挎敹鍒板畬鎴愶細{taggg.SreadAgvover}"); + if (taggg.SOver && taggg.SreadSsxOver) + { + SetRedistoPlc(vqu + ".Ssetreq", "false", vqu + "Queue", "娓匒GV鐢宠"); + SetRedistoPlc(vqu + ".SOver", "false", vqu + "Queue", "娓匒GV鐢宠"); + SetRedistoPlc(vqu + ".StaskMode", "0", vqu + "Queue", "娓匒GV鐢宠"); + } + } + + private void sa2001(Tag tag) + { + var taggg = tag.SA2001; + string vqu = "A2001鏀捐揣浜や簰"; + Console.WriteLine($"{vqu}浠诲姟鐘舵�锛� =====>浠诲姟鐢宠锛歿taggg.Ssetreq},杈撻�绾垮厑璁革細{taggg.SreadCan} 浠诲姟瀹屾垚锛歿taggg.SOver} 杈撻�绾挎敹鍒板畬鎴愶細{taggg.SreadAgvover}"); + if (taggg.SOver && taggg.SreadSsxOver) + { + SetRedistoPlc(vqu + ".Ssetreq", "false", vqu + "Queue", "娓匒GV鐢宠"); + SetRedistoPlc(vqu + ".SOver", "false", vqu + "Queue", "娓匒GV鐢宠"); + SetRedistoPlc(vqu + ".StaskMode", "0", vqu + "Queue", "娓匒GV鐢宠"); + } + } + + private void sa1030(Tag tag) + { + var taggg = tag.SA1030; + string vqu = "A1030鍙栬揣浜や簰"; + Console.WriteLine($"{vqu}浠诲姟鐘舵�锛� =====>浠诲姟鐢宠锛歿taggg.Ssetreq},杈撻�绾垮厑璁革細{taggg.SreadCan} 浠诲姟瀹屾垚锛歿taggg.SOver} 杈撻�绾挎敹鍒板畬鎴愶細{taggg.SreadAgvover}"); + if (taggg.SOver && taggg.SreadAgvover) + { + SetRedistoPlc(vqu + ".Ssetreq", "false", vqu + "Queue", "鍐橝GV鐢宠"); + SetRedistoPlc(vqu + ".SOver", "false", vqu + "Queue", "鍐橝GV鐢宠"); + SetRedistoPlc(vqu + ".StaskMode", "0", vqu + "Queue", "鍐橝GV鐢宠"); + } + } + + private void sa1025(Tag tag) + { + var taggg = tag.SA1025; + string vqu = "A1025鏀捐揣浜や簰"; + Console.WriteLine($"{vqu}浠诲姟鐘舵�锛� =====>浠诲姟鐢宠锛歿taggg.Ssetreq},杈撻�绾垮厑璁革細{taggg.SreadCan} 浠诲姟瀹屾垚锛歿taggg.SOver} 杈撻�绾挎敹鍒板畬鎴愶細{taggg.SreadAgvover}"); + if (taggg.SOver && taggg.SreadAgvover) + { + SetRedistoPlc(vqu + ".Ssetreq", "false", vqu + "Queue", "娓匒GV鐢宠"); + SetRedistoPlc(vqu + ".SOver", "false", vqu + "Queue", "娓匒GV鐢宠"); + SetRedistoPlc(vqu + ".StaskMode", "0", vqu + "Queue", "娓匒GV鐢宠"); + } + } + + private void sa1022(Tag tag) + { + var taggg = tag.SA1022; + string vqu = "A1022鏀捐揣浜や簰"; + Console.WriteLine($"{vqu}浠诲姟鐘舵�锛� =====>浠诲姟鐢宠锛歿taggg.Ssetreq},杈撻�绾垮厑璁革細{taggg.SreadCan} 浠诲姟瀹屾垚锛歿taggg.SOver} 杈撻�绾挎敹鍒板畬鎴愶細{taggg.SreadAgvover}"); + if (taggg.SOver && taggg.SreadAgvover) + { + SetRedistoPlc(vqu + ".Ssetreq", "false", vqu + "Queue", "娓匒GV鐢宠"); + SetRedistoPlc(vqu + ".SOver", "false", vqu + "Queue", "娓匒GV鐢宠"); + SetRedistoPlc(vqu + ".StaskMode", "0", vqu + "Queue", "娓匒GV鐢宠"); + } + } + + private void sa3010(Tag tag) + { + var taggg = tag.ssx杈撻�绾�s3010; + string vqu = "A3010鍙栬揣浜や簰"; + Console.WriteLine($"{vqu}浠诲姟鐘舵�锛� =====>浠诲姟鐢宠锛歿taggg.Ssetreq},杈撻�绾垮厑璁革細{taggg.SreadCan} 浠诲姟瀹屾垚锛歿taggg.SOver} 杈撻�绾挎敹鍒板畬鎴愶細{taggg.SreadAgvover}"); + if (taggg.SOver && taggg.SreadAgvover) + { + SetRedistoPlc(vqu + ".Ssetreq", "false", vqu + "Queue", "娓匒GV鐢宠"); + SetRedistoPlc(vqu + ".SOver", "false", vqu + "Queue", "娓匒GV鐢宠"); + SetRedistoPlc(vqu + ".StaskMode", "0", vqu + "Queue", "娓匒GV鐢宠"); + } + } + + private void sa3006(Tag tag) + { + var taggg = tag.ssx杈撻�绾�s3006; + string vqu = "A3006鏀捐揣浜や簰"; + Console.WriteLine($"{vqu}浠诲姟鐘舵�锛� =====>浠诲姟鐢宠锛歿taggg.Ssetreq},杈撻�绾垮厑璁革細{taggg.SreadCan} 浠诲姟瀹屾垚锛歿taggg.SOver} 杈撻�绾挎敹鍒板畬鎴愶細{taggg.SreadAgvover}"); + if (taggg.SOver && taggg.SreadAgvover) + { + SetRedistoPlc(vqu + ".Ssetreq", "false", vqu + "Queue", "娓匒GV鐢宠"); + SetRedistoPlc(vqu + ".SOver", "false", vqu + "Queue", "娓匒GV鐢宠"); + SetRedistoPlc(vqu + ".StaskMode", "0", vqu + "Queue", "娓匒GV鐢宠"); + } + } + + private void sa3005(Tag tag) + { + var taggg = tag.ssx杈撻�绾�s3005; + string vqu = "A3005鍙栬揣浜や簰"; + Console.WriteLine($"{vqu}浠诲姟鐘舵�锛� =====>浠诲姟鐢宠锛歿taggg.Ssetreq},杈撻�绾垮厑璁革細{taggg.SreadCan} 浠诲姟瀹屾垚锛歿taggg.SOver} 杈撻�绾挎敹鍒板畬鎴愶細{taggg.SreadAgvover}"); + if (taggg.SOver && taggg.SreadAgvover) + { + SetRedistoPlc(vqu + ".Ssetreq", "false", vqu + "Queue", "娓匒GV鐢宠"); + SetRedistoPlc(vqu + ".SOver", "false", vqu + "Queue", "娓匒GV鐢宠"); + SetRedistoPlc(vqu + ".StaskMode", "0", vqu + "Queue", "娓匒GV鐢宠"); + } + } + + private void sa3001(Tag tag) + { + var taggg = tag.ssx杈撻�绾�s3010; + string vqu = "A3001鏀捐揣浜や簰"; + Console.WriteLine($"{vqu}浠诲姟鐘舵�锛� =====>浠诲姟鐢宠锛歿taggg.Ssetreq},杈撻�绾垮厑璁革細{taggg.SreadCan} 浠诲姟瀹屾垚锛歿taggg.SOver} 杈撻�绾挎敹鍒板畬鎴愶細{taggg.SreadAgvover}"); + if (taggg.SOver && taggg.SreadAgvover) + { + SetRedistoPlc(vqu + ".Ssetreq", "false", vqu + "Queue", "娓匒GV鐢宠"); + SetRedistoPlc(vqu + ".SOver", "false", vqu + "Queue", "娓匒GV鐢宠"); + SetRedistoPlc(vqu + ".StaskMode", "0", vqu + "Queue", "娓匒GV鐢宠"); + } + } + public void Thread1025Up(Tag tag) { - Console.WriteLine($"SA1025 浠诲姟鐘舵�锛� =====>"); - Console.WriteLine($"SA1025 浠诲姟鐘舵�锛歿tag.SA1025.RtaskState}- 绌洪棽{tag.SA1025.R5绌洪棽}"); + //if (tag.SA1019.SOver && tag.SA1019.SreadSsxOver) + //{ + // SetRedistoPlc("A1019鍙栬揣浜や簰.Ssetreq", "false", "A1019鍙栬揣浜や簰Queue", "鍐橝GV鐢宠"); + // SetRedistoPlc("A1019鍙栬揣浜や簰.SOver", "false", "A1019鍙栬揣浜や簰Queue", "鍐橝GV鐢宠"); + //} + //Console.WriteLine($"SA1025 浠诲姟鐘舵�锛� =====>"); + //Console.WriteLine($"SA1025 浠诲姟鐘舵�锛歿tag.SA1025.RtaskState}- 绌洪棽{tag.SA1025.R5绌洪棽}"); } public void Thread1022Up(Tag tag) { - Console.WriteLine($"SA1022 =====>"); - Console.WriteLine($"SA1022 浠诲姟鐘舵�锛歿tag.SA1022.RtaskState}- 绌洪棽{tag.SA1022.R5绌洪棽}"); + //if (tag.SA1019.SOver && tag.SA1019.SreadSsxOver) + //{ + // SetRedistoPlc("A1019鍙栬揣浜や簰.Ssetreq", "false", "A1019鍙栬揣浜や簰Queue", "娓呯悊"); + // SetRedistoPlc("A1019鍙栬揣浜や簰.SOver", "false", "A1019鍙栬揣浜や簰Queue", "娓呯悊"); + //} + //Console.WriteLine($"SA1022 =====>"); + //Console.WriteLine($"SA1022 浠诲姟鐘舵�锛歿tag.SA1022.RtaskState}- 绌洪棽{tag.SA1022.R5绌洪棽}"); } public void Thread1030Down(Tag tag) { Console.WriteLine($"SA1030 浠诲姟鐘舵�锛� =====>"); - Console.WriteLine($"SA1030 浠诲姟鐘舵�锛歿tag.SA1030.RtaskState}- 绌洪棽{tag.SA1030.R5绌洪棽}-->瀵瑰簲缁堢偣2001>绌洪棽5锛歿tag.SA2001.R5绌洪棽}"); + if (tag.SA1030.RtaskState == 4 && tag.SA1030.RtaskState_LAST == 0 && tag.SA2001.R5绌洪棽 == 5) + { + var str = Settings.apiHelper.Post(Settings.WMSbaseUrl + "mom-basic/dataTransmission/json/service/200", JsonConvert.SerializeObject(new + { + requestType = 10, + startBit = "1030", + endBit = "2001", + })); + RedisHelper.Add($"S1030Read.RtaskState_LAST", "1", out string msg); + } + else if (tag.SA1030.RtaskState != 4 && tag.SA1030.RtaskState_LAST == 1) + RedisHelper.Add($"S1030Read.RtaskState_LAST", "0", out string msg); + //if (tag.SA1019.SOver && tag.SA1019.SreadSsxOver) + //{ + // SetRedistoPlc("A1022鏀捐揣浜や簰.Ssetreq", "false", "A1022鏀捐揣浜や簰Queue", "娓呯悊"); + // SetRedistoPlc("A1022鏀捐揣浜や簰.SOver", "false", "A1022鏀捐揣浜や簰Queue", "娓呯悊"); + //} + //Console.WriteLine($"SA1030 浠诲姟鐘舵�锛歿tag.SA1030.RtaskState}- 绌洪棽{tag.SA1030.R5绌洪棽}-->瀵瑰簲缁堢偣2001>绌洪棽5锛歿tag.SA2001.R5绌洪棽}"); } public void Thread2030Down(Tag tag) { - Console.WriteLine($"SA2030 浠诲姟鐘舵�锛� =====>"); - Console.WriteLine($"SA2030 浠诲姟鐘舵�锛歿tag.SA2030.RtaskState}- 绌洪棽{tag.SA2030.R5绌洪棽} - barcode:{tag.SA2030.R鎵樼洏鐮亇"); - - + //Console.WriteLine($"SA2030 浠诲姟鐘舵�锛� =====>"); + //Console.WriteLine($"SA2030 浠诲姟鐘舵�锛歿tag.SA2030.RtaskState}- 绌洪棽{tag.SA2030.R5绌洪棽} - barcode:{tag.SA2030.R鎵樼洏鐮亇"); } - 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); @@ -1605,19 +2273,371 @@ LogHelper.Info($"瑙i噴MES浠诲姟 ->{task.S_TASK_NO} {(sx == null ? "闈� : "鏄�)}鎬昏鏈哄櫒浜轰换鍔�); if (sx == null) { - LogHelper.Info($"瑙i噴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($"瑙i噴MES浠诲姟 ->{task.S_TASK_NO} 鐩存帴鐢熸垚瀵瑰簲浠诲姟 缁撴灉锛歿res}"); - if (res) + gotoOOOOOOOOO: + if (string.IsNullOrEmpty(task.S_CNTRS) && !string.IsNullOrEmpty(task.S_INDEX)) { - LogHelper.Info($"瑙i噴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(); + // 鍙枡浠诲姟銆�鎸囧畾鐗╂枡涓嶆寚瀹氭墭鐩橈紝闇�鍑哄簱 + var ssagv = Settings.deviceInfos.Find(x => x.deviceType == 4); + if (ssagv.location.Contains(task.S_START_LOC)) + switch (task.S_START_LOC) + { + case "2030": + if (!string.IsNullOrEmpty(tag.SA2030.R鎵樼洏鐮�) + { + LogHelper.Info($"瑙i噴MES浠诲姟 ->{task.S_TASK_NO} 2030 鍑哄彛鎵樼洏鍙穥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); + goto gotoOOOOOOOOO; + } + else + { + LogHelper.Info($"瑙i噴MES浠诲姟 ->{task.S_TASK_NO} 鐗╂枡{task.S_INDEX} 涓�2030 鍑哄彛鐨勬墭鐩樼墿鏂檣strr.data.materialCode}涓嶇鍚�); + } + } + else + { + //2027 2220 2013.. 璇嗗埆涓�笅锛屽紑濮嬪簱 + //1 鐪�7 20 13 鏄惁鏈変换鍔°� 鏈夊垯涓嶅嚭浜嗐� 绛夊嚭鍙e垽鏂尮閰嶃� + //2 閮芥病鏈変换鍔★紝閫愪釜鍖归厤鏄惁绗﹀悎锛屽垯鍑哄簱銆�+ //LogHelper.Info($""); + { + var t20132027 = tag.ssx杈撻�绾�s2027; + LogHelper.Info($"璇嗗埆2027浠诲姟 鎵樼洏鍙凤細{t20132027.R鎵樼洏鐮亇 RTaskNo>{t20132027.RTaskNo} REbit>{t20132027.REbit} wTaskNo>{t20132027.wTaskNo} wEbit>{t20132027.wEbit}"); + if ((t20132027.RTaskNo > 0 && t20132027.REbit == 2030) || (t20132027.wTaskNo > 0 && t20132027.wEbit == 2030)) + { + LogHelper.Info($"2027浠诲姟 浠诲姟缁堢偣鏄�030 锛岀粓姝�); + continue; + } + } + { + var t20132027 = tag.ssx杈撻�绾�s2020; + LogHelper.Info($"璇嗗埆2027浠诲姟 鎵樼洏鍙凤細{t20132027.R鎵樼洏鐮亇 RTaskNo>{t20132027.RTaskNo} REbit>{t20132027.REbit} wTaskNo>{t20132027.wTaskNo} wEbit>{t20132027.wEbit}"); + if ((t20132027.RTaskNo > 0 && t20132027.REbit == 2030) || (t20132027.wTaskNo > 0 && t20132027.wEbit == 2030)) + { + LogHelper.Info($"2020浠诲姟 浠诲姟缁堢偣鏄�030 锛岀粓姝�); + continue; + } + } + { + var t20132027 = tag.ssx杈撻�绾�s2013; + LogHelper.Info($"璇嗗埆2027浠诲姟 鎵樼洏鍙凤細{t20132027.R鎵樼洏鐮亇 RTaskNo>{t20132027.RTaskNo} REbit>{t20132027.REbit} wTaskNo>{t20132027.wTaskNo} wEbit>{t20132027.wEbit}"); + if ((t20132027.RTaskNo > 0 && t20132027.REbit == 2030) || (t20132027.wTaskNo > 0 && t20132027.wEbit == 2030)) + { + LogHelper.Info($"2013浠诲姟 浠诲姟缁堢偣鏄�030 锛岀粓姝�); + continue; + } + } + if (!string.IsNullOrEmpty(tag.ssx杈撻�绾�s2027.R鎵樼洏鐮�) + { + var str = Settings.apiHelper.Post(Settings.MESbaseUrl + "mom-basic/dataTransmission/json/service/224", JsonConvert.SerializeObject(new + { + cntrCode = tag.ssx杈撻�绾�s2027.R鎵樼洏鐮� + type = 1 + })); + var strr = JsonConvert.DeserializeObject<MES2234>(str); + if (strr.success && strr.data.materialCode == task.S_INDEX) + { + LogHelper.Info($"2027 璇诲埌鎵樼洏{tag.ssx杈撻�绾�s2027.R鎵樼洏鐮亇 鍖归厤鎴愬姛锛屽啓浠诲姟鍙凤細20272030锛岀粓鐐癸細2030 鍜屾墭鐩樼爜鍚岃"); + tag.ssx杈撻�绾�s2027.wTaskNo = 20272030; + tag.ssx杈撻�绾�s2027.wEbit = 2030; + tag.ssx杈撻�绾�s2027.w鎵樼洏鐮�= tag.ssx杈撻�绾�s2027.R鎵樼洏鐮� + LogHelper.Info($"2027 > 2030 SSX浠诲姟涓嬪彂瀹屾垚銆�); + continue; + } + } + if (!string.IsNullOrEmpty(tag.ssx杈撻�绾�s2020.R鎵樼洏鐮�) + { + var str = Settings.apiHelper.Post(Settings.MESbaseUrl + "mom-basic/dataTransmission/json/service/224", JsonConvert.SerializeObject(new + { + cntrCode = tag.ssx杈撻�绾�s2020.R鎵樼洏鐮� + type = 1 + })); + var strr = JsonConvert.DeserializeObject<MES2234>(str); + if (strr.success && strr.data.materialCode == task.S_INDEX) + { + LogHelper.Info($"2020 璇诲埌鎵樼洏{tag.ssx杈撻�绾�s2020.R鎵樼洏鐮亇 鍖归厤鎴愬姛锛屽啓浠诲姟鍙凤細20202030锛岀粓鐐癸細2030 鍜屾墭鐩樼爜鍚岃"); + tag.ssx杈撻�绾�s2020.wTaskNo = 20202030; + tag.ssx杈撻�绾�s2020.wEbit = 2030; + tag.ssx杈撻�绾�s2020.w鎵樼洏鐮�= tag.ssx杈撻�绾�s2020.R鎵樼洏鐮� + LogHelper.Info($"2020 > 2030 SSX浠诲姟涓嬪彂瀹屾垚銆�); + continue; + } + } + if (!string.IsNullOrEmpty(tag.ssx杈撻�绾�s2013.R鎵樼洏鐮�) + { + var str = Settings.apiHelper.Post(Settings.MESbaseUrl + "mom-basic/dataTransmission/json/service/224", JsonConvert.SerializeObject(new + { + cntrCode = tag.ssx杈撻�绾�s2013.R鎵樼洏鐮� + type = 1 + })); + var strr = JsonConvert.DeserializeObject<MES2234>(str); + if (strr.success && strr.data.materialCode == task.S_INDEX) + { + LogHelper.Info($"2013 璇诲埌鎵樼洏{tag.ssx杈撻�绾�s2013.R鎵樼洏鐮亇 鍖归厤鎴愬姛锛屽啓浠诲姟鍙凤細20132030锛岀粓鐐癸細2030 鍜屾墭鐩樼爜鍚岃"); + tag.ssx杈撻�绾�s2013.wTaskNo = 20132030; + tag.ssx杈撻�绾�s2013.wEbit = 2030; + tag.ssx杈撻�绾�s2013.w鎵樼洏鐮�= tag.ssx杈撻�绾�s2013.R鎵樼洏鐮� + LogHelper.Info($"2013 > 2030 SSX浠诲姟涓嬪彂瀹屾垚銆�); + continue; + } + } + LogHelper.Info($"瑙i噴MES浠诲姟 ->{task.S_TASK_NO} 鏃ュ織鑳借窇鍒拌繖锛岃鏄庢病鐗╂枡锛屾垨鑰呴兘涓嶇鍚�鏃犳硶鍘�030"); + } + 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); + goto gotoOOOOOOOOO; + } + else + { + LogHelper.Info($"瑙i噴MES浠诲姟 ->{task.S_TASK_NO} 鐗╂枡{task.S_INDEX} 涓�1019 鍑哄彛鐨勬墭鐩樼墿鏂檣strr.data.materialCode}涓嶇鍚�); + } + } + break; + //case "1030": + // { + + // } + //break; + case "3005": + { + if (!string.IsNullOrEmpty(tag.ssx杈撻�绾�s3005.R鎵樼洏鐮�) + { + var str = Settings.apiHelper.Post(Settings.MESbaseUrl + "mom-basic/dataTransmission/json/service/224", JsonConvert.SerializeObject(new + { + cntrCode = tag.ssx杈撻�绾�s3005.R鎵樼洏鐮� + type = 2 + })); + var strr = JsonConvert.DeserializeObject<MES2234>(str); + if (strr.success && strr.data.materialCode == task.S_INDEX) + { + task.S_CNTRS = tag.ssx杈撻�绾�s3005.R鎵樼洏鐮� + taskservice.Update(task); + goto gotoOOOOOOOOO; + } + else + { + LogHelper.Info($"瑙i噴MES浠诲姟 ->{task.S_TASK_NO} 鐗╂枡{task.S_INDEX} 涓�3010 鍑哄彛鐨勬墭鐩樼墿鏂檣strr.data.materialCode}涓嶇鍚�); + } + } + } + break; + case "3010": + { + if (!string.IsNullOrEmpty(tag.ssx杈撻�绾�s3010.R鎵樼洏鐮�) + { + var str = Settings.apiHelper.Post(Settings.MESbaseUrl + "mom-basic/dataTransmission/json/service/224", JsonConvert.SerializeObject(new + { + cntrCode = tag.ssx杈撻�绾�s3010.R鎵樼洏鐮� + type = 2 + })); + var strr = JsonConvert.DeserializeObject<MES2234>(str); + if (strr.success && strr.data.materialCode == task.S_INDEX) + { + task.S_CNTRS = tag.ssx杈撻�绾�s3010.R鎵樼洏鐮� + taskservice.Update(task); + goto gotoOOOOOOOOO; + } + else + { + LogHelper.Info($"瑙i噴MES浠诲姟 ->{task.S_TASK_NO} 鐗╂枡{task.S_INDEX} 涓�3010 鍑哄彛鐨勬墭鐩樼墿鏂檣strr.data.materialCode}涓嶇鍚�); + } + } + } + break; + } + //else if (ssagv.location.Contains(task.S_END_LOC)) + // switch (task.S_END_LOC) + // { + // case "1022": + // { + // if (tag.SA1022.R5绌洪棽 != 1) + // { + // LogHelper.Info($"瑙i噴MES浠诲姟 ->{task.S_TASK_NO} 缁堢偣1022 闈炵┖闂诧紝涓嶆帹閫�); + // continue; + // } + // } + // break; + // case "1025": + // { + // if (tag.SA1025.R5绌洪棽 != 1) + // { + // LogHelper.Info($"瑙i噴MES浠诲姟 ->{task.S_TASK_NO} 缁堢偣 1025 闈炵┖闂诧紝涓嶆帹閫�); + // continue; + // } + // } + // break; + // case "2001": + // { + // if (tag.SA2001.R5绌洪棽 != 1) + // { + // LogHelper.Info($"瑙i噴MES浠诲姟 ->{task.S_TASK_NO} 缁堢偣 2001 闈炵┖闂诧紝涓嶆帹閫�); + // continue; + // } + // } + // break; + // case "3001": + // { + // if (tag.ssx杈撻�绾�s3001.R5绌洪棽 != 1) + // { + // LogHelper.Info($"瑙i噴MES浠诲姟 ->{task.S_TASK_NO} 缁堢偣 3001 闈炵┖闂诧紝涓嶆帹閫�); + // continue; + // } + // } + // break; + // case "3006": + // { + // if (tag.ssx杈撻�绾�s3006.R5绌洪棽 != 1) + // { + // LogHelper.Info($"瑙i噴MES浠诲姟 ->{task.S_TASK_NO} 缁堢偣 3006 闈炵┖闂诧紝涓嶆帹閫�); + // continue; + // } + // } + // break; + // } + } + else + { + //if (new List<string> { "2001", "1022", "1025", "3001", "3006" }.Contains(task.S_END_LOC)) + //{ + //} + //if (new List<string> { "1019"/*, "1030"*/, "2030", "3005", "3010" }.Contains(task.S_START_LOC)) //1030 鏄富鍔ㄧ敵璇凤紝 涓嶇敤鍒ゆ柇銆�+ //{ + // //鐗╂枡鍖归厤鍒ゆ柇銆傚拰 2030鍒ゆ柇 + //} + string type = ""; + if (new List<string> { "1019"/*, "1030"*/, "2030", "3005", "3010" }.Contains(task.S_START_LOC)) + switch (task.S_START_LOC) + { + case "1019": + { + type = "A009"; + if (tag.SA1019.RtaskState != 4) + { + LogHelper.Info($"瑙i噴MES浠诲姟 ->{task.S_TASK_NO} 璧风偣 1019 RtaskState>{tag.SA1019.RtaskState} 鏈敵璇稲GV浠诲姟锛屼笉鎺ㄩ�"); + continue; + } + } + break; + case "2030": + { + type = "A007"; + if (tag.SA2030.RtaskState != 4) + { + LogHelper.Info($"瑙i噴MES浠诲姟 ->{task.S_TASK_NO} 璧风偣 2030 RtaskState>{tag.SA2030.RtaskState} 鏈敵璇稲GV浠诲姟锛屼笉鎺ㄩ�"); + continue; + } + } + break; + case "3005": + { + type = "A010"; + if (tag.ssx杈撻�绾�s3005.RtaskState != 4) + { + LogHelper.Info($"瑙i噴MES浠诲姟 ->{task.S_TASK_NO} 璧风偣 3005 RtaskState>{tag.ssx杈撻�绾�s3005.RtaskState} 鏈敵璇稲GV浠诲姟锛屼笉鎺ㄩ�"); + continue; + } + } + break; + case "3010": + { + type = "A010"; + if (tag.ssx杈撻�绾�s3010.RtaskState != 4) + { + LogHelper.Info($"瑙i噴MES浠诲姟 ->{task.S_TASK_NO} 璧风偣 3010 RtaskState>{tag.ssx杈撻�绾�s3010.RtaskState} 鏈敵璇稲GV浠诲姟锛屼笉鎺ㄩ�"); + continue; + } + } + break; + } + if (new List<string> { "2001", "1022", "1025", "3001", "3006" }.Contains(task.S_END_LOC)) + switch (task.S_END_LOC) + { + case "1022": + { + type = "A008"; + if (tag.SA1022.R5绌洪棽 != 5) + { + LogHelper.Info($"瑙i噴MES浠诲姟 ->{task.S_TASK_NO} 缁堢偣1022 闈炵┖闂诧紝涓嶆帹閫�); + continue; + } + } + break; + case "1025": + { + type = "A007"; + if (tag.SA1025.R5绌洪棽 != 5) + { + LogHelper.Info($"瑙i噴MES浠诲姟 ->{task.S_TASK_NO} 缁堢偣 1025 闈炵┖闂诧紝涓嶆帹閫�); + continue; + } + } + break; + case "2001": + { + type = "A007"; + if (tag.SA2001.R5绌洪棽 != 5) + { + LogHelper.Info($"瑙i噴MES浠诲姟 ->{task.S_TASK_NO} 缁堢偣 2001 闈炵┖闂诧紝涓嶆帹閫�); + continue; + } + } + break; + case "3001": + { + type = "A010"; + if (tag.ssx杈撻�绾�s3001.R5绌洪棽 != 5) + { + LogHelper.Info($"瑙i噴MES浠诲姟 ->{task.S_TASK_NO} 缁堢偣 3001 闈炵┖闂诧紝涓嶆帹閫�); + continue; + } + } + break; + case "3006": + { + type = "A010"; + if (tag.ssx杈撻�绾�s3006.R5绌洪棽 != 5) + { + LogHelper.Info($"瑙i噴MES浠诲姟 ->{task.S_TASK_NO} 缁堢偣 3006 闈炵┖闂诧紝涓嶆帹閫�); + continue; + } + } + break; + } + + LogHelper.Info($"瑙i噴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>(), "AGV", type); + + LogHelper.Info($"瑙i噴MES浠诲姟 ->{task.S_TASK_NO} 鐩存帴鐢熸垚瀵瑰簲浠诲姟 缁撴灉锛歿res}"); + if (res) + { + LogHelper.Info($"瑙i噴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 @@ -1749,7 +2769,18 @@ } } - + public string procNo() + { + return TaskProcess.GenerateTaskNo("鏃ュ織娴佹按鍙�, "LOG"); + } + public bool SetRedistoPlc(string key, string value, string queue, string desc) + { + var vnc = procNo(); + LogHelper.Info($"{vnc}>>Redis.SetValue鍐檖lc 鎻忚堪锛歿desc} tagName:{key},value:{value},queue:{queue}"); + var v = Conn.榛樿Redis.SetValue(key, value, queue); + LogHelper.Info($"{vnc}>> 鍐欏叆缁撴灉{v}"); + return v; + } public HkReturnResult OperateHKTaskStatus(HaiKangOrderInfo model) { // 鏌ヨ浠诲姟锛氭牴鎹换鍔″彿 @@ -1818,6 +2849,16 @@ // Conn.榛樿Redis.SetValue(device.deviceName + "." + V, "0", device.deviceName + "Queue"); //}); } + else + switch (device.deviceType) + { + case 4: + { + + } + break; + + } } //LocationHelper.UnLockLoc(wcsTask.S_START_LOC); break; @@ -1877,12 +2918,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 { @@ -1912,6 +2953,29 @@ LogHelper.Info($"{ssloc}鐢宠mes浠诲姟缁撴灉{str}"); } } + else + switch (device2.deviceType) + { + case 4: + { + + } + 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; + } } //LocationMethod.JudgeLocation(wcsTask); @@ -2034,16 +3098,131 @@ } } + /// <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], + endBit = "1025", + 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], + endBit = "1025", + 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.DZ2.D2221} D2221_LAST>{tag.DZ2.D2221_LAST} D2226>{tag.DZ2.D2226} D2226_LAST>{tag.DZ2.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], + endBit = "1025", + 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], + endBit = "1025", + 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 @@ -2427,6 +3606,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 { -- Gitblit v1.9.1