LoaderEntity.cs 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986
  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.Routine;
  7. using Aitex.Core.RT.SCCore;
  8. using Aitex.Core.Util;
  9. using Aitex.Core.Utilities;
  10. using MECF.Framework.Common.Equipment;
  11. using MECF.Framework.Common.SubstrateTrackings;
  12. using MECF.Framework.Common.Utilities;
  13. using MECF.Framework.Common.WaferHolder;
  14. using CyberX8_Core;
  15. using CyberX8_RT.Devices.AXIS;
  16. using CyberX8_RT.Devices.Loader;
  17. using System;
  18. using System.Collections.Generic;
  19. using System.Linq;
  20. using System.Text;
  21. using System.Threading.Tasks;
  22. using MECF.Framework.Common.Alarm;
  23. using MECF.Framework.Common.CommonData;
  24. using MECF.Framework.Common.Routine;
  25. using System.Collections;
  26. using System.Windows.Markup;
  27. using MECF.Framework.Common.CommonData.Loader;
  28. using Aitex.Core.Common;
  29. using MECF.Framework.RT.Core.Equipments;
  30. using CyberX8_RT.Modules.Dryer;
  31. namespace CyberX8_RT.Modules.Loader
  32. {
  33. public class LoaderEntity : Entity, IEntity, IModuleEntity
  34. {
  35. public enum LotTrackDatasStatus
  36. {
  37. None,
  38. Half,
  39. Complete
  40. }
  41. #region 属性
  42. public ModuleName Module { get; private set; }
  43. public bool IsInit
  44. {
  45. get { return fsm.State == (int)LOADERSTATE.Init; }
  46. }
  47. public bool IsIdle
  48. {
  49. get
  50. {
  51. return fsm.State == (int)LOADERSTATE.Idle;
  52. }
  53. }
  54. public bool IsError
  55. {
  56. get { return fsm.State == (int)LOADERSTATE.Error; }
  57. }
  58. public bool IsBusy
  59. {
  60. get { return !IsInit && !IsError && !IsIdle; }
  61. }
  62. public bool IsAuto { get; } = true;
  63. /// <summary>
  64. /// 是否为工程模式
  65. /// </summary>
  66. public bool IsEngineering { get; } = false;
  67. /// <summary>
  68. /// 是否为产品模式
  69. /// </summary>
  70. public bool IsProduction { get; } = true;
  71. public bool IsHomed
  72. {
  73. get { return _isHomed; }
  74. }
  75. /// <summary>
  76. /// 当前状态机状态
  77. /// </summary>
  78. public int State { get { return fsm.State; } }
  79. /// <summary>
  80. /// 是否禁用
  81. /// </summary>
  82. public bool IsDisable { get; internal set; }
  83. /// <summary>
  84. /// Rotation是否SwitchOn
  85. /// </summary>
  86. public bool IsRotationSwitchOn
  87. {
  88. get { return _rotationAxis.IsSwitchOn; }
  89. }
  90. /// <summary>
  91. /// ShuttleA是否SwitchOn
  92. /// </summary>
  93. public bool IsShuttleASwitchOn
  94. {
  95. get { return _shuttleAAxis.IsSwitchOn; }
  96. }
  97. /// <summary>
  98. /// ShuttleB是否SwitchOn
  99. /// </summary>
  100. public bool IsShuttleBSwitchOn
  101. {
  102. get { return _shuttleBAxis.IsSwitchOn; }
  103. }
  104. /// <summary>
  105. /// TiltA是否SwitchOn
  106. /// </summary>
  107. public bool IsTiltASwitchOn
  108. {
  109. get { return _tiltAAxis.IsSwitchOn; }
  110. }
  111. /// <summary>
  112. /// TiltB是否SwitchOn
  113. /// </summary>
  114. public bool IsTiltBSwitchOn
  115. {
  116. get { return _tiltBAxis.IsSwitchOn; }
  117. }
  118. /// <summary>
  119. /// CrsA是否SwitchOn
  120. /// </summary>
  121. public bool IsCrsASwitchOn
  122. {
  123. get { return _crsAAxis.IsSwitchOn; }
  124. }
  125. /// <summary>
  126. /// CrsB是否SwitchOn
  127. /// </summary>
  128. public bool IsCrsBSwitchOn
  129. {
  130. get { return _crsBAxis.IsSwitchOn; }
  131. }
  132. /// <summary>
  133. /// WaferHolder信息
  134. /// </summary>
  135. public WaferHolderInfo WaferHolderInfo { get { return WaferHolderManager.Instance.GetWaferHolder("Loader"); } }
  136. #endregion
  137. #region 内部变量
  138. private bool _isHomed = false;
  139. private IRoutine _currentRoutine;
  140. /// <summary>
  141. /// Loader当前unload、load操作Slot
  142. /// </summary>
  143. private Dictionary<string, List<string>> _loaderOperatingWaferInfosList = new Dictionary<string, List<string>> { { "unload", new List<string>(new string[2]) }, { "load", new List<string>(new string[2]) } };
  144. #region Axis
  145. JetAxisBase _shuttleAAxis;
  146. JetAxisBase _shuttleBAxis;
  147. JetAxisBase _tiltAAxis;
  148. JetAxisBase _tiltBAxis;
  149. JetAxisBase _crsAAxis;
  150. JetAxisBase _crsBAxis;
  151. JetAxisBase _rotationAxis;
  152. LoaderSideDevice _sideA;
  153. LoaderSideDevice _sideB;
  154. LoaderCommonDevice _loaderCommon;
  155. #endregion
  156. #region routine
  157. private LoaderHomeAllRoutine _homeAllRoutine;
  158. private LoaderSwitchAllOnRoutine _switchAllOnRoutine;
  159. private LoaderSwitchAllOffRoutine _switchAllOffRoutine;
  160. private LoaderUnloadSideRoutine _unloadSideRoutine;
  161. private LoaderLoadSideRoutine _loadSideRoutine;
  162. #endregion
  163. #region LotTrackDatas
  164. /// <summary>
  165. /// Load LotTrackData
  166. /// </summary>
  167. private List<LoaderLotTrackData> _loadLotTrackDatas = new List<LoaderLotTrackData>();
  168. /// <summary>
  169. /// UnLoad LotTrackData
  170. /// </summary>
  171. private List<LoaderLotTrackData> _unloadLotTrackDatas = new List<LoaderLotTrackData>();
  172. /// <summary>
  173. /// UnLoad LotTrackDataBuffer
  174. /// </summary>
  175. private List<LoaderLotTrackData> _unloadLotTrackDatasBuffer = new List<LoaderLotTrackData>();
  176. /// <summary>
  177. /// LeakTest LotTrackData
  178. /// </summary>
  179. private List<LoaderFlowLotTrackData> _flowLotTrackdatas = new List<LoaderFlowLotTrackData>();
  180. /// <summary>
  181. /// LoadTime
  182. /// </summary>
  183. private List<DateTime> _loadTimeList = new List<DateTime>();
  184. /// <summary>
  185. /// LoadTime
  186. /// </summary>
  187. private List<DateTime> _unloadTimeList = new List<DateTime>();
  188. /// <summary>
  189. /// Unload Start Time
  190. /// </summary>
  191. private DateTime _unloadStartTime;
  192. /// <summary>
  193. /// LotTrackHead
  194. /// </summary>
  195. private LotTrackFileHeaderCommonData _headerdata;
  196. /// <summary>
  197. /// Load Datas Status
  198. private LotTrackDatasStatus _loadDatasStatus = LotTrackDatasStatus.None;
  199. /// <summary>
  200. /// Unload Datas Status
  201. /// </summary>
  202. private LotTrackDatasStatus _unloadDatasStatus = LotTrackDatasStatus.None;
  203. /// <summary>
  204. /// Unload Datas Buffer Status
  205. /// </summary>
  206. private LotTrackDatasStatus _unloadDatasBufferStatus = LotTrackDatasStatus.None;
  207. /// <summary>
  208. /// Flow Test Datas status
  209. /// </summary>
  210. private LotTrackDatasStatus _flowTestDatasStatus = LotTrackDatasStatus.None;
  211. #endregion
  212. #endregion
  213. /// <summary>
  214. /// 构造函数
  215. /// </summary>
  216. /// <param name="module"></param>
  217. public LoaderEntity(ModuleName module)
  218. {
  219. this.Module = module;
  220. _shuttleAAxis = DEVICE.GetDevice<JetAxisBase>($"{module}.ShuttleA");
  221. _shuttleBAxis = DEVICE.GetDevice<JetAxisBase>($"{module}.ShuttleB");
  222. _tiltAAxis = DEVICE.GetDevice<JetAxisBase>($"{module}.TiltA");
  223. _tiltBAxis = DEVICE.GetDevice<JetAxisBase>($"{module}.TiltB");
  224. _crsAAxis = DEVICE.GetDevice<JetAxisBase>($"{module}.LSA");
  225. _crsBAxis = DEVICE.GetDevice<JetAxisBase>($"{module}.LSB");
  226. _rotationAxis = DEVICE.GetDevice<JetAxisBase>($"{module}.Rotation");
  227. _sideA = DEVICE.GetDevice<LoaderSideDevice>($"{Module}.SideA");
  228. _sideB = DEVICE.GetDevice<LoaderSideDevice>($"{Module}.SideB");
  229. _loaderCommon = DEVICE.GetDevice<LoaderCommonDevice>($"{module}.Common");
  230. WaferManager.Instance.SubscribeLocation(Module, 2);
  231. InitialOperation();
  232. InitializeRoutine();
  233. InitialDATA();
  234. InitialFsm();
  235. }
  236. /// <summary>
  237. /// 初始化操作
  238. /// </summary>
  239. private void InitialOperation()
  240. {
  241. OP.Subscribe($"{Module}.Abort", (cmd, args) => { return CheckToPostMessage<LOADERSTATE, LoaderMSG>(eEvent.ERR_LOADER, Module.ToString(), (int)LoaderMSG.Abort); });
  242. OP.Subscribe($"{Module}.ClearError", (cmd, args) => { return CheckToPostMessage<LOADERSTATE, LoaderMSG>(eEvent.ERR_LOADER, Module.ToString(), (int)LoaderMSG.ClearError); });
  243. OP.Subscribe($"{Module}.Common.HomeAll", (cmd, args) => { PostMsg((int)LoaderMSG.HomeAll); return true; });
  244. OP.Subscribe($"{Module}.Common.SwitchOnAll", (cmd, args) => { PostMsg((int)LoaderMSG.SwitchOnAll); return true; });
  245. OP.Subscribe($"{Module}.Common.SwitchOffAll", (cmd, args) => { PostMsg((int)LoaderMSG.SwitchOffAll); return true; });
  246. }
  247. /// <summary>
  248. /// 初始化Routine
  249. /// </summary>
  250. private void InitializeRoutine()
  251. {
  252. _homeAllRoutine=new LoaderHomeAllRoutine(Module.ToString());
  253. _switchAllOnRoutine=new LoaderSwitchAllOnRoutine(Module.ToString());
  254. _switchAllOffRoutine=new LoaderSwitchAllOffRoutine(Module.ToString());
  255. _unloadSideRoutine = new LoaderUnloadSideRoutine(Module.ToString());
  256. _loadSideRoutine=new LoaderLoadSideRoutine(Module.ToString());
  257. }
  258. /// <summary>
  259. /// 初始化数据
  260. /// </summary>
  261. private void InitialDATA()
  262. {
  263. InitializeSvid();
  264. DATA.Subscribe($"{Module}.FsmState", () => ((LOADERSTATE)fsm.State).ToString(), SubscriptionAttribute.FLAG.IgnoreSaveDB);
  265. DATA.Subscribe($"{Module}.IsHomed", () => _isHomed, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  266. DATA.Subscribe($"{Module}.IsError", () => IsError, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  267. }
  268. /// <summary>
  269. /// 初始化SVID
  270. /// </summary>
  271. private void InitializeSvid()
  272. {
  273. DATA.Subscribe($"{Module}.State", () => ((LOADERSTATE)fsm.State).ToString(), SubscriptionAttribute.FLAG.IgnoreSaveDB);
  274. DATA.Subscribe($"{Module}.LotID", () => (WaferHolderInfo != null ? WaferHolderInfo.LotId : ""), SubscriptionAttribute.FLAG.IgnoreSaveDB);
  275. DATA.Subscribe($"{Module}.WSID", () => (WaferHolderInfo != null ? WaferHolderInfo.Id : ""), SubscriptionAttribute.FLAG.IgnoreSaveDB);
  276. DATA.Subscribe($"{Module}.LSAID", () => (WaferHolderInfo != null ? WaferHolderInfo.CrsAId : ""), SubscriptionAttribute.FLAG.IgnoreSaveDB);
  277. DATA.Subscribe($"{Module}.LSBID", () => (WaferHolderInfo != null ? WaferHolderInfo.CrsBId : ""), SubscriptionAttribute.FLAG.IgnoreSaveDB);
  278. DATA.Subscribe($"{Module}.SequenceRecipe", () => (WaferHolderInfo != null ? WaferHolderInfo.SequenceId : ""), SubscriptionAttribute.FLAG.IgnoreSaveDB);
  279. DATA.Subscribe($"{Module}.WaferAID", () => (WaferHolderInfo != null ? WaferHolderInfo.WaferAId : ""), SubscriptionAttribute.FLAG.IgnoreSaveDB);
  280. DATA.Subscribe($"{Module}.WaferBID", () => (WaferHolderInfo != null ? WaferHolderInfo.WaferBId : ""), SubscriptionAttribute.FLAG.IgnoreSaveDB);
  281. DATA.Subscribe($"{Module}.Task", () => WaferHolderInfo!=null?WaferHolderInfo.CurrentControlJobId:"", SubscriptionAttribute.FLAG.IgnoreSaveDB);
  282. }
  283. /// <summary>
  284. /// 初始化状态机
  285. /// </summary>
  286. private void InitialFsm()
  287. {
  288. fsm = new StateMachine<LoaderEntity>(Module.ToString(), (int)LOADERSTATE.Init, 100);
  289. fsm.EnableRepeatedMsg(true);
  290. AnyStateTransition(LoaderMSG.Error, EnterError, LOADERSTATE.Error);
  291. AnyStateTransition(LoaderMSG.ReturnInit, EnterInit, LOADERSTATE.Init);
  292. AnyStateTransition(LoaderMSG.ReturnIdle, NullFunc, LOADERSTATE.Idle);
  293. AnyStateTransition(LoaderMSG.Abort, Abort, LOADERSTATE.Init);
  294. //clear error
  295. Transition(LOADERSTATE.Error, LoaderMSG.ClearError, ResumeError, LOADERSTATE.Init);
  296. //HomeAll
  297. AnyStateTransition(LoaderMSG.HomeAll, HomeAll, LOADERSTATE.Homing);
  298. Transition(LOADERSTATE.Homing, FSM_MSG.TIMER, HomeAllMonitor, LOADERSTATE.Idle);
  299. //Switch On All
  300. Transition(LOADERSTATE.Error, LoaderMSG.SwitchOnAll, SwitchOnAll, LOADERSTATE.SwitchOning);
  301. Transition(LOADERSTATE.Init, LoaderMSG.SwitchOnAll, SwitchOnAll, LOADERSTATE.SwitchOning);
  302. Transition(LOADERSTATE.Idle, LoaderMSG.SwitchOnAll, SwitchOnAll, LOADERSTATE.SwitchOning);
  303. Transition(LOADERSTATE.SwitchOning, FSM_MSG.TIMER, SwitchOnAllMonitor, LOADERSTATE.Init);
  304. //Switch Off All
  305. Transition(LOADERSTATE.Error, LoaderMSG.SwitchOffAll, SwitchOffAll, LOADERSTATE.SwitchOffing);
  306. Transition(LOADERSTATE.Init, LoaderMSG.SwitchOffAll, SwitchOffAll, LOADERSTATE.SwitchOffing);
  307. Transition(LOADERSTATE.Idle, LoaderMSG.SwitchOffAll, SwitchOffAll, LOADERSTATE.SwitchOffing);
  308. Transition(LOADERSTATE.SwitchOffing, FSM_MSG.TIMER, SwitchOffAllMonitor, LOADERSTATE.Init);
  309. //Prepare for Place
  310. Transition(LOADERSTATE.Idle, LoaderMSG.PrepareForPlace, PrePareForPlace, LOADERSTATE.PrepreForPlacing);
  311. Transition(LOADERSTATE.PrepreForPlacing, FSM_MSG.TIMER, PrepareForPlaceMonitor, LOADERSTATE.WaitForUnload);
  312. Transition(LOADERSTATE.Idle, LoaderMSG.ReadyForPuf, NullFunc, LOADERSTATE.WaitForUnload);
  313. Transition(LOADERSTATE.WaitForUnload, LoaderMSG.UnloadSide, UnloadSide, LOADERSTATE.Unloading);
  314. Transition(LOADERSTATE.Unloading, FSM_MSG.TIMER, UnloadSideMonitor, LOADERSTATE.WaitForLoad);
  315. Transition(LOADERSTATE.WaitForLoad, LoaderMSG.LoadSide, LoadSide, LOADERSTATE.Loading);
  316. Transition(LOADERSTATE.Loading, FSM_MSG.TIMER, LoadSideMonitor, LOADERSTATE.Idle);
  317. //Retry
  318. Transition(LOADERSTATE.Error, LoaderMSG.Retry, NullFunc, LOADERSTATE.Retrying);
  319. Transition(LOADERSTATE.Retrying,FSM_MSG.TIMER,LoaderRetry,LOADERSTATE.Retrying);
  320. Transition(LOADERSTATE.Retrying, LoaderMSG.UnloadSide, RetryUnloadSide, LOADERSTATE.Unloading);
  321. Transition(LOADERSTATE.Retrying, LoaderMSG.LoadSide, RetryLoadSide, LOADERSTATE.Loading);
  322. //ConfirmComplete
  323. Transition(LOADERSTATE.Init, LoaderMSG.ConfirmComplete, ClearModuleAlarm, LOADERSTATE.Init);
  324. Transition(LOADERSTATE.Idle, LoaderMSG.ConfirmComplete, ClearModuleAlarm, LOADERSTATE.Idle);
  325. Transition(LOADERSTATE.Error, LoaderMSG.ConfirmComplete, NullFunc, LOADERSTATE.ConfirmCompleting);
  326. Transition(LOADERSTATE.ConfirmCompleting,FSM_MSG.TIMER,ConfirmComplete, LOADERSTATE.ConfirmCompleting);
  327. Transition(LOADERSTATE.ConfirmCompleting, LoaderMSG.PrepareForPlace, NullFunc, LOADERSTATE.WaitForUnload);
  328. Transition(LOADERSTATE.ConfirmCompleting,LoaderMSG.UnloadSide,ConfirmUnloadSide, LOADERSTATE.WaitForLoad);
  329. Transition(LOADERSTATE.ConfirmCompleting, LoaderMSG.LoadSide, ConfirmLoadSide, LOADERSTATE.Idle);
  330. EnumLoop<LOADERSTATE>.ForEach((item) => { fsm.MapState((int)item, item.ToString()); });
  331. EnumLoop<LoaderMSG>.ForEach((item) => { fsm.MapMessage((int)item, item.ToString()); });
  332. }
  333. /// <summary>
  334. /// 恢复错误
  335. /// </summary>
  336. /// <param name="param"></param>
  337. /// <returns></returns>
  338. private bool ResumeError(object[] param)
  339. {
  340. if (_isHomed)
  341. {
  342. PostMsg(LoaderMSG.ReturnIdle);
  343. return false;
  344. }
  345. return true;
  346. }
  347. #region Abort
  348. private bool Abort(object parameter)
  349. {
  350. bool preHomed = IsHomed;
  351. _shuttleAAxis.StopPositionOperation();
  352. _shuttleBAxis.StopPositionOperation();
  353. _tiltAAxis.StopPositionOperation();
  354. _tiltBAxis.StopPositionOperation();
  355. _crsAAxis.StopPositionOperation();
  356. _crsBAxis.StopPositionOperation();
  357. _rotationAxis.StopPositionOperation();
  358. if (_currentRoutine != null)
  359. {
  360. _currentRoutine.Abort();
  361. _currentRoutine = null;
  362. }
  363. if (preHomed)
  364. {
  365. PostMsg(LoaderMSG.ReturnIdle);
  366. return false;
  367. }
  368. //Header信息
  369. if (_headerdata != null)
  370. {
  371. WaferHolderInfo info = WaferHolderManager.Instance.GetWaferHolder(Module.ToString());
  372. _headerdata.SequenceRecipe = (info != null ? $"{info.SequenceRecipe.SequenceType}\\" + $"{info.SequenceRecipe.Ppid}.seq.rcp" : null);
  373. _headerdata.ProcessTransferList = (info != null ? info.SchedulerModules : null);
  374. LoaderLotTrackUtil.ExportLoaderLotTrack(Module.ToString(), _unloadLotTrackDatas, _loadLotTrackDatas, _flowLotTrackdatas, _headerdata, _loaderOperatingWaferInfosList,
  375. _loadTimeList, _unloadTimeList, _unloadStartTime, LotTrackDatasStatus.None, LotTrackDatasStatus.None, LotTrackDatasStatus.None, _unloadLotTrackDatasBuffer, LotTrackDatasStatus.None);
  376. }
  377. return true;
  378. }
  379. #endregion
  380. /// <summary>
  381. /// 进入错误状态
  382. /// </summary>
  383. /// <param name="param"></param>
  384. /// <returns></returns>
  385. private bool EnterError(object param)
  386. {
  387. return true;
  388. }
  389. /// <summary>
  390. /// 进入初始化状态
  391. /// </summary>
  392. /// <param name="param"></param>
  393. /// <returns></returns>
  394. private bool EnterInit(object param)
  395. {
  396. _isHomed = false;
  397. return true;
  398. }
  399. #region HomeAll
  400. /// <summary>
  401. /// Home All
  402. /// </summary>
  403. /// <param name="param"></param>
  404. /// <returns></returns>
  405. private bool HomeAll(object[] param)
  406. {
  407. _isHomed = false;
  408. bool result= _homeAllRoutine.Start(param) == RState.Running;
  409. if (result)
  410. {
  411. _currentRoutine = _homeAllRoutine;
  412. }
  413. return result;
  414. }
  415. /// <summary>
  416. /// Load All监控
  417. /// </summary>
  418. /// <param name="param"></param>
  419. /// <returns></returns>
  420. private bool HomeAllMonitor(object[] param)
  421. {
  422. RState state = _homeAllRoutine.Monitor();
  423. if (state==RState.Failed||state==RState.Timeout)
  424. {
  425. _currentRoutine = null;
  426. PostMsg(LoaderMSG.Error);
  427. return false;
  428. }
  429. bool result= state == RState.End;
  430. if(result)
  431. {
  432. _currentRoutine = null;
  433. _isHomed = true;
  434. }
  435. return result;
  436. }
  437. #endregion
  438. #region Switch On All
  439. private bool SwitchOnAll(object[] param)
  440. {
  441. return _switchAllOnRoutine.Start(param) == RState.Running;
  442. }
  443. private bool SwitchOnAllMonitor(object[] param)
  444. {
  445. RState state = _switchAllOnRoutine.Monitor();
  446. if (state == RState.Failed || state == RState.Timeout)
  447. {
  448. PostMsg(LoaderMSG.ReturnInit);
  449. return false;
  450. }
  451. bool result= state == RState.End;
  452. if(result)
  453. {
  454. _isHomed = false;
  455. }
  456. return result;
  457. }
  458. #endregion
  459. #region Switch Off All
  460. private bool SwitchOffAll(object[] param)
  461. {
  462. return _switchAllOffRoutine.Start(param) == RState.Running;
  463. }
  464. private bool SwitchOffAllMonitor(object[] param)
  465. {
  466. RState state = _switchAllOffRoutine.Monitor();
  467. if (state == RState.Failed || state == RState.Timeout)
  468. {
  469. PostMsg(LoaderMSG.ReturnInit);
  470. return false;
  471. }
  472. bool result = state == RState.End;
  473. if (result)
  474. {
  475. _isHomed = false;
  476. }
  477. return result;
  478. }
  479. #endregion
  480. #region Prepare for Place
  481. /// <summary>
  482. /// Prepare For Place
  483. /// </summary>
  484. /// <returns></returns>
  485. private bool PrePareForPlace(object param)
  486. {
  487. return _rotationAxis.PositionStation("TRNPA");
  488. }
  489. /// <summary>
  490. /// Prepare For Place监控
  491. /// </summary>
  492. /// <param name="param"></param>
  493. /// <returns></returns>
  494. private bool PrepareForPlaceMonitor(object param)
  495. {
  496. RState ret = _rotationAxis.Status;
  497. if (ret == RState.End)
  498. {
  499. return true;
  500. }
  501. if (ret == RState.Failed || ret == RState.Timeout)
  502. {
  503. PostMsg(LoaderMSG.Error);
  504. }
  505. return false;
  506. }
  507. #endregion
  508. #region Unload Side
  509. /// <summary>
  510. /// Unload Side
  511. /// </summary>
  512. /// <param name="param"></param>
  513. /// <returns></returns>
  514. private bool UnloadSide(object[] param)
  515. {
  516. bool result= _unloadSideRoutine.Start(param) == RState.Running;
  517. if(result)
  518. {
  519. LotTrackDataClear();
  520. _currentRoutine = _unloadSideRoutine;
  521. _unloadLotTrackDatas.Clear();
  522. _unloadLotTrackDatasBuffer.Clear();
  523. _unloadTimeList.Clear();
  524. _unloadTimeList.Add(DateTime.Now);
  525. _unloadStartTime = DateTime.Now;
  526. _loaderOperatingWaferInfosList["unload"] = GetWaferInfo();
  527. //Header信息
  528. _headerdata = new LotTrackFileHeaderCommonData();
  529. _headerdata.SoftWareVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
  530. if (SC.ContainsItem("System.ToolID")) _headerdata.ToolID = SC.GetStringValue("System.ToolID");
  531. _loadDatasStatus = LotTrackDatasStatus.None;
  532. _unloadDatasStatus = LotTrackDatasStatus.None;
  533. _flowTestDatasStatus = LotTrackDatasStatus.None;
  534. _headerdata.ProcessTransferList = new List<string>();
  535. }
  536. return result;
  537. }
  538. /// <summary>
  539. /// Retry UloadSide
  540. /// </summary>
  541. /// <param name="param"></param>
  542. /// <returns></returns>
  543. private bool RetryUnloadSide(object[] param)
  544. {
  545. int stepIndex = (int)param[0];
  546. bool result = _unloadSideRoutine.Retry(stepIndex)==RState.Running;
  547. if (result)
  548. {
  549. _unloadDatasStatus = LotTrackDatasStatus.Half;
  550. _unloadLotTrackDatas.Clear();
  551. _currentRoutine = _unloadSideRoutine;
  552. }
  553. return result;
  554. }
  555. /// <summary>
  556. /// Unload Side监控
  557. /// </summary>
  558. /// <param name="param"></param>
  559. /// <returns></returns>
  560. private bool UnloadSideMonitor(object param)
  561. {
  562. RState ret = _unloadSideRoutine.Monitor();
  563. if (ret == RState.End)
  564. {
  565. AlarmListManager.Instance.CheckModuleAlamAndRemove(Module.ToString(), LOADERSTATE.Unloading.ToString());
  566. _unloadLotTrackDatas = _unloadSideRoutine.UnloadLotTrackDatas;
  567. _unloadLotTrackDatasBuffer.AddRange(_unloadSideRoutine.UnloadLotTrackDatas);
  568. _unloadTimeList.Add(DateTime.Now);
  569. //Header信息
  570. WaferHolderInfo info = WaferHolderManager.Instance.GetWaferHolder(Module.ToString());
  571. _headerdata.SequenceRecipe = ((info != null && info.SequenceRecipe != null) ? $"{info.SequenceRecipe.SequenceType}\\" + $"{info.SequenceRecipe.Ppid}.seq.rcp" : "");
  572. if (info != null) _headerdata.ProcessTransferList.AddRange(info.SchedulerModules);
  573. info.SchedulerModules.Clear();
  574. LoaderLotTrackUtil.ExportLoaderLotTrack(Module.ToString(), _unloadLotTrackDatas, _loadLotTrackDatas, _flowLotTrackdatas, _headerdata, _loaderOperatingWaferInfosList,
  575. _loadTimeList, _unloadTimeList, _unloadStartTime, _unloadDatasStatus, _loadDatasStatus, _flowTestDatasStatus, _unloadLotTrackDatasBuffer, _unloadDatasStatus, true);
  576. return true;
  577. }
  578. if (ret == RState.Failed || ret == RState.Timeout)
  579. {
  580. if (Singleton<RouteManager>.Instance.IsAutoRunning)
  581. {
  582. AlarmList alarmList = new AlarmList(Module.ToString(), ((LOADERSTATE)fsm.State).ToString(), (int)LoaderMSG.UnloadSide,
  583. _unloadSideRoutine.ErrorMsg, _unloadSideRoutine.ErrorStep, (int)AlarmType.Error);
  584. AlarmListManager.Instance.AddAlarm(alarmList);
  585. }
  586. PostMsg(LoaderMSG.Error);
  587. _unloadLotTrackDatas = _unloadSideRoutine.UnloadLotTrackDatas;
  588. _unloadLotTrackDatasBuffer.AddRange(_unloadSideRoutine.UnloadLotTrackDatas);
  589. ////Header信息
  590. WaferHolderInfo info = WaferHolderManager.Instance.GetWaferHolder(Module.ToString());
  591. _headerdata.SequenceRecipe = ((info != null && info.SequenceRecipe != null) ? $"{info.SequenceRecipe.SequenceType}\\" + $"{info.SequenceRecipe.Ppid}.seq.rcp" : "");
  592. if (info != null) _headerdata.ProcessTransferList.AddRange(info.SchedulerModules);
  593. info.SchedulerModules.Clear();
  594. LoaderLotTrackUtil.ExportLoaderLotTrack(Module.ToString(), _unloadLotTrackDatas, _loadLotTrackDatas, _flowLotTrackdatas, _headerdata, _loaderOperatingWaferInfosList,
  595. _loadTimeList, _unloadTimeList, _unloadStartTime, _unloadDatasStatus, _loadDatasStatus, _flowTestDatasStatus, _unloadLotTrackDatasBuffer, _unloadDatasStatus, true);
  596. }
  597. return false;
  598. }
  599. /// <summary>
  600. /// 确认UnloadAll是否完成
  601. /// </summary>
  602. /// <param name="param"></param>
  603. /// <returns></returns>
  604. private bool ConfirmUnloadSide(object[] param)
  605. {
  606. int stepIdex=(int)param[0];
  607. bool result = _unloadSideRoutine.CheckCompleteCondition(stepIdex);
  608. if(!result)
  609. {
  610. if (Singleton<RouteManager>.Instance.IsAutoRunning)
  611. {
  612. AlarmList alarmList = new AlarmList(Module.ToString(), ((LOADERSTATE)fsm.State).ToString(), (int)LoaderMSG.UnloadSide,
  613. _unloadSideRoutine.ErrorMsg, _unloadSideRoutine.ErrorStep, (int)AlarmType.Error);
  614. AlarmListManager.Instance.AddAlarm(alarmList);
  615. }
  616. PostMsg(LoaderMSG.Error);
  617. }
  618. else
  619. {
  620. if (Singleton<RouteManager>.Instance.IsAutoRunning)
  621. {
  622. AlarmListManager.Instance.CheckModuleAlamAndRemove(Module.ToString(), LOADERSTATE.Unloading.ToString());
  623. }
  624. }
  625. return result;
  626. }
  627. #endregion
  628. #region Load Side
  629. /// <summary>
  630. /// Load Side
  631. /// </summary>
  632. /// <param name="param"></param>
  633. /// <returns></returns>
  634. private bool LoadSide(object[] param)
  635. {
  636. bool result= _loadSideRoutine.Start(param) == RState.Running;
  637. if(result)
  638. {
  639. _currentRoutine = _loadSideRoutine;
  640. //_loadTimeList.Clear();
  641. _flowLotTrackdatas.Clear();
  642. _loadLotTrackDatas.Clear();
  643. _loadDatasStatus = LotTrackDatasStatus.None;
  644. _flowTestDatasStatus = LotTrackDatasStatus.None;
  645. _unloadDatasStatus = LotTrackDatasStatus.Complete;
  646. _unloadDatasBufferStatus = LotTrackDatasStatus.None;
  647. }
  648. return result;
  649. }
  650. /// <summary>
  651. /// Retry LoadSide
  652. /// </summary>
  653. /// <param name="param"></param>
  654. /// <returns></returns>
  655. private bool RetryLoadSide(object[] param)
  656. {
  657. int stepIndex = (int)param[0];
  658. bool result = _loadSideRoutine.Retry(stepIndex) == RState.Running;
  659. if (result)
  660. {
  661. _unloadDatasStatus = LotTrackDatasStatus.Complete;
  662. _unloadDatasBufferStatus = LotTrackDatasStatus.Complete;
  663. SetLotTrackDatasStatus(stepIndex);
  664. _currentRoutine = _loadSideRoutine;
  665. }
  666. return result;
  667. }
  668. /// <summary>
  669. /// 监控LoadSide
  670. /// </summary>
  671. /// <param name="param"></param>
  672. /// <returns></returns>
  673. private bool LoadSideMonitor(object param)
  674. {
  675. RState ret = _loadSideRoutine.Monitor();
  676. if (ret == RState.End)
  677. {
  678. AlarmListManager.Instance.CheckModuleAlamAndRemove(Module.ToString(), LOADERSTATE.Loading.ToString());
  679. _loadLotTrackDatas = _loadSideRoutine.LoadLotTrackDatas;
  680. _loadTimeList = _loadSideRoutine.LoadTimeList;
  681. _flowLotTrackdatas = _loadSideRoutine.FlowLotTrackDatas;
  682. bool clearFlag = _loadDatasStatus == LotTrackDatasStatus.None && _flowTestDatasStatus == LotTrackDatasStatus.None;
  683. _loaderOperatingWaferInfosList["load"] = GetWaferInfo(clearFlag);
  684. //Header信息
  685. WaferHolderInfo info = WaferHolderManager.Instance.GetWaferHolder(Module.ToString());
  686. _headerdata.SequenceRecipe = ((info != null && info.SequenceRecipe != null) ? $"{info.SequenceRecipe.SequenceType}\\" + $"{info.SequenceRecipe.Ppid}.seq.rcp" : "");
  687. if(info != null) _headerdata.ProcessTransferList.AddRange(info.SchedulerModules);
  688. info.SchedulerModules.Clear();
  689. LoaderLotTrackUtil.ExportLoaderLotTrack(Module.ToString(), _unloadLotTrackDatas, _loadLotTrackDatas, _flowLotTrackdatas, _headerdata, _loaderOperatingWaferInfosList,
  690. _loadTimeList, _unloadTimeList,_unloadStartTime, _unloadDatasStatus, _loadDatasStatus, _flowTestDatasStatus, _unloadLotTrackDatasBuffer, _unloadDatasBufferStatus);
  691. return true;
  692. }
  693. if (ret == RState.Failed || ret == RState.Timeout)
  694. {
  695. if (Singleton<RouteManager>.Instance.IsAutoRunning)
  696. {
  697. AlarmList alarmList = new AlarmList(Module.ToString(), ((LOADERSTATE)fsm.State).ToString(), (int)LoaderMSG.LoadSide,
  698. _loadSideRoutine.ErrorMsg, _loadSideRoutine.ErrorStep, (int)AlarmType.Error);
  699. AlarmListManager.Instance.AddAlarm(alarmList);
  700. }
  701. PostMsg(LoaderMSG.Error);
  702. _loadLotTrackDatas = _loadSideRoutine.LoadLotTrackDatas;
  703. _loadTimeList = _loadSideRoutine.LoadTimeList;
  704. _flowLotTrackdatas = _loadSideRoutine.FlowLotTrackDatas;
  705. bool clearFlag = _loadDatasStatus == LotTrackDatasStatus.None && _flowTestDatasStatus == LotTrackDatasStatus.None;
  706. _loaderOperatingWaferInfosList["load"] = GetWaferInfo(clearFlag);
  707. //Header信息
  708. WaferHolderInfo info = WaferHolderManager.Instance.GetWaferHolder(Module.ToString());
  709. _headerdata.SequenceRecipe = ((info != null && info.SequenceRecipe != null) ? $"{info.SequenceRecipe.SequenceType}\\" + $"{info.SequenceRecipe.Ppid}.seq.rcp" : "");
  710. if (info != null) _headerdata.ProcessTransferList.AddRange(info.SchedulerModules);
  711. info.SchedulerModules.Clear();
  712. LoaderLotTrackUtil.ExportLoaderLotTrack(Module.ToString(), _unloadLotTrackDatas, _loadLotTrackDatas, _flowLotTrackdatas, _headerdata, _loaderOperatingWaferInfosList,
  713. _loadTimeList, _unloadTimeList, _unloadStartTime, _unloadDatasStatus, _loadDatasStatus, _flowTestDatasStatus, _unloadLotTrackDatasBuffer, _unloadDatasBufferStatus);
  714. }
  715. return false;
  716. }
  717. /// <summary>
  718. /// 确认UnloadSide是否完成
  719. /// </summary>
  720. /// <param name="param"></param>
  721. /// <returns></returns>
  722. private bool ConfirmLoadSide(object[] param)
  723. {
  724. int stepIdex = (int)param[0];
  725. bool result = _loadSideRoutine.CheckCompleteCondition(stepIdex);
  726. if (!result)
  727. {
  728. if (Singleton<RouteManager>.Instance.IsAutoRunning)
  729. {
  730. AlarmList alarmList = new AlarmList(Module.ToString(), ((LOADERSTATE)fsm.State).ToString(), (int)LoaderMSG.LoadSide,
  731. _loadSideRoutine.ErrorMsg, _loadSideRoutine.ErrorStep, (int)AlarmType.Error);
  732. AlarmListManager.Instance.AddAlarm(alarmList);
  733. }
  734. PostMsg(LoaderMSG.Error);
  735. }
  736. else
  737. {
  738. if (Singleton<RouteManager>.Instance.IsAutoRunning)
  739. {
  740. AlarmListManager.Instance.CheckModuleAlamAndRemove(Module.ToString(),LOADERSTATE.Loading.ToString());
  741. }
  742. }
  743. return result;
  744. }
  745. #endregion
  746. #region LotTrack
  747. /// <summary>
  748. /// 获取Wafer信息
  749. /// </summary>
  750. private List<string> GetWaferInfo(bool clearPath = false)
  751. {
  752. List<string> waferIDs = new List<string>(new string[2]);
  753. WaferHolderInfo whInfo = WaferHolderManager.Instance.GetWaferHolder(Module.ToString());
  754. if (whInfo == null) return null;
  755. waferIDs[0] = string.IsNullOrEmpty(whInfo.WaferAId) ? "" : whInfo.WaferAId;
  756. waferIDs[1] = string.IsNullOrEmpty(whInfo.WaferBId) ? "" : whInfo.WaferBId;
  757. if (clearPath && !string.IsNullOrEmpty(waferIDs[0])) WaferManager.Instance.ClearWaferLotTrackPath(ModuleName.Loader1, 0);
  758. if (clearPath && !string.IsNullOrEmpty(waferIDs[1])) WaferManager.Instance.ClearWaferLotTrackPath(ModuleName.Loader1, 1);
  759. return waferIDs;
  760. }
  761. /// <summary>
  762. /// 清除信息
  763. /// </summary>
  764. private void LotTrackDataClear()
  765. {
  766. _headerdata = null;
  767. _loadLotTrackDatas.Clear();
  768. _unloadLotTrackDatas.Clear();
  769. _flowLotTrackdatas.Clear();
  770. _loadTimeList.Clear();
  771. _unloadTimeList.Clear();
  772. _loaderOperatingWaferInfosList["load"].Clear();
  773. _loaderOperatingWaferInfosList["unload"].Clear();
  774. }
  775. /// <summary>
  776. /// 设置Load LotTrackDatas记录状态
  777. /// </summary>
  778. /// <param name="stepIndex"></param>
  779. private void SetLotTrackDatasStatus(int stepIndex)
  780. {
  781. if (stepIndex == 0 || stepIndex == -1)
  782. {
  783. _loadDatasStatus = LotTrackDatasStatus.Half;
  784. _flowTestDatasStatus = LotTrackDatasStatus.None;
  785. }
  786. else if (stepIndex == 1)
  787. {
  788. _loadDatasStatus = LotTrackDatasStatus.Complete;
  789. _flowTestDatasStatus = LotTrackDatasStatus.None;
  790. }
  791. else
  792. {
  793. _loadDatasStatus = LotTrackDatasStatus.Complete;
  794. _flowTestDatasStatus = LotTrackDatasStatus.Complete;
  795. }
  796. }
  797. #endregion
  798. #region LoaderRetry
  799. /// <summary>
  800. /// Retry
  801. /// </summary>
  802. /// <param name="param"></param>
  803. /// <returns></returns>
  804. private bool LoaderRetry(object[] param)
  805. {
  806. AlarmList alarmList = AlarmListManager.Instance.GetAlarmListByModule(Module.ToString());
  807. if (alarmList != null)
  808. {
  809. CheckToPostMessage<LOADERSTATE, LoaderMSG>(eEvent.ERR_LOADER, Module.ToString(), alarmList.ModuleCmd,
  810. alarmList.ModuleStep);
  811. }
  812. return false;
  813. }
  814. #endregion
  815. #region ConfirmComplete
  816. /// <summary>
  817. /// 确认是否完成
  818. /// </summary>
  819. /// <param name="param"></param>
  820. /// <returns></returns>
  821. private bool ConfirmComplete(object[] param)
  822. {
  823. AlarmList alarmList = AlarmListManager.Instance.GetAlarmListByModule(Module.ToString());
  824. if (alarmList != null)
  825. {
  826. if(alarmList.ModuleState==LOADERSTATE.Unloading.ToString())
  827. {
  828. CheckToPostMessage<LOADERSTATE, LoaderMSG>(eEvent.ERR_LOADER, Module.ToString(),(int)LoaderMSG.UnloadSide,alarmList.ModuleStep);
  829. }
  830. else if(alarmList.ModuleState==LOADERSTATE.Loading.ToString())
  831. {
  832. CheckToPostMessage<LOADERSTATE, LoaderMSG>(eEvent.ERR_LOADER, Module.ToString(), (int)LoaderMSG.LoadSide,alarmList.ModuleStep);
  833. }
  834. else if (alarmList.ModuleState == LOADERSTATE.PrepreForPlacing.ToString())
  835. {
  836. CheckToPostMessage<LOADERSTATE, LoaderMSG>(eEvent.ERR_LOADER, Module.ToString(), (int)LoaderMSG.PrepareForPlace, alarmList.ModuleStep);
  837. }
  838. else
  839. {
  840. PostMsg(LoaderMSG.Error);
  841. }
  842. }
  843. return false;
  844. }
  845. /// <summary>
  846. /// 清除报警
  847. /// </summary>
  848. /// <param name="param"></param>
  849. /// <returns></returns>
  850. private bool ClearModuleAlarm(object[] param)
  851. {
  852. AlarmList alarmList = AlarmListManager.Instance.GetAlarmListByModule(Module.ToString());
  853. if (alarmList != null)
  854. {
  855. AlarmListManager.Instance.CheckModuleAlamAndRemove(Module.ToString(), "");
  856. }
  857. return true;
  858. }
  859. #endregion
  860. public bool Check(int msg, out string reason, params object[] args)
  861. {
  862. reason = "";
  863. return false;
  864. }
  865. public bool CheckAcked(int msg)
  866. {
  867. return false;
  868. }
  869. public int Invoke(string function, params object[] args)
  870. {
  871. switch (function)
  872. {
  873. case "HomeAll":
  874. if(IsIdle)
  875. {
  876. return (int)FSM_MSG.NONE;
  877. }
  878. if (CheckToPostMessage<LOADERSTATE, LoaderMSG>(eEvent.ERR_LOADER, Module.ToString(), (int)LoaderMSG.HomeAll))
  879. {
  880. return (int)FSM_MSG.NONE;
  881. }
  882. else
  883. {
  884. return (int)FSM_MSG.ALARM;
  885. }
  886. case "Abort":
  887. CheckToPostMessage<LOADERSTATE, LoaderMSG>(eEvent.ERR_LOADER, Module.ToString(), (int)LoaderMSG.Abort);
  888. return (int)FSM_MSG.NONE;
  889. case "PrepareForPlace":
  890. if (CheckToPostMessage<LOADERSTATE, LoaderMSG>(eEvent.ERR_LOADER, Module.ToString(), (int)LoaderMSG.PrepareForPlace))
  891. {
  892. return (int)LoaderMSG.PrepareForPlace;
  893. }
  894. else
  895. {
  896. return (int)FSM_MSG.NONE;
  897. }
  898. case "Retry":
  899. if (CheckToPostMessage<LOADERSTATE, LoaderMSG>(eEvent.ERR_LOADER, Module.ToString(), (int)LoaderMSG.Retry,args))
  900. {
  901. return (int)LoaderMSG.Retry;
  902. }
  903. else
  904. {
  905. return (int)FSM_MSG.NONE;
  906. }
  907. case "ConfirmComplete":
  908. if (CheckToPostMessage<LOADERSTATE, LoaderMSG>(eEvent.ERR_LOADER, Module.ToString(), (int)LoaderMSG.ConfirmComplete, args))
  909. {
  910. return (int)LoaderMSG.ConfirmComplete;
  911. }
  912. else
  913. {
  914. return (int)FSM_MSG.NONE;
  915. }
  916. }
  917. return (int)FSM_MSG.NONE;
  918. }
  919. }
  920. public enum LoaderMSG
  921. {
  922. ReturnInit,
  923. ReturnIdle,
  924. Abort,
  925. HomeAll,
  926. GoToSavedPosition,
  927. StopFlow,
  928. SwitchOnAll,
  929. SwitchOffAll,
  930. Error,
  931. ClearError,
  932. PrepareForPlace,
  933. ReadyForPuf,
  934. UnloadSide,
  935. LoadSide,
  936. Retry,
  937. ConfirmComplete
  938. }
  939. }