领胜LDS 键盘AOI检测项目
src/Bro.M071.Process/M071Process.cs
@@ -19,6 +19,7 @@
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
@@ -47,6 +48,7 @@
        public event Action<IShapeElement> OnElementUpdated;
        public event Action<MachineState> OnMachineStateChanged;
        public event Action OnFullResetDone;
        public event Action OnResetDone;
        #endregion
        string _precision = "f3";
@@ -193,9 +195,13 @@
        }
        #endregion
        object productionLock = new object();
        List<ProductionMeasurement> productionList = new List<ProductionMeasurement>();
        bool _isdoing = false;
        [ProcessMethod("", "StartJob", "开始扫描", InvokeType.TestInvoke)]
        [MethodImpl(MethodImplOptions.Synchronized)]
        public ProcessResponse StartJob(IOperationConfig opConfig, IDevice invokeDevice, IDevice sourceDevice)
        {
            if (!IsAllowedWork)
@@ -204,12 +210,13 @@
            }
            string hint = "";
            if (MachineState != MachineState.Ready)
            {
                hint = "机台未就绪,请勿开始测量";
                OnCheckHintUpload?.Invoke(hint, true);
                throw new ProcessException(hint, null, ExceptionLevel.Fatal);
            }
            //if (MachineState != MachineState.Ready)
            //{
            //    hint = "机台未就绪,请勿开始测量";
            //    OnCheckHintUpload?.Invoke(hint, true);
            //    throw new ProcessException(hint, null, ExceptionLevel.Warning);
            //}
            if (string.IsNullOrWhiteSpace(BarCode))
            {
@@ -218,6 +225,8 @@
                OnCheckHintUpload?.Invoke(hint, true);
                throw new ProcessException(hint);
            }
            _isdoing = true;
            MachineState = MachineState.Running;
@@ -247,15 +256,18 @@
            BarCode = "";
            var existedProduction = productionList.FirstOrDefault(u => u.Barcode == pMeasure.Barcode);
            if (existedProduction != null)
            lock (productionLock)
            {
                productionList.Remove(existedProduction);
                existedProduction.Dispose();
                existedProduction = null;
            }
                var existedProduction = productionList.FirstOrDefault(u => u.Barcode == pMeasure.Barcode);
                if (existedProduction != null)
                {
                    productionList.Remove(existedProduction);
                    existedProduction.Dispose();
                    existedProduction = null;
                }
            productionList.Add(pMeasure);
                productionList.Add(pMeasure);
            }
            pMeasure.InitialMeasurementsPropertyChanged();
            pMeasure.PropertyChanged += MeasureProduction_PropertyChanged;
@@ -311,6 +323,7 @@
                  });
            LogAsync(DateTime.Now, $"{pMeasure.Barcode}测量动作完成", "");
            _isdoing = false;
            GC.Collect(0, GCCollectionMode.Optimized);
@@ -324,8 +337,11 @@
            get => isLeftStart;
            set
            {
                isLeftStart = value;
                StartCheck();
                if (IsLeftStart != value)
                {
                    isLeftStart = value;
                    StartCheck();
                }
            }
        }
@@ -335,8 +351,11 @@
            get => isRightStart;
            set
            {
                isRightStart = value;
                StartCheck();
                if (isRightStart != value)
                {
                    isRightStart = value;
                    StartCheck();
                }
            }
        }
@@ -344,6 +363,11 @@
        {
            if (isRightStart && isLeftStart)
            {
                if (_isdoing)
                {
                    OnCheckHintUpload?.Invoke("设备运行中", false);
                    return;
                }
                StartJob(null, null, null);
            }
        }
@@ -444,9 +468,13 @@
        {
            if (sender is ProductionMeasurement pMeasure)
            {
                var production = productionList.FirstOrDefault(u => u.Barcode == pMeasure.Barcode);
                if (production == null)
                    return;
                ProductionMeasurement production = null;
                lock (productionLock)
                {
                    production = productionList.FirstOrDefault(u => u.Barcode == pMeasure.Barcode);
                    if (production == null)
                        return;
                }
                lock (production)
                {
@@ -553,8 +581,20 @@
                LogAsync(DateTime.Now, $"{pMeasure.Barcode} 检测完成,结果 {pMeasure.PResult}", "");
                if (MachineState == MachineState.Running)
                    MachineState = MachineState.Ready;
                //if (MachineState == MachineState.Running)
                //    MachineState = MachineState.Ready;
                if (MachineState != MachineState.Alarm)
                {
                    if (MachineState == MachineState.Pause)
                    {
                        _machineStateBeforePause = MachineState.Ready;
                    }
                    else
                    {
                        MachineState = MachineState.Ready;
                    }
                }
                var measurementUnitResultAndKeyUnitDataSet = GetMeasurementUnitResultAndKeyUnitData(pMeasure);
@@ -573,7 +613,10 @@
                SaveWholeImage(pMeasure);
                productionList.RemoveAll(p => p.Barcode == pMeasure.Barcode);
                lock (productionLock)
                {
                    productionList.RemoveAll(p => p.Barcode == pMeasure.Barcode);
                }
                pMeasure.Dispose();
                //LogAsync(DateTime.Now, $"{pMeasure.Barcode}产品信息释放完成", JsonConvert.SerializeObject(pMeasure));
            }
@@ -661,7 +704,7 @@
                    }
                    measurementUnitResult.MeasurementType = measurementUnit.MeasureType;
                    measurementUnitResult.MeasurementValue = measurementUnit.Spec.ActualValue == null ? "NA" : measurementUnit.Spec.ActualValue.Value.ToString(_precision);
                    measurementUnitResult.MeasurementResult = measurementUnit.Spec.MeasureResult.Value ? "OK" : "NG";
                    measurementUnitResult.MeasurementResult = measurementUnit.Spec.MeasureResult == null ? "NA" : measurementUnit.Spec.MeasureResult.Value ? "OK" : "NG";
                    measurementUnitResults.Add(measurementUnitResult);
@@ -1183,6 +1226,13 @@
                var keys = Config.KeyUnitCollection.Where(u => u.IsEnabled && u.SnapshotPointId == snapshotId);
                var keyBindCollection = measureList.SelectMany(u => u.KeyUnitCollection).Where(u => keys.Any(k => k.Key == u.Key)).ToList();
                if (imgSet.HImage == null)
                {
                    LogAsync(DateTime.Now, $"{snapshotName}未获取扫描图像", "");
                    keyBindCollection.ForEach(k => k.FillKeyValues(null));
                    return;
                }
                string toolKey = (opConfig as CameraOprerationConfigBase).AlgorithemPath;
                HObject images = new HObject();