kingno
2025-06-17 11219b1b266c7b98dde39eb710faaa83b4a37924
src/Bro.M141.Process/M141Process_ImageCheck.cs
@@ -3,10 +3,12 @@
using Bro.Common.Interface;
using Bro.Common.Model;
using Bro.M135.Common;
using Bro.M135.DBManager;
using HalconDotNet;
using Microsoft.VisualBasic;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using NPOI.Util;
using Sunny.UI;
using System.Data;
using System.Data.SqlTypes;
@@ -28,6 +30,9 @@
        Dictionary<string, List<double>> dicdate = new Dictionary<string, List<double>>();
        ManualResetEvent set1 = new ManualResetEvent(false);
        ManualResetEvent set2 = new ManualResetEvent(false);
        public event Action<string> StartPrinter;
        [ProcessMethod("ImageCheck", "ImageCheckOperation", "通用图片检测操作", InvokeType.TestInvoke)]
        public ResponseMessage ImageCheckOperation(IOperationConfig config, IDevice invokeDevice, IDevice sourceDevice)
@@ -436,8 +441,6 @@
        }
        [ProcessMethod("", "ProductDataUpload", "产品数据汇总", InvokeType.TestInvoke)]
        public ResponseMessage ProductDataUpload(IOperationConfig config, IDevice invokeDevice, IDevice sourceDevice)
        {
@@ -501,6 +504,22 @@
        [ProcessMethod("printer", "printer", "打印机打印", InvokeType.TestInvoke)]
        public ResponseMessage Printer(IOperationConfig config, IDevice invokeDevice, IDevice sourceDevice)
        {
            ResponseMessage msg = new ResponseMessage();
            Plc2 = invokeDevice as PLCBase;
            string message = "";
            StartPrinter.Invoke(message);
            return msg;
        }
        public void PlcwritePrinter(int add, int value)
        {
            Plc2.WriteSingleAddress(add, value, out _);
        }
@@ -515,9 +534,10 @@
                var spec = M141Config.SpecCollection.FirstOrDefault(s => s.Code == u.SpecCode);
                if (spec != null)
                {
                    var temp = spec.Copy<Spec>();
                    var temp = spec.Copy();
                    temp.ActualValue = null;
                    temp.MeasureResult = null;
                    temp.Source = "";
                    specList.Add(temp);
                }
            });
@@ -563,8 +583,6 @@
                        }
                    }
                    LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"产品{pid}检测项{s.Code}赋值{s.GetMeasureValueStr()},结果{s.GetMeasureResultStr()}");
                }
                else
@@ -587,12 +605,21 @@
        {
            isOK = false;
            int num = 0;
            while (p.Details.Any(u => !u.IsDone) && num < 10)
            {
                num++;
                Thread.Sleep(500);
            }
            p.InitialDetailSpecs();
            var resultList = p.Details.SelectMany(u => u.ResultList).ToList();
            resultList.ForEach(u => u.SetResult());
            var defects = resultList.GetDefectDescList();
            var ngSpecCodes = p.Details.SelectMany(u => u.SpecList ?? new List<Spec>()).Where(u => u.MeasureResult != true).Select(u => u.Code);
            var ngSpecCodes = p.Details.SelectMany(u => u.SpecList ?? new List<ISpec>()).Where(u => u.MeasureResult != true).Select(u => u.Code);
            var ngDefectDescList = p.Details.SelectMany(u => u.DefectList ?? new List<string>()).ToList();
            defects.AddRange(ngSpecCodes);
@@ -602,16 +629,18 @@
            {
                defects.Add("TBD");
            }
            defects = defects.Distinct().ToList();
            isOK = defects.Count <= 0;
            UpdateDefectAsync(defects);
            var defectClass = GetDefectClassFromDefectList(defects);
            UpdateResult(DateTime.Now, p.SN, defectClass.ClassName, "");
            UpdateResult(DateTime.Now, p.SN, defectClass.ClassName, "",p.ImagePaths);
            //产品序号+1
            Interlocked.Increment(ref _productIndex);
            //Interlocked.Increment(ref _productIndex);
            List<ISpec> specList = new List<ISpec>();
            specList.AddRange(p.Details.SelectMany(u => u.SpecList).ToList().ConvertAll(u => (ISpec)u));
@@ -638,10 +667,7 @@
            _taskFactory.StartNew(() =>
            {
                if (string.IsNullOrWhiteSpace(_csvHead))
                {
                    _csvHead = p.GetCSVHead(ref _specHeadList, ref _positionList);
                }
                _csvHead = p.GetCSVHead(ref _specHeadList, ref _positionList);
                CSVRecordAsync($"ProductRecord_{DateTime.Now.ToString("yyyyMMdd")}.csv", p.GetCSVData(_specHeadList, _positionList), _csvHead);
                //_manager_P_Product.UpdateProductResult(p.ID, p.PID, p.SN, p.Result);
            });