12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376 |
- using System;
- using Aitex.Core.RT.Device;
- using Aitex.Core.RT.Device.Unit;
- using Aitex.Core.RT.Event;
- using Aitex.Core.RT.IOCore;
- using Aitex.Core.RT.Log;
- using Aitex.Core.RT.Routine;
- using Aitex.Core.RT.SCCore;
- using Aitex.RT.Properties;
- using Aitex.Triton160.Common;
- using Aitex.Triton160.RT.Device;
- namespace Aitex.Triton160.RT.Routine
- {
- public class CommonRoutine : SeqenecRoutine
- {
- //SC
- protected SCItem<int> scOpenGasVavleTimeout = null;
- protected int dOpenGasVavleTimeout = 1; //1S
- protected SCItem<int> scCloseGasVavleTimeout = null;
- protected int dCloseGasVavleTimeout = 2; //2s
- protected SCItem<int> scOpenCloseSlitVavleTimeout = null;
- protected int valveOpenCloseTimeout = 2; //2s
- //private double fInaccuracy = 0.2; //mbar
- protected bool bUINotify;
- //Device
- protected IoValve PV1 = null;
- protected IoValve PV2 = null;
- protected IoValve PV3 = null;
- protected IoValve PV4 = null;
- protected IoValve PV5 = null;
- protected IoValve PV6 = null;
- protected IoValve PV7 = null;
- protected IoValve PV8 = null;
- protected IoValve PV9 = null;
- protected IoValve SV7 = null;
- protected IoMfc mfc1 = null;
- protected IoMfc mfc2 = null;
- protected IoMfc mfc3 = null;
- protected IoMfc mfc4 = null;
- protected IoMfc mfc5 = null;
- protected IoMfc MfcVapor = null;
- public string Module { get; set; }
- public string Name { get; set; }
- public string Display { get; set; }
- private IoValve[] _valvesForPumping =
- {
- DeviceModel.ValveChamberPurge,
- DeviceModel.ValveChamberVent,
- DeviceModel.ValveMfc1,
- DeviceModel.ValveMfc2,
- DeviceModel.ValveMfc3,
- DeviceModel.ValveMfc4,
- DeviceModel.ValveMfc5,
- DeviceModel.ValveProcessGasFinal
- };
- public CommonRoutine()
- {
- bUINotify = false;
- PV1 = DEVICE.GetDevice<IoValve>(TritonDevice.ValveChamberVent.ToString());
- PV2 = DEVICE.GetDevice<IoValve>(TritonDevice.ValveChamberVent.ToString());
- PV3 = DEVICE.GetDevice<IoValve>(TritonDevice.ValveChamberVent.ToString());
- PV4 = DEVICE.GetDevice<IoValve>(TritonDevice.ValveChamberVent.ToString());
- PV5 = DEVICE.GetDevice<IoValve>(TritonDevice.ValveChamberVent.ToString());
- PV6 = DEVICE.GetDevice<IoValve>(TritonDevice.ValveChamberVent.ToString());
- PV7 = DEVICE.GetDevice<IoValve>(TritonDevice.ValveChamberVent.ToString());
- PV8 = DEVICE.GetDevice<IoValve>(TritonDevice.ValveChamberVent.ToString());
- PV9 = DEVICE.GetDevice<IoValve>(TritonDevice.ValveChamberVent.ToString());
- SV7 = DEVICE.GetDevice<IoValve>(TritonDevice.ValveChamberVent.ToString());
- mfc1 = DEVICE.GetDevice<IoMfc>(TritonDevice.ValveChamberVent.ToString());
- mfc2 = DEVICE.GetDevice<IoMfc>(TritonDevice.ValveChamberVent.ToString());
- mfc3 = DEVICE.GetDevice<IoMfc>(TritonDevice.ValveChamberVent.ToString());
- mfc4 = DEVICE.GetDevice<IoMfc>(TritonDevice.ValveChamberVent.ToString());
- mfc5 = DEVICE.GetDevice<IoMfc>(TritonDevice.ValveChamberVent.ToString());
- MfcVapor = DEVICE.GetDevice<IoMfc>(TritonDevice.ValveChamberVent.ToString());
- }
- public bool InitCommon()
- {
- scOpenGasVavleTimeout = SC.GetSC<int>(SCName.System_TimeLimitOfOpenGasVavle);
- dOpenGasVavleTimeout = scOpenGasVavleTimeout.Value;
- scCloseGasVavleTimeout = SC.GetSC<int>(SCName.System_TimeLimitOfCloseGasValve);
- dCloseGasVavleTimeout = scCloseGasVavleTimeout.Value;
- scOpenCloseSlitVavleTimeout = SC.GetSC<int>(SCName.System_TimeLimitForOpenCloseSlitVavle);
- valveOpenCloseTimeout = scOpenCloseSlitVavleTimeout.Value;
- return true;
- }
- protected void UpdateSCValue()
- {
- dOpenGasVavleTimeout = scOpenGasVavleTimeout.Value;
- dCloseGasVavleTimeout = scCloseGasVavleTimeout.Value;
- valveOpenCloseTimeout = scOpenCloseSlitVavleTimeout.Value;
- }
- public void Loop(int id, string name, int count, Action<string> notify, Action<string> error)
- {
- Tuple<bool, Result> ret = Loop(id, () =>
- {
- notify(String.Format("{0}, Loop {1}", name, LoopCounter + 1));
- return true;
- }, count);
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL)
- throw (new RoutineFaildException());
- }
- }
- public void EndLoop(int id, Action<string> notify, Action<string> error)
- {
- Tuple<bool, Result> ret = EndLoop(id, () => { return true; });
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL)
- throw (new RoutineFaildException());
- throw (new RoutineBreakException());
- }
- }
- public void CheckDoor(int id, string name, Action<string> notify, Action<string> error)
- {
- Tuple<bool, Result> ret = Check(id, () =>
- {
- notify(name);
- notify(Resources.CommonRoutine_CheckDoor_CheckChamberDoor);
- if (DeviceModel.SensorChamberDoor != null && !DeviceModel.SensorChamberDoor.Value)
- {
- error(Resources.CommonRoutine_CheckDoor_ChamberDoorNotClosed);
- return false;
- }
- notify(Resources.CommonRoutine_CheckDoor_CheckBackpanelDoor);
- if (DeviceModel.SensorBackPanelDoor != null && !DeviceModel.SensorBackPanelDoor.Value)
- {
- error(Resources.CommonRoutine_CheckDoor_BackpanelDoorNotClosed);
- return false;
- }
- return true;
- });
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL)
- {
- //error("Door Not Closed");
- throw (new RoutineFaildException());
- }
- }
- }
- public void CheckDryPump(int id, string name, Action<string> notify, Action<string> error)
- {
- Tuple<bool, Result> ret = Check(id, () =>
- {
- notify(name);
- if (DeviceModel.MainPump.HasError)
- {
- error("pump is in error state");
- return false;
- }
- if (DeviceModel.MainPump.HasWarning)
- {
- error("pump is in warning state");
- return false;
- }
- if (!DeviceModel.MainPump.IsRunning)
- {
- error("pump not running");
- return false;
- }
- return true;
- });
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL)
- {
- throw (new RoutineFaildException());
- }
- }
- }
- public void CheckPSWCommunaction(int id, string name, Action<string> notify, Action<string> error)
- {
- Tuple<bool, Result> ret = Check(id, () =>
- {
- notify(name);
- //Add实际判断
- return true;
- });
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL)
- {
- error("Pressure Switch Lost Communcation");
- throw (new RoutineFaildException());
- }
- }
- }
- public void CloseAllValve(int id, string name, int time, Action<string> notify, Action<string> error)
- {
- Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
- {
- notify(name);
- string reason;
- foreach (IoValve valve in _valvesForPumping)
- {
- if (valve != null && !valve.TurnValve(false, out reason))
- {
- error(string.Format(Resources.CommonRoutine_CloseAllValve_CanNotCloseValve01, valve.Name, reason));
- }
- }
- return true;
- }, () =>
- {
- foreach (IoValve valve in _valvesForPumping)
- {
- if (valve != null && valve.Status)
- {
- return false;
- }
- }
- return true;
- }, time * 1000);
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL)
- {
- throw (new RoutineFaildException());
- }
- else if (ret.Item2 == Result.TIMEOUT) //timeout
- {
- foreach (IoValve valve in _valvesForPumping)
- {
- if (valve != null && !valve.Status)
- {
- error(string.Format(Resources.CommonRoutine_CloseAllValve_CanNotCloseValve0In1S, valve.Name, time));
- }
- }
- throw (new RoutineFaildException());
- }
- else
- throw (new RoutineBreakException());
- }
- }
- public void StopAllGasFlow(int id, string name, int time, Action<string> notify, Action<string> error)
- {
- Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
- {
- notify(name);
- IoMfc[] mfcs = { DeviceModel.MfcGas1, DeviceModel.MfcGas2, DeviceModel.MfcGas3, DeviceModel.MfcGas4, DeviceModel.MfcGas5 };
- for (int i = 0; i < mfcs.Length; i++)
- {
- if (mfcs[i] != null)
- mfcs[i].Ramp(0, 0);
- }
- return true;
- }, () =>
- {
- IoMfc[] mfcs = { DeviceModel.MfcGas1, DeviceModel.MfcGas2, DeviceModel.MfcGas3, DeviceModel.MfcGas4, DeviceModel.MfcGas5 };
- for (int i = 0; i < mfcs.Length; i++)
- {
- if (mfcs[i] != null)
- {
- if (mfcs[i].FeedBack > 1)
- return false;
- }
- }
- return true;
- }, time * 1000);
- if (ret.Item1)
- {
- throw (new RoutineBreakException());
- }
- }
- public void OpenPumpingValve(int id, string name, int time, Action<string> notify, Action<string> error)
- {
- Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
- {
- notify(name);
- string reason = string.Empty;
- if (DeviceModel.ValveChamberPumping != null && !DeviceModel.ValveChamberPumping.TurnValve(true, out reason))
- {
- error("can not set chamber pumping open valve to open, " + reason);
- return false;
- }
- return true;
- }, () =>
- {
- return DeviceModel.ValveChamberPumping.Status;
- }, time * 1000);
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL)
- {
- throw (new RoutineFaildException());
- }
- else if (ret.Item2 == Result.TIMEOUT) //timeout
- {
- if (!DeviceModel.ValveChamberPumping.Status)
- {
- error("can not set chamber pumping open valve to open");
- }
- throw (new RoutineFaildException());
- }
- else
- throw (new RoutineBreakException());
- }
- }
- public void OpenValve(int id, string name, IoValve valve, int time, Action<string> notify, Action<string> error)
- {
- Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
- {
- notify(String.Format(Resources.CommonRoutine_OpenValve_Open0, name));
- //打开阀门
- string reason = string.Empty;
- if (valve != null && !valve.TurnValve(true, out reason))
- {
- return false;
- }
- return true;
- }, () =>
- {
- //检查阀门是否打开
- return valve == null || (valve != null && valve.Status);
- }, time * 1000);
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL)
- {
- error(String.Format(Resources.CommonRoutine_OpenValve_0CanNotBeOpen, name));
- throw (new RoutineFaildException());
- }
- else if (ret.Item2 == Result.TIMEOUT) //timeout
- {
- //添加具体阀门
- error(String.Format(Resources.CommonRoutine_OpenValve_0CanNotBeOpen, name));
- throw (new RoutineFaildException());
- }
- else
- throw (new RoutineBreakException());
- }
- }
- public void ClosePumpValve(int id, string name, int time, Action<string> notify, Action<string> error)
- {
- Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
- {
- notify(name);
- string reason = string.Empty;
- if (DeviceModel.ValveChamberPumping != null && !DeviceModel.ValveChamberPumping.TurnValve(false, out reason))
- {
- return false;
- }
- return true;
- }, () =>
- {
- if (DeviceModel.ValveChamberPumping != null && DeviceModel.ValveChamberPumping.Status)
- return false;
- return true;
- }, time * 1000);
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL)
- {
- error(String.Format("pump valve can not be closed"));
- throw (new RoutineFaildException());
- }
- else if (ret.Item2 == Result.TIMEOUT) //timeout
- {
- error(String.Format("pump valve can not be closed in {0} seconds", time));
- throw (new RoutineFaildException());
- }
- else
- throw (new RoutineBreakException());
- }
- }
- public void CloseValve(int id, string name, IoValve valve, int time, Action<string> notify, Action<string> error)
- {
- Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
- {
- notify(String.Format(Resources.CommonRoutine_CloseValve_Close0, name));
- //打开阀门
- string reason = string.Empty;
- if (valve != null && !valve.TurnValve(false, out reason))
- {
- return false;
- }
- return true;
- }, () =>
- {
- //检查阀门是否打开
- return valve == null || (valve != null && !valve.Status);
- }, time * 1000);
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL)
- {
- error(String.Format(Resources.CommonRoutine_CloseValve_0CanNotBeClose, name));
- throw (new RoutineFaildException());
- }
- else if (ret.Item2 == Result.TIMEOUT) //timeout
- {
- //添加具体阀门
- error(String.Format(Resources.CommonRoutine_CloseValve_0CanNotBeClose, name));
- throw (new RoutineFaildException());
- }
- else
- throw (new RoutineBreakException());
- }
- }
- public void OpenValve(int id, string name, IoValve[] valves, int time, Action<string> notify, Action<string> error)
- {
- Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
- {
- notify(String.Format(Resources.CommonRoutine_OpenValve_Open0, name));
- //打开阀门
- string reason = string.Empty;
- foreach (var item in valves)
- {
- if (item != null && !item.TurnValve(true, out reason))
- {
- error(String.Format(Resources.CommonRoutine_OpenValve_0CanNotBeOpen, item.Name));
- return false;
- }
- }
- return true;
- }, () =>
- {
- //检查阀门是否打开
- foreach (var item in valves)
- {
- if (item != null && !item.Status)
- {
- return false;
- }
- }
- return true;
- }, time * 1000);
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL)
- {
- throw (new RoutineFaildException());
- }
- else if (ret.Item2 == Result.TIMEOUT) //timeout
- {
- //添加具体阀门
- foreach (var item in valves)
- {
- if (item != null && !item.Status)
- {
- error(String.Format(Resources.CommonRoutine_OpenValve_0CanNotBeOpen, item.Name));
- }
- }
- throw (new RoutineFaildException());
- }
- else
- throw (new RoutineBreakException());
- }
- }
- public void CloseValve(int id, string name, IoValve[] valves, int time, Action<string> notify, Action<string> error)
- {
- Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
- {
- notify(String.Format(Resources.CommonRoutine_CloseValve_Close0, name));
- //打开阀门
- string reason = string.Empty;
- foreach (var item in valves)
- {
- if (item != null && !item.TurnValve(false, out reason))
- {
- error(String.Format(Resources.CommonRoutine_CloseValve_0CanNotBeClose, item.Name));
- return false;
- }
- }
- return true;
- }, () =>
- {
- //检查阀门是否打开
- foreach (var item in valves)
- {
- if (item != null && item.Status)
- {
- return false;
- }
- }
- return true;
- }, time * 1000);
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL)
- {
- throw (new RoutineFaildException());
- }
- else if (ret.Item2 == Result.TIMEOUT) //timeout
- {
- //添加具体阀门
- foreach (var item in valves)
- {
- if (item != null && item.Status)
- {
- error(String.Format(Resources.CommonRoutine_CloseValve_0CanNotBeClose, item.Name));
- }
- }
- throw (new RoutineFaildException());
- }
- else
- throw (new RoutineBreakException());
- }
- }
- public void OpenMFC(int id, string name, IoMfc[] valves, int time, Action<string> notify, Action<string> error)
- {
- Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
- {
- notify(String.Format("Open {0}", name));
- //打开阀门
- string reason = string.Empty;
- foreach (var item in valves)
- {
- // if (!item.Ramp(false, out reason))
- {
- error(String.Format("{0} Can Not Be Open", item.Name));
- return false;
- }
- }
- return true;
- }, () =>
- {
- //检查阀门是否打开
- foreach (var item in valves)
- {
- // if (!item.Status)
- {
- return false;
- }
- }
- return true;
- }, time * 1000);
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL)
- {
- throw (new RoutineFaildException());
- }
- else if (ret.Item2 == Result.TIMEOUT) //timeout
- {
- //添加具体阀门
- foreach (var item in valves)
- {
- // if (!item.Status)
- {
- error(String.Format("{0} Can Not Be Open", item.Name));
- }
- }
- throw (new RoutineFaildException());
- }
- else
- throw (new RoutineBreakException());
- }
- }
- public void StopHeater(int id, string name, int time, Action<string> notify, Action<string> error)
- {
- Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
- {
- notify(String.Format("Close {0}", name));
- //Stop Heater
- string reason = string.Empty;
- return true;
- }, () =>
- {
- //Stop Heater
- return true;
- }, time * 1000);
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL)
- {
- throw (new RoutineFaildException());
- }
- else if (ret.Item2 == Result.TIMEOUT) //timeout
- {
- //添加
- error(String.Format("Heater Not Stop"));
- throw (new RoutineFaildException());
- }
- else
- throw (new RoutineBreakException());
- }
- }
- public void CheckTemper(int id, string name, double target, int time, Action<string> notify, Action<string> error)
- {
- Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
- {
- notify(name);
- return true;
- }, () =>
- {
- //检查是否Cooling
- return true;
- }, time * 1000);
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL)
- {
- throw (new RoutineFaildException());
- }
- else if (ret.Item2 == Result.TIMEOUT) //timeout
- {
- //
- error(String.Format("Cooling Time out"));
- throw (new RoutineFaildException());
- }
- else
- throw (new RoutineBreakException());
- }
- }
- public void CheckATM(int id, string name, int time, Action<string> notify, Action<string> error)
- {
- Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
- {
- notify(name);
- return true;
- }, () =>
- {
- //检查是否ATM
- return DeviceModel.PressureMeterChamber.Value >= 750000;
- }, time * 1000);
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL)
- {
- throw (new RoutineFaildException());
- }
- else if (ret.Item2 == Result.TIMEOUT) //timeout
- {
- //
- error(String.Format("Vent Time out"));
- throw (new RoutineFaildException());
- }
- else
- throw (new RoutineBreakException());
- }
- }
- public void CheckVAC(int id, string name, double target, int time, Action<string> notify, Action<string> error)
- {
- Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
- {
- notify(name);
- return true;
- }, () =>
- {
- if (DeviceModel.PressureMeterChamber.Value < target)
- {
- notify(string.Format(Resources.CommonRoutine_CheckVAC_PumpBelow0, target));
- return true;
- }
- return false;
- }, time * 1000);
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL)
- {
- throw (new RoutineFaildException());
- }
- else if (ret.Item2 == Result.TIMEOUT) //timeout
- {
- Warning(String.Format("Can not pump to base pressure {0} in {1} seconds", target, time));
- throw (new RoutineFaildException());
- }
- else
- throw (new RoutineBreakException());
- }
- }
- public void CheckCondition(int id, string name, ref bool result, Action<string> notify, Action<string> error, Func<bool> func)
- {
- Tuple<bool, Result> ret = Check(id, () =>
- {
- notify(name);
- return func();
- });
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL)
- {
- result = false;
- }
- else
- {
- result = true;
- }
- }
- }
- public void End(int id, string name, Action<string> notify, Action<string> error)
- {
- Tuple<bool, Result> ret = Execute(id, () =>
- {
- double duration_min = counter.GetElapseTime() / 1000.0 / 60;
- string info = string.Format(Resources.CommonRoutine_End_0FinishedIn1Minitues, Name, duration_min.ToString("0.0"));
- notify(info);
- EV.PostMessage(Module, EventEnum.ServiceRoutineStopped, Module, Name);
- if (bUINotify)
- EV.PostPopDialogMessage(EventLevel.Information, Name, String.Format("{0} {1}", Module, info));
- return true;
- });
- }
- //延时
- public void Delay(int id, string name, double time, Action<string> notify, Action<string> error)
- {
- Tuple<bool, Result> ret = Delay(id, () =>
- {
- notify(name);
- return true;
- }, time * 1000);
- if (ret.Item1)
- {
- if (ret.Item2 == Result.RUN)
- {
- throw (new RoutineBreakException());
- }
- }
- }
- ///等待DI
- public void WaitDI(int id, string name, DIAccessor di, bool value, int time, Action<string> notify, Action<string> error)
- {
- Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
- {
- notify(name);
- return true;
- }, () =>
- {
- return di.Value == value;
- }, time * 1000);
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL)
- {
- throw (new RoutineFaildException());
- }
- else if (ret.Item2 == Result.TIMEOUT) //timeout
- {
- error(String.Format("{0}超时失败,超时时间为{1}秒", name, time));
- throw (new RoutineFaildException());
- }
- else
- throw (new RoutineBreakException());
- }
- }
- public void CheckDI(int id, string name, DIAccessor di, bool value, ref bool result, Action<string> notify, Action<string> error)
- {
- Tuple<bool, Result> ret = Check(id, () =>
- {
- notify(name);
- return di.Value == value;
- });
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL)
- {
- result = false;
- }
- else
- {
- result = true;
- }
- }
- }
- public void DefautAndCloseFinal()
- {
- string reason = String.Empty;
- Default();
- }
- public void AlarmEvent()
- {
- }
- protected void Default()
- {
- string reason = String.Empty;
- }
- protected void StopRamp()
- {
- string reason = string.Empty;
- if (!DeviceModel.Rf.SetPowerOnOff(false, out reason))
- {
- LOG.Write(reason);
- }
- IoMfc[] mfcs = { DeviceModel.MfcGas1, DeviceModel.MfcGas2, DeviceModel.MfcGas3, DeviceModel.MfcGas4, DeviceModel.MfcGas5 };
- for (int i = 0; i < mfcs.Length; i++)
- {
- if (mfcs[i] != null)
- mfcs[i].Ramp(0, 0);
- }
- foreach (IoValve valve in _valvesForPumping)
- {
- if (valve != null && !valve.TurnValve(false, out reason))
- {
- LOG.Write(string.Format("can not close valve {0}, {1}", valve.Name, reason));
- }
- }
- }
- protected virtual void Notify(string message)
- {
- EV.PostMessage(Module, EventEnum.ServiceRoutineInfo, Module, Display, message);
- }
- protected virtual void Warning(string message)
- {
- EV.PostMessage(Module, EventEnum.DefaultWarning, message);
- }
- protected virtual void Stop(string reason)
- {
- StopRamp();
- EV.PostPopDialogMessage(EventLevel.Alarm, String.Format("{0} '{1}' stopped", Module, Display),
- String.Format("stop reason:{0}", reason));
- EV.PostMessage(Module, EventEnum.ServiceRoutineAborted, Module, Display, reason);
- }
- public void Abort()
- {
- StopRamp();
- }
- bool DeviceCyclePump(out string reason)
- {
- reason = "";
- if (DeviceModel.ValveChamberPumping != null && !DeviceModel.ValveChamberPumping.TurnValve(true, out reason))
- return false;
- if (DeviceModel.ValveProcessGasFinal != null && !DeviceModel.ValveProcessGasFinal.TurnValve(false, out reason))
- return false;
- if (DeviceModel.ValveChamberPurge != null && !DeviceModel.ValveChamberPurge.TurnValve(false, out reason))
- return false;
- if (DeviceModel.ValveChamberPurge == null && DeviceModel.ValveChamberVent != null)
- {
- if (!DeviceModel.ValveChamberVent.TurnValve(false, out reason))
- return false;
- }
- return true;
- }
- bool DeviceStopCyclePump(out string reason)
- {
- reason = "";
- if (DeviceModel.ValveChamberPumping != null && !DeviceModel.ValveChamberPumping.TurnValve(false, out reason))
- return false;
- return true;
- }
- bool DeviceCycleVent(out string reason)
- {
- reason = "";
- if (DeviceModel.ValveChamberPumping != null && !DeviceModel.ValveChamberPumping.TurnValve(false, out reason))
- return false;
- if (DeviceModel.ValveProcessGasFinal != null && !DeviceModel.ValveProcessGasFinal.TurnValve(true, out reason))
- return false;
- if (DeviceModel.ValveChamberPurge != null && !DeviceModel.ValveChamberPurge.TurnValve(true, out reason))
- return false;
- if (DeviceModel.ValveChamberPurge == null)
- {
- if (DeviceModel.ValveChamberVent != null && !DeviceModel.ValveChamberVent.TurnValve(true, out reason))
- return false;
- }
- return true;
- }
- bool DeviceStopCycleVent(out string reason)
- {
- reason = "";
- if (DeviceModel.ValveProcessGasFinal != null && !DeviceModel.ValveProcessGasFinal.TurnValve(false, out reason))
- return false;
- if (DeviceModel.ValveChamberPurge != null && !DeviceModel.ValveChamberPurge.TurnValve(false, out reason))
- return false;
- if (DeviceModel.ValveChamberPurge == null)
- {
- if (DeviceModel.ValveChamberVent != null && !DeviceModel.ValveChamberVent.TurnValve(false, out reason))
- return false;
- }
- return true;
- }
- //
- public void CyclePump(int id, string name, int target, int timeLimit, bool isStopPumpOnceDone, Action<string> notify, Action<string> error)
- {
- Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
- {
- notify(String.Format(Resources.CommonRoutine_CyclePump_PumpingPressureTo0MTor, target));
- string reason;
- if (!DeviceCyclePump(out reason))
- {
- error(reason);
- return false;
- }
- return true;
- }, () =>
- {
- if (DeviceModel.PressureMeterChamber != null && (DeviceModel.PressureMeterChamber.Value < target))
- {
- if (isStopPumpOnceDone)
- {
- string reason;
- if (!DeviceStopCyclePump(out reason))
- {
- error(reason);
- return false;
- }
- }
- return true;
- }
- return false;
- }, timeLimit * 1000);
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL)
- {
- throw (new RoutineFaildException());
- }
- else if (ret.Item2 == Result.TIMEOUT) //timeout
- {
- error(String.Format("Can not pump to pressure {0} in time {1}", target, timeLimit));
- throw (new RoutineFaildException());
- }
- else
- throw (new RoutineBreakException());
- }
- }
- public void CycleVent(int id, string name, int target, int timeLimit, bool isStopVentOnceDone, Action<string> notify, Action<string> error)
- {
- Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
- {
- notify(String.Format(Resources.CommonRoutine_CycleVent_VentPressureTo0Mtor, target));
- string reason;
- if (!DeviceCycleVent(out reason))
- {
- error(reason);
- return false;
- }
- return true;
- }, () =>
- {
- if (DeviceModel.PressureMeterChamber != null && DeviceModel.PressureMeterChamber.Value > target)
- {
- if (isStopVentOnceDone)
- {
- string reason;
- if (!DeviceStopCycleVent(out reason))
- {
- error(reason);
- return false;
- }
- }
- return true;
- }
- return false;
- }, timeLimit * 1000);
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL)
- {
- throw (new RoutineFaildException());
- }
- else if (ret.Item2 == Result.TIMEOUT) //timeout
- {
- error(String.Format("Can not purge to purge pressure {0} in purge time {1}", target, timeLimit));
- if (isStopVentOnceDone)
- {
- string reason;
- if (!DeviceStopCycleVent(out reason))
- {
- error(reason);
- }
- }
- throw (new RoutineFaildException());
- }
- else
- throw (new RoutineBreakException());
- }
- }
- public void RFPowerOn(int id, string name, int rfOnTime, float alarmRange, float alarmTime, Action<string> notify, Action<string> error)
- {
- Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
- {
- notify(name);
- string reason = string.Empty;
- if (!DeviceModel.Rf.SetPowerOnOff(true, out reason))
- {
- error(reason);
- return false;
- }
- return true;
- }, () =>
- {
- if (Elapsed >= rfOnTime)
- {
- notify(string.Format("RF stop"));
- IoValve[] valves = { DeviceModel.ValveMfc1, DeviceModel.ValveMfc2, DeviceModel.ValveMfc3, DeviceModel.ValveMfc4, DeviceModel.ValveMfc5 };
- IoMfc[] mfcs = { DeviceModel.MfcGas1, DeviceModel.MfcGas2, DeviceModel.MfcGas3, DeviceModel.MfcGas4, DeviceModel.MfcGas5 };
- string reason = string.Empty;
- for (int i = 0; i < mfcs.Length && i < valves.Length; i++)
- {
- if (valves[i] != null)
- valves[i].TurnValve(false, out reason);
- if (mfcs[i] != null)
- mfcs[i].Ramp(0, 0);
- }
- if (DeviceModel.ValveProcessGasFinal != null)
- DeviceModel.ValveProcessGasFinal.TurnValve(false, out reason);
- if (!DeviceModel.Rf.SetPowerOnOff(false, out reason))
- {
- error(reason);
- return null;
- }
- return true;
- }
- if (Math.Abs(DeviceModel.Rf.RFForwardPower - DeviceModel.Rf.PowerSetPoint) > alarmRange)
- {
- if (!timerStart)
- {
- timerStart = true;
- timerAlarm.Start(alarmTime);
- }
- if (ElapsedAlarm > alarmTime)
- {
- timerStart = false;
- timerAlarm.Stop();
- error(string.Format("RF power can not stable within {0} in power alarm time {1}", alarmRange, alarmTime));
- return null;
- }
- }
- else
- {
- timerStart = false;
- timerAlarm.Stop();
- }
- return false;
- }, rfOnTime * 1000);
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL)
- {
- string reason = string.Empty;
- if (!DeviceModel.Rf.SetPowerOnOff(false, out reason))
- {
- error(reason);
- }
- IoValve[] valves = { DeviceModel.ValveMfc1, DeviceModel.ValveMfc2, DeviceModel.ValveMfc3, DeviceModel.ValveMfc4, DeviceModel.ValveMfc5 };
- IoMfc[] mfcs = { DeviceModel.MfcGas1, DeviceModel.MfcGas2, DeviceModel.MfcGas3, DeviceModel.MfcGas4, DeviceModel.MfcGas5 };
- for (int i = 0; i < mfcs.Length && i < valves.Length; i++)
- {
- if (valves[i] != null)
- valves[i].TurnValve(false, out reason);
- if (mfcs[i] != null)
- mfcs[i].Ramp(0, 0);
- }
- if (DeviceModel.ValveProcessGasFinal != null)
- DeviceModel.ValveProcessGasFinal.TurnValve(false, out reason);
- throw (new RoutineFaildException());
- }
- throw (new RoutineBreakException());
- }
- }
- public void RFPowerOff(int id, string name, Action<string> notify, Action<string> error)
- {
- Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
- {
- notify(name);
- string reason = string.Empty;
- if (!DeviceModel.Rf.SetPowerOnOff(false, out reason))
- {
- error(reason);
- return false;
- }
- return true;
- }, () =>
- {
- return true;
- }, 0);
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL)
- {
- throw (new RoutineFaildException());
- }
- throw (new RoutineBreakException());
- }
- }
- public void CheckRfOff(int id, string name)
- {
- Tuple<bool, Result> ret = Check(id, () =>
- {
- Notify(name);
- return !DeviceModel.Rf.IsRfOn;
- });
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL)
- {
- Stop("RF power is on");
- throw (new RoutineFaildException());
- }
- else
- {
- throw (new RoutineBreakException());
- }
- }
- }
- public void CheckPumpingOn(int id, string name)
- {
- Tuple<bool, Result> ret = Check(id, () =>
- {
- Notify(name);
- return DeviceModel.MainPump.IsRunning && DeviceModel.ValveChamberPumping.Status;
- });
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL)
- {
- Stop("pump valve not open");
- throw (new RoutineFaildException());
- }
- else
- {
- throw (new RoutineBreakException());
- }
- }
- }
- public void CheckGasFlowStopped(int id, string name)
- {
- Tuple<bool, Result> ret = Check(id, () =>
- {
- Notify(name);
- IoValve[] valves = { DeviceModel.ValveMfc1, DeviceModel.ValveMfc2, DeviceModel.ValveMfc3, DeviceModel.ValveMfc4, DeviceModel.ValveMfc5, DeviceModel.ValveProcessGasFinal, };
- return !Array.Exists(valves, v => v != null && v.Status);
- });
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL)
- {
- Stop("Gas flow valves not all closed");
- throw (new RoutineFaildException());
- }
- else
- {
- throw (new RoutineBreakException());
- }
- }
- }
- public void SetRfMatchMode(int stepId, string name, int mode)
- {
- Tuple<bool, Result> ret = ExecuteAndWait(stepId, () =>
- {
- Notify(name);
- string reason = string.Empty;
- if (!DeviceModel.Rf.SetMatchMode(mode, out reason))
- {
- Stop(reason);
- return false;
- }
- return true;
- }, () => true, 0);
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL)
- {
- throw (new RoutineFaildException());
- }
- throw (new RoutineBreakException());
- }
- }
- public void VentToPrecision(int stepId, string name, int timeVent, Action<string> notify, Action<string> error)
- {
- Tuple<bool, Result> ret = Delay(stepId, () =>
- {
- notify(name);
- string reason;
- if (!DeviceModel.ValveChamberPumping.TurnValve(false, out reason))
- {
- error(reason);
- return false;
- }
- if (!DeviceModel.ValveChamberVent.TurnValve(true, out reason))
- {
- error(reason);
- return false;
- }
- return true;
- }, timeVent * 1000);
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL)
- {
- throw (new RoutineFaildException());
- }
- throw (new RoutineBreakException());
- }
- }
- }
- }
|