LoaderEntity.cs 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995
  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. using System.Runtime.CompilerServices;
  32. namespace CyberX8_RT.Modules.Loader
  33. {
  34. public class LoaderEntity : Entity, IEntity, IModuleEntity
  35. {
  36. public enum LotTrackDatasStatus
  37. {
  38. None,
  39. Half,
  40. Complete
  41. }
  42. #region 属性
  43. public ModuleName Module { get; private set; }
  44. public bool IsInit
  45. {
  46. get { return fsm.State == (int)LOADERSTATE.Init; }
  47. }
  48. public bool IsIdle
  49. {
  50. get
  51. {
  52. return fsm.State == (int)LOADERSTATE.Idle;
  53. }
  54. }
  55. public bool IsError
  56. {
  57. get { return fsm.State == (int)LOADERSTATE.Error; }
  58. }
  59. public bool IsBusy
  60. {
  61. get { return !IsInit && !IsError && !IsIdle; }
  62. }
  63. public bool IsAuto { get; } = true;
  64. /// <summary>
  65. /// 是否为工程模式
  66. /// </summary>
  67. public bool IsEngineering { get; } = false;
  68. /// <summary>
  69. /// 是否为产品模式
  70. /// </summary>
  71. public bool IsProduction { get; } = true;
  72. public bool IsHomed
  73. {
  74. get { return _isHomed; }
  75. }
  76. /// <summary>
  77. /// 当前状态机状态
  78. /// </summary>
  79. public int State { get { return fsm.State; } }
  80. /// <summary>
  81. /// 是否禁用
  82. /// </summary>
  83. public bool IsDisable { get; internal set; }
  84. /// <summary>
  85. /// Rotation是否SwitchOn
  86. /// </summary>
  87. public bool IsRotationSwitchOn
  88. {
  89. get { return _rotationAxis.IsSwitchOn; }
  90. }
  91. /// <summary>
  92. /// ShuttleA是否SwitchOn
  93. /// </summary>
  94. public bool IsShuttleASwitchOn
  95. {
  96. get { return _shuttleAAxis.IsSwitchOn; }
  97. }
  98. /// <summary>
  99. /// ShuttleB是否SwitchOn
  100. /// </summary>
  101. public bool IsShuttleBSwitchOn
  102. {
  103. get { return _shuttleBAxis.IsSwitchOn; }
  104. }
  105. /// <summary>
  106. /// TiltA是否SwitchOn
  107. /// </summary>
  108. public bool IsTiltASwitchOn
  109. {
  110. get { return _tiltAAxis.IsSwitchOn; }
  111. }
  112. /// <summary>
  113. /// TiltB是否SwitchOn
  114. /// </summary>
  115. public bool IsTiltBSwitchOn
  116. {
  117. get { return _tiltBAxis.IsSwitchOn; }
  118. }
  119. /// <summary>
  120. /// CrsA是否SwitchOn
  121. /// </summary>
  122. public bool IsCrsASwitchOn
  123. {
  124. get { return _crsAAxis.IsSwitchOn; }
  125. }
  126. /// <summary>
  127. /// CrsB是否SwitchOn
  128. /// </summary>
  129. public bool IsCrsBSwitchOn
  130. {
  131. get { return _crsBAxis.IsSwitchOn; }
  132. }
  133. /// <summary>
  134. /// WaferHolder信息
  135. /// </summary>
  136. public WaferHolderInfo WaferHolderInfo { get { return WaferHolderManager.Instance.GetWaferHolder("Loader"); } }
  137. /// <summary>
  138. /// A面Wafer尺寸
  139. /// </summary>
  140. public int SideAWaferSize { get { return _sideAWaferSize; } }
  141. /// <summary>
  142. /// B面Wafer尺寸
  143. /// </summary>
  144. public int SideBWaferSize { get { return _sideBWaferSize; } }
  145. #endregion
  146. #region 内部变量
  147. private bool _isHomed = false;
  148. private IRoutine _currentRoutine;
  149. /// <summary>
  150. /// Loader当前unload、load操作Slot
  151. /// </summary>
  152. 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]) } };
  153. #region Axis
  154. JetAxisBase _shuttleAAxis;
  155. JetAxisBase _shuttleBAxis;
  156. JetAxisBase _tiltAAxis;
  157. JetAxisBase _tiltBAxis;
  158. JetAxisBase _crsAAxis;
  159. JetAxisBase _crsBAxis;
  160. JetAxisBase _rotationAxis;
  161. LoaderSideDevice _sideA;
  162. LoaderSideDevice _sideB;
  163. LoaderCommonDevice _loaderCommon;
  164. int _sideAWaferSize;
  165. int _sideBWaferSize;
  166. #endregion
  167. #region routine
  168. private LoaderHomeAllRoutine _homeAllRoutine;
  169. private LoaderSwitchAllOnRoutine _switchAllOnRoutine;
  170. private LoaderSwitchAllOffRoutine _switchAllOffRoutine;
  171. private LoaderUnloadSideRoutine _unloadSideRoutine;
  172. private LoaderLoadSideRoutine _loadSideRoutine;
  173. #endregion
  174. #region LotTrackDatas
  175. /// <summary>
  176. /// Load LotTrackData
  177. /// </summary>
  178. private List<LoaderLotTrackData> _loaderLotTrackDatas = new List<LoaderLotTrackData>();
  179. /// <summary>
  180. /// Flow Test LotTrackData
  181. /// </summary>
  182. private List<LoaderFlowLotTrackData> _flowLotTrackDatas = new List<LoaderFlowLotTrackData>();
  183. /// <summary>
  184. /// Load / Unload Time
  185. /// </summary>
  186. private List<DateTime> _timeList = new List<DateTime>();
  187. /// <summary>
  188. /// Load Start Time(file name)
  189. /// </summary>
  190. private DateTime _startTime;
  191. /// <summary>
  192. /// LotTrackHead
  193. /// </summary>
  194. private LotTrackFileHeaderCommonData _headerdata;
  195. /// <summary>
  196. /// Load Datas Status
  197. private LotTrackDatasStatus _datasStatus = LotTrackDatasStatus.None;
  198. /// <summary>
  199. /// Flow Test Datas status
  200. /// </summary>
  201. private LotTrackDatasStatus _flowDatasStatus = LotTrackDatasStatus.None;
  202. /// <summary>
  203. /// WaferGroup str
  204. /// </summary>
  205. private string _preWaferGroup = "";
  206. #endregion
  207. #endregion
  208. /// <summary>
  209. /// 构造函数
  210. /// </summary>
  211. /// <param name="module"></param>
  212. public LoaderEntity(ModuleName module)
  213. {
  214. this.Module = module;
  215. _shuttleAAxis = DEVICE.GetDevice<JetAxisBase>($"{module}.ShuttleA");
  216. _shuttleBAxis = DEVICE.GetDevice<JetAxisBase>($"{module}.ShuttleB");
  217. _tiltAAxis = DEVICE.GetDevice<JetAxisBase>($"{module}.TiltA");
  218. _tiltBAxis = DEVICE.GetDevice<JetAxisBase>($"{module}.TiltB");
  219. _crsAAxis = DEVICE.GetDevice<JetAxisBase>($"{module}.LSA");
  220. _crsBAxis = DEVICE.GetDevice<JetAxisBase>($"{module}.LSB");
  221. _rotationAxis = DEVICE.GetDevice<JetAxisBase>($"{module}.Rotation");
  222. _sideA = DEVICE.GetDevice<LoaderSideDevice>($"{Module}.SideA");
  223. _sideB = DEVICE.GetDevice<LoaderSideDevice>($"{Module}.SideB");
  224. _loaderCommon = DEVICE.GetDevice<LoaderCommonDevice>($"{module}.Common");
  225. WaferManager.Instance.SubscribeLocation(Module, 2);
  226. _sideAWaferSize = SC.GetValue<int>("Loader1.SideAWaferSize");
  227. _sideBWaferSize = SC.GetValue<int>("Loader1.SideBWaferSize");
  228. InitialOperation();
  229. InitializeRoutine();
  230. InitialDATA();
  231. InitialFsm();
  232. }
  233. /// <summary>
  234. /// 初始化操作
  235. /// </summary>
  236. private void InitialOperation()
  237. {
  238. OP.Subscribe($"{Module}.Abort", (cmd, args) => { return CheckToPostMessage<LOADERSTATE, LoaderMSG>(eEvent.ERR_LOADER, Module.ToString(), (int)LoaderMSG.Abort); });
  239. OP.Subscribe($"{Module}.ClearError", (cmd, args) => { return CheckToPostMessage<LOADERSTATE, LoaderMSG>(eEvent.ERR_LOADER, Module.ToString(), (int)LoaderMSG.ClearError); });
  240. OP.Subscribe($"{Module}.Common.HomeAll", (cmd, args) => { PostMsg((int)LoaderMSG.HomeAll); return true; });
  241. OP.Subscribe($"{Module}.Common.SwitchOnAll", (cmd, args) => { PostMsg((int)LoaderMSG.SwitchOnAll); return true; });
  242. OP.Subscribe($"{Module}.Common.SwitchOffAll", (cmd, args) => { PostMsg((int)LoaderMSG.SwitchOffAll); return true; });
  243. }
  244. /// <summary>
  245. /// 初始化Routine
  246. /// </summary>
  247. private void InitializeRoutine()
  248. {
  249. _homeAllRoutine=new LoaderHomeAllRoutine(Module.ToString());
  250. _switchAllOnRoutine=new LoaderSwitchAllOnRoutine(Module.ToString());
  251. _switchAllOffRoutine=new LoaderSwitchAllOffRoutine(Module.ToString());
  252. _unloadSideRoutine = new LoaderUnloadSideRoutine(Module.ToString());
  253. _loadSideRoutine=new LoaderLoadSideRoutine(Module.ToString());
  254. }
  255. /// <summary>
  256. /// 初始化数据
  257. /// </summary>
  258. private void InitialDATA()
  259. {
  260. InitializeSvid();
  261. DATA.Subscribe($"{Module}.FsmState", () => ((LOADERSTATE)fsm.State).ToString(), SubscriptionAttribute.FLAG.IgnoreSaveDB);
  262. DATA.Subscribe($"{Module}.IsHomed", () => _isHomed, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  263. DATA.Subscribe($"{Module}.IsError", () => IsError, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  264. }
  265. /// <summary>
  266. /// 初始化SVID
  267. /// </summary>
  268. private void InitializeSvid()
  269. {
  270. DATA.Subscribe($"{Module}.State", () => ((LOADERSTATE)fsm.State).ToString(), SubscriptionAttribute.FLAG.IgnoreSaveDB);
  271. DATA.Subscribe($"{Module}.LotID", () => WaferHolderInfo?.LotId, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  272. DATA.Subscribe($"{Module}.WSID", () => WaferHolderInfo?.Id, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  273. DATA.Subscribe($"{Module}.LSAID", () => WaferHolderInfo?.CrsAId, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  274. DATA.Subscribe($"{Module}.LSBID", () => WaferHolderInfo?.CrsBId, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  275. DATA.Subscribe($"{Module}.SequenceRecipe", () => WaferHolderInfo?.SequenceId, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  276. DATA.Subscribe($"{Module}.WaferAID", () => WaferHolderInfo?.WaferAId, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  277. DATA.Subscribe($"{Module}.WaferBID", () => WaferHolderInfo?.WaferBId, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  278. DATA.Subscribe($"{Module}.Task", () => WaferHolderInfo?.CurrentControlJobId, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  279. }
  280. /// <summary>
  281. /// 初始化状态机
  282. /// </summary>
  283. private void InitialFsm()
  284. {
  285. fsm = new StateMachine<LoaderEntity>(Module.ToString(), (int)LOADERSTATE.Init, 100);
  286. fsm.EnableRepeatedMsg(true);
  287. AnyStateTransition(LoaderMSG.Error, EnterError, LOADERSTATE.Error);
  288. AnyStateTransition(LoaderMSG.ReturnInit, EnterInit, LOADERSTATE.Init);
  289. AnyStateTransition(LoaderMSG.ReturnIdle, NullFunc, LOADERSTATE.Idle);
  290. AnyStateTransition(LoaderMSG.Abort, Abort, LOADERSTATE.Init);
  291. //clear error
  292. Transition(LOADERSTATE.Error, LoaderMSG.ClearError, ResumeError, LOADERSTATE.Init);
  293. //HomeAll
  294. AnyStateTransition(LoaderMSG.HomeAll, HomeAll, LOADERSTATE.Homing);
  295. Transition(LOADERSTATE.Homing, FSM_MSG.TIMER, HomeAllMonitor, LOADERSTATE.Idle);
  296. //Switch On All
  297. Transition(LOADERSTATE.Error, LoaderMSG.SwitchOnAll, SwitchOnAll, LOADERSTATE.SwitchOning);
  298. Transition(LOADERSTATE.Init, LoaderMSG.SwitchOnAll, SwitchOnAll, LOADERSTATE.SwitchOning);
  299. Transition(LOADERSTATE.Idle, LoaderMSG.SwitchOnAll, SwitchOnAll, LOADERSTATE.SwitchOning);
  300. Transition(LOADERSTATE.SwitchOning, FSM_MSG.TIMER, SwitchOnAllMonitor, LOADERSTATE.Init);
  301. //Switch Off All
  302. Transition(LOADERSTATE.Error, LoaderMSG.SwitchOffAll, SwitchOffAll, LOADERSTATE.SwitchOffing);
  303. Transition(LOADERSTATE.Init, LoaderMSG.SwitchOffAll, SwitchOffAll, LOADERSTATE.SwitchOffing);
  304. Transition(LOADERSTATE.Idle, LoaderMSG.SwitchOffAll, SwitchOffAll, LOADERSTATE.SwitchOffing);
  305. Transition(LOADERSTATE.SwitchOffing, FSM_MSG.TIMER, SwitchOffAllMonitor, LOADERSTATE.Init);
  306. //Prepare for Place
  307. Transition(LOADERSTATE.Idle, LoaderMSG.PrepareForPlace, PrePareForPlace, LOADERSTATE.PrepreForPlacing);
  308. Transition(LOADERSTATE.PrepreForPlacing, FSM_MSG.TIMER, PrepareForPlaceMonitor, LOADERSTATE.WaitForUnload);
  309. Transition(LOADERSTATE.Idle, LoaderMSG.ReadyForPuf, NullFunc, LOADERSTATE.WaitForUnload);
  310. Transition(LOADERSTATE.WaitForUnload, LoaderMSG.UnloadSide, UnloadSide, LOADERSTATE.Unloading);
  311. Transition(LOADERSTATE.Unloading, FSM_MSG.TIMER, UnloadSideMonitor, LOADERSTATE.WaitForLoad);
  312. Transition(LOADERSTATE.WaitForLoad, LoaderMSG.LoadSide, LoadSide, LOADERSTATE.Loading);
  313. Transition(LOADERSTATE.Loading, FSM_MSG.TIMER, LoadSideMonitor, LOADERSTATE.Idle);
  314. //Flip
  315. Transition(LOADERSTATE.Idle, LoaderMSG.WaitFlip, NullFunc, LOADERSTATE.WaitForFlip);
  316. Transition(LOADERSTATE.WaitForFlip,LoaderMSG.PrepareForPlace, PrePareForPlace, LOADERSTATE.PrepreForPlacing);
  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. /// <summary>
  348. /// 检验Loader两边waferSize不一致
  349. /// </summary>
  350. /// <returns></returns>
  351. public bool CheckLoaderWaferSizeNotEqual()
  352. {
  353. return _sideAWaferSize != _sideBWaferSize;
  354. }
  355. #region Abort
  356. private bool Abort(object parameter)
  357. {
  358. bool preHomed = IsHomed;
  359. _shuttleAAxis.StopPositionOperation();
  360. _shuttleBAxis.StopPositionOperation();
  361. _tiltAAxis.StopPositionOperation();
  362. _tiltBAxis.StopPositionOperation();
  363. _crsAAxis.StopPositionOperation();
  364. _crsBAxis.StopPositionOperation();
  365. _rotationAxis.StopPositionOperation();
  366. if (_currentRoutine != null)
  367. {
  368. _currentRoutine.Abort();
  369. _currentRoutine = null;
  370. }
  371. if (preHomed)
  372. {
  373. PostMsg(LoaderMSG.ReturnIdle);
  374. return false;
  375. }
  376. //Header信息
  377. if (_headerdata != null)
  378. {
  379. WaferHolderInfo info = WaferHolderManager.Instance.GetWaferHolder(Module.ToString());
  380. _headerdata.SequenceRecipe = (info != null ? $"{info.SequenceRecipe.SequenceType}\\" + $"{info.SequenceRecipe.Ppid}.seq.rcp" : null);
  381. _headerdata.ProcessTransferList = (info != null ? info.SchedulerModules : null);
  382. WaferInfo waferInfo = WaferManager.Instance.GetWafer(Module, _unloadSideRoutine.IsSideA ? 0 : 1);
  383. LoaderLotTrackUtil.ExportLoaderLotTrack(Module.ToString(), _headerdata, _loaderLotTrackDatas, _datasStatus, _timeList, waferInfo,
  384. "SeqGroup", false, _startTime, _flowLotTrackDatas, _flowDatasStatus);
  385. }
  386. return true;
  387. }
  388. #endregion
  389. /// <summary>
  390. /// 进入错误状态
  391. /// </summary>
  392. /// <param name="param"></param>
  393. /// <returns></returns>
  394. private bool EnterError(object param)
  395. {
  396. return true;
  397. }
  398. /// <summary>
  399. /// 进入初始化状态
  400. /// </summary>
  401. /// <param name="param"></param>
  402. /// <returns></returns>
  403. private bool EnterInit(object param)
  404. {
  405. _isHomed = false;
  406. return true;
  407. }
  408. #region HomeAll
  409. /// <summary>
  410. /// Home All
  411. /// </summary>
  412. /// <param name="param"></param>
  413. /// <returns></returns>
  414. private bool HomeAll(object[] param)
  415. {
  416. _isHomed = false;
  417. bool result= _homeAllRoutine.Start(param) == RState.Running;
  418. if (result)
  419. {
  420. _currentRoutine = _homeAllRoutine;
  421. }
  422. return result;
  423. }
  424. /// <summary>
  425. /// Load All监控
  426. /// </summary>
  427. /// <param name="param"></param>
  428. /// <returns></returns>
  429. private bool HomeAllMonitor(object[] param)
  430. {
  431. RState state = _homeAllRoutine.Monitor();
  432. if (state==RState.Failed||state==RState.Timeout)
  433. {
  434. _currentRoutine = null;
  435. PostMsg(LoaderMSG.Error);
  436. return false;
  437. }
  438. bool result= state == RState.End;
  439. if(result)
  440. {
  441. _currentRoutine = null;
  442. _isHomed = true;
  443. }
  444. return result;
  445. }
  446. #endregion
  447. #region Switch On All
  448. private bool SwitchOnAll(object[] param)
  449. {
  450. return _switchAllOnRoutine.Start(param) == RState.Running;
  451. }
  452. private bool SwitchOnAllMonitor(object[] param)
  453. {
  454. RState state = _switchAllOnRoutine.Monitor();
  455. if (state == RState.Failed || state == RState.Timeout)
  456. {
  457. PostMsg(LoaderMSG.ReturnInit);
  458. return false;
  459. }
  460. bool result= state == RState.End;
  461. if(result)
  462. {
  463. _isHomed = false;
  464. }
  465. return result;
  466. }
  467. #endregion
  468. #region Switch Off All
  469. private bool SwitchOffAll(object[] param)
  470. {
  471. return _switchAllOffRoutine.Start(param) == RState.Running;
  472. }
  473. private bool SwitchOffAllMonitor(object[] param)
  474. {
  475. RState state = _switchAllOffRoutine.Monitor();
  476. if (state == RState.Failed || state == RState.Timeout)
  477. {
  478. PostMsg(LoaderMSG.ReturnInit);
  479. return false;
  480. }
  481. bool result = state == RState.End;
  482. if (result)
  483. {
  484. _isHomed = false;
  485. }
  486. return result;
  487. }
  488. #endregion
  489. #region Prepare for Place
  490. /// <summary>
  491. /// Prepare For Place
  492. /// </summary>
  493. /// <returns></returns>
  494. private bool PrePareForPlace(object[] param)
  495. {
  496. //默认"TRNPA"
  497. string str = (param==null||param.Length==0)? "TRNPA":param[0].ToString();
  498. return _rotationAxis.PositionStation(str);
  499. }
  500. /// <summary>
  501. /// Prepare For Place监控
  502. /// </summary>
  503. /// <param name="param"></param>
  504. /// <returns></returns>
  505. private bool PrepareForPlaceMonitor(object param)
  506. {
  507. RState ret = _rotationAxis.Status;
  508. if (ret == RState.End)
  509. {
  510. return true;
  511. }
  512. if (ret == RState.Failed || ret == RState.Timeout)
  513. {
  514. PostMsg(LoaderMSG.Error);
  515. }
  516. return false;
  517. }
  518. #endregion
  519. #region Unload Side
  520. /// <summary>
  521. /// Unload Side
  522. /// </summary>
  523. /// <param name="param"></param>
  524. /// <returns></returns>
  525. private bool UnloadSide(object[] param)
  526. {
  527. bool result= _unloadSideRoutine.Start(param) == RState.Running;
  528. if(result)
  529. {
  530. _currentRoutine = _unloadSideRoutine;
  531. InitLotTrackDatas();
  532. _timeList.Add(DateTime.Now);
  533. }
  534. return result;
  535. }
  536. /// <summary>
  537. /// Retry UloadSide
  538. /// </summary>
  539. /// <param name="param"></param>
  540. /// <returns></returns>
  541. private bool RetryUnloadSide(object[] param)
  542. {
  543. int stepIndex = (int)param[0];
  544. bool result = _unloadSideRoutine.Retry(stepIndex)==RState.Running;
  545. if (result)
  546. {
  547. _datasStatus = LotTrackDatasStatus.Half;
  548. _loaderLotTrackDatas.Clear();
  549. _currentRoutine = _unloadSideRoutine;
  550. }
  551. return result;
  552. }
  553. /// <summary>
  554. /// Unload Side监控
  555. /// </summary>
  556. /// <param name="param"></param>
  557. /// <returns></returns>
  558. private bool UnloadSideMonitor(object param)
  559. {
  560. RState ret = _unloadSideRoutine.Monitor();
  561. if (ret == RState.End)
  562. {
  563. AlarmListManager.Instance.CheckModuleAlamAndRemove(Module.ToString(), LOADERSTATE.Unloading.ToString());
  564. _loaderLotTrackDatas.AddRange(_unloadSideRoutine.UnloadLotTrackDatas);
  565. _timeList.Add(DateTime.Now);
  566. //Header信息
  567. WaferHolderInfo info = WaferHolderManager.Instance.GetWaferHolder(Module.ToString());
  568. _headerdata.SequenceRecipe = ((info != null && info.SequenceRecipe != null) ? $"{info.SequenceRecipe.SequenceType}\\" + $"{info.SequenceRecipe.Ppid}.seq.rcp" : "");
  569. if (info != null)
  570. {
  571. _headerdata.ProcessTransferList.AddRange(info.SchedulerModules);
  572. info.SchedulerModules.Clear();
  573. }
  574. WaferInfo waferInfo = WaferManager.Instance.GetWafer(Module, _unloadSideRoutine.IsSideA ? 0 : 1);
  575. LoaderLotTrackUtil.ExportLoaderLotTrack(Module.ToString(), _headerdata, _loaderLotTrackDatas, _datasStatus, _timeList, waferInfo, _unloadSideRoutine.WaferGroup, false, _startTime);
  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. _loaderLotTrackDatas.AddRange(_unloadSideRoutine.UnloadLotTrackDatas);
  588. ////Header信息
  589. WaferHolderInfo info = WaferHolderManager.Instance.GetWaferHolder(Module.ToString());
  590. _headerdata.SequenceRecipe = ((info != null && info.SequenceRecipe != null) ? $"{info.SequenceRecipe.SequenceType}\\" + $"{info.SequenceRecipe.Ppid}.seq.rcp" : "");
  591. if (info != null)
  592. {
  593. _headerdata.ProcessTransferList.AddRange(info.SchedulerModules);
  594. info.SchedulerModules.Clear();
  595. }
  596. WaferInfo waferInfo = WaferManager.Instance.GetWafer(Module, _unloadSideRoutine.IsSideA ? 0 : 1);
  597. LoaderLotTrackUtil.ExportLoaderLotTrack(Module.ToString(), _headerdata, _loaderLotTrackDatas, _datasStatus, _timeList, waferInfo, _unloadSideRoutine.WaferGroup, false, _startTime);
  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. InitLotTrackDatas();
  643. }
  644. return result;
  645. }
  646. /// <summary>
  647. /// Retry LoadSide
  648. /// </summary>
  649. /// <param name="param"></param>
  650. /// <returns></returns>
  651. private bool RetryLoadSide(object[] param)
  652. {
  653. int stepIndex = (int)param[0];
  654. bool result = _loadSideRoutine.Retry(stepIndex) == RState.Running;
  655. if (result)
  656. {
  657. SetLotTrackDatasStatus(stepIndex);
  658. _currentRoutine = _loadSideRoutine;
  659. }
  660. return result;
  661. }
  662. /// <summary>
  663. /// 监控LoadSide
  664. /// </summary>
  665. /// <param name="param"></param>
  666. /// <returns></returns>
  667. private bool LoadSideMonitor(object param)
  668. {
  669. RState ret = _loadSideRoutine.Monitor();
  670. if (ret == RState.End)
  671. {
  672. AlarmListManager.Instance.CheckModuleAlamAndRemove(Module.ToString(), LOADERSTATE.Loading.ToString());
  673. _loaderLotTrackDatas.AddRange(_loadSideRoutine.LoadLotTrackDatas);
  674. _timeList.AddRange(_loadSideRoutine.LoadTimeList);
  675. _flowLotTrackDatas.AddRange(_loadSideRoutine.FlowLotTrackDatas);
  676. //Header信息
  677. WaferHolderInfo info = WaferHolderManager.Instance.GetWaferHolder(Module.ToString());
  678. _headerdata.SequenceRecipe = ((info != null && info.SequenceRecipe != null) ? $"{info.SequenceRecipe.SequenceType}\\" + $"{info.SequenceRecipe.Ppid}.seq.rcp" : "");
  679. if (info != null)
  680. {
  681. _headerdata.ProcessTransferList.AddRange(info.SchedulerModules);
  682. info.SchedulerModules.Clear();
  683. }
  684. WaferInfo waferInfo = WaferManager.Instance.GetWafer(Module, _loadSideRoutine.IsSideA ? 0 : 1);
  685. CheckStartTime(_loadSideRoutine.WaferGroup);
  686. LoaderLotTrackUtil.ExportLoaderLotTrack(Module.ToString(), _headerdata, _loaderLotTrackDatas, _datasStatus, _timeList,
  687. waferInfo, _loadSideRoutine.WaferGroup, true, _startTime, _flowLotTrackDatas, _flowDatasStatus);
  688. return true;
  689. }
  690. if (ret == RState.Failed || ret == RState.Timeout)
  691. {
  692. if (Singleton<RouteManager>.Instance.IsAutoRunning)
  693. {
  694. AlarmList alarmList = new AlarmList(Module.ToString(), ((LOADERSTATE)fsm.State).ToString(), (int)LoaderMSG.LoadSide,
  695. _loadSideRoutine.ErrorMsg, _loadSideRoutine.ErrorStep, (int)AlarmType.Error);
  696. AlarmListManager.Instance.AddAlarm(alarmList);
  697. }
  698. PostMsg(LoaderMSG.Error);
  699. _loaderLotTrackDatas.AddRange(_loadSideRoutine.LoadLotTrackDatas);
  700. _timeList.AddRange(_loadSideRoutine.LoadTimeList);
  701. _flowLotTrackDatas.AddRange(_loadSideRoutine.FlowLotTrackDatas);
  702. //Header信息
  703. WaferHolderInfo info = WaferHolderManager.Instance.GetWaferHolder(Module.ToString());
  704. _headerdata.SequenceRecipe = ((info != null && info.SequenceRecipe != null) ? $"{info.SequenceRecipe.SequenceType}\\" + $"{info.SequenceRecipe.Ppid}.seq.rcp" : "");
  705. if (info != null)
  706. {
  707. _headerdata.ProcessTransferList.AddRange(info.SchedulerModules);
  708. info.SchedulerModules.Clear();
  709. }
  710. WaferInfo waferInfo = WaferManager.Instance.GetWafer(Module, _loadSideRoutine.IsSideA ? 0 : 1);
  711. LoaderLotTrackUtil.ExportLoaderLotTrack(Module.ToString(), _headerdata, _loaderLotTrackDatas, _datasStatus, _timeList,
  712. waferInfo, _loadSideRoutine.WaferGroup, true, _startTime, _flowLotTrackDatas, _flowDatasStatus);
  713. }
  714. return false;
  715. }
  716. /// <summary>
  717. /// 确认UnloadSide是否完成
  718. /// </summary>
  719. /// <param name="param"></param>
  720. /// <returns></returns>
  721. private bool ConfirmLoadSide(object[] param)
  722. {
  723. int stepIdex = (int)param[0];
  724. bool result = _loadSideRoutine.CheckCompleteCondition(stepIdex);
  725. if (!result)
  726. {
  727. if (Singleton<RouteManager>.Instance.IsAutoRunning)
  728. {
  729. AlarmList alarmList = new AlarmList(Module.ToString(), ((LOADERSTATE)fsm.State).ToString(), (int)LoaderMSG.LoadSide,
  730. _loadSideRoutine.ErrorMsg, _loadSideRoutine.ErrorStep, (int)AlarmType.Error);
  731. AlarmListManager.Instance.AddAlarm(alarmList);
  732. }
  733. PostMsg(LoaderMSG.Error);
  734. }
  735. else
  736. {
  737. if (Singleton<RouteManager>.Instance.IsAutoRunning)
  738. {
  739. AlarmListManager.Instance.CheckModuleAlamAndRemove(Module.ToString(),LOADERSTATE.Loading.ToString());
  740. }
  741. }
  742. return result;
  743. }
  744. #endregion
  745. #region LotTrack
  746. /// <summary>
  747. /// Init LotTrackDatas
  748. /// </summary>
  749. private void InitLotTrackDatas()
  750. {
  751. _loaderLotTrackDatas.Clear();
  752. _flowLotTrackDatas.Clear();
  753. _timeList.Clear();
  754. //Header信息
  755. _headerdata = new LotTrackFileHeaderCommonData();
  756. _headerdata.SoftWareVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
  757. if (SC.ContainsItem("System.ToolID")) _headerdata.ToolID = SC.GetStringValue("System.ToolID");
  758. _headerdata.ProcessTransferList = new List<string>();
  759. _datasStatus = LotTrackDatasStatus.None;
  760. _flowDatasStatus = LotTrackDatasStatus.None;
  761. }
  762. /// <summary>
  763. /// Set LotTrack Datas Status
  764. /// </summary>
  765. /// <param name="stepIndex"></param>
  766. private void SetLotTrackDatasStatus(int stepIndex)
  767. {
  768. if (stepIndex == 0 || stepIndex == -1)
  769. {
  770. _datasStatus = LotTrackDatasStatus.Half;
  771. _flowDatasStatus = LotTrackDatasStatus.None;
  772. }
  773. else if (stepIndex == 1)
  774. {
  775. _datasStatus = LotTrackDatasStatus.Complete;
  776. _flowDatasStatus = LotTrackDatasStatus.None;
  777. }
  778. else
  779. {
  780. _datasStatus = LotTrackDatasStatus.Complete;
  781. _flowDatasStatus = LotTrackDatasStatus.Complete;
  782. }
  783. _loaderLotTrackDatas.Clear();
  784. _flowLotTrackDatas.Clear();
  785. }
  786. /// <summary>
  787. /// Check WaferGroup change
  788. /// </summary>
  789. /// <param name="currentGroupWafer"></param>
  790. /// <returns></returns>
  791. private void CheckStartTime(string currentWaferGroup)
  792. {
  793. if (!currentWaferGroup.Equals(_preWaferGroup))
  794. {
  795. _preWaferGroup = currentWaferGroup;
  796. _startTime = _timeList[0];
  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 (State == (int)LOADERSTATE.WaitForUnload||State==(int)LOADERSTATE.PrepreForPlacing)
  893. {
  894. return (int)LoaderMSG.PrepareForPlace;
  895. }
  896. if (CheckToPostMessage<LOADERSTATE, LoaderMSG>(eEvent.WARN_LOADER, Module.ToString(), (int)LoaderMSG.PrepareForPlace,args))
  897. {
  898. return (int)LoaderMSG.PrepareForPlace;
  899. }
  900. else
  901. {
  902. return (int)FSM_MSG.NONE;
  903. }
  904. case "Retry":
  905. if (CheckToPostMessage<LOADERSTATE, LoaderMSG>(eEvent.ERR_LOADER, Module.ToString(), (int)LoaderMSG.Retry,args))
  906. {
  907. return (int)LoaderMSG.Retry;
  908. }
  909. else
  910. {
  911. return (int)FSM_MSG.NONE;
  912. }
  913. case "ConfirmComplete":
  914. if (CheckToPostMessage<LOADERSTATE, LoaderMSG>(eEvent.ERR_LOADER, Module.ToString(), (int)LoaderMSG.ConfirmComplete, args))
  915. {
  916. return (int)LoaderMSG.ConfirmComplete;
  917. }
  918. else
  919. {
  920. return (int)FSM_MSG.NONE;
  921. }
  922. }
  923. return (int)FSM_MSG.NONE;
  924. }
  925. }
  926. public enum LoaderMSG
  927. {
  928. ReturnInit,
  929. ReturnIdle,
  930. Abort,
  931. HomeAll,
  932. GoToSavedPosition,
  933. StopFlow,
  934. SwitchOnAll,
  935. SwitchOffAll,
  936. Error,
  937. ClearError,
  938. PrepareForPlace,
  939. ReadyForPuf,
  940. UnloadSide,
  941. LoadSide,
  942. Retry,
  943. ConfirmComplete,
  944. WaitFlip,
  945. }
  946. }