PrewetEntity.cs 35 KB

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