EquipmentManager.cs 62 KB

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