12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using Aitex.Core.Common;
- 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 Aitex.Core.Util;
- using EFEM.RT.Devices;
- using Aitex.Sorter.Common;
- using EFEMSC;
- using MECF.Framework.Common.Equipment;
- using MECF.Framework.Common.SubstrateTrackings;
- using MECF.Framework.Common.Utilities;
- using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.LoadPorts;
- using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.OcrReaders;
- using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robot;
- using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robot.NX100;
- using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robots.RobotBase;
- using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robots;
- using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.LoadPorts.LoadPortBase;
- using Aitex.Core.RT.Log;
- using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.BufferStations;
- using EFEM.RT.Devices.Flipper;
- using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Flipper.FlipperBase;
- using EFEM.RT.Modules;
- using static EFEM.RT.Devices.FlipperEntity;
- namespace EFEM.RT.Routines
- {
- public class CommonRoutine : SeqenecRoutine
- {
- protected bool bUINotify;
- public string Module { get; set; }
- public string Name { get; set; }
- public string Display { get; set; }
- //protected LoadPort loadportA = null;
- //protected LoadPort loadportB = null;
- //protected RIDReader ridreaderA = null;
- //protected RIDReader ridreaderB = null;
- protected RobotBaseDevice robot = null;
- protected Aligner aligner = null;
- protected OcrReader widreader = null;
- protected IoCoolingBuffer buffer1 = null;
- protected IoCoolingBuffer buffer2 = null;
- protected JetFlipper flipper = null;
- protected IoCoolingBuffer aligner1 = null;
- protected IoCoolingBuffer aligner2 = null;
- protected LoadLockDevice ll1 = null;
- protected LoadLockDevice ll2 = null;
- protected IoCoolingBuffer _ioCoolBuffer;
- protected BufferStation bf = null;
- protected BufferStation bf1 = null;
- protected BufferStation bf2 = null;
- private List<LoadPortBaseDevice> LPs;
- protected readonly bool HaveAligner = DeviceDefineManager.Instance.GetValue<bool>("AlignerInstalled") ?? false;
- protected readonly bool AlignerNeedMoveUpCommand = DeviceDefineManager.Instance.GetValue<bool>("AlignerNeedMoveUpCommand") ?? false;
- protected readonly int LoadPortQuantity = DeviceDefineManager.Instance.GetValue<int>("LoadPortQuantity") ?? 0;
- protected readonly string RobotTypeDefine = DeviceDefineManager.Instance.GetValue("RobotType");
- protected readonly bool HaveMotionAxis = DeviceDefineManager.Instance.GetValue<bool>("MotionAxisInstalled") ?? false;
- protected static readonly bool LoadLockDoorControlByStation = DeviceDefineManager.Instance.GetValue<bool>("LLDoorControlByStation") ?? false;
- //protected readonly string LoadPortTypeDefine = DeviceDefineManager.Instance.GetValue("LoadPortType");
- protected int OffsetX;
- protected int OffsetY;
- protected int OffsetZ;
- private DeviceTimer _timerQuery = new DeviceTimer();
- private int _queryPeriod = 500; //ms
- protected bool NeedSetParameter;
- protected bool IsStopped;
- private int _existInterval = SC.GetValue<int>("Robot.Robot.ExistInterval");
- protected bool NeedRobotGripAndUngrip=SC.GetValue<bool>("System.EnableRobotGripAndUngrip");
- public bool IsEnableIdentifyThickness
- {
- get
- {
- if (SC.ContainsItem("System.IsEnableIdentifyThickness"))
- return SC.GetValue<bool>("System.IsEnableIdentifyThickness");
- return false;
- }
- }
- public bool IsEnableMultiWaferSize
- {
- get
- {
- if (SC.ContainsItem("System.IsEnableMultiWaferSize"))
- return SC.GetValue<bool>("System.IsEnableMultiWaferSize");
- return false;
- }
- }
- public string EFemNum
- {
- get
- {
- if (SC.ContainsItem("System.EFEMNUM"))
- return SC.GetStringValue("System.EFEMNUM");
- return "001";
- }
- }
- public bool IsVacuumMode
- {
- get
- {
- if (SC.ContainsItem("Robot.Robot.IsVacuumMode"))
- return SC.GetValue<bool>("Robot.Robot.IsVacuumMode");
- return true;
- }
- }
- private DeviceTimer _timerPerf = new DeviceTimer();
- public CommonRoutine()
- {
- robot = DEVICE.GetDevice<RobotBaseDevice>(DeviceName.Robot);
- aligner = DEVICE.GetDevice<Aligner>(DeviceName.Aligner);
- widreader = DEVICE.GetDevice<OcrReader>(DeviceName.WIDReader);
- buffer1 = DEVICE.GetDevice<IoCoolingBuffer>(DeviceName.CoolingBuffer1);
- buffer2 = DEVICE.GetDevice<IoCoolingBuffer>(DeviceName.CoolingBuffer2);
- flipper = DEVICE.GetDevice<JetFlipper>(DeviceName.Flipper);
- aligner1 = DEVICE.GetDevice<IoCoolingBuffer>(DeviceName.Aligner1);
- aligner2 = DEVICE.GetDevice<IoCoolingBuffer>(DeviceName.Aligner2);
- ll1 = DEVICE.GetDevice<LoadLockDevice>(DeviceName.LL1);
- ll2 = DEVICE.GetDevice<LoadLockDevice>(DeviceName.LL2);
- bf = DEVICE.GetDevice<BufferStation>(DeviceName.Buffer);
- bf1 = DEVICE.GetDevice<BufferStation>(DeviceName.Buffer1);
- bf2 = DEVICE.GetDevice<BufferStation>(DeviceName.Buffer2);
- var lpNames = new List<ModuleName>(Singleton<DeviceManager>.Instance.LpNames);
- LPs = new List<LoadPortBaseDevice>();
- lpNames.ForEach(lp =>
- {
- if(!SC.GetValue<bool>($"LoadPort.{lp}.Disable"))
- LPs.Add(DEVICE.GetDevice<LoadPortBaseDevice>(lp.ToString()));
- });
- }
- public bool InitCommon()
- {
- return true;
- }
- protected void UpdateSCValue()
- {
- }
- //延时
- 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());
- }
- }
- }
- #region waferID
- #endregion
- #region robot
- public void RobotReset(int id, RobotBaseDevice device, string name, int time, Action<string> notify, Action<string> error)
- {
- Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
- {
- notify(String.Format("{0} clear error", device.Name));
- string reason = string.Empty;
- device.RobotReset();
- return true;
- }, () =>
- {
- if (!device.IsBusy&& device.RobotState != RobotStateEnum.Error && device.RobotState == RobotStateEnum.Idle)
- {
- return true;
- }
- return false;
- }, time * 1000);
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL)
- {
- throw (new RoutineFaildException());
- }
- else if (ret.Item2 == Result.TIMEOUT) //timeout
- {
- error(String.Format("{0} timeout, than {1} seconds", name, time));
- throw (new RoutineFaildException());
- }
- else
- throw (new RoutineBreakException());
- }
- }
- public void RobotServoOnOff(int id, Robot device, bool trueForOnFalseForOff, Action<string> notify, Action<string> error)
- {
- Tuple<bool, Result> ret = Execute(id, () =>
- {
- notify(String.Format("{0} Home", device.Name));
- string reason = string.Empty;
- return device.SetServoOnOff(trueForOnFalseForOff,out reason);
- });
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL)
- {
- throw (new RoutineFaildException());
- }
- }
- }
- public void RobotInit(int id, Robot device, string name, Action<string> notify, Action<string> error)
- {
- Tuple<bool, Result> ret = Execute(id, () =>
- {
- notify(String.Format("{0} Home", device.Name));
- string reason = string.Empty;
- return device.Init(out reason);
- });
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL)
- {
- throw (new RoutineFaildException());
- }
- }
- }
- public void RobotHome(int id, RobotBaseDevice device, string name, Action<string> notify, Action<string> error)
- {
- Tuple<bool, Result> ret = Execute(id, () =>
- {
- notify(String.Format("{0} Home", device.Name));
- string reason = string.Empty;
- return device.Home(null);
- });
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL)
- {
- throw (new RoutineFaildException());
- }
- }
- }
- public void RobotArmHome(int id, RobotBaseDevice device, string name, Action<string> notify, Action<string> error)
- {
- Tuple<bool, Result> ret = Execute(id, () =>
- {
- notify(String.Format("{0} Arm Home", device.Name));
- string reason = string.Empty;
- return device.Home(null);
- });
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL)
- {
- throw (new RoutineFaildException());
- }
- }
- }
- ///等待 Robot Motion
- public void WaitRobotMotion(int id, RobotBaseDevice device, string name, int time, Action<string> notify, Action<string> error)
- {
- Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
- {
- notify("Wait robot finish motion");
- _timerQuery.Start(_queryPeriod); //开始查询
- return true;
- }, () =>
- {
- if (device.IsReady())
- {
- _timerQuery.Stop();
- return true;
- }
- if (query())
- {
- // string reason = string.Empty;
- // device.QueryState(out reason); //查询位置
- }
- return false;
- }, time * 1000);
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL)
- {
- throw (new RoutineFaildException());
- }
- else if (ret.Item2 == Result.TIMEOUT) //timeout
- {
- error(String.Format("{0} timeout, than {1} seconds", name, time));
- throw (new RoutineFaildException());
- }
- else
- throw (new RoutineBreakException());
- }
- }
- ///等待
- ///
- public void ReserveRobotToBusy(int id, RobotBaseDevice robot, string name,Action<string> notify, Action<string> error)
- {
- Tuple<bool, Result> ret = Execute(id, () =>
- {
- notify(String.Format("{0} set robot to busy", robot.Name));
- string reason = string.Empty;
- robot.IsBusy = true;
- return true;
- });
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL)
- {
- throw (new RoutineFaildException());
- }
- }
- }
- public void Wait(int id, string name, double time, Action<string> notify, Action<string> error)
- {
- Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
- {
- notify($"Wait {time} seconds");
- _timerQuery.Start(_queryPeriod); //开始查询
- return true;
- }, () =>
- {
- if (_timerQuery.GetElapseTime() >= time * 1000)
- {
- _timerQuery.Stop();
- return true;
- }
- return false;
- });
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL)
- {
- throw (new RoutineFaildException());
- }
- else
- throw (new RoutineBreakException());
- }
- }
- public void CoolBufferMoveUP(int id, IoCoolingBuffer device, WaferSize size, int time, Action<string> notify, Action<string> error)
- {
- Tuple<bool, Result> ret = Execute(id, () =>
- {
- notify($"Start {device.Name} Move Up");
- if (device.CheckPinUp()) return true;
- if (!device.Move(size, true, out string reason))
- {
- Stop(reason);
- return false;
- }
- return true;
- });
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL)
- {
- throw (new RoutineFaildException());
- }
- }
- }
-
- public void RobotBusytoSimif(int id, ModuleName moduleName,bool on,int time, Action<string> notify, Action<string> error)
- {
- Tuple<bool, Result> ret = Execute(id, () =>
- {
- notify($"set TrigRBbusytoSIMF of {moduleName} signal {on} ");
- if (on)
- {
- var value = moduleName == ModuleName.LP1 ? DeviceModel.TrigRBbusytoSIMF1.SetTrigger(true, out _) : DeviceModel.TrigRBbusytoSIMF2.SetTrigger(true, out _);
- if (!value)
- {
- Stop(null);
- return false;
- }
- }
- else
- {
- var value = moduleName == ModuleName.LP1 ? DeviceModel.TrigRBbusytoSIMF1.SetTrigger(false, out _) : DeviceModel.TrigRBbusytoSIMF2.SetTrigger(false, out _);
- if (!value)
- {
- Stop(null);
- return false;
- }
- }
- return true;
- });
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL)
- {
- throw (new RoutineFaildException());
- }
- }
- }
- public void UnGripRobotBlade(int id, Hand blade, RobotBaseDevice device, int time)
- {
- Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
- {
- Notify($"Release robot {blade}");
- //IoSensor sensorBlade = blade == Hand.Blade1
- // ? DeviceModel.SensorRobotFork1WaferOn
- // : DeviceModel.SensorRobotFork2WaferOn;
- //var iswaferpersence = blade == Hand.Blade1 ? robot.IsWaferPresenceOnBlade1 : robot.IsWaferPresenceOnBlade2;
- //int slot = blade == Hand.Blade1 ? 0 : 1;
- //if (WaferManager.Instance.CheckNoWafer(ModuleName.Robot, slot)) //!sensorBlade.Value &&
- {
- if (!device.Release((RobotArmEnum)blade))
- {
- Stop(null);
- return false;
- }
- }
- return true;
- }, () =>
- {
- if (!device.IsBusy)
- {
- return true;
- }
- //此处如果发生错误,忽略
- return false;
- }, time * 1000);
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL)
- {
- throw (new RoutineFaildException());
- }
- else if (ret.Item2 == Result.TIMEOUT) //timeout
- {
- Stop($"Release robot {blade} timeout, than {time} seconds");
- throw (new RoutineFaildException());
- }
- else
- throw (new RoutineBreakException());
- }
- }
- public void GripRobotBlade(int id, Hand blade, RobotBaseDevice device, int time)
- {
- Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
- {
- Notify($"Grip robot {blade}");
- //IoSensor sensorBlade = blade == Hand.Blade1
- // ? DeviceModel.SensorRobotFork1WaferOn
- // : DeviceModel.SensorRobotFork2WaferOn;
- //var iswaferpersence = blade == Hand.Blade1 ? robot.IsWaferPresenceOnBlade1 : robot.IsWaferPresenceOnBlade2;
- //int slot = blade == Hand.Blade1 ? 0 : 1;
- //if (!iswaferpersence && WaferManager.Instance.CheckNoWafer(ModuleName.Robot, slot)) //!sensorBlade.Value &&
- //{
- if (!device.Grip((RobotArmEnum)blade))
- {
- Stop(null);
- return false;
- }
- // }
- return true;
- }, () =>
- {
- if (device.IsReady())
- {
- return true;
- }
- //此处如果发生错误,忽略
- return false;
- }, time * 1000);
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL)
- {
- throw (new RoutineFaildException());
- }
- else if (ret.Item2 == Result.TIMEOUT) //timeout
- {
- Stop($"Release robot {blade} timeout, than {time} seconds");
- throw (new RoutineFaildException());
- }
- else
- throw (new RoutineBreakException());
- }
- }
- public void HomeReleaseRobotBlade(int id, Hand blade, RobotBaseDevice device, int time)
- {
- Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
- {
- Notify($"Release robot {blade}");
- //IoSensor sensorBlade = blade == Hand.Blade1
- // ? DeviceModel.SensorRobotFork1WaferOn
- // : DeviceModel.SensorRobotFork2WaferOn;
- //var iswaferpersence = blade == Hand.Blade1 ? robot.IsWaferPresenceOnBlade1 : robot.IsWaferPresenceOnBlade2;
- //int slot = blade == Hand.Blade1 ? 0 : 1;
- //if (!iswaferpersence&&WaferManager.Instance.CheckNoWafer(ModuleName.Robot, slot)) //!sensorBlade.Value &&
- //{
- if (!device.Release((RobotArmEnum)blade))
- {
- Stop(null);
- return false;
- }
- // }
- return true;
- }, () =>
- {
- if (device.IsReady())
- {
- return true;
- }
- //此处如果发生错误,忽略
- return false;
- }, time * 1000);
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL)
- {
- throw (new RoutineFaildException());
- }
- else if (ret.Item2 == Result.TIMEOUT) //timeout
- {
- Stop($"Release robot {blade} timeout, than {time} seconds");
- throw (new RoutineFaildException());
- }
- else
- throw (new RoutineBreakException());
- }
- }
- public void HomeGripAndUngripRobotBlade(int id, Hand blade, RobotBaseDevice device, int time)
- {
- Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
- {
- Notify($"Grip or Ungrip robot {blade}");
-
- int slot = blade == Hand.Blade1 ? 0 : 1;
- if (WaferManager.Instance.CheckHasWafer(ModuleName.Robot, slot))
- {
- if (!device.Grip((RobotArmEnum)blade))
- {
- Stop(null);
- return false;
- }
- }
- else
- {
- if (!device.Release((RobotArmEnum)blade))
- {
- Stop(null);
- return false;
- }
- }
-
- //Thread.Sleep(1000);
- return true;
- }, () =>
- {
- if (device.IsReady())
- {
- return true;
- }
- //此处如果发生错误,忽略
- return false;
- }, time * 1000);
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL)
- {
- throw (new RoutineFaildException());
- }
- else if (ret.Item2 == Result.TIMEOUT) //timeout
- {
- Stop($"Grip robot {blade} timeout, than {time} seconds");
- throw (new RoutineFaildException());
- }
- else
- throw (new RoutineBreakException());
- }
- }
-
- public void CheckBladeWaferIsExist(int id, RobotBaseDevice device,Hand blade, int time)
- {
- Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
- {
- Notify($"Check Blade {blade} Wafer Is Exist");
- try
- {
- if (!device.IsReady())
- {
- LOG.Write($"CheckBladeWaferIsExist:Robot IsReady={device.IsReady()}");
- throw (new RoutineBreakException());
- }
- if (!device.ReadParameter(new object[] { "CheckWaferIsPresence", blade == Hand.Blade1 ? 0 : 1, _existInterval }))
- {
- Stop(null);
- return false;
- }
- }
- catch (Exception ex)
- {
- LOG.Write(ex);
- }
- LOG.Write($"Check Blade Wafer Is Exist");
- //Thread.Sleep(1000);
- return true;
- }, () =>
- {
- // LOG.Write("CheckBladeWaferIsExist1: IsReady=false");
- try
- {
- if (device.IsReady())
- {
- LOG.Write("CheckBladeWaferIsExist: IsReady=true");
- return true;
- }
- }
- catch (Exception ex)
- {
- LOG.Write(ex);
- }
- //LOG.Write("CheckBladeWaferIsExist2: IsReady=false");
- //此处如果发生错误,忽略
- return false;
- }, time * 1000);
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL)
- {
- throw (new RoutineFaildException());
- }
- else if (ret.Item2 == Result.TIMEOUT) //timeout
- {
- Stop($"Check robot WaferPresence timeout, than {time} seconds");
- throw (new RoutineFaildException());
- }
- else
- throw (new RoutineBreakException());
- }
- }
- public void RobotSignalStatus(int id, RobotBaseDevice device , int time)
- {
- Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
- {
- Notify($"Query robot Signal Status");
- if (!device.ReadParameter(new object[] { "SignalStatus"}))
- {
- Stop(null);
- return false;
- }
- //Thread.Sleep(1000);
- return true;
- }, () =>
- {
- if (device.IsReady())
- {
- return true;
- }
- //此处如果发生错误,忽略
- return false;
- }, time * 1000);
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL)
- {
- throw (new RoutineFaildException());
- }
- else if (ret.Item2 == Result.TIMEOUT) //timeout
- {
- throw (new RoutineFaildException());
- }
- else
- throw (new RoutineBreakException());
- }
- }
- public void ConfirmRobotBladeWafer(int id, Hand blade)
- {
- Execute(id, () =>
- {
- Notify($"Confirm robot {blade} wafer");
- //IoSensor sensorBlade = blade == Hand.Blade1
- // ? DeviceModel.SensorRobotFork1WaferOn
- // : DeviceModel.SensorRobotFork2WaferOn;
- var iswaferpersence = blade == Hand.Blade1 ? robot.IsWaferPresenceOnBlade1 : robot.IsWaferPresenceOnBlade2;
- int slot = blade == Hand.Blade1 ? 0 : 1;
- if (iswaferpersence)
- {
- if (WaferManager.Instance.CheckNoWafer(ModuleName.Robot, slot))
- {
- EV.PostWarningLog(Module, $"Found wafer at robot {blade}");
- WaferManager.Instance.CreateWafer(ModuleName.Robot, slot, WaferStatus.Normal);
- }
- }
- else
- {
- if (WaferManager.Instance.CheckHasWafer(ModuleName.Robot, slot))
- {
- EV.PostWarningLog(Module, $"Not found wafer at robot {blade}, please manually confirm again.");
- WaferManager.Instance.DeleteWafer(ModuleName.Robot, slot);
- }
- }
- return true;
- });
- }
- public void CoolBufferMoveDown(int id, IoCoolingBuffer device, WaferSize size, int time, Action<string> notify, Action<string> error)
- {
- Tuple<bool, Result> ret = Execute(id, () =>
- {
- notify($"Start {device.Name} Move Down");
- if (device.CheckPinDown()) return true;
- if (!device.Move(size, false, out string reason))
- {
- Stop(reason);
- return false;
- }
- return true;
- });
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL)
- {
- throw (new RoutineFaildException());
- }
- }
- }
- public void WaitCoolBufferMoveUp(int id, IoCoolingBuffer device, string name, int time, Action<string> notify,
- Action<string> error)
- {
- var ret = ExecuteAndWait(id, () =>
- {
- notify(name);
- return true;
- }, () =>
- {
- if (device.Error)
- {
- Stop("Can not move up, device error");
- return null;
- }
- return device.CheckMovedUp() && !device.Busy ;
- }, time * 1000);
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL)
- throw new RoutineFaildException();
- if (ret.Item2 == Result.TIMEOUT) //timeout
- {
- error($"{name} timeout, than {time} seconds");
- throw new RoutineFaildException();
- }
- bool isMovedUp = device.CheckMovedUp() && !device.Busy && !device.Error;
- if (!isMovedUp)
- {
- throw new RoutineBreakException();
- }
- }
- }
- public void WaitCoolBufferMoveDown(int id, IoCoolingBuffer device, string name, int time, Action<string> notify,
- Action<string> error)
- {
- var ret = ExecuteAndWait(id, () =>
- {
- notify(name);
- _timerQuery.Start(_queryPeriod); //开始查询
- return true;
- }, () =>
- {
- if (device.Error)
- {
- Stop("Can not move down, device error");
- return null;
- }
- return device.CheckMovedDown() && !device.Busy;
- }, time * 1000);
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL) throw new RoutineFaildException();
- if (ret.Item2 == Result.TIMEOUT) //timeout
- {
- error($"{name} timeout, than {time} seconds");
- throw new RoutineFaildException();
- }
- bool isMovedDown = device.CheckMovedDown() && !device.Busy && !device.Error;
- if (!isMovedDown)
- {
- throw new RoutineBreakException();
- }
- }
- }
- public void SetWaferSize(int id, string name, int cmd, ModuleName station, int slot, int time, Action<string> notify, Action<string> error)
- {
- Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
- {
- WaferSize size = WaferSize.WS0;
- if (ModuleHelper.IsLoadPort(station))
- {
-
- }
- else
- {
- size = WaferManager.Instance.GetWaferSize(station, slot);
- }
- notify(String.Format($"Set WaferSize parameter {cmd} {size.ToString()}"));
- string reason = string.Empty;
- //robot.SetWaferSize(cmd, size, out reason);
- return true;
- }, () =>
- {
- if (robot.RobotState == RobotStateEnum.Idle)
- {
- return true;
- }
- return false;
- }, time * 1000);
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL)
- {
- throw (new RoutineFaildException());
- }
- else if (ret.Item2 == Result.TIMEOUT) //timeout
- {
- error(String.Format("Set WaferSize timeout, than {0} seconds", time));
- throw (new RoutineFaildException());
- }
- else
- throw (new RoutineBreakException());
- }
- }
- /// <summary>
- /// 目前只比对0114 parameter
- /// </summary>
- /// <param name="id"></param>
- /// <param name="name"></param>
- /// <param name="parameterNo"></param>
- /// <param name="parameterType"></param>
- /// <param name="waferSize"></param>
- /// <param name="time"></param>
- /// <param name="notify"></param>
- /// <param name="error"></param>
- /// <exception cref="RoutineFaildException"></exception>
- /// <exception cref="RoutineBreakException"></exception>
- protected void RobotGoto(int id, string name, ModuleName chamber, int slot, Hand blade, RobotPostionEnum postype,
- Action<string> notify, Action<string> error)
- {
- var reason = string.Empty;
- var ret = Execute(id, () =>
- {
- notify(string.Format("pick from {0}", chamber.ToString()));
- var obj = new object[] { (RobotArmEnum)(int)blade, chamber.ToString(), slot, postype };
- return robot.GoTo(obj);// (RobotArmEnum)(int)blade, chamber.ToString(), slot);
- });
- if (ret.Item1)
- if (ret.Item2 == Result.FAIL)
- {
- error(reason);
- throw new RoutineFaildException();
- }
- }
- protected void CheckTriggerSignalOn(int id,string name,ModuleName module,int time)
- {
- Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
- {
- Notify(String.Format("Check Trigger Signal"));
- string reason = string.Empty;
- return true;
- }, () =>
- {
- if (SC.GetValue<bool>("System.IsSimulatorMode")) return true;
- if (module.Equals(ModuleName.LL1))
- {
- if (DeviceModel.SensorPMASystemInterlock.Value && DeviceModel.TrigSafetytoPMA.Value)
- {
- return true;
- }
- }
- if (module.Equals(ModuleName.LL2))
- {
- if (DeviceModel.SensorPMBSystemInterlock.Value && DeviceModel.TrigSafetytoPMB.Value)
- {
- return true;
- }
- }
- return false;
- }, time * 1000);
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL)
- {
- throw (new RoutineFaildException());
- }
- else if (ret.Item2 == Result.TIMEOUT) //timeout
- {
- Stop(String.Format("Trigger Signal Change timeout, than {0} seconds", time));
- throw (new RoutineFaildException());
- }
- else
- throw (new RoutineBreakException());
- }
- }
- protected void PickWafer(int id, string name, ModuleName chamber, int slot, Hand blade, int x, int y, int z,
- Action<string> notify, Action<string> error)
- {
- var reason = string.Empty;
- var ret = Execute(id, () =>
- {
- notify(string.Format("pick from {0}", chamber.ToString()));
- if (x == 0 && y == 0 && z == 0)
- return robot.Pick((RobotArmEnum)(int)blade,chamber.ToString(), slot);
- return robot.PickEx((RobotArmEnum)(int)blade, chamber.ToString(), slot, x, y, z);
- });
- if (ret.Item1)
- if (ret.Item2 == Result.FAIL)
- {
- error(reason);
- throw new RoutineFaildException();
- }
- }
- protected void PlaceWafer(int id, string name, ModuleName chamber, int slot, Hand blade, int x, int y, int z,
- Action<string> notify, Action<string> error)
- {
- var ret = Execute(id, () =>
- {
- notify(string.Format("Place wafer to {0}", chamber.ToString()));
- var reason = string.Empty;
- if (x == 0 && y == 0 && z == 0)
- return robot.Place((RobotArmEnum)(int)blade, chamber.ToString(), slot);
- return robot.PlaceEx((RobotArmEnum)(int)blade, chamber.ToString(), slot, x, y, z);
- });
- if (ret.Item1)
- if (ret.Item2 == Result.FAIL)
- throw new RoutineFaildException();
- }
- #endregion
- protected bool CheckRobotMotionInterlock(ModuleName chamber, int slot, out string reason) //Pick/Place/Swap
- {
- reason = string.Empty;
- if (robot.RobotState == RobotStateEnum.Error)
- {
- reason = "robot is error.";
- return false;
- }
- //if (!robot.IsIdle)
- //{
- // reason = string.Format("robot is moving.");
- // return false;
- //}
- if (!CheckRobotReady())
- {
- reason = string.Format("robot isn't Ready.");
- return false;
- }
- if (chamber == ModuleName.Aligner)
- {
- if (aligner.Moving)
- {
- reason = string.Format("aligner is moving.");
- return false;
- }
- if (!CheckAlignerReady())
- {
- reason = string.Format("aligner isn't Ready.");
- return false;
- }
- /*
- if (aligner.Busy)
- {
- reason = string.Format("{0} is busy.", chamber.ToString());
- return false;
- }
- */
- return true;
- }
- else if (ModuleHelper.IsLoadPort(chamber))
- {
- LoadPortBaseDevice loadport = DEVICE.GetDevice<LoadPortBaseDevice>(chamber.ToString());
- if (!loadport.IsEnableTransferWafer(out _))
- {
- reason = string.Format("{0} isn't Ready.", chamber.ToString());
- return false;
- }
- if (loadport.MapError)
- {
- reason = string.Format("{0} Map has crossed error.", chamber.ToString());
- return false;
- }
- if (chamber.Equals(ModuleName.LP1))
- {
- if (SC.GetValue<int>($"LoadPort.LP1.CstType") == 0)
- {
- if (!DeviceModel.SensorSMIF1PODOPEN.Value)
- {
- reason = string.Format("{0} SMIF1PODOPEN signal is Off.", chamber.ToString());
- return false;
- }
- if (!DeviceModel.SensorSMIF1PODPRESENT.Value)
- {
- reason = string.Format("{0} SensorSMIF1PODPRESENT signal is Off,Foup is presence.", chamber.ToString());
- return false;
- }
- if (!DeviceModel.SensorSMIF1READY.Value)
- {
- reason = string.Format("{0} SensorSMIF1READY signal is Off.", chamber.ToString());
- return false;
- }
- }
- else if (SC.GetValue<int>($"LoadPort.LP1.CstType") == 1)
- {
- if(loadport.CassetteState!=LoadportCassetteState.Normal)// (DeviceModel.Sensor4InchCstPresence.Value&& DeviceModel.Sensor6InchCstPresence.Value&& DeviceModel.Sensor8InchCstPresence.Value)
- {
- reason = string.Format("{0} Cst Presence signal is Off,Foup is not presence.", chamber.ToString());
- return false;
- }
- }
- else if (SC.GetValue<int>($"LoadPort.LP1.CstType") == 2)
- {
- if (!DeviceModel.SensorLP1FoupOpen.Value)
- {
- reason = string.Format("{0} SensorLP1FoupOpen signal is Off. Foup is not open.", chamber.ToString());
- return false;
- }
- if (!DeviceModel.SensorLP1FoupPlacement.Value)
- {
- reason = string.Format("{0} SensorLP1FoupPlacement signal is Off. Foup is not placed.", chamber.ToString());
- return false;
- }
- if (!DeviceModel.SensorLP1OperationStatus.Value)
- {
- reason = string.Format("{0} SensorLP1OperationStatus signal is Off. Foup is not in operation status.", chamber.ToString());
- return false;
- }
- if (!DeviceModel.SensorLP1Ready.Value)
- {
- reason = string.Format("{0} SensorLP1Ready signal is Off. Foup is not ready.", chamber.ToString());
- return false;
- }
- if (!DeviceModel.SensorLP1Presence.Value)
- {
- reason = string.Format("{0} SensorLP1Presence signal is Off. Foup is not present.", chamber.ToString());
- return false;
- }
- }
- if (slot + 1 > loadport.ValidSlotsNumber)
- {
- reason = string.Format("{0} ValidSlotsNumber less than {1}.", chamber.ToString(), slot + 1);
- return false;
- }
- }
- else if (chamber.Equals(ModuleName.LP2))
- {
- if (SC.GetValue<int>($"LoadPort.LP2.CstType") == 0)
- {
- if (!DeviceModel.SensorSMIF2PODOPEN.Value)
- {
- reason = string.Format("{0} SMIF2PODOPEN signal is Off.", chamber.ToString());
- return false;
- }
- if (!DeviceModel.SensorSMIF2PODPRESENT.Value)
- {
- reason = string.Format("{0} SensorSMIF2PODPRESENT signal is Off,Foup is not presence .", chamber.ToString());
- return false;
- }
- if (!DeviceModel.SensorSMIF2READY.Value)
- {
- reason = string.Format("{0} SensorSMIF2READY signal is Off.", chamber.ToString());
- return false;
- }
- }
- else if (SC.GetValue<int>($"LoadPort.LP2.CstType") == 1)
- {
- if (loadport.CassetteState != LoadportCassetteState.Normal)// (DeviceModel.Sensor4InchCstPresence.Value&& DeviceModel.Sensor6InchCstPresence.Value&& DeviceModel.Sensor8InchCstPresence.Value)
- {
- reason = string.Format("{0} Cst Presence signal is Off,Foup is not presence.", chamber.ToString());
- return false;
- }
- }
- else if (SC.GetValue<int>($"LoadPort.LP2.CstType") == 2)
- {
- if (!DeviceModel.SensorLP2FoupOpen.Value)
- {
- reason = string.Format("{0} SensorLP2FoupOpen signal is Off. Foup is not open.", chamber.ToString());
- return false;
- }
- if (!DeviceModel.SensorLP2FoupPlacement.Value)
- {
- reason = string.Format("{0} SensorLP2FoupPlacement signal is Off. Foup is not placed.", chamber.ToString());
- return false;
- }
- if (!DeviceModel.SensorLP2OperationStatus.Value)
- {
- reason = string.Format("{0} SensorLP2OperationStatus signal is Off. Foup is not in operation status.", chamber.ToString());
- return false;
- }
- if (!DeviceModel.SensorLP2Ready.Value)
- {
- reason = string.Format("{0} SensorLP2Ready signal is Off. Foup is not ready.", chamber.ToString());
- return false;
- }
- if (!DeviceModel.SensorLP2Presence.Value)
- {
- reason = string.Format("{0} SensorLP2Presence signal is Off. Foup is not present.", chamber.ToString());
- return false;
- }
- }
- if (slot + 1 > loadport.ValidSlotsNumber)
- {
- reason = string.Format("{0} ValidSlotsNumber less than {1}.", chamber.ToString(), slot + 1);
- return false;
- }
- }
- return true;
- }
- if (ModuleHelper.IsLoadLock(chamber))
- {
- var ll = DEVICE.GetDevice<LoadLockDevice>(chamber.ToString());
- if (ll != null && !ll.IsEnableTransferWafer(out reason))
- return false;
- return true;
- }
- if (ModuleHelper.IsBuffer(chamber))
- {
- var bufferStation = DEVICE.GetDevice<BufferStation>(chamber.ToString());
- if (bufferStation !=null && !bufferStation.IsEnableTransferWafer(out reason))
- return false;
- return true;
- }
- if (ModuleHelper.IsCoolingBuffer(chamber)|| ModuleHelper.IsAligner(chamber))
- {
- IoCoolingBuffer buffer = DEVICE.GetDevice<IoCoolingBuffer>(chamber.ToString());
- if(buffer != null)
- {
- if (buffer.Busy)
- {
- reason = "buffer is not idle";
- return false;
- }
- if (!buffer.CheckPinUp())
- {
- reason = "buffer pin not up position";
- return false;
- }
- }
- return true;
- }
- if (ModuleHelper.IsFlipper(chamber))
- {
- return true;
- }
- reason = "error target";
- return false;
- }
- protected bool CheckRobotReady()
- {
- return robot.IsReady();
- }
- protected bool CheckRobotMotionInterlock(out string reason)
- {
- reason = string.Empty;
- if (robot.RobotState != RobotStateEnum.Idle )
- {
- reason = string.Format("robot is not idle.");
- return false;
- }
-
- if (!CheckRobotReadySensor())
- {
- reason = string.Format("robot isn't ready.");
- return false;
- }
- return true;
- }
- public void QueryLoadportState(int id, LoadPort device)
- {
- Tuple<bool, Result> ret = Execute(id, () =>
- {
- Notify(String.Format("Query {0} state", device.Name));
- return device.IsIdle;
- });
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL)
- {
- Stop("not idle");
- throw (new RoutineFaildException());
- }
- else
- throw (new RoutineBreakException());
- }
- }
- public void QueryAlignerState(int id, Aligner device)
- {
- Tuple<bool, Result> ret = Execute(id, () =>
- {
- Notify(String.Format("Query {0} state", device.Name));
- return device.State == DeviceState.Idle;
- });
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL)
- {
- Stop("not idle");
- throw (new RoutineFaildException());
- }
- else
- throw (new RoutineBreakException());
- }
- }
- public void QueryCoolBufferState(int id, IoCoolingBuffer device)
- {
- var ret = Execute(id, () =>
- {
- Notify(string.Format("Query {0} state", device.Name));
- return true;
- });
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL)
- {
- Stop("Station wafer status error");
- throw new RoutineFaildException();
- }
- throw new RoutineBreakException();
- }
- }
- public IoCoolingBuffer GetCoolBuffer(ModuleName coolbufferName)
- {
- switch (coolbufferName)
- {
- case ModuleName.CoolingBuffer1:
- _ioCoolBuffer = buffer1;
- break;
- case ModuleName.CoolingBuffer2:
- _ioCoolBuffer = buffer2;
- break;
- case ModuleName.Aligner1:
- _ioCoolBuffer = aligner1;
- break;
- case ModuleName.Aligner2:
- _ioCoolBuffer = aligner2;
- break;
- }
- return _ioCoolBuffer;
- }
- public JetFlipper GetFlipper()
- {
- return flipper;
- }
- public void QueryLoadportState(int id, string deviceName, int time)
- {
- LoadPortBaseDevice device = DEVICE.GetDevice<LoadPortBaseDevice>(deviceName);
- Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
- {
- Notify(String.Format("{0} query state", deviceName));
- string reason = string.Empty;
- device.QueryState(out reason);
- return true;
- }, () =>
- {
- if (device.IsReady())
- {
- return true;
- }
- return false;
- }, time * 1000);
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL)
- {
- throw (new RoutineFaildException());
- }
- else if (ret.Item2 == Result.TIMEOUT) //timeout
- {
- Stop(String.Format("{0} query timeout, than {1} seconds", device.Name, time));
- throw (new RoutineFaildException());
- }
- else
- throw (new RoutineBreakException());
- }
- }
- public void IsLoadLockReadyToTransfer(string deviceName)
- {
- var device = DEVICE.GetDevice<LoadLockDevice>(deviceName);
- if (!device.IsEnableTransferWafer(out var reason))
- {
- EV.PostMessage(deviceName, EventEnum.DefaultWarning, reason);
- throw new RoutineBreakException();
- }
- }
- public void LoadLockOpenAtmDoor(int id, LoadLockDevice device, string name, int time, Action<string> notify, Action<string> error)
- {
- Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
- {
- notify(name);
- _timerQuery.Start(_queryPeriod); //开始查询
- return LoadLockDevice.LoadLockAtmDoorState == LoadLockDoorState.Opened || LoadLockDevice.OpenAtmDoor(out string reason);
- }, () =>
- {
- if (LoadLockDevice.LoadLockAtmDoorState == LoadLockDoorState.Opened)
- return true;
- return false;
- }, time * 1000);
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL)
- {
- throw (new RoutineFaildException());
- }
- else if (ret.Item2 == Result.TIMEOUT) //timeout
- {
- error(String.Format("{0} timeout, than {1} seconds", name, time));
- throw (new RoutineFaildException());
- }
- else
- throw (new RoutineBreakException());
- }
- }
- public void LoadLockCloseAtmDoor(int id, LoadLockDevice device, string name, int time, Action<string> notify, Action<string> error)
- {
- Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
- {
- notify(name);
- return LoadLockDevice.LoadLockAtmDoorState == LoadLockDoorState.Closed || LoadLockDevice.CloseAtmDoor(out string reason);
- }, () =>
- {
- if (LoadLockDevice.LoadLockAtmDoorState == LoadLockDoorState.Closed)
- return true;
- return false;
- }, time * 1000);
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL)
- {
- throw (new RoutineFaildException());
- }
- else if (ret.Item2 == Result.TIMEOUT) //timeout
- {
- error(String.Format("{0} timeout, than {1} seconds", name, time));
- throw (new RoutineFaildException());
- }
- else
- throw (new RoutineBreakException());
- }
- }
- public void LoadLockOpenVtmDoor(int id, LoadLockDevice device, string name, int time, Action<string> notify, Action<string> error)
- {
- Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
- {
- notify(name);
- _timerQuery.Start(_queryPeriod); //开始查询
- return LoadLockDevice.LoadLockVtmDoorState == LoadLockDoorState.Opened || LoadLockDevice.OpenVtmDoor(out string reason);
- }, () =>
- {
- if (LoadLockDevice.LoadLockVtmDoorState == LoadLockDoorState.Opened)
- return true;
- return false;
- }, time * 1000);
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL)
- {
- throw (new RoutineFaildException());
- }
- else if (ret.Item2 == Result.TIMEOUT) //timeout
- {
- error($"{name} timeout, than {time} seconds");
- throw (new RoutineFaildException());
- }
- else
- throw (new RoutineBreakException());
- }
- }
- public void LoadLockCloseVtmDoor(int id, LoadLockDevice device, string name, int time, Action<string> notify, Action<string> error)
- {
- Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
- {
- notify(name);
- return LoadLockDevice.LoadLockVtmDoorState == LoadLockDoorState.Closed || LoadLockDevice.CloseVtmDoor(out string reason);
- }, () =>
- {
- if (LoadLockDevice.LoadLockVtmDoorState == LoadLockDoorState.Closed)
- return true;
- return false;
- }, time * 1000);
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL)
- {
- throw (new RoutineFaildException());
- }
- else if (ret.Item2 == Result.TIMEOUT) //timeout
- {
- error(String.Format("{0} timeout, than {1} seconds", name, time));
- throw (new RoutineFaildException());
- }
- else
- throw (new RoutineBreakException());
- }
- }
- protected void Default()
- {
- string reason = String.Empty;
- }
- protected virtual void Warning(string message)
- {
- EV.PostMessage(Module, EventEnum.DefaultWarning, message);
- }
- ///等待 Aligner Motion
- public void WaitAlignerMotion(int id, Aligner device, string name, int time, Action<string> notify, Action<string> error)
- {
- Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
- {
- notify(name);
- _timerQuery.Start(_queryPeriod); //开始查询
- return true;
- }, () =>
- {
- // if (device.Moving == false && CheckAlignerReady())
- if (device.Busy == false && CheckAlignerReady())
- {
- _timerQuery.Stop();
- return true;
- }
- if (query())
- {
- // string reason = string.Empty;
- // device.QueryState(out reason); //查询位置
- }
- return false;
- }, time * 1000);
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL)
- {
- throw (new RoutineFaildException());
- }
- else if (ret.Item2 == Result.TIMEOUT) //timeout
- {
- error(String.Format("{0} timeout, than {1} seconds", name, time));
- throw (new RoutineFaildException());
- }
- else
- throw (new RoutineBreakException());
- }
- }
- protected virtual void Notify(string message)
- {
- EV.PostInfoLog(Module, $"{Name}, {message}");
- }
- protected virtual void Stop(string failReason)
- {
- EV.PostAlarmLog(Module, $"{Name}, {failReason}");
- }
- public void Abort()
- {
- }
- private bool query()
- {
- if (_timerQuery.IsTimeout())
- {
- _timerQuery.Start(_queryPeriod);
- return true;
- }
- return false;
- }
- protected bool CheckSeneorHasWafer(ModuleName chamber, int slot)
- {
- if (!SC.GetValue<bool>(SorterCommon.ScPathName.System_IsSimulatorMode))
- {
- if (chamber == ModuleName.Robot)
- {
- if (slot == 0)
- return robot.IsWaferPresenceOnBlade1;//!DeviceModel.SensorRBlowerArmhavewafer.Value;
- return robot.IsWaferPresenceOnBlade2;
- }
- //if (chamber == ModuleName.Aligner)
- //{
- // return !DeviceModel.SensorPreAlignerWaferOn.Value;
- //}
- }
- return WaferManager.Instance.CheckHasWafer(chamber, slot);
- }
- protected bool CheckSensorNoWafer(ModuleName chamber, int slot)
- {
- if (!SC.GetValue<bool>(SorterCommon.ScPathName.System_IsSimulatorMode))
- {
- if (chamber == ModuleName.Robot)
- {
- if (slot == 0)
- return !robot.IsWaferPresenceOnBlade1; //DeviceModel.SensorRBlowerArmhavewafer.Value;
- return !robot.IsWaferPresenceOnBlade2; //DeviceModel.SensorRBupperArmhavewafer.Value;
- }
- //if (chamber == ModuleName.Aligner)
- //{
- // return DeviceModel.SensorPreAlignerWaferOn.Value;
- //}
- }
- return WaferManager.Instance.CheckNoWafer(chamber, slot);
- }
- protected bool CheckRobotReadySensor()
- {
- return (robot.RobotState == RobotStateEnum.Idle);
- }
- protected bool CheckAlignerReady()
- {
- return true;
- }
- ///等待 Loadport
- public void LoadportReset(int id, LoadPortBaseDevice device, string name, int time, Action<string> notify, Action<string> error)
- {
- Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
- {
- notify(String.Format("{0} clear error", device.Name));
- string reason = string.Empty;
- return device.LoadportReset(out reason);
- }, () =>
- {
- if (device.IsReady())
- {
- return true;
- }
- return false;
- }, time * 1000);
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL)
- {
- throw (new RoutineFaildException());
- }
- else if (ret.Item2 == Result.TIMEOUT) //timeout
- {
- error(String.Format("{0} timeout, than {1} seconds", name, time));
- throw (new RoutineFaildException());
- }
- else
- throw (new RoutineBreakException());
- }
- }
- public void LoadportInit(int id, LoadPortBaseDevice device, string name, Action<string> notify, Action<string> error)
- {
- Tuple<bool, Result> ret = Execute(id, () =>
- {
- notify(String.Format("{0} Home", device.Name));
- string reason = string.Empty;
- return device.Home(out reason);
- });
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL)
- {
- throw (new RoutineFaildException());
- }
- }
- }
- protected bool CheckLoadportMotionInterlock(ModuleName chamber, out string reason)
- {
- reason = string.Empty;
- if (robot.RobotState != RobotStateEnum.Idle)
- {
- reason = string.Format("robot is not idle.");
- return false;
- }
- if (!CheckRobotReady())
- {
- reason = string.Format("robot isn't ready.");
- return false;
- }
- return true;
- }
- ///等待 Loadport
- public void WaitLoadportMotion(int id, LoadPortBaseDevice device, string name, int time, Action<string> notify, Action<string> error)
- {
- Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
- {
- notify(name);
- string msg = string.Empty;
- //device.QueryState(out msg); //查询状
- _timerQuery.Start(_queryPeriod); //开始查询
- return true;
- }, () =>
- {
-
- if (device.CurrentState == LoadPortStateEnum.Error)
- {
- return null;
- }
- if (device.IsReady())
- {
- _timerQuery.Stop();
- return true;
- }
- return false;
- }, time * 1000);
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL)
- {
- throw (new RoutineFaildException());
- }
- else if (ret.Item2 == Result.TIMEOUT) //timeout
- {
- error(String.Format("{0} timeout, than {1} seconds", name, time));
- throw (new RoutineFaildException());
- }
- else
- throw (new RoutineBreakException());
- }
- }
- protected void LoadportAllReset(int id, int time)
- {
- Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
- {
- Notify(String.Format("clear error for all loadports"));
- string reason = string.Empty;
- LPs.ForEach(lp => lp.ClearError(out reason));
- return true;
- }, () =>
- {
- if (LPs.Any(lp => lp.IsBusy))
- {
- return false;
- }
- return true;
- }, time * 1000);
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL)
- {
- throw (new RoutineFaildException());
- }
- else if (ret.Item2 == Result.TIMEOUT) //timeout
- {
- Stop(String.Format("LoadportAllReset timeout, than {0} seconds", time));
- throw (new RoutineFaildException());
- }
- else
- throw (new RoutineBreakException());
- }
- }
- protected void LoadportAllInit(int id, int time)
- {
- Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
- {
- Notify(String.Format("All loadports Homing"));
- string reason = string.Empty;
- LPs.ForEach(lp =>lp.Home(out reason));
- _timerQuery.Start(_queryPeriod); //开始查询
- return true;
- }, () =>
- {
-
- if (LPs.Any(lp => lp.CurrentState == LoadPortStateEnum.Error))
- {
- return null;
- }
- if (LPs.Any(lp => !lp.IsHomed)) //!lp.IsReady() &&
- {
- return false;
- }
- LPs.ForEach(m=>LOG.Write($"{m.Name}:{m.IsHomed }"));
- return true;
- }, time * 1000);
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL)
- {
- throw (new RoutineFaildException());
- }
- else if (ret.Item2 == Result.TIMEOUT) //timeout
- {
- Stop(String.Format("LoadportAllInit timeout, than {0} seconds", time));
- throw (new RoutineFaildException());
- }
- else
- throw (new RoutineBreakException());
- }
- }
- protected void PostMessage(int id, string v)
- {
- Tuple<bool, Result> ret = Execute(id, () =>
- {
- EV.PostMessage(ModuleName.System.ToString(), EventEnum.GeneralInfo, v);
-
- return true;
- });
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL)
- {
- throw (new RoutineFaildException());
- }
- }
-
- }
- public void TimeDelay(int id, int timeMs)
- {
- Tuple<bool, Result> ret = Delay(id, () =>
- {
- Notify($"Delay {timeMs} Milliseconds");
- return true;
- }, timeMs);
- if (ret.Item1)
- {
- if (ret.Item2 == Result.RUN)
- {
- throw (new RoutineBreakException());
- }
- }
- }
- /// <summary>
- /// Fliper Reset
- /// </summary>
- /// <param name="id"></param>
- /// <param name="device"></param>
- /// <param name="name"></param>
- /// <param name="time"></param>
- /// <param name="notify"></param>
- /// <param name="error"></param>
- public void FlipperReset(int id, FlipperBase device, string name, int time, Action<string> notify, Action<string> error)
- {
- Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
- {
- notify(String.Format("{0} Clear Error", device.Name));
- string reason = string.Empty;
- device.Reset();
- return true;
- }, () =>
- {
- if (device.IsBusy || device.State != FlipperState.Idle)
- {
- //忙状态
- //_flipper.ShowAction();
- LOG.Info($"{device.Name} is busy state");
- return false;
- }
- else
- {
- //空闲状态
- LOG.Info($"{device.Name} enters idle state");
- 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("{0} timeout, than {1} seconds", name, time));
- throw (new RoutineFaildException());
- }
- else
- throw (new RoutineBreakException());
- }
- }
- /// <summary>
- /// Flipper Clamp Open
- /// </summary>
- /// <param name="id"></param>
- /// <param name="device"></param>
- /// <param name="name"></param>
- /// <param name="time"></param>
- /// <param name="notify"></param>
- /// <param name="error"></param>
- public void FlipperClampOpen(int id, FlipperBase device, string name, int time, Action<string> notify, Action<string> error)
- {
- Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
- {
- notify(String.Format("{0} clamp open", device.Name));
- //有错误 驱动层已打出原因log
- if (device.Clamp(false))
- {
- LOG.Info($"{device.Name} starts unclamp");
- return true;
- }
- else
- {
- LOG.Error($"{device.Name} unclamps failed");
- return false;
- }
- }, () =>
- {
- if (device.IsBusy && device.IsClampOpen)
- {
- //忙状态
- //_flipper.ShowAction();
- LOG.Info($"{device.Name} is busy state");
- return false;
- }
- else
- {
- //空闲状态
- LOG.Info($"{device.Name} enter idle state");
- 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("{0} timeout, than {1} seconds", name, time));
- throw (new RoutineFaildException());
- }
- else
- throw (new RoutineBreakException());
- }
- }
- /// <summary>
- /// Flipper Clamp Close
- /// </summary>
- /// <param name="id"></param>
- /// <param name="device"></param>
- /// <param name="name"></param>
- /// <param name="time"></param>
- /// <param name="notify"></param>
- /// <param name="error"></param>
- public void FlipperClampClose(int id, FlipperBase device, string name, int time, Action<string> notify, Action<string> error)
- {
- Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
- {
- notify(String.Format("{0} Clamp Close", device.Name));
- //有错误 驱动层已打出原因log
- if (device.Clamp(true))
- {
- LOG.Info($"{device.Name} starts clamp");
- return true;
- }
- else
- {
- LOG.Error($"{device.Name} clamps failed");
- return false;
- }
- }, () =>
- {
- if (device.IsBusy && device.IsClampClose)
- {
- //忙状态
- //_flipper.ShowAction();
- LOG.Info($"{device.Name} is busy state");
- return false;
- }
- else
- {
- //空闲状态
- LOG.Info($"{device.Name} enter idle state");
- 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("{0} timeout, than {1} seconds", name, time));
- throw (new RoutineFaildException());
- }
- else
- throw (new RoutineBreakException());
- }
- }
- /// <summary>
- /// Flipper Turn to Home
- /// </summary>
- /// <param name="id"></param>
- /// <param name="device"></param>
- /// <param name="name"></param>
- /// <param name="time"></param>
- /// <param name="notify"></param>
- /// <param name="error"></param>
- public void FlipperTurnToHome(int id, FlipperBase device, string name, int time, Action<string> notify, Action<string> error)
- {
- Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
- {
- notify(String.Format("{0} Turn to Home", device.Name));
- //有错误 驱动层已打出log
- if (device.Home())
- {
- LOG.Info($"{device.Name} start turn to home");
- return true;
- }
- else
- {
- LOG.Error($"{device.Name} turn to home failed");
- return false;
- }
- }, () =>
- {
- if (device.IsBusy || device.State != FlipperState.Idle)
- {
- //忙状态
- //_flipper.ShowAction();
- LOG.Info($"{device.Name} is busy state");
- return false;
- }
- else
- {
- //空闲状态
- LOG.Info($"{device.Name} enter busy state");
- 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("{0} timeout, than {1} seconds", name, time));
- throw (new RoutineFaildException());
- }
- else
- throw (new RoutineBreakException());
- }
- }
- public void FlipperPrepare(int id, FlipperBase device, string name, int time, Action<string> notify, Action<string> error)
- {
- Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
- {
- if(device == null)
- {
- LOG.Error($"{device.Name} device is null, prepare transfer failed");
- return false;
- }
- notify(String.Format("{0} Prepare Transfer", device.Name));
- if (Singleton<RouteManager>.Instance.FLPEntity.CheckToPostMsg(FlipperEntity.FlipperMSG.PrepareTransfer))
- {
- LOG.Info($"{device.Name} start prepare transfer");
- return true;
- }
- else
- {
- LOG.Error($"{device.Name} prepare transfer failed");
- return false;
- }
-
- }, () =>
- {
- if (Singleton<RouteManager>.Instance.FLPEntity.IsTransfer)
- {
- LOG.Info($"{device.Name} end prepare transfer");
- return true;
- }
- return false;
- }, time * 1000);
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL)
- {
- throw (new RoutineFaildException());
- }
- else if (ret.Item2 == Result.TIMEOUT) //timeout
- {
- error(String.Format("{0} timeout, than {1} seconds", name, time));
- throw (new RoutineFaildException());
- }
- else
- throw (new RoutineBreakException());
- }
- }
- public void FlipperComplete(int id, FlipperBase device, string name, int time, Action<string> notify, Action<string> error)
- {
- Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
- {
- if (device == null)
- {
- LOG.Error($"{device.Name} device is null, prepare transfer failed");
- return false;
- }
- notify(String.Format("{0} Complete Transfer", device.Name));
- if (Singleton<RouteManager>.Instance.FLPEntity.CheckToPostMsg(FlipperEntity.FlipperMSG.EndTransfer))
- {
- LOG.Info($"{device.Name} start complete transfer");
- return true;
- }
- else
- {
- LOG.Error($"{device.Name} complete transfer failed");
- return false;
- }
- }, () =>
- {
- if (Singleton<RouteManager>.Instance.FLPEntity.IsIdle)
- {
- LOG.Info($"{device.Name} end complete transfer");
- return true;
- }
- return false;
- }, time * 1000);
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL)
- {
- throw (new RoutineFaildException());
- }
- else if (ret.Item2 == Result.TIMEOUT) //timeout
- {
- error(String.Format("{0} timeout, than {1} seconds", name, time));
- throw (new RoutineFaildException());
- }
- else
- throw (new RoutineBreakException());
- }
- }
- public void FlipperHome(int id, FlipperBase device, string name, int time, Action<string> notify, Action<string> error)
- {
- Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
- {
- if (device == null)
- {
- LOG.Error($"{device.Name} device is null, fliper home failed");
- return false;
- }
- notify(String.Format("{0} Home", device.Name));
- if (Singleton<RouteManager>.Instance.FLPEntity.CheckToPostMsg(FlipperMSG.Home))
- {
- LOG.Info($"{device.Name} start home");
- return true;
- }
- else
- {
- LOG.Error($"{device.Name} home failed");
- return false;
- }
- }, () =>
- {
- if (Singleton<RouteManager>.Instance.FLPEntity.IsIdle)
- {
- LOG.Info($"{device.Name} end home");
- return true;
- }
- return false;
- }, time * 1000);
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL)
- {
- throw (new RoutineFaildException());
- }
- else if (ret.Item2 == Result.TIMEOUT) //timeout
- {
- error(String.Format("{0} timeout, than {1} seconds", name, time));
- throw (new RoutineFaildException());
- }
- else
- throw (new RoutineBreakException());
- }
- }
- }
- }
|