320 lines
8.6 KiB
C#
320 lines
8.6 KiB
C#
|
using Aitex.Core.RT.Device;
|
|||
|
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.Servo.NAIS;
|
|||
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Linq;
|
|||
|
using System.Text;
|
|||
|
using System.Threading.Tasks;
|
|||
|
|
|||
|
namespace SicPM.Routines
|
|||
|
{
|
|||
|
class PMServoResetRoutine : PMBaseRoutine
|
|||
|
{
|
|||
|
enum RoutineStep
|
|||
|
{
|
|||
|
SetReset,
|
|||
|
|
|||
|
SetBlockOn,
|
|||
|
|
|||
|
WaitStatusCorrect,
|
|||
|
|
|||
|
SetBlockOff,
|
|||
|
|
|||
|
AclrOn,
|
|||
|
TimeDelay1,
|
|||
|
AclrOff
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
|
|||
|
private int _timeout;
|
|||
|
|
|||
|
private NAISServo servo;
|
|||
|
|
|||
|
public PMServoResetRoutine(ModuleName module, PMModule pm) : base(module, pm)
|
|||
|
{
|
|||
|
Module = module.ToString();
|
|||
|
Name = "Servo Home";
|
|||
|
servo = DEVICE.GetDevice<NAISServo>($"{Module}.NAISServo");
|
|||
|
|
|||
|
_timeout = SC.GetValue<int>($"PM.{Module}.MainPump.StartTimeout");
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
public void Init()
|
|||
|
{
|
|||
|
//_useSettingValue = false;
|
|||
|
}
|
|||
|
public void Init(float basePressure, int ventDelayTime)
|
|||
|
{
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
public override Result Start(params object[] objs)
|
|||
|
{
|
|||
|
if (PMDevice.CheckServoAlarm())
|
|||
|
{
|
|||
|
EV.PostWarningLog(Module, "can not up,confinementring is error.");
|
|||
|
return Result.FAIL;
|
|||
|
}
|
|||
|
if (PMDevice.CheckServoIsBusy())
|
|||
|
{
|
|||
|
EV.PostWarningLog(Module, "can not vent,confinementring is busy.");
|
|||
|
return Result.FAIL;
|
|||
|
}
|
|||
|
Reset();
|
|||
|
|
|||
|
Notify("Start");
|
|||
|
return Result.RUN;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
public override Result Monitor()
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
ServoReset((int)RoutineStep.SetReset, PMDevice, _timeout);
|
|||
|
|
|||
|
ServoAclrOn((int)RoutineStep.AclrOn);
|
|||
|
|
|||
|
TimeDelay((int)RoutineStep.TimeDelay1, 1);
|
|||
|
|
|||
|
ServoAclrOff((int)RoutineStep.AclrOff);
|
|||
|
|
|||
|
|
|||
|
|
|||
|
//ServoBlockOn((int)RoutineStep.SetBlockOn, PMDevice, _timeout);
|
|||
|
|
|||
|
//WaitStatusCorrect((int)RoutineStep.WaitStatusCorrect, PMDevice, _timeout);
|
|||
|
|
|||
|
//ServoBlockOff((int)RoutineStep.SetBlockOff, PMDevice, _timeout);
|
|||
|
}
|
|||
|
catch (RoutineBreakException)
|
|||
|
{
|
|||
|
return Result.RUN;
|
|||
|
}
|
|||
|
catch (RoutineFaildException)
|
|||
|
{
|
|||
|
return Result.FAIL;
|
|||
|
}
|
|||
|
|
|||
|
Notify("Finished");
|
|||
|
|
|||
|
return Result.DONE;
|
|||
|
}
|
|||
|
|
|||
|
private void ServoReset(int id, PMModule pm, int timeout)
|
|||
|
{
|
|||
|
Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
|
|||
|
{
|
|||
|
Notify($"Run {pm.Name} reset Error.");
|
|||
|
|
|||
|
if (!pm.ConfinementRing.Reset(out string reason))
|
|||
|
{
|
|||
|
Stop(reason);
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
return true;
|
|||
|
}, () =>
|
|||
|
{
|
|||
|
if (!servo.AlarmStatus || pm.ConfinementRing.IsReset)
|
|||
|
return true;
|
|||
|
|
|||
|
return false;
|
|||
|
|
|||
|
}, timeout * 1000);
|
|||
|
//
|
|||
|
if (ret.Item1)
|
|||
|
{
|
|||
|
if (ret.Item2 == Result.FAIL)
|
|||
|
{
|
|||
|
throw (new RoutineFaildException());
|
|||
|
}
|
|||
|
else if (ret.Item2 == Result.TIMEOUT) //timeout
|
|||
|
{
|
|||
|
Stop($"{pm.Name} Reset Error timeout, over {timeout} seconds");
|
|||
|
throw (new RoutineFaildException());
|
|||
|
}
|
|||
|
else
|
|||
|
throw (new RoutineBreakException());
|
|||
|
}
|
|||
|
}
|
|||
|
private void ServoBlockOn(int id, PMModuleBase pm, int timeout)
|
|||
|
{
|
|||
|
Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
|
|||
|
{
|
|||
|
Notify($"Run {pm.Name} set Stb On.");
|
|||
|
|
|||
|
//if (!servo.SetBlockNoHigh())
|
|||
|
//{
|
|||
|
// Stop(reason);
|
|||
|
// return false;
|
|||
|
//}
|
|||
|
servo.SetStbOn();
|
|||
|
return true;
|
|||
|
}, () =>
|
|||
|
{
|
|||
|
if (servo.AlarmStatus)
|
|||
|
{
|
|||
|
Stop($"{pm.Name} error");
|
|||
|
return null;
|
|||
|
}
|
|||
|
if (!servo.IsBusy)
|
|||
|
return true;
|
|||
|
|
|||
|
return false;
|
|||
|
|
|||
|
}, timeout * 1000);
|
|||
|
|
|||
|
if (ret.Item1)
|
|||
|
{
|
|||
|
if (ret.Item2 == Result.FAIL)
|
|||
|
{
|
|||
|
throw (new RoutineFaildException());
|
|||
|
}
|
|||
|
else if (ret.Item2 == Result.TIMEOUT) //timeout
|
|||
|
{
|
|||
|
Stop($"{pm.Name} set Stb On timeout, over {timeout} seconds");
|
|||
|
throw (new RoutineFaildException());
|
|||
|
}
|
|||
|
else
|
|||
|
throw (new RoutineBreakException());
|
|||
|
}
|
|||
|
}
|
|||
|
private void ServoBlockOff(int id, PMModuleBase pm, int timeout)
|
|||
|
{
|
|||
|
Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
|
|||
|
{
|
|||
|
Notify($"Run {pm.Name} set Stb Off.");
|
|||
|
|
|||
|
//if (!servo.SetBlockNoHigh())
|
|||
|
//{
|
|||
|
// Stop(reason);
|
|||
|
// return false;
|
|||
|
//}
|
|||
|
servo.SetStbOn();
|
|||
|
return true;
|
|||
|
}, () =>
|
|||
|
{
|
|||
|
if (servo.AlarmStatus)
|
|||
|
{
|
|||
|
Stop($"{pm.Name} error");
|
|||
|
return null;
|
|||
|
}
|
|||
|
if (!servo.IsBusy)
|
|||
|
return true;
|
|||
|
|
|||
|
return false;
|
|||
|
|
|||
|
}, timeout * 1000);
|
|||
|
|
|||
|
if (ret.Item1)
|
|||
|
{
|
|||
|
if (ret.Item2 == Result.FAIL)
|
|||
|
{
|
|||
|
throw (new RoutineFaildException());
|
|||
|
}
|
|||
|
else if (ret.Item2 == Result.TIMEOUT) //timeout
|
|||
|
{
|
|||
|
Stop($"{pm.Name} set Stb Off timeout, over {timeout} seconds");
|
|||
|
throw (new RoutineFaildException());
|
|||
|
}
|
|||
|
else
|
|||
|
throw (new RoutineBreakException());
|
|||
|
}
|
|||
|
}
|
|||
|
private void WaitStatusCorrect(int id, PMModule pm, int timeout)
|
|||
|
{
|
|||
|
Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
|
|||
|
{
|
|||
|
Notify($"Run {pm.Name} Wait, Wait Status Correct");
|
|||
|
|
|||
|
return true;
|
|||
|
}, () =>
|
|||
|
{
|
|||
|
if (servo.AlarmStatus)
|
|||
|
{
|
|||
|
Stop($"{pm.Name} error");
|
|||
|
return null;
|
|||
|
}
|
|||
|
if (!servo.MotorBusy && !servo.PositionComplete)
|
|||
|
return true;
|
|||
|
return false;
|
|||
|
|
|||
|
}, timeout * 1000);
|
|||
|
|
|||
|
if (ret.Item1)
|
|||
|
{
|
|||
|
if (ret.Item2 == Result.FAIL)
|
|||
|
{
|
|||
|
throw (new RoutineFaildException());
|
|||
|
}
|
|||
|
else if (ret.Item2 == Result.TIMEOUT) //timeout
|
|||
|
{
|
|||
|
Stop($"{pm.Name} Wait Status Correct timeout, over {timeout} seconds");
|
|||
|
throw (new RoutineFaildException());
|
|||
|
}
|
|||
|
else
|
|||
|
throw (new RoutineBreakException());
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
private void ServoAclrOn(int id)
|
|||
|
{
|
|||
|
Tuple<bool, Result> ret = Execute(id, () =>
|
|||
|
{
|
|||
|
Notify($"Set set Aclr On.");
|
|||
|
servo.AclrOn();
|
|||
|
return true;
|
|||
|
});
|
|||
|
|
|||
|
if (ret.Item1)
|
|||
|
{
|
|||
|
if (ret.Item2 == Result.FAIL)
|
|||
|
{
|
|||
|
throw (new RoutineFaildException());
|
|||
|
}
|
|||
|
else
|
|||
|
throw (new RoutineBreakException());
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void ServoAclrOff(int id)
|
|||
|
{
|
|||
|
Tuple<bool, Result> ret = Execute(id, () =>
|
|||
|
{
|
|||
|
Notify($"Set Aclr Off.");
|
|||
|
servo.AclrOff();
|
|||
|
return true;
|
|||
|
});
|
|||
|
|
|||
|
if (ret.Item1)
|
|||
|
{
|
|||
|
if (ret.Item2 == Result.FAIL)
|
|||
|
{
|
|||
|
throw (new RoutineFaildException());
|
|||
|
}
|
|||
|
else
|
|||
|
throw (new RoutineBreakException());
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public override void Abort()
|
|||
|
{
|
|||
|
if (!PMDevice.StopVent(out string reason))
|
|||
|
{
|
|||
|
EV.PostWarningLog(Module, reason);
|
|||
|
}
|
|||
|
|
|||
|
Stop("aborted");
|
|||
|
}
|
|||
|
}
|
|||
|
}
|