| | |
| | | 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; |
| | |
| | | #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) |
| | | { |
| | |
| | | |
| | | return msg; |
| | | } |
| | | |
| | | |
| | | [ProcessMethod("", "PositionCheck_P2", "工位2检测", InvokeType.TestInvoke)] |
| | | public ResponseMessage PositionCheck_P2(IOperationConfig config, IDevice invokeDevice, IDevice sourceDevice) |
| | |
| | | |
| | | return msg; |
| | | } |
| | | |
| | | |
| | | [ProcessMethod("", "PositionCheck_P3", "工位3检测", InvokeType.TestInvoke)] |
| | | public ResponseMessage PositionCheck_P3(IOperationConfig config, IDevice invokeDevice, IDevice sourceDevice) |
| | |
| | | } |
| | | |
| | | |
| | | |
| | | [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 _);//给plc报警 |
| | | } |
| | | } |
| | | 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) |
| | | { |
| | |
| | | } |
| | | return isBarcodeValid; |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | [ProcessMethod("ImageCheck", "CheckLineProfile", "检测产品线轮廓度", InvokeType.TestInvoke)] |
| | |
| | | |
| | | return msg; |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |