EquipmentManager.cs 59 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Threading.Tasks;
  5. using Aitex.Core.Common;
  6. using Aitex.Core.RT.DataCenter;
  7. using Aitex.Core.RT.Device;
  8. using Aitex.Core.RT.Event;
  9. using Aitex.Core.RT.Fsm;
  10. using Aitex.Core.RT.Log;
  11. using Aitex.Core.RT.OperationCenter;
  12. using Aitex.Core.RT.RecipeCenter;
  13. using Aitex.Core.RT.Routine;
  14. using Aitex.Core.RT.SCCore;
  15. using Aitex.Core.Util;
  16. using Aitex.Core.Utilities;
  17. using MECF.Framework.Common.Equipment;
  18. using MECF.Framework.Common.SubstrateTrackings;
  19. using MECF.Framework.RT.Core.Applications;
  20. using MECF.Framework.RT.Core.IoProviders;
  21. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.LoadPorts;
  22. using MECF.Framework.RT.ModuleLibrary.Commons;
  23. using MECF.Framework.RT.ModuleLibrary.EfemModules;
  24. using MECF.Framework.RT.ModuleLibrary.LPModules;
  25. using MECF.Framework.RT.ModuleLibrary.SystemModules.Routines;
  26. using SecsGem.Core.Application;
  27. namespace MECF.Framework.RT.ModuleLibrary.SystemModules
  28. {
  29. public enum RtState
  30. {
  31. Init,
  32. Initializing,
  33. Idle,
  34. Transfer,
  35. AutoRunning,
  36. AutoIdle,
  37. ReturnAllWafer,
  38. TMCycling,
  39. TMCyclePaused,
  40. Error,
  41. }
  42. public class EquipmentManager : FsmDevice, IEquipmentCommand
  43. {
  44. public enum MSG
  45. {
  46. MoveWafer,
  47. ReturnAllWafer,
  48. TMCycleStart,
  49. TMCyclePause,
  50. TMCycleResume,
  51. Stop,
  52. HOME,
  53. RESET,
  54. ABORT,
  55. ERROR,
  56. ToInit,
  57. SetAutoMode,
  58. SetManualMode,
  59. ResetIdleCleanTime,
  60. ResetIdlePurgeTime,
  61. FAJobCommand,
  62. CreateJob,
  63. PauseJob,
  64. ResumeJob,
  65. StartJob,
  66. StopJob,
  67. AbortJob,
  68. JobDone,
  69. ModuleError,
  70. Map,
  71. }
  72. public static Dictionary<ModuleName, ModuleFsmDevice> Modules { get; set; }
  73. public bool IsAutoIdle
  74. {
  75. get
  76. {
  77. return FsmState == (int)RtState.AutoIdle;
  78. }
  79. }
  80. public bool IsAutoMode
  81. {
  82. get
  83. {
  84. return FsmState == (int)RtState.AutoRunning || FsmState == (int)RtState.AutoIdle;
  85. }
  86. }
  87. public bool IsInit
  88. {
  89. get { return FsmState == (int)RtState.Init; }
  90. }
  91. public bool IsIdle
  92. {
  93. get { return FsmState == (int)RtState.Idle; }
  94. }
  95. public bool IsAlarm
  96. {
  97. get { return FsmState == (int)RtState.Error; }
  98. }
  99. public bool IsRunning
  100. {
  101. get
  102. {
  103. return !IsAlarm && !IsIdle && !IsInit && (FsmState != (int)RtState.AutoIdle);
  104. }
  105. }
  106. private bool _isInited;
  107. protected IRoutine _manualTransfer;
  108. protected IAutoTransfer _auto;
  109. protected IRoutine _homeAll;
  110. protected IRoutine _returnAll;
  111. protected IRoutine _tmCycle;
  112. private List<string> _modules;
  113. public EquipmentManager()
  114. {
  115. Module = "System";
  116. Name = "System";
  117. Modules = new Dictionary<ModuleName, ModuleFsmDevice>();
  118. _modules = new List<string>() { "System" };
  119. }
  120. public override bool Initialize()
  121. {
  122. InitDevices();
  123. InitModules();
  124. EnumLoop<RtState>.ForEach((item) =>
  125. {
  126. MapState((int)item, item.ToString());
  127. });
  128. EnumLoop<MSG>.ForEach((item) =>
  129. {
  130. MapMessage((int)item, item.ToString());
  131. });
  132. EnableFsm(100, RtState.Init);
  133. BuildTransitionTable();
  134. SubscribeDataVariable();
  135. SubscribeOperation();
  136. InitRoutine();
  137. Singleton<EventManager>.Instance.OnAlarmEvent += Instance_OnAlarmEvent;
  138. return true;
  139. }
  140. protected void BuildModules(params ModuleFsmDevice[] modules)
  141. {
  142. if (modules != null && modules.Length > 0)
  143. {
  144. foreach (var moduleFsmDevice in modules)
  145. {
  146. Modules[ModuleHelper.Converter(moduleFsmDevice.Module)] = moduleFsmDevice;
  147. }
  148. foreach (var modulesKey in Modules.Keys)
  149. {
  150. _modules.Add(modulesKey.ToString());
  151. }
  152. foreach (var modulesValue in Modules.Values)
  153. {
  154. if (modulesValue.Module != ModuleName.TM.ToString() && modulesValue.Module != ModuleName.EFEM.ToString())
  155. {
  156. if (!SC.GetValue<bool>($"System.SetUp.{modulesValue.Module}.IsInstalled"))
  157. {
  158. continue;
  159. }
  160. }
  161. modulesValue.Initialize();
  162. }
  163. }
  164. }
  165. protected virtual void InitRoutine()
  166. {
  167. }
  168. protected virtual void InitModules()
  169. {
  170. }
  171. protected virtual void InitDevices()
  172. {
  173. }
  174. //private PeriodicJob _job1;
  175. //Stopwatch _sw = new Stopwatch();
  176. //private bool OnJob1()
  177. //{
  178. // _sw.Restart();
  179. // BufferModule buffer = Modules[ModuleName.Buffer] as BufferModule;
  180. // if (!buffer.CheckToPostMessage(BufferModule.MSG.InTransfer))
  181. // {
  182. // System.Diagnostics.Trace.Assert(false)
  183. // System.Diagnostics.Trace.WriteLine("fail to in transfer");
  184. // }
  185. // if (buffer.IsIdle)
  186. // {
  187. // System.Diagnostics.Trace.Assert(false);
  188. // System.Diagnostics.Trace.WriteLine("!!!==========>IsIdle");
  189. // }
  190. // //System.Diagnostics.Trace.Assert(buffer.IsIdle, $"in {buffer.StringFsmStatus}");
  191. // while (buffer.IsIdle)
  192. // {
  193. // Thread.Sleep(5);
  194. // }
  195. // //buffer.NoteTransferStop(ModuleName.EfemRobot, Hand.Blade1, 0, EnumTransferType.Place);
  196. // //Thread.Sleep(15);
  197. // if (!buffer.CheckToPostMessage(BufferModule.MSG.TransferComplete))
  198. // {
  199. // System.Diagnostics.Trace.Assert(false);
  200. // System.Diagnostics.Trace.WriteLine("fail to complete");
  201. // }
  202. // //if (!buffer.IsIdle)
  203. // //{
  204. // // System.Diagnostics.Trace.WriteLine("not idle");
  205. // //}
  206. // System.Diagnostics.Trace.WriteLine($" === {_sw.ElapsedMilliseconds}");
  207. // while (!buffer.IsIdle)
  208. // {
  209. // Thread.Sleep(5);
  210. // }
  211. // return true;
  212. //}
  213. private void BuildTransitionTable()
  214. {
  215. //Init sequence
  216. Transition(RtState.Init, MSG.HOME, FsmStartHome, RtState.Initializing);
  217. Transition(RtState.Idle, MSG.HOME, FsmStartHome, RtState.Initializing);
  218. Transition(RtState.Error, MSG.HOME, FsmStartHome, RtState.Initializing);
  219. Transition(RtState.Error, MSG.ToInit, null, RtState.Init);
  220. Transition(RtState.Initializing, FSM_MSG.TIMER, FsmMonitorHome, RtState.Idle);
  221. Transition(RtState.Initializing, MSG.ERROR, fError, RtState.Error);
  222. Transition(RtState.Initializing, MSG.ABORT, FsmAbort, RtState.Init);
  223. //Reset
  224. AnyStateTransition(MSG.RESET, fStartReset, RtState.Idle);
  225. AnyStateTransition(MSG.ERROR, fError, RtState.Error);
  226. AnyStateTransition((int)FSM_MSG.ALARM, fError, (int)RtState.Error);
  227. //Auto/manual sequence
  228. Transition(RtState.Idle, MSG.SetAutoMode, fStartAutoTransfer, RtState.AutoIdle);
  229. Transition(RtState.AutoRunning, FSM_MSG.TIMER, fAutoTransfer, RtState.AutoRunning);
  230. Transition(RtState.AutoRunning, MSG.ABORT, FsmAbort, RtState.AutoIdle);
  231. Transition(RtState.AutoRunning, MSG.JobDone, null, RtState.AutoIdle);
  232. Transition(RtState.AutoRunning, MSG.CreateJob, FsmCreateJob, RtState.AutoRunning);
  233. //Transition(RtState.AutoRunning, MSG.FAJobCommand, FsmFAJobCommand, RtState.AutoRunning);
  234. Transition(RtState.AutoRunning, MSG.StartJob, FsmStartJob, RtState.AutoRunning);
  235. Transition(RtState.AutoRunning, MSG.PauseJob, FsmPauseJob, RtState.AutoRunning);
  236. Transition(RtState.AutoRunning, MSG.ResumeJob, FsmResumeJob, RtState.AutoRunning);
  237. Transition(RtState.AutoRunning, MSG.StopJob, FsmStopJob, RtState.AutoRunning);
  238. Transition(RtState.AutoRunning, MSG.AbortJob, FsmAbortJob, RtState.AutoRunning);
  239. Transition(RtState.AutoRunning, MSG.ModuleError, FsmModuleError, RtState.AutoRunning);
  240. Transition(RtState.AutoRunning, MSG.Map, FsmMap, RtState.AutoRunning);
  241. Transition(RtState.AutoRunning, MSG.ResetIdleCleanTime, FsmResetIdleCleanTime, RtState.AutoRunning);
  242. Transition(RtState.AutoRunning, MSG.ResetIdlePurgeTime, FsmResetIdlePurgeTime, RtState.AutoRunning);
  243. EnterExitTransition<RtState, FSM_MSG>(RtState.AutoRunning, null, FSM_MSG.NONE, fExitAutoTransfer);
  244. Transition(RtState.AutoIdle, FSM_MSG.TIMER, FsmMonitorAutoIdle, RtState.AutoIdle);
  245. //Transition(RtState.AutoIdle, MSG.FAJobCommand, FsmFAJobCommand, RtState.AutoIdle);
  246. Transition(RtState.AutoIdle, MSG.SetManualMode, FsmStartSetManualMode, RtState.Idle);
  247. Transition(RtState.AutoIdle, MSG.CreateJob, FsmCreateJob, RtState.AutoIdle);
  248. Transition(RtState.AutoIdle, MSG.StartJob, FsmStartJob, RtState.AutoRunning);
  249. Transition(RtState.AutoIdle, MSG.ABORT, FsmAbort, RtState.AutoIdle);
  250. Transition(RtState.AutoIdle, MSG.AbortJob, FsmAbortJob, RtState.AutoIdle);
  251. Transition(RtState.AutoIdle, MSG.Map, FsmMap, RtState.AutoIdle);
  252. Transition(RtState.AutoIdle, MSG.ResetIdleCleanTime, FsmResetIdleCleanTime, RtState.AutoIdle);
  253. Transition(RtState.AutoIdle, MSG.ResetIdlePurgeTime, FsmResetIdlePurgeTime, RtState.AutoIdle);
  254. //return all wafer
  255. Transition(RtState.Idle, MSG.ReturnAllWafer, FsmStartReturnAllWafer, RtState.ReturnAllWafer);
  256. Transition(RtState.ReturnAllWafer, FSM_MSG.TIMER, FsmMonitorReturnAllWafer, RtState.Idle);
  257. Transition(RtState.ReturnAllWafer, MSG.ABORT, FsmAbortReturnAllWafer, RtState.Idle);
  258. //return all wafer
  259. Transition(RtState.Idle, MSG.TMCycleStart, FsmStartTMCycle, RtState.TMCycling);
  260. Transition(RtState.TMCycling, MSG.TMCyclePause, null, RtState.TMCyclePaused);
  261. Transition(RtState.TMCyclePaused, MSG.TMCycleResume, null, RtState.TMCycling);
  262. Transition(RtState.TMCycling, FSM_MSG.TIMER, FsmMonitorTMCycle, RtState.Idle);
  263. Transition(RtState.TMCycling, MSG.ABORT, FsmAbortTMCycle, RtState.Idle);
  264. //Transfer sequence
  265. Transition(RtState.Idle, MSG.MoveWafer, fStartTransfer, RtState.Transfer);
  266. Transition(RtState.Transfer, FSM_MSG.TIMER, fTransfer, RtState.Idle);
  267. Transition(RtState.Transfer, MSG.ABORT, FsmAbort, RtState.Idle);
  268. EnterExitTransition<RtState, FSM_MSG>(RtState.Transfer, null, FSM_MSG.NONE, fExitTransfer);
  269. }
  270. void SubscribeDataVariable()
  271. {
  272. DATA.Subscribe("Rt.Status", () => StringFsmStatus);
  273. DATA.Subscribe("System.IsIdle", () => IsIdle || IsInit|| IsAutoIdle);
  274. DATA.Subscribe("System.IsAlarm", () => IsAlarm);
  275. DATA.Subscribe("System.IsBusy", () => IsRunning);
  276. DATA.Subscribe("System.IsAutoRunning", () => IsRunning);
  277. DATA.Subscribe("System.IsAutoMode", () => IsAutoMode);
  278. DATA.Subscribe("System.IsConnectedWithHost", () => CheckSecsGemOnline(Singleton<SecGemApplication>.Instance.ControlState));
  279. DATA.Subscribe("System.IsDisconnectWithHost", () => CheckSecsGemOnline(Singleton<SecGemApplication>.Instance.ControlState));
  280. DATA.Subscribe("System.Modules", () => _modules);
  281. DATA.Subscribe("System.EquipmentMode", () => IsAutoMode ? 0 : 1, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  282. DATA.Subscribe("System.EquipmentStatus", () =>
  283. {
  284. //"0 = Uninit
  285. //1 = Idle
  286. //2 = Running
  287. //3 = Error
  288. //4 = Pause
  289. //"
  290. if (IsInit) return 0;
  291. if (IsIdle) return 1;
  292. if (IsAlarm) return 3;
  293. return 2;
  294. }, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  295. }
  296. /// <summary>
  297. /// 检验Secsgem在线情况
  298. /// </summary>
  299. /// <param name="controlState"></param>
  300. /// <returns></returns>
  301. private bool CheckSecsGemOnline(SecsGem.Core.EnumData.ControlState controlState)
  302. {
  303. if(controlState==SecsGem.Core.EnumData.ControlState.OnlineLocal||controlState==SecsGem.Core.EnumData.ControlState.OnlineRemote)
  304. {
  305. return true;
  306. }
  307. return false;
  308. }
  309. void SubscribeOperation()
  310. {
  311. OP.Subscribe("Create8InchWafer", InvokeCreate8InchWafer);
  312. OP.Subscribe("Create12InchWafer", InvokeCreate12InchWafer);
  313. OP.Subscribe("CreateWafer", InvokeCreateWafer);
  314. OP.Subscribe("DeleteWafer", InvokeDeleteWafer);
  315. OP.Subscribe("ReturnWafer", InvokeReturnWafer);
  316. OP.Subscribe("System.ReturnAllWafer", (string cmd, object[] args) =>
  317. {
  318. return CheckToPostMessage((int)MSG.ReturnAllWafer, args);
  319. });
  320. OP.Subscribe("System.TMCycleStart", (string cmd, object[] args) =>
  321. {
  322. return CheckToPostMessage((int)MSG.TMCycleStart, args);
  323. });
  324. OP.Subscribe("System.TMCyclePause", (string cmd, object[] args) =>
  325. {
  326. return CheckToPostMessage((int)MSG.TMCyclePause);
  327. });
  328. OP.Subscribe("System.TMCycleResume", (string cmd, object[] args) =>
  329. {
  330. return CheckToPostMessage((int)MSG.TMCycleResume);
  331. });
  332. OP.Subscribe("System.ResetIdleCleanTime", (string cmd, object[] args) =>
  333. {
  334. return CheckToPostMessage((int)MSG.ResetIdleCleanTime, args[0]);
  335. });
  336. OP.Subscribe("System.ResetIdlePurgeTime", (string cmd, object[] args) =>
  337. {
  338. return CheckToPostMessage((int)MSG.ResetIdlePurgeTime, args[0]);
  339. });
  340. OP.Subscribe("System.MoveWafer", (string cmd, object[] args) =>
  341. {
  342. if (!Enum.TryParse((string)args[0], out ModuleName source))
  343. {
  344. EV.PostWarningLog(Name, $"Parameter source {(string)args[0]} not valid");
  345. return false;
  346. }
  347. if (!Enum.TryParse((string)args[2], out ModuleName destination))
  348. {
  349. EV.PostWarningLog(Name, $"Parameter destination {(string)args[1]} not valid");
  350. return false;
  351. }
  352. if (args.Length > 8)
  353. {
  354. return CheckToPostMessage((int)MSG.MoveWafer, source, (int)args[1], destination, (int)args[3],
  355. (bool)args[4], (int)args[5], (bool)args[6], (int)args[7]);
  356. }
  357. else if (args.Length > 5)
  358. {
  359. return CheckToPostMessage((int)MSG.MoveWafer, source, (int)args[1], destination, (int)args[3], (bool)args[4]);
  360. }
  361. return CheckToPostMessage((int)MSG.MoveWafer, source, (int)args[1], destination, (int)args[3]);
  362. });
  363. OP.Subscribe("System.HomeAll", (string cmd, object[] args) =>
  364. {
  365. return CheckToPostMessage((int)MSG.HOME);
  366. });
  367. OP.Subscribe("System.Abort", (string cmd, object[] args) =>
  368. {
  369. return CheckToPostMessage((int)MSG.ABORT);
  370. });
  371. OP.Subscribe("System.Reset", (string cmd, object[] args) =>
  372. {
  373. return CheckToPostMessage((int)MSG.RESET);
  374. });
  375. OP.Subscribe("System.SetAutoMode", (string cmd, object[] args) =>
  376. {
  377. return CheckToPostMessage((int)MSG.SetAutoMode);
  378. });
  379. OP.Subscribe("System.SetManualMode", (string cmd, object[] args) =>
  380. {
  381. return CheckToPostMessage((int)MSG.SetManualMode);
  382. });
  383. OP.Subscribe("System.CreateJob", (string cmd, object[] args) =>
  384. {
  385. return CheckToPostMessage((int)MSG.CreateJob, args[0]);
  386. });
  387. OP.Subscribe("System.StartJob", (string cmd, object[] args) =>
  388. {
  389. return CheckToPostMessage((int)MSG.StartJob, args[0]);
  390. });
  391. OP.Subscribe("System.PauseJob", (string cmd, object[] args) =>
  392. {
  393. bool result= CheckToPostMessage((int)MSG.PauseJob, args[0]);
  394. //if(result)
  395. //{
  396. // OP.DoOperation("E94PauseJob",args);
  397. //}
  398. return result;
  399. });
  400. OP.Subscribe("System.ResumeJob", (string cmd, object[] args) =>
  401. {
  402. bool result = CheckToPostMessage((int)MSG.ResumeJob, args[0]);
  403. //if(result)
  404. //{
  405. // OP.DoOperation("E94ResumeJob", args);
  406. //}
  407. return result;
  408. });
  409. OP.Subscribe("System.StopJob", (string cmd, object[] args) =>
  410. {
  411. bool result= CheckToPostMessage((int)MSG.StopJob, args[0]);
  412. //if(result)
  413. //{
  414. // OP.DoOperation("E94StopJob", args);
  415. //}
  416. return result;
  417. });
  418. OP.Subscribe("System.AbortJob", (string cmd, object[] args) =>
  419. {
  420. bool result= CheckToPostMessage((int)MSG.AbortJob, args[0]);
  421. //if(result)
  422. //{
  423. // OP.DoOperation("E94AbortJob", args);
  424. //}
  425. return result;
  426. });
  427. OP.Subscribe("System.ShutDown", InvokeShutDown);
  428. OP.Subscribe("System.MapWafer", InvokeEfemMap);
  429. OP.Subscribe("System.LP1.Map", (string cmd, object[] args) =>
  430. {
  431. if (IsAutoMode)
  432. {
  433. return CheckToPostMessage((int)MSG.Map, ModuleName.LP1.ToString());
  434. }
  435. return false;
  436. });
  437. OP.Subscribe("System.LP2.Map", (string cmd, object[] args) =>
  438. {
  439. if (IsAutoMode)
  440. {
  441. return CheckToPostMessage((int)MSG.Map, ModuleName.LP2.ToString());
  442. }
  443. return false;
  444. });
  445. OP.Subscribe("System.LP3.Map", (string cmd, object[] args) =>
  446. {
  447. if (IsAutoMode)
  448. {
  449. return CheckToPostMessage((int)MSG.Map, ModuleName.LP3.ToString());
  450. }
  451. return false;
  452. });
  453. }
  454. private void Instance_OnAlarmEvent(EventItem obj)
  455. {
  456. }
  457. #region Init
  458. private bool FsmStartHome(object[] objs)
  459. {
  460. _isInited = false;
  461. return _homeAll.Start() == Result.RUN;
  462. }
  463. private bool FsmMonitorHome(object[] objs)
  464. {
  465. Result ret = _homeAll.Monitor();
  466. if (ret == Result.DONE)
  467. {
  468. _isInited = true;
  469. return true;
  470. }
  471. if (ret == Result.FAIL)
  472. {
  473. PostMsg(MSG.ERROR);
  474. }
  475. return false;
  476. }
  477. private bool fError(object[] objs)
  478. {
  479. if (FsmState == (int)RtState.Transfer)
  480. {
  481. }
  482. return true;
  483. }
  484. #endregion
  485. #region AutoTransfer
  486. private bool FsmMonitorAutoIdle(object[] param)
  487. {
  488. //fMonitorFAJob(param);
  489. //return true;
  490. Result ret = _auto.Monitor();
  491. if (!_auto.CheckAllJobDone())
  492. {
  493. return false;
  494. }
  495. return ret == Result.DONE;
  496. }
  497. private bool FsmStartSetManualMode(object[] objs)
  498. {
  499. if (_auto.HasJobRunning)
  500. {
  501. EV.PostWarningLog("System", "Can not change to manual mode, abort running job first");
  502. return false;
  503. }
  504. return true;
  505. }
  506. private bool fStartAutoTransfer(object[] objs)
  507. {
  508. Result ret = _auto.Start(objs);
  509. return ret == Result.RUN;
  510. }
  511. private bool fAutoTransfer(object[] objs)
  512. {
  513. //fMonitorFAJob(objs);
  514. Result ret = _auto.Monitor();
  515. if (_auto.CheckAllJobDone())
  516. {
  517. if (!CheckToPostMessage((int)MSG.JobDone))
  518. return false;
  519. }
  520. return ret == Result.DONE;
  521. }
  522. private bool fExitAutoTransfer(object[] objs)
  523. {
  524. return true;
  525. }
  526. private bool fAbortAutoTransfer(object[] objs)
  527. {
  528. return true;
  529. }
  530. #endregion
  531. #region return all wafer
  532. private bool FsmAbortReturnAllWafer(object[] param)
  533. {
  534. _returnAll.Abort();
  535. return true;
  536. }
  537. private bool FsmMonitorReturnAllWafer(object[] param)
  538. {
  539. return _returnAll.Monitor() == Result.DONE;
  540. }
  541. private bool FsmStartReturnAllWafer(object[] param)
  542. {
  543. return _returnAll.Start(param) == Result.RUN;
  544. }
  545. #endregion
  546. #region return all wafer
  547. private bool FsmAbortTMCycle(object[] param)
  548. {
  549. _tmCycle.Abort();
  550. return true;
  551. }
  552. private bool FsmMonitorTMCycle(object[] param)
  553. {
  554. return _tmCycle.Monitor() == Result.DONE;
  555. }
  556. private bool FsmStartTMCycle(object[] param)
  557. {
  558. return _tmCycle.Start(param) == Result.RUN;
  559. }
  560. #endregion
  561. #region Transfer
  562. private bool fStartTransfer(object[] objs)
  563. {
  564. Result ret = _manualTransfer.Start(objs);
  565. if (ret == Result.FAIL || ret == Result.DONE)
  566. return false;
  567. return ret == Result.RUN;
  568. }
  569. private bool fTransfer(object[] objs)
  570. {
  571. Result ret = _manualTransfer.Monitor();
  572. if (ret == Result.FAIL)
  573. {
  574. PostMsg(MSG.ERROR);
  575. return false;
  576. }
  577. return ret == Result.DONE;
  578. }
  579. private bool fExitTransfer(object[] objs)
  580. {
  581. return true;
  582. }
  583. private bool fAbortTransfer(object[] objs)
  584. {
  585. return true;
  586. }
  587. #endregion
  588. #region reset
  589. private bool fStartReset(object[] objs)
  590. {
  591. EV.ClearAlarmEvent();
  592. //Singleton<DeviceEntity>.Instance.PostMsg(DeviceEntity.MSG.RESET);
  593. IoProviderManager.Instance.Reset();
  594. foreach (var modulesValue in Modules.Values)
  595. {
  596. if (modulesValue.Module != ModuleName.TM.ToString() &&
  597. modulesValue.Module != ModuleName.EFEM.ToString() &&
  598. !SC.GetValue<bool>($"System.SetUp.{modulesValue.Module}.IsInstalled"))
  599. continue;
  600. modulesValue.Reset();
  601. }
  602. if (FsmState == (int)RtState.Error)
  603. {
  604. if (!_isInited)
  605. {
  606. PostMsg(MSG.ToInit);
  607. return false;
  608. }
  609. return true;
  610. }
  611. return false;
  612. }
  613. #endregion
  614. private bool FsmCreateJob(object[] param)
  615. {
  616. _auto.CreateJob((Dictionary<string, object>)param[0]);
  617. return true;
  618. }
  619. private bool FsmAbortJob(object[] param)
  620. {
  621. _auto.AbortJob((string)param[0]);
  622. return true;
  623. }
  624. private bool FsmStopJob(object[] param)
  625. {
  626. _auto.StopJob((string)param[0]);
  627. //CheckToPostMessage((int)MSG.StopJob);//
  628. return true;
  629. }
  630. private bool FsmResumeJob(object[] param)
  631. {
  632. _auto.ResumeJob((string)param[0]);
  633. return true;
  634. }
  635. private bool FsmPauseJob(object[] param)
  636. {
  637. _auto.PauseJob((string)param[0]);
  638. return true;
  639. }
  640. private bool FsmStartJob(object[] param)
  641. {
  642. return _auto.StartJob((string)param[0]);
  643. }
  644. private bool FsmAbort(object[] param)
  645. {
  646. if (FsmState == (int)RtState.Transfer)
  647. {
  648. // _manualTransfer.Clear();
  649. }
  650. if (FsmState == (int)RtState.AutoRunning || FsmState == (int)RtState.AutoIdle)
  651. {
  652. _auto.Clear();
  653. }
  654. if (FsmState == (int)RtState.Initializing)
  655. {
  656. _homeAll.Abort();
  657. }
  658. return true;
  659. }
  660. private bool FsmModuleError(object[] param)
  661. {
  662. _auto.ModuleError((string)param[0]);
  663. return true;
  664. }
  665. private bool FsmMap(object[] param)
  666. {
  667. _auto.Map((string)param[0]);
  668. return true;
  669. }
  670. private bool FsmResetIdlePurgeTime(object[] param)
  671. {
  672. _auto.ResetIdlePurgeTime((string)param[0]);
  673. return true;
  674. }
  675. private bool FsmResetIdleCleanTime(object[] param)
  676. {
  677. _auto.ResetIdleCleanTime((string)param[0]);
  678. return true;
  679. }
  680. private bool InvokeReturnWafer(string arg1, object[] args)
  681. {
  682. ModuleName target = ModuleHelper.Converter(args[0].ToString());
  683. int slot = (int)args[1];
  684. if (ModuleHelper.IsLoadPort(target))
  685. {
  686. EV.PostInfoLog("System", string.Format("Wafer already at LoadPort {0} {1}, return operation is not valid", target.ToString(), slot + 1));
  687. return false;
  688. }
  689. if (!WaferManager.Instance.IsWaferSlotLocationValid(target, slot))
  690. {
  691. EV.PostWarningLog("System", string.Format("Invalid position,{0},{1}", target.ToString(), slot.ToString()));
  692. return false;
  693. }
  694. WaferInfo wafer = WaferManager.Instance.GetWafer(target, slot);
  695. if (wafer.IsEmpty)
  696. {
  697. EV.PostInfoLog("System", string.Format("No wafer at {0} {1}, return operation is not valid", target.ToString(), slot + 1));
  698. return false;
  699. }
  700. return CheckToPostMessage((int)MSG.MoveWafer,
  701. target, slot,
  702. (ModuleName)wafer.OriginStation, wafer.OriginSlot,
  703. false, 0, false, 0);
  704. }
  705. private bool InvokeDeleteWafer(string arg1, object[] args)
  706. {
  707. ModuleName chamber = ModuleHelper.Converter(args[0].ToString());
  708. int slot = (int)args[1];
  709. if (WaferManager.Instance.IsWaferSlotLocationValid(chamber, slot))
  710. {
  711. if (WaferManager.Instance.CheckHasWafer(chamber, slot))
  712. {
  713. WaferManager.Instance.DeleteWafer(chamber, slot);
  714. EV.PostMessage(ModuleName.System.ToString(), EventEnum.WaferDelete, chamber.ToString(), slot + 1);
  715. }
  716. else
  717. {
  718. EV.PostInfoLog("System", string.Format("No wafer at {0} {1}, delete not valid", chamber.ToString(), slot + 1));
  719. }
  720. }
  721. else
  722. {
  723. EV.PostWarningLog("System", string.Format("Invalid position,{0},{1}", chamber.ToString(), slot.ToString()));
  724. return false;
  725. }
  726. return true;
  727. }
  728. private bool InvokeCreateWafer(string arg1, object[] args)
  729. {
  730. ModuleName chamber = ModuleHelper.Converter(args[0].ToString());
  731. int slot = (int)args[1];
  732. WaferStatus state = WaferStatus.Normal;
  733. //if (ModuleHelper.IsLoadPort(chamber))
  734. //{
  735. // var lp = Modules[chamber] as LoadPortModule;
  736. // if (lp.LPDevice.CassetteState != LoadportCassetteState.Normal)
  737. // {
  738. // EV.PostWarningLog("System", $"Can not create wafer at {chamber}.{slot + 1}, Cassette not placed.");
  739. // return false;
  740. // }
  741. //}
  742. WaferSize ws = WaferSize.WS0;
  743. switch (SC.GetValueOrDefault<int>("System.DefaultCreateWaferSize"))
  744. {
  745. case 0:
  746. ws = WaferSize.WS0;
  747. break;
  748. case 4:
  749. ws = WaferSize.WS4;
  750. break;
  751. case 6:
  752. ws = WaferSize.WS6;
  753. break;
  754. case 8:
  755. ws = WaferSize.WS8;
  756. break;
  757. case 12:
  758. ws = WaferSize.WS12;
  759. break;
  760. }
  761. if (WaferManager.Instance.IsWaferSlotLocationValid(chamber, slot))
  762. {
  763. var wafer = WaferManager.Instance.GetWafer(chamber,slot);
  764. if(wafer != null && !wafer.IsEmpty)
  765. {
  766. EV.PostInfoLog("System", string.Format("{0} slot {1} already has wafer.create wafer is not valid", chamber, slot));
  767. }
  768. else if (WaferManager.Instance.CreateWafer(chamber, slot, state, ws) != null)
  769. {
  770. EV.PostMessage(ModuleName.System.ToString(), EventEnum.WaferCreate, chamber.ToString(), slot + 1, state.ToString());
  771. }
  772. }
  773. else
  774. {
  775. EV.PostWarningLog("System", string.Format("Invalid position,{0},{1}", chamber.ToString(), slot.ToString()));
  776. return false;
  777. }
  778. return true;
  779. }
  780. private bool InvokeCreate8InchWafer(string arg1, object[] args)
  781. {
  782. ModuleName chamber = ModuleHelper.Converter(args[0].ToString());
  783. int slot = (int)args[1];
  784. WaferStatus state = WaferStatus.Normal;
  785. //if (ModuleHelper.IsLoadPort(chamber))
  786. //{
  787. // var lp = Modules[chamber] as LoadPortModule;
  788. // if (lp.LPDevice.CassetteState != LoadportCassetteState.Normal)
  789. // {
  790. // EV.PostWarningLog("System", $"Can not create wafer at {chamber}.{slot + 1}, Cassette not placed.");
  791. // return false;
  792. // }
  793. //}
  794. if (WaferManager.Instance.IsWaferSlotLocationValid(chamber, slot))
  795. {
  796. if (WaferManager.Instance.CheckHasWafer(chamber, slot))
  797. {
  798. EV.PostInfoLog("System", string.Format("{0} slot {1} already has wafer.create wafer is not valid", chamber, slot));
  799. }
  800. else if (WaferManager.Instance.CreateWafer(chamber, slot, state, WaferSize.WS8) != null)
  801. {
  802. EV.PostMessage(ModuleName.System.ToString(), EventEnum.WaferCreate, chamber.ToString(), slot + 1, state.ToString());
  803. }
  804. }
  805. else
  806. {
  807. EV.PostWarningLog("System", string.Format("Invalid position,{0},{1}", chamber.ToString(), slot.ToString()));
  808. return false;
  809. }
  810. return true;
  811. }
  812. private bool InvokeCreate12InchWafer(string arg1, object[] args)
  813. {
  814. ModuleName chamber = ModuleHelper.Converter(args[0].ToString());
  815. int slot = (int)args[1];
  816. WaferStatus state = WaferStatus.Normal;
  817. //if (ModuleHelper.IsLoadPort(chamber))
  818. //{
  819. // var lp = Modules[chamber] as LoadPortModule;
  820. // if (lp.LPDevice.CassetteState != LoadportCassetteState.Normal)
  821. // {
  822. // EV.PostWarningLog("System", $"Can not create wafer at {chamber}.{slot + 1}, Cassette not placed.");
  823. // return false;
  824. // }
  825. //}
  826. if (WaferManager.Instance.IsWaferSlotLocationValid(chamber, slot))
  827. {
  828. if (WaferManager.Instance.CheckHasWafer(chamber, slot))
  829. {
  830. EV.PostInfoLog("System", string.Format("{0} slot {1} already has wafer.create wafer is not valid", chamber, slot));
  831. }
  832. else if (WaferManager.Instance.CreateWafer(chamber, slot, state, WaferSize.WS12) != null)
  833. {
  834. EV.PostMessage(ModuleName.System.ToString(), EventEnum.WaferCreate, chamber.ToString(), slot + 1, state.ToString());
  835. }
  836. }
  837. else
  838. {
  839. EV.PostWarningLog("System", string.Format("Invalid position,{0},{1}", chamber.ToString(), slot.ToString()));
  840. return false;
  841. }
  842. return true;
  843. }
  844. private bool InvokeShutDown(string arg1, object[] arg2)
  845. {
  846. if (IsAlarm || IsIdle || IsInit)
  847. {
  848. EV.PostWarningLog(Module, $"System start shut down");
  849. EV.PostKickoutMessage("ShutDown");
  850. RtApplication.Instance.Terminate();
  851. return true;
  852. }
  853. EV.PostWarningLog(Module, $"System in {StringFsmStatus} mode, can not shut down");
  854. return false;
  855. }
  856. private bool InvokeEfemMap(string arg1, object[] arg2)
  857. {
  858. ModuleName target = ModuleHelper.Converter((string)arg2[0]);
  859. if (!ModuleHelper.IsLoadPort(target))
  860. {
  861. EV.PostWarningLog("System", $"Invalid map target {target}");
  862. return false;
  863. }
  864. for (int i = 0; i < 25; i++)
  865. {
  866. WaferInfo wafer = WaferManager.Instance.GetWafer(target, i);
  867. if (wafer.IsEmpty)
  868. continue;
  869. if (wafer.ProcessState == EnumWaferProcessStatus.Completed ||
  870. wafer.ProcessState == EnumWaferProcessStatus.Failed)
  871. {
  872. EV.PostWarningLog("System", $"{target} wafer is processed, can not map again");
  873. return false;
  874. }
  875. }
  876. if (IsAutoMode)
  877. {
  878. _auto.Map((string)arg2[0]);
  879. return true;
  880. }
  881. //EfemModule efem = Modules[ModuleName.EfemRobot] as EfemModule;
  882. //if (!efem.Map(ModuleHelper.Converter((string) arg2[0]), out string reason))
  883. //{
  884. // EV.PostWarningLog(Module, reason);
  885. //}
  886. return true;
  887. }
  888. private void OnModuleError(string module)
  889. {
  890. if (FsmState == (int)RtState.AutoRunning)
  891. {
  892. ModuleName mod = ModuleHelper.Converter(module);
  893. PostMsg(MSG.ModuleError, module);
  894. }
  895. }
  896. public override void Monitor()
  897. {
  898. base.Monitor();
  899. }
  900. string sourceModule = "";
  901. #region control job /process job nnotation
  902. /*
  903. private bool fMonitorFAJob(object[] param)
  904. {
  905. //Singleton<FAJobController>.Instance.MonitorJob();
  906. E40ProcessJob[] pjs = Singleton<FAJobController>.Instance.FAProcessJobs.Values.ToArray();
  907. E94ControlJob[] cjs = Singleton<FAJobController>.Instance.FAControlJobs.Values.ToArray();
  908. foreach (var pj in pjs)
  909. {
  910. if ((pj.PJstate == ProcessJobState.NONE || pj.PJstate == ProcessJobState.PROCESS_COMPLETE)
  911. && Singleton<FAJobController>.Instance.FAProcessJobs.ContainsKey(pj.ObjtID))
  912. Singleton<FAJobController>.Instance.FAProcessJobs.Remove(pj.ObjtID);
  913. if (pj.PJstate == ProcessJobState.ABORTING)
  914. Singleton<FAJobController>.Instance.FAProcessJobs[pj.ObjtID].PJAborted();
  915. if (pj.PJstate == ProcessJobState.ABORTED)
  916. Singleton<FAJobController>.Instance.FAProcessJobs.Remove(pj.ObjtID);
  917. }
  918. foreach (var cj in cjs)
  919. {
  920. if ((cj.state == ControlJobState.NONE || cj.state == ControlJobState.COMPLETED)
  921. && Singleton<FAJobController>.Instance.FAControlJobs.ContainsKey(cj.ObjtID))
  922. Singleton<FAJobController>.Instance.FAControlJobs.Remove(cj.ObjtID);
  923. }
  924. if (Singleton<FAJobController>.Instance.FAProcessJobs.Count == 0) return true;
  925. if (Singleton<FAJobController>.Instance.FAControlJobs.Count == 0) return true;
  926. foreach (var pj in pjs)
  927. {
  928. if (pj.PJstate == ProcessJobState.POOLED)
  929. {
  930. foreach (var mtrlname in pj.PRMtlNameList)
  931. {
  932. string lp = CarrierManager.Instance.GetLocationByCarrierId(mtrlname.CarrierID);
  933. if (lp == null)
  934. continue;
  935. if (Singleton<FAJobController>.Instance.FAloadports[lp].GetCarrierIDStatus() == CarrierIDStatus.ID_VERIFICATION_OK &&
  936. Singleton<FAJobController>.Instance.FAloadports[lp].GetSlotMapStatus() == SlotMapStatus.SLOT_MAP_VERIFICATION_OK)
  937. {
  938. pj.MaterialPresentAndResourceReady();
  939. AssignProcessJob(mtrlname, pj.RecID, pj.PRRecipeMethod, pj.RecVariableList, pj.ObjtID);
  940. }
  941. }
  942. }
  943. }
  944. foreach (var cj in cjs)
  945. {
  946. if (cj.state == ControlJobState.QUEUED)
  947. {
  948. bool allPjSetUp = true;
  949. cj.MtrlOutSpec = new List<MtrlOutSpecPair>();
  950. foreach (var pj in cj.ProcessingCtrlSpec)
  951. {
  952. if (!Singleton<FAJobController>.Instance.FAProcessJobs.ContainsKey(pj))
  953. {
  954. allPjSetUp = false;
  955. break;
  956. }
  957. if (Singleton<FAJobController>.Instance.FAProcessJobs[pj].PJstate != ProcessJobState.SETTING_UP)
  958. {
  959. allPjSetUp = false;
  960. break;
  961. }
  962. foreach (var PRMtl in Singleton<FAJobController>.Instance.FAProcessJobs[pj].PRMtlNameList)
  963. {
  964. cj.MtrlOutSpec.Add(new MtrlOutSpecPair() { sourceCarID = PRMtl.CarrierID, DestCarID = PRMtl.CarrierID, sourceSlots = PRMtl.SlotID, destSlots = PRMtl.SlotID });
  965. }
  966. }
  967. if (allPjSetUp)
  968. {
  969. cj.ProcessResourceReady();
  970. }
  971. }
  972. if (cj.MtrlOutSpec == null || cj.MtrlOutSpec.Count == 0)
  973. continue;
  974. //string sourceModule = "";
  975. //检查source ready
  976. if (cj.state == ControlJobState.SELECTED)
  977. {
  978. bool sourceReady = true;
  979. for (int i = 0; i < cj.MtrlOutSpec.Count; i++)
  980. {
  981. sourceModule = cj.MtrlOutSpec[i].sourceCarID;
  982. if (!CheckCJMaterialSourceReady(cj.MtrlOutSpec[i]) || !CheckCJMaterialDestReady(cj.MtrlOutSpec[i]))
  983. {
  984. sourceReady = false;
  985. break;
  986. }
  987. }
  988. if (!sourceReady)
  989. continue;
  990. Task.Delay(500).ContinueWith(x =>
  991. {
  992. cj.MaterialArrived();
  993. });
  994. Task.Delay(1000).ContinueWith(x =>
  995. {
  996. foreach (var pj in cj.ProcessingCtrlSpec)
  997. {
  998. Singleton<FAJobController>.Instance.FAProcessJobs[pj].MaterialReadyForProcessing();
  999. }
  1000. });
  1001. }
  1002. if (cj.state == ControlJobState.EXECUTING)
  1003. {
  1004. cj.MtrlOutSpec.Clear();
  1005. AssignControlJob(cj.ObjtID, CarrierManager.Instance.GetLocationByCarrierId(sourceModule), cj.ProcessingCtrlSpec);
  1006. }
  1007. }
  1008. return true;
  1009. }
  1010. public bool CheckCJMaterialSourceReady(MtrlOutSpecPair mtp)
  1011. {
  1012. string lp = CarrierManager.Instance.GetLocationByCarrierId(mtp.sourceCarID);
  1013. if (string.IsNullOrEmpty(lp)) return false;
  1014. if (Singleton<FAJobController>.Instance.FAloadports[lp].GetSlotMapStatus()
  1015. != SlotMapStatus.SLOT_MAP_VERIFICATION_OK) return false;
  1016. if (Singleton<FAJobController>.Instance.FAloadports[lp].GetCarrierIDStatus()
  1017. != CarrierIDStatus.ID_VERIFICATION_OK) return false;
  1018. foreach (var slot in mtp.sourceSlots)
  1019. {
  1020. var wafer = WaferManager.Instance.GetWafer((ModuleName)Enum.Parse(typeof(ModuleName), lp), slot - 1);
  1021. if (wafer.IsEmpty) return false;
  1022. if (wafer.SubstE90Status != EnumE90Status.NeedProcessing) return false;
  1023. }
  1024. return true;
  1025. }
  1026. public bool CheckCJMaterialDestReady(MtrlOutSpecPair mtp)
  1027. {
  1028. string lp = CarrierManager.Instance.GetLocationByCarrierId(mtp.DestCarID);
  1029. if (string.IsNullOrEmpty(lp)) return false;
  1030. if (Singleton<FAJobController>.Instance.FAloadports[lp].GetSlotMapStatus()
  1031. != SlotMapStatus.SLOT_MAP_VERIFICATION_OK) return false;
  1032. if (Singleton<FAJobController>.Instance.FAloadports[lp].GetCarrierIDStatus()
  1033. != CarrierIDStatus.ID_VERIFICATION_OK) return false;
  1034. return true;
  1035. }
  1036. public bool AssignProcessJob(ProcessMaterialName matrial, string recipe, ProcessRecipeMethod method, Dictionary<string, object> RecVariableList, string pjID)
  1037. {
  1038. string lp = CarrierManager.Instance.GetLocationByCarrierId(matrial.CarrierID);
  1039. string[] slotsequence = new string[25];
  1040. for (int i = 0; i < 25; i++)
  1041. {
  1042. if (matrial.SlotID.Contains(i + 1)) slotsequence[i] = recipe;
  1043. else slotsequence[i] = "";
  1044. }
  1045. Dictionary<string, object> para = new Dictionary<string, object>();
  1046. para.Add("JobId", pjID);
  1047. para.Add("Module", lp);
  1048. para.Add("SlotSequence", slotsequence);
  1049. para.Add("AutoStart", true);
  1050. //OP.DoOperation("System.CreateJob", new object[] { para });
  1051. List<int> slot = new List<int>();
  1052. foreach (var i in matrial.SlotID)
  1053. {
  1054. slot.Add(i - 1);
  1055. }
  1056. CheckToPostMessage((int)MSG.FAJobCommand, new object[] { "CreateProcessJob", pjID, recipe, slot, true });
  1057. return true;
  1058. }
  1059. public bool AssignControlJob(string cjID, string module, List<string> pjList)
  1060. {
  1061. //OP.DoOperation("System.StartJob", new object[] { pjID });
  1062. CheckToPostMessage((int)MSG.FAJobCommand, new object[] { "CreateControlJob", cjID, module, pjList, true });
  1063. return true;
  1064. }
  1065. private bool FsmFAJobCommand(object[] param)
  1066. {
  1067. switch ((string)param[0])
  1068. {
  1069. case "CreateProcessJob":
  1070. _auto.CreateProcessJob((string)param[1], (string)param[2], (List<int>)param[3], (bool)param[4]);
  1071. break;
  1072. case "CreateControlJob":
  1073. _auto.CreateControlJob((string)param[1], (string)param[2], (List<string>)param[3], (bool)param[4]);
  1074. CheckToPostMessage((int)MSG.StartJob, (string)param[1]);
  1075. break;
  1076. }
  1077. return true;
  1078. }
  1079. */
  1080. #endregion
  1081. public bool RegisterEvent(bool isAlarm, string eventname, string eventcontext)
  1082. {
  1083. return true;
  1084. }
  1085. public bool PostEvent(bool isAlarm, string eventname, Dictionary<string, string> dvid, Dictionary<string, object> objdvid)
  1086. {
  1087. return true;
  1088. }
  1089. public bool ExcuteCommand(string command, object[] paras, out string reason)
  1090. {
  1091. reason = "";
  1092. int portID;
  1093. string jobID;
  1094. string lotId;
  1095. object[] sequence;
  1096. string[] slotsequence;
  1097. LoadPortModuleBase lp;
  1098. switch (command.ToUpper())
  1099. {
  1100. case "PP-SELECT":
  1101. if(!IsAutoMode)
  1102. {
  1103. reason = "system is not auto";
  1104. return false;
  1105. }
  1106. portID = int.Parse(paras[0].ToString());
  1107. jobID = paras[1].ToString();
  1108. lotId = paras[2].ToString();
  1109. sequence = (object[])paras[3];
  1110. slotsequence = new string[25];
  1111. for (int i = 0; i < 25; i++)
  1112. {
  1113. slotsequence[i] = sequence[i].ToString() == "*null*" ? "" : sequence[i].ToString();
  1114. }
  1115. Dictionary<string, object> para = new Dictionary<string, object>();
  1116. para.Add("JobId", jobID);
  1117. para.Add("LotId", lotId);
  1118. para.Add("Module", ((ModuleName)portID).ToString());
  1119. para.Add("SlotSequence", slotsequence);
  1120. para.Add("AutoStart", true);
  1121. return CheckToPostMessage((int)MSG.CreateJob, para);
  1122. case "STARTJOB":
  1123. jobID = paras[0].ToString();
  1124. return CheckToPostMessage((int)MSG.StartJob, jobID);
  1125. case "ABORTJOB":
  1126. jobID = paras[0].ToString();
  1127. return _auto.AbortJob(jobID);
  1128. case "PAUSEJOB":
  1129. jobID = paras[0].ToString();
  1130. return _auto.PauseJob(jobID);
  1131. case "RESUMEJOB":
  1132. jobID = paras[0].ToString();
  1133. return _auto.ResumeJob(jobID);
  1134. case "STOPJOB":
  1135. jobID = paras[0].ToString();
  1136. return _auto.StopJob(jobID);
  1137. case "LOAD":
  1138. portID = int.Parse(paras[0].ToString());
  1139. lp = Modules[(ModuleName)portID] as LoadPortModuleBase;
  1140. if (lp != null)
  1141. {
  1142. return lp.Load();
  1143. }
  1144. reason = $"Not Find LP{portID}";
  1145. return false;
  1146. case "UNLOAD":
  1147. portID = int.Parse(paras[0].ToString());
  1148. lp = Modules[(ModuleName)portID] as LoadPortModuleBase;
  1149. if (lp != null)
  1150. {
  1151. return lp.Unload();
  1152. }
  1153. reason = $"Not Find LP{portID}";
  1154. return false;
  1155. case "MAPCASSETTE":
  1156. portID = int.Parse(paras[0].ToString());
  1157. var efem = Modules[ModuleName.EFEM] as EfemModuleBase;
  1158. if (efem != null && (portID == 1 || portID == 2))
  1159. {
  1160. return efem.Map((ModuleName)portID, out reason);
  1161. }
  1162. reason = $"Not Find LP{portID}";
  1163. return false;
  1164. case "READID":
  1165. case "READRFID":
  1166. case "READTAG":
  1167. portID = int.Parse(paras[0].ToString());
  1168. LoadPort lpDevice = DEVICE.GetDevice<LoadPort>("LP" + portID.ToString());
  1169. if (lpDevice != null)
  1170. {
  1171. return lpDevice.ReadRfId(out reason);
  1172. }
  1173. else
  1174. {
  1175. reason = $"Not Find LP{portID}";
  1176. return false;
  1177. }
  1178. case "CLAMP":
  1179. case "LOCK":
  1180. {
  1181. portID = int.Parse(paras[0].ToString());
  1182. lpDevice = DEVICE.GetDevice<LoadPort>("LP" + portID.ToString());
  1183. if (lpDevice != null)
  1184. {
  1185. return lpDevice.Clamp(out reason);
  1186. }
  1187. else
  1188. {
  1189. reason = $"Not Find LP{portID}";
  1190. return false;
  1191. }
  1192. }
  1193. case "UNCLAMP":
  1194. case "UNLOCK":
  1195. {
  1196. portID = int.Parse(paras[0].ToString());
  1197. lpDevice = DEVICE.GetDevice<LoadPort>("LP" + portID.ToString());
  1198. if (lpDevice != null)
  1199. {
  1200. return lpDevice.Unclamp(out reason);
  1201. }
  1202. else
  1203. {
  1204. reason = $"Not Find LP{portID}";
  1205. return false;
  1206. }
  1207. }
  1208. case "WRITEID":
  1209. case "WRITERFID":
  1210. case "WRITETAG":
  1211. {
  1212. portID = int.Parse(paras[0].ToString());
  1213. string rfid = paras[1].ToString();
  1214. lpDevice = DEVICE.GetDevice<LoadPort>("LP" + portID.ToString());
  1215. if (lpDevice != null)
  1216. {
  1217. return lpDevice.WriteRfId(rfid, out reason);
  1218. }
  1219. else
  1220. {
  1221. reason = $"Not Find LP{portID}";
  1222. return false;
  1223. }
  1224. }
  1225. }
  1226. return true;
  1227. }
  1228. public string[] GetRecipeList(string param)
  1229. {
  1230. if (param == "SEQUENCE")
  1231. return RecipeFileManager.Instance.GetSequenceNameList().ToArray();
  1232. if (param == "PMA")
  1233. return RecipeFileManager.Instance.GetRecipes("PMA", true).ToArray();
  1234. if (param == "PMB")
  1235. return RecipeFileManager.Instance.GetRecipes("PMB", true).ToArray();
  1236. return RecipeFileManager.Instance.GetSequenceNameList().ToArray();
  1237. }
  1238. public string GetRecipeBody(string param, string recipename)
  1239. {
  1240. if (param == "SEQUENCE")
  1241. return RecipeFileManager.Instance.GetSequence(recipename, false);
  1242. if (param == "PMA")
  1243. return RecipeFileManager.Instance.LoadRecipe("PMA", recipename, false);
  1244. if (param == "PMB")
  1245. return RecipeFileManager.Instance.LoadRecipe("PMB", recipename, false);
  1246. return RecipeFileManager.Instance.GetSequence(recipename, false);
  1247. }
  1248. public string[] GetSequenceList()
  1249. {
  1250. return RecipeFileManager.Instance.GetSequenceNameList().ToArray();
  1251. }
  1252. public string GetSequenceBody(string ppid)
  1253. {
  1254. return RecipeFileManager.Instance.GetSequence(ppid, false);
  1255. }
  1256. public List<string> GetFormatedSequence(string ppid)
  1257. {
  1258. List<string> result = new List<string>();
  1259. string reason = string.Empty;
  1260. try
  1261. {
  1262. string content = "";
  1263. if (ppid.StartsWith("PMA") || ppid.StartsWith("PMB") || ppid.StartsWith("PMC"))
  1264. {
  1265. content = RecipeFileManager.Instance.LoadRecipe("", ppid, false);
  1266. }
  1267. else
  1268. {
  1269. content = RecipeFileManager.Instance.GetSequence(ppid, false);
  1270. }
  1271. result.Add(content);
  1272. }
  1273. catch (Exception ex)
  1274. {
  1275. reason = ex.Message;
  1276. }
  1277. return result;
  1278. }
  1279. public bool deleteSequence(string ppid)
  1280. {
  1281. return RecipeFileManager.Instance.DeleteSequence(ppid);
  1282. }
  1283. public bool UpdateSequence(string ppid, string body)
  1284. {
  1285. return RecipeFileManager.Instance.SaveSequence(ppid, body, false);
  1286. }
  1287. public void ShowTerminalMessage(string message)
  1288. {
  1289. }
  1290. /// <summary>
  1291. /// 创建ProcessJob
  1292. /// </summary>
  1293. /// <param name="processJobId"></param>
  1294. /// <param name="sequenceName"></param>
  1295. /// <param name="carrierId"></param>
  1296. /// <returns></returns>
  1297. public bool CreateProcessJob(string processJobId, string sequenceName,string carrierId,out string reason)
  1298. {
  1299. if(!IsAutoMode)
  1300. {
  1301. reason = "system is not auto";
  1302. return false;
  1303. }
  1304. return _auto.CreateProcessJob(processJobId, sequenceName,carrierId, out reason);
  1305. }
  1306. /// <summary>
  1307. /// 更新processJob carrierSlot信息
  1308. /// </summary>
  1309. /// <param name="processJobId"></param>
  1310. /// <param name="moduleName"></param>
  1311. /// <param name="slots"></param>
  1312. public void UpdateProcessJobCarrierSlot(string processJobId, string moduleName, List<int> slots)
  1313. {
  1314. _auto.UpdateProcessJobSlotWafer(processJobId, moduleName, slots);
  1315. }
  1316. /// <summary>
  1317. /// 检验创建ControlJob的条件
  1318. /// </summary>
  1319. /// <returns></returns>
  1320. public bool CheckCreateControlJobCondition(List<string> modules, out string reason)
  1321. {
  1322. if (!IsAutoMode)
  1323. {
  1324. reason = "system is not auto";
  1325. return false;
  1326. }
  1327. return _auto.CheckCreateControlJobCondition(modules,out reason);
  1328. }
  1329. /// <summary>
  1330. /// 创建ControlJob
  1331. /// </summary>
  1332. /// <param name="controlJobId"></param>
  1333. /// <param name="moduleName"></param>
  1334. /// <param name="carrierId"></param>
  1335. /// <param name="processJobs"></param>
  1336. /// <param name="reason"></param>
  1337. /// <returns></returns>
  1338. public void CreateControlJob(string controlJobId, string carrierId, List<string> processJobs)
  1339. {
  1340. _auto.CreateControlJob(controlJobId, carrierId, processJobs);
  1341. }
  1342. /// <summary>
  1343. /// 更新ControlJob Module信息
  1344. /// </summary>
  1345. /// <param name="controlJobId"></param>
  1346. /// <param name="moduleName"></param>
  1347. public void UpdateControlJobModule(string controlJobId, string moduleName)
  1348. {
  1349. _auto.UpdateControlJobModule(controlJobId, moduleName);
  1350. }
  1351. /// <summary>
  1352. /// 启动任务
  1353. /// </summary>
  1354. /// <param name="controlJob"></param>
  1355. /// <returns></returns>
  1356. public bool StartControlJob(string controlJob)
  1357. {
  1358. return CheckToPostMessage((int)MSG.StartJob, controlJob);
  1359. }
  1360. /// <summary>
  1361. /// 停止任务
  1362. /// </summary>
  1363. /// <param name="controlJob"></param>
  1364. /// <returns></returns>
  1365. public bool StopControlJob(string controlJob)
  1366. {
  1367. return CheckToPostMessage((int)MSG.StopJob, controlJob);
  1368. }
  1369. /// <summary>
  1370. /// 中止任务
  1371. /// </summary>
  1372. /// <param name="controlJob"></param>
  1373. /// <returns></returns>
  1374. public bool AbortControlJob(string controlJob)
  1375. {
  1376. return CheckToPostMessage((int)MSG.AbortJob, controlJob);
  1377. }
  1378. /// <summary>
  1379. /// 暂停任务
  1380. /// </summary>
  1381. /// <param name="controlJob"></param>
  1382. /// <returns></returns>
  1383. public bool PauseControlJob(string controlJob)
  1384. {
  1385. return CheckToPostMessage((int)MSG.PauseJob, controlJob);
  1386. }
  1387. /// <summary>
  1388. /// 启动任务
  1389. /// </summary>
  1390. /// <param name="controlJob"></param>
  1391. /// <returns></returns>
  1392. public bool ResumeControlJob(string controlJob)
  1393. {
  1394. return CheckToPostMessage((int)MSG.ResumeJob, controlJob);
  1395. }
  1396. /// <summary>
  1397. /// 检验Auto
  1398. /// </summary>
  1399. /// <returns></returns>
  1400. public bool CheckAuto()
  1401. {
  1402. return IsAutoMode;
  1403. }
  1404. /// <summary>
  1405. /// 告警日志
  1406. /// </summary>
  1407. /// <param name="message"></param>
  1408. public void WriteWarningLog(string message)
  1409. {
  1410. LOG.Warning($"EAP {message}");
  1411. }
  1412. /// <summary>
  1413. /// 错误日志
  1414. /// </summary>
  1415. /// <param name="message"></param>
  1416. public void WriteErrorLog(string message)
  1417. {
  1418. EV.PostAlarmLog("EAP", $"EAP {message}");
  1419. }
  1420. /// <summary>
  1421. /// 正常日志
  1422. /// </summary>
  1423. /// <param name="message"></param>
  1424. public void WriteInfoLog(string message)
  1425. {
  1426. LOG.Write($"EAP {message}" );
  1427. }
  1428. }
  1429. }