领胜LDS 键盘AOI检测项目
wells.liu
2020-07-04 4cb676856f0c791ffcbef569c0ca8195bf8b0938
src/Bro.M071.Process/M071Process.cs
@@ -2,6 +2,7 @@
using Bro.Common.Helper;
using Bro.Common.Interface;
using Bro.Common.Model;
using Bro.M071.Model;
using Bro.Process;
using HalconDotNet;
using System;
@@ -33,7 +34,7 @@
        #region 事件
        public event Action OnMeasureStart;
        public event Action<string> OnBarcodeChanged;
        public event Action OnClearBarcode;
        public event Action<IShapeElement> OnElementUpdated;
        #endregion
@@ -42,10 +43,23 @@
            InitialSetting();
            base.Open();
            CheckMachineState();
        }
        /// <summary>
        /// 检查设备状态
        /// </summary>
        private void CheckMachineState()
        {
            //throw new NotImplementedException();
        }
        private void InitialSetting()
        {
            //数据库迁移检查
            DatabaseInitialize.Initialize();
            Config.SnapshotPointCollection.ForEach(u =>
            {
                u.GetHalconToolPathList().ForEach(path =>
@@ -100,7 +114,7 @@
                    if (keyRespone.Count == 0)
                        throw new ProcessException($"{u.GetDisplayText()}对应的单键不存在或不可用");
                    if (b.KeyResult == "All")
                    if (b.KeyResultId == "All")
                    {
                        keyRespone.SelectMany(kr => kr.KeyResultList).ToList().ForEach(r =>
                          {
@@ -109,7 +123,7 @@
                    }
                    else
                    {
                        b.MeasureValueDict[b.KeyResult] = null;
                        b.MeasureValueDict[b.KeyResultId] = null;
                    }
                });
            });
@@ -140,19 +154,7 @@
        //}
        #endregion
        private string barCode = "";
        public string BarCode
        {
            get => barCode;
            set
            {
                if (barCode != value)
                {
                    barCode = value;
                    OnBarcodeChanged?.Invoke(value);
                }
            }
        }
        public string BarCode { get; set; }
        List<ProductionMeasurement> productionList = new List<ProductionMeasurement>();
@@ -161,14 +163,9 @@
        {
            if (string.IsNullOrWhiteSpace(BarCode))
            {
                OnClearBarcode?.Invoke();
                throw new ProcessException("未输入产品条码,请勿开始测量");
            }
            //检查产品放置OK
            //气缸推动压板移动到产品上方
            //压板压紧产品
            OnMeasureStart?.BeginInvoke(null, null);
@@ -232,39 +229,6 @@
            BarCode = "";
            return new ProcessResponse(true);
        }
        /// <summary>
        /// 暂停标志
        /// WaitHandle 暂停句柄  默认为非阻塞 可执行
        /// WaitResult 暂停标志 true 正常执行  false 暂停中
        /// </summary>
        ManualWaitConfirm _pauseHandle = new ManualWaitConfirm()
        {
            WaitHandle = new ManualResetEvent(true),
            WaitResult = true,
        };
        [ProcessMethod("", "PauseJob", "暂停流程", InvokeType.TestInvoke)]
        public ProcessResponse PauseJob(IOperationConfig opConfig, IDevice invokeDevice, IDevice sourceDevice)
        {
            if (_pauseHandle.WaitResult)
            {
                #region 板卡暂停动作
                #endregion
                _pauseHandle.WaitHandle.Reset();
            }
            else
            {
                #region 板卡恢复动作
                #endregion
                _pauseHandle.WaitHandle.Set();
            }
            _pauseHandle.WaitResult = !_pauseHandle.WaitResult;
            return new ProcessResponse(_pauseHandle.WaitResult);
        }
        #region 私有方法
@@ -375,7 +339,7 @@
            }
        }
        private void SaveKeyImages(string barCode, MeasurementUint measureUnit)
        private void SaveKeyImages(string barCode, MeasurementUnit measureUnit)
        {
            string measureName = measureUnit.GetDisplayText();
            if (Config.ImageSaveOption.IsSaveOriginImage)
@@ -406,7 +370,7 @@
            }
        }
        private async void SaveKeyImages(MeasurementUint measureUnit, string measureName, string dir)
        private async void SaveKeyImages(MeasurementUnit measureUnit, string measureName, string dir)
        {
            await Task.Run(() =>
            {
@@ -426,7 +390,7 @@
        }
        #endregion
        private async void RunImageHandle(CameraBase camera, IOperationConfig opConfig, HImage hImage, string snapshotId, string snapshotName, List<MeasurementUint> measureList)
        private async void RunImageHandle(CameraBase camera, IOperationConfig opConfig, HImage hImage, string snapshotId, string snapshotName, List<MeasurementUnit> measureList)
        {
            await Task.Run(() =>
             {