From 8ab19ae17dc98d3c79f87ca54aa4cdc75d174b12 Mon Sep 17 00:00:00 2001 From: cjs <2216046164@qq.com> Date: 星期三, 18 六月 2025 17:10:30 +0800 Subject: [PATCH] 111 --- ams/Hanhe.iWCS.TaizhouGEMTwoProtocol/PLCControl.cs | 225 +++++++++++++++++++++++++++++++++++--------------------- 1 files changed, 140 insertions(+), 85 deletions(-) diff --git a/ams/Hanhe.iWCS.TaizhouGEMTwoProtocol/PLCControl.cs b/ams/Hanhe.iWCS.TaizhouGEMTwoProtocol/PLCControl.cs index 070d127..d541128 100644 --- a/ams/Hanhe.iWCS.TaizhouGEMTwoProtocol/PLCControl.cs +++ b/ams/Hanhe.iWCS.TaizhouGEMTwoProtocol/PLCControl.cs @@ -1470,8 +1470,10 @@ /// </summary> /// <param name="ip"></param> /// <param name="taskNo"></param> - internal static void CacheStackingMouth6(Settings.PlcInfo plc) + internal static void CacheStackingMouth6(Settings.PlcInfo plc, string taskNo) { + var taskInfo = MongoDBSingleton.Instance.FindOne<TN_I_TASK_MST>(Query.EQ("CN_S_TASK_NO", taskNo), "TN_I_TASK_MST"); + MongoDBSingleton.Instance.Remove<WMSInfo>(Query.EQ("trayCode", taskInfo.CN_S_BATCH_NO), RemoveFlags.Single); var wirte = OITcpHelper.RegisterWriteOutPut(new OITcpHelper.RegisterWriteOutPutModel { addr = plc.writeAddr + 1, @@ -1749,6 +1751,7 @@ host = plc.ip, port = plc.port }); + CMMLog.Info($"鍙犵洏涓嬬嚎璇诲彇閫氶亾{plc.ip}锛宲ort锛歿plc.port},鍦板潃锛歿plc.readAddr + 1}鐨勫�涓簕JsonConvert.SerializeObject(result)}"); if (result != null && result.errCode == 0) { //1.婊℃墭涓嬬嚎 @@ -1760,7 +1763,14 @@ string wmstaskno = ""; string traycode = ""; string trayType = ""; - if(plc.deviceType == "25") trayType = result.result[1] == 1 ? "宸濆瓧鎵� : "鐢板瓧鎵�; + if (plc.deviceType == "25") + { + trayType = result.result[1] == 1 ? "宸濆瓧鎵� : result.result[1] == 2 ? "鐢板瓧鎵� : ""; + if (string.IsNullOrEmpty(trayType)) + { + return; + } + } bool req = WMSHelper.WMSIn(plc.location, "", ref wmstaskno, ref traycode,"","",false, trayType); if (req) { @@ -2016,62 +2026,6 @@ } } } - - /// <summary> - /// 3妤兼墦鍖呮満涓嬬嚎锛屽垽鏂墦鍖呮満鏄惁鐢辩敓鎴愭墦鍖呬笅绾跨殑浠诲姟锛堝洓閽磋溅闂达級 - /// </summary> - /// <param name="plc"></param> - internal static void CheckPackingLineFullTwo(Settings.PlcInfo plc) - { - //璇籶lc淇″彿锛岀湅鏈夋病鏈変笅绾胯姹傦紝鍒ゆ柇鏄惁宸茬粡鏈変换鍔�- //娌℃湁浠诲姟锛岀户缁璸lc锛屽寘瑁呬笅绾跨殑鐗╂枡淇″彿 - //妫�煡鎵撳寘鏈洪�閬�鏄惁鏈夊嚭鏂欎换鍔′俊鍙凤紝濡傛灉鏈夌敓鎴愬彇鏂欎换鍔°� - if (CheckStartFree(plc.location)) - { - try - { - var result = OITcpHelper.RegisterReadOutPut(new OITcpHelper.RegisterReadOutPutModel - { - dataNum = 1, - addr = plc.readAddr + 1, - host = plc.ip, - port = plc.port - }); - if (result != null && result.errCode == 0) - { - if (result.result[0] == 1) - { - //鑾峰彇MODBUS閫氶亾閲岄潰瀛樻斁鐨勬椂闂存埑 - var resultTime = OITcpHelper.RegisterReadOutPut(new OITcpHelper.RegisterReadOutPutModel - { - addr = plc.readAddr + 10, - host = plc.ip, - port = plc.port, - dataNum = 170 - }); - if (resultTime.errCode == 0) - { - string wmstaskno = ""; - TimeCuoInfoComTwo timecuo = TimeCuoTwo(resultTime.result); - if (timecuo != null) - { - string timeStamp = timecuo.TimeCuo; - string employeeId = timecuo.employeeId1; - // ERP鍙樻洿-璋冪敤ERP鎺ュ彛浼犺緭鐩稿叧鏁版嵁 - WMSHelper.WMSIn(plc.location, "time", ref wmstaskno, ref timeStamp, timeStamp, employeeId,true); - } - else CMMLog.Info($"鏃堕棿鎴虫帴鍙h繑鍥炲�涓虹┖锛�); - } - else CMMLog.Info($"MODBUS鏃堕棿鎴虫暟鎹繑鍥炲�閿欒锛氳繑鍥炲�瑙f瀽锛歿JsonConvert.SerializeObject(result)}"); - } - } - } - catch (Exception ex) - { - CMMLog.Error(ex.Message); - } - } - } #endregion #region 鎵撳寘鏈哄嚭鍙ODBUS浜や簰锛堝紑濮嬪彇鏂欙紝鍙栨枡瀹屾垚锛�@@ -2080,9 +2034,9 @@ /// 璁惧鍏佽鍑烘枡 1 PLC鍐欙紝AMS璇�1-璁惧璇锋眰鍑烘枡锛�-鍏佽杩涘叆锛�-纭璐х墿鍙栬蛋锛岄�鍑虹墿鏂欙紱 ///鎵撳寘绾夸笅绾库�鈥斿皬杞﹀紑濮嬪彇璐�- internal static void PackingLineUnload1012(string ip, string taskNo) + internal static void PackingLineUnload1012(string ip, string taskNo, int port) { - var plc = Settings.GetPlcInfo().Where(a => a.deviceType == "4").FirstOrDefault(); + var plc = Settings.GetPlcInfo().Where(a => a.ip == ip && a.port == port).FirstOrDefault(); if (plc != null) { try @@ -2131,11 +2085,11 @@ /// </summary> /// <param name="ip"></param> /// <param name="taskNo"></param> - internal static void PackingLineComplete4(string ip, string taskNo) + internal static void PackingLineComplete4(string ip, string taskNo, int port) { //鍙栬揣瀹屾垚鍚庨渶瑕佽鍙栬澶囨椂闂存埑閲岄潰鐨勬暟鎹紝骞跺皢鍏舵殏瀛樿嚦涓棿琛ㄧ瓑鍒板叆搴撲换鍔″畬鎴愪紶杈撶粰WMS - var plc = Settings.GetPlcInfo().Where(a => a.deviceType == "4").FirstOrDefault(); + var plc = Settings.GetPlcInfo().Where(a => a.ip == ip && a.port == port).FirstOrDefault(); if (plc != null) { try @@ -3975,7 +3929,7 @@ if (result != null && result.errCode == 0) { //3锛氫汉宸ュ彨绌烘墭鐩�宸濆瓧) 4:浜哄伐鍙┖鎵樼洏(鐢板瓧) - if (result.result[0] == 3 || result.result[0] == 4) + if ((pmInfo.deviceType == "1" && result.result[0] == 3)|| (pmInfo.deviceType == "21" &&(result.result[0] == 3 || result.result[0] == 4))) { //鍖呰绾胯ˉ绌烘祦绋� //鍒ゆ柇绌烘墭缂撳瓨鐐癸紙5 瀵�2锛夋槸鍚︽湁绌烘墭锛屾湁绌烘墭鍒ゆ柇鏄惁鏈変换鍔★紝鏈変换鍔″垯鍒ゆ柇鍙︿竴涓偣浣�@@ -3988,9 +3942,9 @@ { CMMLog.Info($"鍛ㄨ浆鎵樼洏浣嶏細{a}"); var ddInfo = Settings.GetDDSiteList().Where(b => b.ddLoc == a && b.Enable == 1).FirstOrDefault(); - if(ddInfo != null) + if (ddInfo != null) { - if(ddInfo.trayType == result.result[0] - 2) + if (ddInfo.trayType == result.result[0] - 2) { if (ProcessHelper.PickUpEndFree(pmInfo.location) && ProcessHelper.PickUpStartFree(a)) { @@ -4015,21 +3969,6 @@ CMMLog.Info("閰嶇疆鏂囦欢鏈厤缃寘瑁呮満绌烘墭缂撳瓨鐐�); } } - //娴佺▼鏈鎺ュソ锛屾槸鍚﹁繖鏍蜂娇鐢�寰呭畾 - //if (result.result[0] == 4) - //{ - // //璋冪敤wms鍑哄簱鎺ュ彛 - // var tasks = MongoDBSingleton.Instance.Find<TN_I_TASK_MST>(Query.EQ("CN_S_END_BIT", pmInfo.location), "TN_I_TASK_MST"); - // //鍒ゆ柇涓�笅褰撳墠鍙犳墭鐐规槸鍚︽湁浠诲姟鍗犵敤 - // if (ProcessHelper.CheckEndFree(pmInfo.location) && tasks.Count == 0) - // { - // //鍙互鐢熸垚浠诲姟锛岃皟WMS鎺ュ彛鑾峰彇浠诲姟淇℃伅 - // bool req = WMSHelper.WMSOut(pmInfo.location, ""); - // if (req) CMMLog.Debug($"璋冪敤WMS鑾峰彇杈呮潗鍑哄簱鐢熸垚浠诲姟鎴愬姛锛�);//鐜板湪浠诲姟鐢盬MS鑷繁涓嬪彂锛孉MS鍋氭嫤鎴鐞嗭紙鏌ヨext1閲岄潰瀵瑰簲鐨勪换鍔$被鍨嬶紝骞舵洿鏀逛换鍔$被鍨嬶級 - // else CMMLog.Debug($"璋冪敤WMS鑾峰彇杈呮潗鍑哄簱鐢熸垚浠诲姟澶辫触锛�); - // } - // else CMMLog.Debug($"妫�煡褰撳墠鍙犳墭鐐规槸鍚︽湁浠诲姟鍗犵敤锛屾垨鑰匨ST涓昏〃涓湁缂撳瓨鏋跺叆鍙犵洏鏈虹殑浠诲姟锛�); - //} } else { @@ -4045,7 +3984,7 @@ { if (action) { - int[] num = new int[3] {1,1,1}; + int[] num = new int[3] {1,0,1}; var writeRes = OITcpHelper.RegisterWriteOutPutMulti(new OITcpHelper.RegisterWriteOutPutModelMulti { host = plc.ip, @@ -4069,14 +4008,24 @@ { //鎺ㄩ�灏忚溅杩涘叆 TSHelper.GoToAGV(taskNo, 10, 3); - writeRes = OITcpHelper.RegisterWriteOutPut(new OITcpHelper.RegisterWriteOutPutModel + + int[] num1 = new int[2] { 1, 2}; + writeRes = OITcpHelper.RegisterWriteOutPutMulti(new OITcpHelper.RegisterWriteOutPutModelMulti { host = plc.ip, - addr = plc.writeAddr + 2, - data = 2, + addr = plc.writeAddr + 1, + data = num1, port = plc.port }); - CMMLog.Debug($"鍐欏叆璁惧{plc.location}閫氶亾{plc.writeAddr + 2}閲岄潰鏁版嵁涓�."); + + //writeRes = OITcpHelper.RegisterWriteOutPut(new OITcpHelper.RegisterWriteOutPutModel + //{ + // host = plc.ip, + // addr = plc.writeAddr + 2, + // data = 2, + // port = plc.port + //}); + CMMLog.Debug($"鍐欏叆璁惧{plc.location}閫氶亾{plc.writeAddr + 1}閲岄潰鏁版嵁涓簕JsonConvert.SerializeObject(num1)}."); } } } @@ -4192,6 +4141,112 @@ } Thread.Sleep(100000); } + + internal static void CheckPackingLineFullThree(Settings.PlcInfo plc) + { + string trayCode = ""; + var result = OITcpHelper.RegisterReadOutPut(new OITcpHelper.RegisterReadOutPutModel + { + dataNum = 25, + addr = plc.readAddr, + host = plc.ip, + port = plc.port + }); + if(result != null && result.errCode == 0) + { + if (result.result[0] == 1) + { + //鑾峰彇鐗╂枡淇℃伅 鏍规嵁鎵樼洏鐮佸尯鍒�+ trayCode = RemoveNull(GetTrayCode(result.result.Skip(6).Take(3).ToArray()));//鎵樼洏鐮�+ + + var infoPack = MongoDBSingleton.Instance.FindOne<TimeCuoInfoComTwo>(Query.And(Query.EQ("trayCode", trayCode)), "TimeCuoInfoComTwo"); + if (infoPack != null) + { + string empCode = RemoveNull(GetTrayCode(result.result.Skip(1).Take(5).ToArray()));//鍛樺伐缂栫爜 + string machineCode = RemoveNull(GetTrayCode(result.result.Skip(9).Take(1).ToArray()));//鍖呰鏈哄彿 + int needWeight = Convert.ToInt32(Completion(result.result[10]) + Completion(result.result[11]), 2);//浜у搧闇�眰閲嶉噺 + int oneWeight = Convert.ToInt32(Completion(result.result[12]) + Completion(result.result[13]), 2);//鍗曟墭姣涢噸 + int readWeight = Convert.ToInt32(Completion(result.result[14]) + Completion(result.result[15]), 2);//鍗曟墭鍑�噸 + int fcWeight = Convert.ToInt32(Completion(result.result[16]) + Completion(result.result[17]), 2);//鍗曟墭澶嶇О閲嶉噺 + int trayType = Convert.ToInt32(Completion(result.result[18]), 2);//鎵樼洏绫诲瀷 + int addState = Convert.ToInt32(Completion(result.result[19]), 2);//鍙犲寘灞傛暟 + int bagNumber = Convert.ToInt32(Completion(result.result[20]), 2);//琚嬪彿 + int productTime = Convert.ToInt32(Completion(result.result[21]) + Completion(result.result[22]), 2);//鐢熶骇鏃ユ湡 + string timeCuoTwo = Convert.ToInt32(Completion(result.result[23]) + Completion(result.result[24]), 2).ToString(); //鏃堕棿鎴�+ + UpdateBuilder updateBuilder = Update.Set("employeeId", empCode).Set("trayCode", trayCode).Set("packingMachineNumber", machineCode).Set("needWeight", needWeight) + .Set("oneWeight", oneWeight).Set("realWeight", readWeight).Set("FCWeight", fcWeight).Set("trayType", trayType) + .Set("isFold", addState).Set("bagNumber", bagNumber).Set("productData", productTime); + //浜у搧鎵规鍙� 浜у搧鍨嬪彿 鐗╂枡鍚嶇О 璁¢噺鍗曚綅鍧囧彲鍦╡rp琛ㄤ腑鏍规嵁鐗╂枡缂栫爜鑾峰彇 + + result = OITcpHelper.RegisterReadOutPut(new OITcpHelper.RegisterReadOutPutModel + { + dataNum = 15, + addr = plc.readAddr + 131, + host = plc.ip, + port = plc.port + }); + + string materialCode = RemoveNull(GetTrayCode(result.result.Skip(0).Take(15).ToArray()).Trim().ToString()); + UpdateBuilder update = Update.Set("materialCode", materialCode).Set("createTime",DateTime.Now); + MongoDBSingleton.Instance.Update<TimeCuoInfoComTwo>(Query.EQ("trayCode", trayCode), update, UpdateFlags.None); + + var writeRes = OITcpHelper.RegisterWriteOutPut(new OITcpHelper.RegisterWriteOutPutModel + { + host = plc.ip, + addr = plc.writeAddr, + data = 1, + port = plc.port + }); + CMMLog.Debug($"鍐欏叆璁惧{plc.location}閫氶亾{plc.writeAddr}閲岄潰鏁版嵁涓�."); + } + } + } + + var xxPlc = Settings.GetPlcInfo().Where(a => a.deviceType == "27" && a.enable == 1).FirstOrDefault(); + if(xxPlc != null) + { + result = OITcpHelper.RegisterReadOutPut(new OITcpHelper.RegisterReadOutPutModel + { + dataNum = 1, + addr = plc.readAddr + 1, + host = plc.ip, + port = plc.port + }); + if(result != null && result.errCode == 0) + { + if (result.result[0] == 1) + { + var resultTime = OITcpHelper.RegisterReadOutPut(new OITcpHelper.RegisterReadOutPutModel + { + dataNum = 2, + addr = plc.readAddr + 8, + host = plc.ip, + port = plc.port + }); + if (resultTime.errCode == 0) + { + string timeCuoData = (resultTime.result[0] * 65536 + resultTime.result[1]).ToString(); + TimeCuoInfoComTwo time = null; + var timeTwo = MongoDBSingleton.Instance.Find<TimeCuoInfoComTwo>(Query.EQ("trayCode", trayCode), "TimeCuoInfoComTwo"); + if(timeTwo.Count > 0) + { + time = timeTwo.OrderBy(a => a.createTime).FirstOrDefault(); + MongoDBSingleton.Instance.Update<TimeCuoInfoComTwo>(Query.EQ("_id", time._id),Update.Set("TimeCuo", timeCuoData)); + } + string wmstaskno = ""; + WMSHelper.WMSIn(plc.location, "time", ref wmstaskno, ref timeCuoData, timeCuoData, time.employeeId, true); + } + } + } + } + else + { + CMMLog.Info("涓嬬嚎鍙h澶囨湭閰嶇疆"); + } + + } #endregion } } -- Gitblit v1.9.1