PrewetEntity.cs 33 KB

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