PMEntity.cs 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240
  1. using System;
  2. using System.Linq;
  3. using System.Windows.Forms;
  4. using Aitex.Core.RT.Device.Unit;
  5. using Aitex.Core.RT.Fsm;
  6. using Aitex.Core.RT.Job;
  7. using Aitex.Core.Utilities;
  8. using Aitex.RT.Properties;
  9. using Aitex.Triton160.RT.Device;
  10. using Aitex.Triton160.RT.Routine.PM;
  11. using Aitex.Core.RT.DataCenter;
  12. using Aitex.Triton160.Common;
  13. using Aitex.Triton160.RT.Routine.Process;
  14. using Aitex.Core.RT.Event;
  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.RT.FactoryAutomation;
  21. using System.Threading.Tasks;
  22. using Aitex.Core.MES;
  23. using Aitex.Core.MES.YZQZ;
  24. using System.Collections.Generic;
  25. namespace Aitex.Triton160.RT.Module
  26. {
  27. public enum EnumEquipmentMode
  28. {
  29. Auto,
  30. Manual,
  31. }
  32. public enum EnumEquipmentStatus
  33. {
  34. Uninit,
  35. Idle,
  36. Running,
  37. Error,
  38. }
  39. public class PMEntity : Entity, IEntity
  40. {
  41. //public enum STATE
  42. //{
  43. //};
  44. public enum MSG
  45. {
  46. Idle,
  47. SetAutoMode,
  48. SetManualMode,
  49. Abort,
  50. Vent,
  51. PumpDown,
  52. StopPumpDown,
  53. GasFlow,
  54. StopGasFlow,
  55. RfPower,
  56. CyclePurge,
  57. LeakCheck,
  58. RunRecipe,
  59. Process,
  60. PreProcess,
  61. PostProcess,
  62. RciepeAbort,
  63. RecipeSkipStep,
  64. RecipePause,
  65. RecipeResume,
  66. RecipeUpdate,
  67. Error,
  68. Reset,
  69. };
  70. private VentRountine _ventRountine = new VentRountine(ModuleName.System.ToString(), "Vent");
  71. private PumpDownRoutine _pumpRoutine = new PumpDownRoutine(ModuleName.System.ToString(), "Pump");
  72. private StopPumpRoutine _stopPumpRoutine = new StopPumpRoutine(ModuleName.System.ToString(), "Stop Pump");
  73. private GasFlowRoutine _gasFlowRoutine = new GasFlowRoutine(ModuleName.System.ToString(), "Gas Flow");
  74. private StopGasFlowRoutine _stopGasFlowRoutine = new StopGasFlowRoutine(ModuleName.System.ToString(), "Stop Gas Flow");
  75. private RfPowerRoutine _rfPowerRoutine = new RfPowerRoutine(ModuleName.System.ToString(), "Rf PowerOn");
  76. private CyclePurgeRoutine cyclePurgeRoutine = new CyclePurgeRoutine(ModuleName.System.ToString(), "Cycle Purge");
  77. private Process processRoutine = new Process(ModuleName.System.ToString(), "Process");
  78. private PreProcess preProcessRoutine = new PreProcess(ModuleName.System.ToString(), "PreProcess");
  79. private PostProcess postProcessRoutine = new PostProcess(ModuleName.System.ToString(), "PostProcess");
  80. private LeakCheckRoutine _leakCheckRoutine = new LeakCheckRoutine(ModuleName.System.ToString(), "Leak Check");
  81. public string Name { get; set; }
  82. public bool IsIdle { get { return fsm.State == (int)PMState.Idle; } }
  83. public string Status { get { return fsm.State.ToString(); } }
  84. public bool IsAutoMode
  85. {
  86. get;
  87. private set;
  88. }
  89. public bool IsProcessMode { get { return (fsm.State == (int)PMState.LoadProcessRecipe) || (fsm.State == (int)PMState.Processing) || (fsm.State == (int)PMState.PreProcess) || (fsm.State == (int)PMState.PostProcess); } }
  90. public bool IsRunRecipe { get { return (fsm.State == (int)PMState.Processing); } }
  91. //public bool IsAlarm { get; private set; }
  92. //public bool IsWarning { get; private set; }
  93. //public Guid CurrentRecipeRunGuid { get; set; }
  94. public JobInfo CurrentRunningJob
  95. {
  96. get; set;
  97. }
  98. private string _processStatus = string.Empty;
  99. private DateTime _pumpStartTime;
  100. private TimeSpan _pumpElapsedTime;
  101. private string PumpTime
  102. {
  103. get
  104. {
  105. if ((fsm.State == (int)PMState.Pumping) || (fsm.State == (int)PMState.PreProcess))
  106. _pumpElapsedTime = DateTime.Now - _pumpStartTime;
  107. return string.Format("{0}:{1}:{2}", ((int)_pumpElapsedTime.TotalHours).ToString("00"),
  108. _pumpElapsedTime.Minutes.ToString("00"), _pumpElapsedTime.Seconds.ToString("00"));
  109. }
  110. }
  111. //private int _rfTime;
  112. //int RfTime
  113. //{
  114. // get
  115. // {
  116. // if (fsm.State == (int)PMState.RfPowering)
  117. // _rfTime = _rfPowerRoutine.Elapsed;
  118. // else
  119. // {
  120. // _rfTime = 0;
  121. // }
  122. // return _rfTime;
  123. // }
  124. //}
  125. bool IsPumpingOkForProcess
  126. {
  127. get
  128. {
  129. return DeviceModel.MainPump.IsRunning &&
  130. DeviceModel.ValveChamberPumping.Status;
  131. }
  132. }
  133. bool IsGasFlowingOkForProcess
  134. {
  135. get
  136. {
  137. if (!IsPumpingOkForProcess)
  138. return false;
  139. if (! ( (DeviceModel.ValveProcessGasFinal!=null && DeviceModel.ValveProcessGasFinal.Status)))
  140. return false;
  141. IoValve[] valves = { DeviceModel.ValveMfc1, DeviceModel.ValveMfc2 , DeviceModel.ValveMfc3, DeviceModel.ValveMfc4, DeviceModel.ValveMfc5};
  142. if (!Array.Exists(valves, v => v!=null && v.Status))
  143. return false;
  144. IoMfc[] mfcs = { DeviceModel.MfcGas1, DeviceModel.MfcGas2, DeviceModel.MfcGas3, DeviceModel.MfcGas4, DeviceModel.MfcGas5 };
  145. if (!Array.Exists(mfcs, m => m!=null && m.FeedBack > 0.1))
  146. return false;
  147. return true ;
  148. }
  149. }
  150. private DateTime _recipeStartTime;
  151. private TimeSpan _recipeElapsedTime;
  152. public string RecipeElapsedTime
  153. {
  154. get
  155. {
  156. if (fsm.State == (int) PMState.LoadProcessRecipe || fsm.State == (int) PMState.PreProcess
  157. || fsm.State == (int) PMState.Processing || fsm.State == (int) PMState.PostProcess)
  158. _recipeElapsedTime = DateTime.Now - _recipeStartTime;
  159. return string.Format("{0}:{1}:{2}", ((int)_recipeElapsedTime.TotalHours).ToString("00"),
  160. _recipeElapsedTime.Minutes.ToString("00"), _recipeElapsedTime.Seconds.ToString("00"));
  161. }
  162. }
  163. private DateTime _leakCheckStartTime;
  164. private TimeSpan _leakCheckElapsedTime;
  165. private string LeakCheckElapseTime
  166. {
  167. get
  168. {
  169. if ((fsm.State == (int)PMState.LeakCheck) )
  170. _leakCheckElapsedTime = DateTime.Now - _leakCheckStartTime;
  171. return string.Format("{0}:{1}:{2}", ((int)_leakCheckElapsedTime.TotalHours).ToString("00"),
  172. _leakCheckElapsedTime.Minutes.ToString("00"), _leakCheckElapsedTime.Seconds.ToString("00"));
  173. }
  174. }
  175. private const string EventCarrierLoaded = "CarrierLoaded";
  176. private const string EventCarrierUnloaded = "CarrierUnloaded";
  177. private const string EventLotStart = "LotStart";
  178. private const string EventLotFinished = "LotFinished";
  179. private const string EventEquipmentStatusChanged = "EquipmentStatusChanged";
  180. private const string EventEquipmentModeChanged = "EquipmentModeChanged";
  181. private int _preEquipmentState;
  182. public PMEntity()
  183. {
  184. Running = false;
  185. IsAutoMode = false;
  186. //IsAlarm = false;
  187. //IsWarning = false;
  188. Name = "Chamber";
  189. fsm = new StateMachine<PMEntity>(Name, (int)PMState.Init, 50);
  190. EnterExitTransition<PMState, MSG>(PMState.Init, fEnterInit, MSG.Idle, null);
  191. Transition(PMState.Init, MSG.Idle, fInit, PMState.Idle);
  192. EnterExitTransition<PMState, FSM_MSG>(PMState.Error, fEnterError, FSM_MSG.NONE, null);
  193. AnyStateTransition(FSM_MSG.WARNING, fWarning, FSM_STATE.SAME);
  194. AnyStateTransition((int)FSM_MSG.ALARM, fAlarm, (int)PMState.Error);
  195. AnyStateTransition(MSG.Reset, fReset, PMState.Idle);
  196. //Auto/manual sequence
  197. Transition(PMState.Idle, MSG.SetAutoMode, fSetAutoMode, PMState.Idle);
  198. Transition(PMState.Idle, MSG.SetManualMode, fSetManualMode, PMState.Idle);
  199. //vent sequence
  200. Transition(PMState.Idle, MSG.Vent, fStartVent, PMState.Vent);
  201. Transition(PMState.Vent, FSM_MSG.TIMER, fVent, PMState.Idle);
  202. Transition(PMState.Vent, MSG.Abort, fAbortVent, PMState.Idle);
  203. Transition(PMState.Vent, MSG.PumpDown, fVentToPumping, PMState.Pumping);
  204. //Pump sequence
  205. Transition(PMState.Idle, MSG.PumpDown, fStartPumpDown, PMState.Pumping);
  206. Transition(PMState.Pumping, FSM_MSG.TIMER, fPumpDown, PMState.Idle);
  207. Transition(PMState.Pumping, MSG.Abort, fAbortPumping, PMState.Idle);
  208. Transition(PMState.Pumping, MSG.Vent, fPumpingToVent, PMState.Vent);
  209. //Stop Pump sequence
  210. Transition(PMState.Idle, MSG.StopPumpDown, fStartStopPump, PMState.StopPumping);
  211. Transition(PMState.StopPumping, FSM_MSG.TIMER, fStopPump, PMState.Idle);
  212. Transition(PMState.StopPumping, MSG.Abort, fAbortStopPump, PMState.Idle);
  213. //Gas Flow sequence
  214. Transition(PMState.Idle, MSG.GasFlow, fStartGasFlow, PMState.GasFlowing);
  215. Transition(PMState.GasFlowing, FSM_MSG.TIMER, fGasFlow, PMState.Idle);
  216. Transition(PMState.GasFlowing, MSG.Abort, fAbortGasFlow, PMState.Idle);
  217. //Stop Gas Flow sequence
  218. Transition(PMState.Idle, MSG.StopGasFlow, fStartStopGasFlow, PMState.StopGasFlowing);
  219. Transition(PMState.StopGasFlowing, FSM_MSG.TIMER, fStopGasFlow, PMState.Idle);
  220. Transition(PMState.StopGasFlowing, MSG.Abort, fAbortStopGasFlow, PMState.Idle);
  221. //RF Power sequence
  222. Transition(PMState.Idle, MSG.RfPower, fStartRfPower, PMState.RfPowering);
  223. Transition(PMState.RfPowering, FSM_MSG.TIMER, fRfPower, PMState.Idle);
  224. Transition(PMState.RfPowering, MSG.Abort, fAbortRfPower, PMState.Idle);
  225. //Leak check sequence
  226. Transition(PMState.Idle, MSG.LeakCheck, fStartLeakCheck, PMState.LeakCheck);
  227. Transition(PMState.LeakCheck, FSM_MSG.TIMER, fLeakCheck, PMState.Idle);
  228. Transition(PMState.LeakCheck, MSG.Abort, fAbortLeakCheck, PMState.Idle);
  229. //CyclePurge sequence
  230. Transition(PMState.Idle, MSG.CyclePurge, fStartCyclePurge, PMState.CyclePurge);
  231. Transition(PMState.CyclePurge, FSM_MSG.TIMER, fCyclePurge, PMState.Idle);
  232. Transition(PMState.CyclePurge, MSG.Abort, fAbortCyclePurge, PMState.Idle);
  233. //PreProcess sequence
  234. Transition(PMState.Idle, MSG.RunRecipe, fProcessLoadRecipe, PMState.LoadProcessRecipe );
  235. Transition(PMState.LoadProcessRecipe, MSG.PreProcess, fStartPreProcess, PMState.PreProcess);
  236. Transition(PMState.LoadProcessRecipe, MSG.Abort, null, PMState.Idle);
  237. Transition(PMState.LoadProcessRecipe, MSG.Error, null, PMState.Idle);
  238. Transition(PMState.PreProcess, FSM_MSG.TIMER, fPreProcess, PMState.PreProcess);
  239. Transition(PMState.PreProcess, MSG.Abort, fAbortPreProcess, PMState.Idle);
  240. Transition(PMState.PreProcess, MSG.RciepeAbort, fAbortPreProcess, PMState.Idle);
  241. Transition(PMState.PreProcess, MSG.Error, fAbortPreProcess, PMState.Error);
  242. Transition(PMState.PreProcess, MSG.Process, fStartProcess, PMState.Processing);
  243. Transition(PMState.Processing, FSM_MSG.TIMER, fProcess, PMState.Processing);
  244. Transition(PMState.Processing, MSG.Error, fAbortProcess, PMState.Error);
  245. Transition(PMState.Processing, MSG.RciepeAbort, fAbortProcess, PMState.PostProcess);
  246. Transition(PMState.Processing, MSG.RecipePause, fPauseProcess, PMState.Processing);
  247. Transition(PMState.Processing, MSG.RecipeResume, fResumeRecipe, PMState.Processing);
  248. Transition(PMState.Processing, MSG.RecipeUpdate, fUpdateRecipe, PMState.Processing);
  249. Transition(PMState.Processing, MSG.RecipeSkipStep, fSkipStep, PMState.Processing);
  250. EnterExitTransition<PMState,FSM_MSG>(PMState.Processing, fEnterProcess, FSM_MSG.NONE, fExitProcess);
  251. //PostProcess sequence
  252. Transition(PMState.Processing, MSG.PostProcess, fStartPostProcess, PMState.PostProcess);
  253. Transition(PMState.PostProcess, FSM_MSG.TIMER, fPostProcess, PMState.Idle);
  254. Transition(PMState.PostProcess, MSG.Abort, fAbortPostProcess, PMState.Idle);
  255. Transition(PMState.PostProcess, MSG.RciepeAbort, fAbortPostProcess, PMState.Idle);
  256. EnterExitTransition<PMState, FSM_MSG>(PMState.PostProcess, null, FSM_MSG.NONE, fExitPostProcess);
  257. DATA.Subscribe(ModuleName.System.ToString(), StateData.IsAutoMode.ToString(), () => IsAutoMode);
  258. DATA.Subscribe(ModuleName.System.ToString(), StateData.PMState.ToString(), () => fsm.State);
  259. DATA.Subscribe(ModuleName.System.ToString(), StateData.IsPumpingOkForProcess.ToString(), () => IsPumpingOkForProcess);
  260. DATA.Subscribe(ModuleName.System.ToString(), StateData.IsGasFlowingOkForProcess.ToString(), () => IsGasFlowingOkForProcess);
  261. DATA.Subscribe(ModuleName.System.ToString(), StateData.PumpTime.ToString(), () => PumpTime);
  262. //DATA.Subscribe(ModuleName.System.ToString(), StateData.RfTimeElapsed.ToString(), () => RfTime);
  263. DATA.Subscribe(ModuleName.System.ToString(), StateData.RecipeStepRfTimeSetPoint.ToString(), () => (processRoutine.CurStepTotalRfTime /1000).ToString("F0"));
  264. DATA.Subscribe(ModuleName.System.ToString(), StateData.RecipeStepTimeElapsed.ToString(), () => (processRoutine.CurStepElpasedTime / 1000).ToString("F0"));
  265. DATA.Subscribe(ModuleName.System.ToString(), StateData.RecipeStepTimeSetPoint.ToString(), () => (processRoutine.CurStepTotalTime / 1000) .ToString("F0"));
  266. DATA.Subscribe(ModuleName.System.ToString(), StateData.ProcessStatus.ToString(), () => _processStatus);
  267. DATA.Subscribe(ModuleName.System.ToString(), StateData.RecipeProcessTime.ToString(), () => RecipeElapsedTime);
  268. DATA.Subscribe(ModuleName.System.ToString(), StateData.LeakCheckElapseTime.ToString(), () => LeakCheckElapseTime);
  269. DATA.Subscribe(string.Format("{0}.{1}", ModuleName.System, StateData.AlarmEvent), EV.GetAlarmEvent);
  270. DATA.Subscribe(ModuleName.System.ToString(), StateData.RecipeStepNo.ToString(), () => processRoutine.CurStepNum + 1);
  271. DATA.Subscribe(ModuleName.System.ToString(), StateData.RecipeName.ToString(), () =>
  272. {
  273. switch ((PMState)fsm.State)
  274. {
  275. case PMState.PreProcess:
  276. return preProcessRoutine.CurrentRecipeBaseName;
  277. default:
  278. return processRoutine.CurrentRecipeBaseName;
  279. }
  280. });
  281. DATA.Subscribe(ModuleName.System.ToString(), StateData.TotalCycle.ToString(), () => processRoutine.TotalCycle);
  282. DATA.Subscribe(ModuleName.System.ToString(), StateData.DataLogName.ToString(), () => processRoutine.CurrentRecipeRunningName);
  283. DATA.Subscribe(ModuleName.System.ToString(), StateData.LotName.ToString(), () =>
  284. {
  285. switch ((PMState)fsm.State)
  286. {
  287. case PMState.PreProcess:
  288. return preProcessRoutine.CurrentLotName;
  289. default:
  290. return processRoutine.CurrentLotName;
  291. }
  292. });
  293. DATA.Subscribe("RecipeList", () => RecipeFileManager.Instance.GetRecipes("System", false).ToList());
  294. DATA.Subscribe("EquipmentMode", () => { return (int) (IsAutoMode ? EnumEquipmentMode.Auto : EnumEquipmentMode.Manual); });
  295. DATA.Subscribe("EquipmentStatus", () =>
  296. {
  297. int result = 0;
  298. switch ((PMState)fsm.State)
  299. {
  300. case PMState.Error:
  301. result = (int) EnumEquipmentStatus.Error;
  302. break;
  303. case PMState.Init:
  304. result = (int) EnumEquipmentStatus.Uninit;
  305. break;
  306. case PMState.Idle:
  307. result = (int) EnumEquipmentStatus.Idle;
  308. break;
  309. default:
  310. result = (int) EnumEquipmentStatus.Running;
  311. break;
  312. }
  313. if (_preEquipmentState != result)
  314. {
  315. EV.Notify(EventEquipmentStatusChanged, new SerializableDictionary<string, string>());
  316. }
  317. _preEquipmentState = result;
  318. return result;
  319. });
  320. EnumLoop<PMState>.ForEach((item) =>
  321. {
  322. fsm.MapState((int)item, item.ToString());
  323. });
  324. EnumLoop<MSG>.ForEach((item) =>
  325. {
  326. fsm.MapMessage((int)item, item.ToString());
  327. });
  328. EV.Subscribe(new EventItem("Event", EventCarrierLoaded, "Event Carrier Loaded"));
  329. EV.Subscribe(new EventItem("Event", EventCarrierUnloaded, "Event Carrier Unloaded"));
  330. EV.Subscribe(new EventItem("Event", EventLotStart, "EventLotStart"));
  331. EV.Subscribe(new EventItem("Event", EventLotFinished, "EventLotFinished"));
  332. EV.Subscribe(new EventItem("Event", EventEquipmentStatusChanged, "EventEquipmentStatusChanged"));
  333. EV.Subscribe(new EventItem("Event", EventEquipmentModeChanged, "EventEquipmentModeChanged"));
  334. OP.Subscribe("CarrierLoad", (string cmd, object[] args) =>
  335. {
  336. var dvid = new SerializableDictionary<string, string>();
  337. EV.Notify(EventCarrierLoaded, dvid);
  338. return true;
  339. });
  340. OP.Subscribe("CarrierUnload", (string cmd, object[] args) =>
  341. {
  342. //var dvid = new SerializableDictionary<string, string>();
  343. //EV.Notify(EventCarrierUnloaded, dvid);
  344. EV.Notify(EventCarrierUnloaded, new SerializableDictionary<string, string>()
  345. {
  346. {DVIDName.LotId, preProcessRoutine.CurrentLotName},
  347. {DVIDName.JobId, preProcessRoutine.CurrentJobName},
  348. {DVIDName.RecipeId, preProcessRoutine.CurrentRecipeBaseName }
  349. });
  350. return true;
  351. });
  352. }
  353. public Tuple<string, string> GetRecipeInfo()
  354. {
  355. if (fsm.State == (int)PMState.PreProcess)
  356. return new Tuple<string, string>(preProcessRoutine.CurrentRecipeRunningName, preProcessRoutine.CurrentRecipeContent);
  357. else if(fsm.State == (int)PMState.Processing)
  358. return new Tuple<string, string>(processRoutine.CurrentRecipeRunningName, processRoutine.CurrentRecipeContent);
  359. return new Tuple<string, string>(String.Empty, String.Empty);
  360. }
  361. public bool Check(int msg, out string reason, params object[] args)
  362. {
  363. if (!fsm.FindTransition(fsm.State, msg))
  364. {
  365. reason = String.Format("{0} is in {1},can not do {2}", Name, (PMState)fsm.State, (MSG)msg);
  366. return false;
  367. }
  368. bool bRet = true;
  369. reason = "";
  370. switch (msg)
  371. {
  372. case (int)MSG.RunRecipe:
  373. if (fsm.State != (int)PMState.Idle)
  374. {
  375. reason = String.Format("{0} Is In {1},Can not do {2}", Name, (PMState)fsm.State, (MSG)msg);
  376. bRet = false;
  377. }
  378. break;
  379. case (int)MSG.RecipePause:
  380. case (int)MSG.RecipeResume:
  381. case (int)MSG.RecipeSkipStep:
  382. case (int)MSG.RecipeUpdate:
  383. if (fsm.State != (int)PMState.Processing)
  384. {
  385. reason = String.Format("{0} not running recipe,can not do {1}", Name, (MSG)(msg));
  386. bRet = false;
  387. }
  388. break;
  389. default:
  390. break;
  391. }
  392. return bRet;
  393. }
  394. protected override bool Init()
  395. {
  396. _rfPowerRoutine.Initialize();
  397. _gasFlowRoutine.Initialize();
  398. _stopGasFlowRoutine.Initialize();
  399. _pumpRoutine.Initialize();
  400. _stopPumpRoutine.Initialize();
  401. cyclePurgeRoutine.Initialize();
  402. _ventRountine.Initialize();
  403. processRoutine.Initialize();
  404. preProcessRoutine.Initialize();
  405. postProcessRoutine.Initialize();
  406. _leakCheckRoutine.Initialize();
  407. Running = true;
  408. Default();
  409. return true;
  410. }
  411. private bool fSetAutoMode(object[] objs)
  412. {
  413. if (IsAutoMode)
  414. return true;
  415. IsAutoMode = true;
  416. EV.Notify(EventEquipmentModeChanged, new SerializableDictionary<string, string>()
  417. {
  418. });
  419. EV.PostMessage(ModuleNameString.System, Triton160EventEnum.RunningModeChanged, Resources.GlobalLableAutoMode);
  420. return true;
  421. }
  422. private bool fSetManualMode(object[] objs)
  423. {
  424. if (!IsAutoMode)
  425. return true;
  426. if (SC.GetValue<bool>(SCName.System_EnableFa)
  427. && Singleton<FaManager>.Instance.FaControlState== "OnlineRemote"
  428. && Singleton<FaManager>.Instance.FaCommunicationState == "EnabledCommunicating")
  429. {
  430. EV.PostWarningLog("System", Aitex.RT.Properties.Resources.SystemInOnlineRemoteModeCanNotSwitchToManualSwitchOffHostControlFirst);
  431. return true;
  432. }
  433. IsAutoMode = false;
  434. EV.Notify(EventEquipmentModeChanged, new SerializableDictionary<string, string>()
  435. {
  436. });
  437. EV.PostMessage(ModuleNameString.System, Triton160EventEnum.RunningModeChanged, Resources.GlobalLableManualMode );
  438. return true;
  439. }
  440. private bool fEnterInit(object[] objs)
  441. {
  442. return true;
  443. }
  444. private bool fInit(object[] objs)
  445. {
  446. return true;
  447. }
  448. private bool fEnterError(object[] objs)
  449. {
  450. if (IsProcessMode)
  451. {
  452. EV.Notify(EventLotFinished, new SerializableDictionary<string, string>()
  453. {
  454. {DVIDName.LotId, preProcessRoutine.CurrentLotName},
  455. {DVIDName.JobId, preProcessRoutine.CurrentJobName},
  456. {DVIDName.RecipeId, preProcessRoutine.CurrentRecipeBaseName }
  457. });
  458. }
  459. return true;
  460. }
  461. private bool fWarning(object[] objs)
  462. {
  463. //IsWarning = false;
  464. return true;
  465. }
  466. private bool fAlarm(object[] objs)
  467. {
  468. StartJobRecord(false);
  469. if (fsm.State == (int)PMState.Init)
  470. return false;
  471. if (fsm.State == (int) PMState.Processing)
  472. {
  473. PostMsg(MSG.Error);
  474. MESErrorRecordAlarm(processRoutine.CurrentLotName, processRoutine.CurrentRecipeBaseName, objs);
  475. return false;
  476. }
  477. //IsAlarm = true;
  478. return true;
  479. }
  480. private async void MESErrorRecordAlarm(string lotId, string receipeName, object[] objs)
  481. {
  482. await Task.Run(() => {
  483. string erroMsg=string.Empty;
  484. if (objs != null && objs.Length > 0)
  485. { foreach (var o in objs)
  486. erroMsg += o.ToString()+"|";
  487. }
  488. erroMsg= erroMsg.TrimEnd('|');
  489. Fab fb = (Fab)Enum.Parse(typeof(Fab), SC.GetValue<int>(SCName.System_Company).ToString());
  490. if (fb == Fab.YZQZ)
  491. {
  492. List<RequestMachineErrorRecord> records = new List<RequestMachineErrorRecord>();
  493. FabAutoComm com = new YZQZFabAuto();
  494. lotId = lotId.TrimEnd('/');
  495. string[] items = lotId.Split('/');
  496. foreach (var item in items)
  497. {
  498. RequestMachineErrorRecord record = new RequestMachineErrorRecord() { LotId = item, RecipeName = receipeName, MachineNumber = SC.GetSCString(SCName.System_YZQZMachineNumber).Value, MachineType = SC.GetSCString(SCName.System_YZQZMachineType).Value, ErrorMessage = erroMsg };
  499. records.Add(record);
  500. }
  501. com.SaveMachineErrorRecord(records);
  502. }
  503. });
  504. }
  505. private bool fReset(object[] objs)
  506. {
  507. //IsAlarm = false;
  508. if (fsm.State == (int)PMState.Error)
  509. return true;
  510. return false;
  511. }
  512. public void ToggleChamberStatus()
  513. {
  514. string reason = string.Empty;
  515. }
  516. public void Default()
  517. {
  518. }
  519. public void AlarmEvent()
  520. {
  521. }
  522. #region Vent
  523. private bool fStartVent(object[] objs)
  524. {
  525. Result ret = _ventRountine.Start();
  526. if (ret == Result.DONE)
  527. {
  528. return false;
  529. }
  530. else if (ret == Result.FAIL)
  531. {
  532. return false; //do noting
  533. }
  534. return true;
  535. }
  536. private bool fVent(object[] objs)
  537. {
  538. Result ret = _ventRountine.Monitor();
  539. if (ret == Result.DONE)
  540. return true;
  541. else if (ret == Result.FAIL)
  542. {
  543. //do nothing
  544. return true;
  545. }
  546. return false; ;
  547. }
  548. private bool fAbortVent(object[] objs)
  549. {
  550. _ventRountine.Abort();
  551. return true;
  552. }
  553. private bool fVentToPumping(object[] objs)
  554. {
  555. if (_ventRountine.Abort() != Result.DONE)
  556. {
  557. PostMsg(MSG.Error);
  558. return true;
  559. }
  560. fStartPumpDown(null);
  561. return true;
  562. }
  563. #endregion
  564. #region Pumping
  565. private bool fStartPumpDown(object[] objs)
  566. {
  567. _pumpStartTime = DateTime.Now;
  568. Result ret = _pumpRoutine.Start();
  569. if (ret == Result.DONE)
  570. {
  571. return false;
  572. }
  573. else if (ret == Result.FAIL || ret == Result.TIMEOUT)
  574. {
  575. return false; //do noting
  576. }
  577. return true;
  578. }
  579. private bool fPumpDown(object[] objs)
  580. {
  581. Result ret = _pumpRoutine.Monitor();
  582. if (ret == Result.DONE)
  583. return true;
  584. else if (ret == Result.FAIL || ret == Result.TIMEOUT)
  585. {
  586. //do nothing
  587. return true;
  588. }
  589. return false; ;
  590. }
  591. private bool fAbortPumping(object[] objs)
  592. {
  593. _pumpRoutine.Abort();
  594. return true;
  595. }
  596. private bool fPumpingToVent(object[] objs)
  597. {
  598. if (_pumpRoutine.Abort() != Result.DONE)
  599. {
  600. PostMsg(MSG.Error);
  601. return true;
  602. }
  603. fStartVent(null);
  604. return true;
  605. }
  606. #endregion
  607. #region Stop Pump
  608. private bool fStartStopPump(object[] objs)
  609. {
  610. Result ret = _stopPumpRoutine.Start(objs);
  611. if (ret == Result.DONE)
  612. {
  613. return false;
  614. }
  615. else if (ret == Result.FAIL || ret == Result.TIMEOUT)
  616. {
  617. return false; //do noting
  618. }
  619. return true;
  620. }
  621. private bool fStopPump(object[] objs)
  622. {
  623. Result ret = _stopPumpRoutine.Monitor();
  624. if (ret == Result.DONE)
  625. return true;
  626. else if (ret == Result.FAIL || ret == Result.TIMEOUT)
  627. {
  628. //do nothing
  629. return true;
  630. }
  631. return false;
  632. ;
  633. }
  634. private bool fAbortStopPump(object[] objs)
  635. {
  636. _stopPumpRoutine.Abort();
  637. return true;
  638. }
  639. #endregion
  640. #region Gas Flow
  641. private bool fStartGasFlow(object[] objs)
  642. {
  643. Result ret = _gasFlowRoutine.Start(objs);
  644. if (ret == Result.DONE)
  645. {
  646. return false;
  647. }
  648. else if (ret == Result.FAIL || ret == Result.TIMEOUT)
  649. {
  650. return false; //do noting
  651. }
  652. return true;
  653. }
  654. private bool fGasFlow(object[] objs)
  655. {
  656. Result ret = _gasFlowRoutine.Monitor();
  657. if (ret == Result.DONE)
  658. return true;
  659. else if (ret == Result.FAIL || ret == Result.TIMEOUT)
  660. {
  661. //do nothing
  662. return true;
  663. }
  664. return false;
  665. ;
  666. }
  667. private bool fAbortGasFlow(object[] objs)
  668. {
  669. _gasFlowRoutine.Abort();
  670. return true;
  671. }
  672. #endregion
  673. #region Stop Gas Flow
  674. private bool fStartStopGasFlow(object[] objs)
  675. {
  676. Result ret = _stopGasFlowRoutine.Start(objs);
  677. if (ret == Result.DONE)
  678. {
  679. return false;
  680. }
  681. else if (ret == Result.FAIL || ret == Result.TIMEOUT)
  682. {
  683. return false; //do noting
  684. }
  685. return true;
  686. }
  687. private bool fStopGasFlow(object[] objs)
  688. {
  689. Result ret = _stopGasFlowRoutine.Monitor();
  690. if (ret == Result.DONE)
  691. return true;
  692. else if (ret == Result.FAIL || ret == Result.TIMEOUT)
  693. {
  694. //do nothing
  695. return true;
  696. }
  697. return false;
  698. ;
  699. }
  700. private bool fAbortStopGasFlow(object[] objs)
  701. {
  702. _stopGasFlowRoutine.Abort();
  703. return true;
  704. }
  705. #endregion
  706. #region Rf Power On
  707. private bool fStartRfPower(object[] objs)
  708. {
  709. Result ret = _rfPowerRoutine.Start(objs);
  710. if (ret == Result.DONE)
  711. {
  712. return false;
  713. }
  714. else if (ret == Result.FAIL || ret == Result.TIMEOUT)
  715. {
  716. return false; //do noting
  717. }
  718. return true;
  719. }
  720. private bool fRfPower(object[] objs)
  721. {
  722. Result ret = _rfPowerRoutine.Monitor();
  723. if (ret == Result.DONE)
  724. return true;
  725. else if (ret == Result.FAIL || ret == Result.TIMEOUT)
  726. {
  727. //do nothing
  728. return true;
  729. }
  730. return false;
  731. ;
  732. }
  733. private bool fAbortRfPower(object[] objs)
  734. {
  735. _rfPowerRoutine.AbortRf();
  736. _rfPowerRoutine.Abort();
  737. return true;
  738. }
  739. #endregion
  740. #region CyclePurge
  741. private bool fStartCyclePurge(object[] objs)
  742. {
  743. Result ret = cyclePurgeRoutine.Start(objs);
  744. if (ret == Result.DONE)
  745. {
  746. return false;
  747. }
  748. else if (ret == Result.FAIL)
  749. {
  750. return false; //do noting
  751. }
  752. return true;
  753. }
  754. private bool fCyclePurge(object[] objs)
  755. {
  756. Result ret = cyclePurgeRoutine.Monitor();
  757. if (ret == Result.DONE)
  758. return true;
  759. else if (ret == Result.FAIL)
  760. {
  761. //do nothing
  762. return true;
  763. }
  764. return false; ;
  765. }
  766. private bool fAbortCyclePurge(object[] objs)
  767. {
  768. cyclePurgeRoutine.Abort();
  769. return true;
  770. }
  771. #endregion
  772. #region PreProcess
  773. private bool fProcessLoadRecipe(object[] objs)
  774. {
  775. _processStatus = Resources.PMEntity_fProcessLoadRecipe_LoadingRecipeFile;
  776. _recipeStartTime = DateTime.Now;
  777. Result ret = preProcessRoutine.LoadRecipe(objs);
  778. if (ret == Result.DONE)
  779. {
  780. //if (preProcessRoutine.HighVac)
  781. // PostMsg(MSG.HighVacTest);
  782. //else
  783. PostMsg(MSG.PreProcess);
  784. return true;
  785. }
  786. else if (ret == Result.FAIL)
  787. {
  788. _processStatus = Resources.PMEntity_fProcessLoadRecipe_LoadingRecipeFileFailed;
  789. return false; //do noting
  790. }
  791. return true;
  792. }
  793. private bool fStartPreProcess(object[] objs)
  794. {
  795. _pumpStartTime = DateTime.Now;
  796. _processStatus = Resources.PMEntity_fStartPreProcess_PreparingRunningRecipe;
  797. Result ret = preProcessRoutine.Start(objs);
  798. if (ret == Result.DONE)
  799. {
  800. return false;
  801. }
  802. else if (ret == Result.FAIL)
  803. {
  804. _processStatus = Resources.PMEntity_fStartPreProcess_PreparingRunningRecipeFailed;
  805. PostMsg(MSG.Error);
  806. return false; //do noting
  807. }
  808. EV.Notify(EventLotStart, new SerializableDictionary<string, string>()
  809. {
  810. {DVIDName.LotId, preProcessRoutine.CurrentLotName},
  811. {DVIDName.RecipeId, preProcessRoutine.CurrentRecipeBaseName },
  812. {DVIDName.JobId, preProcessRoutine.CurrentJobName},
  813. });
  814. StartJobRecord(true,preProcessRoutine.CurrentLotName, preProcessRoutine.CurrentRecipeBaseName,preProcessRoutine.CurrentJobName, preProcessRoutine.CurrentUserId);
  815. return true;
  816. }
  817. private async void StartJobRecord(bool startEnd, string lotId="", string receipeName = "",string operation="",string operatorId="" )
  818. {
  819. await Task.Run(() => {
  820. Fab fb = (Fab)Enum.Parse(typeof(Fab), SC.GetValue<int>(SCName.System_Company).ToString());
  821. if (fb == Fab.YZQZ)
  822. {
  823. FabAutoComm com = new YZQZFabAuto();
  824. if (startEnd)
  825. com.StartJobRecord(lotId, receipeName,operation,operatorId);
  826. else com.EndJobRecord();
  827. }
  828. });
  829. }
  830. private bool fPreProcess(object[] objs)
  831. {
  832. _processStatus = Resources.PMEntity_fPreProcess_RunRecipePumpingDown;
  833. Result ret = preProcessRoutine.Monitor();
  834. if (ret == Result.DONE)
  835. {
  836. PostMsg(MSG.Process,
  837. preProcessRoutine.CurrentRecipeBaseName,
  838. preProcessRoutine.CurrentRecipeRunningName,
  839. 0,
  840. preProcessRoutine.CurrentLotName,
  841. preProcessRoutine.CurrentRecipeContent,
  842. preProcessRoutine.CurrentRecipeHead,
  843. preProcessRoutine.CurrentRecipeStepList,
  844. preProcessRoutine.CurrentJobName);
  845. return true;
  846. }
  847. else if (ret == Result.FAIL)
  848. {
  849. _processStatus = Resources.PMEntity_fPreProcess_RunRecipePumpingDownFailed;
  850. PostMsg(MSG.Error);
  851. return true;
  852. }
  853. return false; ;
  854. }
  855. private bool fAbortPreProcess(object[] objs)
  856. {
  857. _processStatus = Resources.PMEntity_fAbortPreProcess_RunRecipePumpingDownAborted;
  858. preProcessRoutine.Abort();
  859. return true;
  860. }
  861. #endregion
  862. #region Process
  863. private bool fStartProcess(object[] objs)
  864. {
  865. _processStatus = Resources.PMEntity_fStartProcess_StartRunningRecipe;
  866. Result ret = processRoutine.Start(objs);
  867. if (ret == Result.DONE)
  868. {
  869. return true;
  870. }
  871. else if (ret == Result.FAIL)
  872. {
  873. _processStatus = Resources.PMEntity_fStartProcess_RunRecipeFailed;
  874. PostMsg(MSG.Error);
  875. return true; //do noting
  876. }
  877. return true;
  878. }
  879. private bool fProcess(object[] objs)
  880. {
  881. _processStatus = Resources.PMEntity_fProcess_RunningRecipe;
  882. Result ret = processRoutine.Monitor();
  883. {
  884. if (ret == Result.DONE)
  885. {
  886. PostMsg(MSG.PostProcess, processRoutine.CurrentRecipeRunningName, processRoutine.CurrentRecipeContent);
  887. return true;
  888. }
  889. else if (ret == Result.FAIL)
  890. {
  891. _processStatus = Resources.PMEntity_fStartProcess_RunRecipeFailed;
  892. PostMsg(MSG.Error);
  893. //MESErrorRecordAlarm(processRoutine.CurrentRecipeRunningName, MSG.Error);
  894. return true;
  895. }
  896. return false;
  897. }
  898. }
  899. private bool fAbortProcess(object[] objs)
  900. {
  901. _processStatus = Resources.PMEntity_fAbortProcess_RunningRecipeAborted;
  902. processRoutine.AbortRecipe();
  903. Result ret = postProcessRoutine.Start(new object[] { processRoutine.CurrentRecipeRunningName, processRoutine.CurrentRecipeContent });
  904. if (ret == Result.DONE)
  905. {
  906. return false;
  907. }
  908. else if (ret == Result.FAIL)
  909. {
  910. PostMsg(MSG.Error);
  911. _processStatus = Resources.PMEntity_fAbortProcess_RunRecipeAborted;
  912. return false; //do noting
  913. }
  914. return true;
  915. }
  916. private bool fEnterProcess(object[] objs)
  917. {
  918. return true;
  919. }
  920. private bool fExitProcess(object[] objs)
  921. {
  922. processRoutine.Exit();
  923. return true;
  924. }
  925. private bool fExitPostProcess(object[] objs)
  926. {
  927. postProcessRoutine.Exit();
  928. EV.Notify(EventLotFinished, new SerializableDictionary<string, string>()
  929. {
  930. {DVIDName.LotId, preProcessRoutine.CurrentLotName},
  931. {DVIDName.JobId, preProcessRoutine.CurrentJobName},
  932. {DVIDName.RecipeId, preProcessRoutine.CurrentRecipeBaseName }
  933. });
  934. StartJobRecord(false);
  935. return true;
  936. }
  937. private bool fPauseProcess(object[] objs)
  938. {
  939. _processStatus = "run recipe paused";
  940. processRoutine.PauseRecipe();
  941. return false;
  942. }
  943. private bool fResumeRecipe(object[] objs)
  944. {
  945. _processStatus = "run recipe resumed";
  946. processRoutine.ResumeRecipe();
  947. return false;
  948. }
  949. private bool fSkipStep(object[] objs)
  950. {
  951. _processStatus = Resources.PMEntity_fSkipStep_RunRecipeSkipped;
  952. processRoutine.SkipCurrentRecipeStep();
  953. return false;
  954. }
  955. private bool fUpdateRecipe(object[] objs)
  956. {
  957. processRoutine.UpdateRecipe((string)objs[0]);
  958. return false;
  959. }
  960. #endregion
  961. #region PostProcess
  962. private bool fStartPostProcess(object[] objs)
  963. {
  964. _processStatus = Resources.PMEntity_fStartPostProcess_RunRecipePostProcess;
  965. Result ret = postProcessRoutine.Start(objs);
  966. if (ret == Result.DONE)
  967. {
  968. return false;
  969. }
  970. else if (ret == Result.FAIL)
  971. {
  972. PostMsg(MSG.Error);
  973. return false; //do noting
  974. }
  975. return true;
  976. }
  977. private bool fPostProcess(object[] objs)
  978. {
  979. _processStatus = Resources.PMEntity_fPostProcess_RunRecipeCyclePurge;
  980. Result ret = postProcessRoutine.Monitor();
  981. if (ret == Result.DONE)
  982. {
  983. _processStatus = Resources.PMEntity_fPostProcess_RecipeCompleted;
  984. if ((int)SC.GetValue<double>(SCName.ProcessConfig_ProcessFinishedReminderFlag) != 0)
  985. {
  986. processRoutine.PopProcessEndDialog();
  987. }
  988. return true;
  989. }
  990. else if (ret == Result.FAIL)
  991. {
  992. _processStatus = Resources.PMEntity_fPostProcess_RunRecipeCyclePurgeError;
  993. PostMsg(MSG.Error);
  994. return true;
  995. }
  996. return false;
  997. }
  998. private bool fAbortPostProcess(object[] objs)
  999. {
  1000. _processStatus = Resources.PMEntity_fAbortPostProcess_RecipeAborted;
  1001. postProcessRoutine.Abort();
  1002. return true;
  1003. }
  1004. #endregion
  1005. #region Leak Check
  1006. private bool fStartLeakCheck(object[] objs)
  1007. {
  1008. _leakCheckStartTime = DateTime.Now;
  1009. Result ret = _leakCheckRoutine.Start(objs);
  1010. if (ret == Result.DONE)
  1011. {
  1012. return false;
  1013. }
  1014. else if (ret == Result.FAIL || ret == Result.TIMEOUT)
  1015. {
  1016. return false; //do noting
  1017. }
  1018. return true;
  1019. }
  1020. private bool fLeakCheck(object[] objs)
  1021. {
  1022. Result ret = _leakCheckRoutine.Monitor();
  1023. if (ret == Result.DONE)
  1024. return true;
  1025. else if (ret == Result.FAIL || ret == Result.TIMEOUT)
  1026. {
  1027. PostMsg(MSG.Error);
  1028. EV.PostMessage(ModuleNameString.System, EventEnum.GeneralInfo, "Leak check stopped due to error");
  1029. return true;
  1030. }
  1031. return false;
  1032. ;
  1033. }
  1034. private bool fAbortLeakCheck(object[] objs)
  1035. {
  1036. _leakCheckRoutine.AbortLeakCheck();
  1037. return true;
  1038. }
  1039. #endregion
  1040. }
  1041. }