From 007782bf44e49b4e3d5166ef361ac9fd03cad9c2 Mon Sep 17 00:00:00 2001 From: kingno <30263@KINGNO> Date: 星期二, 17 六月 2025 13:07:43 +0800 Subject: [PATCH] 合并 --- src/Bro.M141_AOI1.Process/AOI1Process.cs | 157 ++++++++++++++++++++++++++++++++++++---------------- 1 files changed, 109 insertions(+), 48 deletions(-) diff --git a/src/Bro.M141_AOI1.Process/AOI1Process.cs b/src/Bro.M141_AOI1.Process/AOI1Process.cs index 139b24d..fe5e0fe 100644 --- a/src/Bro.M141_AOI1.Process/AOI1Process.cs +++ b/src/Bro.M141_AOI1.Process/AOI1Process.cs @@ -6,12 +6,14 @@ using Bro.M141.Process; using Bro.UI.Model.Winform; using HalconDotNet; +using Newtonsoft.Json; using NPOI.POIFS.Crypt.Dsig; using NPOI.SS.Formula.Functions; using NPOI.XSSF.Streaming.Values; using System.Collections.Concurrent; using System.Net.Sockets; using System.Text.RegularExpressions; +using static Bro.Common.Helper.EnumHelper; using static NPOI.HSSF.Util.HSSFColor; using static Org.BouncyCastle.Crypto.Engines.SM2Engine; using static Org.BouncyCastle.Math.EC.ECCurve; @@ -28,19 +30,28 @@ #endregion AOI1Config ConfigAOI1 => Config as AOI1Config; - TcpClientWrapBase BarcodeScanner = null; - public override void Open() { + + //string configPath = @"C:\Users\30263\Desktop\666.txt"; + + //string _configBackupStr = ""; + //using (StreamReader reader = new StreamReader(configPath, System.Text.Encoding.UTF8)) + //{ + // _configBackupStr = reader.ReadToEnd(); + + //} + + //ProductModel p = JsonConvert.DeserializeObject<ProductModel>(_configBackupStr, new JsonSerializerSettings() { TypeNameHandling = TypeNameHandling.All }); + base.Open(); - BarcodeScanner = DeviceCollection.FirstOrDefault(u => u is TcpClientWrapBase) as TcpClientWrapBase; } + [ProcessMethod("", "PositionCheck_P1", "宸ヤ綅1妫�娴�", InvokeType.TestInvoke)] public ResponseMessage PositionCheck_P1(IOperationConfig config, IDevice invokeDevice, IDevice sourceDevice) { - var positionSet = M141Config.WorkPositionCollection.Where(u => u.IsEnabled).FirstOrDefault(u => u.TriggerValue == "1#"); if (positionSet == null) { @@ -54,6 +65,7 @@ return msg; } + [ProcessMethod("", "PositionCheck_P2", "宸ヤ綅2妫�娴�", InvokeType.TestInvoke)] public ResponseMessage PositionCheck_P2(IOperationConfig config, IDevice invokeDevice, IDevice sourceDevice) @@ -71,6 +83,7 @@ return msg; } + [ProcessMethod("", "PositionCheck_P3", "宸ヤ綅3妫�娴�", InvokeType.TestInvoke)] public ResponseMessage PositionCheck_P3(IOperationConfig config, IDevice invokeDevice, IDevice sourceDevice) @@ -90,78 +103,139 @@ } - [ProcessMethod("ImageCheck", "ReadBarcode", "璇荤爜", InvokeType.TestInvoke)] public ResponseMessage ReadBarcode(IOperationConfig config, IDevice invokeDevice, IDevice sourceDevice) { ResponseMessage msg = new ResponseMessage(); if (config is IImageCheckOperationConfig opConfig) { - var results = opConfig.Products.Select(u => + if (invokeDevice is TcpClientWrapBase BarcodeScanner) { - DetectResult result = new DetectResult(); - result.PID = u.PID; - result.Specs = GetSpecListFromConfigSelection(opConfig.SpecCollection); - return result; - }).ToList(); + var results = opConfig.Products.Select(u => + { + DetectResult result = new DetectResult(); + result.PID = u.PID; + result.Specs = GetSpecListFromConfigSelection(opConfig.SpecCollection); + return result; + }).ToList(); - msg.DataObj = results; + msg.DataObj = results; - string barcode = BarcodeScannerCommunicate(); + string barcode = BarcodeScannerCommunicate(BarcodeScanner); - List<double> ret = new List<double>(); - if ("NOREAD".Equals(barcode.ToUpper())) - { - ret.Add(999); + List<double> ret = new List<double>(); + if ("NOREAD".Equals(barcode.ToUpper())) + { + ret.Add(999); + } + else + { + if (barcode.Split('-').Length > 5) + { + int mh = Plc1.Read(4000, 1, out _)[0]; + string codestr = barcode.Split('-')[4]; + if (codestr == "L") + { + codestr = "10"; + } + + if (codestr.Equals(mh.ToString())) + { + ret.Add(1); + } + else + { + ret.Add(2); + Plc1.WriteSingleAddress(4010, 1, out _);//缁檖lc鎶ヨ + } + } + else + { + ret.Add(999); + } + } + + FillSpecResults(results[0].PID, results[0].Specs, ret, opConfig.Products[0].SEQUENCE); + + + opConfig.Products[0].SN = barcode; + opConfig.Products[0].PID = barcode + "_1"; + opConfig.Products[0].Details.ForEach(u => + { + u.SN = barcode; + u.PID = barcode + "_1"; + u.ResultList.ForEach(x => + { + + x.PID = barcode + "_1"; + + }); + }); + + LogAsync(DateTime.Now, EnumHelper.LogLevel.Action, $"浜у搧{opConfig.Products[0].PID}鏉$爜鑾峰彇涓簕barcode}"); } - else - { - ret.Add(1); - } - - FillSpecResults(results[0].PID, results[0].Specs, ret, opConfig.Products[0].SEQUENCE); - - - opConfig.Products[0].SN = barcode; - opConfig.Products[0].Details.ForEach(u => u.SN = barcode); - - LogAsync(DateTime.Now, EnumHelper.LogLevel.Action, $"浜у搧{opConfig.Products[0].PID}鏉$爜鑾峰彇涓簕barcode}"); - } return msg; } + [ProcessMethod("ImageCheck", "ReadBarcode2", "璇绘爮鍏风爜", InvokeType.TestInvoke)] + public ResponseMessage ReadBarcode2(IOperationConfig config, IDevice invokeDevice, IDevice sourceDevice) + { + ResponseMessage msg = new ResponseMessage(); - private string BarcodeScannerCommunicate() + if (invokeDevice is TcpClientWrapBase BarcodeScanner2) + { + string barcode = BarcodeScannerCommunicate(BarcodeScanner2); + if (string.IsNullOrEmpty(barcode) || "noread".Equals(barcode.ToLower())) + { + LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"鏍忓叿鐮佽幏鍙栧け璐�"); + Plc1.WriteSingleAddress(1524, 2, out _); + Plc1.WriteSingleAddress(1514, 1, out _); + } + else + { + Plc1.WriteSingleAddress(1524, 1, out _); + Plc1.WriteSingleAddress(1514, 1, out _); + ConfigAOI1.basketcode = barcode; + LogAsync(DateTime.Now, EnumHelper.LogLevel.Action, $"鑾峰彇鍒版爮鍏风爜涓簕barcode}"); + } + } + + return msg; + } + + + private string BarcodeScannerCommunicate(TcpClientWrapBase client) { string barcode = ""; for (int i = 0; i < 3; i++) { - if (BarcodeScanner.WriteAndRead("start", out string error, out barcode, true)) + if (client.WriteAndRead("start", out string error, out barcode, true)) { barcode = barcode.Trim(' ', '\r', '\n'); if (CheckBarcodeValid(barcode)) { - LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"{BarcodeScanner.Name}鎵爜瀹屾垚锛屽弽棣坽barcode}"); + LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"{client.Name}鎵爜瀹屾垚锛屽弽棣坽barcode}"); return barcode; } else { - LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"{BarcodeScanner.Name}绗瑊i + 1}鎵爜瀹屾垚锛屽弽棣坽barcode}锛屼笉鏄悎娉曟潯鐮�"); + LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"{client.Name}绗瑊i + 1}鎵爜瀹屾垚锛屽弽棣坽barcode}锛屼笉鏄悎娉曟潯鐮�"); Thread.Sleep(200); } } else { - LogAsync(DateTime.Now, EnumHelper.LogLevel.Error, $"{BarcodeScanner.Name}鎵爜澶辫触锛寋error}"); + LogAsync(DateTime.Now, EnumHelper.LogLevel.Error, $"{client.Name}鎵爜澶辫触锛寋error}"); break; } } return "NOREAD"; } + private bool CheckBarcodeValid(string barcode) { @@ -172,10 +246,6 @@ } return isBarcodeValid; } - - - - [ProcessMethod("ImageCheck", "CheckLineProfile", "妫�娴嬩骇鍝佺嚎杞粨搴�", InvokeType.TestInvoke)] @@ -319,15 +389,6 @@ return msg; } - - - - - - - - - -- Gitblit v1.8.0