using Aitex.Core.RT.Fsm;
using Aitex.Core.RT.Routine;
using Aitex.Core.Util;
using MECF.Framework.Common.Equipment;
using MECF.Framework.Common.Routine;
using CyberX8_Core;
using CyberX8_RT.Modules.Loader;
using CyberX8_RT.Modules.PUF;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CyberX8_RT.Modules.Transporter;
namespace CyberX8_RT.Modules
{
public class ModuleHomeAllRoutine : RoutineBase, IRoutine
{
private enum HomeStep
{
DualPufHome,
DelayPuf,
DualPufHomeWait,
LoaderHome,
LoaderDelay,
LoaderHomeWait,
LoaderTransporterHome,
LoaderTransporterDelay,
LoaderTransporterHomeWait,
ProcessTransporterHome,
ProcessTransporterDelay,
ProcessTransporterHomeWait,
End
}
#region 内部变量
private PUFEntity _puf1Entity;
private PUFEntity _puf2Entity;
private LoaderEntity _loaderEntity;
private TransporterEntity _loaderTransporterEntity;
private TransporterEntity _processTransporterEntity;
#endregion
///
/// 构造函数
///
///
public ModuleHomeAllRoutine(string module) : base(module)
{
}
///
/// 中止
///
public void Abort()
{
Runner.Stop("Manual Stop");
}
///
/// 监控
///
///
public RState Monitor()
{
Runner.Run(HomeStep.DualPufHome, HomeDualPuf, _delay_1ms)
.Delay(HomeStep.DelayPuf, _delay_1s)
.WaitWithStopCondition(HomeStep.DualPufHomeWait, CheckHomeDualPufStatus, CheckHomeDualPufStopStatus)
.Run(HomeStep.LoaderHome, HomeLoaderEntity, _delay_1ms)
.Delay(HomeStep.LoaderDelay, _delay_1s)
.WaitWithStopCondition(HomeStep.LoaderHomeWait, CheckHomeLoaderStatus, CheckHomeLoaderStopStatus)
.Run(HomeStep.LoaderTransporterHome, HomeLoaderTransporterEntity, _delay_1ms)
.Delay(HomeStep.LoaderTransporterDelay, _delay_1s)
.WaitWithStopCondition(HomeStep.LoaderTransporterHomeWait, CheckHomeLoaderTransporterStatus, CheckHomeLoaderTransporterStopStatus)
.Run(HomeStep.ProcessTransporterHome, HomeProcessTransporterEntity, _delay_1ms)
.Delay(HomeStep.ProcessTransporterDelay, _delay_1s)
.WaitWithStopCondition(HomeStep.ProcessTransporterHomeWait, CheckHomeProcessTransporterStatus, CheckHomeProcessTransporterStopStatus)
.End(HomeStep.End, NullFun, _delay_1ms);
return Runner.Status;
}
///
/// Home Dual Puf
///
///
private bool HomeDualPuf()
{
if (ModuleHelper.IsInstalled(ModuleName.PUF1))
{
if (_puf1Entity.Invoke("HomeAll") == (int)FSM_MSG.ALARM)
{
return false;
}
}
return true;
}
///
/// 检验dual puf home情况
///
///
private bool CheckHomeDualPufStatus()
{
bool puf1Result = true;
if (ModuleHelper.IsInstalled(ModuleName.PUF1))
{
puf1Result = _puf1Entity.IsIdle;
}
return puf1Result;
}
///
/// 检验dual puf home失败情况
///
///
private bool CheckHomeDualPufStopStatus()
{
bool puf1Result = false;
if (ModuleHelper.IsInstalled(ModuleName.PUF1))
{
puf1Result = _puf1Entity.State != (int)PUFSTATE.Idle && _puf1Entity.State != (int)PUFSTATE.Homing; ;
}
bool puf2Result = false;
if (ModuleHelper.IsInstalled(ModuleName.PUF2))
{
puf2Result = _puf2Entity.State != (int)PUFSTATE.Idle && _puf2Entity.State != (int)PUFSTATE.Homing;
}
return puf1Result && puf2Result;
}
///
/// Home Loader
///
///
private bool HomeLoaderEntity()
{
if (ModuleHelper.IsInstalled(ModuleName.Loader1))
{
if (_loaderEntity.Invoke("HomeAll") == (int)FSM_MSG.ALARM)
{
return false;
}
}
return true;
}
///
/// 检验Loader home情况
///
///
private bool CheckHomeLoaderStatus()
{
bool result = true;
if (ModuleHelper.IsInstalled(ModuleName.Loader1))
{
result = _loaderEntity.IsIdle;
}
return result;
}
///
/// 检验Loader home失败情况
///
///
private bool CheckHomeLoaderStopStatus()
{
bool result = false;
if (ModuleHelper.IsInstalled(ModuleName.Loader1))
{
result = _loaderEntity.State != (int)LOADERSTATE.Idle && _loaderEntity.State != (int)LOADERSTATE.Homing;
}
return result;
}
///
/// Home LoaderTransporter
///
///
private bool HomeLoaderTransporterEntity()
{
if (ModuleHelper.IsInstalled(ModuleName.Transporter2))
{
if (_loaderTransporterEntity.Invoke("HomeAll") == (int)FSM_MSG.ALARM)
{
return false;
}
}
return true;
}
///
/// 检验LoaderTransporter home情况
///
///
private bool CheckHomeLoaderTransporterStatus()
{
bool result = true;
if (ModuleHelper.IsInstalled(ModuleName.Transporter2))
{
result = _loaderTransporterEntity.IsIdle;
}
return result;
}
///
/// 检验Loader home失败情况
///
///
private bool CheckHomeLoaderTransporterStopStatus()
{
bool result = false;
if (ModuleHelper.IsInstalled(ModuleName.Transporter2))
{
result = _loaderTransporterEntity.State != (int)TransporterState.Idle && _loaderTransporterEntity.State != (int)TransporterState.Homing;
}
return result;
}
///
/// Home ProcessTransporter
///
///
private bool HomeProcessTransporterEntity()
{
if (ModuleHelper.IsInstalled(ModuleName.Transporter1))
{
if (_processTransporterEntity.Invoke("HomeAll") == (int)FSM_MSG.ALARM)
{
return false;
}
}
return true;
}
///
/// 检验LoaderTransporter home情况
///
///
private bool CheckHomeProcessTransporterStatus()
{
bool result = true;
if (ModuleHelper.IsInstalled(ModuleName.Transporter1))
{
result = _processTransporterEntity.IsIdle;
}
return result;
}
///
/// 检验Loader home失败情况
///
///
private bool CheckHomeProcessTransporterStopStatus()
{
bool result = false;
if (ModuleHelper.IsInstalled(ModuleName.Transporter1))
{
result = _processTransporterEntity.State != (int)TransporterState.Idle && _processTransporterEntity.State != (int)TransporterState.Homing;
}
return result;
}
public RState Start(params object[] objs)
{
_puf1Entity = Singleton.Instance.GetModule(ModuleName.PUF1.ToString());
_puf2Entity = Singleton.Instance.GetModule(ModuleName.PUF2.ToString());
_loaderEntity = Singleton.Instance.GetModule(ModuleName.Loader1.ToString());
_loaderTransporterEntity = Singleton.Instance.GetModule(ModuleName.Transporter2.ToString());
_processTransporterEntity = Singleton.Instance.GetModule(ModuleName.Transporter1.ToString());
return Runner.Start("System", "System Home All");
}
}
}