namespace SHARP_CLAS_UI
|
{
|
public class Aligner
|
{
|
#region Enum
|
private enum ProcessSteps
|
{
|
Wait,
|
|
ForwardSolOn,
|
ForwardSolOnCheck,
|
ForwardSensorCheck,
|
|
ForwardSolOff,
|
ForwardSolOffCheck,
|
BackwardSensorCheck,
|
}
|
#endregion
|
|
#region Property
|
public bool ForwardSol
|
{
|
get
|
{
|
return _equipment.Board_Control.IO_manager.Get_Output(_forwardSol);
|
}
|
|
set
|
{
|
_equipment.Board_Control.IO_manager.Set_Output(_forwardSol, value);
|
}
|
}
|
|
public bool IsForwardSensor1
|
{
|
get
|
{
|
return _equipment.Board_Control.IO_manager.Get_Input(_isForwardSensor1);
|
}
|
}
|
|
public bool IsForwardSensor2
|
{
|
get
|
{
|
return _equipment.Board_Control.IO_manager.Get_Input(_isForwardSensor2);
|
}
|
}
|
|
public bool IsBackwardSensor1
|
{
|
get
|
{
|
return _equipment.Board_Control.IO_manager.Get_Input(_isBackwardSensor1);
|
}
|
}
|
|
public bool IsBackwardSensor2
|
{
|
get
|
{
|
return _equipment.Board_Control.IO_manager.Get_Input(_isBackwardSensor2);
|
}
|
}
|
|
public bool IsForward
|
{
|
get
|
{
|
return ForwardSol && IsForwardSensor1 && IsForwardSensor2;
|
}
|
}
|
|
public bool IsBackward
|
{
|
get
|
{
|
return ForwardSol == false && IsBackwardSensor1 && IsBackwardSensor2;
|
}
|
}
|
|
public bool IsWorkEnd
|
{
|
get
|
{
|
if (_step == ProcessSteps.Wait)
|
{
|
return true;
|
}
|
else
|
{
|
return false;
|
}
|
}
|
}
|
#endregion
|
|
#region Field
|
Equipment _equipment;
|
|
private OutputData _forwardSol;
|
|
private InputData _isForwardSensor1;
|
private InputData _isForwardSensor2;
|
|
private InputData _isBackwardSensor1;
|
private InputData _isBackwardSensor2;
|
|
private En_Alarm_List _forwardSensor1Alarm;
|
private En_Alarm_List _forwardSensor2Alarm;
|
private En_Alarm_List _backwardSensor1Alarm;
|
private En_Alarm_List _backwardSensor2Alarm;
|
private ProcessSteps _step;
|
|
private SequenceTimer _sequenceTimer;
|
|
private readonly int _retryLimitCount = 3;
|
private int _retryCount;
|
#endregion
|
|
#region Construct
|
public Aligner(Equipment equipment)
|
{
|
_equipment = equipment;
|
_sequenceTimer = new SequenceTimer();
|
_retryCount = 0;
|
_step = ProcessSteps.Wait;
|
}
|
#endregion
|
|
#region Function
|
public void Initialize(OutputData forwardSol, InputData isForwardSensor1, InputData isForwardSensor2, InputData isBackwardSensor1, InputData isBackwardSensor2,
|
En_Alarm_List forwardSensor1Alarm, En_Alarm_List forwardSensor2Alarm, En_Alarm_List backwardSensor1Alarm, En_Alarm_List backwardSensor2Alarm)
|
{
|
_forwardSol = forwardSol;
|
_isForwardSensor1 = isForwardSensor1;
|
_isForwardSensor2 = isForwardSensor2;
|
_isBackwardSensor1 = isBackwardSensor1;
|
_isBackwardSensor2 = isBackwardSensor2;
|
|
_forwardSensor1Alarm = forwardSensor1Alarm;
|
_forwardSensor2Alarm = forwardSensor2Alarm;
|
_backwardSensor1Alarm = backwardSensor1Alarm;
|
_backwardSensor2Alarm = backwardSensor2Alarm;
|
}
|
|
public void ExecuteProcess()
|
{
|
switch (_step)
|
{
|
case ProcessSteps.Wait:
|
{
|
break;
|
}
|
case ProcessSteps.ForwardSolOn:
|
{
|
ForwardSol = true;
|
_sequenceTimer.Restart();
|
_step = ProcessSteps.ForwardSolOnCheck;
|
break;
|
}
|
case ProcessSteps.ForwardSolOnCheck:
|
{
|
if(ForwardSol == true)
|
{
|
_retryCount = 0;
|
_sequenceTimer.Restart();
|
_step = ProcessSteps.ForwardSensorCheck;
|
}
|
else
|
{
|
if(_sequenceTimer.Seconds > 1)
|
{
|
if(_retryCount < _retryLimitCount)
|
{
|
_retryCount++;
|
_step = ProcessSteps.ForwardSolOn;
|
}
|
else
|
{
|
_retryCount = 0;
|
Interlock_Manager.Add_Interlock_Msg($"{_forwardSol} on fail.", $"{_forwardSol} on is fail (retry 3).");
|
_step = ProcessSteps.Wait;
|
}
|
}
|
}
|
break;
|
}
|
case ProcessSteps.ForwardSensorCheck:
|
{
|
if(IsForwardSensor1 && IsForwardSensor2)
|
{
|
_sequenceTimer.Reset();
|
_step = ProcessSteps.Wait;
|
}
|
else
|
{
|
if (_sequenceTimer.Seconds > _equipment.Setting.Cylinder_Timeout)
|
{
|
if(IsForwardSensor1 == false)
|
{
|
Alarm_Manager.Instance.Occurred(_forwardSensor1Alarm);
|
}
|
|
if(IsForwardSensor2 == false)
|
{
|
Alarm_Manager.Instance.Occurred(_forwardSensor2Alarm);
|
}
|
|
_step = ProcessSteps.Wait;
|
}
|
}
|
break;
|
}
|
case ProcessSteps.ForwardSolOff:
|
{
|
ForwardSol = false;
|
_sequenceTimer.Restart();
|
_step = ProcessSteps.ForwardSolOffCheck;
|
break;
|
}
|
|
case ProcessSteps.ForwardSolOffCheck:
|
{
|
if (ForwardSol == false)
|
{
|
_retryCount = 0;
|
_sequenceTimer.Restart();
|
_step = ProcessSteps.BackwardSensorCheck;
|
}
|
else
|
{
|
if (_sequenceTimer.Seconds > 1)
|
{
|
if (_retryCount < _retryLimitCount)
|
{
|
_retryCount++;
|
_step = ProcessSteps.ForwardSolOff;
|
}
|
else
|
{
|
_retryCount = 0;
|
Interlock_Manager.Add_Interlock_Msg($"{_forwardSol} off fail.", $"{_forwardSol} off is fail (retry 3).");
|
_step = ProcessSteps.Wait;
|
}
|
}
|
}
|
|
break;
|
}
|
case ProcessSteps.BackwardSensorCheck:
|
{
|
if (IsBackwardSensor1 && IsBackwardSensor2)
|
{
|
_sequenceTimer.Reset();
|
_step = ProcessSteps.Wait;
|
}
|
else
|
{
|
if (_sequenceTimer.Seconds > _equipment.Setting.Cylinder_Timeout)
|
{
|
if (IsBackwardSensor1 == false)
|
{
|
Alarm_Manager.Instance.Occurred(_backwardSensor1Alarm);
|
}
|
|
if (IsBackwardSensor2 == false)
|
{
|
Alarm_Manager.Instance.Occurred(_backwardSensor2Alarm);
|
}
|
|
_step = ProcessSteps.Wait;
|
}
|
}
|
break;
|
}
|
}
|
}
|
|
public bool Forward()
|
{
|
if(IsWorkEnd)
|
{
|
if(ForwardSol && IsForwardSensor1 && IsForwardSensor2)
|
{
|
return true;
|
}
|
else
|
{
|
_step = ProcessSteps.ForwardSolOn;
|
return true;
|
}
|
}
|
else
|
{
|
return false;
|
}
|
}
|
|
public bool Backward()
|
{
|
if (IsWorkEnd)
|
{
|
if (ForwardSol == false && IsBackwardSensor1 && IsBackwardSensor2)
|
{
|
return true;
|
}
|
else
|
{
|
_step = ProcessSteps.ForwardSolOff;
|
return true;
|
}
|
}
|
else
|
{
|
return false;
|
}
|
}
|
#endregion
|
}
|
}
|