PrewetEntity.cs 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769
  1. using Aitex.Core.RT.DataCenter;
  2. using Aitex.Core.RT.Device;
  3. using Aitex.Core.RT.Fsm;
  4. using Aitex.Core.RT.Log;
  5. using Aitex.Core.RT.OperationCenter;
  6. using Aitex.Core.RT.SCCore;
  7. using Aitex.Core.Util;
  8. using Aitex.Core.Utilities;
  9. using MECF.Framework.Common.Device.LinMot;
  10. using MECF.Framework.Common.Equipment;
  11. using MECF.Framework.Common.ToolLayout;
  12. using MECF.Framework.Common.WaferHolder;
  13. using CyberX8_Core;
  14. using CyberX8_RT.Devices.LinMot;
  15. using CyberX8_RT.Devices.Prewet;
  16. using System;
  17. using System.Collections.Generic;
  18. using System.Linq;
  19. using System.Text;
  20. using System.Threading.Tasks;
  21. using System.Xaml.Schema;
  22. using MECF.Framework.Common.SubstrateTrackings;
  23. using MECF.Framework.Common.Persistent.Prewet;
  24. using MECF.Framework.Common.RecipeCenter;
  25. using Aitex.Core.RT.RecipeCenter;
  26. using System.Timers;
  27. using Aitex.Core.RT.Routine;
  28. using System.Windows.Markup;
  29. using CyberX8_RT.Dispatch;
  30. using MECF.Framework.Common.Jobs;
  31. using MECF.Framework.Common.CommonData;
  32. namespace CyberX8_RT.Modules.Prewet
  33. {
  34. public class PrewetEntity : Entity, IEntity, IModuleEntity
  35. {
  36. #region 常量
  37. private const string AUTO = "Auto";
  38. private const string MANUAL = "Manual";
  39. private const string DISABLED = "Disabled";
  40. private const string ENGINEERING = "Engineering";
  41. private const string PRODUCTION = "Production";
  42. #endregion
  43. #region 内部变量
  44. /// <summary>
  45. /// LintMot Axis
  46. /// </summary>
  47. private LinMotAxis _linmotAxis;
  48. /// <summary>
  49. /// prepare to trans
  50. /// </summary>
  51. private PrepareToTransferRoutine _prepareToTransferRoutine;
  52. /// <summary>
  53. /// Initialize routine
  54. /// </summary>
  55. private PrewetInitializeRoutine _initializeRoutine;
  56. /// <summary>
  57. /// Linmot Wet Scan Routine
  58. /// </summary>
  59. private PrewetLinmotScanWetRoutine _linmotWetScanRoutine;
  60. /// <summary>
  61. /// Manual模式下Cycle run
  62. /// </summary>
  63. private CycleManualProcessRecipeRoutine _cycleManualProcessRoutine;
  64. /// <summary>
  65. /// delay keepwet routine
  66. /// </summary>
  67. private PrewetDelayKeepwetRoutine _delayKeepwetRoutine;
  68. /// <summary>
  69. /// prewet Keepwet routine
  70. /// </summary>
  71. private PrewetKeepWetRoutine _prewetKeepWetRoutine;
  72. /// <summary>
  73. /// 执行前的状态
  74. /// </summary>
  75. private string _preExecuteState;
  76. /// <summary>
  77. /// Cycle次数
  78. /// </summary>
  79. private int _cycle = 0;
  80. /// <summary>
  81. /// 已经完成的Cycle次数
  82. /// </summary>
  83. private int _achievedCycle = 0;
  84. /// <summary>
  85. /// linmot设备数据
  86. /// </summary>
  87. private LinMotDeviceData _linMotDeviveData = new LinMotDeviceData();
  88. /// <summary>
  89. /// LinmotName
  90. /// </summary>
  91. private string _linmotName;
  92. /// <summary>
  93. /// PrewetDevice
  94. /// </summary>
  95. private PrewetDevice _prewetDevice;
  96. /// <summary>
  97. /// 工艺当前执行小步骤
  98. /// </summary>
  99. private string _currentStateMachine = "Init";
  100. /// <summary>
  101. /// 工艺当前执行大步骤
  102. /// </summary>
  103. private string _currentStatus = "Init";
  104. /// <summary>
  105. /// 持久化对象
  106. /// </summary>
  107. private PrewetPersistentValue _persistentValue;
  108. /// <summary>
  109. /// 当前Recipe
  110. /// </summary>
  111. private PwtRecipe _currentRecipe;
  112. /// <summary>
  113. /// recipe时长
  114. /// </summary>
  115. private int _recipeTime;
  116. /// <summary>
  117. /// keepwet倒计时
  118. /// </summary>
  119. private int _keepwetCountDown;
  120. /// <summary>
  121. /// run recipe start time
  122. /// </summary>
  123. private DateTime _runRecipeStartTime;
  124. /// <summary>
  125. /// run recipe complete time
  126. /// </summary>
  127. private DateTime _runRecipeCompleteTime;
  128. /// <summary>
  129. /// 是否Retry
  130. /// </summary>
  131. private bool _isRetry = false;
  132. #endregion
  133. #region 属性
  134. /// <summary>
  135. /// 模块名称
  136. /// </summary>
  137. public ModuleName Module { get; private set; }
  138. /// <summary>
  139. /// 初始化状态
  140. /// </summary>
  141. public bool IsInit { get { return fsm.State == (int)PrewetState.Init; } }
  142. /// <summary>
  143. /// 空闲状态
  144. /// </summary>
  145. public bool IsIdle { get { return fsm.State == (int)PrewetState.Idle; } }
  146. /// <summary>
  147. /// 是否发生错误
  148. /// </summary>
  149. public bool IsError { get { return fsm.State == (int)PrewetState.Error; } }
  150. /// <summary>
  151. /// 是否正在作业
  152. /// </summary>
  153. public bool IsBusy { get { return fsm.State>(int)PrewetState.Idle; } }
  154. /// <summary>
  155. /// 是否初始化完成
  156. /// </summary>
  157. public bool IsInitialized { get { return fsm.State >= (int)PrewetState.Initialized; } }
  158. /// <summary>
  159. /// 是否禁用
  160. /// </summary>
  161. public bool IsDisable { get { return _persistentValue == null || _persistentValue.OperatingMode == DISABLED; } }
  162. /// <summary>
  163. /// 自动模式
  164. /// </summary>
  165. public bool IsAuto { get { return _persistentValue != null && _persistentValue.OperatingMode == AUTO; } }
  166. /// <summary>
  167. /// 自动模式
  168. /// </summary>
  169. public bool IsManual { get { return _persistentValue != null && _persistentValue.OperatingMode == MANUAL; } }
  170. /// <summary>
  171. /// 是否为工程模式
  172. /// </summary>
  173. public bool IsEngineering { get { return _persistentValue != null && _persistentValue.RecipeOperatingMode == ENGINEERING; } }
  174. /// <summary>
  175. /// 是否为产品模式
  176. /// </summary>
  177. public bool IsProduction { get { return _persistentValue != null && _persistentValue.RecipeOperatingMode == PRODUCTION; } }
  178. /// <summary>
  179. /// WaferHolder信息
  180. /// </summary>
  181. public WaferHolderInfo WaferHolderInfo { get { return WaferHolderManager.Instance.GetWaferHolder(Module.ToString()); } }
  182. /// <summary>
  183. /// 当前状态机状态
  184. /// </summary>
  185. public int State { get { return fsm.State; } }
  186. /// <summary>
  187. /// recipe时长
  188. /// </summary>
  189. public int RecipeTime { get { return _recipeTime; } }
  190. #endregion
  191. /// <summary>
  192. /// 构造函数
  193. /// </summary>
  194. public PrewetEntity(ModuleName moduleName)
  195. {
  196. this.Module = moduleName;
  197. _prewetDevice = DEVICE.GetDevice<PrewetDevice>(Module.ToString());
  198. WaferManager.Instance.SubscribeLocation(Module, 2);
  199. InitialFsm();
  200. }
  201. /// <summary>
  202. /// 初始化
  203. /// </summary>
  204. /// <returns></returns>
  205. protected override bool Init()
  206. {
  207. InitializeParameter();
  208. InitialDATA();
  209. InitializeRoutine();
  210. InitialOperation();
  211. //InitialStateMachine();
  212. return true;
  213. }
  214. /// <summary>
  215. /// 中止
  216. /// </summary>
  217. protected override void Term()
  218. {
  219. }
  220. /// 初始化状态机
  221. /// </summary>
  222. private void InitialFsm()
  223. {
  224. fsm = new StateMachine<PrewetEntity>(Module.ToString(), (int)PrewetState.Init, 20);
  225. fsm.EnableRepeatedMsg(true);
  226. AnyStateTransition(PrewetMsg.Error, ErrorSolution, PrewetState.Error);
  227. AnyStateTransition(PrewetMsg.ReturnInit, NullFunc, PrewetState.Init);
  228. AnyStateTransition(PrewetMsg.ReturnIdle, NullFunc, PrewetState.Idle);
  229. Transition(PrewetState.Error, PrewetMsg.ResumeError, (param) => { return true; }, PrewetState.Init);
  230. //Initialize
  231. AnyStateTransition(PrewetMsg.Initialize, InitializeAll, PrewetState.Initializing);
  232. Transition(PrewetState.Initializing, FSM_MSG.TIMER, InitializeAllTimeout, PrewetState.Idle);
  233. //LinmotWetScan
  234. Transition(PrewetState.Idle, PrewetMsg.LinmotScanWet, LinmotScanWet, PrewetState.Linmot_Scanning);
  235. Transition(PrewetState.Linmot_Scanning, FSM_MSG.TIMER, LinmotScanTimeout, PrewetState.Idle);
  236. //Kepwet
  237. Transition(PrewetState.Idle, PrewetMsg.KeepWet, KeepWet, PrewetState.KeepWeting);
  238. Transition(PrewetState.KeepWeting, FSM_MSG.TIMER, KeepWetMonitor, PrewetState.Idle);
  239. Transition(PrewetState.Idle, PrewetMsg.DelayKeepwet, DelayKeepwet, PrewetState.DelayKeepweting);
  240. Transition(PrewetState.DelayKeepwetComplete, PrewetMsg.DelayKeepwet, DelayKeepwet, PrewetState.DelayKeepweting);
  241. Transition(PrewetState.RunRecipeComplete, PrewetMsg.DelayKeepwet, DelayKeepwet, PrewetState.DelayKeepweting);
  242. Transition(PrewetState.DelayKeepweting, FSM_MSG.TIMER, DelayKeepwetMonitor, PrewetState.DelayKeepwetComplete);
  243. //PrepareToTransfer
  244. Transition(PrewetState.Idle, PrewetMsg.PrepareToTransfer, PrepareToTransfer, PrewetState.PrepareToTransfering);
  245. Transition(PrewetState.PrepareToTransfering, FSM_MSG.TIMER, PrepareToTransferTimeout, PrewetState.Idle);
  246. //PrepareToPlace
  247. Transition(PrewetState.Idle, PrewetMsg.PrepareToPlace, PrepareToTransfer, PrewetState.PreparingToPlace);
  248. Transition(PrewetState.PreparingToPlace, FSM_MSG.TIMER, PrepareToTransferTimeout, PrewetState.WaitForPlace);
  249. //PrepareToPick
  250. Transition(PrewetState.DelayKeepweting, PrewetMsg.PrepareToPick, PrepareToTransfer, PrewetState.PreparingToPick);
  251. Transition(PrewetState.RunRecipeComplete, PrewetMsg.PrepareToPick, PrepareToTransfer, PrewetState.PreparingToPick);
  252. Transition(PrewetState.DelayKeepwetComplete, PrewetMsg.PrepareToPick, PrepareToTransfer, PrewetState.PreparingToPick);
  253. Transition(PrewetState.Idle, PrewetMsg.PrepareToPick, PrepareToTransfer, PrewetState.PreparingToPick);
  254. Transition(PrewetState.PreparingToPick, FSM_MSG.TIMER, PrepareToTransferTimeout, PrewetState.WaitForPick);
  255. Transition(PrewetState.WaitForPick, PrewetMsg.PickComplete, NullFunc, PrewetState.Idle);
  256. //RunRecipe
  257. Transition(PrewetState.Idle, PrewetMsg.RunRecipe, CycleManualProcess, PrewetState.RunReciping);
  258. Transition(PrewetState.WaitForPlace, PrewetMsg.RunRecipe, CycleManualProcess, PrewetState.RunReciping);
  259. Transition(PrewetState.RunReciping, FSM_MSG.TIMER, CycleManualMonitor, PrewetState.RunRecipeComplete);
  260. //Cycle Manual Process
  261. Transition(PrewetState.Idle, PrewetMsg.CycleProcessRecipe, CycleManualProcess, PrewetState.CycleManualProcessing);
  262. Transition(PrewetState.CycleManualProcessing, FSM_MSG.TIMER, CycleManualMonitor, PrewetState.Idle);
  263. //Abort
  264. Transition(PrewetState.CycleManualProcessing, PrewetMsg.Abort, CycleManualAbort, PrewetState.Abort);
  265. //Enter Init
  266. Transition(PrewetState.Idle, PrewetMsg.Init, NullFunc, PrewetState.Init);
  267. EnumLoop<PrewetState>.ForEach((item) => { fsm.MapState((int)item, item.ToString()); });
  268. EnumLoop<PrewetMsg>.ForEach((item) => { fsm.MapMessage((int)item, item.ToString()); });
  269. }
  270. /// <summary>
  271. /// 初始化参数
  272. /// </summary>
  273. private void InitializeParameter()
  274. {
  275. _persistentValue = PrewetPersistentManager.Instance.GetPrewetPersistentValue(Module.ToString());
  276. if (_persistentValue == null)
  277. {
  278. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module.ToString(), "Persistent Value Object is not exist");
  279. }
  280. _keepwetCountDown = 0;
  281. }
  282. /// <summary>
  283. /// 初始化数据
  284. /// </summary>
  285. private void InitialDATA()
  286. {
  287. PrewetItem prewetItem = PrewetItemManager.Instance.GetPrewetItem(Module.ToString());
  288. if (prewetItem!=null)
  289. {
  290. _linmotAxis = DEVICE.GetDevice<LinMotAxis>(prewetItem.LinmotID);
  291. string LinmotDeviceName = _linmotName = _linmotAxis.DeviceID;
  292. LinMotDevice linMotDevice = LinMotDeviceConfigManager.Instance.GetLinMotDevice(LinmotDeviceName);
  293. if (linMotDevice != null)
  294. {
  295. _linMotDeviveData = linMotDevice.LinMotDeviceData;
  296. }
  297. }
  298. InitializeSvid();
  299. DATA.Subscribe($"{Module}.FsmState", () => ((PrewetState)fsm.State).ToString(), SubscriptionAttribute.FLAG.IgnoreSaveDB);
  300. DATA.Subscribe($"{Module}.WaferHolder", () => WaferHolderInfo, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  301. DATA.Subscribe($"{Module}.AchievedCycle", () => _achievedCycle, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  302. DATA.Subscribe($"{Module}.GetKeepWetLimit", () => fsm.State==(int)PrewetState.DelayKeepweting?Math.Max(_keepwetCountDown-_delayKeepwetRoutine.ElapsedMilliseconds/1000,0):0 , SubscriptionAttribute.FLAG.IgnoreSaveDB);
  303. DATA.Subscribe($"{Module}.IsInit", () => IsInit, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  304. DATA.Subscribe($"{Module}.IsIdle", () => IsIdle, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  305. DATA.Subscribe($"{Module}.IsError", () => IsError, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  306. DATA.Subscribe($"{Module}.IsBusy", () => IsBusy, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  307. DATA.Subscribe($"{Module}.IsDisable", () => IsDisable, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  308. DATA.Subscribe($"{Module}.LinmotDeviceData", () => _linMotDeviveData, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  309. DATA.Subscribe($"{Module}.LinmotName", () => _linmotName, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  310. DATA.Subscribe($"{Module}.CurrentStateMachine", () => _currentStateMachine, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  311. DATA.Subscribe($"{Module}.CurrentStatus", () => _currentStatus, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  312. DATA.Subscribe($"{Module}.CurrentRecipe", () => _currentRecipe != null ? _currentRecipe.Ppid : "", SubscriptionAttribute.FLAG.IgnoreSaveDB);
  313. DATA.Subscribe($"{Module}.Linmot.ID", () => _linmotAxis.Module, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  314. DATA.Subscribe($"{Module}.Linmot.IsMotorOn", () => _linmotAxis.IsMotorOn, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  315. DATA.Subscribe($"{Module}.Linmot.IsError", () => _linmotAxis.IsError, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  316. DATA.Subscribe($"{Module}.Linmot.IsSwitchOn", () => _linmotAxis.IsSwitchOn, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  317. DATA.Subscribe($"{Module}.Linmot.ErrorCode", () => _linmotAxis.ErrorCode, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  318. DATA.Subscribe($"{Module}.Linmot.CurrentPosition", () => _linmotAxis.CurrentPosition, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  319. DATA.Subscribe($"{Module}.Linmot.ScanCount", () => _linmotAxis.ScanCount, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  320. }
  321. /// <summary>
  322. /// 初始化SVID
  323. /// </summary>
  324. private void InitializeSvid()
  325. {
  326. DATA.Subscribe($"{Module}.State", () => ((PrewetState)fsm.State).ToString(), SubscriptionAttribute.FLAG.IgnoreSaveDB);
  327. DATA.Subscribe($"{Module}.LotID", () => WaferHolderInfo?.LotId, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  328. DATA.Subscribe($"{Module}.WSID", () => WaferHolderInfo?.Id, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  329. DATA.Subscribe($"{Module}.LSAID", () => WaferHolderInfo?.CrsAId, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  330. DATA.Subscribe($"{Module}.LSBID", () => WaferHolderInfo?.CrsBId, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  331. DATA.Subscribe($"{Module}.ModuleRecipe", () => _currentRecipe?.Ppid, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  332. DATA.Subscribe($"{Module}.SequenceRecipe", () => WaferHolderInfo?.SequenceId, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  333. DATA.Subscribe($"{Module}.WaferAID", () => WaferHolderInfo?.WaferAId, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  334. DATA.Subscribe($"{Module}.WaferBID", () => WaferHolderInfo?.WaferBId, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  335. DATA.Subscribe($"{Module}.TotalTime", () => _recipeTime, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  336. DATA.Subscribe($"{Module}.TimeRemain", () => _recipeTime != 0 ? (_recipeTime - Math.Round((double)_cycleManualProcessRoutine.ElapsedMilliseconds / 1000, 0)) : 0, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  337. DATA.Subscribe($"{Module}.Task", () => WaferHolderInfo?.CurrentControlJobId, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  338. DATA.Subscribe($"{Module}.OperatingMode", () => _persistentValue != null ? _persistentValue.OperatingMode : "None", SubscriptionAttribute.FLAG.IgnoreSaveDB);
  339. }
  340. /// <summary>
  341. /// 初始化操作
  342. /// </summary>
  343. protected void InitialOperation()
  344. {
  345. OP.Subscribe($"{Module}.InitializeAll", (cmd, args) => { return CheckToPostMessage<PrewetState,PrewetMsg>(eEvent.ERR_PREWET,Module.ToString(),(int)PrewetMsg.Initialize); });
  346. OP.Subscribe($"{Module}.Abort", (cmd, args) => { return CheckToPostMessage<PrewetState,PrewetMsg>(eEvent.ERR_PREWET,Module.ToString(),(int)PrewetMsg.Abort); });
  347. OP.Subscribe($"{Module}.LimotScanWet", (cmd, args) => { return CheckToPostMessage<PrewetState, PrewetMsg>(eEvent.ERR_PREWET, Module.ToString(), (int)PrewetMsg.LinmotScanWet, args); });
  348. OP.Subscribe($"{Module}.KeepWet", (cmd, args) => { return CheckToPostMessage<PrewetState, PrewetMsg>(eEvent.ERR_PREWET, Module.ToString(), (int)PrewetMsg.KeepWet, args); });
  349. OP.Subscribe($"{Module}.PrepareToTransfer", (cmd, args) => { return CheckToPostMessage<PrewetState, PrewetMsg>(eEvent.ERR_PREWET, Module.ToString(), (int)PrewetMsg.PrepareToTransfer); });
  350. OP.Subscribe($"{Module}.ManualProcessRecipe", (cmd, args) => { return CheckToPostMessage<PrewetState, PrewetMsg>(eEvent.ERR_PREWET, Module.ToString(), (int)PrewetMsg.ProcessRecipe,args); });
  351. OP.Subscribe($"{Module}.CycleManualProcessRecipe", (cmd, args) =>
  352. {
  353. PwtRecipe recipe = RecipeFileManager.Instance.LoadGenericityRecipe<PwtRecipe>(args[0].ToString());
  354. if (recipe == null)
  355. {
  356. LOG.WriteLog(eEvent.ERR_PREWET, Module.ToString(), $"{args[0]} recipe is null");
  357. return false;
  358. }
  359. object[] objects = new object[args.Length];
  360. objects[0] = recipe;
  361. for (int i = 1; i < args.Length; i++)
  362. {
  363. objects[i] = args[i];
  364. }
  365. return CheckToPostMessage<PrewetState, PrewetMsg>(eEvent.ERR_PREWET, Module.ToString(), (int)PrewetMsg.CycleProcessRecipe,objects);
  366. });
  367. }
  368. /// <summary>
  369. /// EnterInit
  370. /// </summary>
  371. public void EnterInit()
  372. {
  373. if ((PrewetState)fsm.State != PrewetState.Idle) return;
  374. else
  375. {
  376. CheckToPostMessage<PrewetState, PrewetMsg>(eEvent.ERR_PREWET, Module.ToString(), (int)PrewetMsg.Init);
  377. }
  378. }
  379. /// <summary>
  380. /// 初始化Routine
  381. /// </summary>
  382. private void InitializeRoutine()
  383. {
  384. _prepareToTransferRoutine = new PrepareToTransferRoutine(Module.ToString(), _linmotAxis);
  385. _initializeRoutine=new PrewetInitializeRoutine(Module.ToString(), _linmotAxis);
  386. _linmotWetScanRoutine=new PrewetLinmotScanWetRoutine(Module.ToString(), _linmotAxis);
  387. _cycleManualProcessRoutine = new CycleManualProcessRecipeRoutine(Module.ToString(), _linmotAxis);
  388. _delayKeepwetRoutine=new PrewetDelayKeepwetRoutine(Module.ToString(),_linmotAxis);
  389. _prewetKeepWetRoutine = new PrewetKeepWetRoutine(Module.ToString(), _linmotAxis);
  390. }
  391. /// <summary>
  392. /// 初始化状态机
  393. /// </summary>
  394. private void InitialStateMachine()
  395. {
  396. //_keepwetStateMachine = new PrewetKeepWetStateMachine(Module.ToString(),_linmotAxis);
  397. //_keepwetStateMachine.Initialize();
  398. }
  399. private bool ErrorSolution(object[] param)
  400. {
  401. bool result = _prewetDevice.PumpValveClose();
  402. if (!result)
  403. {
  404. LOG.WriteLog(eEvent.ERR_PREWET,Module.ToString(), "Close Pump Valve error");
  405. }
  406. return true;
  407. }
  408. #region Initialize
  409. /// <summary>
  410. /// Initialize
  411. /// </summary>
  412. /// <param name="param"></param>
  413. /// <returns></returns>
  414. private bool InitializeAll(object[] param)
  415. {
  416. if (fsm.State == (int)PrewetState.Initializing)
  417. {
  418. LOG.WriteLog(eEvent.WARN_PREWET, Module.ToString(), "state is Initializing,cannot do initialize");
  419. return false;
  420. }
  421. return _initializeRoutine.Start() == RState.Running;
  422. }
  423. /// <summary>
  424. /// Initialize 监控
  425. /// </summary>
  426. /// <param name="param"></param>
  427. /// <returns></returns>
  428. private bool InitializeAllTimeout(object[] param)
  429. {
  430. RState ret = _initializeRoutine.Monitor();
  431. _currentStateMachine = _initializeRoutine.CurrentStateMachine;
  432. _currentStatus = "initializing";
  433. if (ret == RState.Failed || ret == RState.Timeout)
  434. {
  435. PostMsg(PrewetMsg.Error);
  436. _currentStateMachine = "Error";
  437. _currentStatus = "Error";
  438. return false;
  439. }
  440. bool result = ret == RState.End;
  441. if (result)
  442. {
  443. _currentStateMachine = "Idle";
  444. _currentStatus = "Idle";
  445. }
  446. return result;
  447. }
  448. #endregion
  449. #region Linmot scan wet
  450. /// <summary>
  451. /// Initialize
  452. /// </summary>
  453. /// <param name="param"></param>
  454. /// <returns></returns>
  455. private bool LinmotScanWet(object[] param)
  456. {
  457. _preExecuteState = ((PrewetState)fsm.State).ToString();
  458. return _linmotWetScanRoutine.Start(param) == RState.Running;
  459. }
  460. /// <summary>
  461. /// LinmotScan 监控
  462. /// </summary>
  463. /// <param name="param"></param>
  464. /// <returns></returns>
  465. private bool LinmotScanTimeout(object[] param)
  466. {
  467. RState ret = _linmotWetScanRoutine.Monitor();
  468. if (ret == RState.Failed || ret == RState.Timeout)
  469. {
  470. PostReturnPreState();
  471. _currentStateMachine = "Error";
  472. _currentStatus = "Error";
  473. return false;
  474. }
  475. return ret == RState.End;
  476. }
  477. #endregion
  478. #region Keep wet
  479. /// <summary>
  480. /// Keep Wet
  481. /// </summary>
  482. /// <param name="param"></param>
  483. /// <returns></returns>
  484. private bool KeepWet(object[] param)
  485. {
  486. _preExecuteState = ((PrewetState)fsm.State).ToString();
  487. return _prewetKeepWetRoutine.Start() == RState.Running;
  488. }
  489. /// <summary>
  490. /// Keep Wet Monitor
  491. /// </summary>
  492. /// <param name="param"></param>
  493. /// <returns></returns>
  494. private bool KeepWetMonitor(object[] param)
  495. {
  496. RState ret = _prewetKeepWetRoutine.Monitor();
  497. if(ret==RState.End)
  498. {
  499. //导出lotTrack数据
  500. LotTrackFileHeaderCommonData headerCommonData = new LotTrackFileHeaderCommonData();
  501. if (SC.ContainsItem("System.ToolID")) headerCommonData.ToolID = SC.GetStringValue("System.ToolID");
  502. headerCommonData.SoftWareVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
  503. PrewetLotTrackUtil.ExportPrewetLotTrack(Module.ToString(), _prewetKeepWetRoutine.PrewetLotTrackDatas,
  504. headerCommonData, IsAuto, false);
  505. return true;
  506. }
  507. else if(ret==RState.Failed||ret==RState.Timeout)
  508. {
  509. //导出lotTrack数据
  510. LotTrackFileHeaderCommonData headerCommonData = new LotTrackFileHeaderCommonData();
  511. if (SC.ContainsItem("System.ToolID")) headerCommonData.ToolID = SC.GetStringValue("System.ToolID");
  512. headerCommonData.SoftWareVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
  513. PrewetLotTrackUtil.ExportPrewetLotTrack(Module.ToString(), _prewetKeepWetRoutine.PrewetLotTrackDatas,
  514. headerCommonData, IsAuto, false);
  515. PostReturnPreState();
  516. return false;
  517. }
  518. return false;
  519. }
  520. /// <summary>
  521. /// Delay Keepwet
  522. /// </summary>
  523. /// <param name="param"></param>
  524. /// <returns></returns>
  525. private bool DelayKeepwet(object[] param)
  526. {
  527. _preExecuteState = ((PrewetState)fsm.State).ToString();
  528. _keepwetCountDown = SC.GetValue<int>("Prewet.IdleKeepwetPauseBetweenScanSeconds");
  529. return _delayKeepwetRoutine.Start() == RState.Running;
  530. }
  531. /// <summary>
  532. /// Delay Keepwet 监控
  533. /// </summary>
  534. /// <param name="param"></param>
  535. /// <returns></returns>
  536. private bool DelayKeepwetMonitor(object[] param)
  537. {
  538. RState ret = _delayKeepwetRoutine.Monitor();
  539. if(ret==RState.End)
  540. {
  541. //导出lotTrack数据
  542. PrewetLotTrackUtil.ExportPrewetLotTrack(Module.ToString(), _delayKeepwetRoutine.PrewetLotTrackDatas,
  543. null, IsAuto, true);
  544. return true;
  545. }
  546. else if(ret==RState.Failed||ret==RState.Timeout)
  547. {
  548. //导出lotTrack数据
  549. PrewetLotTrackUtil.ExportPrewetLotTrack(Module.ToString(), _delayKeepwetRoutine.PrewetLotTrackDatas,
  550. null, IsAuto, true);
  551. PostMsg(PrewetMsg.Error);
  552. return false;
  553. }
  554. return false;
  555. }
  556. #endregion
  557. #region PrepareToTransfer
  558. /// <summary>
  559. /// PrepareToTransfer
  560. /// </summary>
  561. /// <param name="param"></param>
  562. /// <returns></returns>
  563. private bool PrepareToTransfer(object[] param)
  564. {
  565. bool isNeedStopLinmot = true;
  566. if (fsm.State == (int)PrewetState.DelayKeepweting)
  567. {
  568. _delayKeepwetRoutine.Abort();
  569. isNeedStopLinmot = false;
  570. }
  571. _preExecuteState = ((PrewetState)fsm.State).ToString();
  572. return _prepareToTransferRoutine.Start(isNeedStopLinmot) == RState.Running;
  573. }
  574. /// <summary>
  575. /// PrepareToTransfer 监控
  576. /// </summary>
  577. /// <param name="param"></param>
  578. /// <returns></returns>
  579. private bool PrepareToTransferTimeout(object[] param)
  580. {
  581. RState ret = _prepareToTransferRoutine.Monitor();
  582. if (ret == RState.Failed || ret == RState.Timeout)
  583. {
  584. PostReturnPreState();
  585. _currentStateMachine = "Error";
  586. _currentStatus = "Error";
  587. return false;
  588. }
  589. return ret == RState.End;
  590. }
  591. #endregion
  592. #region Manual Process
  593. private bool CycleManualProcess(object[] param)
  594. {
  595. PwtRecipe recipe = param[0] as PwtRecipe;
  596. _cycle = (int)param[1];
  597. bool result = _cycleManualProcessRoutine.Start(param) == RState.Running;
  598. if(result)
  599. {
  600. _isRetry = false;
  601. if (CellItemRecipeTimeManager.Instance.ContainRecipe(recipe.Ppid))
  602. {
  603. _recipeTime = _cycle * CellItemRecipeTimeManager.Instance.GetRecipeTotalTime(recipe.Ppid);
  604. }
  605. else
  606. {
  607. _recipeTime = 0;
  608. }
  609. _currentRecipe = recipe;
  610. _runRecipeStartTime = DateTime.Now;
  611. if (WaferHolderInfo != null && _currentRecipe != null)
  612. {
  613. FaModuleNotifier.Instance.NotifyWaferShuttleRecipeStart(WaferHolderInfo, _currentRecipe.Ppid);
  614. }
  615. }
  616. return result;
  617. }
  618. private bool CycleManualMonitor(object[] param)
  619. {
  620. RState state = _cycleManualProcessRoutine.Monitor();
  621. _currentStatus = _cycleManualProcessRoutine.CurrentStatus;
  622. _currentStateMachine = _cycleManualProcessRoutine.CurrentStateMachine;
  623. if (state == RState.Failed || state == RState.Timeout)
  624. {
  625. PostMsg(PrewetMsg.Error);
  626. _currentStateMachine = "Error";
  627. _currentStatus = "Error";
  628. _runRecipeCompleteTime = DateTime.Now;
  629. _cycleManualProcessRoutine.PrewetLotTrackHeaderDatas.ProcessTime = (_runRecipeCompleteTime - _runRecipeStartTime).TotalSeconds.ToString("F2");
  630. //导出lotTrack数据
  631. PrewetLotTrackUtil.ExportPrewetLotTrack(Module.ToString(), _cycleManualProcessRoutine.PrewetLotTrackDatas,
  632. _cycleManualProcessRoutine.PrewetLotTrackHeaderDatas, IsAuto, _isRetry);
  633. if (WaferHolderInfo != null && _currentRecipe != null)
  634. {
  635. FaModuleNotifier.Instance.NotifyWaferShuttleRecipeFailed(WaferHolderInfo, _currentRecipe.Ppid);
  636. }
  637. return false;
  638. }
  639. _achievedCycle = _cycleManualProcessRoutine.GetAchievedCycle();
  640. bool result = state == RState.End;
  641. if (result)
  642. {
  643. double elapsedMilliseconds = _cycleManualProcessRoutine.ElapsedMilliseconds;
  644. int recipeTime = (int)Math.Floor(elapsedMilliseconds / _cycle/ 1000);
  645. CellItemRecipeTimeManager.Instance.UpdateRecipeTime(_currentRecipe.Ppid, recipeTime);
  646. _runRecipeCompleteTime = DateTime.Now;
  647. _cycleManualProcessRoutine.PrewetLotTrackHeaderDatas.ProcessTime = (_runRecipeCompleteTime - _runRecipeStartTime).TotalSeconds.ToString("F2");
  648. //导出lotTrack数据
  649. PrewetLotTrackUtil.ExportPrewetLotTrack(Module.ToString(), _cycleManualProcessRoutine.PrewetLotTrackDatas,
  650. _cycleManualProcessRoutine.PrewetLotTrackHeaderDatas, IsAuto, _isRetry);
  651. if (WaferHolderInfo != null && _currentRecipe != null)
  652. {
  653. FaModuleNotifier.Instance.NotifyWaferShuttleRecipeEnd(WaferHolderInfo, _currentRecipe.Ppid, recipeTime);
  654. }
  655. }
  656. return result;
  657. }
  658. private bool CycleManualAbort(object[] param)
  659. {
  660. _cycleManualProcessRoutine.Abort();
  661. _currentStateMachine = "Abort";
  662. _currentStatus = "Abort";
  663. _runRecipeCompleteTime = DateTime.Now;
  664. _cycleManualProcessRoutine.PrewetLotTrackHeaderDatas.ProcessTime = (_runRecipeCompleteTime - _runRecipeStartTime).TotalSeconds.ToString("F2");
  665. //导出lotTrack数据
  666. PrewetLotTrackUtil.ExportPrewetLotTrack(Module.ToString(), _cycleManualProcessRoutine.PrewetLotTrackDatas,
  667. _cycleManualProcessRoutine.PrewetLotTrackHeaderDatas, IsAuto, _isRetry);
  668. return true;
  669. }
  670. #endregion
  671. /// <summary>
  672. /// 返回上一状态
  673. /// </summary>
  674. private void PostReturnPreState()
  675. {
  676. if (_preExecuteState == PrewetState.Init.ToString())
  677. {
  678. PostMsg(PrewetMsg.ReturnInit);
  679. }
  680. else if (_preExecuteState != PrewetState.Init.ToString())
  681. {
  682. PostMsg(PrewetMsg.ReturnIdle);
  683. }
  684. }
  685. #region IEntity接口模块(unused)
  686. public bool Check(int msg, out string reason, params object[] args)
  687. {
  688. throw new NotImplementedException();
  689. }
  690. public bool CheckAcked(int msg)
  691. {
  692. throw new NotImplementedException();
  693. }
  694. public int Invoke(string function, params object[] args)
  695. {
  696. switch (function)
  697. {
  698. case "HomeAll":
  699. if (IsIdle)
  700. {
  701. return (int)FSM_MSG.NONE;
  702. }
  703. if (CheckToPostMessage<PrewetState, PrewetMsg>(eEvent.ERR_PREWET, Module.ToString(), (int)PrewetMsg.Initialize))
  704. {
  705. return (int)PrewetMsg.Initialize;
  706. }
  707. else
  708. {
  709. return (int)FSM_MSG.NONE;
  710. }
  711. }
  712. return (int)FSM_MSG.NONE;
  713. }
  714. #endregion
  715. }
  716. public enum PrewetMsg
  717. {
  718. Error,
  719. Abort,
  720. ResumeError,
  721. Initialize,
  722. LinmotScanWet,
  723. KeepWet,
  724. DelayKeepwet,
  725. PrepareToPlace,
  726. PrepareToPick,
  727. PrepareToTransfer,
  728. ReturnInit,
  729. ReturnIdle,
  730. ProcessRecipe,
  731. CycleProcessRecipe,
  732. RunRecipe,
  733. PickComplete,
  734. Init
  735. }
  736. }