From 745d1ce73a3b27d2a3507843c8060755a0c95765 Mon Sep 17 00:00:00 2001
From: quanzhou <quan.zhou@broconcentric.com>
Date: 星期二, 21 十月 2025 19:06:36 +0800
Subject: [PATCH] 打印机条码格式修改,增添一个点检功能方法
---
src/Bro.M141_AOI1.Process/AOI1Process.cs | 219 ++++++++++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 210 insertions(+), 9 deletions(-)
diff --git a/src/Bro.M141_AOI1.Process/AOI1Process.cs b/src/Bro.M141_AOI1.Process/AOI1Process.cs
index 8f105c1..8d82bef 100644
--- a/src/Bro.M141_AOI1.Process/AOI1Process.cs
+++ b/src/Bro.M141_AOI1.Process/AOI1Process.cs
@@ -9,10 +9,12 @@
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;
@@ -105,6 +107,75 @@
}
+ [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)
{
@@ -140,7 +211,6 @@
{
codestr = "10";
}
-
if (codestr.Equals(mh.ToString()))
{
ret.Add(1);
@@ -158,7 +228,6 @@
}
FillSpecResults(results[0].PID, results[0].Specs, ret, opConfig.Products[0].SEQUENCE);
-
opConfig.Products[0].SN = barcode;
opConfig.Products[0].PID = barcode + "_1";
@@ -179,7 +248,6 @@
}
return msg;
}
-
[ProcessMethod("ImageCheck", "ReadBarcode2", "璇绘爮鍏风爜", InvokeType.TestInvoke)]
public ResponseMessage ReadBarcode2(IOperationConfig config, IDevice invokeDevice, IDevice sourceDevice)
@@ -295,7 +363,6 @@
return msg;
}
-
private string BarcodeScannerCommunicate(TcpClientWrapBase client)
{
string barcode = "";
@@ -326,7 +393,6 @@
return "NOREAD";
}
-
private bool CheckBarcodeValid(string barcode)
{
bool isBarcodeValid = true;
@@ -336,7 +402,6 @@
}
return isBarcodeValid;
}
-
[ProcessMethod("ImageCheck", "CheckLineProfile", "妫�娴嬩骇鍝佺嚎杞粨搴�", InvokeType.TestInvoke)]
public ResponseMessage CheckLineProfile(IOperationConfig config, IDevice invokeDevice, IDevice sourceDevice)
@@ -500,7 +565,6 @@
return msg;
}
-
[ProcessMethod("ImageCheck", "GetMatrix", "鑾峰彇鐭╅樀", InvokeType.TestInvoke)]
public ResponseMessage GetMatrix(IOperationConfig config, IDevice invokeDevice, IDevice sourceDevice)
{
@@ -529,10 +593,147 @@
return msg;
}
+ [ProcessMethod("", "MESupdata", "MES姝e父涓婁紶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寮傚父 杩斿洖鏁版嵁涓簄ull");
+ }
+ 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寮傚父 杩斿洖鏁版嵁涓簄ull");
+ }
+ 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寮傚父 杩斿洖鏁版嵁涓簄ull");
+ }
+ 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涓婁紶杩涙枡鍙g┖绡�", InvokeType.TestInvoke)]
--
Gitblit v1.8.0