127 lines
3.1 KiB
C#
127 lines
3.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Aitex.Core.RT.Device;
|
|
using Aitex.Core.RT.Device.Unit;
|
|
using Aitex.Core.RT.Event;
|
|
using Aitex.Core.RT.Routine;
|
|
using Aitex.Core.RT.SCCore;
|
|
using MECF.Framework.Common.Equipment;
|
|
using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.LoadLocks;
|
|
|
|
namespace Mainframe.LLs
|
|
{
|
|
public class LoadLockLiftRoutine : ModuleRoutine, IRoutine
|
|
{
|
|
enum RoutineStep
|
|
{
|
|
LiftMove,
|
|
}
|
|
|
|
private LoadLock _ll = null;
|
|
|
|
private int _timeout;
|
|
|
|
private int _slot ;
|
|
|
|
public LoadLockLiftRoutine(ModuleName module )
|
|
{
|
|
Module = module.ToString();
|
|
|
|
Name = "Lift Move";
|
|
|
|
_ll = DEVICE.GetDevice<LoadLock>($"{module.ToString()}.{module.ToString()}");
|
|
}
|
|
|
|
public void Init(int targetSlot)
|
|
{
|
|
_slot = targetSlot;
|
|
}
|
|
|
|
public Result Start(params object[] objs)
|
|
{
|
|
Reset();
|
|
|
|
if (!_ll.EnableLift)
|
|
{
|
|
EV.PostWarningLog(Module, $"do not support lift function");
|
|
return Result.DONE;
|
|
}
|
|
|
|
_timeout = SC.GetValue<int>("LoadLock.LiftMoveTimeout");
|
|
|
|
if (_ll.CheckLift(_slot))
|
|
{
|
|
string updown = _slot == 0 ? "Up" : "Down";
|
|
EV.PostInfoLog(Module, $"Lift at {updown} position slot {_slot+1}");
|
|
return Result.DONE;
|
|
}
|
|
|
|
Notify("Start");
|
|
return Result.RUN;
|
|
}
|
|
|
|
|
|
public Result Monitor()
|
|
{
|
|
try
|
|
{
|
|
LiftMove((int)RoutineStep.LiftMove, _slot, _timeout);
|
|
}
|
|
catch (RoutineBreakException)
|
|
{
|
|
return Result.RUN;
|
|
}
|
|
catch (RoutineFaildException)
|
|
{
|
|
return Result.FAIL;
|
|
}
|
|
|
|
Notify("Finished");
|
|
|
|
return Result.DONE;
|
|
}
|
|
|
|
public void Abort()
|
|
{
|
|
|
|
}
|
|
|
|
protected void LiftMove(int id, int slot, int timeout)
|
|
{
|
|
Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
|
|
{
|
|
Notify($"Move {Module} Lift to {slot+1}");
|
|
if (!_ll.SetLift(slot, out string reason))
|
|
{
|
|
Stop(reason);
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}, () =>
|
|
{
|
|
return _ll.CheckLift(slot);
|
|
}, timeout * 1000);
|
|
|
|
if (ret.Item1)
|
|
{
|
|
if (ret.Item2 == Result.FAIL)
|
|
{
|
|
throw (new RoutineFaildException());
|
|
}
|
|
else if (ret.Item2 == Result.TIMEOUT) //timeout
|
|
{
|
|
Stop($"Timeout, over {timeout} seconds");
|
|
throw (new RoutineFaildException());
|
|
}
|
|
else
|
|
throw (new RoutineBreakException());
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|