领胜LDS 键盘AOI检测项目
patrick.xu
2021-02-20 78289c64a16dd02cc9fec595bf758a9e30a30926
src/Bro.M071.Process/M071Process.cs
@@ -48,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";
@@ -197,8 +198,10 @@
        object productionLock = new object();
        List<ProductionMeasurement> productionList = new List<ProductionMeasurement>();
        bool _isdoing = false;
        object _doingLock = new object();
        [ProcessMethod("", "StartJob", "开始扫描", InvokeType.TestInvoke)]
        [MethodImpl(MethodImplOptions.Synchronized)]
        public ProcessResponse StartJob(IOperationConfig opConfig, IDevice invokeDevice, IDevice sourceDevice)
        {
            if (!IsAllowedWork)
@@ -207,6 +210,7 @@
            }
            string hint = "";
            //if (MachineState != MachineState.Ready)
            //{
            //    hint = "机台未就绪,请勿开始测量";
@@ -220,6 +224,17 @@
                OnClearBarcode?.Invoke();
                OnCheckHintUpload?.Invoke(hint, true);
                throw new ProcessException(hint);
            }
            lock (_doingLock)
            {
                if (_isdoing)
                {
                    LogAsync(DateTime.Now, "设备正在运行中", "");
                    return new ProcessResponse(true);
                }
                _isdoing = true;
            }
            MachineState = MachineState.Running;
@@ -266,7 +281,9 @@
            pMeasure.InitialMeasurementsPropertyChanged();
            pMeasure.PropertyChanged += MeasureProduction_PropertyChanged;
            Config.SnapshotPointCollection.Where(u => u.IsEnabled).ToList().ForEach(s =>
            try
            {
                Config.SnapshotPointCollection.Where(u => u.IsEnabled).ToList().ForEach(s =>
                  {
                      _pausedHandle.Wait();
@@ -315,23 +332,43 @@
                      RunImageHandle(s.CameraOp.OpConfig, set, s.Id, s.Name, pMeasure.Measurements);
                  });
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                LogAsync(DateTime.Now, $"{pMeasure.Barcode}测量动作完成", "");
                _isdoing = false;
            LogAsync(DateTime.Now, $"{pMeasure.Barcode}测量动作完成", "");
            GC.Collect(0, GCCollectionMode.Optimized);
                GC.Collect(0, GCCollectionMode.Optimized);
            }
            return new ProcessResponse(true);
        }
        #region 双手启动
        object _leftStartLock = new object();
        object _rightStartLock = new object();
        bool isLeftStart = false;
        bool IsLeftStart
        {
            get => isLeftStart;
            set
            {
                isLeftStart = value;
                StartCheck();
                if (isLeftStart != value)
                {
                    lock (_leftStartLock)
                    {
                        if (IsLeftStart != value)
                        {
                            isLeftStart = value;
                            StartCheck();
                        }
                    }
                }
            }
        }
@@ -341,15 +378,30 @@
            get => isRightStart;
            set
            {
                isRightStart = value;
                StartCheck();
                if (isRightStart != value)
                {
                    lock (_rightStartLock)
                    {
                        if (isRightStart != value)
                        {
                            isRightStart = value;
                            StartCheck();
                        }
                    }
                }
            }
        }
        private void StartCheck()
        {
            if (isRightStart && isLeftStart)
            {
                if (_isdoing)
                {
                    OnCheckHintUpload?.Invoke("设备运行中", false);
                    return;
                }
                StartJob(null, null, null);
            }
        }