LoaderEntity.cs 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988
  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. //默认"TRNPA"
  488. string str = (param==null||param.Length==0)? "TRNPA":param[0].ToString();
  489. return _rotationAxis.PositionStation(str);
  490. }
  491. /// <summary>
  492. /// Prepare For Place监控
  493. /// </summary>
  494. /// <param name="param"></param>
  495. /// <returns></returns>
  496. private bool PrepareForPlaceMonitor(object param)
  497. {
  498. RState ret = _rotationAxis.Status;
  499. if (ret == RState.End)
  500. {
  501. return true;
  502. }
  503. if (ret == RState.Failed || ret == RState.Timeout)
  504. {
  505. PostMsg(LoaderMSG.Error);
  506. }
  507. return false;
  508. }
  509. #endregion
  510. #region Unload Side
  511. /// <summary>
  512. /// Unload Side
  513. /// </summary>
  514. /// <param name="param"></param>
  515. /// <returns></returns>
  516. private bool UnloadSide(object[] param)
  517. {
  518. bool result= _unloadSideRoutine.Start(param) == RState.Running;
  519. if(result)
  520. {
  521. LotTrackDataClear();
  522. _currentRoutine = _unloadSideRoutine;
  523. _unloadLotTrackDatas.Clear();
  524. _unloadLotTrackDatasBuffer.Clear();
  525. _unloadTimeList.Clear();
  526. _unloadTimeList.Add(DateTime.Now);
  527. _unloadStartTime = DateTime.Now;
  528. _loaderOperatingWaferInfosList["unload"] = GetWaferInfo();
  529. //Header信息
  530. _headerdata = new LotTrackFileHeaderCommonData();
  531. _headerdata.SoftWareVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
  532. if (SC.ContainsItem("System.ToolID")) _headerdata.ToolID = SC.GetStringValue("System.ToolID");
  533. _loadDatasStatus = LotTrackDatasStatus.None;
  534. _unloadDatasStatus = LotTrackDatasStatus.None;
  535. _flowTestDatasStatus = LotTrackDatasStatus.None;
  536. _headerdata.ProcessTransferList = new List<string>();
  537. }
  538. return result;
  539. }
  540. /// <summary>
  541. /// Retry UloadSide
  542. /// </summary>
  543. /// <param name="param"></param>
  544. /// <returns></returns>
  545. private bool RetryUnloadSide(object[] param)
  546. {
  547. int stepIndex = (int)param[0];
  548. bool result = _unloadSideRoutine.Retry(stepIndex)==RState.Running;
  549. if (result)
  550. {
  551. _unloadDatasStatus = LotTrackDatasStatus.Half;
  552. _unloadLotTrackDatas.Clear();
  553. _currentRoutine = _unloadSideRoutine;
  554. }
  555. return result;
  556. }
  557. /// <summary>
  558. /// Unload Side监控
  559. /// </summary>
  560. /// <param name="param"></param>
  561. /// <returns></returns>
  562. private bool UnloadSideMonitor(object param)
  563. {
  564. RState ret = _unloadSideRoutine.Monitor();
  565. if (ret == RState.End)
  566. {
  567. AlarmListManager.Instance.CheckModuleAlamAndRemove(Module.ToString(), LOADERSTATE.Unloading.ToString());
  568. _unloadLotTrackDatas = _unloadSideRoutine.UnloadLotTrackDatas;
  569. _unloadLotTrackDatasBuffer.AddRange(_unloadSideRoutine.UnloadLotTrackDatas);
  570. _unloadTimeList.Add(DateTime.Now);
  571. //Header信息
  572. WaferHolderInfo info = WaferHolderManager.Instance.GetWaferHolder(Module.ToString());
  573. _headerdata.SequenceRecipe = ((info != null && info.SequenceRecipe != null) ? $"{info.SequenceRecipe.SequenceType}\\" + $"{info.SequenceRecipe.Ppid}.seq.rcp" : "");
  574. if (info != null) _headerdata.ProcessTransferList.AddRange(info.SchedulerModules);
  575. info.SchedulerModules.Clear();
  576. LoaderLotTrackUtil.ExportLoaderLotTrack(Module.ToString(), _unloadLotTrackDatas, _loadLotTrackDatas, _flowLotTrackdatas, _headerdata, _loaderOperatingWaferInfosList,
  577. _loadTimeList, _unloadTimeList, _unloadStartTime, _unloadDatasStatus, _loadDatasStatus, _flowTestDatasStatus, _unloadLotTrackDatasBuffer, _unloadDatasStatus, true);
  578. return true;
  579. }
  580. if (ret == RState.Failed || ret == RState.Timeout)
  581. {
  582. if (Singleton<RouteManager>.Instance.IsAutoRunning)
  583. {
  584. AlarmList alarmList = new AlarmList(Module.ToString(), ((LOADERSTATE)fsm.State).ToString(), (int)LoaderMSG.UnloadSide,
  585. _unloadSideRoutine.ErrorMsg, _unloadSideRoutine.ErrorStep, (int)AlarmType.Error);
  586. AlarmListManager.Instance.AddAlarm(alarmList);
  587. }
  588. PostMsg(LoaderMSG.Error);
  589. _unloadLotTrackDatas = _unloadSideRoutine.UnloadLotTrackDatas;
  590. _unloadLotTrackDatasBuffer.AddRange(_unloadSideRoutine.UnloadLotTrackDatas);
  591. ////Header信息
  592. WaferHolderInfo info = WaferHolderManager.Instance.GetWaferHolder(Module.ToString());
  593. _headerdata.SequenceRecipe = ((info != null && info.SequenceRecipe != null) ? $"{info.SequenceRecipe.SequenceType}\\" + $"{info.SequenceRecipe.Ppid}.seq.rcp" : "");
  594. if (info != null) _headerdata.ProcessTransferList.AddRange(info.SchedulerModules);
  595. info.SchedulerModules.Clear();
  596. LoaderLotTrackUtil.ExportLoaderLotTrack(Module.ToString(), _unloadLotTrackDatas, _loadLotTrackDatas, _flowLotTrackdatas, _headerdata, _loaderOperatingWaferInfosList,
  597. _loadTimeList, _unloadTimeList, _unloadStartTime, _unloadDatasStatus, _loadDatasStatus, _flowTestDatasStatus, _unloadLotTrackDatasBuffer, _unloadDatasStatus, true);
  598. }
  599. return false;
  600. }
  601. /// <summary>
  602. /// 确认UnloadAll是否完成
  603. /// </summary>
  604. /// <param name="param"></param>
  605. /// <returns></returns>
  606. private bool ConfirmUnloadSide(object[] param)
  607. {
  608. int stepIdex=(int)param[0];
  609. bool result = _unloadSideRoutine.CheckCompleteCondition(stepIdex);
  610. if(!result)
  611. {
  612. if (Singleton<RouteManager>.Instance.IsAutoRunning)
  613. {
  614. AlarmList alarmList = new AlarmList(Module.ToString(), ((LOADERSTATE)fsm.State).ToString(), (int)LoaderMSG.UnloadSide,
  615. _unloadSideRoutine.ErrorMsg, _unloadSideRoutine.ErrorStep, (int)AlarmType.Error);
  616. AlarmListManager.Instance.AddAlarm(alarmList);
  617. }
  618. PostMsg(LoaderMSG.Error);
  619. }
  620. else
  621. {
  622. if (Singleton<RouteManager>.Instance.IsAutoRunning)
  623. {
  624. AlarmListManager.Instance.CheckModuleAlamAndRemove(Module.ToString(), LOADERSTATE.Unloading.ToString());
  625. }
  626. }
  627. return result;
  628. }
  629. #endregion
  630. #region Load Side
  631. /// <summary>
  632. /// Load Side
  633. /// </summary>
  634. /// <param name="param"></param>
  635. /// <returns></returns>
  636. private bool LoadSide(object[] param)
  637. {
  638. bool result= _loadSideRoutine.Start(param) == RState.Running;
  639. if(result)
  640. {
  641. _currentRoutine = _loadSideRoutine;
  642. //_loadTimeList.Clear();
  643. _flowLotTrackdatas.Clear();
  644. _loadLotTrackDatas.Clear();
  645. _loadDatasStatus = LotTrackDatasStatus.None;
  646. _flowTestDatasStatus = LotTrackDatasStatus.None;
  647. _unloadDatasStatus = LotTrackDatasStatus.Complete;
  648. _unloadDatasBufferStatus = LotTrackDatasStatus.None;
  649. }
  650. return result;
  651. }
  652. /// <summary>
  653. /// Retry LoadSide
  654. /// </summary>
  655. /// <param name="param"></param>
  656. /// <returns></returns>
  657. private bool RetryLoadSide(object[] param)
  658. {
  659. int stepIndex = (int)param[0];
  660. bool result = _loadSideRoutine.Retry(stepIndex) == RState.Running;
  661. if (result)
  662. {
  663. _unloadDatasStatus = LotTrackDatasStatus.Complete;
  664. _unloadDatasBufferStatus = LotTrackDatasStatus.Complete;
  665. SetLotTrackDatasStatus(stepIndex);
  666. _currentRoutine = _loadSideRoutine;
  667. }
  668. return result;
  669. }
  670. /// <summary>
  671. /// 监控LoadSide
  672. /// </summary>
  673. /// <param name="param"></param>
  674. /// <returns></returns>
  675. private bool LoadSideMonitor(object param)
  676. {
  677. RState ret = _loadSideRoutine.Monitor();
  678. if (ret == RState.End)
  679. {
  680. AlarmListManager.Instance.CheckModuleAlamAndRemove(Module.ToString(), LOADERSTATE.Loading.ToString());
  681. _loadLotTrackDatas = _loadSideRoutine.LoadLotTrackDatas;
  682. _loadTimeList = _loadSideRoutine.LoadTimeList;
  683. _flowLotTrackdatas = _loadSideRoutine.FlowLotTrackDatas;
  684. bool clearFlag = _loadDatasStatus == LotTrackDatasStatus.None && _flowTestDatasStatus == LotTrackDatasStatus.None;
  685. _loaderOperatingWaferInfosList["load"] = GetWaferInfo(clearFlag);
  686. //Header信息
  687. WaferHolderInfo info = WaferHolderManager.Instance.GetWaferHolder(Module.ToString());
  688. _headerdata.SequenceRecipe = ((info != null && info.SequenceRecipe != null) ? $"{info.SequenceRecipe.SequenceType}\\" + $"{info.SequenceRecipe.Ppid}.seq.rcp" : "");
  689. if(info != null) _headerdata.ProcessTransferList.AddRange(info.SchedulerModules);
  690. info.SchedulerModules.Clear();
  691. LoaderLotTrackUtil.ExportLoaderLotTrack(Module.ToString(), _unloadLotTrackDatas, _loadLotTrackDatas, _flowLotTrackdatas, _headerdata, _loaderOperatingWaferInfosList,
  692. _loadTimeList, _unloadTimeList,_unloadStartTime, _unloadDatasStatus, _loadDatasStatus, _flowTestDatasStatus, _unloadLotTrackDatasBuffer, _unloadDatasBufferStatus);
  693. return true;
  694. }
  695. if (ret == RState.Failed || ret == RState.Timeout)
  696. {
  697. if (Singleton<RouteManager>.Instance.IsAutoRunning)
  698. {
  699. AlarmList alarmList = new AlarmList(Module.ToString(), ((LOADERSTATE)fsm.State).ToString(), (int)LoaderMSG.LoadSide,
  700. _loadSideRoutine.ErrorMsg, _loadSideRoutine.ErrorStep, (int)AlarmType.Error);
  701. AlarmListManager.Instance.AddAlarm(alarmList);
  702. }
  703. PostMsg(LoaderMSG.Error);
  704. _loadLotTrackDatas = _loadSideRoutine.LoadLotTrackDatas;
  705. _loadTimeList = _loadSideRoutine.LoadTimeList;
  706. _flowLotTrackdatas = _loadSideRoutine.FlowLotTrackDatas;
  707. bool clearFlag = _loadDatasStatus == LotTrackDatasStatus.None && _flowTestDatasStatus == LotTrackDatasStatus.None;
  708. _loaderOperatingWaferInfosList["load"] = GetWaferInfo(clearFlag);
  709. //Header信息
  710. WaferHolderInfo info = WaferHolderManager.Instance.GetWaferHolder(Module.ToString());
  711. _headerdata.SequenceRecipe = ((info != null && info.SequenceRecipe != null) ? $"{info.SequenceRecipe.SequenceType}\\" + $"{info.SequenceRecipe.Ppid}.seq.rcp" : "");
  712. if (info != null) _headerdata.ProcessTransferList.AddRange(info.SchedulerModules);
  713. info.SchedulerModules.Clear();
  714. LoaderLotTrackUtil.ExportLoaderLotTrack(Module.ToString(), _unloadLotTrackDatas, _loadLotTrackDatas, _flowLotTrackdatas, _headerdata, _loaderOperatingWaferInfosList,
  715. _loadTimeList, _unloadTimeList, _unloadStartTime, _unloadDatasStatus, _loadDatasStatus, _flowTestDatasStatus, _unloadLotTrackDatasBuffer, _unloadDatasBufferStatus);
  716. }
  717. return false;
  718. }
  719. /// <summary>
  720. /// 确认UnloadSide是否完成
  721. /// </summary>
  722. /// <param name="param"></param>
  723. /// <returns></returns>
  724. private bool ConfirmLoadSide(object[] param)
  725. {
  726. int stepIdex = (int)param[0];
  727. bool result = _loadSideRoutine.CheckCompleteCondition(stepIdex);
  728. if (!result)
  729. {
  730. if (Singleton<RouteManager>.Instance.IsAutoRunning)
  731. {
  732. AlarmList alarmList = new AlarmList(Module.ToString(), ((LOADERSTATE)fsm.State).ToString(), (int)LoaderMSG.LoadSide,
  733. _loadSideRoutine.ErrorMsg, _loadSideRoutine.ErrorStep, (int)AlarmType.Error);
  734. AlarmListManager.Instance.AddAlarm(alarmList);
  735. }
  736. PostMsg(LoaderMSG.Error);
  737. }
  738. else
  739. {
  740. if (Singleton<RouteManager>.Instance.IsAutoRunning)
  741. {
  742. AlarmListManager.Instance.CheckModuleAlamAndRemove(Module.ToString(),LOADERSTATE.Loading.ToString());
  743. }
  744. }
  745. return result;
  746. }
  747. #endregion
  748. #region LotTrack
  749. /// <summary>
  750. /// 获取Wafer信息
  751. /// </summary>
  752. private List<string> GetWaferInfo(bool clearPath = false)
  753. {
  754. List<string> waferIDs = new List<string>(new string[2]);
  755. WaferHolderInfo whInfo = WaferHolderManager.Instance.GetWaferHolder(Module.ToString());
  756. if (whInfo == null) return null;
  757. waferIDs[0] = string.IsNullOrEmpty(whInfo.WaferAId) ? "" : whInfo.WaferAId;
  758. waferIDs[1] = string.IsNullOrEmpty(whInfo.WaferBId) ? "" : whInfo.WaferBId;
  759. if (clearPath && !string.IsNullOrEmpty(waferIDs[0])) WaferManager.Instance.ClearWaferLotTrackPath(ModuleName.Loader1, 0);
  760. if (clearPath && !string.IsNullOrEmpty(waferIDs[1])) WaferManager.Instance.ClearWaferLotTrackPath(ModuleName.Loader1, 1);
  761. return waferIDs;
  762. }
  763. /// <summary>
  764. /// 清除信息
  765. /// </summary>
  766. private void LotTrackDataClear()
  767. {
  768. _headerdata = null;
  769. _loadLotTrackDatas.Clear();
  770. _unloadLotTrackDatas.Clear();
  771. _flowLotTrackdatas.Clear();
  772. _loadTimeList.Clear();
  773. _unloadTimeList.Clear();
  774. _loaderOperatingWaferInfosList["load"].Clear();
  775. _loaderOperatingWaferInfosList["unload"].Clear();
  776. }
  777. /// <summary>
  778. /// 设置Load LotTrackDatas记录状态
  779. /// </summary>
  780. /// <param name="stepIndex"></param>
  781. private void SetLotTrackDatasStatus(int stepIndex)
  782. {
  783. if (stepIndex == 0 || stepIndex == -1)
  784. {
  785. _loadDatasStatus = LotTrackDatasStatus.Half;
  786. _flowTestDatasStatus = LotTrackDatasStatus.None;
  787. }
  788. else if (stepIndex == 1)
  789. {
  790. _loadDatasStatus = LotTrackDatasStatus.Complete;
  791. _flowTestDatasStatus = LotTrackDatasStatus.None;
  792. }
  793. else
  794. {
  795. _loadDatasStatus = LotTrackDatasStatus.Complete;
  796. _flowTestDatasStatus = LotTrackDatasStatus.Complete;
  797. }
  798. }
  799. #endregion
  800. #region LoaderRetry
  801. /// <summary>
  802. /// Retry
  803. /// </summary>
  804. /// <param name="param"></param>
  805. /// <returns></returns>
  806. private bool LoaderRetry(object[] param)
  807. {
  808. AlarmList alarmList = AlarmListManager.Instance.GetAlarmListByModule(Module.ToString());
  809. if (alarmList != null)
  810. {
  811. CheckToPostMessage<LOADERSTATE, LoaderMSG>(eEvent.ERR_LOADER, Module.ToString(), alarmList.ModuleCmd,
  812. alarmList.ModuleStep);
  813. }
  814. return false;
  815. }
  816. #endregion
  817. #region ConfirmComplete
  818. /// <summary>
  819. /// 确认是否完成
  820. /// </summary>
  821. /// <param name="param"></param>
  822. /// <returns></returns>
  823. private bool ConfirmComplete(object[] param)
  824. {
  825. AlarmList alarmList = AlarmListManager.Instance.GetAlarmListByModule(Module.ToString());
  826. if (alarmList != null)
  827. {
  828. if(alarmList.ModuleState==LOADERSTATE.Unloading.ToString())
  829. {
  830. CheckToPostMessage<LOADERSTATE, LoaderMSG>(eEvent.ERR_LOADER, Module.ToString(),(int)LoaderMSG.UnloadSide,alarmList.ModuleStep);
  831. }
  832. else if(alarmList.ModuleState==LOADERSTATE.Loading.ToString())
  833. {
  834. CheckToPostMessage<LOADERSTATE, LoaderMSG>(eEvent.ERR_LOADER, Module.ToString(), (int)LoaderMSG.LoadSide,alarmList.ModuleStep);
  835. }
  836. else if (alarmList.ModuleState == LOADERSTATE.PrepreForPlacing.ToString())
  837. {
  838. CheckToPostMessage<LOADERSTATE, LoaderMSG>(eEvent.ERR_LOADER, Module.ToString(), (int)LoaderMSG.PrepareForPlace, alarmList.ModuleStep);
  839. }
  840. else
  841. {
  842. PostMsg(LoaderMSG.Error);
  843. }
  844. }
  845. return false;
  846. }
  847. /// <summary>
  848. /// 清除报警
  849. /// </summary>
  850. /// <param name="param"></param>
  851. /// <returns></returns>
  852. private bool ClearModuleAlarm(object[] param)
  853. {
  854. AlarmList alarmList = AlarmListManager.Instance.GetAlarmListByModule(Module.ToString());
  855. if (alarmList != null)
  856. {
  857. AlarmListManager.Instance.CheckModuleAlamAndRemove(Module.ToString(), "");
  858. }
  859. return true;
  860. }
  861. #endregion
  862. public bool Check(int msg, out string reason, params object[] args)
  863. {
  864. reason = "";
  865. return false;
  866. }
  867. public bool CheckAcked(int msg)
  868. {
  869. return false;
  870. }
  871. public int Invoke(string function, params object[] args)
  872. {
  873. switch (function)
  874. {
  875. case "HomeAll":
  876. if(IsIdle)
  877. {
  878. return (int)FSM_MSG.NONE;
  879. }
  880. if (CheckToPostMessage<LOADERSTATE, LoaderMSG>(eEvent.ERR_LOADER, Module.ToString(), (int)LoaderMSG.HomeAll))
  881. {
  882. return (int)FSM_MSG.NONE;
  883. }
  884. else
  885. {
  886. return (int)FSM_MSG.ALARM;
  887. }
  888. case "Abort":
  889. CheckToPostMessage<LOADERSTATE, LoaderMSG>(eEvent.ERR_LOADER, Module.ToString(), (int)LoaderMSG.Abort);
  890. return (int)FSM_MSG.NONE;
  891. case "PrepareForPlace":
  892. if (CheckToPostMessage<LOADERSTATE, LoaderMSG>(eEvent.WARN_LOADER, Module.ToString(), (int)LoaderMSG.PrepareForPlace,args))
  893. {
  894. return (int)LoaderMSG.PrepareForPlace;
  895. }
  896. else
  897. {
  898. return (int)FSM_MSG.NONE;
  899. }
  900. case "Retry":
  901. if (CheckToPostMessage<LOADERSTATE, LoaderMSG>(eEvent.ERR_LOADER, Module.ToString(), (int)LoaderMSG.Retry,args))
  902. {
  903. return (int)LoaderMSG.Retry;
  904. }
  905. else
  906. {
  907. return (int)FSM_MSG.NONE;
  908. }
  909. case "ConfirmComplete":
  910. if (CheckToPostMessage<LOADERSTATE, LoaderMSG>(eEvent.ERR_LOADER, Module.ToString(), (int)LoaderMSG.ConfirmComplete, args))
  911. {
  912. return (int)LoaderMSG.ConfirmComplete;
  913. }
  914. else
  915. {
  916. return (int)FSM_MSG.NONE;
  917. }
  918. }
  919. return (int)FSM_MSG.NONE;
  920. }
  921. }
  922. public enum LoaderMSG
  923. {
  924. ReturnInit,
  925. ReturnIdle,
  926. Abort,
  927. HomeAll,
  928. GoToSavedPosition,
  929. StopFlow,
  930. SwitchOnAll,
  931. SwitchOffAll,
  932. Error,
  933. ClearError,
  934. PrepareForPlace,
  935. ReadyForPuf,
  936. UnloadSide,
  937. LoadSide,
  938. Retry,
  939. ConfirmComplete
  940. }
  941. }