领胜LDS 键盘AOI检测项目
wells.liu
2020-07-13 9519d0962fb2772cce85653f53d140b8aa657ab2
src/Bro.M071.Process/M071Process_MotionCard.cs
@@ -26,6 +26,9 @@
            get => machineState;
            set
            {
                if (machineState == value)
                    return;
                machineState = value;
                switch (machineState)
@@ -40,9 +43,10 @@
                        Task.Run(() =>
                        {
                            lock (machineStateLock)
                            while (MachineState == MachineState.Ready)
                            {
                                while (MachineState == MachineState.Ready)
                                lock (machineStateLock)
                                {
                                    SwitchLightGreen(true);
                                    Thread.Sleep(1000);
@@ -79,9 +83,9 @@
                        }
                        Task.Run(() =>
                        {
                            lock (machineStateLock)
                            while (MachineState == MachineState.Pause)
                            {
                                while (MachineState == MachineState.Pause)
                                lock (machineStateLock)
                                {
                                    SwitchLightYellow(true);
                                    SwitchLightGreen(true);
@@ -102,10 +106,11 @@
                        }
                        Task.Run(() =>
                        {
                            lock (machineStateLock)
                            while (MachineState == MachineState.Resetting)
                            {
                                while (MachineState == MachineState.Resetting)
                                lock (machineStateLock)
                                {
                                    SwitchLightYellow(true);
                                    Thread.Sleep(1000);
                                    SwitchLightYellow(false);
@@ -185,6 +190,16 @@
            }
        }
        [ProcessMethod("MotionCardBase", "GotoReadyPosition", "运动到预备位置", InvokeType.TestInvoke)]
        public ProcessResponse GotoReadyPosition(IOperationConfig opConfig, IDevice invokeDevice, IDevice sourceDevice)
        {
            MotionCardDefaultRun("GotoReadyPosition", ref opConfig, ref invokeDevice);
            LogAsync(DateTime.Now, "运动到预备位置完成", "");
            return new ProcessResponse(true);
        }
        [ProcessMethod("MotionCardBase", "Reset", "简单复位操作", InvokeType.TestInvoke)]
        public ProcessResponse Reset(IOperationConfig opConfig, IDevice invokeDevice, IDevice sourceDevice)
        {
@@ -206,9 +221,23 @@
            //    }
            //}
            if (IsSafetyBeamTrigged || IsSafetyDoorTrigged)
            if (ResetTimer == null)
            {
                LogAsync(DateTime.Now, $"{(IsSafetyDoorTrigged ? "安全门" : "")}{(IsSafetyBeamTrigged ? " 安全光线" : "")}触发中,复位失败", "");
                ResetTimer = new Timer(FullReset, null, -1, -1);
            }
            if (opConfig?.InputPara != null && opConfig.InputPara.Count > 0)
            {
                //大复位信号
                ResetTimer.Change(opConfig.InputPara[0] == 1 ? FULLRESETTIME * 1000 : -1, -1);
                if (opConfig.InputPara[0] == 0)
                    return new ProcessResponse(true);
            }
            if (!IsAllowedWork)
            {
                LogAsync(DateTime.Now, $"{SafetyMsg},复位失败", "");
                return new ProcessResponse(false);
            }
@@ -218,16 +247,19 @@
            RaisedAlarm("");
            MachineState = MachineState.Ready;
            if (ResetTimer == null)
            if (IsEmergencyStopped)
            {
                ResetTimer = new Timer(FullReset, null, -1, -1);
                RaisedAlarm("急停按钮未恢复,请执行大复位");
                MachineState = MachineState.Alarm;
            }
            if (opConfig.InputPara.Count > 0)
            {
                //大复位信号
                ResetTimer.Change(-1, opConfig.InputPara[0] == 1 ? FULLRESETTIME * 1000 : -1);
            }
            //if (opConfig.InputPara?.Count > 0)
            //{
            //    //大复位信号
            //    ResetTimer.Change(-1, opConfig.InputPara[0] == 1 ? FULLRESETTIME * 1000 : -1);
            //}
            //if (invokeDevice is MotionCardBase motionCard)
            //{
@@ -277,6 +309,7 @@
            //{
            //    motionCard.Run(opConfig);
            //}
            MachineState = MachineState.Resetting;
            MotionCardDefaultRun("FullReset", ref opConfig, ref invokeDevice);
@@ -285,8 +318,14 @@
            OnFullResetDone?.Invoke();
            isFullResetCovered = true;
            LogAsync(DateTime.Now, "大复位动作完成", "");
            RaisedAlarm("");
            MachineState = MachineState.Ready;
            GotoReadyPosition(null, null, null);
            return new ProcessResponse(true);
        }
@@ -319,9 +358,17 @@
                throw new ProcessException("未获取板卡设备");
            bool? isToPause = null; //true 暂停 false 继续
            if (opConfig.InputPara != null && opConfig.InputPara.Count > 0)
            //if (opConfig.InputPara != null && opConfig.InputPara.Count > 0)
            //{
            //    isToPause = opConfig.InputPara[0] == 1;
            //}
            if (opConfig.InputPara[0] == 10)
            {
                isToPause = opConfig.InputPara[0] == 1;
                isToPause = false;
            }
            else if (opConfig.InputPara[0] == 11)
            {
                isToPause = true;
            }
            if (isToPause == null)
@@ -554,7 +601,7 @@
        private void MotionCardDefaultRun(string methodCode, ref IOperationConfig opConfig, ref IDevice invokeDevice)
        {
            IMonitorSet monitorSet = null;
            if (opConfig == null)
            if (opConfig == null || !(opConfig is MotionCardOperationConfigBase))
            {
                monitorSet = Config.MonitorSetCollection.FirstOrDefault(u => u.MethodCode == methodCode);
                if (monitorSet == null)
@@ -580,6 +627,15 @@
                    throw new ProcessException($"{motionCard.Name}异常,{response.Message}", null, ExceptionLevel.Fatal);
                }
            }
        }
        bool IsAllowedWork
        {
            get => !(IsSafetyBeamTrigged || IsSafetyDoorTrigged || IsEmergencyStopped);
        }
        string SafetyMsg
        {
            get => $"{(IsSafetyBeamTrigged ? "安全光幕" : "")}{(IsSafetyDoorTrigged ? " 安全门" : "")}{(IsEmergencyStopped ? " 急停按钮" : "")}触发中";
        }
        #region 安全门 & 安全光线
@@ -617,6 +673,9 @@
        [ProcessMethod("", "SafetyBeamSignal", "安全光幕信号监控,正常ON,OFF时报警", InvokeType.TestInvoke)]
        public ProcessResponse SafetyBeamSignal(IOperationConfig opConfig, IDevice invokeDevice, IDevice sourceDevice)
        {
            if (MachineState != MachineState.Running && MachineState != MachineState.Alarm)
                return new ProcessResponse(true);
            if (opConfig.InputPara == null || opConfig.InputPara.Count == 0)
                throw new ProcessException("安全光幕监控未配置输入信号");
@@ -631,5 +690,43 @@
            return new ProcessResponse(true);
        }
        #endregion
        #region 急停
        bool isEmergencyStopped = false;
        bool isFullResetCovered = true;
        public bool IsEmergencyStopped
        {
            get => isEmergencyStopped && isFullResetCovered;
            set
            {
                if (value)
                {
                    isFullResetCovered = false;
                    isEmergencyStopped = true;
                }
                else
                {
                    isEmergencyStopped = false;
                }
            }
        }
        [ProcessMethod("", "EmergencyStop", "急停按钮被拍下", InvokeType.TestInvoke)]
        public ProcessResponse EmergencyStop(IOperationConfig opConfig, IDevice invokeDevice, IDevice sourceDevice)
        {
            if (opConfig.InputPara == null || opConfig.InputPara.Count == 0)
                throw new ProcessException("急停按钮未配置输入信号");
            IsEmergencyStopped = opConfig.InputPara[0] == 0;
            if (IsEmergencyStopped)
            {
                RaisedAlarm("急停按钮被拍下");
                MachineState = MachineState.Alarm;
            }
            return new ProcessResponse(true);
        }
        #endregion
    }
}