EquipmentManager.cs 65 KB

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