EquipmentManager.cs 57 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Threading.Tasks;
  5. using System.Windows.Media;
  6. using Aitex.Core.Common;
  7. using Aitex.Core.RT.DataCenter;
  8. using Aitex.Core.RT.Device;
  9. using Aitex.Core.RT.Event;
  10. using Aitex.Core.RT.Fsm;
  11. using Aitex.Core.RT.Log;
  12. using Aitex.Core.RT.OperationCenter;
  13. using Aitex.Core.RT.RecipeCenter;
  14. using Aitex.Core.RT.Routine;
  15. using Aitex.Core.RT.SCCore;
  16. using Aitex.Core.Util;
  17. using Aitex.Core.Utilities;
  18. using FurnaceRT.Devices;
  19. using FurnaceRT.Equipments.CarrierRobots;
  20. using FurnaceRT.Equipments.FIMSs;
  21. using FurnaceRT.Equipments.Jobs;
  22. using FurnaceRT.Equipments.LPs;
  23. using FurnaceRT.Equipments.PMs;
  24. using FurnaceRT.Equipments.PMs.RecipeExecutions;
  25. using FurnaceRT.Equipments.Schedulers;
  26. using FurnaceRT.Equipments.Stockers;
  27. using FurnaceRT.Equipments.WaferRobots;
  28. using FurnaceRT.Instances;
  29. using MECF.Framework.Common.Alarms;
  30. using MECF.Framework.Common.DataCenter;
  31. using MECF.Framework.Common.Device.Bases;
  32. using MECF.Framework.Common.Equipment;
  33. using MECF.Framework.Common.Jobs;
  34. using MECF.Framework.Common.SubstrateTrackings;
  35. using MECF.Framework.RT.Core.Applications;
  36. using MECF.Framework.RT.Core.IoProviders;
  37. using AutoTransfer = FurnaceRT.Equipments.Jobs.AutoTransfer;
  38. using ReturnAllWafer = FurnaceRT.Equipments.Jobs.ReturnAllWafer;
  39. namespace FurnaceRT.Equipments.Systems
  40. {
  41. public enum RtState
  42. {
  43. Init,
  44. Initializing,
  45. Idle,
  46. Transfer,
  47. AutoRunning,
  48. AutoIdle,
  49. ReturnAllWafer,
  50. Error,
  51. Loading,
  52. Unloading,
  53. ChargeProcessDischarging,
  54. LoadProcessStockering,
  55. LoadProcessUnloading,
  56. ReturnWafer,
  57. }
  58. public enum TransferJobState
  59. {
  60. Idle,
  61. Error,
  62. Loading,
  63. Unloading,
  64. }
  65. public enum ProcessJobState
  66. {
  67. Idle,
  68. Error,
  69. Charging,
  70. Processing,
  71. Cooling,
  72. Discharging,
  73. }
  74. public partial class EquipmentManager : FsmDevice
  75. {
  76. public enum MSG
  77. {
  78. MoveWafer,
  79. ReturnAllWafer,
  80. Stop,
  81. HOME,
  82. RESET,
  83. ABORT,
  84. ERROR,
  85. ToInit,
  86. SetAutoMode,
  87. SetManualMode,
  88. CreateJob,
  89. PauseJob,
  90. ResumeJob,
  91. StartJob,
  92. StopJob,
  93. AbortJob,
  94. JobDone,
  95. ModuleError,
  96. Map,
  97. Load,
  98. Unload,
  99. ChargeProcessDischarge,
  100. LoadProcessStocker,
  101. LoadProcessUnload,
  102. CancelUnloadingJob,
  103. ToUnloading,
  104. ToLoading,
  105. CreateTransferJob,
  106. AbortTransferJob,
  107. }
  108. public Dictionary<ModuleName, ModuleFsmDevice> Modules { get; set; }
  109. public bool IsAutoMode
  110. {
  111. get
  112. {
  113. return FsmState == (int)RtState.AutoRunning || FsmState == (int)RtState.AutoIdle;
  114. }
  115. }
  116. public bool IsReturnWafer
  117. {
  118. get
  119. {
  120. return FsmState == (int)RtState.ReturnAllWafer || FsmState == (int)RtState.ReturnWafer;
  121. }
  122. }
  123. public bool IsInit
  124. {
  125. get { return FsmState == (int)RtState.Init; }
  126. }
  127. public bool IsIdle
  128. {
  129. get { return FsmState == (int)RtState.Idle; }
  130. }
  131. public bool IsAlarm
  132. {
  133. get { return FsmState == (int)RtState.Error; }
  134. }
  135. public bool IsRunning
  136. {
  137. get
  138. {
  139. return !IsAlarm && !IsIdle && !IsInit && (FsmState != (int)RtState.AutoIdle);
  140. }
  141. }
  142. public bool IsAlarmConditionBuzzerOn { get; set; }
  143. public TransferJobState TransferJobStatus { get; set; } = TransferJobState.Idle;
  144. public ProcessJobState ProcessJobStatus { get; set; } = ProcessJobState.Idle;
  145. private bool _isInited;
  146. protected IRoutine _manualTransfer;
  147. private AutoTransfer _auto = null;
  148. private TransferJob _transferJob = null;
  149. protected IRoutine _homeAll;
  150. protected IRoutine _returnAll;
  151. private string _batchType;
  152. private string _processJob;
  153. private string _processRecipe;
  154. private DeviceTimer _coolTimer = new DeviceTimer();
  155. private int _cycledCount = 0;
  156. private int _jobMSG = 0;
  157. private object[] _jobParas;
  158. private object _locker = new object();
  159. private List<string> _modules;
  160. private PeriodicJob _cycleJob;
  161. private RD_TRIG _plcConnectTrig = new RD_TRIG();
  162. public EquipmentManager()
  163. {
  164. Module = "System";
  165. Name = "System";
  166. Modules = new Dictionary<ModuleName, ModuleFsmDevice>();
  167. _modules = new List<string>() { "System" };
  168. }
  169. public override bool Initialize()
  170. {
  171. InitDevices();
  172. InitModules();
  173. EnumLoop<RtState>.ForEach((item) =>
  174. {
  175. MapState((int)item, item.ToString());
  176. });
  177. EnumLoop<MSG>.ForEach((item) =>
  178. {
  179. MapMessage((int)item, item.ToString());
  180. });
  181. EnableFsm(50, RtState.Init);
  182. BuildTransitionTable();
  183. SubscribeDataVariable();
  184. SubscribeOperation();
  185. InitRoutine();
  186. InitAlarmDefine();
  187. _auto = new AutoTransfer();
  188. _transferJob = new TransferJob();
  189. _cycleJob = new PeriodicJob(100, OnCycleTimer, Name, true);
  190. Singleton<EventManager>.Instance.OnAlarmEvent += Instance_OnAlarmEvent;
  191. return true;
  192. }
  193. protected void BuildModules(params ModuleFsmDevice[] modules)
  194. {
  195. if (modules != null && modules.Length > 0)
  196. {
  197. foreach (var moduleFsmDevice in modules)
  198. {
  199. Modules[ModuleHelper.Converter(moduleFsmDevice.Module)] = moduleFsmDevice;
  200. }
  201. foreach (var modulesKey in Modules.Keys)
  202. {
  203. _modules.Add(modulesKey.ToString());
  204. }
  205. foreach (var modulesValue in Modules.Values)
  206. {
  207. modulesValue.Initialize();
  208. }
  209. }
  210. }
  211. protected virtual void InitRoutine()
  212. {
  213. _homeAll = new HomeAll();
  214. _returnAll = new ReturnAllWafer();
  215. _dbCallback = new SchedulerDBCallback();
  216. }
  217. //private PeriodicJob _job1;
  218. //Stopwatch _sw = new Stopwatch();
  219. //private bool OnJob1()
  220. //{
  221. // _sw.Restart();
  222. // BufferModule buffer = Modules[ModuleName.Buffer] as BufferModule;
  223. // if (!buffer.CheckToPostMessage(BufferModule.MSG.InTransfer))
  224. // {
  225. // System.Diagnostics.Trace.Assert(false)
  226. // System.Diagnostics.Trace.WriteLine("fail to in transfer");
  227. // }
  228. // if (buffer.IsIdle)
  229. // {
  230. // System.Diagnostics.Trace.Assert(false);
  231. // System.Diagnostics.Trace.WriteLine("!!!==========>IsIdle");
  232. // }
  233. // //System.Diagnostics.Trace.Assert(buffer.IsIdle, $"in {buffer.StringFsmStatus}");
  234. // while (buffer.IsIdle)
  235. // {
  236. // Thread.Sleep(5);
  237. // }
  238. // //buffer.NoteTransferStop(ModuleName.EfemRobot, Hand.Blade1, 0, EnumTransferType.Place);
  239. // //Thread.Sleep(15);
  240. // if (!buffer.CheckToPostMessage(BufferModule.MSG.TransferComplete))
  241. // {
  242. // System.Diagnostics.Trace.Assert(false);
  243. // System.Diagnostics.Trace.WriteLine("fail to complete");
  244. // }
  245. // //if (!buffer.IsIdle)
  246. // //{
  247. // // System.Diagnostics.Trace.WriteLine("not idle");
  248. // //}
  249. // System.Diagnostics.Trace.WriteLine($" === {_sw.ElapsedMilliseconds}");
  250. // while (!buffer.IsIdle)
  251. // {
  252. // Thread.Sleep(5);
  253. // }
  254. // return true;
  255. //}
  256. private void BuildTransitionTable()
  257. {
  258. //Init sequence
  259. Transition(RtState.Init, MSG.HOME, FsmStartHome, RtState.Initializing);
  260. Transition(RtState.Idle, MSG.HOME, FsmStartHome, RtState.Initializing);
  261. Transition(RtState.Error, MSG.HOME, FsmStartHome, RtState.Initializing);
  262. Transition(RtState.Error, MSG.ToInit, null, RtState.Init);
  263. Transition(RtState.Initializing, FSM_MSG.TIMER, FsmMonitorHome, RtState.Idle);
  264. Transition(RtState.Initializing, MSG.ERROR, fError, RtState.Error);
  265. Transition(RtState.Initializing, MSG.ABORT, FsmAbort, RtState.Init);
  266. //Reset
  267. AnyStateTransition(MSG.ERROR, fError, RtState.Error);
  268. AnyStateTransition((int)FSM_MSG.ALARM, fError, (int)RtState.Error);
  269. Transition(RtState.Error, MSG.RESET, fStartReset, RtState.Idle);
  270. Transition(RtState.Init, MSG.RESET, fStartReset, RtState.Init);
  271. Transition(RtState.Idle, MSG.RESET, fStartReset, RtState.Idle);
  272. Transition(RtState.AutoIdle, MSG.RESET, fStartReset, RtState.AutoIdle);
  273. Transition(RtState.AutoRunning, MSG.RESET, fStartReset, RtState.AutoRunning);
  274. Transition(RtState.ReturnWafer, MSG.RESET, fStartReset, RtState.ReturnWafer);
  275. //Auto/manual sequence
  276. Transition(RtState.Idle, MSG.SetAutoMode, fStartAutoTransfer, RtState.AutoIdle);
  277. Transition(RtState.AutoRunning, FSM_MSG.TIMER, fAutoTransfer, RtState.AutoRunning);
  278. Transition(RtState.AutoRunning, MSG.ABORT, FsmAbort, RtState.Idle);
  279. Transition(RtState.AutoRunning, MSG.JobDone, null, RtState.AutoIdle);
  280. Transition(RtState.Idle, MSG.CreateJob, FsmCreateJob, RtState.AutoRunning);
  281. Transition(RtState.Idle, MSG.LoadProcessUnload, FsmStartLoadProcessUnload, RtState.AutoRunning);
  282. Transition(RtState.Idle, MSG.LoadProcessStocker, FsmStartLoadProcessStocker, RtState.AutoRunning);
  283. Transition(RtState.AutoRunning, MSG.CreateJob, FsmCreateJob, RtState.AutoRunning);
  284. Transition(RtState.AutoRunning, MSG.StartJob, FsmStartJob, RtState.AutoRunning);
  285. Transition(RtState.AutoRunning, MSG.PauseJob, FsmPauseJob, RtState.AutoRunning);
  286. Transition(RtState.AutoRunning, MSG.ResumeJob, FsmResumeJob, RtState.AutoRunning);
  287. Transition(RtState.AutoRunning, MSG.StopJob, FsmStopJob, RtState.AutoRunning);
  288. Transition(RtState.AutoRunning, MSG.AbortJob, FsmAbortJob, RtState.AutoRunning);
  289. Transition(RtState.AutoRunning, MSG.ModuleError, FsmModuleError, RtState.AutoRunning);
  290. Transition(RtState.AutoRunning, MSG.Load, FsmStartLoad, RtState.AutoRunning);
  291. Transition(RtState.AutoRunning, MSG.Unload, FsmStartUnload, RtState.AutoRunning);
  292. Transition(RtState.Idle, MSG.CreateTransferJob, FsmCreateTransferJob, RtState.AutoRunning);
  293. Transition(RtState.AutoRunning, MSG.CreateTransferJob, FsmCreateTransferJob, RtState.AutoRunning);
  294. Transition(RtState.AutoRunning, MSG.AbortTransferJob, FsmAbortTransferJob, RtState.AutoRunning);
  295. Transition(RtState.AutoRunning, MSG.CancelUnloadingJob, FsmCancelUnloadingJob, RtState.AutoRunning);
  296. Transition(RtState.AutoRunning, MSG.LoadProcessUnload, FsmStartLoadProcessUnload, RtState.AutoRunning);
  297. Transition(RtState.AutoRunning, MSG.LoadProcessStocker, FsmStartLoadProcessStocker, RtState.AutoRunning);
  298. Transition(RtState.AutoIdle, FSM_MSG.TIMER, FsmMonitorAutoIdle, RtState.AutoIdle);
  299. Transition(RtState.AutoIdle, MSG.SetManualMode, FsmStartSetManualMode, RtState.Idle);
  300. Transition(RtState.AutoIdle, MSG.CreateJob, FsmCreateJob, RtState.AutoRunning);
  301. Transition(RtState.AutoIdle, MSG.StartJob, FsmStartJob, RtState.AutoRunning);
  302. Transition(RtState.AutoIdle, MSG.ABORT, FsmAbort, RtState.Idle);
  303. Transition(RtState.AutoIdle, MSG.AbortJob, FsmAbortJob, RtState.AutoIdle);
  304. Transition(RtState.AutoIdle, MSG.Load, FsmStartLoad, RtState.AutoIdle);
  305. Transition(RtState.AutoIdle, MSG.Unload, FsmStartUnload, RtState.AutoIdle);
  306. Transition(RtState.AutoIdle, MSG.CreateTransferJob, FsmCreateTransferJob, RtState.AutoRunning);
  307. Transition(RtState.AutoIdle, MSG.AbortTransferJob, FsmAbortTransferJob, RtState.AutoIdle);
  308. Transition(RtState.AutoIdle, MSG.LoadProcessUnload, FsmStartLoadProcessUnload, RtState.AutoRunning);
  309. Transition(RtState.AutoIdle, MSG.LoadProcessStocker, FsmStartLoadProcessStocker, RtState.AutoRunning);
  310. EnterExitTransition<RtState, FSM_MSG>(RtState.AutoRunning, null, FSM_MSG.NONE, fExitAutoTransfer);
  311. //return all wafer
  312. //Transition(RtState.Idle, MSG.ReturnAllWafer, FsmStartReturnAllWafer, RtState.ReturnAllWafer);
  313. //Transition(RtState.ReturnAllWafer, FSM_MSG.TIMER, FsmMonitorReturnAllWafer, RtState.Idle);
  314. //Transition(RtState.ReturnAllWafer, MSG.ABORT, FsmAbortReturnAllWafer, RtState.Idle);
  315. //Return wafer
  316. Transition(RtState.Idle, MSG.ReturnAllWafer, FsmStartReturnWafer, RtState.ReturnWafer);
  317. Transition(RtState.AutoIdle, MSG.ReturnAllWafer, FsmStartReturnWafer, RtState.ReturnWafer);
  318. Transition(RtState.ReturnWafer, FSM_MSG.TIMER, FsmMonitorReturnWafer, RtState.Idle);
  319. Transition(RtState.ReturnWafer, MSG.ABORT, FsmAbort, RtState.Idle);
  320. //Transfer sequence
  321. Transition(RtState.Idle, MSG.MoveWafer, fStartTransfer, RtState.Transfer);
  322. Transition(RtState.Transfer, FSM_MSG.TIMER, fTransfer, RtState.Idle);
  323. EnterExitTransition<RtState, FSM_MSG>(RtState.Transfer, null, FSM_MSG.NONE, fExitTransfer);
  324. Transition(RtState.Transfer, MSG.ABORT, FsmAbort, RtState.Idle);
  325. }
  326. void SubscribeDataVariable()
  327. {
  328. DATA.Subscribe("Rt.Status", () => StringFsmStatus);
  329. DATA.Subscribe("System.IsInitialized", () => _isInited);
  330. DATA.Subscribe("System.IsIdle", () => IsIdle || IsInit || (FsmState == (int)RtState.AutoIdle));
  331. DATA.Subscribe("System.IsAlarm", () => IsAlarm);
  332. DATA.Subscribe("System.IsBusy", () => IsRunning);
  333. DATA.Subscribe("System.IsAutoRunning", () => IsRunning);
  334. DATA.Subscribe("System.IsAlarmConditionBuzzerOn", () => IsAlarmConditionBuzzerOn);
  335. DATA.Subscribe("System.Modules", () => _modules);
  336. }
  337. void SubscribeOperation()
  338. {
  339. OP.Subscribe("CreateWafer", InvokeCreateWafer);
  340. OP.Subscribe("CreateWaferFromTo", InvokeCreateWaferFromTo);
  341. OP.Subscribe("DeleteWafer", InvokeDeleteWafer);
  342. OP.Subscribe("DeleteWaferFromTo", InvokeDeleteWaferFromTo);
  343. OP.Subscribe("CreateCassetteWafer", InvokeCreateCassetteWafer);
  344. OP.Subscribe("DeleteCassetteWafer", InvokeDeleteCassetteWafer);
  345. OP.Subscribe("System.CreateCarrier", InvokeCreateCarrier);
  346. OP.Subscribe("System.DeleteCarrier", InvokeDeleteCarrier);
  347. OP.Subscribe("System.SetLotID", InvokeSetLotID);
  348. OP.Subscribe("System.DeleteAllWafer", InvokeDeleteAllWafer);
  349. OP.Subscribe("System.DeleteAllCarrier", InvokeDeleteAllCarrier);
  350. OP.Subscribe("ReturnWafer", InvokeReturnWafer);
  351. OP.Subscribe("System.SignalTower.SwitchOffBuzzer", InvokeSwitchOffBuzzer);
  352. OP.Subscribe("System.ReturnAllWafer", (string cmd, object[] args) =>
  353. {
  354. return CheckToPostMessage((int)MSG.ReturnAllWafer);
  355. });
  356. OP.Subscribe("System.MoveWafer", (string cmd, object[] args) =>
  357. {
  358. if (!Enum.TryParse((string)args[0], out ModuleName source))
  359. {
  360. EV.PostWarningLog(Name, $"Parameter source {(string)args[0]} not valid");
  361. return false;
  362. }
  363. if (!Enum.TryParse((string)args[2], out ModuleName destination))
  364. {
  365. EV.PostWarningLog(Name, $"Parameter destination {(string)args[1]} not valid");
  366. return false;
  367. }
  368. if (args.Length > 8)
  369. {
  370. return CheckToPostMessage((int)MSG.MoveWafer, source, (int)args[1], destination, (int)args[3],
  371. (bool)args[4], (int)args[5], (bool)args[6], (int)args[7]);
  372. }
  373. else if (args.Length > 5)
  374. {
  375. return CheckToPostMessage((int)MSG.MoveWafer, source, (int)args[1], destination, (int)args[3], (bool)args[4]);
  376. }
  377. return CheckToPostMessage((int)MSG.MoveWafer, source, (int)args[1], destination, (int)args[3]);
  378. });
  379. OP.Subscribe("System.HomeAll", (string cmd, object[] args) =>
  380. {
  381. return CheckToPostMessage((int)MSG.HOME);
  382. });
  383. OP.Subscribe("System.Abort", (string cmd, object[] args) =>
  384. {
  385. return CheckToPostMessage((int)MSG.ABORT);
  386. });
  387. OP.Subscribe("System.Reset", (string cmd, object[] args) =>
  388. {
  389. return CheckToPostMessage((int)MSG.RESET);
  390. });
  391. OP.Subscribe("System.SetAutoMode", (string cmd, object[] args) =>
  392. {
  393. return CheckToPostMessage((int)MSG.SetAutoMode);
  394. });
  395. OP.Subscribe("System.SetManualMode", (string cmd, object[] args) =>
  396. {
  397. return CheckToPostMessage((int)MSG.SetManualMode);
  398. });
  399. OP.Subscribe("System.CreateJob", (string cmd, object[] args) =>
  400. {
  401. return CheckToPostMessage((int)MSG.CreateJob, args[0]);
  402. });
  403. OP.Subscribe("System.StartJob", (string cmd, object[] args) =>
  404. {
  405. return CheckToPostMessage((int)MSG.StartJob, args[0]);
  406. });
  407. OP.Subscribe("System.PauseJob", (string cmd, object[] args) =>
  408. {
  409. return CheckToPostMessage((int)MSG.PauseJob, args[0]);
  410. });
  411. OP.Subscribe("System.ResumeJob", (string cmd, object[] args) =>
  412. {
  413. return CheckToPostMessage((int)MSG.ResumeJob, args[0]);
  414. });
  415. OP.Subscribe("System.StopJob", (string cmd, object[] args) =>
  416. {
  417. return CheckToPostMessage((int)MSG.StopJob, args[0]);
  418. });
  419. OP.Subscribe("System.AbortJob", (string cmd, object[] args) =>
  420. {
  421. return CheckToPostMessage((int)MSG.AbortJob, args[0]);
  422. });
  423. OP.Subscribe("System.CoolingSkip", (string cmd, object[] args) =>
  424. {
  425. CoolingSkip();
  426. return true;
  427. });
  428. OP.Subscribe("System.ShutDown", InvokeShutDown);
  429. OP.Subscribe($"System.Load", (string cmd, object[] args) => CheckToPostJobMessage((int)MSG.CreateTransferJob, args));
  430. OP.Subscribe($"System.Unload", (string cmd, object[] args) => CheckToPostJobMessage((int)MSG.CreateTransferJob, args));
  431. OP.Subscribe($"System.ChargeProcessDischarge", (string cmd, object[] args) => CheckToPostJobMessage((int)MSG.CreateJob, args));
  432. OP.Subscribe($"System.LoadProcessUnload", (string cmd, object[] args) => CheckToPostJobMessage((int)MSG.LoadProcessUnload, args));
  433. OP.Subscribe($"System.LoadProcessStocker", (string cmd, object[] args) => CheckToPostJobMessage((int)MSG.LoadProcessStocker, args));
  434. OP.Subscribe($"System.MonitorLoad", (string cmd, object[] args) => CheckToPostJobMessage((int)MSG.CreateTransferJob, args));
  435. OP.Subscribe($"System.MonitorUnload", (string cmd, object[] args) => CheckToPostJobMessage((int)MSG.CreateTransferJob, args));
  436. OP.Subscribe($"System.SDLoad", (string cmd, object[] args) => CheckToPostJobMessage((int)MSG.CreateTransferJob, args));
  437. OP.Subscribe($"System.SDUnload", (string cmd, object[] args) => CheckToPostJobMessage((int)MSG.CreateTransferJob, args));
  438. OP.Subscribe($"{Module}.AlarmAction", (string cmd, object[] args) =>
  439. {
  440. Enum.TryParse(args[0].ToString(), out AlarmAction alarmAction);
  441. if (alarmAction == AlarmAction.ClearAll)
  442. {
  443. CheckToPostMessage((int)MSG.RESET);
  444. return true;
  445. }
  446. string eventName = null;
  447. if (args.Length > 1)
  448. eventName = args[1].ToString();
  449. if (eventName != null)
  450. {
  451. EV.ClearAlarmEvent(eventName);
  452. var item = _triggeredAlarmList.FirstOrDefault(x => x.EventEnum == eventName);
  453. if (item != null)
  454. {
  455. item.Reset();
  456. _triggeredAlarmList.Remove(item);
  457. }
  458. if (item != null)
  459. {
  460. switch (alarmAction)
  461. {
  462. case AlarmAction.Retry:
  463. {
  464. CheckToPostMessage((int)item.RetryMessage, item.RetryMessageParas);
  465. }
  466. break;
  467. case AlarmAction.Abort:
  468. {
  469. CheckToPostMessage((int)MSG.ABORT);
  470. }
  471. break;
  472. case AlarmAction.Clear:
  473. {
  474. int alarmCount = 0;
  475. var alarms = EV.GetAlarmEvent();
  476. foreach (var alarm in alarms)
  477. {
  478. if (alarm.Level == EventLevel.Alarm && alarm.Source == Name)
  479. alarmCount++;
  480. }
  481. if (alarmCount == 0)
  482. CheckToPostMessage((int)MSG.RESET);
  483. }
  484. break;
  485. case AlarmAction.Continue:
  486. {
  487. int alarmCount = 0;
  488. var alarms = EV.GetAlarmEvent();
  489. foreach (var alarm in alarms)
  490. {
  491. if (alarm.Level == EventLevel.Alarm && alarm.Source == Name)
  492. alarmCount++;
  493. }
  494. if (alarmCount == 0)
  495. CheckToPostMessage((int)MSG.RESET);
  496. }
  497. break;
  498. }
  499. }
  500. }
  501. return true;
  502. });
  503. }
  504. private void Instance_OnAlarmEvent(EventItem item)
  505. {
  506. if (item != null && item.Level == EventLevel.Alarm && (item.Source == Name || item.Source == Module))
  507. {
  508. DEVICE.GetDevice<SignalTowerBase>("System.SignalTower")?.Reset();
  509. LOG.Write($"{item.Source} {item.EventEnum} {item.Description}\n");
  510. PostMsg(MSG.ERROR);
  511. }
  512. }
  513. #region Init
  514. private bool FsmStartHome(object[] objs)
  515. {
  516. _isInited = false;
  517. return _homeAll.Start() == Result.RUN;
  518. }
  519. private bool FsmMonitorHome(object[] objs)
  520. {
  521. Result ret = _homeAll.Monitor();
  522. if (ret == Result.DONE)
  523. {
  524. _isInited = true;
  525. return true;
  526. }
  527. if (ret == Result.FAIL)
  528. {
  529. PostMsg(MSG.ERROR);
  530. }
  531. return false;
  532. }
  533. private bool fError(object[] objs)
  534. {
  535. if (FsmState == (int)RtState.Transfer)
  536. {
  537. }
  538. return true;
  539. }
  540. #endregion
  541. #region job
  542. private bool FsmStartLoad(object[] param)
  543. {
  544. if (_transferJob.CreateJob(param) != Result.RUN)
  545. {
  546. return false;
  547. }
  548. return true;
  549. }
  550. private bool FsmStartUnload(object[] param)
  551. {
  552. if (_transferJob.CreateJob(param) != Result.RUN)
  553. {
  554. return false;
  555. }
  556. return true;
  557. }
  558. private bool FsmStartLoadProcessStocker(object[] param)
  559. {
  560. var paramDic = (Dictionary<string, object>)param[0];
  561. if (paramDic == null)
  562. {
  563. LoadProcessStockerStartFailedWarning.Set("Parameter not valid");
  564. return false;
  565. }
  566. paramDic["TransferType"] = "Loading";
  567. param[0] = paramDic;
  568. if (_transferJob.CreateJob(param) != Result.RUN)
  569. {
  570. return false;
  571. }
  572. if (_auto.CreateJob(param) != Result.RUN)
  573. {
  574. return false;
  575. }
  576. return true;
  577. }
  578. private bool FsmStartLoadProcessUnload(object[] param)
  579. {
  580. var paramDic = (Dictionary<string, object>)param[0];
  581. if (paramDic == null)
  582. {
  583. LoadProcessUnloadStartFailedWarning.Set("Parameter not valid");
  584. return false;
  585. }
  586. paramDic["TransferType"] = "Loading";
  587. param[0] = paramDic;
  588. if (_transferJob.CreateJob(param) != Result.RUN)
  589. {
  590. return false;
  591. }
  592. if (_auto.CreateJob(param) != Result.RUN)
  593. {
  594. return false;
  595. }
  596. paramDic["TransferType"] = "Unloading";
  597. param[0] = paramDic;
  598. if (_transferJob.CreateJob(param) != Result.RUN)
  599. {
  600. return false;
  601. }
  602. return true;
  603. }
  604. #endregion
  605. #region AutoTransfer
  606. private bool FsmMonitorAutoIdle(object[] param)
  607. {
  608. Result ret = _transferJob.Monitor();
  609. _auto.Monitor();
  610. if (!_auto.CheckAllJobDone() || !_transferJob.CheckAllJobDone())
  611. {
  612. return false;
  613. }
  614. return ret == Result.DONE;
  615. }
  616. private bool FsmStartSetManualMode(object[] objs)
  617. {
  618. if (_auto.HasJobRunning)
  619. {
  620. EV.PostWarningLog("System", "Can not change to manual mode, abort running job first");
  621. return false;
  622. }
  623. return true;
  624. }
  625. private bool fStartAutoTransfer(object[] objs)
  626. {
  627. Result ret = _auto.Start(objs);
  628. return ret == Result.RUN;
  629. }
  630. private bool fAutoTransfer(object[] objs)
  631. {
  632. Result ret = _transferJob.Monitor();
  633. _auto.Monitor();
  634. if (_auto.CheckAllJobDone() && _transferJob.CheckAllJobDone())
  635. {
  636. if (!CheckToPostMessage((int)MSG.JobDone))
  637. return false;
  638. }
  639. return ret == Result.DONE;
  640. }
  641. private bool fExitAutoTransfer(object[] objs)
  642. {
  643. _auto.Clear();
  644. _transferJob.Clear();
  645. return true;
  646. }
  647. private bool fAbortAutoTransfer(object[] objs)
  648. {
  649. _auto.Clear();
  650. _transferJob.Clear();
  651. return true;
  652. }
  653. #endregion
  654. #region return all wafer
  655. private bool FsmAbortReturnAllWafer(object[] param)
  656. {
  657. return true;
  658. }
  659. private bool FsmMonitorReturnAllWafer(object[] param)
  660. {
  661. return _returnAll.Monitor() == Result.DONE;
  662. }
  663. private bool FsmStartReturnAllWafer(object[] param)
  664. {
  665. return _returnAll.Start() == Result.RUN;
  666. }
  667. #endregion
  668. #region Transfer
  669. private bool fStartTransfer(object[] objs)
  670. {
  671. Result ret = _manualTransfer.Start(objs);
  672. if (ret == Result.FAIL || ret == Result.DONE)
  673. return false;
  674. return ret == Result.RUN;
  675. }
  676. private bool fTransfer(object[] objs)
  677. {
  678. Result ret = _manualTransfer.Monitor();
  679. if (ret == Result.FAIL)
  680. {
  681. PostMsg(MSG.ERROR);
  682. return false;
  683. }
  684. return ret == Result.DONE;
  685. }
  686. private bool fExitTransfer(object[] objs)
  687. {
  688. return true;
  689. }
  690. private bool fAbortTransfer(object[] objs)
  691. {
  692. return true;
  693. }
  694. #endregion
  695. #region reset
  696. private bool fStartReset(object[] objs)
  697. {
  698. EV.ClearAlarmEvent();
  699. Singleton<DeviceEntity>.Instance.PostMsg(DeviceEntity.MSG.RESET);
  700. IoProviderManager.Instance.Reset();
  701. foreach (var modulesValue in Modules.Values)
  702. {
  703. modulesValue.Reset();
  704. }
  705. _triggeredAlarmList.ForEach(x => x.Reset());
  706. _triggeredAlarmList.Clear();
  707. if (FsmState == (int)RtState.Error)
  708. {
  709. if (!_isInited)
  710. {
  711. PostMsg(MSG.ToInit);
  712. return false;
  713. }
  714. return true;
  715. }
  716. return false;
  717. }
  718. #endregion
  719. private bool FsmCreateJob(object[] param)
  720. {
  721. if (FsmState != (int)RtState.AutoRunning && CarrierManager.Instance.CheckHasCarrier(ModuleName.CarrierRobot, 0))
  722. {
  723. EV.PostWarningLog("System", $"FOUP robot already has a FOUP, create job failed");
  724. return false;
  725. }
  726. _auto.CreateJob((Dictionary<string, object>)param[0]);
  727. return true;
  728. }
  729. private bool FsmAbortJob(object[] param)
  730. {
  731. _auto.AbortJob((string)param[0]);
  732. return true;
  733. }
  734. private bool FsmStopJob(object[] param)
  735. {
  736. _auto.StopJob((string)param[0]);
  737. //CheckToPostMessage((int)MSG.StopJob);//
  738. return true;
  739. }
  740. private bool FsmResumeJob(object[] param)
  741. {
  742. _auto.ResumeJob((string)param[0]);
  743. return true;
  744. }
  745. private bool FsmPauseJob(object[] param)
  746. {
  747. _auto.PauseJob((string)param[0]);
  748. return true;
  749. }
  750. private bool FsmStartJob(object[] param)
  751. {
  752. return _auto.StartJob((string)param[0]);
  753. }
  754. private bool FsmCreateTransferJob(object[] param)
  755. {
  756. if(FsmState != (int)RtState.AutoRunning && CarrierManager.Instance.CheckHasCarrier(ModuleName.CarrierRobot, 0))
  757. {
  758. EV.PostWarningLog("System", $"FOUP robot already has a FOUP, create job failed");
  759. return false;
  760. }
  761. _transferJob.CreateJob(param);
  762. return true;
  763. }
  764. private bool FsmAbortTransferJob(object[] param)
  765. {
  766. _transferJob.AbortJob((string)param[0]);
  767. return true;
  768. }
  769. private bool FsmCancelUnloadingJob(object[] param)
  770. {
  771. _transferJob.CancelUnloadingJob((string)param[0], (string)param[1]);
  772. return true;
  773. }
  774. private bool FsmAbort(object[] param)
  775. {
  776. if (FsmState == (int)RtState.Transfer)
  777. {
  778. // _manualTransfer.Clear();
  779. }
  780. if (FsmState == (int)RtState.ChargeProcessDischarging || FsmState == (int)RtState.LoadProcessStockering || FsmState == (int)RtState.LoadProcessUnloading)
  781. {
  782. _auto.PjUpdated();
  783. _auto.PjFinished("Job Abort");
  784. }
  785. if (FsmState == (int)RtState.AutoRunning)
  786. {
  787. _auto.Clear();
  788. }
  789. if (FsmState == (int)RtState.Initializing)
  790. {
  791. _homeAll.Abort();
  792. }
  793. return true;
  794. }
  795. private bool FsmModuleError(object[] param)
  796. {
  797. //_auto.ModuleError((string)param[0]);
  798. return true;
  799. }
  800. private bool FsmStartReturnWafer(object[] objs)
  801. {
  802. Result ret = _returnAll.Start();
  803. if (ret == Result.FAIL)
  804. {
  805. PostMsg(MSG.ERROR);
  806. return false;
  807. }
  808. return ret == Result.RUN;
  809. }
  810. private bool FsmMonitorReturnWafer(object[] objs)
  811. {
  812. Result ret = _returnAll.Monitor();
  813. if (ret == Result.FAIL)
  814. {
  815. PostMsg(MSG.ERROR);
  816. return false;
  817. }
  818. if (ret == Result.DONE)
  819. {
  820. _batchType = "";
  821. _processJob = "";
  822. _processRecipe = "";
  823. (Modules[ModuleName.CarrierRobot] as CarrierRobotModule).Home(out _);
  824. (Modules[ModuleName.WaferRobot] as WaferRobotModule).Home(out _);
  825. }
  826. return ret == Result.DONE;
  827. }
  828. private bool InvokeSwitchOffBuzzer(string arg1, object[] args)
  829. {
  830. DEVICE.GetDevice<SignalTowerBase>("System.SignalTower")?.SwitchOffBuzzer(true);
  831. IsAlarmConditionBuzzerOn = false;
  832. return true;
  833. }
  834. private bool InvokeReturnWafer(string arg1, object[] args)
  835. {
  836. ModuleName target = ModuleHelper.Converter(args[0].ToString());
  837. int slot = (int)args[1];
  838. if (ModuleHelper.IsLoadPort(target))
  839. {
  840. EV.PostInfoLog("System", string.Format("Wafer already at LoadPort {0} {1}, return operation is not valid", target.ToString(), slot + 1));
  841. return false;
  842. }
  843. if (!WaferManager.Instance.IsWaferSlotLocationValid(target, slot))
  844. {
  845. EV.PostWarningLog("System", string.Format("Invalid position,{0},{1}", target.ToString(), slot.ToString()));
  846. return false;
  847. }
  848. WaferInfo wafer = WaferManager.Instance.GetWafer(target, slot);
  849. if (wafer.IsEmpty)
  850. {
  851. EV.PostInfoLog("System", string.Format("No wafer at {0} {1}, return operation is not valid", target.ToString(), slot + 1));
  852. return false;
  853. }
  854. return CheckToPostMessage((int)MSG.MoveWafer,
  855. target, slot,
  856. (ModuleName)wafer.OriginStation, wafer.OriginSlot,
  857. false, 0, false, 0);
  858. }
  859. private bool InvokeDeleteAllWafer(string arg1, object[] args)
  860. {
  861. foreach (var item in Modules.Values)
  862. {
  863. if ((item as PMModule) != null || (item as WaferRobotModule) != null)
  864. {
  865. var wafers = WaferManager.Instance.GetWafers(ModuleHelper.Converter(item.Module));
  866. for (int i = 0; i < wafers.Length; i++)
  867. {
  868. if (!wafers[i].IsEmpty)
  869. WaferManager.Instance.DeleteWafer(ModuleHelper.Converter(item.Module), i);
  870. }
  871. }
  872. }
  873. return true;
  874. }
  875. private bool InvokeDeleteAllCarrier(string arg1, object[] args)
  876. {
  877. foreach (var item in Modules.Values)
  878. {
  879. if ((item as LoadPortModule) != null || (item as StockerModule) != null || (item as FIMSModule) != null || (item as CarrierRobotModule) != null)
  880. {
  881. if (CarrierManager.Instance.HasCarrier(item.Module.ToString()))
  882. {
  883. CarrierManager.Instance.DeleteCarrier(item.Module.ToString());
  884. var wafers = WaferManager.Instance.GetWafers(ModuleHelper.Converter(item.Module));
  885. for (int i = 0; i < wafers.Length; i++)
  886. {
  887. if (!wafers[i].IsEmpty)
  888. WaferManager.Instance.DeleteWafer(ModuleHelper.Converter(item.Module), i);
  889. }
  890. }
  891. }
  892. }
  893. return true;
  894. }
  895. private bool InvokeDeleteWaferFromTo(string arg1, object[] args)
  896. {
  897. ModuleName chamber = ModuleHelper.Converter(args[0].ToString());
  898. int slotFrom = (int)args[1];
  899. int slotTo = (int)args[2];
  900. for (int slot = slotTo - 1; slot >= slotFrom - 1; slot--)
  901. {
  902. if (WaferManager.Instance.IsWaferSlotLocationValid(chamber, slot))
  903. {
  904. if (WaferManager.Instance.CheckHasWafer(chamber, slot))
  905. {
  906. WaferManager.Instance.DeleteWafer(chamber, slot);
  907. EV.PostMessage(ModuleName.System.ToString(), EventEnum.WaferDelete, chamber.ToString(), slot + 1);
  908. }
  909. else
  910. {
  911. EV.PostInfoLog("System", string.Format("No wafer at {0} {1}, delete not valid", chamber.ToString(), slot + 1));
  912. }
  913. }
  914. else
  915. {
  916. DeleteWaferFailedWarning.Set(string.Format("Invalid position,{0},{1}", chamber.ToString(), slot.ToString()));
  917. return false;
  918. }
  919. }
  920. var carrier = CarrierManager.Instance.GetCarrier(chamber);
  921. if (carrier != null)
  922. {
  923. CarrierManager.Instance.UpdateWaferIn(chamber, 0, false);
  924. }
  925. var wafers = WaferManager.Instance.GetWafers(chamber);
  926. if (wafers != null && carrier != null)
  927. {
  928. foreach (var wafer in wafers)
  929. {
  930. if (wafer != null && !wafer.IsEmpty)
  931. {
  932. CarrierManager.Instance.UpdateWaferIn(chamber, 0, true);
  933. break;
  934. }
  935. }
  936. }
  937. return true;
  938. }
  939. private bool InvokeDeleteWafer(string arg1, object[] args)
  940. {
  941. ModuleName chamber = ModuleHelper.Converter(args[0].ToString());
  942. int slot = (int)args[1];
  943. if (WaferManager.Instance.IsWaferSlotLocationValid(chamber, slot))
  944. {
  945. if (WaferManager.Instance.CheckHasWafer(chamber, slot))
  946. {
  947. WaferManager.Instance.DeleteWafer(chamber, slot);
  948. EV.PostMessage(ModuleName.System.ToString(), EventEnum.WaferDelete, chamber.ToString(), slot + 1);
  949. }
  950. else
  951. {
  952. EV.PostInfoLog("System", string.Format("No wafer at {0} {1}, delete not valid", chamber.ToString(), slot + 1));
  953. }
  954. }
  955. else
  956. {
  957. DeleteWaferFailedWarning.Set(string.Format("Invalid position,{0},{1}", chamber.ToString(), slot.ToString()));
  958. return false;
  959. }
  960. var carrier = CarrierManager.Instance.GetCarrier(chamber);
  961. if (carrier != null)
  962. {
  963. CarrierManager.Instance.UpdateWaferIn(chamber, 0, false);
  964. }
  965. var wafers = WaferManager.Instance.GetWafers(chamber);
  966. if (wafers != null && carrier != null)
  967. {
  968. foreach (var wafer in wafers)
  969. {
  970. if (wafer != null && !wafer.IsEmpty)
  971. {
  972. CarrierManager.Instance.UpdateWaferIn(chamber, 0, true);
  973. break;
  974. }
  975. }
  976. }
  977. return true;
  978. }
  979. private bool InvokeCreateWaferFromTo(string arg1, object[] args)
  980. {
  981. ModuleName chamber = ModuleHelper.Converter(args[0].ToString());
  982. ModuleName originChamber = chamber;
  983. int slotFrom = (int)args[1];
  984. int slotTo = (int)args[2];
  985. int originSlot = 1;
  986. WaferStatus state = WaferStatus.Normal;
  987. WaferType waferTye = WaferType.None;
  988. var strs = (string[])args[3];
  989. Enum.TryParse(strs[0].ToString(), out waferTye);
  990. originChamber = ModuleHelper.Converter(strs[1].ToString());
  991. originSlot = int.Parse(strs[2]);
  992. for (int slot = slotTo - 1; slot >= slotFrom - 1; slot--)
  993. {
  994. if (WaferManager.Instance.IsWaferSlotLocationValid(chamber, slot))
  995. {
  996. if (WaferManager.Instance.CheckHasWafer(chamber, slot))
  997. {
  998. EV.PostInfoLog("System", string.Format("{0} slot {1} already has wafer.create wafer is not valid", chamber, slot + 1));
  999. }
  1000. else
  1001. {
  1002. if (originChamber == chamber && WaferManager.Instance.CreateWafer(chamber, slot, state, waferTye) != null)
  1003. {
  1004. EV.PostMessage(ModuleName.System.ToString(), EventEnum.WaferCreate, chamber.ToString(), slot + 1, state.ToString());
  1005. }
  1006. else if (originChamber != chamber && WaferManager.Instance.CreateWafer(chamber, slot, originChamber, originSlot, state, waferTye) != null)
  1007. {
  1008. EV.PostMessage(ModuleName.System.ToString(), EventEnum.WaferCreate, chamber.ToString(), slot + 1, state.ToString());
  1009. }
  1010. }
  1011. }
  1012. else
  1013. {
  1014. EV.PostWarningLog("System", string.Format("Invalid position,{0},{1}", chamber.ToString(), slot.ToString()));
  1015. return false;
  1016. }
  1017. }
  1018. var carrier = CarrierManager.Instance.GetCarrier(chamber);
  1019. if (carrier != null)
  1020. {
  1021. CarrierManager.Instance.UpdateWaferIn(chamber, 0, true);
  1022. }
  1023. return true;
  1024. }
  1025. private bool InvokeCreateWafer(string arg1, object[] args)
  1026. {
  1027. ModuleName chamber = ModuleHelper.Converter(args[0].ToString());
  1028. ModuleName originChamber = chamber;
  1029. int slot = (int)args[1];
  1030. int originSlot = 1;
  1031. WaferStatus state = WaferStatus.Normal;
  1032. WaferType waferTye = WaferType.None;
  1033. if (args.Length > 2)
  1034. Enum.TryParse(args[2].ToString(), out waferTye);
  1035. if (args.Length > 3)
  1036. originChamber = ModuleHelper.Converter(args[3].ToString());
  1037. if (args.Length > 4)
  1038. originSlot = (int)args[4];
  1039. if (ModuleHelper.IsLoadPort(chamber))
  1040. {
  1041. //var lp = Modules[chamber] as LoadPortModule;
  1042. //if (lp.LPDevice.CassetteState != LoadportCassetteState.Normal)
  1043. //{
  1044. // EV.PostWarningLog("System", $"Can not create wafer at {chamber}.{slot + 1}, Cassette not placed.");
  1045. // return false;
  1046. //}
  1047. }
  1048. if (WaferManager.Instance.IsWaferSlotLocationValid(chamber, slot))
  1049. {
  1050. if (WaferManager.Instance.CheckHasWafer(chamber, slot))
  1051. {
  1052. EV.PostInfoLog("System", string.Format("{0} slot {1} already has wafer.create wafer is not valid", chamber, slot + 1));
  1053. }
  1054. else
  1055. {
  1056. if (originChamber == chamber && WaferManager.Instance.CreateWafer(chamber, slot, state, waferTye) != null)
  1057. {
  1058. EV.PostMessage(ModuleName.System.ToString(), EventEnum.WaferCreate, chamber.ToString(), slot + 1, state.ToString());
  1059. }
  1060. else if (originChamber != chamber && WaferManager.Instance.CreateWafer(chamber, slot, originChamber, originSlot, state, waferTye) != null)
  1061. {
  1062. EV.PostMessage(ModuleName.System.ToString(), EventEnum.WaferCreate, chamber.ToString(), slot + 1, state.ToString());
  1063. }
  1064. }
  1065. }
  1066. else
  1067. {
  1068. EV.PostWarningLog("System", string.Format("Invalid position,{0},{1}", chamber.ToString(), slot.ToString()));
  1069. return false;
  1070. }
  1071. var carrier = CarrierManager.Instance.GetCarrier(chamber);
  1072. if (carrier != null)
  1073. {
  1074. CarrierManager.Instance.UpdateWaferIn(chamber, 0, true);
  1075. }
  1076. return true;
  1077. }
  1078. private bool InvokeCreateCassetteWafer(string arg1, object[] args)
  1079. {
  1080. ModuleName chamber = ModuleHelper.Converter(args[0].ToString());
  1081. var carrier = CarrierManager.Instance.GetCarrier(chamber);
  1082. if (carrier == null || carrier.IsEmpty)
  1083. {
  1084. EV.PostInfoLog(Module, $"{chamber} create wafer fail for carrier not exist.");
  1085. return false;
  1086. }
  1087. if (args.Length > 3 && !carrier.CarrierType.ToString().Equals(CarrierType.None.ToString()) && !carrier.CarrierType.ToString().Equals(args[3].ToString()))
  1088. {
  1089. EV.PostInfoLog(Module, $"{chamber} type mismatch!");
  1090. return false;
  1091. }
  1092. int slotFrom = (int)args[1];
  1093. int slotTo = (int)args[2];
  1094. WaferStatus state = WaferStatus.Normal;
  1095. WaferType waferTye = WaferType.None;
  1096. if (args.Length > 3)
  1097. Enum.TryParse(args[3].ToString(), out waferTye);
  1098. for (int slot = slotTo - 1; slot >= slotFrom - 1; slot--)
  1099. {
  1100. if (WaferManager.Instance.IsWaferSlotLocationValid(chamber, slot))
  1101. {
  1102. if (WaferManager.Instance.CheckHasWafer(chamber, slot))
  1103. {
  1104. EV.PostInfoLog(Module, string.Format("{0} slot {1} already has wafer.", chamber, slot + 1));
  1105. continue;
  1106. }
  1107. else if (WaferManager.Instance.CreateWafer(chamber, slot, state, waferTye) == null)
  1108. {
  1109. CreateWaferFailedWarning.Set(string.Format($"Create slot {slot + 1} wafer failed."));
  1110. return false;
  1111. }
  1112. }
  1113. else
  1114. {
  1115. CreateWaferFailedWarning.Set(string.Format("Invalid slot,{0},{1}", chamber.ToString(), (slot + 1).ToString()));
  1116. return false;
  1117. }
  1118. }
  1119. if (carrier != null)
  1120. {
  1121. CarrierManager.Instance.UpdateWaferIn(chamber, 0, true);
  1122. }
  1123. EV.PostInfoLog(Module, $"Create wafer from {slotFrom} to {slotTo} successed.");
  1124. return true;
  1125. }
  1126. private bool InvokeDeleteCassetteWafer(string arg1, object[] args)
  1127. {
  1128. ModuleName chamber = ModuleHelper.Converter(args[0].ToString());
  1129. int slotFrom = (int)args[1];
  1130. int slotTo = (int)args[2];
  1131. if (WaferManager.Instance.IsWaferSlotLocationValid(chamber, slotFrom - 1) && WaferManager.Instance.IsWaferSlotLocationValid(chamber, slotTo - 1))
  1132. {
  1133. WaferManager.Instance.DeleteWafer(chamber, slotFrom - 1, slotTo - slotFrom + 1);
  1134. }
  1135. else
  1136. {
  1137. DeleteWaferFailedWarning.Set(string.Format($"Invalid slot,{chamber} slot from {slotFrom}, slot to {slotTo}"));
  1138. return false;
  1139. }
  1140. var carrier = CarrierManager.Instance.GetCarrier(chamber);
  1141. if (carrier != null)
  1142. {
  1143. CarrierManager.Instance.UpdateWaferIn(chamber, 0, false);
  1144. }
  1145. var wafers = WaferManager.Instance.GetWafers(chamber);
  1146. if (wafers != null && carrier != null)
  1147. {
  1148. foreach (var wafer in wafers)
  1149. {
  1150. if (wafer != null && !wafer.IsEmpty)
  1151. {
  1152. CarrierManager.Instance.UpdateWaferIn(chamber, 0, true);
  1153. break;
  1154. }
  1155. }
  1156. }
  1157. EV.PostInfoLog(Module, $"Delete wafer from {slotFrom} to {slotTo} successed.");
  1158. return true;
  1159. }
  1160. private CarrierType GetStockerType(string name)
  1161. {
  1162. var result = CarrierType.SD;
  1163. var scName = name.Contains("LP") ? $"{name}Type" : $"{name}WaferType";
  1164. string configType = SC.GetStringValue($"System.Stocker.{scName}");
  1165. if (string.IsNullOrEmpty(configType))
  1166. {
  1167. return result;
  1168. }
  1169. result = configType.StartsWith(CarrierType.P.ToString()) ? CarrierType.P : (CarrierType)Enum.Parse(typeof(CarrierType), configType);
  1170. return result;
  1171. }
  1172. public bool InvokeCreateCarrier(string arg1, object[] args)
  1173. {
  1174. ModuleName chamber = ModuleHelper.Converter(args[0].ToString());
  1175. int slot = (int)args[1];
  1176. CarrierType carrierTye = GetStockerType(chamber.ToString());
  1177. if (args.Length > 2)
  1178. {
  1179. var inputType = args[2].ToString();
  1180. if (!carrierTye.ToString().Equals(CarrierType.None.ToString()) && !carrierTye.ToString().Equals(inputType))
  1181. {
  1182. EV.PostInfoLog(Module, $"{chamber} type mismatch!");
  1183. return false;
  1184. }
  1185. Enum.TryParse(args[2].ToString(), out carrierTye);
  1186. }
  1187. if (CarrierManager.Instance.HasCarrier(args[0].ToString(), slot))
  1188. {
  1189. EV.PostInfoLog("System", $"{chamber} already has carrier.create is not valid");
  1190. }
  1191. else
  1192. {
  1193. CarrierManager.Instance.CreateCarrier(args[0].ToString(), carrierTye, args[0].ToString());
  1194. EV.PostInfoLog("System", $"{chamber} create carrier");
  1195. }
  1196. var wafers = WaferManager.Instance.GetWafers(chamber);
  1197. if (wafers != null)
  1198. {
  1199. foreach (var wafer in wafers)
  1200. {
  1201. if (wafer != null && !wafer.IsEmpty)
  1202. {
  1203. CarrierManager.Instance.UpdateWaferIn(chamber, 0, true);
  1204. break;
  1205. }
  1206. }
  1207. }
  1208. return true;
  1209. }
  1210. private bool InvokeDeleteCarrier(string arg1, object[] args)
  1211. {
  1212. ModuleName chamber = ModuleHelper.Converter(args[0].ToString());
  1213. if (CarrierManager.Instance.HasCarrier(chamber.ToString()))
  1214. {
  1215. CarrierManager.Instance.DeleteCarrier(chamber.ToString());
  1216. EV.PostInfoLog("System", $"Carrier deleted from {chamber}");
  1217. var wafers = WaferManager.Instance.GetWafers(chamber);
  1218. for (int i = 0; i < wafers.Length; i++)
  1219. {
  1220. if (!wafers[i].IsEmpty)
  1221. WaferManager.Instance.DeleteWafer(chamber, i);
  1222. }
  1223. }
  1224. else
  1225. {
  1226. EV.PostInfoLog("System", string.Format("No carrier at {0}, delete not valid", chamber.ToString()));
  1227. }
  1228. return true;
  1229. }
  1230. private bool InvokeSetLotID(string arg1, object[] args)
  1231. {
  1232. ModuleName chamber = ModuleHelper.Converter(args[0].ToString());
  1233. List<string> lotIdLst = new List<string>();
  1234. foreach (var module in Modules.Keys)
  1235. {
  1236. if ((Modules[module] as StockerModule) == null)
  1237. continue;
  1238. if (CarrierManager.Instance.HasCarrier(module.ToString()))
  1239. {
  1240. lotIdLst.Add(CarrierManager.Instance.GetCarrier(module.ToString()).CarrierId);
  1241. }
  1242. }
  1243. if (lotIdLst.Any(x => x == args[1].ToString()))
  1244. {
  1245. SetLotIDFailedWarning.Set($"Carrier ID={args[1]} of {chamber} is already exist");
  1246. return false;
  1247. }
  1248. if (CarrierManager.Instance.HasCarrier(chamber.ToString()))
  1249. {
  1250. CarrierManager.Instance.UpdateCarrierId(chamber.ToString(), args[1].ToString());
  1251. EV.PostInfoLog("System", $"Carrier {chamber} update carrier ID {args[1]}");
  1252. }
  1253. else
  1254. {
  1255. EV.PostInfoLog("System", string.Format("No carrier at {0}, update carrier ID not valid", chamber.ToString()));
  1256. }
  1257. return true;
  1258. }
  1259. private bool InvokeShutDown(string arg1, object[] arg2)
  1260. {
  1261. if (IsAlarm || IsIdle || IsInit)
  1262. {
  1263. EV.PostWarningLog(Module, $"System start shut down");
  1264. EV.PostKickoutMessage("ShutDown");
  1265. RtApplication.Instance.Terminate();
  1266. return true;
  1267. }
  1268. EV.PostWarningLog(Module, $"System in {StringFsmStatus} mode, can not shut down");
  1269. return false;
  1270. }
  1271. private void OnModuleError(string module)
  1272. {
  1273. if (FsmState == (int)RtState.AutoRunning)
  1274. {
  1275. ModuleName mod = ModuleHelper.Converter(module);
  1276. PostMsg(MSG.ModuleError, module);
  1277. }
  1278. }
  1279. public override void Monitor()
  1280. {
  1281. base.Monitor();
  1282. }
  1283. private bool CheckPWaferBatch(ModuleName module, string batch)
  1284. {
  1285. string stockerWaferType = batch == "A" ? "P1" : "P2";
  1286. return SC.GetStringValue($"System.Stocker.{module}WaferType") == stockerWaferType;
  1287. }
  1288. private bool CheckMWaferBatch(ModuleName module, string batch)
  1289. {
  1290. string stockerWaferType = batch == "A" ? "M1" : "M2";
  1291. return SC.GetStringValue($"System.Stocker.{module}WaferType") == stockerWaferType;
  1292. }
  1293. private bool CheckJobPause()
  1294. {
  1295. return _pauseTrig.R;
  1296. }
  1297. private bool CheckToPostJobMessage(int msg, params object[] args)
  1298. {
  1299. _cycledCount = 0;
  1300. //只有LoadProcessUnload和ChargeProcessDischarge有cycle模式
  1301. if (SC.GetValue<bool>("System.IsCycleMode") && (msg == (int)MSG.LoadProcessUnload || msg == (int)MSG.ChargeProcessDischarge))
  1302. {
  1303. lock (_locker)
  1304. {
  1305. _jobMSG = msg;
  1306. _jobParas = args;
  1307. }
  1308. }
  1309. else
  1310. {
  1311. lock (_locker)
  1312. {
  1313. _jobMSG = 0;
  1314. _jobParas = null;
  1315. }
  1316. }
  1317. return CheckToPostMessage(msg, args);
  1318. }
  1319. private bool OnCycleTimer()
  1320. {
  1321. if (!SC.GetValue<bool>("System.IsSimulatorMode"))
  1322. {
  1323. //_plcConnectTrig.CLK = !(IoProviderManager.Instance.Providers[0] as AdsPlcAdapter).IsPlcConnected;
  1324. //if (_plcConnectTrig.R)
  1325. //{
  1326. // PLCDisconnectAlarm.Set();
  1327. //}
  1328. //if (_plcConnectTrig.T)
  1329. //{
  1330. // EV.ClearAlarmEvent(PLCDisconnectAlarm.Id);
  1331. // PLCDisconnectAlarm.Reset();
  1332. // PLCConnectRecoveryWarning.Set();
  1333. //}
  1334. }
  1335. _cassetteRobotModule.Monitor();
  1336. _waferRobotModule.Monitor();
  1337. _lp1Module.Monitor();
  1338. _lp2Module.Monitor();
  1339. _lp3Module.Monitor();
  1340. _lp4Module.Monitor();
  1341. _fims1Module.Monitor();
  1342. _fims2Module.Monitor();
  1343. _boatModule.Monitor();
  1344. foreach (var module in Modules.Keys)
  1345. {
  1346. if (!(Modules[module] is StockerModule))
  1347. continue;
  1348. Modules[module].Monitor();
  1349. }
  1350. return true;
  1351. }
  1352. public List<ProcessJobInfo> GetProcessJobInfo()
  1353. {
  1354. return _auto.LstProcessJobs;
  1355. }
  1356. public List<Tuple<string, string, List<int>>> GetProcessingStockers()
  1357. {
  1358. return _auto.GetProcessingStockers();
  1359. }
  1360. public List<Tuple<string, string, List<int>>> GetAllPJStockers()
  1361. {
  1362. return _auto.GetAllPJStockers();
  1363. }
  1364. public List<CarrierPara> GetTransferJobStockers()
  1365. {
  1366. return _transferJob.GetTransferJobStockers();
  1367. }
  1368. public void ResetTask(ModuleName module)
  1369. {
  1370. _auto.ResetTask(module);
  1371. _transferJob.ResetTask(module);
  1372. (_returnAll as ReturnAllWafer).ResetTask(module);
  1373. }
  1374. private void CoolingSkip()
  1375. {
  1376. _auto.CoolingSkip();
  1377. }
  1378. }
  1379. }