EquipmentManager.cs 65 KB

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