namespace SHARP_CLAS_UI { public class TrayShuttle { #region Enum private enum ProcessSteps { Wait, //Shuttle Forward BeforeBackwardSolOff, BeforeBackwardSolOffCheck, ForwardSolOn, ForwardSolOnCheck, ForwardSensorCheck, //Shuttle Backward BeforeForwardSolOff, BeforeForwardSolOffCheck, BackwardSolOn, BackwardSolOnCheck, BackwardSensorCheck, } #endregion #region Property public bool ForwardOnSol { get { return _equip.Board_Control.IO_manager.Get_Output(_forwardOnSol); } set { _equip.Board_Control.IO_manager.Set_Output(_forwardOnSol, value); } } public bool BackwardOnSol { get { return _equip.Board_Control.IO_manager.Get_Output(_backwardOnSol); } set { _equip.Board_Control.IO_manager.Set_Output(_backwardOnSol, value); } } public bool IsForwardSensor { get { return _equip.Board_Control.IO_manager.Get_Input(_forwardSensor); } } public bool IsBackwardSensor { get { return _equip.Board_Control.IO_manager.Get_Input(_backwardSensor); } } public bool IsForward { get { if(ForwardOnSol == true && BackwardOnSol == false && IsForwardSensor) { return true; } else { return false; } } } public bool IsBackward { get { if (ForwardOnSol == false && BackwardOnSol == true && IsBackwardSensor) { return true; } else { return false; } } } public bool IsWorkEnd { get { if (_step == ProcessSteps.Wait) { return true; } else { return false; } } } #endregion #region Field private Equipment _equip; private OutputData _forwardOnSol; private OutputData _backwardOnSol; private InputData _forwardSensor; private InputData _backwardSensor; private En_Alarm_List _forwardSensorAlarm; private En_Alarm_List _backwardSensorAlarm; private ProcessSteps _step; private SequenceTimer _sequenceTimer; private readonly int _retryLimitCount = 3; private readonly int _sensorTimeout = 60; private int _retryCount; #endregion #region Construct public TrayShuttle(Equipment equip) { _equip = equip; _sequenceTimer = new SequenceTimer(); _step = ProcessSteps.Wait; } #endregion #region Function public void Initialize(OutputData forwardOnSol, OutputData backwardOnSol, InputData forwardSensor, InputData backwardSensor, En_Alarm_List forwardSensorAlarm, En_Alarm_List backwardSensorAlarm) { _forwardOnSol = forwardOnSol; _backwardOnSol = backwardOnSol; _forwardSensor = forwardSensor; _backwardSensor = backwardSensor; _forwardSensorAlarm = forwardSensorAlarm; _backwardSensorAlarm = backwardSensorAlarm; } public void ExecuteProcess() { switch (_step) { case ProcessSteps.Wait: { break; } case ProcessSteps.BeforeBackwardSolOff: { BackwardOnSol = false; _sequenceTimer.Restart(); _step = ProcessSteps.BeforeBackwardSolOffCheck; break; } case ProcessSteps.BeforeBackwardSolOffCheck: { if(BackwardOnSol == false) { _sequenceTimer.Restart(); _step = ProcessSteps.ForwardSolOn; } else { if (_sequenceTimer.Seconds > 3) { if (_retryCount < _retryLimitCount) { _retryCount++; _step = ProcessSteps.BeforeBackwardSolOff; } else { _retryCount = 0; Interlock_Manager.Add_Interlock_Msg($"{_backwardOnSol} on fail.", $"{_backwardOnSol} on is fail (retry 3)."); _step = ProcessSteps.Wait; } } } break; } case ProcessSteps.ForwardSolOn: { ForwardOnSol = true; _sequenceTimer.Restart(); _step = ProcessSteps.ForwardSolOnCheck; break; } case ProcessSteps.ForwardSolOnCheck: { if (ForwardOnSol) { _sequenceTimer.Restart(); _step = ProcessSteps.ForwardSensorCheck; } else { if (_sequenceTimer.Seconds > 3) { if (_retryCount < _retryLimitCount) { _retryCount++; _step = ProcessSteps.ForwardSolOn; } else { _retryCount = 0; Interlock_Manager.Add_Interlock_Msg($"{_forwardOnSol} on fail.", $"{_forwardOnSol} on is fail (retry 3)."); _step = ProcessSteps.Wait; } } } break; } case ProcessSteps.ForwardSensorCheck: { if(IsForwardSensor) { _sequenceTimer.Reset(); _step = ProcessSteps.Wait; } else { if (_sequenceTimer.Seconds > _sensorTimeout) { Alarm_Manager.Instance.Occurred(_forwardSensorAlarm); _step = ProcessSteps.Wait; } } break; } case ProcessSteps.BeforeForwardSolOff: { ForwardOnSol = false; _sequenceTimer.Restart(); _step = ProcessSteps.BeforeForwardSolOffCheck; break; } case ProcessSteps.BeforeForwardSolOffCheck: { if (ForwardOnSol == false) { _sequenceTimer.Restart(); _step = ProcessSteps.BackwardSolOn; } else { if (_sequenceTimer.Seconds > 3) { if (_retryCount < _retryLimitCount) { _retryCount++; _step = ProcessSteps.BeforeForwardSolOff; } else { _retryCount = 0; Interlock_Manager.Add_Interlock_Msg($"{_forwardOnSol} on fail.", $"{_forwardOnSol} on is fail (retry 3)."); _step = ProcessSteps.Wait; } } } break; } case ProcessSteps.BackwardSolOn: { BackwardOnSol = true; _sequenceTimer.Restart(); _step = ProcessSteps.BackwardSolOnCheck; break; } case ProcessSteps.BackwardSolOnCheck: { if (BackwardOnSol) { _sequenceTimer.Restart(); _step = ProcessSteps.BackwardSensorCheck; } else { if (_sequenceTimer.Seconds > 3) { if (_retryCount < _retryLimitCount) { _retryCount++; _step = ProcessSteps.BackwardSolOn; } else { _retryCount = 0; Interlock_Manager.Add_Interlock_Msg($"{_backwardOnSol} on fail.", $"{_backwardOnSol} on is fail (retry 3)."); _step = ProcessSteps.Wait; } } } break; } case ProcessSteps.BackwardSensorCheck: { if (IsBackwardSensor) { _sequenceTimer.Reset(); _step = ProcessSteps.Wait; } else { if (_sequenceTimer.Seconds > _sensorTimeout) { Alarm_Manager.Instance.Occurred(_backwardSensorAlarm); _step = ProcessSteps.Wait; } } break; } } } public bool Forward() { if(IsWorkEnd) { if(ForwardOnSol && BackwardOnSol == false && IsForwardSensor) { return true; } else { _step = ProcessSteps.BeforeBackwardSolOff; return true; } } else { return false; } } public bool Backward() { if (IsWorkEnd) { if (BackwardOnSol && ForwardOnSol == false && IsBackwardSensor) { return true; } else { _step = ProcessSteps.BeforeForwardSolOff; return true; } } else { return false; } } #endregion } }