EquipmentManager.cs 65 KB

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