From f9c7928bff92596686e05a15fef21d499e954088 Mon Sep 17 00:00:00 2001 From: wells.liu <wells.liu@broconcentric.com> Date: 星期一, 06 七月 2020 18:17:41 +0800 Subject: [PATCH] Merge branch 'master' of http://gitblit.broconcentric.com:8088/r/M071 --- src/Bro.M071.Process/UI/M071_MainForm.cs | 7 + src/Bro.M071.Process/M071Process.cs | 5 + src/Bro.M071.Process/M071Process_MotionCard.cs | 226 +++++++++++++++++++++++++++++++++++++++++++++----------- src/Bro.Common.Model/Helper/EnumHelper.cs | 1 4 files changed, 190 insertions(+), 49 deletions(-) diff --git a/src/Bro.Common.Model/Helper/EnumHelper.cs b/src/Bro.Common.Model/Helper/EnumHelper.cs index 03c6d7a..fdbb5b7 100644 --- a/src/Bro.Common.Model/Helper/EnumHelper.cs +++ b/src/Bro.Common.Model/Helper/EnumHelper.cs @@ -611,6 +611,7 @@ Running, Alarm, Pause, + Resetting, } } } diff --git a/src/Bro.M071.Process/M071Process.cs b/src/Bro.M071.Process/M071Process.cs index c026e29..52d0f48 100644 --- a/src/Bro.M071.Process/M071Process.cs +++ b/src/Bro.M071.Process/M071Process.cs @@ -47,6 +47,11 @@ base.Open(); + SwitchBeep(false); + SwitchLightGreen(false); + SwitchLightRed(false); + SwitchLightYellow(false); + Reset(null, null, null); FullReset(null); } diff --git a/src/Bro.M071.Process/M071Process_MotionCard.cs b/src/Bro.M071.Process/M071Process_MotionCard.cs index 06474aa..29b2055 100644 --- a/src/Bro.M071.Process/M071Process_MotionCard.cs +++ b/src/Bro.M071.Process/M071Process_MotionCard.cs @@ -19,6 +19,7 @@ public Timer ResetTimer = null; const int FULLRESETTIME = 5; + object machineStateLock = new object(); MachineState machineState = MachineState.Unknown; public MachineState MachineState { @@ -30,45 +31,86 @@ switch (machineState) { case MachineState.Ready: - SwitchBeep(false); - SwitchLightRed(false); - SwitchLightYellow(false); + lock (machineStateLock) + { + SwitchBeep(false); + SwitchLightRed(false); + SwitchLightYellow(false); + } Task.Run(() => { - while (MachineState == MachineState.Ready) + lock (machineStateLock) { - SwitchLightGreen(true); - Thread.Sleep(1000); - SwitchLightGreen(false); + while (MachineState == MachineState.Ready) + { + SwitchLightGreen(true); + Thread.Sleep(1000); + SwitchLightGreen(false); + Thread.Sleep(1000); + } } }); break; case MachineState.Running: - SwitchBeep(false); - SwitchLightRed(false); - SwitchLightYellow(false); - SwitchLightGreen(true); + lock (machineStateLock) + { + SwitchBeep(false); + SwitchLightRed(false); + SwitchLightYellow(false); + SwitchLightGreen(true); + } break; case MachineState.Alarm: - SwitchBeep(true); - SwitchLightRed(true); - SwitchLightYellow(false); - SwitchLightGreen(false); + lock (machineStateLock) + { + SwitchBeep(true); + SwitchLightRed(true); + SwitchLightYellow(false); + SwitchLightGreen(false); + } break; case MachineState.Pause: - SwitchBeep(false); - SwitchLightRed(false); + lock (machineStateLock) + { + SwitchBeep(false); + SwitchLightRed(false); + } Task.Run(() => { - while (MachineState == MachineState.Pause) + lock (machineStateLock) { - SwitchLightYellow(true); - SwitchLightGreen(true); - Thread.Sleep(1000); - SwitchLightYellow(false); - SwitchLightGreen(false); + while (MachineState == MachineState.Pause) + { + SwitchLightYellow(true); + SwitchLightGreen(true); + Thread.Sleep(1000); + SwitchLightYellow(false); + SwitchLightGreen(false); + Thread.Sleep(1000); + } + } + }); + break; + case MachineState.Resetting: + lock (machineStateLock) + { + SwitchBeep(false); + SwitchLightRed(false); + SwitchLightGreen(false); + } + Task.Run(() => + { + lock (machineStateLock) + { + while (MachineState == MachineState.Resetting) + { + SwitchLightYellow(true); + Thread.Sleep(1000); + SwitchLightYellow(false); + Thread.Sleep(1000); + } } }); break; @@ -199,7 +241,14 @@ private void FullReset(object state) { - FullReset(null, null, null); + try + { + FullReset(null, null, null); + } + catch (Exception ex) + { + ExceptionRaisedInMonitor(ex); + } } [ProcessMethod("MotionCardOperationConfigCollection", "FullReset", "澶у浣嶆搷浣�", InvokeType.TestInvoke)] @@ -227,7 +276,7 @@ //{ // motionCard.Run(opConfig); //} - + MachineState = MachineState.Resetting; MotionCardDefaultRun("FullReset", ref opConfig, ref invokeDevice); productionList.ForEach(u => u.Dispose()); @@ -236,6 +285,8 @@ OnFullResetDone?.Invoke(); LogAsync(DateTime.Now, "澶у浣嶅姩浣滃畬鎴�", ""); + MachineState = MachineState.Ready; + return new ProcessResponse(true); } @@ -249,36 +300,115 @@ WaitHandle = new ManualResetEvent(true), WaitResult = true, }; - + MachineState _machineStateBeforePause = MachineState.Unknown; + List<MachineState> _statesAllowPause = new List<MachineState>() { MachineState.Running, MachineState.Ready, MachineState.Pause }; [ProcessMethod("", "PauseJob", "鏆傚仠娴佺▼", InvokeType.TestInvoke)] - public ProcessResponse PauseJob(IOperationConfig opConfig, IDevice invokeDevice, IDevice sourceDevice) + public ProcessResponse SwitchJobStatus(IOperationConfig opConfig, IDevice invokeDevice, IDevice sourceDevice) { - if (!_pauseHandle.WaitResult) - { - #region 鏉垮崱鏆傚仠鍔ㄤ綔 - #endregion + if (!_statesAllowPause.Contains(MachineState)) + return new ProcessResponse(-999); - _pauseHandle.WaitHandle.Reset(); + MotionCardBase motionDevice = sourceDevice as MotionCardBase; + if (motionDevice == null) + { + motionDevice = DeviceCollection.FirstOrDefault(u => u is MotionCardBase) as MotionCardBase; } - _pauseHandle.WaitResult = !_pauseHandle.WaitResult; + if (motionDevice == null) + throw new ProcessException("鏈幏鍙栨澘鍗¤澶�"); + + bool? isToPause = null; //true 鏆傚仠 false 缁х画 + if (opConfig.InputPara != null && opConfig.InputPara.Count > 0) + { + isToPause = opConfig.InputPara[0] == 1; + } + + if (isToPause == null) + { + if (!_pauseHandle.WaitResult) + { + #region 鏉垮崱鏆傚仠鍔ㄤ綔 + motionDevice.StateChange(DeviceState.DSPause); + #endregion + + _pauseHandle.WaitHandle.Reset(); + _pauseHandle.WaitResult = true; + _machineStateBeforePause = MachineState; + MachineState = MachineState.Pause; + } + else if (!_pauseHandle.WaitResult) + { + #region 鏉垮崱鎭㈠鍔ㄤ綔 + motionDevice.StateChange(DeviceState.DSOpen); + #endregion + + _pauseHandle.WaitHandle.Set(); + _pauseHandle.WaitResult = false; + MachineState = _machineStateBeforePause; + } + } + else + { + if (isToPause.Value) + { + if (!_pauseHandle.WaitResult) + { + #region 鏉垮崱鏆傚仠鍔ㄤ綔 + motionDevice.StateChange(DeviceState.DSPause); + #endregion + + _pauseHandle.WaitHandle.Reset(); + _pauseHandle.WaitResult = true; + MachineState = MachineState.Pause; + } + } + else + { + if (!_pauseHandle.WaitResult) + { + #region 鏉垮崱鎭㈠鍔ㄤ綔 + motionDevice.StateChange(DeviceState.DSOpen); + #endregion + + _pauseHandle.WaitHandle.Set(); + _pauseHandle.WaitResult = false; + MachineState = _machineStateBeforePause; + } + } + } + return new ProcessResponse(_pauseHandle.WaitResult); } - [ProcessMethod("", "ResumeJob", "缁х画娴佺▼", InvokeType.TestInvoke)] - public ProcessResponse ResumeJob(IOperationConfig opConfig, IDevice invokeDevice, IDevice sourceDevice) - { - if (_pauseHandle.WaitResult) - { - #region 鏉垮崱鎭㈠鍔ㄤ綔 - #endregion + ////[ProcessMethod("", "PauseJob", "鏆傚仠娴佺▼", InvokeType.TestInvoke)] + //public ProcessResponse PauseJob(IOperationConfig opConfig, IDevice invokeDevice, IDevice sourceDevice) + //{ + // if (!_pauseHandle.WaitResult) + // { + // #region 鏉垮崱鏆傚仠鍔ㄤ綔 + // #endregion - _pauseHandle.WaitHandle.Set(); - } + // _pauseHandle.WaitHandle.Reset(); + // } - _pauseHandle.WaitResult = !_pauseHandle.WaitResult; - return new ProcessResponse(_pauseHandle.WaitResult); - } + // _pauseHandle.WaitResult = !_pauseHandle.WaitResult; + // return new ProcessResponse(_pauseHandle.WaitResult); + //} + + ////[ProcessMethod("", "ResumeJob", "缁х画娴佺▼", InvokeType.TestInvoke)] + //public ProcessResponse ResumeJob(IOperationConfig opConfig, IDevice invokeDevice, IDevice sourceDevice) + //{ + // if (_pauseHandle.WaitResult) + // { + // #region 鏉垮崱鎭㈠鍔ㄤ綔 + // #endregion + + // _pauseHandle.WaitHandle.Set(); + // } + + // _pauseHandle.WaitResult = !_pauseHandle.WaitResult; + // return new ProcessResponse(_pauseHandle.WaitResult); + //} #region 涓夎壊鐏� & 铚傞福鍣� //[ProcessMethod("MotionCardBase", "SwitchLightRed", "鍒囨崲鎸囩ず鐏�-绾�", InvokeType.TestInvoke)] @@ -443,7 +573,11 @@ if (invokeDevice is MotionCardBase motionCard) { - motionCard.Run(opConfig); + var response = motionCard.Run(opConfig); + if (!response.Result) + { + throw new ProcessException($"{motionCard.Name}寮傚父锛寋response.Message}", null, ExceptionLevel.Fatal); + } } } diff --git a/src/Bro.M071.Process/UI/M071_MainForm.cs b/src/Bro.M071.Process/UI/M071_MainForm.cs index 63f429e..8623ac8 100644 --- a/src/Bro.M071.Process/UI/M071_MainForm.cs +++ b/src/Bro.M071.Process/UI/M071_MainForm.cs @@ -1,4 +1,5 @@ -锘縰sing Bro.Common.Helper; +锘縰sing Bro.Common.Base; +using Bro.Common.Helper; using Bro.UI.Model.Winform; using System; using System.Collections.Generic; @@ -307,12 +308,12 @@ } else if (btnStartMeasure.Text == "缁х画娴嬮噺") { - Process_M071.ResumeJob(null, null, null); + Process_M071.SwitchJobStatus(new OperationConfigBase() { InputPara = new List<int>() { 0 } }, null, null); btnStartMeasure.Text = "鏆傚仠娴嬮噺"; } else { - Process_M071.PauseJob(null, null, null); + Process_M071.SwitchJobStatus(new OperationConfigBase() { InputPara = new List<int>() { 1 } }, null, null); btnStartMeasure.Text = "缁х画娴嬮噺"; } -- Gitblit v1.8.0