| | |
| | | using System.ComponentModel; |
| | | using System.Drawing.Design; |
| | | using System.Linq; |
| | | using System.Runtime.CompilerServices; |
| | | using System.Text; |
| | | using System.Threading; |
| | | using System.Threading.Tasks; |
| | |
| | | public partial class M071Process |
| | | { |
| | | public Timer ResetTimer = null; |
| | | const int FULLRESETTIME = 5; |
| | | |
| | | MachineState MeasureState = MachineState.Unknown; |
| | | |
| | | object machineStateLock = new object(); |
| | | //MachineState _machineStatePre = MachineState.Unknown; |
| | |
| | | if (machineState == value) |
| | | return; |
| | | |
| | | //_machineStatePre = machineState; |
| | | |
| | | LogAsync(DateTime.Now, $"设备状态切换:{machineState.ToString()}->{value.ToString()}", ""); |
| | | machineState = value; |
| | | |
| | | switch (machineState) |
| | | Task.Run(() => |
| | | { |
| | | case MachineState.Ready: |
| | | lock (machineStateLock) |
| | | { |
| | | SwitchBeep(false); |
| | | SwitchLightRed(false); |
| | | SwitchLightYellow(false); |
| | | } |
| | | OnMachineStateChanged?.Invoke(machineState); |
| | | |
| | | Task.Run(() => |
| | | { |
| | | |
| | | while (MachineState == MachineState.Ready) |
| | | switch (machineState) |
| | | { |
| | | case MachineState.Ready: |
| | | lock (machineStateLock) |
| | | { |
| | | lock (machineStateLock) |
| | | { |
| | | SwitchLightGreen(true); |
| | | Thread.Sleep(1000); |
| | | SwitchLightGreen(false); |
| | | Thread.Sleep(1000); |
| | | } |
| | | SwitchBeep(false); |
| | | SwitchLightRed(false); |
| | | SwitchLightYellow(false); |
| | | } |
| | | }); |
| | | |
| | | break; |
| | | case MachineState.Running: |
| | | lock (machineStateLock) |
| | | { |
| | | SwitchBeep(false); |
| | | SwitchLightRed(false); |
| | | SwitchLightYellow(false); |
| | | SwitchLightGreen(true); |
| | | } |
| | | break; |
| | | case MachineState.Alarm: |
| | | lock (machineStateLock) |
| | | { |
| | | SwitchBeep(true); |
| | | SwitchLightRed(true); |
| | | SwitchLightYellow(false); |
| | | SwitchLightGreen(false); |
| | | } |
| | | break; |
| | | case MachineState.Pause: |
| | | lock (machineStateLock) |
| | | { |
| | | SwitchBeep(false); |
| | | SwitchLightRed(false); |
| | | } |
| | | Task.Run(() => |
| | | { |
| | | while (MachineState == MachineState.Pause) |
| | | Task.Run(() => |
| | | { |
| | | lock (machineStateLock) |
| | | while (MachineState == MachineState.Ready) |
| | | { |
| | | SwitchLightYellow(true); |
| | | SwitchLightGreen(true); |
| | | Thread.Sleep(1000); |
| | | SwitchLightYellow(false); |
| | | SwitchLightGreen(false); |
| | | Thread.Sleep(1000); |
| | | lock (machineStateLock) |
| | | { |
| | | SwitchLightGreen(true); |
| | | Thread.Sleep(1000); |
| | | SwitchLightGreen(false); |
| | | Thread.Sleep(1000); |
| | | } |
| | | } |
| | | } |
| | | }); |
| | | break; |
| | | case MachineState.Resetting: |
| | | lock (machineStateLock) |
| | | { |
| | | SwitchBeep(false); |
| | | SwitchLightRed(false); |
| | | SwitchLightGreen(false); |
| | | } |
| | | Task.Run(() => |
| | | { |
| | | while (MachineState == MachineState.Resetting) |
| | | }); |
| | | |
| | | break; |
| | | case MachineState.Running: |
| | | lock (machineStateLock) |
| | | { |
| | | lock (machineStateLock) |
| | | { |
| | | |
| | | SwitchLightYellow(true); |
| | | Thread.Sleep(1000); |
| | | SwitchLightYellow(false); |
| | | Thread.Sleep(1000); |
| | | } |
| | | SwitchBeep(false); |
| | | SwitchLightRed(false); |
| | | SwitchLightYellow(false); |
| | | SwitchLightGreen(true); |
| | | } |
| | | }); |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | |
| | | OnMachineStateChanged?.Invoke(machineState); |
| | | |
| | | //if (_machineStatePre == MachineState.Running && machineState == MachineState.Pause) |
| | | //{ |
| | | // Pause(); |
| | | //} |
| | | //else if (_machineStatePre == MachineState.Pause && (machineState == MachineState.Running || machineState == MachineState.Ready)) |
| | | //{ |
| | | // Resume(); |
| | | //} |
| | | break; |
| | | case MachineState.Alarm: |
| | | lock (machineStateLock) |
| | | { |
| | | SwitchBeep(true); |
| | | SwitchLightRed(true); |
| | | SwitchLightYellow(false); |
| | | SwitchLightGreen(false); |
| | | } |
| | | break; |
| | | case MachineState.Pause: |
| | | 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); |
| | | Thread.Sleep(1000); |
| | | } |
| | | } |
| | | }); |
| | | break; |
| | | case MachineState.Resetting: |
| | | lock (machineStateLock) |
| | | { |
| | | SwitchBeep(false); |
| | | SwitchLightRed(false); |
| | | SwitchLightGreen(false); |
| | | } |
| | | Task.Run(() => |
| | | { |
| | | while (MachineState == MachineState.Resetting) |
| | | { |
| | | lock (machineStateLock) |
| | | { |
| | | SwitchLightYellow(true); |
| | | Thread.Sleep(1000); |
| | | SwitchLightYellow(false); |
| | | Thread.Sleep(1000); |
| | | } |
| | | } |
| | | }); |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | }); |
| | | } |
| | | } |
| | | |
| | |
| | | if (opConfig?.InputPara != null && opConfig.InputPara.Count > 0) |
| | | { |
| | | //大复位信号 |
| | | ResetTimer.Change(opConfig.InputPara[0] == 1 ? FULLRESETTIME * 1000 : -1, -1); |
| | | ResetTimer.Change(opConfig.InputPara[0] == 1 ? Config.FullResetRequiredDuration * 1000 : -1, -1); |
| | | |
| | | if (opConfig.InputPara[0] == 0) |
| | | return new ProcessResponse(true); |
| | |
| | | MotionCardDefaultRun("Reset", ref opConfig, ref invokeDevice); |
| | | (invokeDevice as MotionCardBase).ResetAlarm(); |
| | | |
| | | RaisedAlarm(""); |
| | | _isdoing = false; |
| | | _pausedHandle.Set(); |
| | | |
| | | if (MachineState != MachineState.Pause) |
| | | { |
| | | MachineState = MachineState.Ready; |
| | | } |
| | | else |
| | | { |
| | | LogAsync(DateTime.Now, "设备暂停中,无法复位", ""); |
| | | return new ProcessResponse(true); |
| | | } |
| | | RaisedAlarm(""); |
| | | OnCheckHintUpload?.Invoke("", false); |
| | | |
| | | //if (MachineState != MachineState.Pause) |
| | | //{ |
| | | MachineState = MachineState.Ready; |
| | | //} |
| | | //else |
| | | //{ |
| | | // LogAsync(DateTime.Now, "设备暂停中,无法复位", ""); |
| | | // return new ProcessResponse(true); |
| | | //} |
| | | |
| | | if (IsEmergencyStopped) |
| | | { |
| | |
| | | } |
| | | |
| | | LogAsync(DateTime.Now, "普通复位动作完成", ""); |
| | | OnResetDone?.Invoke(); |
| | | |
| | | return new ProcessResponse(true); |
| | | } |
| | |
| | | MachineState = MachineState.Resetting; |
| | | MotionCardDefaultRun("FullReset", ref opConfig, ref invokeDevice); |
| | | |
| | | productionList.ForEach(u => u.Dispose()); |
| | | productionList.Clear(); |
| | | lock (productionLock) |
| | | { |
| | | productionList.ForEach(u => u.Dispose()); |
| | | productionList.Clear(); |
| | | } |
| | | |
| | | OnFullResetDone?.Invoke(); |
| | | |
| | |
| | | |
| | | ManualResetEventSlim _pausedHandle = new ManualResetEventSlim(true); |
| | | MachineState _machineStateBeforePause = MachineState.Unknown; |
| | | private void CheckMachinePauseState() |
| | | object _pauseLock = new object(); |
| | | private async void CheckMachinePauseState() |
| | | { |
| | | //await Task.Run(() => |
| | | await Task.Run(() => |
| | | { |
| | | if (IsMachinePaused) |
| | | lock (_pauseLock) |
| | | { |
| | | if (MachineState == MachineState.Ready || MachineState == MachineState.Running) |
| | | if (IsMachinePaused) |
| | | { |
| | | _machineStateBeforePause = MachineState; |
| | | } |
| | | MachineState = MachineState.Pause; |
| | | _pausedHandle.Reset(); |
| | | if (MachineState == MachineState.Ready || MachineState == MachineState.Running) |
| | | { |
| | | _machineStateBeforePause = MachineState; |
| | | } |
| | | MachineState = MachineState.Pause; |
| | | _pausedHandle.Reset(); |
| | | |
| | | if (_machineStateBeforePause == MachineState.Running) |
| | | { |
| | | Pause(); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | if (MachineState == MachineState.Pause) |
| | | { |
| | | if (_machineStateBeforePause == MachineState.Running) |
| | | { |
| | | Resume(true); |
| | | Pause(); |
| | | } |
| | | _pausedHandle.Set(); |
| | | RaisedAlarm(""); |
| | | MachineState = _machineStateBeforePause; |
| | | } |
| | | else |
| | | { |
| | | if (MachineState == MachineState.Pause) |
| | | { |
| | | if (_machineStateBeforePause == MachineState.Running || _machineStateBeforePause == MachineState.Ready) |
| | | { |
| | | Resume(true); |
| | | } |
| | | _pausedHandle.Set(); |
| | | RaisedAlarm(""); |
| | | |
| | | if (_machineStateBeforePause == MachineState.Running && MeasureState == MachineState.Ready) |
| | | { |
| | | MachineState = MachineState.Ready; |
| | | } |
| | | else |
| | | { |
| | | MachineState = _machineStateBeforePause; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | //); |
| | | ); |
| | | } |
| | | |
| | | public bool IsMachinePaused |
| | |
| | | } |
| | | |
| | | [ProcessMethod("", "SafetyDoorSignal", "安全门信号监控,正常ON,OFF时报警", InvokeType.TestInvoke)] |
| | | [MethodImpl(MethodImplOptions.Synchronized)] |
| | | public ProcessResponse SafetyDoorSignal(IOperationConfig opConfig, IDevice invokeDevice, IDevice sourceDevice) |
| | | { |
| | | //if (MachineState != MachineState.Running && MachineState != MachineState.Pause) |
| | |
| | | } |
| | | |
| | | [ProcessMethod("", "SafetyBeamSignal", "安全光幕信号监控,正常ON,OFF时报警", InvokeType.TestInvoke)] |
| | | [MethodImpl(MethodImplOptions.Synchronized)] |
| | | public ProcessResponse SafetyBeamSignal(IOperationConfig opConfig, IDevice invokeDevice, IDevice sourceDevice) |
| | | { |
| | | if (opConfig.InputPara == null || opConfig.InputPara.Count == 0) |