EquipmentManager.cs 58 KB

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