| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715 | 
							- using System;
 
- using System.Collections.Generic;
 
- using System.Linq;
 
- using System.Threading.Tasks;
 
- using System.Windows.Media;
 
- using Aitex.Core.Common;
 
- using Aitex.Core.RT.DataCenter;
 
- using Aitex.Core.RT.Device;
 
- using Aitex.Core.RT.Event;
 
- using Aitex.Core.RT.Fsm;
 
- using Aitex.Core.RT.Log;
 
- using Aitex.Core.RT.OperationCenter;
 
- using Aitex.Core.RT.RecipeCenter;
 
- using Aitex.Core.RT.Routine;
 
- using Aitex.Core.RT.SCCore;
 
- using Aitex.Core.Util;
 
- using Aitex.Core.Utilities;
 
- using FurnaceRT.Devices;
 
- using FurnaceRT.Equipments.CarrierRobots;
 
- using FurnaceRT.Equipments.FIMSs;
 
- using FurnaceRT.Equipments.Jobs;
 
- using FurnaceRT.Equipments.LPs;
 
- using FurnaceRT.Equipments.PMs;
 
- using FurnaceRT.Equipments.PMs.RecipeExecutions;
 
- using FurnaceRT.Equipments.Schedulers;
 
- using FurnaceRT.Equipments.Stockers;
 
- using FurnaceRT.Equipments.WaferRobots;
 
- using FurnaceRT.Instances;
 
- using MECF.Framework.Common.Alarms;
 
- using MECF.Framework.Common.DataCenter;
 
- using MECF.Framework.Common.Device.Bases;
 
- using MECF.Framework.Common.Equipment;
 
- using MECF.Framework.Common.Jobs;
 
- using MECF.Framework.Common.SCCore;
 
- using MECF.Framework.Common.SubstrateTrackings;
 
- using MECF.Framework.FA.Core.FAControl;
 
- using MECF.Framework.RT.Core.Applications;
 
- using MECF.Framework.RT.Core.IoProviders;
 
- using AutoTransfer = FurnaceRT.Equipments.Jobs.AutoTransfer;
 
- using ReturnAllWafer = FurnaceRT.Equipments.Jobs.ReturnAllWafer;
 
- namespace FurnaceRT.Equipments.Systems
 
- {
 
-     public enum RtState
 
-     {
 
-         Init,
 
-         Initializing,
 
-         Idle,
 
-         Transfer,
 
-         AutoRunning,
 
-         AutoIdle,
 
-         ReturnAllWafer,
 
-         Error,
 
-         Loading,
 
-         Unloading,
 
-         ChargeProcessDischarging,
 
-         LoadProcessStockering,
 
-         LoadProcessUnloading,
 
-         ReturnWafer,
 
-     }
 
-     public enum TransferJobState
 
-     {
 
-         Idle,
 
-         Error,
 
-         Loading,
 
-         Unloading,
 
-     }
 
-     public enum ProcessJobState
 
-     {
 
-         Idle,
 
-         Error,
 
-         Charging,
 
-         Processing,
 
-         Cooling,
 
-         Discharging,
 
-     }
 
-     public partial class EquipmentManager : FsmDevice
 
-     {
 
-         public enum MSG
 
-         {
 
-             MoveWafer,
 
-             ReturnAllWafer,
 
-             Stop,
 
-             HOME,
 
-             RESET,
 
-             ABORT,
 
-             ERROR,
 
-             ToInit,
 
-             SetAutoMode,
 
-             SetManualMode,
 
-             CreateJob,
 
-             PauseJob,
 
-             ResumeJob,
 
-             StartJob,
 
-             StopJob,
 
-             AbortJob,
 
-             JobDone,
 
-             ModuleError,
 
-             Map,
 
-             Load,
 
-             Unload,
 
-             ChargeProcessDischarge,
 
-             LoadProcessStocker,
 
-             LoadProcessUnload,
 
-             CancelUnloadingJob,
 
-             ToUnloading,
 
-             ToLoading,
 
-             CreateTransferJob,
 
-             AbortTransferJob,
 
-         }
 
-         public Dictionary<ModuleName, ModuleFsmDevice> Modules { get; set; }
 
-         public bool IsAutoMode
 
-         {
 
-             get
 
-             {
 
-                 return FsmState == (int)RtState.AutoRunning || FsmState == (int)RtState.AutoIdle;
 
-             }
 
-         }
 
-         public bool IsReturnWafer
 
-         {
 
-             get
 
-             {
 
-                 return FsmState == (int)RtState.ReturnAllWafer || FsmState == (int)RtState.ReturnWafer;
 
-             }
 
-         }
 
-         public bool IsInit
 
-         {
 
-             get { return FsmState == (int)RtState.Init; }
 
-         }
 
-         public bool IsIdle
 
-         {
 
-             get { return FsmState == (int)RtState.Idle; }
 
-         }
 
-         public bool IsAlarm
 
-         {
 
-             get { return FsmState == (int)RtState.Error; }
 
-         }
 
-         public bool IsRunning
 
-         {
 
-             get
 
-             {
 
-                 return !IsAlarm && !IsIdle && !IsInit && (FsmState != (int)RtState.AutoIdle);
 
-             }
 
-         }
 
-         public bool IsAlarmConditionBuzzerOn { get; set; }
 
-         public TransferJobState TransferJobStatus { get; set; } = TransferJobState.Idle;
 
-         public ProcessJobState ProcessJobStatus { get; set; } = ProcessJobState.Idle;
 
-         public object JsonConvert { get; private set; }
 
-         private bool _isInited;
 
-         protected IRoutine _manualTransfer;
 
-         private AutoTransfer _auto = null;
 
-         private TransferJob _transferJob = null;
 
-         protected IRoutine _homeAll;
 
-         protected IRoutine _returnAll;
 
-         private string _batchType;
 
-         private string _processJob;
 
-         private string _processRecipe;
 
-         private DeviceTimer _coolTimer = new DeviceTimer();
 
-         private int _cycledCount = 0;
 
-         private int _jobMSG = 0;
 
-         private object[] _jobParas;
 
-         private object _locker = new object();
 
-         private List<string> _modules;
 
-         private PeriodicJob _cycleJob;
 
-         private RD_TRIG _plcConnectTrig = new RD_TRIG();
 
-         public EquipmentManager()
 
-         {
 
-             Module = "System";
 
-             Name = "System";
 
-             Modules = new Dictionary<ModuleName, ModuleFsmDevice>();
 
-             _modules = new List<string>() { "System" };
 
-         }
 
-         public override bool Initialize()
 
-         {
 
-             InitDevices();
 
-             InitModules();
 
-             EnumLoop<RtState>.ForEach((item) =>
 
-             {
 
-                 MapState((int)item, item.ToString());
 
-             });
 
-             EnumLoop<MSG>.ForEach((item) =>
 
-             {
 
-                 MapMessage((int)item, item.ToString());
 
-             });
 
-             EnableFsm(50, RtState.Init);
 
-             BuildTransitionTable();
 
-             SubscribeDataVariable();
 
-             SubscribeOperation();
 
-             InitRoutine();
 
-             InitAlarmDefine();
 
-             _auto = new AutoTransfer();
 
-             _transferJob = new TransferJob();
 
-             _cycleJob = new PeriodicJob(100, OnCycleTimer, Name, true);
 
-             Singleton<EventManager>.Instance.OnAlarmEvent += Instance_OnAlarmEvent;
 
-             return true;
 
-         }
 
-         protected void BuildModules(params ModuleFsmDevice[] modules)
 
-         {
 
-             if (modules != null && modules.Length > 0)
 
-             {
 
-                 foreach (var moduleFsmDevice in modules)
 
-                 {
 
-                     Modules[ModuleHelper.Converter(moduleFsmDevice.Module)] = moduleFsmDevice;
 
-                 }
 
-                 foreach (var modulesKey in Modules.Keys)
 
-                 {
 
-                     _modules.Add(modulesKey.ToString());
 
-                 }
 
-                 foreach (var modulesValue in Modules.Values)
 
-                 {
 
-                     modulesValue.Initialize();
 
-                 }
 
-             }
 
-         }
 
-         protected virtual void InitRoutine()
 
-         {
 
-             _homeAll = new HomeAll();
 
-             _returnAll = new ReturnAllWafer();
 
-             _dbCallback = new SchedulerDBCallback();
 
-         }
 
-         //private PeriodicJob _job1;
 
-         //Stopwatch _sw = new Stopwatch();
 
-         //private bool OnJob1()
 
-         //{
 
-         //    _sw.Restart();
 
-         //    BufferModule buffer = Modules[ModuleName.Buffer] as BufferModule;
 
-         //    if (!buffer.CheckToPostMessage(BufferModule.MSG.InTransfer))
 
-         //    {
 
-         //        System.Diagnostics.Trace.Assert(false)
 
-         //        System.Diagnostics.Trace.WriteLine("fail to in transfer");
 
-         //    }
 
-         //    if (buffer.IsIdle)
 
-         //    {
 
-         //        System.Diagnostics.Trace.Assert(false);
 
-         //        System.Diagnostics.Trace.WriteLine("!!!==========>IsIdle");
 
-         //    }
 
-         //    //System.Diagnostics.Trace.Assert(buffer.IsIdle, $"in {buffer.StringFsmStatus}");
 
-         //    while (buffer.IsIdle)
 
-         //    {
 
-         //        Thread.Sleep(5);
 
-         //    }
 
-         //    //buffer.NoteTransferStop(ModuleName.EfemRobot, Hand.Blade1, 0, EnumTransferType.Place);
 
-         //    //Thread.Sleep(15);
 
-         //    if (!buffer.CheckToPostMessage(BufferModule.MSG.TransferComplete))
 
-         //    {
 
-         //        System.Diagnostics.Trace.Assert(false);
 
-         //        System.Diagnostics.Trace.WriteLine("fail to complete");
 
-         //    }
 
-         //    //if (!buffer.IsIdle)
 
-         //    //{
 
-         //    //    System.Diagnostics.Trace.WriteLine("not idle");
 
-         //    //}
 
-         //    System.Diagnostics.Trace.WriteLine($" === {_sw.ElapsedMilliseconds}");
 
-         //    while (!buffer.IsIdle)
 
-         //    {
 
-         //        Thread.Sleep(5);
 
-         //    }
 
-         //    return true;
 
-         //}
 
-         private void BuildTransitionTable()
 
-         {
 
-             //Init sequence
 
-             Transition(RtState.Init, MSG.HOME, FsmStartHome, RtState.Initializing);
 
-             Transition(RtState.Idle, MSG.HOME, FsmStartHome, RtState.Initializing);
 
-             Transition(RtState.Error, MSG.HOME, FsmStartHome, RtState.Initializing);
 
-             Transition(RtState.Error, MSG.ToInit, null, RtState.Init);
 
-             Transition(RtState.Initializing, FSM_MSG.TIMER, FsmMonitorHome, RtState.Idle);
 
-             Transition(RtState.Initializing, MSG.ERROR, fError, RtState.Error);
 
-             Transition(RtState.Initializing, MSG.ABORT, FsmAbort, RtState.Init);
 
-             //Reset
 
-             AnyStateTransition(MSG.ERROR, fError, RtState.Error);
 
-             AnyStateTransition((int)FSM_MSG.ALARM, fError, (int)RtState.Error);
 
-             Transition(RtState.Error, MSG.RESET, fStartReset, RtState.Idle);
 
-             Transition(RtState.Init, MSG.RESET, fStartReset, RtState.Init);
 
-             Transition(RtState.Idle, MSG.RESET, fStartReset, RtState.Idle);
 
-             Transition(RtState.AutoIdle, MSG.RESET, fStartReset, RtState.AutoIdle);
 
-             Transition(RtState.AutoRunning, MSG.RESET, fStartReset, RtState.AutoRunning);
 
-             Transition(RtState.ReturnWafer, MSG.RESET, fStartReset, RtState.ReturnWafer);
 
-             //Auto/manual sequence
 
-             Transition(RtState.Idle, MSG.SetAutoMode, fStartAutoTransfer, RtState.AutoIdle);
 
-             Transition(RtState.AutoRunning, FSM_MSG.TIMER, fAutoTransfer, RtState.AutoRunning);
 
-             Transition(RtState.AutoRunning, MSG.ABORT, FsmAbort, RtState.Idle);
 
-             Transition(RtState.AutoRunning, MSG.JobDone, null, RtState.AutoIdle);
 
-             Transition(RtState.Idle, MSG.CreateJob, FsmCreateJob, RtState.AutoRunning);
 
-             Transition(RtState.Idle, MSG.LoadProcessUnload, FsmStartLoadProcessUnload, RtState.AutoRunning);
 
-             Transition(RtState.Idle, MSG.LoadProcessStocker, FsmStartLoadProcessStocker, RtState.AutoRunning);
 
-             Transition(RtState.AutoRunning, MSG.CreateJob, FsmCreateJob, RtState.AutoRunning);
 
-             Transition(RtState.AutoRunning, MSG.StartJob, FsmStartJob, RtState.AutoRunning);
 
-             Transition(RtState.AutoRunning, MSG.PauseJob, FsmPauseJob, RtState.AutoRunning);
 
-             Transition(RtState.AutoRunning, MSG.ResumeJob, FsmResumeJob, RtState.AutoRunning);
 
-             Transition(RtState.AutoRunning, MSG.StopJob, FsmStopJob, RtState.AutoRunning);
 
-             Transition(RtState.AutoRunning, MSG.AbortJob, FsmAbortJob, RtState.AutoRunning);
 
-             Transition(RtState.AutoRunning, MSG.ModuleError, FsmModuleError, RtState.AutoRunning);
 
-             Transition(RtState.AutoRunning, MSG.Load, FsmStartLoad, RtState.AutoRunning);
 
-             Transition(RtState.AutoRunning, MSG.Unload, FsmStartUnload, RtState.AutoRunning);
 
-             Transition(RtState.Idle, MSG.CreateTransferJob, FsmCreateTransferJob, RtState.AutoRunning);
 
-             Transition(RtState.AutoRunning, MSG.CreateTransferJob, FsmCreateTransferJob, RtState.AutoRunning);
 
-             Transition(RtState.AutoRunning, MSG.AbortTransferJob, FsmAbortTransferJob, RtState.AutoRunning);
 
-             Transition(RtState.AutoRunning, MSG.CancelUnloadingJob, FsmCancelUnloadingJob, RtState.AutoRunning);
 
-             Transition(RtState.AutoRunning, MSG.LoadProcessUnload, FsmStartLoadProcessUnload, RtState.AutoRunning);
 
-             Transition(RtState.AutoRunning, MSG.LoadProcessStocker, FsmStartLoadProcessStocker, RtState.AutoRunning);
 
-             Transition(RtState.AutoIdle, FSM_MSG.TIMER, FsmMonitorAutoIdle, RtState.AutoIdle);
 
-             Transition(RtState.AutoIdle, MSG.SetManualMode, FsmStartSetManualMode, RtState.Idle);
 
-             Transition(RtState.AutoIdle, MSG.CreateJob, FsmCreateJob, RtState.AutoRunning);
 
-             Transition(RtState.AutoIdle, MSG.StartJob, FsmStartJob, RtState.AutoRunning);
 
-             Transition(RtState.AutoIdle, MSG.ABORT, FsmAbort, RtState.Idle);
 
-             Transition(RtState.AutoIdle, MSG.AbortJob, FsmAbortJob, RtState.AutoIdle);
 
-             Transition(RtState.AutoIdle, MSG.Load, FsmStartLoad, RtState.AutoIdle);
 
-             Transition(RtState.AutoIdle, MSG.Unload, FsmStartUnload, RtState.AutoIdle);
 
-             Transition(RtState.AutoIdle, MSG.CreateTransferJob, FsmCreateTransferJob, RtState.AutoRunning);
 
-             Transition(RtState.AutoIdle, MSG.AbortTransferJob, FsmAbortTransferJob, RtState.AutoIdle);
 
-             Transition(RtState.AutoIdle, MSG.LoadProcessUnload, FsmStartLoadProcessUnload, RtState.AutoRunning);
 
-             Transition(RtState.AutoIdle, MSG.LoadProcessStocker, FsmStartLoadProcessStocker, RtState.AutoRunning);
 
-             EnterExitTransition<RtState, FSM_MSG>(RtState.AutoRunning, null, FSM_MSG.NONE, fExitAutoTransfer);
 
-             //return all wafer
 
-             //Transition(RtState.Idle, MSG.ReturnAllWafer, FsmStartReturnAllWafer, RtState.ReturnAllWafer);
 
-             //Transition(RtState.ReturnAllWafer, FSM_MSG.TIMER, FsmMonitorReturnAllWafer, RtState.Idle);
 
-             //Transition(RtState.ReturnAllWafer, MSG.ABORT, FsmAbortReturnAllWafer, RtState.Idle);
 
-             //Return wafer
 
-             Transition(RtState.Idle, MSG.ReturnAllWafer, FsmStartReturnWafer, RtState.ReturnWafer);
 
-             Transition(RtState.AutoIdle, MSG.ReturnAllWafer, FsmStartReturnWafer, RtState.ReturnWafer);
 
-             Transition(RtState.ReturnWafer, FSM_MSG.TIMER, FsmMonitorReturnWafer, RtState.Idle);
 
-             Transition(RtState.ReturnWafer, MSG.ABORT, FsmAbort, RtState.Idle);
 
-             //Transfer sequence
 
-             Transition(RtState.Idle, MSG.MoveWafer, fStartTransfer, RtState.Transfer);
 
-             Transition(RtState.Transfer, FSM_MSG.TIMER, fTransfer, RtState.Idle);
 
-             EnterExitTransition<RtState, FSM_MSG>(RtState.Transfer, null, FSM_MSG.NONE, fExitTransfer);
 
-             Transition(RtState.Transfer, MSG.ABORT, FsmAbort, RtState.Idle);
 
-         }
 
-         void SubscribeDataVariable()
 
-         {
 
-             DATA.Subscribe("Rt.Status", () => StringFsmStatus);
 
-             DATA.Subscribe("System.IsInitialized", () => _isInited);
 
-             DATA.Subscribe("System.IsIdle", () => IsIdle || IsInit || (FsmState == (int)RtState.AutoIdle));
 
-             DATA.Subscribe("System.IsAlarm", () => IsAlarm);
 
-             DATA.Subscribe("System.IsBusy", () => IsRunning);
 
-             DATA.Subscribe("System.IsAutoRunning", () => IsRunning);
 
-             DATA.Subscribe("System.IsAlarmConditionBuzzerOn", () => IsAlarmConditionBuzzerOn);
 
-             DATA.Subscribe("System.Modules", () => _modules);
 
-         }
 
-         void SubscribeOperation()
 
-         {
 
-             OP.Subscribe("CreateWafer", InvokeCreateWafer);
 
-             OP.Subscribe("System.UpdateWafer", InvokeUpdateWafer);
 
-             OP.Subscribe("CreateWaferFromTo", InvokeCreateWaferFromTo);
 
-             OP.Subscribe("DeleteWafer", InvokeDeleteWafer);
 
-             OP.Subscribe("DeleteWaferFromTo", InvokeDeleteWaferFromTo);
 
-             OP.Subscribe("CreateCassetteWafer", InvokeCreateCassetteWafer);
 
-             OP.Subscribe("DeleteCassetteWafer", InvokeDeleteCassetteWafer);
 
-             OP.Subscribe("System.CreateCarrier", InvokeCreateCarrier);
 
-             OP.Subscribe("System.DeleteCarrier", InvokeDeleteCarrier);
 
-             OP.Subscribe("System.SetLotID", InvokeSetLotID);
 
-             OP.Subscribe("System.DeleteAllWafer", InvokeDeleteAllWafer);
 
-             OP.Subscribe("System.DeleteAllCarrier", InvokeDeleteAllCarrier);
 
-             OP.Subscribe("ReturnWafer", InvokeReturnWafer);
 
-             OP.Subscribe("System.SignalTower.SwitchOffBuzzer", InvokeSwitchOffBuzzer);
 
-             OP.Subscribe("System.ReturnAllWafer", (string cmd, object[] args) =>
 
-             {
 
-                 return CheckToPostMessage((int)MSG.ReturnAllWafer);
 
-             });
 
-             OP.Subscribe("System.MoveWafer", (string cmd, object[] args) =>
 
-             {
 
-                 if (!Enum.TryParse((string)args[0], out ModuleName source))
 
-                 {
 
-                     EV.PostWarningLog(Name, $"Parameter source {(string)args[0]} not valid");
 
-                     return false;
 
-                 }
 
-                 if (!Enum.TryParse((string)args[2], out ModuleName destination))
 
-                 {
 
-                     EV.PostWarningLog(Name, $"Parameter destination {(string)args[1]} not valid");
 
-                     return false;
 
-                 }
 
-                 if (args.Length > 8)
 
-                 {
 
-                     return CheckToPostMessage((int)MSG.MoveWafer, source, (int)args[1], destination, (int)args[3],
 
-                         (bool)args[4], (int)args[5], (bool)args[6], (int)args[7]);
 
-                 }
 
-                 else if (args.Length > 5)
 
-                 {
 
-                     return CheckToPostMessage((int)MSG.MoveWafer, source, (int)args[1], destination, (int)args[3], (bool)args[4]);
 
-                 }
 
-                 return CheckToPostMessage((int)MSG.MoveWafer, source, (int)args[1], destination, (int)args[3]);
 
-             });
 
-             OP.Subscribe("System.HomeAll", (string cmd, object[] args) =>
 
-             {
 
-                 return CheckToPostMessage((int)MSG.HOME);
 
-             });
 
-             OP.Subscribe("System.Abort", (string cmd, object[] args) =>
 
-             {
 
-                 return CheckToPostMessage((int)MSG.ABORT);
 
-             });
 
-             OP.Subscribe("System.Reset", (string cmd, object[] args) =>
 
-             {
 
-                 return CheckToPostMessage((int)MSG.RESET);
 
-             });
 
-             OP.Subscribe("System.SetAutoMode", (string cmd, object[] args) =>
 
-             {
 
-                 return CheckToPostMessage((int)MSG.SetAutoMode);
 
-             });
 
-             OP.Subscribe("System.SetManualMode", (string cmd, object[] args) =>
 
-             {
 
-                 return CheckToPostMessage((int)MSG.SetManualMode);
 
-             });
 
-             OP.Subscribe("System.CreateJob", (string cmd, object[] args) =>
 
-             {
 
-                 return CheckToPostMessage((int)MSG.CreateJob, args[0]);
 
-             });
 
-             OP.Subscribe("System.StartJob", (string cmd, object[] args) =>
 
-             {
 
-                 return CheckToPostMessage((int)MSG.StartJob, args[0]);
 
-             });
 
-             OP.Subscribe("System.PauseJob", (string cmd, object[] args) =>
 
-             {
 
-                 return CheckToPostMessage((int)MSG.PauseJob, args[0]);
 
-             });
 
-             OP.Subscribe("System.ResumeJob", (string cmd, object[] args) =>
 
-             {
 
-                 return CheckToPostMessage((int)MSG.ResumeJob, args[0]);
 
-             });
 
-             OP.Subscribe("System.StopJob", (string cmd, object[] args) =>
 
-             {
 
-                 return CheckToPostMessage((int)MSG.StopJob, args[0]);
 
-             });
 
-             OP.Subscribe("System.AbortJob", (string cmd, object[] args) =>
 
-             {
 
-                 return CheckToPostMessage((int)MSG.AbortJob, args[0]);
 
-             });
 
-             OP.Subscribe("System.CoolingSkip", (string cmd, object[] args) =>
 
-             {
 
-                 CoolingSkip();
 
-                 return true;
 
-             });
 
-             OP.Subscribe("System.ShutDown", InvokeShutDown);
 
-             OP.Subscribe($"System.Load", (string cmd, object[] args) => CheckToPostJobMessage((int)MSG.CreateTransferJob, args));
 
-             OP.Subscribe($"System.Unload", (string cmd, object[] args) => CheckToPostJobMessage((int)MSG.CreateTransferJob, args));
 
-             OP.Subscribe($"System.ChargeProcessDischarge", (string cmd, object[] args) => CheckToPostJobMessage((int)MSG.CreateJob, args));
 
-             OP.Subscribe($"System.LoadProcessUnload", (string cmd, object[] args) => CheckToPostJobMessage((int)MSG.LoadProcessUnload, args));
 
-             OP.Subscribe($"System.LoadProcessStocker", (string cmd, object[] args) => CheckToPostJobMessage((int)MSG.LoadProcessStocker, args));
 
-             OP.Subscribe($"System.MonitorLoad", (string cmd, object[] args) => CheckToPostJobMessage((int)MSG.CreateTransferJob, args));
 
-             OP.Subscribe($"System.MonitorUnload", (string cmd, object[] args) => CheckToPostJobMessage((int)MSG.CreateTransferJob, args));
 
-             OP.Subscribe($"System.SDLoad", (string cmd, object[] args) => CheckToPostJobMessage((int)MSG.CreateTransferJob, args));
 
-             OP.Subscribe($"System.SDUnload", (string cmd, object[] args) => CheckToPostJobMessage((int)MSG.CreateTransferJob, args));
 
-             OP.Subscribe($"{Module}.AlarmAction", (string cmd, object[] args) =>
 
-             {
 
-                 Enum.TryParse(args[0].ToString(), out AlarmAction alarmAction);
 
-                 if (alarmAction == AlarmAction.ClearAll)
 
-                 {
 
-                     CheckToPostMessage((int)MSG.RESET);
 
-                     return true;
 
-                 }
 
-                 string eventName = null;
 
-                 if (args.Length > 1)
 
-                     eventName = args[1].ToString();
 
-                 if (eventName != null)
 
-                 {
 
-                     EV.ClearAlarmEvent(eventName);
 
-                     var item = _triggeredAlarmList.FirstOrDefault(x => x.EventEnum == eventName);
 
-                     if (item != null)
 
-                     {
 
-                         item.Reset();
 
-                         _triggeredAlarmList.Remove(item);
 
-                     }
 
-                     if (item != null)
 
-                     {
 
-                         switch (alarmAction)
 
-                         {
 
-                             case AlarmAction.Retry:
 
-                                 {
 
-                                     CheckToPostMessage((int)item.RetryMessage, item.RetryMessageParas);
 
-                                 }
 
-                                 break;
 
-                             case AlarmAction.Abort:
 
-                                 {
 
-                                     CheckToPostMessage((int)MSG.ABORT);
 
-                                 }
 
-                                 break;
 
-                             case AlarmAction.Clear:
 
-                                 {
 
-                                     int alarmCount = 0;
 
-                                     var alarms = EV.GetAlarmEvent();
 
-                                     foreach (var alarm in alarms)
 
-                                     {
 
-                                         if (alarm.Level == EventLevel.Alarm && alarm.Source == Name)
 
-                                             alarmCount++;
 
-                                     }
 
-                                     if (alarmCount == 0)
 
-                                         CheckToPostMessage((int)MSG.RESET);
 
-                                 }
 
-                                 break;
 
-                             case AlarmAction.Continue:
 
-                                 {
 
-                                     int alarmCount = 0;
 
-                                     var alarms = EV.GetAlarmEvent();
 
-                                     foreach (var alarm in alarms)
 
-                                     {
 
-                                         if (alarm.Level == EventLevel.Alarm && alarm.Source == Name)
 
-                                             alarmCount++;
 
-                                     }
 
-                                     if (alarmCount == 0)
 
-                                         CheckToPostMessage((int)MSG.RESET);
 
-                                 }
 
-                                 break;
 
-                         }
 
-                     }
 
-                 }
 
-                 return true;
 
-             });
 
-         }
 
-         private void Instance_OnAlarmEvent(EventItem item)
 
-         {
 
-             if (item != null && item.Level == EventLevel.Alarm && (item.Source == Name || item.Source == Module))
 
-             {
 
-                 DEVICE.GetDevice<SignalTowerBase>("System.SignalTower")?.Reset();
 
-                 LOG.Write($"{item.Source} {item.EventEnum} {item.Description}\n");
 
-                 PostMsg(MSG.ERROR);
 
-             }
 
-         }
 
-         #region Init
 
-         private bool FsmStartHome(object[] objs)
 
-         {
 
-             _isInited = false;
 
-             return _homeAll.Start() == Result.RUN;
 
-         }
 
-         private bool FsmMonitorHome(object[] objs)
 
-         {
 
-             Result ret = _homeAll.Monitor();
 
-             if (ret == Result.DONE)
 
-             {
 
-                 _isInited = true;
 
-                 return true;
 
-             }
 
-             if (ret == Result.FAIL)
 
-             {
 
-                 PostMsg(MSG.ERROR);
 
-             }
 
-             return false;
 
-         }
 
-         private bool fError(object[] objs)
 
-         {
 
-             if (FsmState == (int)RtState.Transfer)
 
-             {
 
-             }
 
-             return true;
 
-         }
 
-         #endregion
 
-         #region job
 
-         private bool FsmStartLoad(object[] param)
 
-         {
 
-             if (_transferJob.CreateJob(param) != Result.RUN)
 
-             {
 
-                 return false;
 
-             }
 
-             return true;
 
-         }
 
-         private bool FsmStartUnload(object[] param)
 
-         {
 
-             if (_transferJob.CreateJob(param) != Result.RUN)
 
-             {
 
-                 return false;
 
-             }
 
-             return true;
 
-         }
 
-         private bool FsmStartLoadProcessStocker(object[] param)
 
-         {
 
-             var paramDic = (Dictionary<string, object>)param[0];
 
-             if (paramDic == null)
 
-             {
 
-                 LoadProcessStockerStartFailedWarning.Set("Parameter not valid");
 
-                 return false;
 
-             }
 
-             paramDic["TransferType"] = "Loading";
 
-             param[0] = paramDic;
 
-             if (_transferJob.CreateJob(param) != Result.RUN)
 
-             {
 
-                 return false;
 
-             }
 
-             if (_auto.CreateJob(param) != Result.RUN)
 
-             {
 
-                 return false;
 
-             }
 
-             return true;
 
-         }
 
-         private bool FsmStartLoadProcessUnload(object[] param)
 
-         {
 
-             var paramDic = (Dictionary<string, object>)param[0];
 
-             if (paramDic == null)
 
-             {
 
-                 LoadProcessUnloadStartFailedWarning.Set("Parameter not valid");
 
-                 return false;
 
-             }
 
-             paramDic["TransferType"] = "Loading";
 
-             param[0] = paramDic;
 
-             if (_transferJob.CreateJob(param) != Result.RUN)
 
-             {
 
-                 return false;
 
-             }
 
-             if (_auto.CreateJob(param) != Result.RUN)
 
-             {
 
-                 return false;
 
-             }
 
-             paramDic["TransferType"] = "Unloading";
 
-             param[0] = paramDic;
 
-             if (_transferJob.CreateJob(param) != Result.RUN)
 
-             {
 
-                 return false;
 
-             }
 
-             return true;
 
-         }
 
-         #endregion
 
-         #region AutoTransfer
 
-         private bool FsmMonitorAutoIdle(object[] param)
 
-         {
 
-             Result ret = _transferJob.Monitor();
 
-             _auto.Monitor();
 
-             if (!_auto.CheckAllJobDone() || !_transferJob.CheckAllJobDone())
 
-             {
 
-                 return false;
 
-             }
 
-             return ret == Result.DONE;
 
-         }
 
-         private bool FsmStartSetManualMode(object[] objs)
 
-         {
 
-             if (_auto.HasJobRunning)
 
-             {
 
-                 EV.PostWarningLog("System", "Can not change to manual mode, abort running job first");
 
-                 return false;
 
-             }
 
-             return true;
 
-         }
 
-         private bool fStartAutoTransfer(object[] objs)
 
-         {
 
-             Result ret = _auto.Start(objs);
 
-             return ret == Result.RUN;
 
-         }
 
-         private bool fAutoTransfer(object[] objs)
 
-         {
 
-             Result ret = _transferJob.Monitor();
 
-             _auto.Monitor();
 
-             if (_auto.CheckAllJobDone() && _transferJob.CheckAllJobDone())
 
-             {
 
-                 if (!CheckToPostMessage((int)MSG.JobDone))
 
-                     return false;
 
-             }
 
-             return ret == Result.DONE;
 
-         }
 
-         private bool fExitAutoTransfer(object[] objs)
 
-         {
 
-             _auto.Clear();
 
-             _transferJob.Clear();
 
-             return true;
 
-         }
 
-         private bool fAbortAutoTransfer(object[] objs)
 
-         {
 
-             _auto.Clear();
 
-             _transferJob.Clear();
 
-             return true;
 
-         }
 
-         #endregion
 
-         #region  return all wafer
 
-         private bool FsmAbortReturnAllWafer(object[] param)
 
-         {
 
-             return true;
 
-         }
 
-         private bool FsmMonitorReturnAllWafer(object[] param)
 
-         {
 
-             return _returnAll.Monitor() == Result.DONE;
 
-         }
 
-         private bool FsmStartReturnAllWafer(object[] param)
 
-         {
 
-             return _returnAll.Start() == Result.RUN;
 
-         }
 
-         #endregion
 
-         #region Transfer
 
-         private bool fStartTransfer(object[] objs)
 
-         {
 
-             Result ret = _manualTransfer.Start(objs);
 
-             if (ret == Result.FAIL || ret == Result.DONE)
 
-                 return false;
 
-             return ret == Result.RUN;
 
-         }
 
-         private bool fTransfer(object[] objs)
 
-         {
 
-             Result ret = _manualTransfer.Monitor();
 
-             if (ret == Result.FAIL)
 
-             {
 
-                 PostMsg(MSG.ERROR);
 
-                 return false;
 
-             }
 
-             return ret == Result.DONE;
 
-         }
 
-         private bool fExitTransfer(object[] objs)
 
-         {
 
-             return true;
 
-         }
 
-         private bool fAbortTransfer(object[] objs)
 
-         {
 
-             return true;
 
-         }
 
-         #endregion
 
-         #region reset
 
-         private bool fStartReset(object[] objs)
 
-         {
 
-             EV.ClearAlarmEvent();
 
-             Singleton<DeviceEntity>.Instance.PostMsg(DeviceEntity.MSG.RESET);
 
-             IoProviderManager.Instance.Reset();
 
-             foreach (var modulesValue in Modules.Values)
 
-             {
 
-                 modulesValue.Reset();
 
-             }
 
-             _triggeredAlarmList.ForEach(x => x.Reset());
 
-             _triggeredAlarmList.Clear();
 
-             if (FsmState == (int)RtState.Error)
 
-             {
 
-                 if (!_isInited)
 
-                 {
 
-                     PostMsg(MSG.ToInit);
 
-                     return false;
 
-                 }
 
-                 return true;
 
-             }
 
-             return false;
 
-         }
 
-         #endregion
 
-         private bool FsmCreateJob(object[] param)
 
-         {
 
-             if (FsmState != (int)RtState.AutoRunning && CarrierManager.Instance.CheckHasCarrier(ModuleName.CarrierRobot, 0))
 
-             {
 
-                 EV.PostWarningLog("System", $"FOUP robot already has a FOUP, create job failed");
 
-                 return false;
 
-             }
 
-             _auto.CreateJob((Dictionary<string, object>)param[0]);
 
-             return true;
 
-         }
 
-         private bool FsmAbortJob(object[] param)
 
-         {
 
-             _auto.AbortJob((string)param[0]);
 
-             return true;
 
-         }
 
-         private bool FsmStopJob(object[] param)
 
-         {
 
-             _auto.StopJob((string)param[0]);
 
-             Singleton<FAJobController>.Instance.CJAbort((string)param[0]);
 
-             //CheckToPostMessage((int)MSG.StopJob);//
 
-             return true;
 
-         }
 
-         private bool FsmResumeJob(object[] param)
 
-         {
 
-             _auto.ResumeJob((string)param[0]);
 
-             return true;
 
-         }
 
-         private bool FsmPauseJob(object[] param)
 
-         {
 
-             _auto.PauseJob((string)param[0]);
 
-             return true;
 
-         }
 
-         private bool FsmStartJob(object[] param)
 
-         {
 
-             return _auto.StartJob((string)param[0]);
 
-         }
 
-         private bool FsmCreateTransferJob(object[] param)
 
-         {
 
-             if (FsmState != (int)RtState.AutoRunning && CarrierManager.Instance.CheckHasCarrier(ModuleName.CarrierRobot, 0))
 
-             {
 
-                 EV.PostWarningLog("System", $"FOUP robot already has a FOUP, create job failed");
 
-                 return false;
 
-             }
 
-             _transferJob.CreateJob(param);
 
-             return true;
 
-         }
 
-         private bool FsmAbortTransferJob(object[] param)
 
-         {
 
-             _transferJob.AbortJob((string)param[0]);
 
-             return true;
 
-         }
 
-         private bool FsmCancelUnloadingJob(object[] param)
 
-         {
 
-             _transferJob.CancelUnloadingJob((string)param[0], (string)param[1]);
 
-             return true;
 
-         }
 
-         private bool FsmAbort(object[] param)
 
-         {
 
-             if (FsmState == (int)RtState.Transfer)
 
-             {
 
-                 // _manualTransfer.Clear();
 
-             }
 
-             if (FsmState == (int)RtState.ChargeProcessDischarging || FsmState == (int)RtState.LoadProcessStockering || FsmState == (int)RtState.LoadProcessUnloading)
 
-             {
 
-                 _auto.PjUpdated();
 
-                 _auto.PjFinished("Job Abort");
 
-             }
 
-             if (FsmState == (int)RtState.AutoRunning)
 
-             {
 
-                 _auto.Clear();
 
-             }
 
-             if (FsmState == (int)RtState.Initializing)
 
-             {
 
-                 _homeAll.Abort();
 
-             }
 
-             return true;
 
-         }
 
-         private bool FsmModuleError(object[] param)
 
-         {
 
-             //_auto.ModuleError((string)param[0]);
 
-             return true;
 
-         }
 
-         private bool FsmStartReturnWafer(object[] objs)
 
-         {
 
-             Result ret = _returnAll.Start();
 
-             if (ret == Result.FAIL)
 
-             {
 
-                 PostMsg(MSG.ERROR);
 
-                 return false;
 
-             }
 
-             return ret == Result.RUN;
 
-         }
 
-         private bool FsmMonitorReturnWafer(object[] objs)
 
-         {
 
-             Result ret = _returnAll.Monitor();
 
-             if (ret == Result.FAIL)
 
-             {
 
-                 PostMsg(MSG.ERROR);
 
-                 return false;
 
-             }
 
-             if (ret == Result.DONE)
 
-             {
 
-                 _batchType = "";
 
-                 _processJob = "";
 
-                 _processRecipe = "";
 
-                 (Modules[ModuleName.CarrierRobot] as CarrierRobotModule).Home(out _);
 
-                 (Modules[ModuleName.WaferRobot] as WaferRobotModule).Home(out _);
 
-             }
 
-             return ret == Result.DONE;
 
-         }
 
-         private bool InvokeSwitchOffBuzzer(string arg1, object[] args)
 
-         {
 
-             DEVICE.GetDevice<SignalTowerBase>("System.SignalTower")?.SwitchOffBuzzer(true);
 
-             IsAlarmConditionBuzzerOn = false;
 
-             return true;
 
-         }
 
-         private bool InvokeReturnWafer(string arg1, object[] args)
 
-         {
 
-             ModuleName target = ModuleHelper.Converter(args[0].ToString());
 
-             int slot = (int)args[1];
 
-             if (ModuleHelper.IsLoadPort(target))
 
-             {
 
-                 EV.PostInfoLog("System", string.Format("Wafer already at LoadPort {0} {1}, return operation is not valid", target.ToString(), slot + 1));
 
-                 return false;
 
-             }
 
-             if (!WaferManager.Instance.IsWaferSlotLocationValid(target, slot))
 
-             {
 
-                 EV.PostWarningLog("System", string.Format("Invalid position,{0},{1}", target.ToString(), slot.ToString()));
 
-                 return false;
 
-             }
 
-             WaferInfo wafer = WaferManager.Instance.GetWafer(target, slot);
 
-             if (wafer.IsEmpty)
 
-             {
 
-                 EV.PostInfoLog("System", string.Format("No wafer at {0} {1}, return operation is not valid", target.ToString(), slot + 1));
 
-                 return false;
 
-             }
 
-             return CheckToPostMessage((int)MSG.MoveWafer,
 
-                 target, slot,
 
-                 (ModuleName)wafer.OriginStation, wafer.OriginSlot,
 
-                 false, 0, false, 0);
 
-         }
 
-         private bool InvokeDeleteAllWafer(string arg1, object[] args)
 
-         {
 
-             foreach (var item in Modules.Values)
 
-             {
 
-                 if ((item as PMModule) != null || (item as WaferRobotModule) != null)
 
-                 {
 
-                     var wafers = WaferManager.Instance.GetWafers(ModuleHelper.Converter(item.Module));
 
-                     for (int i = 0; i < wafers.Length; i++)
 
-                     {
 
-                         if (!wafers[i].IsEmpty)
 
-                             WaferManager.Instance.DeleteWafer(ModuleHelper.Converter(item.Module), i);
 
-                     }
 
-                 }
 
-             }
 
-             return true;
 
-         }
 
-         private bool InvokeDeleteAllCarrier(string arg1, object[] args)
 
-         {
 
-             foreach (var item in Modules.Values)
 
-             {
 
-                 if ((item as LoadPortModule) != null || (item as StockerModule) != null || (item as FIMSModule) != null || (item as CarrierRobotModule) != null)
 
-                 {
 
-                     if (CarrierManager.Instance.HasCarrier(item.Module.ToString()))
 
-                     {
 
-                         CarrierManager.Instance.DeleteCarrier(item.Module.ToString());
 
-                         var wafers = WaferManager.Instance.GetWafers(ModuleHelper.Converter(item.Module));
 
-                         for (int i = 0; i < wafers.Length; i++)
 
-                         {
 
-                             if (!wafers[i].IsEmpty)
 
-                                 WaferManager.Instance.DeleteWafer(ModuleHelper.Converter(item.Module), i);
 
-                         }
 
-                     }
 
-                 }
 
-             }
 
-             return true;
 
-         }
 
-         private bool InvokeDeleteWaferFromTo(string arg1, object[] args)
 
-         {
 
-             ModuleName chamber = ModuleHelper.Converter(args[0].ToString());
 
-             int slotFrom = (int)args[1];
 
-             int slotTo = (int)args[2];
 
-             for (int slot = slotTo - 1; slot >= slotFrom - 1; slot--)
 
-             {
 
-                 if (WaferManager.Instance.IsWaferSlotLocationValid(chamber, slot))
 
-                 {
 
-                     if (WaferManager.Instance.CheckHasWafer(chamber, slot))
 
-                     {
 
-                         WaferManager.Instance.DeleteWafer(chamber, slot);
 
-                         EV.PostMessage(ModuleName.System.ToString(), EventEnum.WaferDelete, chamber.ToString(), slot + 1);
 
-                     }
 
-                     else
 
-                     {
 
-                         EV.PostInfoLog("System", string.Format("No wafer at {0} {1}, delete not valid", chamber.ToString(), slot + 1));
 
-                     }
 
-                 }
 
-                 else
 
-                 {
 
-                     DeleteWaferFailedWarning.Set(string.Format("Invalid position,{0},{1}", chamber.ToString(), slot.ToString()));
 
-                     return false;
 
-                 }
 
-             }
 
-             var carrier = CarrierManager.Instance.GetCarrier(chamber);
 
-             if (carrier != null)
 
-             {
 
-                 CarrierManager.Instance.UpdateWaferIn(chamber, 0, false);
 
-             }
 
-             var wafers = WaferManager.Instance.GetWafers(chamber);
 
-             if (wafers != null && carrier != null)
 
-             {
 
-                 foreach (var wafer in wafers)
 
-                 {
 
-                     if (wafer != null && !wafer.IsEmpty)
 
-                     {
 
-                         CarrierManager.Instance.UpdateWaferIn(chamber, 0, true);
 
-                         break;
 
-                     }
 
-                 }
 
-             }
 
-             return true;
 
-         }
 
-         private bool InvokeDeleteWafer(string arg1, object[] args)
 
-         {
 
-             ModuleName chamber = ModuleHelper.Converter(args[0].ToString());
 
-             int slot = (int)args[1];
 
-             if (WaferManager.Instance.IsWaferSlotLocationValid(chamber, slot))
 
-             {
 
-                 if (WaferManager.Instance.CheckHasWafer(chamber, slot))
 
-                 {
 
-                     WaferManager.Instance.DeleteWafer(chamber, slot);
 
-                     EV.PostMessage(ModuleName.System.ToString(), EventEnum.WaferDelete, chamber.ToString(), slot + 1);
 
-                 }
 
-                 else
 
-                 {
 
-                     EV.PostInfoLog("System", string.Format("No wafer at {0} {1}, delete not valid", chamber.ToString(), slot + 1));
 
-                 }
 
-             }
 
-             else
 
-             {
 
-                 DeleteWaferFailedWarning.Set(string.Format("Invalid position,{0},{1}", chamber.ToString(), slot.ToString()));
 
-                 return false;
 
-             }
 
-             var carrier = CarrierManager.Instance.GetCarrier(chamber);
 
-             if (carrier != null)
 
-             {
 
-                 CarrierManager.Instance.UpdateWaferIn(chamber, 0, false);
 
-             }
 
-             var wafers = WaferManager.Instance.GetWafers(chamber);
 
-             if (wafers != null && carrier != null)
 
-             {
 
-                 foreach (var wafer in wafers)
 
-                 {
 
-                     if (wafer != null && !wafer.IsEmpty)
 
-                     {
 
-                         CarrierManager.Instance.UpdateWaferIn(chamber, 0, true);
 
-                         break;
 
-                     }
 
-                 }
 
-             }
 
-             return true;
 
-         }
 
-         private bool InvokeCreateWaferFromTo(string arg1, object[] args)
 
-         {
 
-             ModuleName chamber = ModuleHelper.Converter(args[0].ToString());
 
-             ModuleName originChamber = chamber;
 
-             int slotFrom = (int)args[1];
 
-             int slotTo = (int)args[2];
 
-             int originSlot = 1;
 
-             WaferStatus state = WaferStatus.Normal;
 
-             WaferType waferTye = WaferType.None;
 
-             var strs = (string[])args[3];
 
-             Enum.TryParse(strs[0].ToString(), out waferTye);
 
-             originChamber = ModuleHelper.Converter(strs[1].ToString());
 
-             originSlot = int.Parse(strs[2]);
 
-             for (int slot = slotTo - 1; slot >= slotFrom - 1; slot--)
 
-             {
 
-                 if (WaferManager.Instance.IsWaferSlotLocationValid(chamber, slot))
 
-                 {
 
-                     if (WaferManager.Instance.CheckHasWafer(chamber, slot))
 
-                     {
 
-                         EV.PostInfoLog("System", string.Format("{0} slot {1} already has wafer.create wafer is not valid", chamber, slot + 1));
 
-                     }
 
-                     else
 
-                     {
 
-                         if (originChamber == chamber && WaferManager.Instance.CreateWafer(chamber, slot, state, waferTye) != null)
 
-                         {
 
-                             EV.PostMessage(ModuleName.System.ToString(), EventEnum.WaferCreate, chamber.ToString(), slot + 1, state.ToString());
 
-                         }
 
-                         else if (originChamber != chamber && WaferManager.Instance.CreateWafer(chamber, slot, originChamber, originSlot, state, waferTye) != null)
 
-                         {
 
-                             EV.PostMessage(ModuleName.System.ToString(), EventEnum.WaferCreate, chamber.ToString(), slot + 1, state.ToString());
 
-                         }
 
-                     }
 
-                 }
 
-                 else
 
-                 {
 
-                     EV.PostWarningLog("System", string.Format("Invalid position,{0},{1}", chamber.ToString(), slot.ToString()));
 
-                     return false;
 
-                 }
 
-             }
 
-             var carrier = CarrierManager.Instance.GetCarrier(chamber);
 
-             if (carrier != null)
 
-             {
 
-                 CarrierManager.Instance.UpdateWaferIn(chamber, 0, true);
 
-             }
 
-             return true;
 
-         }
 
-         private bool InvokeCreateWafer(string arg1, object[] args)
 
-         {
 
-             ModuleName chamber = ModuleHelper.Converter(args[0].ToString());
 
-             ModuleName originChamber = chamber;
 
-             int slot = (int)args[1];
 
-             int originSlot = 1;
 
-             WaferStatus state = WaferStatus.Normal;
 
-             WaferType waferTye = WaferType.None;
 
-             if (args.Length > 2)
 
-                 Enum.TryParse(args[2].ToString(), out waferTye);
 
-             if (args.Length > 3)
 
-                 originChamber = ModuleHelper.Converter(args[3].ToString());
 
-             if (args.Length > 4)
 
-                 originSlot = (int)args[4];
 
-             if (ModuleHelper.IsLoadPort(chamber))
 
-             {
 
-                 //var lp = Modules[chamber] as LoadPortModule;
 
-                 //if (lp.LPDevice.CassetteState != LoadportCassetteState.Normal)
 
-                 //{
 
-                 //    EV.PostWarningLog("System", $"Can not create wafer at {chamber}.{slot + 1}, Cassette not placed.");
 
-                 //    return false;
 
-                 //}
 
-             }
 
-             if (WaferManager.Instance.IsWaferSlotLocationValid(chamber, slot))
 
-             {
 
-                 if (WaferManager.Instance.CheckHasWafer(chamber, slot))
 
-                 {
 
-                     EV.PostInfoLog("System", string.Format("{0} slot {1} already has wafer.create wafer is not valid", chamber, slot + 1));
 
-                 }
 
-                 else
 
-                 {
 
-                     if (originChamber == chamber && WaferManager.Instance.CreateWafer(chamber, slot, state, waferTye) != null)
 
-                     {
 
-                         EV.PostMessage(ModuleName.System.ToString(), EventEnum.WaferCreate, chamber.ToString(), slot + 1, state.ToString());
 
-                     }
 
-                     else if (originChamber != chamber && WaferManager.Instance.CreateWafer(chamber, slot, originChamber, originSlot, state, waferTye) != null)
 
-                     {
 
-                         EV.PostMessage(ModuleName.System.ToString(), EventEnum.WaferCreate, chamber.ToString(), slot + 1, state.ToString());
 
-                     }
 
-                 }
 
-             }
 
-             else
 
-             {
 
-                 EV.PostWarningLog("System", string.Format("Invalid position,{0},{1}", chamber.ToString(), slot.ToString()));
 
-                 return false;
 
-             }
 
-             var carrier = CarrierManager.Instance.GetCarrier(chamber);
 
-             if (carrier != null)
 
-             {
 
-                 CarrierManager.Instance.UpdateWaferIn(chamber, 0, true);
 
-             }
 
-             return true;
 
-         }
 
-         private bool InvokeUpdateWafer(string arg1, params object[] args)
 
-         {
 
-             if (args == null || args.Length == 0) return false;
 
-             ModuleName chamber = ModuleHelper.Converter(args[0].ToString());
 
-             var carrier = CarrierManager.Instance.GetCarrier(chamber);
 
-             if (carrier == null || carrier.IsEmpty)
 
-             {
 
-                 EV.PostInfoLog(Module, $"{chamber} update wafer fail for carrier not exist.");
 
-                 return false;
 
-             }
 
-             if (args.Length > 3 && !carrier.CarrierType.ToString().Equals(CarrierType.None.ToString()) && !carrier.CarrierType.ToString().Equals(args[2].ToString()))
 
-             {
 
-                 EV.PostInfoLog(Module, $"{chamber} type mismatch!");
 
-                 return false;
 
-             }
 
-             int slot=0;
 
-             if (args.Length > 1)
 
-             {
 
-                 int.TryParse(args[1].ToString(), out slot);
 
-                 slot = slot - 1;
 
-             }
 
-             WaferType waferTye = WaferType.None;
 
-             if (args.Length > 2)
 
-             {
 
-                 Enum.TryParse(args[2].ToString(), out waferTye);
 
-             }
 
-             float useCount = 0, useThick = 0, UseTime = 0;
 
-             if (args.Length > 3)
 
-             {
 
-                 float.TryParse(args[3].ToString(), out useCount);
 
-             }
 
-             if (args.Length > 4)
 
-             {
 
-                 float.TryParse(args[4].ToString(), out useThick);
 
-             }
 
-             if (args.Length > 5)
 
-             {
 
-                 float.TryParse(args[5].ToString(), out UseTime);
 
-             }
 
-             if (WaferManager.Instance.IsWaferSlotLocationValid(chamber, slot))
 
-             {
 
-                 if (WaferManager.Instance.CheckHasWafer(chamber, slot))
 
-                 {
 
-                     WaferManager.Instance.UpdateWaferStatistics(chamber, slot, useCount, useThick, UseTime);
 
-                 }
 
-             }
 
-             if (carrier != null)
 
-             {
 
-                 CarrierManager.Instance.UpdateWaferIn(chamber, 0, true);
 
-             }
 
-             return true;
 
-         }
 
-         private bool InvokeCreateCassetteWafer(string arg1, object[] args)
 
-         {
 
-             ModuleName chamber = ModuleHelper.Converter(args[0].ToString());
 
-             var carrier = CarrierManager.Instance.GetCarrier(chamber);
 
-             if (carrier == null || carrier.IsEmpty)
 
-             {
 
-                 EV.PostInfoLog(Module, $"{chamber} create wafer fail for carrier not exist.");
 
-                 return false;
 
-             }
 
-             if (args.Length > 3 && !carrier.CarrierType.ToString().Equals(CarrierType.None.ToString()) && !carrier.CarrierType.ToString().Equals(args[3].ToString()))
 
-             {
 
-                 EV.PostInfoLog(Module, $"{chamber} type mismatch!");
 
-                 return false;
 
-             }
 
-             int slotFrom = (int)args[1];
 
-             int slotTo = (int)args[2];
 
-             WaferStatus state = WaferStatus.Normal;
 
-             WaferType waferTye = WaferType.None;
 
-             if (args.Length > 3)
 
-                 Enum.TryParse(args[3].ToString(), out waferTye);
 
-             for (int slot = slotTo - 1; slot >= slotFrom - 1; slot--)
 
-             {
 
-                 if (WaferManager.Instance.IsWaferSlotLocationValid(chamber, slot))
 
-                 {
 
-                     if (WaferManager.Instance.CheckHasWafer(chamber, slot))
 
-                     {
 
-                         EV.PostInfoLog(Module, string.Format("{0} slot {1} already has wafer.", chamber, slot + 1));
 
-                         continue;
 
-                     }
 
-                     else if (WaferManager.Instance.CreateWafer(chamber, slot, state, waferTye) == null)
 
-                     {
 
-                         CreateWaferFailedWarning.Set(string.Format($"Create slot {slot + 1} wafer failed."));
 
-                         return false;
 
-                     }
 
-                 }
 
-                 else
 
-                 {
 
-                     CreateWaferFailedWarning.Set(string.Format("Invalid slot,{0},{1}", chamber.ToString(), (slot + 1).ToString()));
 
-                     return false;
 
-                 }
 
-             }
 
-             if (carrier != null)
 
-             {
 
-                 CarrierManager.Instance.UpdateWaferIn(chamber, 0, true);
 
-             }
 
-             EV.PostInfoLog(Module, $"Create wafer from {slotFrom} to {slotTo} successed.");
 
-             return true;
 
-         }
 
-         private bool InvokeDeleteCassetteWafer(string arg1, object[] args)
 
-         {
 
-             ModuleName chamber = ModuleHelper.Converter(args[0].ToString());
 
-             int slotFrom = (int)args[1];
 
-             int slotTo = (int)args[2];
 
-             if (WaferManager.Instance.IsWaferSlotLocationValid(chamber, slotFrom - 1) && WaferManager.Instance.IsWaferSlotLocationValid(chamber, slotTo - 1))
 
-             {
 
-                 WaferManager.Instance.DeleteWafer(chamber, slotFrom - 1, slotTo - slotFrom + 1);
 
-             }
 
-             else
 
-             {
 
-                 DeleteWaferFailedWarning.Set(string.Format($"Invalid slot,{chamber} slot from {slotFrom}, slot to {slotTo}"));
 
-                 return false;
 
-             }
 
-             var carrier = CarrierManager.Instance.GetCarrier(chamber);
 
-             if (carrier != null)
 
-             {
 
-                 CarrierManager.Instance.UpdateWaferIn(chamber, 0, false);
 
-             }
 
-             var wafers = WaferManager.Instance.GetWafers(chamber);
 
-             if (wafers != null && carrier != null)
 
-             {
 
-                 foreach (var wafer in wafers)
 
-                 {
 
-                     if (wafer != null && !wafer.IsEmpty)
 
-                     {
 
-                         CarrierManager.Instance.UpdateWaferIn(chamber, 0, true);
 
-                         break;
 
-                     }
 
-                 }
 
-             }
 
-             EV.PostInfoLog(Module, $"Delete wafer from {slotFrom} to {slotTo} successed.");
 
-             return true;
 
-         }
 
-         private CarrierType GetStockerType(string name)
 
-         {
 
-             var result = CarrierType.SD;
 
-             var scName = name.Contains("LP") ? $"{name}Type" : $"{name}WaferType";
 
-             string configType = SC.GetStringValue($"System.Stocker.{scName}");
 
-             if (string.IsNullOrEmpty(configType))
 
-             {
 
-                 return result;
 
-             }
 
-             result = configType.StartsWith(CarrierType.P.ToString()) ? CarrierType.P : (CarrierType)Enum.Parse(typeof(CarrierType), configType);
 
-             return result;
 
-         }
 
-         public bool InvokeCreateCarrier(string arg1, object[] args)
 
-         {
 
-             ModuleName chamber = ModuleHelper.Converter(args[0].ToString());
 
-             int slot = (int)args[1];
 
-             CarrierType carrierTye = GetStockerType(chamber.ToString());
 
-             if (args.Length > 2)
 
-             {
 
-                 var inputType = args[2].ToString();
 
-                 if (!carrierTye.ToString().Equals(CarrierType.None.ToString()) && !carrierTye.ToString().Equals(inputType))
 
-                 {
 
-                     EV.PostInfoLog(Module, $"{chamber} type mismatch!");
 
-                     return false;
 
-                 }
 
-                 Enum.TryParse(args[2].ToString(), out carrierTye);
 
-             }
 
-             if (CarrierManager.Instance.HasCarrier(args[0].ToString(), slot))
 
-             {
 
-                 EV.PostInfoLog("System", $"{chamber} already has carrier.create is not valid");
 
-             }
 
-             else
 
-             {
 
-                 CarrierManager.Instance.CreateCarrier(args[0].ToString(), carrierTye, args[0].ToString());
 
-                 EV.PostInfoLog("System", $"{chamber} create carrier");
 
-             }
 
-             var wafers = WaferManager.Instance.GetWafers(chamber);
 
-             if (wafers != null)
 
-             {
 
-                 foreach (var wafer in wafers)
 
-                 {
 
-                     if (wafer != null && !wafer.IsEmpty)
 
-                     {
 
-                         CarrierManager.Instance.UpdateWaferIn(chamber, 0, true);
 
-                         break;
 
-                     }
 
-                 }
 
-             }
 
-             return true;
 
-         }
 
-         private bool InvokeDeleteCarrier(string arg1, object[] args)
 
-         {
 
-             ModuleName chamber = ModuleHelper.Converter(args[0].ToString());
 
-             if (CarrierManager.Instance.HasCarrier(chamber.ToString()))
 
-             {
 
-                 CarrierManager.Instance.DeleteCarrier(chamber.ToString());
 
-                 EV.PostInfoLog("System", $"Carrier deleted from {chamber}");
 
-                 var wafers = WaferManager.Instance.GetWafers(chamber);
 
-                 for (int i = 0; i < wafers.Length; i++)
 
-                 {
 
-                     if (!wafers[i].IsEmpty)
 
-                         WaferManager.Instance.DeleteWafer(chamber, i);
 
-                 }
 
-             }
 
-             else
 
-             {
 
-                 EV.PostInfoLog("System", string.Format("No carrier at {0}, delete not valid", chamber.ToString()));
 
-             }
 
-             return true;
 
-         }
 
-         private bool InvokeSetLotID(string arg1, object[] args)
 
-         {
 
-             ModuleName chamber = ModuleHelper.Converter(args[0].ToString());
 
-             List<string> lotIdLst = new List<string>();
 
-             foreach (var module in Modules.Keys)
 
-             {
 
-                 if ((Modules[module] as StockerModule) == null)
 
-                     continue;
 
-                 if (CarrierManager.Instance.HasCarrier(module.ToString()))
 
-                 {
 
-                     lotIdLst.Add(CarrierManager.Instance.GetCarrier(module.ToString()).CarrierId);
 
-                 }
 
-             }
 
-             if (lotIdLst.Any(x => x == args[1].ToString()))
 
-             {
 
-                 SetLotIDFailedWarning.Set($"Carrier ID={args[1]} of {chamber} is already exist");
 
-                 return false;
 
-             }
 
-             if (CarrierManager.Instance.HasCarrier(chamber.ToString()))
 
-             {
 
-                 CarrierManager.Instance.UpdateCarrierId(chamber.ToString(), args[1].ToString());
 
-                 EV.PostInfoLog("System", $"Carrier {chamber} update carrier ID {args[1]}");
 
-             }
 
-             else
 
-             {
 
-                 EV.PostInfoLog("System", string.Format("No carrier at {0}, update carrier ID not valid", chamber.ToString()));
 
-             }
 
-             return true;
 
-         }
 
-         private bool InvokeShutDown(string arg1, object[] arg2)
 
-         {
 
-             if (IsAlarm || IsIdle || IsInit)
 
-             {
 
-                 EV.PostWarningLog(Module, $"System start shut down");
 
-                 EV.PostKickoutMessage("ShutDown");
 
-                 RtApplication.Instance.Terminate();
 
-                 return true;
 
-             }
 
-             EV.PostWarningLog(Module, $"System in {StringFsmStatus} mode, can not shut down");
 
-             return false;
 
-         }
 
-         private void OnModuleError(string module)
 
-         {
 
-             if (FsmState == (int)RtState.AutoRunning)
 
-             {
 
-                 ModuleName mod = ModuleHelper.Converter(module);
 
-                 PostMsg(MSG.ModuleError, module);
 
-             }
 
-         }
 
-         public override void Monitor()
 
-         {
 
-             base.Monitor();
 
-         }
 
-         private bool CheckPWaferBatch(ModuleName module, string batch)
 
-         {
 
-             string stockerWaferType = batch == "A" ? "P1" : "P2";
 
-             return SC.GetStringValue($"System.Stocker.{module}WaferType") == stockerWaferType;
 
-         }
 
-         private bool CheckMWaferBatch(ModuleName module, string batch)
 
-         {
 
-             string stockerWaferType = batch == "A" ? "M1" : "M2";
 
-             return SC.GetStringValue($"System.Stocker.{module}WaferType") == stockerWaferType;
 
-         }
 
-         private bool CheckJobPause()
 
-         {
 
-             return _pauseTrig.R;
 
-         }
 
-         private bool CheckToPostJobMessage(int msg, params object[] args)
 
-         {
 
-             _cycledCount = 0;
 
-             //只有LoadProcessUnload和ChargeProcessDischarge有cycle模式
 
-             if (SC.GetValue<bool>("System.IsCycleMode") && (msg == (int)MSG.LoadProcessUnload || msg == (int)MSG.ChargeProcessDischarge))
 
-             {
 
-                 lock (_locker)
 
-                 {
 
-                     _jobMSG = msg;
 
-                     _jobParas = args;
 
-                 }
 
-             }
 
-             else
 
-             {
 
-                 lock (_locker)
 
-                 {
 
-                     _jobMSG = 0;
 
-                     _jobParas = null;
 
-                 }
 
-             }
 
-             return CheckToPostMessage(msg, args);
 
-         }
 
-         private bool OnCycleTimer()
 
-         {
 
-             if (!SC.GetValue<bool>("System.IsSimulatorMode"))
 
-             {
 
-                 //_plcConnectTrig.CLK = !(IoProviderManager.Instance.Providers[0] as AdsPlcAdapter).IsPlcConnected;
 
-                 //if (_plcConnectTrig.R)
 
-                 //{
 
-                 //    PLCDisconnectAlarm.Set();
 
-                 //}
 
-                 //if (_plcConnectTrig.T)
 
-                 //{
 
-                 //    EV.ClearAlarmEvent(PLCDisconnectAlarm.Id);
 
-                 //    PLCDisconnectAlarm.Reset();
 
-                 //    PLCConnectRecoveryWarning.Set();
 
-                 //}
 
-             }
 
-             _cassetteRobotModule.Monitor();
 
-             _waferRobotModule.Monitor();
 
-             _lp1Module.Monitor();
 
-             _lp2Module.Monitor();
 
-             _lp3Module.Monitor();
 
-             _lp4Module.Monitor();
 
-             _fims1Module.Monitor();
 
-             _fims2Module.Monitor();
 
-             _boatModule.Monitor();
 
-             foreach (var module in Modules.Keys)
 
-             {
 
-                 if (!(Modules[module] is StockerModule))
 
-                     continue;
 
-                 Modules[module].Monitor();
 
-             }
 
-             return true;
 
-         }
 
-         public List<ProcessJobInfo> GetProcessJobInfo()
 
-         {
 
-             return _auto.LstProcessJobs;
 
-         }
 
-         public List<Tuple<string, string, List<int>>> GetProcessingStockers()
 
-         {
 
-             return _auto.GetProcessingStockers();
 
-         }
 
-         public List<Tuple<string, string, List<int>>> GetAllPJStockers()
 
-         {
 
-             return _auto.GetAllPJStockers();
 
-         }
 
-         public List<CarrierPara> GetTransferJobStockers()
 
-         {
 
-             return _transferJob.GetTransferJobStockers();
 
-         }
 
-         public void ResetTask(ModuleName module)
 
-         {
 
-             _auto.ResetTask(module);
 
-             _transferJob.ResetTask(module);
 
-             (_returnAll as ReturnAllWafer).ResetTask(module);
 
-         }
 
-         private void CoolingSkip()
 
-         {
 
-             _auto.CoolingSkip();
 
-         }
 
-         public void SetVisibility(CarrierInfo carrierInfo, bool setValue, string moduleName = null)
 
-         {
 
-             if (carrierInfo == null)
 
-             {
 
-                 return;
 
-             }
 
-             carrierInfo.UIExitFoup = setValue;
 
-             carrierInfo.UICarrierColorVisibility = setValue;
 
-             carrierInfo.UICarrierStatusVisibility = setValue;
 
-             carrierInfo.UICarrierTypeVisibility = setValue;
 
-             carrierInfo.UICarrierWaferCountVisibility = setValue;
 
-         }
 
-         public void SetUIWaferCount(CarrierInfo carrierInfo, ModuleName name, out WaferInfo[] wafers)
 
-         {
 
-             wafers = WaferManager.Instance.GetWafers(name);
 
-             if (carrierInfo == null)
 
-             {
 
-                 return;
 
-             }
 
-             var count = wafers == null ? 0 : wafers.Count(a => !a.IsEmpty);
 
-             carrierInfo.UICarrierWaferCount = $"({count})";
 
-         }
 
-         public string GetActivePjStatus()
 
-         {
 
-             return _auto.GetFirstPJStatus();
 
-         }
 
-     }
 
- }
 
 
  |