Sic02-new/Modules/Mainframe/LLs/LoadLockDoorRoutine.cs

129 lines
3.4 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 LoadLockDoorRoutine : LoadLockBaseRoutine
{
private enum RoutineStep
{
WaitDoorInterlock,
DoorOperation,
}
private int _timeout;
private bool _paramIsOpen;
private IoDoor _door;
public LoadLockDoorRoutine(ModuleName module):base(module)
{
_door = DEVICE.GetDevice<IoDoor>($"ATMDoor{module}");
}
public void Init(bool open)
{
Name = open ? "Open Door" : "Close Door";
_paramIsOpen = open;
}
public override Result Start(params object[] objs)
{
Reset();
_timeout = SC.GetValue<int>("System.SlitValveMotionTimeout");
if (_paramIsOpen)
{
if (!LoadLockDevice.CheckAtm())
{
EV.PostWarningLog(Module, $"Can not {Name}, {Module} not in ATM");
return Result.FAIL;
}
if (!TMDevice.CheckSlitValveClose(ModuleHelper.Converter(Module)))
{
EV.PostWarningLog(Module, $"Can not {Name}, {Module} slit valve not closed");
return Result.FAIL;
}
}
if (_paramIsOpen && LoadLockDevice.CheckDoorOpen())
{
EV.PostInfoLog(Module, $"door is opened");
return Result.DONE;
}
if (!_paramIsOpen && LoadLockDevice.CheckDoorClose())
{
EV.PostInfoLog(Module, $"door is closed");
return Result.DONE;
}
Notify("Start");
return Result.RUN;
}
public override Result Monitor()
{
try
{
//WaitDoorInterlock((int)RoutineStep.WaitDoorInterlock, LoadLockDevice, _paramIsOpen, _timeout);
//OpenDoor((int)RoutineStep.DoorOperation, LoadLockDevice, _paramIsOpen, _timeout);
}
catch (RoutineBreakException)
{
return Result.RUN;
}
catch (RoutineFaildException)
{
return Result.FAIL;
}
Notify("Finished");
return Result.DONE;
}
public override void Abort()
{
}
protected void WaitDoorInterlock(int id, LoadLock ll, bool open, int timeout)
{
Tuple<bool, Result> ret = Wait(id, () =>
{
return ll == null || _door.CheckInterlockEnable(open);
}, timeout * 1000);
if (ret.Item1)
{
if (ret.Item2 == Result.TIMEOUT) //timeout
{
Stop($"wait {ll.Name} {Name} Interlock timeout, over {timeout} seconds");
throw (new RoutineFaildException());
}
else
throw (new RoutineBreakException());
}
}
}
}