| | |
| | | using Bro.Common.Base; |
| | | using Bro.Common.Factory; |
| | | using Bro.Common.Helper; |
| | | using Bro.Common.Interface; |
| | | using Bro.Common.Model; |
| | |
| | | using Bro.UI.Model.Winform; |
| | | using HalconDotNet; |
| | | using Newtonsoft.Json; |
| | | using Newtonsoft.Json.Linq; |
| | | using NPOI.OpenXmlFormats.Vml; |
| | | using NPOI.POIFS.Crypt.Dsig; |
| | | using NPOI.SS.Formula.Functions; |
| | | using NPOI.XSSF.Streaming.Values; |
| | | using System.Collections.Concurrent; |
| | | using System.Collections.Generic; |
| | | using System.Net.Sockets; |
| | | using System.Text.RegularExpressions; |
| | | using static Bro.Common.Helper.EnumHelper; |
| | |
| | | } |
| | | |
| | | |
| | | [ProcessMethod("ImageCheck", "CheckProduction", "产品点检", InvokeType.TestInvoke)] |
| | | public ResponseMessage CheckProduction(IOperationConfig config, IDevice invokeDevice, IDevice sourceDevice) |
| | | { |
| | | ResponseMessage msg = new ResponseMessage(); |
| | | |
| | | if (config is IImageCheckOperationConfig opConfig) |
| | | { |
| | | var results1 = GetSpecListFromConfigSelection(opConfig.SpecCollection); |
| | | IImageSet imageSet = null; |
| | | string Head = "时间,"; |
| | | string data = $"{DateTime.Now.ToString("yyyyMMddHHmmss")}T,"; |
| | | try |
| | | { |
| | | var messure = M141Config.MeasureBindCollection_Check.FirstOrDefault(u => u.CameraId == invokeDevice.Id); |
| | | var camera = DeviceCollection.FirstOrDefault(u => u.Id == messure.CameraId) as CameraBase; |
| | | try |
| | | { |
| | | imageSet = CollectHImage(camera, messure.SnapshotOpConfig); |
| | | } |
| | | catch (Exception exx) |
| | | { |
| | | LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"点检功能获取图像失败{exx.ToString()}"); |
| | | } |
| | | var tool = GetHalconTool(null, "", opConfig.AlgorithemPath); |
| | | var ret = tool.RunProcedure(null, new Dictionary<string, HalconDotNet.HObject>() { { "INPUT_Image", imageSet.HImage } }, new List<string>() { "OUTPUT_Results" }, null); |
| | | //var ret = tool.RunProcedure(null, null, new List<string>() { "OUTPUT_Results" }, null); |
| | | List<IShapeElement> eleList = new List<IShapeElement>(); |
| | | TextDisplay text = new TextDisplay(); |
| | | text.LineLimit = M141Config.LineLimit_p; |
| | | text.FontSize = M141Config.FontSize_p; |
| | | eleList.Add(text); |
| | | text.StartX = text.StartY = 0; |
| | | text.AddText("点检运行成功", Color.Lime, Color.Transparent); |
| | | var b = ret.Item2["OUTPUT_Results"].HTupleToDouble(); |
| | | if (ret != null&& results1.Count== b.Count()) |
| | | { |
| | | var itemDict = results1.ToDictionary(u => u.OutputIndex); |
| | | b.ForEach(u => |
| | | { |
| | | int index = b.IndexOf(u); // 获取当前值的索引 |
| | | if (itemDict.TryGetValue(index, out var item)) |
| | | { |
| | | double diff = u - item.StandardValue; |
| | | bool isInTolerance = (diff - item.Tolrenance_Positive) *(diff - item.Tolrenance_Negative) <= 0; |
| | | text.AddText($"{item.Code} {u}", isInTolerance == true ? Color.Lime: Color.Red, Color.Transparent); |
| | | Head += $"{item.Code},"; |
| | | data += $"{u},"; |
| | | } |
| | | }); |
| | | } |
| | | camera.SaveFitImage(eleList, imageSet); |
| | | LogAsync(DateTime.Now, EnumHelper.LogLevel.Action, $"点检功能运行成功"); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"点检功能失败,{ex.ToString()}"); |
| | | } |
| | | LogAsync(DateTime.Now, EnumHelper.LogLevel.Action, $"点检图片开始释放"); |
| | | imageSet.HImage?.Dispose(); |
| | | imageSet.HImage = null; |
| | | imageSet.Dispose(); |
| | | imageSet = null; |
| | | LogAsync(DateTime.Now, EnumHelper.LogLevel.Action, $"图片已释放"); |
| | | //报表输出 |
| | | CSVRecordAsync($"相机{invokeDevice.Name}_点检数据记录.csv", data, Head); |
| | | } |
| | | return msg; |
| | | } |
| | | |
| | | [ProcessMethod("ImageCheck", "ReadBarcode", "读码", InvokeType.TestInvoke)] |
| | | public ResponseMessage ReadBarcode(IOperationConfig config, IDevice invokeDevice, IDevice sourceDevice) |
| | | { |
| | |
| | | { |
| | | codestr = "10"; |
| | | } |
| | | |
| | | if (codestr.Equals(mh.ToString())) |
| | | { |
| | | ret.Add(1); |
| | |
| | | } |
| | | |
| | | FillSpecResults(results[0].PID, results[0].Specs, ret, opConfig.Products[0].SEQUENCE); |
| | | |
| | | |
| | | opConfig.Products[0].SN = barcode; |
| | | opConfig.Products[0].PID = barcode + "_1"; |
| | |
| | | return msg; |
| | | } |
| | | |
| | | |
| | | [ProcessMethod("ImageCheck", "ReadBarcode2", "读栏具码", InvokeType.TestInvoke)] |
| | | public ResponseMessage ReadBarcode2(IOperationConfig config, IDevice invokeDevice, IDevice sourceDevice) |
| | | { |
| | |
| | | } |
| | | 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++; |
| | | if (ConfigAOI1.ISokMes) |
| | | { |
| | | Plc1.WriteSingleAddress(1524, 1, out _); |
| | | Plc1.WriteSingleAddress(1514, 1, out _); |
| | | LogAsync(DateTime.Now, EnumHelper.LogLevel.Information, $"已强制读栏具码运行设备"); |
| | | } |
| | | else |
| | | { |
| | | 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 |
| | | { |
| | | try |
| | | { |
| | | if (zwordstr.Contains("version错误")) |
| | | { |
| | | Regex reg = new Regex("[0-9]+", RegexOptions.IgnoreCase | RegexOptions.Singleline, TimeSpan.FromSeconds(2)); |
| | | MatchCollection matches = reg.Matches(obj.zerrmsg); |
| | | if (matches[0] != null && matches.Count == 3) |
| | | { |
| | | ConfigAOI1.mesnum2 = int.Parse(matches[0].Value)+1; |
| | | } |
| | | else |
| | | { |
| | | ConfigAOI1.mesnum2 = 0; |
| | | } |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | } |
| | | 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 |
| | | { |
| | | LogAsync(DateTime.Now, EnumHelper.LogLevel.Information, $"已关闭mes连接"); |
| | | 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)] |
| | | public ResponseMessage CheckLineProfile(IOperationConfig config, IDevice invokeDevice, IDevice sourceDevice) |
| | |
| | | LogAsync(DateTime.Now, EnumHelper.LogLevel.Detail, $"检测产品线轮廓度输入点数据 {string.Join(',', pointdataF)}"); |
| | | |
| | | var tool = GetHalconTool(null, "", opConfig.AlgorithemPath); |
| | | var ret = tool.RunProcedure(new Dictionary<string, HalconDotNet.HTuple>() { { "INPUT_Points", pointdataF.ToArray() } }, new Dictionary<string, HalconDotNet.HObject>() { { "INPUT_Image", opConfig.ImageSet.HImage } }, new List<string>() { "OUTPUT_Results", "OUTPUT_PointZ" }, null); |
| | | |
| | | var ret = tool.RunProcedure(new Dictionary<string, HalconDotNet.HTuple>() { { "INPUT_Points", pointdataF.ToArray() } }, new Dictionary<string, HalconDotNet.HObject>() { { "INPUT_Image", opConfig.ImageSet.HImage } }, new List<string>() { "OUTPUT_Results", "OUTPUT_PointZ" }, null); |
| | | if (ret == null) |
| | | { |
| | | LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"脚本{opConfig.AlgorithemPath}运行异常,返回值为null"); |
| | |
| | | if (datasZ.Count == CheckPointList.Count) |
| | | { |
| | | string Postion = "P" + opConfig.TriggerStr.Split('#')[0]; |
| | | string csvhead = "Time,Pid,Postion"; |
| | | string csvhead = "Time,Pid" + |
| | | ",Postion"; |
| | | string csvdata = $"{DateTime.Now.ToString("yyyyMMddHHmmss")}T,{results[0].PID},{Postion}"; |
| | | |
| | | for (int i = 0; i < CheckPointList.Count; i++) |
| | |
| | | else |
| | | { |
| | | item.ActualValue = retcal.Item2["OUTPUT_Results"].HTupleToDouble()[0]; |
| | | |
| | | if (item.IsEnableCompensation && item.CompensationValue.Count > 1) |
| | | { |
| | | string index = opConfig.TriggerStr.Split('#')[0]; |
| | | LogAsync(DateTime.Now, EnumHelper.LogLevel.Detail, $"{item.Code}进入双重补偿{index},初始值为{item.ActualValue}"); |
| | | |
| | | if (index=="1") |
| | | { |
| | | item.ActualValue += item.CompensationValue[0]; |
| | | LogAsync(DateTime.Now, EnumHelper.LogLevel.Detail, $"{item.Code}进入双重补偿,补偿值为{item.CompensationValue[0]},最终结果为{item.ActualValue}"); |
| | | } |
| | | else |
| | | { |
| | | item.ActualValue += item.CompensationValue[1]; |
| | | LogAsync(DateTime.Now, EnumHelper.LogLevel.Detail, $"{item.Code}进入双重补偿,补偿值为{item.CompensationValue[1]},最终结果为{item.ActualValue}"); |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | | LogAsync(DateTime.Now, EnumHelper.LogLevel.Detail, $"{results[0].PID}获取计算公式数据{item.Code} {item.GetMeasureValueStr()}"); |
| | | } |
| | | } |
| | |
| | | |
| | | return msg; |
| | | } |
| | | |
| | | |
| | | [ProcessMethod("ImageCheck", "GetMatrix", "获取矩阵", InvokeType.TestInvoke)] |
| | | public ResponseMessage GetMatrix(IOperationConfig config, IDevice invokeDevice, IDevice sourceDevice) |
| | |
| | | return msg; |
| | | } |
| | | |
| | | [ProcessMethod("", "MESupdata", "MES正常上传OK产品获取条码", InvokeType.TestInvoke)] |
| | | public ResponseMessage MESupdata(IOperationConfig config, IDevice invokeDevice, IDevice sourceDevice) |
| | | { |
| | | ResponseMessage msg = new ResponseMessage(); |
| | | |
| | | Plc3 = invokeDevice as PLCBase; |
| | | ///产品1上传 |
| | | var plcnum = Plc3.Read(2100, 1, out _); |
| | | if (plcnum[0] != 0) |
| | | { |
| | | var plist = mysqlhelper.GetProductList(plcnum + "_1"); |
| | | ProductModel newp = new ProductModel(); |
| | | newp.SEQUENCE = plist[0].SEQUENCE; |
| | | newp.PID = plist[0].PID; |
| | | newp.BasketCode = plist[0].BasketCode; |
| | | newp.Zword = plist[0].Zword; |
| | | newp.Result = "OK"; |
| | | newp.SN = plist[0].SN; |
| | | |
| | | var tems = Task.Run(() => mqtt.MESForProduceAsync(newp, M141Config.mesnum2.ToString(), M141Config.numpro)).Result; |
| | | M141Config.mesnum2++; |
| | | if (tems == null) |
| | | { |
| | | LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"产品{plist[0].PID}数据上传MES异常 返回数据为null"); |
| | | } |
| | | else |
| | | { |
| | | try |
| | | { |
| | | var obj = JsonConvert.DeserializeObject<AutoLineMacBarcodeQueueBak>(tems); |
| | | if (obj.zstatus == "200") |
| | | { |
| | | Plc1.WriteSingleAddress(2120, 1, out _); |
| | | LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"产品{plist[0].PID}数据上传MES成功 {tems}"); |
| | | } |
| | | else |
| | | { |
| | | LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"产品{plist[0].PID}数据上传MES失败 {tems}"); |
| | | } |
| | | } |
| | | catch (Exception) |
| | | { |
| | | LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"产品{plist[0].PID}数据上传MES失败 {tems}"); |
| | | } |
| | | } |
| | | ///产品1上传 |
| | | var plcnum1 = Plc3.Read(2102, 1, out _); |
| | | if (plcnum1[0] != 0) |
| | | { |
| | | var plist1 = mysqlhelper.GetProductList(plcnum1 + "_1"); |
| | | ProductModel newp1 = new ProductModel(); |
| | | newp1.SEQUENCE = plist[0].SEQUENCE; |
| | | newp1.PID = plist[0].PID; |
| | | newp1.BasketCode = plist[0].BasketCode; |
| | | newp1.Zword = plist[0].Zword; |
| | | newp1.Result = "OK"; |
| | | newp1.SN = plist[0].SN; |
| | | |
| | | var tems1 = Task.Run(() => mqtt.MESForProduceAsync(newp1, M141Config.mesnum2.ToString(), M141Config.numpro)).Result; |
| | | M141Config.mesnum2++; |
| | | if (tems1 == null) |
| | | { |
| | | LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"产品{plist[0].PID}数据上传MES异常 返回数据为null"); |
| | | } |
| | | else |
| | | { |
| | | try |
| | | { |
| | | var obj1 = JsonConvert.DeserializeObject<AutoLineMacBarcodeQueueBak>(tems1); |
| | | if (obj1.zstatus == "200") |
| | | { |
| | | Plc1.WriteSingleAddress(2120, 1, out _); |
| | | LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"产品{plist[0].PID}数据上传MES成功 {tems}"); |
| | | } |
| | | else |
| | | { |
| | | LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"产品{plist[0].PID}数据上传MES失败 {tems}"); |
| | | } |
| | | } |
| | | catch (Exception) |
| | | { |
| | | LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"产品{plist[0].PID}数据上传MES失败 {tems}"); |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |
| | | return msg; |
| | | } |
| | | |
| | | [ProcessMethod("", "MESupFinallydata", "MES上传尾盘OK产品获取条码", InvokeType.TestInvoke)] |
| | | public ResponseMessage MESupFinallydata(IOperationConfig config, IDevice invokeDevice, IDevice sourceDevice) |
| | | { |
| | | ResponseMessage msg = new ResponseMessage(); |
| | | |
| | | Plc3 = invokeDevice as PLCBase; |
| | | ///产品1上传 |
| | | var plcnum = Plc3.Read(2100, 1, out _); |
| | | var plist = mysqlhelper.GetProductList(plcnum+"_1"); |
| | | ProductModel newp = new ProductModel(); |
| | | newp.SEQUENCE = plist[0].SEQUENCE; |
| | | newp.PID = plist[0].PID; |
| | | newp.BasketCode = plist[0].BasketCode; |
| | | newp.Zword = plist[0].Zword; |
| | | newp.Result = "OK"; |
| | | newp.SN = plist[0].SN; |
| | | //上传尾盘数据 |
| | | var tems = Task.Run(() => mqtt.MESForProduceAsync(newp, M141Config.mesnum2.ToString(), M141Config.numpro,"Y")).Result; |
| | | M141Config.mesnum2 = 0; |
| | | if (tems == null) |
| | | { |
| | | LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"产品{plist[0].PID}数据上传MES异常 返回数据为null"); |
| | | } |
| | | else |
| | | { |
| | | try |
| | | { |
| | | var obj = JsonConvert.DeserializeObject<AutoLineMacBarcodeQueueBak>(tems); |
| | | if (obj.zstatus == "200") |
| | | { |
| | | LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"产品{plist[0].PID}数据上传MES成功 {tems}"); |
| | | |
| | | |
| | | //打印获取的条码 |
| | | if (M141Config.Isprint && !string.IsNullOrEmpty(obj.tary_label)) |
| | | { |
| | | StartPrint(obj.tary_label); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"产品{plist[0].PID}数据上传MES失败 {tems}"); |
| | | } |
| | | } |
| | | catch (Exception) |
| | | { |
| | | LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"产品{plist[0].PID}数据上传MES失败 {tems}"); |
| | | } |
| | | } |
| | | 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 (ConfigAOI1.ISokMes) |
| | | { |
| | | ConfigAOI1.mesnum1++; |
| | | Plc1.WriteSingleAddress(1590, 1, out _); |
| | | LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"已强制MES上传进料口空篮"); |
| | | } |
| | | else |
| | | { |
| | | if (Msg != null) |
| | | { |
| | | try |
| | | { |
| | | var obj = JsonConvert.DeserializeObject<AutoLineMacQueueBak>(Msg); |
| | | if (obj?.zstatus == "200") |
| | | { |
| | | ConfigAOI1.mesnum1++; |
| | | Plc1.WriteSingleAddress(1590, 1, out _); |
| | | } |
| | | else |
| | | { |
| | | try |
| | | { |
| | | if (Msg.Contains("version错误")) |
| | | { |
| | | Regex reg = new Regex("[0-9]+", RegexOptions.IgnoreCase | RegexOptions.Singleline, TimeSpan.FromSeconds(2)); |
| | | MatchCollection matches = reg.Matches(obj.zerrmsg); |
| | | if (matches[0] != null && matches.Count == 3) |
| | | { |
| | | ConfigAOI1.mesnum1 = int.Parse(matches[0].Value)+ 1; |
| | | } |
| | | else |
| | | { |
| | | ConfigAOI1.mesnum1 = 0; |
| | | } |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | } |
| | | 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 |
| | | { |
| | | LogAsync(DateTime.Now, EnumHelper.LogLevel.Information, $"已关闭mes连接"); |
| | | 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 (ConfigAOI1.ISokMes) |
| | | { |
| | | ConfigAOI1.mesnum1++; |
| | | Plc1.WriteSingleAddress(1590, 1, out _); |
| | | LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"已强制MES上传进料口满载"); |
| | | } |
| | | else |
| | | { |
| | | if (Msg != null) |
| | | { |
| | | |
| | | try |
| | | { |
| | | var obj = JsonConvert.DeserializeObject<AutoLineMacQueueBak>(Msg); |
| | | if (obj?.zstatus == "200") |
| | | { |
| | | ConfigAOI1.mesnum1++; |
| | | Plc1.WriteSingleAddress(1590, 1, out _); |
| | | } |
| | | else |
| | | { |
| | | try |
| | | { |
| | | if (Msg.Contains("version错误")) |
| | | { |
| | | Regex reg = new Regex("[0-9]+", RegexOptions.IgnoreCase | RegexOptions.Singleline, TimeSpan.FromSeconds(2)); |
| | | MatchCollection matches = reg.Matches(obj.zerrmsg); |
| | | if (matches[0] != null && matches.Count == 3) |
| | | { |
| | | ConfigAOI1.mesnum1 = int.Parse(matches[0].Value) + 1; |
| | | } |
| | | else |
| | | { |
| | | ConfigAOI1.mesnum1 = 0; |
| | | } |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | } |
| | | 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 |
| | | { |
| | | LogAsync(DateTime.Now, EnumHelper.LogLevel.Information, $"已关闭mes连接"); |
| | | 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 |
| | | { |
| | | try |
| | | { |
| | | if (Msg.Contains("version错误")) |
| | | { |
| | | Regex reg = new Regex("[0-9]+", RegexOptions.IgnoreCase | RegexOptions.Singleline, TimeSpan.FromSeconds(2)); |
| | | MatchCollection matches = reg.Matches(obj.zerrmsg); |
| | | if (matches[0] != null && matches.Count == 3) |
| | | { |
| | | ConfigAOI1.mesnum3 = int.Parse(matches[0].Value)+1; |
| | | } |
| | | else |
| | | { |
| | | ConfigAOI1.mesnum3 = 0; |
| | | } |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | } |
| | | 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 |
| | | { |
| | | LogAsync(DateTime.Now, EnumHelper.LogLevel.Information, $"已关闭mes连接"); |
| | | 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++; |
| | | } |
| | | else |
| | | { |
| | | try |
| | | { |
| | | if (Msg.Contains("version错误")) |
| | | { |
| | | Regex reg = new Regex("[0-9]+", RegexOptions.IgnoreCase | RegexOptions.Singleline, TimeSpan.FromSeconds(2)); |
| | | MatchCollection matches = reg.Matches(obj.zerrmsg); |
| | | if (matches[0] != null && matches.Count == 3) |
| | | { |
| | | ConfigAOI1.mesnum3 = int.Parse(matches[0].Value) + 1; |
| | | } |
| | | else |
| | | { |
| | | ConfigAOI1.mesnum3 = 0; |
| | | } |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | } |
| | | } |
| | | 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 |
| | | { |
| | | try |
| | | { |
| | | if (Msg.Contains("version错误")) |
| | | { |
| | | Regex reg = new Regex("[0-9]+", RegexOptions.IgnoreCase | RegexOptions.Singleline, TimeSpan.FromSeconds(2)); |
| | | MatchCollection matches = reg.Matches(obj.zerrmsg); |
| | | if (matches[0] != null && matches.Count == 3) |
| | | { |
| | | ConfigAOI1.mesnum4 = int.Parse(matches[0].Value) + 1; |
| | | } |
| | | else |
| | | { |
| | | ConfigAOI1.mesnum4 = 0; |
| | | } |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | } |
| | | 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 |
| | | { |
| | | LogAsync(DateTime.Now, EnumHelper.LogLevel.Information, $"已关闭mes连接"); |
| | | Plc1.WriteSingleAddress(1591, 1, out _); |
| | | } |
| | | return msg; |
| | | } |
| | | } |
| | | } |