12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697 |
- using System;
- using System.Collections.Generic;
- using System.IO.Ports;
- using System.Linq;
- using System.Text;
- using Aitex.Core.Common.DeviceData;
- using Aitex.Core.RT.Device;
- using Aitex.Core.RT.Device.Unit;
- using Aitex.Core.RT.Event;
- using Aitex.Core.RT.Log;
- using Aitex.Core.RT.OperationCenter;
- using Aitex.Core.RT.SCCore;
- using Aitex.Core.Util;
- using MECF.Framework.Common.Communications;
- using MECF.Framework.Common.Device.Bases;
- using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Common;
- using Newtonsoft.Json;
- using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robots.RobotBase;
- using MECF.Framework.Common.Equipment;
- using MECF.Framework.Common.SubstrateTrackings;
- using System.Threading;
- using Aitex.Core.Common;
- using Aitex.Core.RT.DataCenter;
- using System.Text.RegularExpressions;
- using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.LoadPorts;
- using MECF.Framework.Common.CommonData;
- using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.LoadPorts.LoadPortBase;
- using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.WalkingAixs;
- using Aitex.Core.RT.Routine;
- using static MECF.Framework.RT.EquipmentLibrary.HardwareUnits.WalkingAixs.WalkingAxisBaseDevice;
- namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robots.JEL
- {
- public class JelRobotWithX : JelRobot, IConnection
- {
- protected WalkingAxisBaseDevice m_WalkingAxis { get; set; }
- protected bool m_IsNeedMoveWalkingAxis { get; set; }
- public JelRobotWithX(string module, string name, string scRoot,WalkingAxisBaseDevice xaxis=null) :
- base(module, name, scRoot)
- {
- m_WalkingAxis = xaxis;
- }
-
- public override bool OnTimer()
- {
- return base.OnTimer();
- }
- protected override bool fReset(object[] param)
- {
- m_WalkingAxis.Reset(null);
- return base.fReset(param);
- }
- protected override bool fMonitorReset(object[] param)
- {
- IsBusy = false;
- if (DateTime.Now - _dtActionStart > TimeSpan.FromSeconds(RobotCommandTimeout))
- {
- HandlerError("ResetTimeout");
- return true;
- }
- if (!m_WalkingAxis.IsReady()) return false;
- return base.fMonitorReset(param);
- }
- protected override bool fStartGoTo(object[] param)
- {
- RobotArmEnum arm = (RobotArmEnum)param[0];
- ModuleName module = (ModuleName)Enum.Parse(typeof(ModuleName), param[1].ToString());
- BladeTarget = module;
- Blade1Target = module;
- Blade2Target = module;
- int slot = (int)param[2] + 1;
- RobotPostionEnum postype = (RobotPostionEnum)param[3];
- if (!m_WalkingAxis.IsReady())
- return false;
- m_WalkingAxis.MoveTo(module);
- int compaundcmdNO = SC.GetValue<int>($"Robot.{Name}.{arm}{postype}CmdNO");
- var wz = WaferManager.Instance.GetWaferSize(RobotModuleName, (int)arm);
- if (ModuleHelper.IsLoadPort(module))
- {
- var lp = DEVICE.GetDevice<LoadPortBaseDevice>(module.ToString());
- if (lp != null) lp.NoteTransferStart();
- }
- int bankno;
- int cassetteNO;
- if(!GetBankAndCassetteNumber(module, wz, out bankno, out cassetteNO))
- return false;
- lock (_locker)
- {
- _lstMonitorHandler.AddLast(new JelRobotSetHandler(this, "BC", bankno.ToString("X")));
- _lstMonitorHandler.AddLast(new JelRobotSetHandler(this, "WCP", cassetteNO.ToString()));
- _lstMonitorHandler.AddLast(new JelRobotSetHandler(this, "WCD", slot.ToString()));
- _lstMonitorHandler.AddLast(new JelRobotReadHandler(this, "BC"));
- _lstMonitorHandler.AddLast(new JelRobotReadHandler(this, "WCP"));
- _lstMonitorHandler.AddLast(new JelRobotCompaundCommandHandler(this, compaundcmdNO.ToString()));
- _lstMonitorHandler.AddLast(new JelRobotReadHandler(this, "G"));
- }
- _dtActionStart = DateTime.Now;
- return true;
- }
- protected override bool fMonitorGoTo(object[] param)
- {
- IsBusy = false;
- RobotArmEnum arm = (RobotArmEnum)CurrentParamter[0];
- ModuleName tempmodule = (ModuleName)Enum.Parse(typeof(ModuleName), CurrentParamter[1].ToString());
- if (DateTime.Now - _dtActionStart > TimeSpan.FromSeconds(RobotCommandTimeout))
- {
- HandlerError($"Goto{BladeTarget}Timeout");
- return true;
- }
- if(m_WalkingAxis.DeviceState == WalkingAxisState.ERROR)
- {
- HandlerError($"WalkingAxisError");
- return true;
- }
- if (_lstMonitorHandler.Count == 0 && !_connection.IsBusy)
- {
- if (CurrentCompoundCommandStatus == JelCommandStatus.NormalEnd)
- {
- BladeTarget = ModuleName.System;
- Blade1Target = ModuleName.System;
- Blade2Target = ModuleName.System;
- CmdTarget = ModuleName.System;
- MoveInfo = new RobotMoveInfo()
- {
- Action = RobotAction.Picking,
- ArmTarget = CmdRobotArm == RobotArmEnum.Lower ? RobotArm.ArmA : RobotArm.ArmB,
- BladeTarget = BuildBladeTarget(),
- };
- if (ModuleHelper.IsLoadPort(tempmodule))
- {
- var lp = DEVICE.GetDevice<LoadPortBaseDevice>(tempmodule.ToString());
- if (lp != null) lp.NoteTransferStop();
- }
- return true;
- }
- if (CurrentCompoundCommandStatus == JelCommandStatus.InError)
- {
- _lstMonitorHandler.AddLast(new JelRobotReadHandler(this, "GER"));
- HandlerError("GotoFailed");
- }
- }
- return false;
- }
- protected override bool fStartInit(object[] param)
- {
- _dtActionStart = DateTime.Now;
- int compaundcmdNO = SC.GetValue<int>($"Robot.{Name}.InitCmdNO");
- int Robotspeed = SC.GetValue<int>($"Robot.{Name}.RobotSpeed");
- if (Robotspeed < 0)
- Robotspeed = 0;
- if (Robotspeed > 9)
- Robotspeed = 9;
- lock (_locker)
- {
- _lstMonitorHandler.AddLast(new JelRobotCompaundCommandHandler(this, compaundcmdNO.ToString()));
- _lstMonitorHandler.AddLast(new JelRobotMoveHandler(this, ""));
-
- _lstMonitorHandler.AddLast(new JelRobotSetHandler(this, "CS1"));
- _lstMonitorHandler.AddLast(new JelRobotReadHandler(this, "BC")); // Read bank number
- _lstMonitorHandler.AddLast(new JelRobotReadHandler(this, "WCP")); // Read Cassette Number
- _lstMonitorHandler.AddLast(new JelRobotReadHandler(this, "6M", "1"));
- _lstMonitorHandler.AddLast(new JelRobotReadHandler(this, "6M", "2"));
- _lstMonitorHandler.AddLast(new JelRobotReadHandler(this, "6M", "3"));
- _lstMonitorHandler.AddLast(new JelRobotReadHandler(this, "6M", "4"));
- _lstMonitorHandler.AddLast(new JelRobotSetHandler(this, "SP", Robotspeed.ToString()));
- _lstMonitorHandler.AddLast(new JelRobotReadHandler(this, "G"));
- }
- ResetRoutine();
- return true;
- }
- protected override bool fMonitorInit(object[] param)
- {
- IsBusy = false;
- if (DateTime.Now - _dtActionStart > TimeSpan.FromSeconds(RobotCommandTimeout))
- {
- HandlerError("InitTimeout");
- return true;
- }
- WaitRobotCompleteMove((int)JelStep.Step1, "Wait robot home complete", RobotCommandTimeout);
- if (ExecuteResult.Item1)
- {
- return false;
- }
- HomeWalkingAxis((int)JelStep.Step2, "Home walking axis", RobotCommandTimeout);
- if (ExecuteResult.Item1)
- {
- return false;
- }
- Blade1Target = ModuleName.System;
- Blade2Target = ModuleName.System;
- CmdTarget = ModuleName.System;
- MoveInfo = new RobotMoveInfo()
- {
- Action = RobotAction.Moving,
- ArmTarget = CmdRobotArm == RobotArmEnum.Lower ? RobotArm.ArmA : RobotArm.ArmB,
- BladeTarget = BuildBladeTarget(),
- };
-
- return true;
- }
-
-
- public override bool IsReady()
- {
- return RobotState == RobotStateEnum.Idle && !IsBusy;
- }
- protected override bool fClear(object[] param)
- {
- return true;
- }
- protected override bool fStop(object[] param)
- {
- m_WalkingAxis.Stop(null);
- _lstMonitorHandler.Clear();
- _connection.ForceClear();
- _connection.Execute(new JelRobotSetHandler(this, "S"));
- return ReadStatus();
-
- }
-
- protected override bool fStartMapWafer(object[] param)
- {
- ResetRoutine();
- ModuleName tempmodule = (ModuleName)Enum.Parse(typeof(ModuleName), param[0].ToString());
- _dtActionStart = DateTime.Now;
- return true;
- }
- protected override bool fMonitorMap(object[] param)
- {
- IsBusy = false;
- if (DateTime.Now - _dtActionStart > TimeSpan.FromSeconds(RobotCommandTimeout))
- {
- HandlerError("MapTimeout");
- return true;
- }
- ModuleName tempmodule = (ModuleName)Enum.Parse(typeof(ModuleName), CurrentParamter[0].ToString());
- WalkingAxisMoveToPos((int)JelStep.Step1, "Wait Axis move complete", tempmodule, RobotCommandTimeout);
- if (ExecuteResult.Item1)
- {
- return false;
- }
- RobotExecuteMap((int)JelStep.Step2);
- if (ExecuteResult.Item1)
- {
- return false;
- }
- WaitRobotCompleteMove((int)JelStep.Step3, "Wait mappingg complete", RobotCommandTimeout);
- if (ExecuteResult.Item1)
- {
- return false;
- }
- EV.PostInfoLog("Robot", $"{RobotModuleName} Map {tempmodule} complete. ");
- return true;
- }
- protected override bool fStartPickWafer(object[] param)
- {
- ModuleName tempmodule = (ModuleName)Enum.Parse(typeof(ModuleName), CurrentParamter[1].ToString());
- m_IsNeedMoveWalkingAxis = m_WalkingAxis.GetCurrentStation() != m_WalkingAxis.GetStationIndex(tempmodule);
- ResetRoutine();
- _dtActionStart = DateTime.Now;
- return true;
- }
- protected override bool fMonitorPick(object[] param)
- {
- IsBusy = false;
- if (DateTime.Now - _dtActionStart > TimeSpan.FromSeconds(RobotCommandTimeout))
- {
- HandlerError("PickTimeout");
- return true;
- }
- ModuleName tempmodule = (ModuleName)Enum.Parse(typeof(ModuleName), CurrentParamter[1].ToString());
- int slotindex = int.Parse(CurrentParamter[2].ToString());
- if(m_IsNeedMoveWalkingAxis)
- {
- RobotExecutePickReady((int)JelStep.Step1);
- if (ExecuteResult.Item1)
- {
- return false;
- }
- WalkingAxisMoveToPos((int)JelStep.Step2, "Wait Axis move complete", tempmodule, RobotCommandTimeout);
- if (ExecuteResult.Item1)
- {
- return false;
- }
- WaitRobotCompleteMove((int)JelStep.Step3, "Wait picking complete", RobotCommandTimeout);
- if (ExecuteResult.Item1)
- {
- return false;
- }
- }
- RobotExecutePick((int)JelStep.Step4);
- if (ExecuteResult.Item1)
- {
- return false;
- }
- WaitRobotCompleteMove((int)JelStep.Step5, "Wait picking complete", RobotCommandTimeout);
- if (ExecuteResult.Item1)
- {
- return false;
- }
- RobotCompletePick((int)JelStep.Step7);
- EV.PostInfoLog("Robot", $"{RobotModuleName} pick wafer from {tempmodule}:{slotindex+1} complete. ");
- return true;
- }
- protected override bool fStartSwapWafer(object[] param)
- {
- ResetRoutine();
- ModuleName tempmodule = (ModuleName)Enum.Parse(typeof(ModuleName), CurrentParamter[1].ToString());
- m_IsNeedMoveWalkingAxis = m_WalkingAxis.GetCurrentStation() != m_WalkingAxis.GetStationIndex(tempmodule);
- _dtActionStart = DateTime.Now;
- return true;
- }
- protected override bool fMonitorSwap(object[] param)
- {
- IsBusy = false;
- if (DateTime.Now - _dtActionStart > TimeSpan.FromSeconds(RobotCommandTimeout))
- {
- HandlerError("SwapTimeout");
- return true;
- }
- ModuleName tempmodule = (ModuleName)Enum.Parse(typeof(ModuleName), CurrentParamter[1].ToString());
- int slotindex = int.Parse(CurrentParamter[2].ToString());
- if (m_IsNeedMoveWalkingAxis)
- {
- RobotExecutePickReady((int)JelStep.Step1);
- if (ExecuteResult.Item1)
- {
- return false;
- }
- WalkingAxisMoveToPos((int)JelStep.Step2, "Wait Axis move complete", tempmodule, RobotCommandTimeout);
- if (ExecuteResult.Item1)
- {
- return false;
- }
- WaitRobotCompleteMove((int)JelStep.Step3, "Wait picking complete", RobotCommandTimeout);
- if (ExecuteResult.Item1)
- {
- return false;
- }
- }
- RobotExecuteSwap((int)JelStep.Step4);
- if (ExecuteResult.Item1)
- {
- return false;
- }
- WaitRobotCompleteMove((int)JelStep.Step5, "Wait swapping complete", RobotCommandTimeout);
- if (ExecuteResult.Item1)
- {
- return false;
- }
- RobotCompleteSwap((int)JelStep.Step6);
- EV.PostInfoLog("Robot", $"{RobotModuleName} Swap wafer from {tempmodule}:{slotindex + 1} complete. ");
- return true;
- }
- protected override bool fStartPlaceWafer(object[] param)
- {
- ResetRoutine();
- ModuleName tempmodule = (ModuleName)Enum.Parse(typeof(ModuleName), CurrentParamter[1].ToString());
- m_IsNeedMoveWalkingAxis = m_WalkingAxis.GetCurrentStation() != m_WalkingAxis.GetStationIndex(tempmodule);
- _dtActionStart = DateTime.Now;
- return true;
- }
-
- protected override bool fMonitorPlace(object[] param)
- {
- IsBusy = false;
- if (DateTime.Now - _dtActionStart > TimeSpan.FromSeconds(RobotCommandTimeout))
- {
- HandlerError("PlaceTimeout");
- return true;
- }
- ModuleName tempmodule = (ModuleName)Enum.Parse(typeof(ModuleName), CurrentParamter[1].ToString());
- int slotindex = int.Parse(CurrentParamter[2].ToString());
- if (m_IsNeedMoveWalkingAxis)
- {
- RobotExecutePickReady((int)JelStep.Step1);
- if (ExecuteResult.Item1)
- {
- return false;
- }
- WalkingAxisMoveToPos((int)JelStep.Step2, "Wait Axis move complete", tempmodule, RobotCommandTimeout);
- if (ExecuteResult.Item1)
- {
- return false;
- }
- WaitRobotCompleteMove((int)JelStep.Step3, "Wait picking complete", RobotCommandTimeout);
- if (ExecuteResult.Item1)
- {
- return false;
- }
- }
- RobotExecutePlace((int)JelStep.Step4);
- if (ExecuteResult.Item1)
- {
- return false;
- }
- WaitRobotCompleteMove((int)JelStep.Step5, "Wait placing complete", RobotCommandTimeout);
- if (ExecuteResult.Item1)
- {
- return false;
- }
- RobotCompletePlace((int)JelStep.Step6);
- if (ExecuteResult.Item1)
- {
- return false;
- }
- EV.PostInfoLog("Robot", $"{RobotModuleName} place wafer to {tempmodule}:{slotindex + 1} complete. ");
- return true;
- }
-
- public override RobotArmWaferStateEnum GetWaferState(RobotArmEnum arm)
- {
- if (arm == RobotArmEnum.Lower)
- return IsLeftArmPressureSensorON? RobotArmWaferStateEnum.Present: RobotArmWaferStateEnum.Absent;
- if (arm == RobotArmEnum.Upper)
- return IsRightArmPressureSensorON ? RobotArmWaferStateEnum.Present : RobotArmWaferStateEnum.Absent; ;
- return RobotArmWaferStateEnum.ArmInvalid;
- }
- protected void RobotExecutePickReady(int id)
- {
- Tuple<bool, Result> ret = Execute(id, () =>
- {
- RobotArmEnum arm = (RobotArmEnum)CurrentParamter[0];
- ModuleName tempmodule = (ModuleName)Enum.Parse(typeof(ModuleName), CurrentParamter[1].ToString());
- int slotindex = int.Parse(CurrentParamter[2].ToString());
- var wz = WaferManager.Instance.GetWaferSize(tempmodule, slotindex);
- int bankno;
- int cassetteNO;
- if (!GetBankAndCassetteNumber(tempmodule, wz, out bankno, out cassetteNO))
- return false;
- int compaundcmdNO = SC.GetValue<int>($"Robot.{Name}.{arm}PickReadyCmdNO");
- lock (_locker)
- {
- _lstMonitorHandler.AddLast(new JelRobotSetHandler(this, "BC", bankno.ToString("X")));
- _lstMonitorHandler.AddLast(new JelRobotSetHandler(this, "WCP", cassetteNO.ToString()));
- _lstMonitorHandler.AddLast(new JelRobotSetHandler(this, "WCD", (slotindex + 1).ToString()));
- _lstMonitorHandler.AddLast(new JelRobotCompaundCommandHandler(this, compaundcmdNO.ToString()));
- _lstMonitorHandler.AddLast(new JelRobotReadHandler(this, "G"));
- }
- Blade1Target = tempmodule;
- Blade2Target = tempmodule;
- CmdTarget = tempmodule;
- MoveInfo = new RobotMoveInfo()
- {
- Action = RobotAction.Picking,
- ArmTarget = CmdRobotArm == RobotArmEnum.Lower ? RobotArm.ArmA : RobotArm.ArmB,
- BladeTarget = BuildBladeTarget(),
- };
- return true;
- });
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL)
- {
- OnError($"{RobotModuleName}GoPickReadyError.");
- }
- }
- }
- protected void RobotExecutePlaceReady(int id)
- {
- Tuple<bool, Result> ret = Execute(id, () =>
- {
- RobotArmEnum arm = (RobotArmEnum)CurrentParamter[0];
- ModuleName tempmodule = (ModuleName)Enum.Parse(typeof(ModuleName), CurrentParamter[1].ToString());
- int slotindex = int.Parse(CurrentParamter[2].ToString());
- var wz = WaferManager.Instance.GetWaferSize(RobotModuleName, arm == RobotArmEnum.Both ? 0 : (int)arm);
- int bankno;
- int cassetteNO;
- if(!GetBankAndCassetteNumber(tempmodule,wz, out bankno, out cassetteNO))
- return false;
- int compaundcmdNO = SC.GetValue<int>($"Robot.{Name}.{arm}PlaceReadyCmdNO");
- lock (_locker)
- {
- _lstMonitorHandler.AddLast(new JelRobotSetHandler(this, "BC", bankno.ToString("X")));
- _lstMonitorHandler.AddLast(new JelRobotSetHandler(this, "WCP", cassetteNO.ToString()));
- _lstMonitorHandler.AddLast(new JelRobotSetHandler(this, "WCD", (slotindex + 1).ToString()));
- _lstMonitorHandler.AddLast(new JelRobotCompaundCommandHandler(this, compaundcmdNO.ToString()));
- _lstMonitorHandler.AddLast(new JelRobotReadHandler(this, "G"));
- }
- Blade1Target = tempmodule;
- Blade2Target = tempmodule;
- CmdTarget = tempmodule;
- MoveInfo = new RobotMoveInfo()
- {
- Action = RobotAction.Moving,
- ArmTarget = CmdRobotArm == RobotArmEnum.Lower ? RobotArm.ArmA : RobotArm.ArmB,
- BladeTarget = BuildBladeTarget(),
- };
- return true;
- });
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL)
- {
- OnError($"{RobotModuleName}GoPlaceReadyError.");
- }
- }
- }
- protected void RobotExecuteMap(int id)
- {
- Tuple<bool, Result> ret = Execute(id, () =>
- {
-
- ModuleName tempmodule = (ModuleName)Enum.Parse(typeof(ModuleName), CurrentParamter[0].ToString());
- EV.PostInfoLog($"{RobotModuleName}", $"Start mapping wafer on {tempmodule}");
-
- WaferSize wz = WaferManager.Instance.GetWaferSize(tempmodule, 0);
- int bankno;
- int cassetteNO;
- if (!GetBankAndCassetteNumber(tempmodule, wz, out bankno, out cassetteNO))
- return false;
- int compaundcmdNO = SC.GetValue<int>($"Robot.{Name}.MapCmdNO");
- lock (_locker)
- {
- _lstMonitorHandler.AddLast(new JelRobotSetHandler(this, "BC", bankno.ToString("X")));
- _lstMonitorHandler.AddLast(new JelRobotSetHandler(this, "WCP", cassetteNO.ToString()));
- _lstMonitorHandler.AddLast(new JelRobotCompaundCommandHandler(this, compaundcmdNO.ToString()));
- _lstMonitorHandler.AddLast(new JelRobotReadHandler(this, "G"));
- _lstMonitorHandler.AddLast(new JelRobotReadHandler(this, ""));
- _lstMonitorHandler.AddLast(new JelRobotReadHandler(this, "WFW"));
- _lstMonitorHandler.AddLast(new JelRobotReadHandler(this, "WFK"));
- }
- Blade1Target = tempmodule;
- Blade2Target = tempmodule;
- CmdTarget = tempmodule;
- MoveInfo = new RobotMoveInfo()
- {
- Action = RobotAction.Picking,
- ArmTarget = CmdRobotArm == RobotArmEnum.Lower ? RobotArm.ArmA : RobotArm.ArmB,
- BladeTarget = BuildBladeTarget(),
- };
- return true;
- });
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL)
- {
- OnError($"{RobotModuleName}MappingError.");
- }
- }
- }
- protected void RobotExecutePick(int id)
- {
- Tuple<bool, Result> ret = Execute(id, () =>
- {
- RobotArmEnum arm = (RobotArmEnum)CurrentParamter[0];
- ModuleName tempmodule = (ModuleName)Enum.Parse(typeof(ModuleName), CurrentParamter[1].ToString());
- int slotindex = int.Parse(CurrentParamter[2].ToString());
- var wz = WaferManager.Instance.GetWaferSize(tempmodule, slotindex);
-
- int bankno;
- int cassetteNO;
- if (!GetBankAndCassetteNumber(tempmodule, wz, out bankno, out cassetteNO))
- return false;
- int compaundcmdNO = SC.GetValue<int>($"Robot.{Name}.{arm}PickCmdNO");
- lock (_locker)
- {
- _lstMonitorHandler.AddLast(new JelRobotSetHandler(this, "BC", bankno.ToString("X")));
- _lstMonitorHandler.AddLast(new JelRobotSetHandler(this, "WCP", cassetteNO.ToString()));
- _lstMonitorHandler.AddLast(new JelRobotSetHandler(this, "WCD", (slotindex + 1).ToString()));
- _lstMonitorHandler.AddLast(new JelRobotReadHandler(this, "BC"));
- _lstMonitorHandler.AddLast(new JelRobotReadHandler(this, "WCP"));
- _lstMonitorHandler.AddLast(new JelRobotCompaundCommandHandler(this, compaundcmdNO.ToString()));
- _lstMonitorHandler.AddLast(new JelRobotReadHandler(this, "G"));
- }
- Blade1Target = tempmodule;
- Blade2Target = tempmodule;
- CmdTarget = tempmodule;
- MoveInfo = new RobotMoveInfo()
- {
- Action = RobotAction.Picking,
- ArmTarget = CmdRobotArm == RobotArmEnum.Lower ? RobotArm.ArmA : RobotArm.ArmB,
- BladeTarget = BuildBladeTarget(),
- };
- return true;
- });
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL)
- {
- OnError($"{RobotModuleName}PickingError.");
- }
- }
- }
- protected void RobotCompletePick(int id)
- {
- Tuple<bool, Result> ret = Execute(id, () =>
- {
- RobotArmEnum arm = (RobotArmEnum)CurrentParamter[0];
- ModuleName sourcemodule;
- if (!Enum.TryParse(CurrentParamter[1].ToString(), out sourcemodule)) return false;
- int SourceslotIndex;
- if (!int.TryParse(CurrentParamter[2].ToString(), out SourceslotIndex)) return false;
- if (arm == RobotArmEnum.Lower)
- WaferManager.Instance.WaferMoved(sourcemodule, SourceslotIndex, RobotModuleName, 0);
- if (arm == RobotArmEnum.Upper)
- WaferManager.Instance.WaferMoved(sourcemodule, SourceslotIndex, RobotModuleName, 1);
- if (arm == RobotArmEnum.Both)
- {
- WaferManager.Instance.WaferMoved(sourcemodule, SourceslotIndex, RobotModuleName, 0);
- WaferManager.Instance.WaferMoved(sourcemodule, SourceslotIndex, RobotModuleName, 1);
- }
- Blade1Target = ModuleName.System;
- Blade2Target = ModuleName.System;
- CmdTarget = ModuleName.System;
- MoveInfo = new RobotMoveInfo()
- {
- Action = RobotAction.Moving,
- ArmTarget = CmdRobotArm == RobotArmEnum.Lower ? RobotArm.ArmA : RobotArm.ArmB,
- BladeTarget = BuildBladeTarget(),
- };
- return true;
- });
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL)
- {
- OnError($"{RobotModuleName}CompletePickingError.");
- }
- }
- }
- protected void RobotExecutePlace(int id)
- {
- Tuple<bool, Result> ret = Execute(id, () =>
- {
- RobotArmEnum arm = (RobotArmEnum)CurrentParamter[0];
- ModuleName tempmodule = (ModuleName)Enum.Parse(typeof(ModuleName), CurrentParamter[1].ToString());
- int slotindex = int.Parse(CurrentParamter[2].ToString());
- var wz = WaferManager.Instance.GetWaferSize(RobotModuleName, arm == RobotArmEnum.Both ? 0 : (int)arm);
- int bankno;
- int cassetteNO;
- if (!GetBankAndCassetteNumber(tempmodule, wz, out bankno, out cassetteNO))
- return false;
- int compaundcmdNO = SC.GetValue<int>($"Robot.{Name}.{arm}PlaceCmdNO");
- lock (_locker)
- {
- _lstMonitorHandler.AddLast(new JelRobotSetHandler(this, "BC", bankno.ToString("X")));
- _lstMonitorHandler.AddLast(new JelRobotSetHandler(this, "WCP", cassetteNO.ToString()));
- _lstMonitorHandler.AddLast(new JelRobotSetHandler(this, "WCD", (slotindex + 1).ToString()));
- _lstMonitorHandler.AddLast(new JelRobotCompaundCommandHandler(this, compaundcmdNO.ToString()));
- _lstMonitorHandler.AddLast(new JelRobotReadHandler(this, "G"));
- }
- Blade1Target = tempmodule;
- Blade2Target = tempmodule;
- CmdTarget = tempmodule;
- MoveInfo = new RobotMoveInfo()
- {
- Action = RobotAction.Moving,
- ArmTarget = CmdRobotArm == RobotArmEnum.Lower ? RobotArm.ArmA : RobotArm.ArmB,
- BladeTarget = BuildBladeTarget(),
- };
- return true;
- });
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL)
- {
- OnError($"{RobotModuleName}PlacingError.");
- }
- }
- }
- protected void RobotCompletePlace(int id)
- {
- Tuple<bool, Result> ret = Execute(id, () =>
- {
- RobotArmEnum arm = (RobotArmEnum)CurrentParamter[0];
- ModuleName sourcemodule;
- if (!Enum.TryParse(CurrentParamter[1].ToString(), out sourcemodule)) return false;
- int Sourceslotindex;
- if (!int.TryParse(CurrentParamter[2].ToString(), out Sourceslotindex)) return false;
- if (arm == RobotArmEnum.Lower)
- WaferManager.Instance.WaferMoved(RobotModuleName, 0, sourcemodule, Sourceslotindex);
- if (arm == RobotArmEnum.Upper)
- WaferManager.Instance.WaferMoved(RobotModuleName, 1, sourcemodule, Sourceslotindex);
- if (arm == RobotArmEnum.Both)
- {
- WaferManager.Instance.WaferMoved(RobotModuleName, 0, sourcemodule, Sourceslotindex);
- WaferManager.Instance.WaferMoved(RobotModuleName, 1, sourcemodule, Sourceslotindex);
- }
- Blade1Target = ModuleName.System;
- Blade2Target = ModuleName.System;
- CmdTarget = ModuleName.System;
- MoveInfo = new RobotMoveInfo()
- {
- Action = RobotAction.Moving,
- ArmTarget = CmdRobotArm == RobotArmEnum.Lower ? RobotArm.ArmA : RobotArm.ArmB,
- BladeTarget = BuildBladeTarget(),
- };
- return true;
- });
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL)
- {
- OnError($"{RobotModuleName}CompletePickingError.");
- }
- }
- }
- protected void RobotExecuteSwap(int id)
- {
- Tuple<bool, Result> ret = Execute(id, () =>
- {
- RobotArmEnum arm = (RobotArmEnum)CurrentParamter[0];
- ModuleName tempmodule = (ModuleName)Enum.Parse(typeof(ModuleName), CurrentParamter[1].ToString());
- int slotindex = int.Parse(CurrentParamter[2].ToString());
-
- var wz = WaferManager.Instance.GetWaferSize(RobotModuleName, arm == RobotArmEnum.Both ? 0 : (int)arm);
-
- int bankno;
- int cassetteNO;
- if (!GetBankAndCassetteNumber(tempmodule, wz, out bankno, out cassetteNO))
- return false;
- int compaundcmdNO = SC.GetValue<int>($"Robot.{Name}.{arm}PickSwapCmdNO");
- lock (_locker)
- {
- _lstMonitorHandler.AddLast(new JelRobotSetHandler(this, "BC", bankno.ToString("X")));
- _lstMonitorHandler.AddLast(new JelRobotSetHandler(this, "WCP", cassetteNO.ToString()));
- _lstMonitorHandler.AddLast(new JelRobotSetHandler(this, "WCD", (slotindex + 1).ToString()));
- _lstMonitorHandler.AddLast(new JelRobotCompaundCommandHandler(this, compaundcmdNO.ToString()));
- _lstMonitorHandler.AddLast(new JelRobotReadHandler(this, "G"));
- }
- Blade1Target = tempmodule;
- Blade2Target = tempmodule;
- CmdTarget = tempmodule;
- MoveInfo = new RobotMoveInfo()
- {
- Action = RobotAction.Moving,
- ArmTarget = CmdRobotArm == RobotArmEnum.Lower ? RobotArm.ArmA : RobotArm.ArmB,
- BladeTarget = BuildBladeTarget(),
- };
- return true;
- });
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL)
- {
- OnError($"{RobotModuleName}SwappingError.");
- }
- }
- }
- protected void RobotCompleteSwap(int id)
- {
- Tuple<bool, Result> ret = Execute(id, () =>
- {
- RobotArmEnum arm = (RobotArmEnum)CurrentParamter[0];
- ModuleName sourcemodule;
- if (!Enum.TryParse(CurrentParamter[1].ToString(), out sourcemodule)) return false;
- int Sourceslotindex;
- if (!int.TryParse(CurrentParamter[2].ToString(), out Sourceslotindex)) return false;
- if (arm == RobotArmEnum.Lower)
- {
- WaferManager.Instance.WaferMoved(sourcemodule, Sourceslotindex, RobotModuleName, 0);
- WaferManager.Instance.WaferMoved(RobotModuleName, 1, sourcemodule, Sourceslotindex);
- }
- if (arm == RobotArmEnum.Upper)
- {
- WaferManager.Instance.WaferMoved(sourcemodule, Sourceslotindex, RobotModuleName, 1);
- WaferManager.Instance.WaferMoved(RobotModuleName, 0, sourcemodule, Sourceslotindex);
- }
- if (arm == RobotArmEnum.Both)
- {
- }
- Blade1Target = ModuleName.System;
- Blade2Target = ModuleName.System;
- CmdTarget = ModuleName.System;
- MoveInfo = new RobotMoveInfo()
- {
- Action = RobotAction.Moving,
- ArmTarget = CmdRobotArm == RobotArmEnum.Lower ? RobotArm.ArmA : RobotArm.ArmB,
- BladeTarget = BuildBladeTarget(),
- };
- return true;
- });
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL)
- {
- OnError($"{RobotModuleName}CompletePickingError.");
- }
- }
- }
- public void WaitRobotCompleteMove(int id, string name, int time)
- {
- var ret = ExecuteAndWait(id, () =>
- {
- EV.PostInfoLog($"{RobotModuleName}",name);
- return true;
- }, () =>
- {
- if (_lstMonitorHandler.Count >0 || _connection.IsBusy)
- {
- return Result.RUN;
- }
- if (CurrentCompoundCommandStatus == JelCommandStatus.InError)
- return Result.FAIL;
- if (CurrentCompoundCommandStatus == JelCommandStatus.NormalEnd)
- {
- Blade1Target = ModuleName.System;
- Blade2Target = ModuleName.System;
- CmdTarget = ModuleName.System;
- MoveInfo = new RobotMoveInfo()
- {
- Action = RobotAction.Moving,
- ArmTarget = CmdRobotArm == RobotArmEnum.Lower ? RobotArm.ArmA : RobotArm.ArmB,
- BladeTarget = BuildBladeTarget(),
- };
- return Result.DONE;
- }
-
- return Result.RUN;
- }, time * 1000);
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL)
- {
- OnError(string.Format("{0} occurred error", name));
- }
- if (ret.Item2 == Result.TIMEOUT) //timeout
- {
- OnError(string.Format("{0} timeout, than {1} seconds", name, time));
- }
- }
- }
- public void HomeWalkingAxis(int id, string name, int time)
- {
- var ret = ExecuteAndWait(id, () =>
- {
- EV.PostInfoLog($"{RobotModuleName}", name);
- m_WalkingAxis.Home(null);
- return true;
- }, () =>
- {
- if (m_WalkingAxis.IsReady())
- return Result.DONE;
- if (m_WalkingAxis.DeviceState == WalkingAxisState.ERROR)
- return Result.FAIL;
- return Result.RUN;
- }, time * 1000);
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL)
- {
- OnError(string.Format("{0} occurred error", name));
- }
- if (ret.Item2 == Result.TIMEOUT) //timeout
- {
- OnError(string.Format("{0} timeout, than {1} seconds", name, time));
- }
- }
- }
- public void WalkingAxisMoveToPos(int id, string name, ModuleName module, int time)
- {
- var ret = ExecuteAndWait(id, () =>
- {
- EV.PostInfoLog($"{m_WalkingAxis.Name}", name);
- return m_WalkingAxis.MoveTo(module);
- }, () =>
- {
- if (m_WalkingAxis.IsReady() && m_WalkingAxis.IsArrivedTarget)
- return Result.DONE;
- if (m_WalkingAxis.DeviceState == WalkingAxisState.ERROR)
- return Result.FAIL;
- return Result.RUN;
- }, time * 1000);
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL)
- {
- OnError(string.Format("{0} occurred error", name));
- }
- if (ret.Item2 == Result.TIMEOUT) //timeout
- {
- OnError(string.Format("{0} timeout, than {1} seconds", name, time));
- }
- }
- }
- protected DeviceTimer counter = new DeviceTimer();
- protected DeviceTimer delayTimer = new DeviceTimer();
- private enum STATE
- {
- IDLE,
- WAIT,
- }
- public int TokenId
- {
- get { return _id; }
- }
- private int _id; //step index
- private int _currentTokenId = -1;
- /// <summary>
- /// already done steps
- /// </summary>
- private Stack<int> _steps = new Stack<int>();
- private STATE state; //step state //idel,wait,
- //loop control
- private int loop = 0;
- private int loopCount = 0;
- private int loopID = 0;
- private DeviceTimer timer = new DeviceTimer();
- public int LoopCounter { get { return loop; } }
- public int LoopTotalTime { get { return loopCount; } }
- // public int Timeout { get { return (int)(timer.GetTotalTime() / 1000); } }
- //状态持续时间,单位为秒
- public int Elapsed { get { return (int)(timer.GetElapseTime() / 1000); } }
- protected RoutineResult RoutineToken = new RoutineResult() { Result = RoutineState.Running };
- protected Tuple<bool, Result> ExecuteResult;
- public void ResetRoutine()
- {
- _id = 0;
- _steps.Clear();
- loop = 0;
- loopCount = 0;
- state = STATE.IDLE;
- counter.Start(60 * 60 * 100); //默认1小时
- RoutineToken.Result = RoutineState.Running;
- _currentTokenId = -1;
- ExecuteResult = Tuple.Create(false, Result.DONE);
- }
- protected void PerformRoutineStep(int id, Func<RoutineState> execution, RoutineResult result)
- {
- if (!Acitve(id))
- return;
- result.Result = execution();
- }
- #region interface
- public void StopLoop()
- {
- loop = loopCount;
- }
- public Tuple<bool, Result> Loop<T>(T id, Func<bool> func, int count)
- {
- int idx = Convert.ToInt32(id);
- bool bActive = Acitve(idx);
- if (bActive)
- {
- if (!func())
- {
- return Tuple.Create(bActive, Result.FAIL); //执行错误
- }
- loopID = idx;
- loopCount = count;
- next();
- return Tuple.Create(true, Result.RUN);
- }
- return Tuple.Create(false, Result.RUN);
- }
- public Tuple<bool, Result> EndLoop<T>(T id, Func<bool> func)
- {
- int idx = Convert.ToInt32(id);
- bool bActive = Acitve(idx);
- if (bActive)
- {
- if (++loop >= loopCount) //Loop 结束
- {
- if (!func())
- {
- return Tuple.Create(bActive, Result.FAIL); //执行错误
- }
- loop = 0;
- loopCount = 0; // Loop 结束时,当前loop和loop总数都清零
- next();
- return Tuple.Create(true, Result.RUN);
- }
- //继续下一LOOP
- next(loopID);
- return Tuple.Create(true, Result.RUN);
- }
- return Tuple.Create(false, Result.RUN);
- }
- public Tuple<bool, Result> ExecuteAndWait<T>(T id, IRoutine routine)
- {
- int idx = Convert.ToInt32(id);
- bool bActive = Acitve(idx);
- if (bActive)
- {
- if (state == STATE.IDLE)
- {
- Result startRet = routine.Start();
- if (startRet == Result.FAIL)
- {
- return Tuple.Create(true, Result.FAIL); //执行错误
- }
- else if (startRet == Result.DONE)
- {
- next();
- return Tuple.Create(true, Result.DONE);
- }
- state = STATE.WAIT;
- }
- Result ret = routine.Monitor();
- if (ret == Result.DONE)
- {
- next();
- return Tuple.Create(true, Result.DONE);
- }
- else if (ret == Result.FAIL || ret == Result.TIMEOUT)
- {
- return Tuple.Create(true, Result.FAIL);
- }
- else
- {
- return Tuple.Create(true, Result.RUN);
- }
- }
- return Tuple.Create(false, Result.RUN);
- }
- public Tuple<bool, Result> ExecuteAndWait<T>(T id, List<IRoutine> routines)
- {
- int idx = Convert.ToInt32(id);
- bool bActive = Acitve(idx);
- if (bActive)
- {
- if (state == STATE.IDLE)
- {
- foreach (var item in routines)
- {
- if (item.Start() == Result.FAIL)
- return Tuple.Create(true, Result.FAIL);
- }
- state = STATE.WAIT;
- }
- //wait all sub failed or completedboo
- bool bFail = false;
- bool bDone = true;
- foreach (var item in routines)
- {
- Result ret = item.Monitor();
- bDone &= (ret == Result.FAIL || ret == Result.DONE);
- bFail |= ret == Result.FAIL;
- }
- if (bDone)
- {
- next();
- if (bFail)
- return Tuple.Create(true, Result.FAIL);
- return Tuple.Create(true, Result.DONE);
- }
- return Tuple.Create(true, Result.RUN);
- }
- return Tuple.Create(false, Result.RUN);
- }
- public Tuple<bool, Result> Check<T>(T id, Func<bool> func) //顺序执行
- {
- return Check(Check(Convert.ToInt32(id), func));
- }
- public Tuple<bool, Result> Execute<T>(T id, Func<bool> func) //顺序执行
- {
- return Check(execute(Convert.ToInt32(id), func));
- }
- public Tuple<bool, Result> Wait<T>(T id, Func<bool> func, double timeout = int.MaxValue) //Wait condition
- {
- return Check(wait(Convert.ToInt32(id), func, timeout));
- }
- public Tuple<bool, Result> Wait<T>(T id, Func<bool?> func, double timeout = int.MaxValue) //Wait condition
- {
- return Check(wait(Convert.ToInt32(id), func, timeout));
- }
- public Tuple<bool, Result> ExecuteAndWait<T>(T id, Func<bool> execute, Func<Result?> check, double timeout = int.MaxValue)
- {
- int idx = Convert.ToInt32(id);
- bool bActive = Acitve(idx);
- Result? bExecute = Result.RUN;
- if (bActive)
- {
- //if (idx != _currentTokenId && ExecuteResult.Item1) return ExecuteResult;
- if (state == STATE.IDLE)
- {
- if (!execute())
- {
- ExecuteResult = Tuple.Create(bActive, Result.FAIL);
- return Tuple.Create(bActive, Result.FAIL); //执行错误
- }
- timer.Start(timeout);
- state = STATE.WAIT;
- _currentTokenId = idx;
- }
- bExecute = check();
- if (bExecute == null)
- {
- ExecuteResult = Tuple.Create(bActive, Result.FAIL);
- return Tuple.Create(bActive, Result.FAIL); //Termianate
- }
- else
- {
- if (bExecute == Result.DONE) //检查Success, next
- {
- next();
- ExecuteResult = Tuple.Create(true, Result.RUN);
- return Tuple.Create(true, Result.RUN);
- }
- if (bExecute == Result.Succeed) //检查Success, next
- {
- next();
- ExecuteResult = Tuple.Create(true, Result.RUN);
- return Tuple.Create(true, Result.RUN);
- }
- if (bExecute == Result.FAIL) //检查 Fail 直接返回Fail
- {
- ExecuteResult = Tuple.Create(true, Result.FAIL);
- return Tuple.Create(true, Result.FAIL);
- }
- }
- if (timer.IsTimeout())
- {
- ExecuteResult = Tuple.Create(true, Result.TIMEOUT);
- return Tuple.Create(true, Result.TIMEOUT);
- }
- ExecuteResult = Tuple.Create(true, Result.RUN);
- return Tuple.Create(true, Result.RUN);
- }
- ExecuteResult = Tuple.Create(false, Result.RUN);
- return Tuple.Create(false, Result.RUN);
- }
- public Tuple<bool, Result> Wait<T>(T id, IRoutine rt)
- {
- int idx = Convert.ToInt32(id);
- bool bActive = Acitve(idx);
- if (bActive)
- {
- if (state == STATE.IDLE)
- {
- rt.Start();
- state = STATE.WAIT;
- }
- Result ret = rt.Monitor();
- return Tuple.Create(true, ret);
- }
- return Tuple.Create(false, Result.RUN);
- }
- //Monitor
- public Tuple<bool, Result> Monitor<T>(T id, Func<bool> func, Func<bool> check, double time)
- {
- int idx = Convert.ToInt32(id);
- bool bActive = Acitve(idx);
- bool bCheck = false;
- if (bActive)
- {
- if (state == STATE.IDLE)
- {
- if ((func != null) && !func())
- {
- return Tuple.Create(true, Result.FAIL);
- }
- timer.Start(time);
- state = STATE.WAIT;
- }
- bCheck = check();
- if (!bCheck)
- {
- return Tuple.Create(true, Result.FAIL); //Termianate
- }
- if (timer.IsTimeout())
- {
- next();
- }
- return Tuple.Create(true, Result.RUN);
- }
- return Tuple.Create(false, Result.RUN);
- }
- //Delay
- public Tuple<bool, Result> Delay<T>(T id, Func<bool> func, double time)
- {
- int idx = Convert.ToInt32(id);
- bool bActive = Acitve(idx);
- if (bActive)
- {
- //if (_currentTokenId != idx && !ExecuteResult.Item1) return ExecuteResult;
- if (state == STATE.IDLE)
- {
- if ((func != null) && !func())
- {
- ExecuteResult = Tuple.Create(true, Result.FAIL);
- return Tuple.Create(true, Result.FAIL);
- }
- _currentTokenId = idx;
- timer.Start(time);
- state = STATE.WAIT;
- }
- if (timer.IsTimeout())
- {
- next();
- }
- ExecuteResult = Tuple.Create(true, Result.RUN);
- return Tuple.Create(true, Result.RUN);
- }
- ExecuteResult = Tuple.Create(false, Result.RUN);
- return Tuple.Create(false, Result.RUN);
- }
- //先delay 再运行
- public Tuple<bool, Result> DelayCheck<T>(T id, Func<bool> func, double time)
- {
- int idx = Convert.ToInt32(id);
- bool bActive = Acitve(idx);
- if (bActive)
- {
- if (state == STATE.IDLE)
- {
- timer.Start(time);
- state = STATE.WAIT;
- }
- if (timer.IsTimeout())
- {
- if (func != null && !func())
- {
- return Tuple.Create(true, Result.FAIL);
- }
- next();
- }
- return Tuple.Create(true, Result.RUN);
- }
- return Tuple.Create(false, Result.RUN);
- }
- #endregion
- private Tuple<bool, bool> execute(int id, Func<bool> func) //顺序执行
- {
- bool bActive = Acitve(id);
- bool bExecute = false;
- if (bActive)
- {
- //if (ExecuteResult.Item1) return Tuple.Create(true, true);
- bExecute = func();
- if (bExecute)
- {
- next();
- }
- }
- return Tuple.Create(bActive, bExecute);
- }
- private Tuple<bool, bool> Check(int id, Func<bool> func) //check
- {
- bool bActive = Acitve(id);
- bool bExecute = false;
- if (bActive)
- {
- if (ExecuteResult.Item1) return Tuple.Create(true, true);
- bExecute = func();
- next();
- }
- return Tuple.Create(bActive, bExecute);
- }
- /// <summary>
- /// </summary>
- /// <param name="id"></param>
- /// <param name="func"></param>
- /// <param name="timeout"></param>
- /// <returns>
- /// item1 Active
- /// item2 execute
- /// item3 Timeout
- ///</returns>
- private Tuple<bool, bool, bool> wait(int id, Func<bool> func, double timeout = int.MaxValue) //Wait condition
- {
- bool bActive = Acitve(id);
- bool bExecute = false;
- bool bTimeout = false;
- if (bActive)
- {
- if (state == STATE.IDLE)
- {
- timer.Start(timeout);
- state = STATE.WAIT;
- }
- bExecute = func();
- if (bExecute)
- {
- next();
- }
- bTimeout = timer.IsTimeout();
- }
- return Tuple.Create(bActive, bExecute, bTimeout);
- }
- private Tuple<bool, bool?, bool> wait(int id, Func<bool?> func, double timeout = int.MaxValue) //Wait condition && Check error
- {
- bool bActive = Acitve(id);
- bool? bExecute = false;
- bool bTimeout = false;
- if (bActive)
- {
- if (state == STATE.IDLE)
- {
- timer.Start(timeout);
- state = STATE.WAIT;
- }
- bExecute = func();
- if (bExecute.HasValue && bExecute.Value)
- {
- next();
- }
- bTimeout = timer.IsTimeout();
- }
- return Tuple.Create(bActive, bExecute, bTimeout);
- }
- /// <summary>
- /// </summary>
- /// <param name="value"></param>
- /// <returns>
- /// item1 true, return item2
- /// </returns>
- private Tuple<bool, Result> Check(Tuple<bool, bool> value)
- {
- if (value.Item1)
- {
- if (!value.Item2)
- {
- ExecuteResult = Tuple.Create(true, Result.FAIL);
- return Tuple.Create(true, Result.FAIL);
- }
- ExecuteResult = Tuple.Create(true, Result.RUN);
- return Tuple.Create(true, Result.RUN);
- }
- ExecuteResult = Tuple.Create(false, Result.RUN);
- return Tuple.Create(false, Result.RUN);
- }
- private Tuple<bool, Result> Check(Tuple<bool, bool, bool> value)
- {
- if (value.Item1) // 当前执行
- {
- if (CheckTimeout(value)) //timeout
- {
- return Tuple.Create(true, Result.TIMEOUT);
- }
- return Tuple.Create(true, Result.RUN);
- }
- return Tuple.Create(false, Result.RUN);
- }
- private Tuple<bool, Result> Check(Tuple<bool, bool?, bool> value)
- {
- if (value.Item1) // 当前执行
- {
- if (value.Item2 == null)
- {
- return Tuple.Create(true, Result.FAIL);
- }
- else
- {
- if (value.Item2 == false && value.Item3 == true) //timeout
- {
- return Tuple.Create(true, Result.TIMEOUT);
- }
- return Tuple.Create(true, Result.RUN);
- }
- }
- return Tuple.Create(false, Result.RUN);
- }
- private bool CheckTimeout(Tuple<bool, bool, bool> value)
- {
- return value.Item1 == true && value.Item2 == false && value.Item3 == true;
- }
- private bool Acitve(int id) //
- {
- if (_steps.Contains(id))
- return false;
- this._id = id;
- return true;
- }
- private void next()
- {
- _steps.Push(this._id);
- state = STATE.IDLE;
- }
- private void next(int step) //loop
- {
- while (_steps.Pop() != step) ;
- state = STATE.IDLE;
- }
- public void Delay(int id, double delaySeconds)
- {
- Tuple<bool, Result> ret = Delay(id, () =>
- {
- return true;
- }, delaySeconds * 1000);
- if (ret.Item1)
- {
- if (ret.Item2 == Result.RUN)
- {
- }
- }
- }
- public bool IsActived(int id)
- {
- return _steps.Contains(id);
- }
- enum JelStep
- {
- Step1,
- Step2,
- Step3,
- Step4,
- Step5,
- Step6,
- Step7,
- Step8,
- Step9,
- Step10,
- Step11,
- Step12,
- }
- }
-
- }
|