| | |
| | | using Bro.Common.Base; |
| | | using Bro.Common.Factory; |
| | | using Bro.Common.Helper; |
| | | using Bro.Common.Interface; |
| | | using Bro.Common.Model; |
| | |
| | | using Bro.M141.Process; |
| | | using Bro.UI.Model.Winform; |
| | | using HalconDotNet; |
| | | using Newtonsoft.Json; |
| | | using Newtonsoft.Json.Linq; |
| | | 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; |
| | |
| | | |
| | | AOI1Config ConfigAOI1 => Config as AOI1Config; |
| | | |
| | | |
| | | |
| | | 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(); |
| | | } |
| | | |
| | | |
| | | [ProcessMethod("", "PositionCheck_P1", "工位1检测", InvokeType.TestInvoke)] |
| | | public ResponseMessage PositionCheck_P1(IOperationConfig config, IDevice invokeDevice, IDevice sourceDevice) |
| | |
| | | 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) |
| | | { |
| | |
| | | |
| | | return msg; |
| | | } |
| | | |
| | | |
| | | |
| | | [ProcessMethod("ImageCheck", "ReadBarcode", "读码", InvokeType.TestInvoke)] |
| | |
| | | } |
| | | else |
| | | { |
| | | ret.Add(1); |
| | | 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].Details.ForEach(u => u.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 |
| | | { |
| | | Plc1.WriteSingleAddress(1524, 1, out _); |
| | | Plc1.WriteSingleAddress(1514, 1, out _); |
| | | ConfigAOI1.basketcode = barcode; |
| | | int num = Plc1.Read(1577, 1, out _)[0]; |
| | | |
| | | if (ConfigAOI1.PlcAndBasketcodes.Count > 10) |
| | | { |
| | | ConfigAOI1.PlcAndBasketcodes.RemoveAt(0); |
| | | } |
| | | |
| | | if (ConfigAOI1.PlcAndBasketcodes.Any(u => u.id == num)) |
| | | { |
| | | ConfigAOI1.PlcAndBasketcodes.FirstOrDefault(u => u.id == num).code = barcode; |
| | | } |
| | | else |
| | | { |
| | | ConfigAOI1.PlcAndBasketcodes.Add(new PlcAndBasketcode |
| | | { |
| | | code = barcode, |
| | | id = num, |
| | | }); |
| | | } |
| | | |
| | | LogAsync(DateTime.Now, EnumHelper.LogLevel.Action, $"获取到栏具码为{barcode}"); |
| | | |
| | | mysqlhelper.NewBasketcode(barcode); |
| | | RerefreshBasketcode(); |
| | | |
| | | if (ConfigAOI1.ISupMES) |
| | | { |
| | | //string zword = mqtt.MESForBasketAsync("2", "DS02217", barcode, "1", num.ToString()).Result; |
| | | string zwordstr = Task.Run(() => mqtt.MESForBasketAsync("2", "DS02217", barcode, "1", ConfigAOI1.mesnum2.ToString())).Result; |
| | | |
| | | ConfigAOI1.mesnum2++; |
| | | |
| | | try |
| | | { |
| | | var obj = JsonConvert.DeserializeObject<AutoLineMacQueueBak>(zwordstr); |
| | | ConfigAOI1.zwoid = obj.zwoid; |
| | | if (!string.IsNullOrEmpty(obj.zwoid) && obj.zstatus == "200") |
| | | { |
| | | Plc1.WriteSingleAddress(1524, 1, out _); |
| | | Plc1.WriteSingleAddress(1514, 1, out _); |
| | | LogAsync(DateTime.Now, EnumHelper.LogLevel.Information, $"RabbitMQ zwoid获取成功 {obj.zstatus} {obj.zwoid} "); |
| | | } |
| | | else |
| | | { |
| | | Plc1.WriteSingleAddress(1524, 2, out _); |
| | | Plc1.WriteSingleAddress(1514, 1, out _); |
| | | LogAsync(DateTime.Now, EnumHelper.LogLevel.Information, $"RabbitMQ zwoid获取失败 {zwordstr} "); |
| | | } |
| | | } |
| | | catch |
| | | { |
| | | Plc1.WriteSingleAddress(1524, 2, out _); |
| | | Plc1.WriteSingleAddress(1514, 1, out _); |
| | | LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"RabbitMQ zwoid获取异常 返回数据为 {zwordstr} "); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | Plc1.WriteSingleAddress(1524, 1, out _); |
| | | Plc1.WriteSingleAddress(1514, 1, out _); |
| | | } |
| | | SaveProcessConfig(ConfigAOI1); |
| | | } |
| | | |
| | | } |
| | | |
| | | return msg; |
| | | } |
| | | |
| | | |
| | | |
| | | private string BarcodeScannerCommunicate(TcpClientWrapBase client) |
| | |
| | | return "NOREAD"; |
| | | } |
| | | |
| | | |
| | | private bool CheckBarcodeValid(string barcode) |
| | | { |
| | | bool isBarcodeValid = true; |
| | |
| | | } |
| | | return isBarcodeValid; |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | [ProcessMethod("ImageCheck", "CheckLineProfile", "检测产品线轮廓度", InvokeType.TestInvoke)] |
| | |
| | | } |
| | | |
| | | |
| | | [ProcessMethod("ImageCheck", "GetMatrix", "获取矩阵", InvokeType.TestInvoke)] |
| | | public ResponseMessage GetMatrix(IOperationConfig config, IDevice invokeDevice, IDevice sourceDevice) |
| | | { |
| | | ResponseMessage msg = new ResponseMessage(); |
| | | if (config is IImageCheckOperationConfig opConfig) |
| | | { |
| | | var tool = GetHalconTool(null, "", opConfig.AlgorithemPath); |
| | | var ret = tool.RunProcedure(null, new Dictionary<string, HalconDotNet.HObject>() { { "INPUT_Image", opConfig.ImageSet.HImage } }, new List<string>() { "OUTPUT_Results" }, null); |
| | | |
| | | |
| | | if (ret == null) |
| | | { |
| | | LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"脚本{opConfig.AlgorithemPath}运行异常,返回值为null"); |
| | | } |
| | | else if (!ret.Item1) |
| | | { |
| | | LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"脚本{opConfig.AlgorithemPath}运行异常,{ret.Item4}"); |
| | | } |
| | | else |
| | | { |
| | | List<double> datas = ret.Item2["OUTPUT_Results"].HTupleToDouble(); |
| | | opConfig.Products[0].Centermatrix = datas; |
| | | LogAsync(DateTime.Now, EnumHelper.LogLevel.Action, $"产品{opConfig.Products[0].PID}矩阵获取为 {string.Join(',', datas)}"); |
| | | } |
| | | } |
| | | return msg; |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | [ProcessMethod("", "MESup1", "MES上传进料口空篮", InvokeType.TestInvoke)] |
| | | public ResponseMessage MESup1(IOperationConfig config, IDevice invokeDevice, IDevice sourceDevice) |
| | | { |
| | | ResponseMessage msg = new ResponseMessage(); |
| | | |
| | | //int num = Plc1.Read(1575, 1, out _)[0]; |
| | | //mqtt.Send("1", "DS02216", "", "0", num.ToString()); |
| | | //Plc1.WriteSingleAddress(1590, 1, out _); |
| | | if (ConfigAOI1.ISupMES) |
| | | { |
| | | string Msg = Task.Run(() => mqtt.MESForBasketAsync("1", "DS02216", "", "0", ConfigAOI1.mesnum1.ToString())).Result; |
| | | if (Msg != null) |
| | | { |
| | | try |
| | | { |
| | | var obj = JsonConvert.DeserializeObject<AutoLineMacQueueBak>(Msg); |
| | | if (obj?.zstatus == "200") |
| | | { |
| | | ConfigAOI1.mesnum1++; |
| | | Plc1.WriteSingleAddress(1590, 1, out _); |
| | | } |
| | | else |
| | | { |
| | | Plc1.WriteSingleAddress(1590, 2, out _); |
| | | } |
| | | LogAsync(DateTime.Now, obj?.zstatus == "200" ? EnumHelper.LogLevel.Information : EnumHelper.LogLevel.Exception, $"RabbitMQ 篮具 进料口空篮 上传{(obj?.zstatus == "200" ? "成功" : "失败")} {obj?.zstatus}"); |
| | | |
| | | } |
| | | catch |
| | | { |
| | | LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"RabbitMQ 篮具 进料口空篮 获取返回值解析异常 返回数据{Msg} "); |
| | | Plc1.WriteSingleAddress(1590, 2, out _); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | Plc1.WriteSingleAddress(1590, 2, out _); |
| | | LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"RabbitMQ 篮具 进料口空篮 获取返回值失败 返回数据null "); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | Plc1.WriteSingleAddress(1590, 1, out _); |
| | | |
| | | } |
| | | |
| | | return msg; |
| | | } |
| | | |
| | | |
| | | |
| | | [ProcessMethod("", "MESup2", "MES上传进料口满载", InvokeType.TestInvoke)] |
| | | public ResponseMessage MESup2(IOperationConfig config, IDevice invokeDevice, IDevice sourceDevice) |
| | | { |
| | | ResponseMessage msg = new ResponseMessage(); |
| | | //int num = Plc1.Read(1575, 1, out _)[0]; |
| | | |
| | | //mqtt.Send("1", "DS02216", "", "1", num.ToString()); |
| | | //Plc1.WriteSingleAddress(1590, 1, out _); |
| | | |
| | | if (ConfigAOI1.ISupMES) |
| | | { |
| | | string Msg = Task.Run(() => mqtt.MESForBasketAsync("1", "DS02216", "", "1", ConfigAOI1.mesnum1.ToString())).Result; |
| | | if (Msg != null) |
| | | { |
| | | |
| | | try |
| | | { |
| | | var obj = JsonConvert.DeserializeObject<AutoLineMacQueueBak>(Msg); |
| | | if (obj?.zstatus == "200") |
| | | { |
| | | ConfigAOI1.mesnum1++; |
| | | Plc1.WriteSingleAddress(1590, 1, out _); |
| | | } |
| | | else |
| | | { |
| | | Plc1.WriteSingleAddress(1590, 2, out _); |
| | | } |
| | | |
| | | LogAsync(DateTime.Now, obj?.zstatus == "200" ? EnumHelper.LogLevel.Information : EnumHelper.LogLevel.Exception, $"RabbitMQ 篮具 进料口满载 上传{(obj?.zstatus == "200" ? "成功" : "失败")} {obj?.zstatus}"); |
| | | } |
| | | catch |
| | | { |
| | | Plc1.WriteSingleAddress(1590, 2, out _); |
| | | LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"RabbitMQ 篮具 进料口满载 获取返回值解析异常 返回数据{Msg} "); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"RabbitMQ 篮具 进料口满载 获取返回值解析异常 返回数据null "); |
| | | Plc1.WriteSingleAddress(1590, 2, out _); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | Plc1.WriteSingleAddress(1590, 1, out _); |
| | | } |
| | | |
| | | |
| | | return msg; |
| | | } |
| | | |
| | | [ProcessMethod("", "MESup3", "MES上传下料口空篮", InvokeType.TestInvoke)] |
| | | public ResponseMessage MESup3(IOperationConfig config, IDevice invokeDevice, IDevice sourceDevice) |
| | | { |
| | | ResponseMessage msg = new ResponseMessage(); |
| | | |
| | | |
| | | |
| | | if (ConfigAOI1.ISupMES) |
| | | { |
| | | int num = Plc1.Read(1578, 1, out _)[0]; |
| | | |
| | | string Msg = Task.Run(() => mqtt.MESForBasketAsync("3", "DS02217", ConfigAOI1.PlcAndBasketcodes.Any(u => u.id == num) ? ConfigAOI1.PlcAndBasketcodes.FirstOrDefault(u => u.id == num).code : "NoRead", "0", ConfigAOI1.mesnum3.ToString())).Result; |
| | | if (Msg != null) |
| | | { |
| | | |
| | | try |
| | | { |
| | | var obj = JsonConvert.DeserializeObject<AutoLineMacQueueBak>(Msg); |
| | | if (obj?.zstatus == "200") |
| | | { |
| | | ConfigAOI1.mesnum3++; |
| | | Plc1.WriteSingleAddress(1591, 1, out _); |
| | | } |
| | | else |
| | | { |
| | | Plc1.WriteSingleAddress(1591, 2, out _); |
| | | } |
| | | LogAsync(DateTime.Now, obj?.zstatus == "200" ? EnumHelper.LogLevel.Information : EnumHelper.LogLevel.Exception, $"RabbitMQ 篮具 下料口空篮 上传{(obj?.zstatus == "200" ? "成功" : "失败")} {obj?.zstatus}"); |
| | | |
| | | } |
| | | catch |
| | | { |
| | | LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"RabbitMQ 篮具 下料口空篮 获取返回值解析异常 返回数据{Msg} "); |
| | | Plc1.WriteSingleAddress(1591, 2, out _); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"RabbitMQ 篮具 进料口下料口空篮空篮 获取返回值解析异常 返回数据null "); |
| | | Plc1.WriteSingleAddress(1591, 2, out _); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | Plc1.WriteSingleAddress(1591, 1, out _); |
| | | } |
| | | |
| | | return msg; |
| | | } |
| | | |
| | | [ProcessMethod("", "MESup4", "MES上传下料口满载", InvokeType.TestInvoke)] |
| | | public ResponseMessage MESup4(IOperationConfig config, IDevice invokeDevice, IDevice sourceDevice) |
| | | { |
| | | ResponseMessage msg = new ResponseMessage(); |
| | | |
| | | if (ConfigAOI1.ISupMES) |
| | | { |
| | | int num = Plc1.Read(1578, 1, out _)[0]; |
| | | //mqtt.Send("3", "DS02217", ConfigAOI1.Dicbasketcode.ContainsKey(num) ? ConfigAOI1.Dicbasketcode[num] : ConfigAOI1.basketcode, "2", num.ToString()); |
| | | |
| | | string Msg = Task.Run(() => mqtt.MESForBasketAsync("3", "DS02217", ConfigAOI1.PlcAndBasketcodes.Any(u => u.id == num) ? ConfigAOI1.PlcAndBasketcodes.FirstOrDefault(u => u.id == num).code : "NoRead", "2", ConfigAOI1.mesnum3.ToString())).Result; |
| | | if (Msg != null) |
| | | { |
| | | try |
| | | { |
| | | var obj = JsonConvert.DeserializeObject<AutoLineMacQueueBak>(Msg); |
| | | if (obj?.zstatus == "200") |
| | | { |
| | | ConfigAOI1.mesnum3++; |
| | | } |
| | | LogAsync(DateTime.Now, obj?.zstatus == "200" ? EnumHelper.LogLevel.Information : EnumHelper.LogLevel.Exception, $"RabbitMQ 篮具 下料口满载1 上传{(obj?.zstatus == "200" ? "成功" : "失败")} {obj?.zstatus}"); |
| | | } |
| | | catch |
| | | { |
| | | LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"RabbitMQ 篮具 下料口满载1 获取返回值解析异常 返回数据{Msg} "); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"RabbitMQ 篮具 下料口满载1 获取返回值解析异常 返回数据null "); |
| | | } |
| | | |
| | | |
| | | Thread.Sleep(1000); |
| | | //mqtt.Send("4", "DS02217", ConfigAOI1.Dicbasketcode.ContainsKey(num) ? ConfigAOI1.Dicbasketcode[num] : ConfigAOI1.basketcode, "1", num.ToString()); |
| | | Msg = Task.Run(() => mqtt.MESForBasketAsync("4", "DS02217", ConfigAOI1.PlcAndBasketcodes.Any(u => u.id == num) ? ConfigAOI1.PlcAndBasketcodes.FirstOrDefault(u => u.id == num).code : "NoRead", "1", ConfigAOI1.mesnum4.ToString())).Result; |
| | | if (Msg != null) |
| | | { |
| | | try |
| | | { |
| | | var obj = JsonConvert.DeserializeObject<AutoLineMacQueueBak>(Msg); |
| | | if (obj?.zstatus == "200") |
| | | { |
| | | ConfigAOI1.mesnum4++; |
| | | Plc1.WriteSingleAddress(1591, 1, out _); |
| | | } |
| | | else |
| | | { |
| | | Plc1.WriteSingleAddress(1591, 2, out _); |
| | | } |
| | | LogAsync(DateTime.Now, obj?.zstatus == "200" ? EnumHelper.LogLevel.Information : EnumHelper.LogLevel.Exception, $"RabbitMQ 篮具 下料口满载 上传{(obj?.zstatus == "200" ? "成功" : "失败")} {obj?.zstatus}"); |
| | | } |
| | | catch |
| | | { |
| | | LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"RabbitMQ 篮具 下料口满载 获取返回值解析异常 返回数据{Msg} "); |
| | | Plc1.WriteSingleAddress(1591, 2, out _); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"RabbitMQ 篮具 下料口满载 获取返回值解析异常 返回数据null "); |
| | | Plc1.WriteSingleAddress(1591, 2, out _); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | Plc1.WriteSingleAddress(1591, 1, out _); |
| | | } |
| | | return msg; |
| | | } |
| | | |
| | | |
| | | |