From 6a4463810e276b62356d77c88509fa6fa7af65cf Mon Sep 17 00:00:00 2001 From: kingno <30263@KINGNO> Date: 星期三, 23 七月 2025 15:46:33 +0800 Subject: [PATCH] mes数据逻辑上传完善,缺陷代码完善,添加S4工位的S2结果上传Plc的通信日志mes优化 --- src/Bro.M141.Process/M141Process_ImageCheck.cs | 132 +++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 130 insertions(+), 2 deletions(-) diff --git a/src/Bro.M141.Process/M141Process_ImageCheck.cs b/src/Bro.M141.Process/M141Process_ImageCheck.cs index dfcf451..91dc61d 100644 --- a/src/Bro.M141.Process/M141Process_ImageCheck.cs +++ b/src/Bro.M141.Process/M141Process_ImageCheck.cs @@ -9,6 +9,7 @@ using Microsoft.VisualBasic; using Newtonsoft.Json; using Newtonsoft.Json.Linq; +using NPOI.SS.Formula.Functions; using NPOI.SS.UserModel; using NPOI.Util; using NPOI.XSSF.UserModel; @@ -450,7 +451,8 @@ public ResponseMessage ProductDataUpload(IOperationConfig config, IDevice invokeDevice, IDevice sourceDevice) { ResponseMessage msg = new ResponseMessage(); - string inputSequence = Plc1.Read(1536, 1, out _)[0].ToString(); + int numplca = Plc1.Read(1536, 1, out _)[0]; + string inputSequence = numplca.ToString(); var productList = new List<int>() { 1 }.Select(u => { @@ -458,6 +460,10 @@ return FindProductBySequence(sequence, true); }).ToList(); + if (PlcNumForAll == -1) + { + PlcNumForAll = numplca; + } int waitInterval = 300; int repeatTime = M141Config.DetectTimeout / waitInterval; @@ -488,6 +494,9 @@ { ////mysqlhelper.GetS2Result(productList[0].SEQUENCE); Plc1.WriteSingleAddress(1526, mysqlhelper.GetS2Result(productList[0].SEQUENCE) ? 1 : 2, out _); + + LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"浜у搧{string.Join(",", productList.Select(u => u.PID))}妫�娴嬪弽棣坽mysqlhelper.GetS2Result(productList[0].SEQUENCE)}"); + } else { @@ -496,9 +505,128 @@ Plc1.WriteSingleAddress(1516, 1, out _); + //if (M141Config.ISupMES && (M141Config.MESchannel == -1 || M141Config.MESchannel == 1)) + //{ + // if (M141Config.numpro >= 50) + // { + // M141Config.numpro = 0; + // } + + // if (productList[0].Result == "OK") + // { + // M141Config.numpro++; + // } + + // //mqtt.demes(productList[0], M141Config.zwoid); + // string Msgreceice = Task.Run(() => mqtt.MESForProduceAsync(productList[0], M141Config.zwoid, M141Config.numpro)).Result; + // if (Msgreceice == null) + // { + // LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"浜у搧{productList[0].PID}鏁版嵁涓婁紶MES寮傚父 杩斿洖鏁版嵁涓簄ull"); + // } + // else + // { + // try + // { + // var obj = JsonConvert.DeserializeObject<AutoLineMacBarcodeQueueBak>(Msgreceice); + + // if (obj.zstatus == "200") + // { + // LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"浜у搧{productList[0].PID}鏁版嵁涓婁紶MES鎴愬姛 {Msgreceice}"); + // } + // else + // { + // LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"浜у搧{productList[0].PID}鏁版嵁涓婁紶MES澶辫触 {Msgreceice}"); + // } + // } + // catch + // { + // LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"浜у搧{productList[0].PID}鏁版嵁涓婁紶MES寮傚父 {Msgreceice}"); + // } + // } + + + + // lock (plcnumlock) + // { + // int differ = numplca - PlcNumForAll; + // if (differ > 1) + // { + // for (int i = PlcNumForAll + 1; i < numplca; i++) + // { + // try + // { + // var plist = mysqlhelper.GetProductList(i + "_1"); + // ProductModel newp = new ProductModel(); + // newp.SEQUENCE = plist[0].SEQUENCE; + // newp.PID = plist[0].PID; + // newp.BasketCode = plist[0].BasketCode; + // newp.Result = "NG"; + // newp.SN = plist[0].SN; + // var tems = Task.Run(() => mqtt.MESForProduceAsync(newp, M141Config.zwoid, M141Config.numpro)).Result; + + // } + // catch + // { + + // } + // } + // } + // else if (differ != -29998) + // { + // for (int i = PlcNumForAll + 1; i <= 29999; i++) + // { + // try + // { + // var plist = mysqlhelper.GetProductList(i + "_1"); + // ProductModel newp = new ProductModel(); + // newp.SEQUENCE = plist[0].SEQUENCE; + // newp.PID = plist[0].PID; + // newp.BasketCode = plist[0].BasketCode; + // newp.Result = "NG"; + // newp.SN = plist[0].SN; + // var tems = Task.Run(() => mqtt.MESForProduceAsync(newp, M141Config.zwoid, M141Config.numpro)).Result; + + // } + // catch + // { + + // } + // } + + + + // for (int i = 1; i < numplca; i++) + // { + // try + // { + // var plist = mysqlhelper.GetProductList(i + "_1"); + // ProductModel newp = new ProductModel(); + // newp.SEQUENCE = plist[0].SEQUENCE; + // newp.PID = plist[0].PID; + // newp.BasketCode = plist[0].BasketCode; + // newp.Result = "NG"; + // newp.SN = plist[0].SN; + // var tems = Task.Run(() => mqtt.MESForProduceAsync(newp, M141Config.zwoid, M141Config.numpro)).Result; + + // } + // catch + // { + + // } + // } + + + // } + // PlcNumForAll = numplca; + // } + + //} + return msg; } + object plcnumlock = new object(); + int PlcNumForAll = -1; private bool _isDemoStarted = false; [ProcessMethod("OfflineDemo", "OfflineDemo", "绂荤嚎娴嬭瘯", InvokeType.CalibInvoke)] @@ -552,7 +680,7 @@ continue; } - var sn = nameDatas[0]+"_1"; + var sn = nameDatas[0] + "_1"; var imageSeq = nameDatas[2][^1].ToString(); var measureBind = M141Config.MeasureBindCollection.FirstOrDefault(u => u.ImageSaveSeq == imageSeq); -- Gitblit v1.8.0