From 1894ccc4014d813ea60cf276ac066e5870a82566 Mon Sep 17 00:00:00 2001
From: kingno <30263@KINGNO>
Date: 星期四, 18 九月 2025 13:51:20 +0800
Subject: [PATCH] 简化代码
---
src/Bro.M141_AOI1.Process/AOI1Process.cs | 577 ---------------------------------------------------------
1 files changed, 0 insertions(+), 577 deletions(-)
diff --git a/src/Bro.M141_AOI1.Process/AOI1Process.cs b/src/Bro.M141_AOI1.Process/AOI1Process.cs
index 0e2bd6f..2a4d05f 100644
--- a/src/Bro.M141_AOI1.Process/AOI1Process.cs
+++ b/src/Bro.M141_AOI1.Process/AOI1Process.cs
@@ -76,10 +76,6 @@
Plc1.WriteSingleAddress(ConfigAOI1.Plcover, 1, out _);
LogAsync(DateTime.Now, EnumHelper.LogLevel.Detail, $"浜у搧璁℃椂缁撴潫 plc鏂欏彿 {pronum} 缁撴灉{pronum + (result[0] ? 1 : 2)},{pronum + (result[1] ? 1 : 2)},{pronum + (result[2] ? 1 : 2)} 鎬荤敤鏃� {(DateTime.Now - dicplctime[pronum / 10]).TotalMilliseconds}ms ");
- Thread.Sleep(100);
- Plc1.WriteSingleAddress(ConfigAOI1.Finresult1, 0, out _);
- Plc1.WriteSingleAddress(ConfigAOI1.Finresult2, 0, out _);
- Plc1.WriteSingleAddress(ConfigAOI1.Finresult3, 0, out _);
}
else
@@ -91,586 +87,13 @@
Plc1.WriteSingleAddress(ConfigAOI1.Plcover, 1, out _);
LogAsync(DateTime.Now, EnumHelper.LogLevel.Detail, $"浜у搧璁℃椂缁撴潫 plc鏂欏彿 {pronum} 缁撴灉{pronum + 2},{pronum + 2},{pronum + 2} 鎬荤敤鏃� {(DateTime.Now - dicplctime[pronum/10]).TotalMilliseconds}ms ");
LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"娴嬭瘯缁撴灉鏁伴噺寮傚父!!!!!!!!");
-
- Thread.Sleep(100);
- Plc1.WriteSingleAddress(ConfigAOI1.Finresult1, 0, out _);
- Plc1.WriteSingleAddress(ConfigAOI1.Finresult2, 0, out _);
- Plc1.WriteSingleAddress(ConfigAOI1.Finresult3, 0, out _);
}
-
}
catch
{
}
-
- //else if (Postion.Contains("2"))
- //{
- // Plc1.WriteSingleAddress(ConfigAOI1.P2over, result, out _);
- //}
- //else if (Postion.Contains("3"))
- //{
- // Plc1.WriteSingleAddress(ConfigAOI1.P3over, result, out _);
- //}
- //else
- //{
- // Plc1.WriteSingleAddress(ConfigAOI1.Finresult, result, out _);
- //}
}
-
-
-
- //[ProcessMethod("", "PositionCheck_P1_F", "宸ヤ綅1妫�娴嬮鎷�", InvokeType.TestInvoke)]
- //public ResponseMessage PositionCheck_P1_F(IOperationConfig config, IDevice invokeDevice, IDevice sourceDevice)
- //{
- // if (config.TriggerValue == 1)
- // {
- // Productcode = DateTime.Now.ToString("yyyyMMddHHmmss");
- // }
-
- // config.TriggerStr = "1#,1,Str," + Productcode;
- // ResponseMessage msg = new ResponseMessage();
- // msg.Result = 1;
- // msg.IsReply = false;
- // List<MeasureBind> measureBinds = new List<MeasureBind>();
- // string inputSequence = "";
-
- // try
- // {
- // RunImageCheckPreTreat_plc(config, out measureBinds, out inputSequence);
- // }
- // catch (Exception ex)
- // {
- // LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"妫�娴嬮澶勭悊寮傚父锛寋ex.GetExceptionMessage()}");
- // msg.Result = -1;
- // msg.Message = ex.Message;
- // msg.IsReply = false;
- // return msg;
- // }
-
- // int measureNums = measureBinds.Count;
- // bool WaitSignalstate = true;
- // //_isLastCheckFlag = false;
- // measureBinds.GroupBy(u => u.CameraId).AsParallel().ForAll(c =>
- // {
- // var camera = DeviceCollection.FirstOrDefault(u => u.Id == c.Key) as CameraBase;
- // foreach (var i in c.ToList().OrderBy(u => u.ImageIndex).ToList())
- // {
- // string index = (i.ImageIndex + 1).ToString();
- // if (ConfigAOI1.P1SFstate)
- // {
- // if (!WaitSignal(index))
- // {
- // WaitSignalstate = false;
- // break;
- // }
- // }
- // var products = i.ProductIndices.Select(pi =>
- // {
- // return FindProductBySequence($"{inputSequence}_{pi}", true);
- // }).ToList();
-
- // IImageSet imgSet = null;
- // try
- // {
- // imgSet = CollectHImage(camera, i.SnapshotOpConfig);
- // lock (trigerStr)
- // {
- // trigerStr.Add(index + "over");
- // }
- // if (imgSet == null)
- // {
- // LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"宸ヤ綅1{camera?.Name}鍙栧儚{i?.ImageIndex}澶辫触 鍥惧儚涓虹┖");
- // break;
- // }
- // }
- // catch (Exception ex)
- // {
- // LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"宸ヤ綅1{camera?.Name}鍙栧儚{i?.ImageIndex}寮傚父锛寋ex.ToString()}");
- // break;
- // }
-
- // RunImageCheckAsync(products, config.TriggerStr, config.TriggerSource, imgSet, i).ContinueWith(t =>
- // {
- // Interlocked.Decrement(ref measureNums);
- // });
- // }
- // });
-
- // if (!WaitSignalstate)
- // {
- // LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"鍥剧墖閲囬泦淇℃伅涓嶅叏");
- // msg.IsReply = false;
- // return msg;
- // }
-
-
- // while (measureNums > 0)
- // {
- // Thread.Sleep(50);
- // }
-
- // //妫�娴嬪畬鎴愬悗娓呯悊鍥剧墖缂撳瓨
- // measureBinds.Select(u => u.CameraId).Distinct().ToList().ForEach(u =>
- // {
- // var camera = DeviceCollection.FirstOrDefault(c => c.Id == u) as CameraBase;
- // camera.ClearImageBufferQueue();
- // LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"{camera.Name}鐩告満宸ヤ綅1妫�娴嬪悗娓呯悊缂撳瓨");
- // });
-
- // string positionName = measureBinds[0].WorkPosition;
- // var pList = CheckPositionDoneAsync_plc(positionName, inputSequence, config, new List<string>()).GetAwaiter().GetResult();
-
- // return msg;
- //}
-
-
- //[ProcessMethod("", "PositionCheck_P1_photo", "宸ヤ綅1鎷嶇収", InvokeType.TestInvoke)]
- //public ResponseMessage PositionCheck_P1_photo(IOperationConfig config, IDevice invokeDevice, IDevice sourceDevice)
- //{
- // ResponseMessage msg = new ResponseMessage();
- // msg.IsReply = false;
-
- // int index = config.TriggerValue;
- // if (index == 1)
- // {
- // trigerStr.Clear();
- // }
- // lock (trigerStr)
- // {
- // trigerStr.Add(index.ToString());
- // }
-
- // WaitSignal(index + "over");
- // ReplyPlcData("P1", index);
- // return msg;
- //}
-
-
-
-
- //[ProcessMethod("", "PositionCheck_P2_F", "宸ヤ綅2妫�娴嬮鎷�", InvokeType.TestInvoke)]
- //public ResponseMessage PositionCheck_P2_F(IOperationConfig config, IDevice invokeDevice, IDevice sourceDevice)
- //{
-
- // config.TriggerStr = "2#,1,Str," + Productcode;
- // ResponseMessage msg = new ResponseMessage();
- // msg.Result = 1;
- // msg.IsReply = false;
- // List<MeasureBind> measureBinds = new List<MeasureBind>();
- // string inputSequence = "";
-
- // try
- // {
- // RunImageCheckPreTreat_plc(config, out measureBinds, out inputSequence);
- // }
- // catch (Exception ex)
- // {
- // LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"妫�娴嬮澶勭悊寮傚父锛寋ex.GetExceptionMessage()}");
- // msg.Result = -1;
- // msg.Message = ex.Message;
- // msg.IsReply = false;
- // return msg;
- // }
-
-
- // int measureNums = measureBinds.Count;
- // bool WaitSignalstate = true;
- // //_isLastCheckFlag = false;
- // measureBinds.GroupBy(u => u.CameraId).AsParallel().ForAll(c =>
- // {
- // var camera = DeviceCollection.FirstOrDefault(u => u.Id == c.Key) as CameraBase;
- // foreach (var i in c.ToList().OrderBy(u => u.ImageIndex).ToList())
- // {
- // string index = (i.ImageIndex + 1).ToString();
- // if (ConfigAOI1.P2SFstate)
- // {
- // if (!WaitSignal(index, "p2"))
- // {
- // WaitSignalstate = false;
- // break;
- // }
- // }
- // var products = i.ProductIndices.Select(pi =>
- // {
- // return FindProductBySequence($"{inputSequence}_{pi}", true);
- // }).ToList();
-
- // IImageSet imgSet = null;
- // try
- // {
- // imgSet = CollectHImage(camera, i.SnapshotOpConfig);
- // lock (trigerStr2)
- // {
- // trigerStr2.Add(index + "over");
- // }
- // if (imgSet == null)
- // {
- // LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"宸ヤ綅2{camera?.Name}鍙栧儚{i?.ImageIndex}澶辫触 鍥惧儚涓虹┖");
- // break;
- // }
- // }
- // catch (Exception ex)
- // {
- // LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"宸ヤ綅2{camera?.Name}鍙栧儚{i?.ImageIndex}寮傚父锛寋ex.ToString()}");
- // break;
- // }
-
- // RunImageCheckAsync(products, config.TriggerStr, config.TriggerSource, imgSet, i).ContinueWith(t =>
- // {
- // Interlocked.Decrement(ref measureNums);
- // });
- // }
- // });
-
- // if (!WaitSignalstate)
- // {
- // LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"鍥剧墖閲囬泦淇℃伅涓嶅叏");
- // msg.IsReply = false;
- // return msg;
- // }
-
-
- // while (measureNums > 0)
- // {
- // Thread.Sleep(50);
- // }
-
- // //妫�娴嬪畬鎴愬悗娓呯悊鍥剧墖缂撳瓨
- // measureBinds.Select(u => u.CameraId).Distinct().ToList().ForEach(u =>
- // {
- // var camera = DeviceCollection.FirstOrDefault(c => c.Id == u) as CameraBase;
- // camera.ClearImageBufferQueue();
- // LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"{camera.Name}鐩告満宸ヤ綅2妫�娴嬪悗娓呯悊缂撳瓨");
- // });
-
- // string positionName = measureBinds[0].WorkPosition;
- // var pList = CheckPositionDoneAsync_plc(positionName, inputSequence, config, new List<string>()).GetAwaiter().GetResult();
-
- // return msg;
- //}
-
-
- //[ProcessMethod("", "PositionCheck_P2_photo", "宸ヤ綅2鎷嶇収", InvokeType.TestInvoke)]
- //public ResponseMessage PositionCheck_P2_photo(IOperationConfig config, IDevice invokeDevice, IDevice sourceDevice)
- //{
- // ResponseMessage msg = new ResponseMessage();
- // msg.IsReply = false;
-
- // int index = config.TriggerValue;
- // if (index == 1)
- // {
- // trigerStr2.Clear();
- // }
- // lock (trigerStr2)
- // {
- // trigerStr2.Add(index.ToString());
- // }
-
- // WaitSignal(index + "over", "p2");
- // ReplyPlcData("P2", index);
- // return msg;
- //}
-
-
- //[ProcessMethod("", "PositionCheck_P3_F", "宸ヤ綅3妫�娴嬮鎷�", InvokeType.TestInvoke)]
- //public ResponseMessage PositionCheck_P3_F(IOperationConfig config, IDevice invokeDevice, IDevice sourceDevice)
- //{
- // config.TriggerStr = "3#,1,Str," + Productcode;
- // ResponseMessage msg = new ResponseMessage();
- // msg.Result = 1;
- // msg.IsReply = false;
- // List<MeasureBind> measureBinds = new List<MeasureBind>();
- // string inputSequence = "";
-
- // try
- // {
- // RunImageCheckPreTreat_plc(config, out measureBinds, out inputSequence);
- // }
- // catch (Exception ex)
- // {
- // LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"妫�娴嬮澶勭悊寮傚父锛寋ex.GetExceptionMessage()}");
- // msg.Result = -1;
- // msg.Message = ex.Message;
- // msg.IsReply = false;
- // return msg;
- // }
- // int measureNums = measureBinds.Count;
- // bool WaitSignalstate = true;
- // //_isLastCheckFlag = false;
- // measureBinds.GroupBy(u => u.CameraId).AsParallel().ForAll(c =>
- // {
- // var camera = DeviceCollection.FirstOrDefault(u => u.Id == c.Key) as CameraBase;
- // foreach (var i in c.ToList().OrderBy(u => u.ImageIndex).ToList())
- // {
- // string index = (i.ImageIndex + 1).ToString();
- // if (ConfigAOI1.P3SFstate)
- // {
- // if (!WaitSignal(index, "p3"))
- // {
- // WaitSignalstate = false;
- // break;
- // }
- // }
- // var products = i.ProductIndices.Select(pi =>
- // {
- // return FindProductBySequence($"{inputSequence}_{pi}", true);
- // }).ToList();
-
- // IImageSet imgSet = null;
- // try
- // {
- // imgSet = CollectHImage(camera, i.SnapshotOpConfig);
- // lock (trigerStr3)
- // {
- // trigerStr3.Add(index + "over");
- // }
- // if (imgSet == null)
- // {
- // LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"宸ヤ綅1{camera?.Name}鍙栧儚{i?.ImageIndex}澶辫触 鍥惧儚涓虹┖");
- // break;
- // }
- // }
- // catch (Exception ex)
- // {
- // LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"宸ヤ綅1{camera?.Name}鍙栧儚{i?.ImageIndex}寮傚父锛寋ex.ToString()}");
- // break;
- // }
-
- // RunImageCheckAsync(products, config.TriggerStr, config.TriggerSource, imgSet, i).ContinueWith(t =>
- // {
- // Interlocked.Decrement(ref measureNums);
- // });
- // }
- // });
-
- // if (!WaitSignalstate)
- // {
- // LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"鍥剧墖閲囬泦淇℃伅涓嶅叏");
- // msg.IsReply = false;
- // return msg;
- // }
-
-
- // while (measureNums > 0)
- // {
- // Thread.Sleep(50);
- // }
-
- // //妫�娴嬪畬鎴愬悗娓呯悊鍥剧墖缂撳瓨
- // measureBinds.Select(u => u.CameraId).Distinct().ToList().ForEach(u =>
- // {
- // var camera = DeviceCollection.FirstOrDefault(c => c.Id == u) as CameraBase;
- // camera.ClearImageBufferQueue();
- // LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"{camera.Name}鐩告満宸ヤ綅1妫�娴嬪悗娓呯悊缂撳瓨");
- // });
-
- // string positionName = measureBinds[0].WorkPosition;
- // var pList = CheckPositionDoneAsync_plc(positionName, inputSequence, config, new List<string>()).GetAwaiter().GetResult();
-
- // return msg;
- //}
-
-
- //[ProcessMethod("", "PositionCheck_P3_photo", "宸ヤ綅3鎷嶇収", InvokeType.TestInvoke)]
- //public ResponseMessage PositionCheck_P3_photo(IOperationConfig config, IDevice invokeDevice, IDevice sourceDevice)
- //{
- // ResponseMessage msg = new ResponseMessage();
- // msg.IsReply = false;
-
- // int index = config.TriggerValue;
- // if (index == 1)
- // {
- // trigerStr3.Clear();
- // }
- // lock (trigerStr3)
- // {
- // trigerStr3.Add(index.ToString());
- // }
-
- // WaitSignal(index + "over", "p3");
- // ReplyPlcData("P3", index);
- // return msg;
- //}
-
- //public bool WaitSignal(string index, string p = "p1")
- //{
- // DateTime dt = DateTime.Now;
- // while ((DateTime.Now - dt).TotalMilliseconds < ConfigAOI1.PhotolayoutTime)
- // {
- // if (p.Equals("p1"))
- // {
- // lock (trigerStr)
- // {
- // if (trigerStr.Contains(index))
- // {
- // return true;
- // }
- // }
- // }
- // else if (p == "p2")
- // {
- // lock (trigerStr2)
- // {
- // if (trigerStr2.Contains(index))
- // {
- // return true;
- // }
- // }
- // }
- // else if (p == "p3")
- // {
- // lock (trigerStr3)
- // {
- // if (trigerStr3.Contains(index))
- // {
- // return true;
- // }
- // }
- // }
- // Thread.Sleep(50);
- // }
- // return false;
- //}
-
- //List<string> trigerStr = new List<string>();
- //List<string> trigerStr2 = new List<string>();
- //List<string> trigerStr3 = new List<string>();
-
-
-
-
- //[ProcessMethod("", "PositionCheck_P2", "宸ヤ綅2妫�娴�", InvokeType.TestInvoke)]
- //public ResponseMessage PositionCheck_P2(IOperationConfig config, IDevice invokeDevice, IDevice sourceDevice)
- //{
- // config.TriggerStr = "2#," + config.TriggerValue + ",Str," + Productcode;
- // ResponseMessage msg = RunImageCheck_plc(config);
- // msg.IsReply = false;
-
- // if (msg.Result != 1)
- // {
- // ReplyPlcData("P2", config.TriggerValue);
- // }
- // return msg;
- //}
-
- //[ProcessMethod("", "PositionCheck_P3", "宸ヤ綅3妫�娴�", InvokeType.TestInvoke)]
- //public ResponseMessage PositionCheck_P3(IOperationConfig config, IDevice invokeDevice, IDevice sourceDevice)
- //{
- // config.TriggerStr = "3#," + config.TriggerValue + ",Str," + Productcode;
- // ResponseMessage msg = RunImageCheck_plc(config);
- // msg.IsReply = false;
-
- // if (msg.Result != 1)
- // {
- // ReplyPlcData("P3", config.TriggerValue);
- // }
- // return msg;
- //}
-
-
- //[ProcessMethod("", "PositionCheck_Fin", "缁撴灉鍙嶉plc", InvokeType.TestInvoke)]
- //public ResponseMessage PositionCheck_Fin(IOperationConfig config, IDevice invokeDevice, IDevice sourceDevice)
- //{
- // config.TriggerStr = "#,UpData," + Productcode;
- // ResponseMessage msg = new ResponseMessage();
-
- // var triggerDatas = config.TriggerStr.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
- // string inputSequence = triggerDatas[triggerDatas.Length - 1];
-
- // var productList = new List<int>() { 1 }.Select(u =>
- // {
- // string sequence = $"{inputSequence}_{u}";
- // return FindProductBySequence(sequence, true);
- // }).ToList();
-
-
- // int waitInterval = 300;
- // int repeatTime = /*M141Config.DetectTimeout / waitInterval+*/2;
-
- // do
- // {
- // if (productList.All(p => !string.IsNullOrWhiteSpace(p.Result)))
- // {
- // break;
- // }
- // else
- // {
- // Thread.Sleep(waitInterval);
- // repeatTime--;
- // }
-
- // if (repeatTime < 0)
- // {
- // LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"浜у搧{string.Join(",", productList.Select(u => u.PID))}妫�娴嬭幏鍙栨眹鎬荤粨鏋滆秴鏃讹紝浣跨敤褰撳墠缁撴灉");
- // break;
- // }
- // } while (true);
-
-
- // var Defaultclass = M141Config.DefectClassCollection.FirstOrDefault(u => u.IsDefault);
- // productList.ForEach(p =>
- // {
- // if (Defaultclass == null)
- // {
- // if (string.IsNullOrEmpty(p.Result))
- // {
- // p.Result = "NG";
- // }
- // }
- // else
- // {
- // if (string.IsNullOrEmpty(p.Result))
- // {
- // p.Result = Defaultclass.ClassName;
- // }
- // }
-
- // var specList = p.Details.SelectMany(u => u.ResultList.SelectMany(r => r.Specs)).ToList();
- // p.Details.SelectMany(u => u.SpecList).ToList().ForEach(s =>
- // {
- // if (!specList.Any(u => u.Code == s.Code))
- // {
- // specList.Add(s);
- // }
- // });
-
- // List<Pointdata> Pointdatas11 = new List<Pointdata>();
-
- // foreach (var item in specList)
- // {
- // try
- // {
- // Pointdatas11.Add(new Pointdata()
- // {
- // Code = item.Code,
- // Value = Convert.ToDouble(item.GetMeasureValueStr()),
- // Stand = item.StandardValue,
- // Min = item.StandardValue - item.Tolrenance_Negative,
- // Max = item.StandardValue + item.Tolrenance_Positive,
- // ispoint = false,
- // });
- // }
- // catch
- // {
-
- // }
- // }
- // M141Codelist.Add(Pointdatas11);
-
- // ReplyPlcData("Fin", p.Result.ToUpper().Contains("NG") ? 2 : 1);
- // });
-
-
-
- // return msg;
- //}
-
-
-
-
-
-
--
Gitblit v1.8.0