From fae1a7742f0d847a47a0f8d3d1235e4826f5d4c6 Mon Sep 17 00:00:00 2001 From: cjs <2216046164@qq.com> Date: 星期三, 02 七月 2025 17:37:13 +0800 Subject: [PATCH] 1 --- ams/Hanhe.iWCS.TaizhouGEMTwoProtocol/PLCControl.cs | 465 ++++++++++++++++++++++++++++++++++++++++++++------------- 1 files changed, 355 insertions(+), 110 deletions(-) diff --git a/ams/Hanhe.iWCS.TaizhouGEMTwoProtocol/PLCControl.cs b/ams/Hanhe.iWCS.TaizhouGEMTwoProtocol/PLCControl.cs index d541128..0555a24 100644 --- a/ams/Hanhe.iWCS.TaizhouGEMTwoProtocol/PLCControl.cs +++ b/ams/Hanhe.iWCS.TaizhouGEMTwoProtocol/PLCControl.cs @@ -22,6 +22,9 @@ using static Hanhe.iWCS.TaizhouGEMTwoProtocol.ProtocolAnalysis; using log4net.Appender; using System.Net.Configuration; +using static System.Runtime.CompilerServices.RuntimeHelpers; +using System.Reflection.Emit; +using System.Text.RegularExpressions; namespace Hanhe.iWCS.TaizhouGEMTwoProtocol { @@ -1066,7 +1069,6 @@ WriteCacheStackingData(plc, task, machine); - var wirte = OITcpHelper.RegisterWriteOutPut(new OITcpHelper.RegisterWriteOutPutModel { addr = plc.writeAddr + 1, @@ -1092,11 +1094,12 @@ //璇诲彇閫氶亾1閲岄潰鍙傛暟鏄惁涓�锛屽垽鏂彔鐩樻満鏄惁闇�涓婃枡 var result = OITcpHelper.RegisterReadOutPut(new OITcpHelper.RegisterReadOutPutModel { - dataNum = 1, + dataNum = 2, addr = pmInfo.readAddr + 1, host = pmInfo.ip, port = pmInfo.port }); + CMMLog.Info($"鑾峰彇纰熺洏鍏ュ彛淇℃伅锛歿JsonConvert.SerializeObject(result)}"); if (result != null && result.errCode == 0) { //鍙傛暟1琛ㄧず鍙犳墭鐐圭敵璇峰叆鏂�@@ -1112,6 +1115,66 @@ else CMMLog.Debug($"璋冪敤WMS鑾峰彇纰熺洏鍑哄簱鐢熸垚浠诲姟澶辫触锛�); } else CMMLog.Debug($"妫�煡褰撳墠鍙犳墭鐐规槸鍚︽湁浠诲姟鍗犵敤锛屾垨鑰匨ST涓昏〃涓湁缂撳瓨鏋跺叆鍙犵洏鏈虹殑浠诲姟锛�); + } + if (pmInfo.deviceType == "23" && result.result[1] == 1) + { + //鍥涢挻杞﹂棿锛屼汉宸ヤ笂鏂欐ā寮�+ result = OITcpHelper.RegisterReadOutPut(new OITcpHelper.RegisterReadOutPutModel + { + dataNum = 21, + addr = pmInfo.readAddr + 120, + host = pmInfo.ip, + port = pmInfo.port + }); + CMMLog.Info($"鑾峰彇纰熺洏浜哄伐涓婃枡鍐欏叆淇℃伅锛歿JsonConvert.SerializeObject(result)}"); + if (result != null && result.errCode == 0) + { + string lotNo = RemoveNull(GetTrayCode(result.result.Skip(0).Take(20).ToArray()).Trim().ToString()); //鎵规鍙�+ string bagNumber = Convert.ToInt32(Completion(result.result[20]), 2).ToString(); + var machinInfo = MongoDBSingleton.Instance.FindOne<MachineInfoTwoTetracobalt>(Query.And(Query.EQ("lotNo", lotNo), Query.EQ("packageCode", bagNumber)), "MachineInfoTwoTetracobalt"); + if(machinInfo != null) + { + TN_I_TASK_MST task = new TN_I_TASK_MST + { + CN_S_BATCH_NO = machinInfo.trayCode + }; + WMSInfo machine = new WMSInfo + { + location = machinInfo.location, + productWeight = machinInfo.productWeight, + oneTrayWeight = machinInfo.oneTrayWeight, + addState = machinInfo.addState, + packageCode = machinInfo.packageCode, + itemCode = machinInfo.materialCode + }; + PLCControl.WriteCacheStackingData(pmInfo, task,machine); + machinInfo = MongoDBSingleton.Instance.FindOne<MachineInfoTwoTetracobalt>(Query.And(Query.EQ("lotNo", lotNo), Query.EQ("packageCode", bagNumber)), "MachineInfoTwoTetracobalt"); + if(machinInfo == null) + { + //淇℃伅鍐欏叆鎴愬姛 + var wirte = OITcpHelper.RegisterWriteOutPut(new OITcpHelper.RegisterWriteOutPutModel + { + addr = pmInfo.writeAddr + 2, + host = pmInfo.ip, + port = pmInfo.port, + data = 1 + }); + CMMLog.Info("浜哄伐鍙犲寘淇℃伅鏌ヨ鎴愬姛锛屽啓鍏�"); + + } + } + else + { + var wirte = OITcpHelper.RegisterWriteOutPut(new OITcpHelper.RegisterWriteOutPutModel + { + addr = pmInfo.writeAddr + 2, + host = pmInfo.ip, + port = pmInfo.port, + data = 2 + }); + CMMLog.Info("浜哄伐鍙犲寘淇℃伅鏌ヨ澶辫触锛屽啓鍏�"); + } + } } } else CMMLog.Debug($"缂撳瓨鍏ュ彔鐩樻満锛屽垱寤轰换鍔★紝result={result.errMsg}"); @@ -1247,17 +1310,17 @@ num[8] = int.Parse(AsciiToTen(machine.location));//鍖呰鏈哄彿 for (int b = 9; b <= 10; b++) { - int k = b % 2 == 0 ? 0 : 16; + int k = b % 2 == 0 ? 16 : 0; num[b] = Convert.ToInt32(Convert.ToString(int.Parse(machine.productWeight), 2).PadLeft(32, '0').ToString().Substring(k, 16), 2); } for (int b = 11; b <= 12; b++) { - int k = b % 2 == 0 ? 0 : 16; + int k = b % 2 == 0 ? 16 : 0; num[b] = Convert.ToInt32(Convert.ToString(int.Parse(machineInfoTwo.trayCodeWeight), 2).PadLeft(32, '0').ToString().Substring(k, 16), 2); } for (int b = 13; b <= 14; b++) { - int k = b % 2 == 0 ? 0 : 16; + int k = b % 2 == 0 ? 16 : 0; num[b] = Convert.ToInt32(Convert.ToString(int.Parse(machine.oneTrayWeight), 2).PadLeft(32, '0').ToString().Substring(k, 16), 2); } for (int b = 15; b <= 16; b++) @@ -1282,7 +1345,9 @@ #endregion string pcHead = ""; + string pcTail = ""; string cpHead = ""; + string cpTail = ""; string mtHead = "";// 璁惧鐨勭湡瀹炵墿鏂欑紪鐮� #region 35~54 => 41~60 浜у搧鎵规鍙�@@ -1291,12 +1356,17 @@ CMMLog.Info($"41~60data1_1:{data}"); if (data.Length % 2 != 0) { - data = "0" + machineInfoTwo.lotNo; - pcHead = "" + machineInfoTwo.lotNo.Substring(0, 1); + //data = "0" + machineInfoTwo.lotNo; + //pcHead = "" + machineInfoTwo.lotNo.Substring(0, 1); + + pcTail = machineInfoTwo.lotNo.Substring(data.Length - 1, 1) + ""; + CMMLog.Info($"pcTail:{pcTail}"); + data = machineInfoTwo.lotNo + " "; } CMMLog.Info($"41~60data1_2:{data}"); //瀛楃涓查暱搴�/ 2 = 鍐欏叆閫氶亾鏁伴噺(涓や綅涓�浆) 鍒楋細 3L0050 鍐欏叆涓変釜閫氶亾 int maxLength = 34 + (data.Length / 2);// data.Length / 2 鑷冲皯涓�1 + int maxLength2 = maxLength; int aa = 0; for (int i = 35; i <= maxLength; i++) { @@ -1304,11 +1374,45 @@ aa = aa + 2; } for (int x = maxLength + 1; x <= 54; x++) num[x] = 0;//灏嗕骇鍝佹壒娆″彿鏃犳暟鎹殑閫氶亾鍏ㄩ儴缃负 0 + CMMLog.Info($"num:{JsonConvert.SerializeObject(num)}"); #endregion - #region 55~64 => 61~70 浜у搧鍨嬪彿 + #region 55~64 => 61~70 浜у搧鍨嬪彿(鍥涢挻浜у搧鍨嬪彿鏈変腑鏂囧拰鑻辨枃) - ERPService.HandleItemInfoChina(machine.itemCode, 55, 64, num);// 涓枃澶勭悊 55~64 61~70 + int maxLength3 = 0; + if (Regex.IsMatch(ErpItemInfo.item_spec, @"[\u4e00-\u9fff]")) + { + ERPService.HandleItemInfoChina(ErpItemInfo.item_spec, 55, 64, num);// 涓枃澶勭悊 55~64 61~70 + } + else + { + data = ErpItemInfo.item_spec; + CMMLog.Info($"61~70data1_1:{data}"); + if (data.Length % 2 != 0) + { + //data = "0" + machineInfoTwo.lotNo; + //pcHead = "" + machineInfoTwo.lotNo.Substring(0, 1); + + cpTail = ErpItemInfo.item_spec.Substring(data.Length - 1, 1) + ""; + CMMLog.Info($"cpTail:{cpTail}"); + data = ErpItemInfo.item_spec + " "; + } + CMMLog.Info($"61~70data1_2:{data}"); + //瀛楃涓查暱搴�/ 2 = 鍐欏叆閫氶亾鏁伴噺(涓や綅涓�浆) 鍒楋細 3L0050 鍐欏叆涓変釜閫氶亾 + maxLength = 54 + (data.Length / 2);// data.Length / 2 鑷冲皯涓�1 + maxLength3 = maxLength; + aa = 0; + for (int i = 55; i <= maxLength; i++) + { + num[i] = int.Parse(AsciiToTen(data.Substring(aa, 2))); + aa = aa + 2; + } + for (int x = maxLength3 + 1; x <= 64; x++) num[x] = 0;//灏嗕骇鍝佹壒娆″彿鏃犳暟鎹殑閫氶亾鍏ㄩ儴缃负 0 + CMMLog.Info($"num:{JsonConvert.SerializeObject(num)}"); + + //ERPService.HandleItemInfo(ErpItemInfo.item_spec, 55, 64, num); + } + //string data2 = machine.itemCode; //CMMLog.Info($"51~50data2_1:{data2}"); @@ -1352,14 +1456,28 @@ ERPService.HandleItemInfo(ErpItemInfo.item_uom, 100, 104, num);// 100~104 106~110 // 濡傛灉 浜у搧鎵规鍙�鎴栬� 浜у搧鍨嬪彿 浣嶆暟 涓�濂囨暟锛屽垯灏嗘彁鍓嶅彇鍑虹殑 棣栧瓧绗�閲嶆柊杞爜 鍐欏叆 鍏舵墍瀵瑰簲閫氶亾鍖哄煙鐨�棣栭�閬�- if (pcHead != "") num[35] = int.Parse(AsciiToTen(pcHead)); - if (cpHead != "") num[55] = int.Parse(AsciiToTen(cpHead)); + //if (pcHead != "") num[35] = int.Parse(AsciiToTen(pcHead)); + if (pcTail != "") num[maxLength2] = tailToTen(pcTail); + //if (cpHead != "") num[55] = int.Parse(AsciiToTen(cpHead)); + if (cpHead != "") num[maxLength3] = int.Parse(AsciiToTen(cpTail)); if (mtHead != "") num[65] = int.Parse(AsciiToTen(mtHead)); if (pcHead != "" || cpHead != "") CMMLog.Info($"浜у搧鍨嬪彿鎴栨壒娆″彿鏁伴噺涓哄鏁帮紝鐗瑰皢棣栦綅鍙栧嚭鍗曠嫭澶勭悊锛屼互涓嬩负鎵规鍙峰拰浜у搧鍨嬪彿鐨勫崄杩涘埗鏁板�{num[35]},{num[55]}"); CMMLog.Info($"鍙犵洏鏈烘暟鎹鐞嗗畬姣曪細{JsonConvert.SerializeObject(num)}"); return num; + } + + private static int tailToTen(string Tail) + { + char inputChar = Tail[0]; // 鑾峰彇瀛楃涓茬殑绗竴涓瓧绗�+ int asciiValue = (int)inputChar; // 杞崲涓篈SCII鐮�+ string hexValue = asciiValue.ToString("X2"); // 杞崲涓�6杩涘埗 + string binaryValue = Convert.ToString(asciiValue, 2).PadLeft(8, '0'); // 杞崲涓�浣嶄簩杩涘埗 + string finalBinaryValue = binaryValue + "00000000"; // 琛�涓簩杩涘埗0 + int finalDecimalValue = Convert.ToInt32(finalBinaryValue, 2); // 杞崲涓�0杩涘埗 + + return finalDecimalValue; } /// <summary> @@ -1758,7 +1876,7 @@ if (result.result[0] == 1) { //鍒ゆ柇3妤煎彔鐩樿捣鐐规槸鍚︽湁浠诲姟鍗犵敤锛屾病鏈夊垯鐢熸垚浠诲姟 - if (ProcessHelper.CheckStartFree(plc.location)) + if (ProcessHelper.CheckStartFree(plc.location)) { string wmstaskno = ""; string traycode = ""; @@ -2804,11 +2922,11 @@ //info.productType = RemoveNull(GetTrayCode(result.Skip(50).Take(10).ToArray()).Trim().ToString()); //info.materialCode = RemoveNull(GetTrayCode(result.Skip(60).Take(20).ToArray()).Trim().ToString()); - info.lotNo = RemoveNull(GetTrayCode(result.Skip(35).Take(20).ToArray()).Trim().ToString()); - info.productType = RemoveNull(GetTrayCode(result.Skip(55).Take(10).ToArray()).Trim().ToString()); - info.materialCode = RemoveNull(GetTrayCode(result.Skip(65).Take(15).ToArray()).Trim().ToString()); - info.materialName = RemoveNull(GetTrayCode(result.Skip(80).Take(20).ToArray()).Trim().ToString()); - info.measurementUnit = RemoveNull(GetTrayCode(result.Skip(100).Take(5).ToArray()).Trim().ToString()); + info.lotNo =RemoveNull(GetTrayCode(result.Skip(35).Take(20).ToArray()).Trim().ToString()).TrimStart(); + info.productType = RemoveNull(GetTrayCode(result.Skip(55).Take(10).ToArray()).Trim().ToString()).TrimStart(); + info.materialCode = RemoveNull(GetTrayCode(result.Skip(65).Take(15).ToArray()).Trim().ToString()).TrimStart(); + info.materialName = RemoveNull(GetTrayCode(result.Skip(80).Take(20).ToArray()).Trim().ToString()).TrimStart(); + info.measurementUnit = RemoveNull(GetTrayCode(result.Skip(100).Take(5).ToArray()).Trim().ToString()).TrimStart(); CMMLog.Info($"鏁版嵁澶勭悊娴佺▼锛氬寘瑁呮満鏃燤ES鎯呭喌涓嬶紝鑾峰彇浠ュ線MES浼犺緭鐨勬暟鎹紝鏂拌幏寰楁暟鎹紝lotNo:{info.lotNo},productType:{info.productType},materialCode:{info.materialCode},materialName:{info.materialName},measurementUnit:{info.measurementUnit}"); @@ -3653,7 +3771,7 @@ if (result != null && result.errCode == 0 && result.result.Count() > 0) { //1锛氬彇鏂�- if (result.result[0] == 1) + if (result.result[0] == 1 || result.result[0] == 5) { string PlcBit02 = Settings.GetPlcInfo().Where(a => a.deviceType == "22").FirstOrDefault().location; //鍖呰涓嬬嚎浠诲姟锛岀粓鐐逛负澶嶇О浣嶇疆锛堣繖閲屽垽鏂寘瑁呮満璧风偣锛屽绉拌捣鐐圭粓鐐瑰潎鏃犱换鍔★紝鍒欐帹閫佷换鍔★級 @@ -3710,7 +3828,7 @@ port = pmInfo.port, data = 4 }); - + CMMLog.Debug($"锛堝洓閽磋溅闂达級鍖呰涓嬬嚎娴佺▼-{pmInfo.location}锛歩p:{pmInfo.ip},port:{pmInfo.port},addr:{pmInfo.writeAddr},鍐欏叆4"); //string timeStamp = ProcessHelper.GetTimeStamp(31, 1, 1); //tray.trayCode = "VW" + timeStamp; //MongoDBSingleton.Instance.Update<MachineInfoTetracobalt>(Query.EQ("_id", tray._id), Update.Set("trayCode", tray.trayCode), UpdateFlags.None); @@ -3724,22 +3842,57 @@ } else if (tray.trayCode != "0" && !string.IsNullOrEmpty(tray.trayCode)) { - HHAmsExecuteResult req = AMSHelper.CreateTask(DateTime.Now.Ticks.ToString(), pmInfo.location, PlcBit02, "3妤煎寘瑁呭彇鏂�鍥涢挻)", 0, tray.trayCode, timeStamp); - if (req.success) + if (result.result[0] == 1) { - string weight = (double.Parse(tray.oneTrayWeight) / 100).ToString(); - ERPService.packageInfo(tray.machineNo, tray.trayCode, tray.lotNo, weight); - - //璁板綍鎵樼洏绫诲瀷 - var trayTypeInfo = MongoDBSingleton.Instance.FindOne<trayTypeTable>(Query.EQ("locCode", pmInfo.location), "trayTypeTable"); - if(trayTypeInfo == null) + HHAmsExecuteResult req = AMSHelper.CreateTask(DateTime.Now.Ticks.ToString(), pmInfo.location, PlcBit02, "3妤煎寘瑁呭彇鏂�鍥涢挻)", 0, tray.trayCode, timeStamp); + if (req.success) { - MongoDBSingleton.Instance.Insert<trayTypeTable>(new trayTypeTable + string weight = (double.Parse(tray.oneTrayWeight) / 100).ToString(); + ERPService.packageInfo(tray.machineNo, tray.trayCode, tray.lotNo, weight); + + //璁板綍鎵樼洏绫诲瀷 + var trayTypeInfo = MongoDBSingleton.Instance.FindOne<trayTypeTable>(Query.EQ("locCode", pmInfo.location), "trayTypeTable"); + if (trayTypeInfo == null) { - locCode = pmInfo.location, - trayType = tray.trayType - }); + MongoDBSingleton.Instance.Insert<trayTypeTable>(new trayTypeTable + { + locCode = pmInfo.location, + trayType = tray.trayType + }); + } } + } + else + { + //var writeRes0 = OITcpHelper.RegisterWriteOutPut(new OITcpHelper.RegisterWriteOutPutModel + //{ + // host = pmInfo.ip, + // addr = pmInfo.writeAddr, + // data = 5,//鍘熷厛鏄�,鍗曚釜鍐欏叆 + // port = pmInfo.port + //}); + + //浜哄伐妯″紡锛屾棤闇�敓鎴愪换鍔�+ //鍒犻櫎MachineInfoTetracobalt琛ㄤ腑鐨勬暟鎹�+ MongoDBSingleton.Instance.Remove<MachineInfoTetracobalt>(Query.And(Query.EQ("machineNo", pmInfo.location), Query.EQ("trayCode", tray.trayCode)), "MachineInfoTetracobalt", RemoveFlags.None); + + //鍒犻櫎 MachineInfoTwoTetracobalt 閲嶅鐨勬暟鎹�+ var twoInfo = MongoDBSingleton.Instance.Find<MachineInfoTwoTetracobalt>(Query.And(Query.EQ("lotNo", tray.lotNo), Query.EQ("packageCode",tray.packageCode)), "MachineInfoTwoTetracobalt"); + if(twoInfo.Count > 1) + { + foreach(var a in twoInfo) + { + MongoDBSingleton.Instance.Remove<MachineInfoTwoTetracobalt>(Query.EQ("_id", a._id),RemoveFlags.None); + if (MongoDBSingleton.Instance.Find<MachineInfoTwoTetracobalt>(Query.And(Query.EQ("lotNo", tray.lotNo), Query.EQ("packageCode", tray.packageCode)), "MachineInfoTwoTetracobalt").Count == 1) + { + break; + } + } + } + + //璁板綍鍖呰闂翠笅鏂欎俊鎭�+ string Weight = (decimal.Parse(tray.oneTrayWeight) / 100).ToString("F2"); + MongoDBSingleton.Instance.Insert<packageInfoModel>(new packageInfoModel { machineNo = tray.machineNo, trayCode = tray.trayCode, batchNo = tray.lotNo, time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), weight = Weight }); } } } @@ -4144,107 +4297,199 @@ internal static void CheckPackingLineFullThree(Settings.PlcInfo plc) { - string trayCode = ""; var result = OITcpHelper.RegisterReadOutPut(new OITcpHelper.RegisterReadOutPutModel { - dataNum = 25, - addr = plc.readAddr, + dataNum = 1, + addr = plc.readAddr + 1, host = plc.ip, port = plc.port }); + CMMLog.Info($"涓嬬嚎鍙�ip锛歿plc.ip}锛宲ort:{plc.port},addr:{plc.writeAddr + 1}锛宺euslt:{JsonConvert.SerializeObject(result)}."); 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) + var resultTime = OITcpHelper.RegisterReadOutPut(new OITcpHelper.RegisterReadOutPutModel { - 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琛ㄤ腑鏍规嵁鐗╂枡缂栫爜鑾峰彇 + dataNum = 26, + addr = plc.readAddr + 8, + host = plc.ip, + port = plc.port + }); + CMMLog.Info($"涓嬬嚎鍙�ip锛歿plc.ip}锛宲ort:{plc.port},addr:{plc.writeAddr + 8}锛宺euslt:{JsonConvert.SerializeObject(resultTime)}."); + if (resultTime.errCode == 0) + { + string timeCuoData = (resultTime.result[0] * 65536 + resultTime.result[1]).ToString(); + string empCode = RemoveNull(GetTrayCode(resultTime.result.Skip(2).Take(5).ToArray()));//鍛樺伐缂栫爜 + string machineCode = RemoveNull(GetTrayCode(resultTime.result.Skip(10).Take(1).ToArray()));//鍖呰鏈哄彿 + int needWeight = Convert.ToInt32(Completion(resultTime.result[11]) + Completion(resultTime.result[12]), 2);//浜у搧闇�眰閲嶉噺 + int oneWeight = Convert.ToInt32(Completion(resultTime.result[13]) + Completion(resultTime.result[14]), 2);//鍗曟墭姣涢噸 + int readWeight = Convert.ToInt32(Completion(resultTime.result[15]) + Completion(resultTime.result[16]), 2);//鍗曟墭鍑�噸 + int fcWeight = Convert.ToInt32(Completion(resultTime.result[17]) + Completion(resultTime.result[18]), 2);//鍗曟墭澶嶇О閲嶉噺 + int trayType = Convert.ToInt32(Completion(resultTime.result[19]), 2);//鎵樼洏绫诲瀷 + int addState = Convert.ToInt32(Completion(resultTime.result[20]), 2);//鍙犲寘灞傛暟 + int bagNumber = Convert.ToInt32(Completion(resultTime.result[21]), 2);//琚嬪彿 + int productTime = Convert.ToInt32(Completion(resultTime.result[22]) + Completion(resultTime.result[23]), 2);//鐢熶骇鏃ユ湡 result = OITcpHelper.RegisterReadOutPut(new OITcpHelper.RegisterReadOutPutModel { - dataNum = 15, - addr = plc.readAddr + 131, + dataNum = 70, + addr = plc.readAddr + 110, 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 + CMMLog.Info($"涓嬬嚎鍙o紝ip锛歿plc.ip}锛宲ort:{plc.port},addr:{plc.readAddr + 140},result:{JsonConvert.SerializeObject(result)}"); + string lotNo = RemoveNull(GetTrayCode(result.result.Skip(0).Take(20).ToArray()).Trim().ToString()); + string materialCode = RemoveNull(GetTrayCode(result.result.Skip(30).Take(15).ToArray()).Trim().ToString()); + CMMLog.Info($"涓嬬嚎鍙o細timeCuoData:{timeCuoData},empCode:{empCode},machineCode:{machineCode},needWeight:{needWeight},oneWeight:{oneWeight},readWeight:{readWeight}" + + $",fcWeight:{fcWeight},trayType:{trayType},addState:{addState},bagNumber:{bagNumber},productTime:{productTime},TimeCuo:{timeCuoData}"); + var timeTwo = MongoDBSingleton.Instance.FindOne<TimeCuoInfoComTwo>(Query.EQ("TimeCuo", timeCuoData), "TimeCuoInfoComTwo"); + if (timeTwo == null) { - 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) + MongoDBSingleton.Instance.Insert<TimeCuoInfoComTwo>(new TimeCuoInfoComTwo { - 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); + timeCuo = timeCuoData, + employeeId = empCode, + packingMachineNumber = machineCode, + needWeight = needWeight, + oneWeight = oneWeight, + realWeight = readWeight, + FCWeight = fcWeight, + trayType = trayType.ToString(), + isFold = addState, + bagNumber = bagNumber, + productData = productTime.ToString(), + TimeCuo = timeCuoData, + lotNo = lotNo, + materialCode = materialCode + }, "TimeCuoInfoComTwo"); } + else + { + var query1 = Query.EQ("TimeCuo", timeCuoData); + UpdateBuilder updateBuilder = Update.Set("employeeId", empCode).Set("packingMachineNumber", machineCode).Set("needWeight", needWeight) + .Set("oneWeight", oneWeight).Set("realWeight", readWeight).Set("FCWeight", fcWeight).Set("trayType", trayType.ToString()) + .Set("isFold", addState).Set("bagNumber", bagNumber).Set("productData", productTime.ToString()).Set("TimeCuo", timeCuoData) + .Set("materialCode", materialCode); + MongoDBSingleton.Instance.Update<TimeCuoInfoComTwo>(query1, updateBuilder, "TimeCuoInfoComTwo", UpdateFlags.None); + } + string wmstaskno = ""; + WMSHelper.WMSIn(plc.location, "time", ref wmstaskno, ref timeCuoData, timeCuoData, empCode, true); } } } - else - { - CMMLog.Info("涓嬬嚎鍙h澶囨湭閰嶇疆"); - } + + + //string trayCode = ""; + //var result = OITcpHelper.RegisterReadOutPut(new OITcpHelper.RegisterReadOutPutModel + //{ + // dataNum = 25, + // addr = plc.readAddr, + // host = plc.ip, + // port = plc.port + //}); + //CMMLog.Info($"璐存爣鏈鸿幏鍙栦俊鎭紝ip锛歿plc.ip}锛宲ort:{plc.port},addr:{plc.readAddr},result:{JsonConvert.SerializeObject(result)}"); + //if(result != null && result.errCode == 0) + //{ + // if (result.result[0] == 1) + // { + // //鑾峰彇鐗╂枡淇℃伅 鏍规嵁鎵樼洏鐮佸尯鍒�+ // trayCode = RemoveNull(GetTrayCode(result.result.Skip(6).Take(3).ToArray()));//鎵樼洏鐮�+ // + // if (!string.IsNullOrEmpty(trayCode)) + // { + // 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 + // }); + // CMMLog.Info($"璐存爣鏈猴紝ip锛歿plc.ip}锛宲ort:{plc.port},addr:{plc.readAddr + 131},result:{JsonConvert.SerializeObject(result)}"); + // 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($"璐存爣鏈猴紝鍐欏叆 ip锛歿plc.ip}锛宲ort:{plc.port},addr:{plc.writeAddr}鐨勬暟鎹负1."); + // } + // } + // } + //} + // + //var xxPlc = Settings.GetPlcInfo().Where(a => a.deviceType == "27" && a.enable == 1).FirstOrDefault(); + //if(xxPlc != null) + //{ + // if (CheckStartFree(plc.location)) + // { + // result = OITcpHelper.RegisterReadOutPut(new OITcpHelper.RegisterReadOutPutModel + // { + // dataNum = 1, + // addr = plc.readAddr + 1, + // host = plc.ip, + // port = plc.port + // }); + // + // CMMLog.Debug($"涓嬬嚎鍙�ip锛歿plc.ip}锛宲ort:{plc.port},addr:{plc.writeAddr + 1}锛宺euslt:{JsonConvert.SerializeObject(result)}."); + // 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 + // }); + // CMMLog.Debug($"涓嬬嚎鍙�ip锛歿plc.ip}锛宲ort:{plc.port},addr:{plc.writeAddr + 8}锛宺euslt:{JsonConvert.SerializeObject(result)}."); + // 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