JelAlignerWithLiftNcd.cs 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO.Ports;
  4. using System.Linq;
  5. using System.Text;
  6. using Aitex.Core.Common.DeviceData;
  7. using Aitex.Core.RT.Device;
  8. using Aitex.Core.RT.Device.Unit;
  9. using Aitex.Core.RT.Event;
  10. using Aitex.Core.RT.Log;
  11. using Aitex.Core.RT.OperationCenter;
  12. using Aitex.Core.RT.SCCore;
  13. using Aitex.Core.Util;
  14. using MECF.Framework.Common.Communications;
  15. using MECF.Framework.Common.Device.Bases;
  16. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Common;
  17. using Newtonsoft.Json;
  18. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robots.RobotBase;
  19. using MECF.Framework.Common.Equipment;
  20. using MECF.Framework.Common.SubstrateTrackings;
  21. using System.Threading;
  22. using Aitex.Core.Common;
  23. using Aitex.Core.RT.DataCenter;
  24. using System.Text.RegularExpressions;
  25. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Aligners.AlignersBase;
  26. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robots.JEL;
  27. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robots;
  28. namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Aligners.JelAligner
  29. {
  30. public class JelAlignerWithLiftNcd : JelAligner
  31. {
  32. /* SAL3262HV model: for 2-inch to 6-inch wafer
  33. SAL3362HV model: for 3-inch to 6-inch wafer
  34. SAL3482HV model: for 4-inch to 8-inch wafer
  35. SAL38C3HV model: for 8-inch to 12-inch wafer*/
  36. public JelAlignerWithLiftNcd(string module, string name, string scRoot, IoSensor[] dis, IoTrigger[] dos, int alignerType = 0, string robotModel = "") :
  37. base(module, name, scRoot, null, null, alignerType, robotModel)
  38. {
  39. _scRoot = scRoot;
  40. if (dis != null)
  41. {
  42. _diWaferPresent = dis[0];
  43. _diLifterPinError = dis[1];
  44. _diLifterPinStatus = dis[2];
  45. _diLifterPinUp = dis[3];
  46. _diLifterPinHome = dis[4];
  47. _diLifterPinError.OnSignalChanged += _diLifterPinError_OnSignalChanged;
  48. }
  49. if (dos != null)
  50. {
  51. _doLifterPinHome = dos[0];
  52. _doLifterPinUp = dos[1];
  53. _doLifterPinReset = dos[2];
  54. }
  55. }
  56. private void _diLifterPinError_OnSignalChanged(IoSensor arg1, bool arg2)
  57. {
  58. if (arg2)
  59. {
  60. OnError("MotionError");
  61. }
  62. }
  63. private IoSensor _diWaferPresent;
  64. private IoSensor _diLifterPinError;
  65. private IoSensor _diLifterPinStatus;
  66. private IoSensor _diLifterPinUp;
  67. private IoSensor _diLifterPinHome;
  68. private IoTrigger _doLifterPinHome;
  69. private IoTrigger _doLifterPinUp;
  70. private IoTrigger _doLifterPinReset;
  71. private int _bodyNumber;
  72. private string _robotModel; //T-00902H
  73. //public int BodyNumber { get => _bodyNumber; }
  74. private string _address = "";
  75. //public string Address { get => _address; }
  76. private bool isSimulatorMode;
  77. private string _scRoot;
  78. private PeriodicJob _thread;
  79. //protected JelAlignerConnection _connection;
  80. private R_TRIG _trigError = new R_TRIG();
  81. private R_TRIG _trigCommunicationError = new R_TRIG();
  82. private R_TRIG _trigRetryConnect = new R_TRIG();
  83. private R_TRIG _trigActionDone = new R_TRIG();
  84. private LinkedList<HandlerBase> _lstMoveHandler = new LinkedList<HandlerBase>();
  85. private LinkedList<HandlerBase> _lstMonitorHandler = new LinkedList<HandlerBase>();
  86. private bool _isAligned;
  87. private bool _isOnHomedPostion;
  88. //public int TimelimitAlginerHome { get; private set; }
  89. //public int TimelimitForAlignWafer { get; private set; }
  90. private object _locker = new object();
  91. private bool _enableLog;
  92. public override bool OnTimer()
  93. {
  94. try
  95. {
  96. if (!_connection.IsConnected || _connection.IsCommunicationError)
  97. {
  98. lock (_locker)
  99. {
  100. _lstMoveHandler.Clear();
  101. }
  102. _trigRetryConnect.CLK = !_connection.IsConnected;
  103. if (_trigRetryConnect.Q)
  104. {
  105. _connection.SetPortAddress(SC.GetStringValue($"{_scRoot}.{Name}.PortName"));
  106. if (!_connection.Connect())
  107. {
  108. EV.PostAlarmLog(Module, $"Can not connect with {_connection.Address}, {Module}.{Name}");
  109. }
  110. else
  111. {
  112. }
  113. }
  114. return true;
  115. }
  116. HandlerBase handler = null;
  117. DateTime dtstart = DateTime.Now;
  118. lock (_locker)
  119. {
  120. while (_lstMoveHandler.Count > 0 && _lstMonitorHandler.Count == 0)
  121. {
  122. if (!_connection.IsBusy)
  123. {
  124. if (YAxisAndThetaAxisStatus == JelAxisStatus.NormalEnd &&
  125. XAxisStatus == JelAxisStatus.NormalEnd)
  126. {
  127. handler = _lstMoveHandler.First.Value;
  128. _connection.Execute(handler);
  129. _lstMoveHandler.RemoveFirst();
  130. }
  131. else
  132. {
  133. _connection.Execute(new JelAlignerReadHandler(this, ""));
  134. }
  135. }
  136. else
  137. {
  138. _connection.MonitorTimeout();
  139. _trigCommunicationError.CLK = _connection.IsCommunicationError;
  140. if (_trigCommunicationError.Q)
  141. {
  142. _lstMoveHandler.Clear();
  143. OnError($"{Module}.{Name} communication error, {_connection.LastCommunicationError}");
  144. }
  145. }
  146. if (DateTime.Now - dtstart > TimeSpan.FromSeconds(150))
  147. {
  148. _lstMonitorHandler.Clear();
  149. _lstMoveHandler.Clear();
  150. OnError("Robot action timeout");
  151. }
  152. }
  153. while (_lstMonitorHandler.Count > 0)
  154. {
  155. if (!_connection.IsBusy)
  156. {
  157. handler = _lstMonitorHandler.First.Value;
  158. _connection.Execute(handler);
  159. _lstMonitorHandler.RemoveFirst();
  160. }
  161. if (DateTime.Now - dtstart > TimeSpan.FromSeconds(150))
  162. {
  163. _lstMonitorHandler.Clear();
  164. _lstMoveHandler.Clear();
  165. OnError("Robot action timeout");
  166. }
  167. }
  168. }
  169. }
  170. catch (Exception ex)
  171. {
  172. LOG.Write(ex);
  173. }
  174. return true;
  175. }
  176. public override bool IsNeedChangeWaferSize(WaferSize wz)
  177. {
  178. return false;
  179. }
  180. protected override bool fReset(object[] param)
  181. {
  182. if (!_connection.IsConnected)
  183. {
  184. _enableLog = SC.GetValue<bool>($"{_scRoot}.{Name}.EnableLogMessage");
  185. _bodyNumber = SC.GetValue<int>($"{_scRoot}.{Name}.BodyNumber");
  186. PortName = SC.GetStringValue($"{_scRoot}.{Name}.PortName");
  187. //TimelimitAlginerHome = SC.GetValue<int>($"{_scRoot}.{Name}.TimeLimitAlignerHome");
  188. _connection = new JelAlignerConnection(PortName);
  189. _connection.EnableLog(_enableLog);
  190. if (_connection.Connect())
  191. {
  192. EV.PostInfoLog(Module, $"{Module}.{Name} connected");
  193. }
  194. }
  195. _trigError.RST = true;
  196. _connection.SetCommunicationError(false, "");
  197. _trigCommunicationError.RST = true;
  198. _enableLog = SC.GetValue<bool>($"{_scRoot}.{Name}.EnableLogMessage");
  199. _connection.EnableLog(_enableLog);
  200. _trigRetryConnect.RST = true;
  201. _lstMoveHandler.Clear();
  202. _lstMonitorHandler.Clear();
  203. _connection.ForceClear();
  204. lock (_locker)
  205. {
  206. _lstMonitorHandler.AddLast(new JelAlignerRawCommandHandler(this, $"${BodyNumber}RD\r"));
  207. _lstMonitorHandler.AddLast(new JelAlignerReadHandler(this, ""));
  208. _lstMonitorHandler.AddLast(new JelAlignerReadHandler(this, "WIS1"));
  209. _lstMonitorHandler.AddLast(new JelAlignerReadHandler(this, "WAS"));
  210. }
  211. _doLifterPinReset.SetTrigger(true, out _);
  212. _dtActionStart = DateTime.Now;
  213. return true;
  214. }
  215. protected override bool fMonitorReset(object[] param)
  216. {
  217. IsBusy = false;
  218. if (DateTime.Now - _dtActionStart > TimeSpan.FromSeconds((double)TimelimitAlginerHome))
  219. {
  220. _doLifterPinReset.SetTrigger(false, out _);
  221. OnError("Reset timeout");
  222. }
  223. if (_diLifterPinError.Value) return false;
  224. _isAligned = false;
  225. if (_lstMonitorHandler.Count == 0 && !_connection.IsBusy)
  226. return true;
  227. return false;
  228. //if (XAxisStatus == JelAxisStatus.NormalEnd
  229. // && (YAxisAndThetaAxisStatus == JelAxisStatus.NormalEnd)
  230. // && _lstMoveHandler.Count == 0
  231. // && _lstMonitorHandler.Count == 0
  232. // && !_connection.IsBusy)
  233. //{
  234. // IsBusy = false;
  235. // return true;
  236. //}
  237. //if (_lstMonitorHandler.Count == 0 && _lstMoveHandler.Count == 0 && !_connection.IsBusy)
  238. // _connection.Execute(new JelAlignerReadHandler(this, ""));
  239. //return false;
  240. }
  241. protected override bool fStartInit(object[] param)
  242. {
  243. lock (_locker)
  244. {
  245. _lstMoveHandler.AddLast(new JelAlignerMoveHandler(this, "W0"));
  246. _lstMoveHandler.AddLast(new JelAlignerReadHandler(this, ""));
  247. _lstMoveHandler.AddLast(new JelAlignerReadHandler(this, "WIS1"));
  248. if (SC.ContainsItem($"{_scRoot}.{Name}.JelWaferType"))
  249. {
  250. int wafertype = SC.GetValue<int>($"{_scRoot}.{Name}.JelWaferType");
  251. _lstMoveHandler.AddLast(new JelAlignerSetHandler(this, "WAT", wafertype.ToString()));
  252. }
  253. // if (WaferManager.Instance.CheckHasWafer(RobotModuleName, 0))
  254. // {
  255. // string strpara;
  256. // switch (WaferManager.Instance.GetWaferSize(RobotModuleName, 0))
  257. // {
  258. // case WaferSize.WS2:
  259. // case WaferSize.WS3:
  260. // case WaferSize.WS4:
  261. // case WaferSize.WS5:
  262. // case WaferSize.WS6:
  263. // case WaferSize.WS8:
  264. // strpara = _currentSetWaferSize.ToString().Replace("WS", "");
  265. // break;
  266. // case WaferSize.WS12:
  267. // strpara = "9";
  268. // break;
  269. // default:
  270. // return false;
  271. // }
  272. // _lstMonitorHandler.AddLast(new JelAlignerMoveHandler(this, "WAS", strpara));
  273. // }
  274. // _lstMoveHandler.AddLast(new JelAlignerMoveHandler(this, "WMC"));
  275. // _lstMoveHandler.AddLast(new JelAlignerReadHandler(this, "WAS"));
  276. //}
  277. string strpara = _currentSetWaferSize.ToString().Replace("WS", "");
  278. _lstMonitorHandler.AddLast(new JelAlignerMoveHandler(this, "WAS", strpara));
  279. }
  280. _doLifterPinUp.SetTrigger(false, out _);
  281. _doLifterPinHome.SetTrigger(true, out _);
  282. _isAligned = false;
  283. _isOnHomedPostion = false;
  284. _dtActionStart = DateTime.Now;
  285. return true;
  286. }
  287. private DateTime _dtActionStart;
  288. protected override bool fMonitorInit(object[] param)
  289. {
  290. _isAligned = false;
  291. IsBusy = false;
  292. if (DateTime.Now - _dtActionStart > TimeSpan.FromSeconds((double)TimelimitAlginerHome))
  293. {
  294. _doLifterPinHome.SetTrigger(false, out _);
  295. OnError("Init timeout");
  296. }
  297. if (!_diLifterPinHome.Value || _diLifterPinUp.Value) return false;
  298. _doLifterPinHome.SetTrigger(false, out _);
  299. if (_lstMoveHandler.Count == 0
  300. && !_connection.IsBusy && XAxisStatus == JelAxisStatus.NormalEnd
  301. && YAxisAndThetaAxisStatus == JelAxisStatus.NormalEnd)
  302. {
  303. if (IsWaferPresent(0) && WaferManager.Instance.CheckNoWafer(RobotModuleName, 0))
  304. {
  305. WaferManager.Instance.CreateWafer(RobotModuleName, 0,
  306. WaferStatus.Normal, GetCurrentWaferSize());
  307. }
  308. if (!IsWaferPresent(0) && WaferManager.Instance.CheckHasWafer(RobotModuleName, 0))
  309. {
  310. WaferManager.Instance.DeleteWafer(RobotModuleName, 0);
  311. }
  312. return true;
  313. }
  314. if (_lstMoveHandler.Count == 0 && !_connection.IsBusy)
  315. _connection.Execute(new JelAlignerReadHandler(this, ""));
  316. return false;
  317. }
  318. protected override bool fStartHome(object[] param)
  319. {
  320. lock (_locker)
  321. {
  322. _lstMoveHandler.AddLast(new JelAlignerMoveHandler(this, "W0"));
  323. _lstMoveHandler.AddLast(new JelAlignerReadHandler(this, ""));
  324. _lstMoveHandler.AddLast(new JelAlignerReadHandler(this, "WIS1"));
  325. if (SC.ContainsItem($"{_scRoot}.{Name}.JelWaferType"))
  326. {
  327. int wafertype = SC.GetValue<int>($"{_scRoot}.{Name}.JelWaferType");
  328. _lstMoveHandler.AddLast(new JelAlignerSetHandler(this, "WAT", wafertype.ToString()));
  329. }
  330. //if (WaferManager.Instance.CheckHasWafer(RobotModuleName, 0))
  331. //{
  332. // string strpara;
  333. // switch (WaferManager.Instance.GetWaferSize(RobotModuleName, 0))
  334. // {
  335. // case WaferSize.WS2:
  336. // case WaferSize.WS3:
  337. // case WaferSize.WS4:
  338. // case WaferSize.WS5:
  339. // case WaferSize.WS6:
  340. // case WaferSize.WS8:
  341. // strpara = _currentSetWaferSize.ToString().Replace("WS", "");
  342. // break;
  343. // case WaferSize.WS12:
  344. // strpara = "9";
  345. // break;
  346. // default:
  347. // return false;
  348. // }
  349. // _lstMonitorHandler.AddLast(new JelAlignerMoveHandler(this, "WAS", strpara));
  350. //}
  351. string strpara = _currentSetWaferSize.ToString().Replace("WS", "");
  352. _lstMonitorHandler.AddLast(new JelAlignerMoveHandler(this, "WAS", strpara));
  353. _lstMoveHandler.AddLast(new JelAlignerMoveHandler(this, "WMC"));
  354. _lstMoveHandler.AddLast(new JelAlignerReadHandler(this, "WAS"));
  355. }
  356. _doLifterPinHome.SetTrigger(true, out _);
  357. _isAligned = false;
  358. _dtActionStart = DateTime.Now;
  359. return true;
  360. }
  361. protected override bool fMonitorHome(object[] param)
  362. {
  363. if (DateTime.Now - _dtActionStart > TimeSpan.FromSeconds((double)TimelimitAlginerHome))
  364. {
  365. OnError("Home timeout");
  366. _doLifterPinHome.SetTrigger(false, out _);
  367. }
  368. if (!_diLifterPinHome.Value || _diLifterPinUp.Value) return false;
  369. _doLifterPinHome.SetTrigger(false, out _);
  370. if (_lstMoveHandler.Count == 0
  371. && !_connection.IsBusy && XAxisStatus == JelAxisStatus.NormalEnd
  372. && YAxisAndThetaAxisStatus == JelAxisStatus.NormalEnd)
  373. {
  374. IsBusy = false;
  375. _isOnHomedPostion = true;
  376. return true;
  377. }
  378. if (_lstMoveHandler.Count == 0 && !_connection.IsBusy)
  379. _connection.Execute(new JelAlignerReadHandler(this, ""));
  380. return false;
  381. }
  382. public override bool IsReady()
  383. {
  384. return AlignerState == AlignerStateEnum.Idle && !IsBusy;
  385. }
  386. public override bool IsWaferPresent(int slotindex)
  387. {
  388. if (_diWaferPresent != null)
  389. return _diWaferPresent.Value;
  390. return WaferManager.Instance.CheckHasWafer(RobotModuleName, slotindex);
  391. }
  392. public override bool IsNeedPrepareBeforePlaceWafer()
  393. {
  394. return !_isOnHomedPostion;
  395. }
  396. protected override bool fStartLiftup(object[] param) //Ungrip
  397. {
  398. _dtActionStart = DateTime.Now;
  399. lock (_locker)
  400. {
  401. _doLifterPinHome.SetTrigger(false, out _);
  402. _doLifterPinUp.SetTrigger(true, out _);
  403. //_lstMoveHandler.AddLast(new JelAlignerMoveHandler(this, "WU"));
  404. //_lstMoveHandler.AddLast(new JelAlignerReadHandler(this, ""));
  405. }
  406. return true;
  407. }
  408. protected override bool fMonitorLiftup(object[] param)
  409. {
  410. if (DateTime.Now - _dtActionStart > TimeSpan.FromSeconds(TimelimitForAlignWafer))
  411. OnError("Liftup timeout");
  412. if (!_diLifterPinHome.Value && _diLifterPinUp.Value)
  413. {
  414. IsBusy = false;
  415. _isAligned = false;
  416. _isOnHomedPostion = false;
  417. return true;
  418. }
  419. //if (_lstMoveHandler.Count == 0
  420. // && !_connection.IsBusy && XAxisStatus == JelAxisStatus.NormalEnd
  421. // && YAxisAndThetaAxisStatus == JelAxisStatus.NormalEnd)
  422. //{
  423. // IsBusy = false;
  424. // _isAligned = false;
  425. // _isOnHomedPostion = false;
  426. // return true;
  427. //}
  428. //if (_lstMoveHandler.Count == 0 && !_connection.IsBusy)
  429. // _connection.Execute(new JelAlignerReadHandler(this, ""));
  430. return false;
  431. }
  432. protected override bool fStartLiftdown(object[] param)
  433. {
  434. _dtActionStart = DateTime.Now;
  435. lock (_locker)
  436. {
  437. _doLifterPinUp.SetTrigger(false, out _);
  438. _doLifterPinHome.SetTrigger(true, out _);
  439. //_lstMoveHandler.AddLast(new JelAlignerMoveHandler(this, "WD"));
  440. //_lstMoveHandler.AddLast(new JelAlignerReadHandler(this, ""));
  441. }
  442. return true;
  443. }
  444. protected override bool fMonitorLiftdown(object[] param)
  445. {
  446. if (DateTime.Now - _dtActionStart > TimeSpan.FromSeconds(TimelimitForAlignWafer))
  447. OnError("Liftdown timeout");
  448. if (_diLifterPinHome.Value && !_diLifterPinUp.Value)
  449. {
  450. IsBusy = false;
  451. _isAligned = false;
  452. _isOnHomedPostion = false;
  453. return true;
  454. }
  455. //if (_lstMoveHandler.Count == 0
  456. // && !_connection.IsBusy && XAxisStatus == JelAxisStatus.NormalEnd
  457. // && YAxisAndThetaAxisStatus == JelAxisStatus.NormalEnd)
  458. //{
  459. // IsBusy = false;
  460. // _isAligned = true;
  461. // _isOnHomedPostion = false;
  462. // return true;
  463. //}
  464. //if (_lstMoveHandler.Count == 0 && !_connection.IsBusy)
  465. // _connection.Execute(new JelAlignerReadHandler(this, ""));
  466. return false;
  467. }
  468. protected override bool fStartAlign(object[] param)
  469. {
  470. _dtActionStart = DateTime.Now;
  471. _doLifterPinUp.SetTrigger(false, out _);
  472. _doLifterPinHome.SetTrigger(true, out _);
  473. while (!_diLifterPinHome.Value || _diLifterPinUp.Value)
  474. {
  475. if (_diLifterPinError.Value)
  476. {
  477. OnError("MotionError");
  478. return false;
  479. }
  480. if (DateTime.Now - _dtActionStart > TimeSpan.FromSeconds(TimelimitForAlignWafer))
  481. {
  482. OnError("Alignment timeout");
  483. return false;
  484. }
  485. }
  486. WaferSize wz = WaferManager.Instance.GetWaferSize(RobotModuleName, 0);
  487. if (wz != GetCurrentWaferSize())
  488. {
  489. EV.PostAlarmLog("System", "Wafer size is not match, can't do alignment");
  490. return false;
  491. }
  492. double aligneangle = (double)param[0];
  493. while (aligneangle < 0 || aligneangle > 360)
  494. {
  495. if (aligneangle < 0)
  496. aligneangle += 360;
  497. if (aligneangle > 360)
  498. aligneangle -= 360;
  499. }
  500. //int speed = SC.GetValue<int>($"{_scRoot}.{Name}.AlignSpeed");
  501. int intangle = (int)(aligneangle * 20000 / 360);
  502. CurrentNotch = aligneangle;
  503. lock (_locker)
  504. {
  505. _lstMoveHandler.AddLast(new JelAlignerRawCommandHandler(this, $"${BodyNumber}RD\r"));
  506. _lstMoveHandler.AddLast(new JelAlignerMoveHandler(this, "WUC")); //Close grip
  507. _lstMoveHandler.AddLast(new JelAlignerReadHandler(this, ""));
  508. //_lstMoveHandler.AddLast(new JelAlignerMoveHandler(this, "WA")); //Move down
  509. //_lstMoveHandler.AddLast(new JelAlignerReadHandler(this, ""));
  510. _lstMoveHandler.AddLast(new JelAlignerSetHandler(this, "WOP", intangle.ToString()));
  511. _lstMoveHandler.AddLast(new JelAlignerRawCommandHandler(this, $"${BodyNumber}RD\r"));
  512. if (_isAligned)
  513. {
  514. _lstMoveHandler.AddLast(new JelAlignerMoveHandler(this, "G15")); //Align to angle compaund command
  515. }
  516. else
  517. _lstMoveHandler.AddLast(new JelAlignerMoveHandler(this, "WA")); //Align
  518. _lstMoveHandler.AddLast(new JelAlignerReadHandler(this, ""));
  519. _lstMoveHandler.AddLast(new JelAlignerMoveHandler(this, "WDF")); //Ungrip
  520. _lstMoveHandler.AddLast(new JelAlignerReadHandler(this, ""));
  521. _lstMoveHandler.AddLast(new JelAlignerReadHandler(this, "WIS1"));
  522. }
  523. return true;
  524. }
  525. protected override bool fMonitorAligning(object[] param)
  526. {
  527. IsBusy = false;
  528. if (DateTime.Now - _dtActionStart > TimeSpan.FromSeconds(TimelimitForAlignWafer))
  529. OnError("Alignment timeout");
  530. if (_lstMoveHandler.Count == 0
  531. && !_connection.IsBusy && XAxisStatus == JelAxisStatus.NormalEnd
  532. && YAxisAndThetaAxisStatus == JelAxisStatus.NormalEnd)
  533. {
  534. _isAligned = true;
  535. _isOnHomedPostion = false;
  536. return true;
  537. }
  538. if (_lstMoveHandler.Count == 0 && !_connection.IsBusy)
  539. _connection.Execute(new JelAlignerReadHandler(this, ""));
  540. return false;
  541. }
  542. protected override bool fStop(object[] param)
  543. {
  544. return true;
  545. }
  546. protected override bool FsmAbort(object[] param)
  547. {
  548. return true;
  549. }
  550. protected override bool fClear(object[] param)
  551. {
  552. return true;
  553. }
  554. protected override bool fStartReadData(object[] param)
  555. {
  556. return true;
  557. }
  558. protected override bool fStartSetParameters(object[] param)
  559. {
  560. _dtActionStart = DateTime.Now;
  561. _currentSetParameter = param[0].ToString();
  562. switch (_currentSetParameter)
  563. {
  564. case "WaferSize":
  565. if (GetWaferState() != RobotArmWaferStateEnum.Absent)
  566. {
  567. EV.PostAlarmLog("System", "Can't set wafersize when wafer is not absent");
  568. return false;
  569. }
  570. _currentSetWaferSize = (WaferSize)param[1];
  571. if (WaferManager.Instance.CheckHasWafer(RobotModuleName, 0))
  572. {
  573. WaferManager.Instance.UpdateWaferSize(RobotModuleName, 0, _currentSetWaferSize);
  574. }
  575. string strpara;
  576. switch (_currentSetWaferSize)
  577. {
  578. case WaferSize.WS2:
  579. case WaferSize.WS3:
  580. case WaferSize.WS4:
  581. case WaferSize.WS5:
  582. case WaferSize.WS6:
  583. case WaferSize.WS8:
  584. strpara = _currentSetWaferSize.ToString().Replace("WS", "");
  585. break;
  586. case WaferSize.WS12:
  587. strpara = "9";
  588. break;
  589. default:
  590. return false;
  591. }
  592. lock (_locker)
  593. {
  594. _lstMonitorHandler.AddLast(new JelAlignerMoveHandler(this, "WAS", strpara));
  595. _lstMonitorHandler.AddLast(new JelAlignerReadHandler(this, "WAS"));
  596. _lstMonitorHandler.AddLast(new JelAlignerMoveHandler(this, "WMC"));
  597. }
  598. break;
  599. }
  600. return true;
  601. }
  602. private string _currentSetParameter;
  603. public override WaferSize GetCurrentWaferSize()
  604. {
  605. return _currentSetWaferSize;
  606. }
  607. private WaferSize _currentSetWaferSize = WaferSize.WS8;
  608. protected override bool fMonitorSetParamter(object[] param)
  609. {
  610. IsBusy = false;
  611. if (DateTime.Now - _dtActionStart > TimeSpan.FromSeconds(TimelimitForAlignWafer))
  612. OnError("Set parameter timeout");
  613. switch (_currentSetParameter)
  614. {
  615. case "WaferSize":
  616. if (_lstMonitorHandler.Count == 0 && _lstMoveHandler.Count == 0 && !_connection.IsBusy)
  617. {
  618. if (_currentSetWaferSize != Size)
  619. {
  620. OnError($"Fail to set wafer size,set:{_currentSetWaferSize},return:{Size}");
  621. }
  622. if (_currentSetWaferSize == WaferSize.WS12)
  623. {
  624. return true;
  625. }
  626. if (_currentSetWaferSize == WaferSize.WS8)
  627. {
  628. return true;
  629. }
  630. return true;
  631. }
  632. break;
  633. }
  634. return false;
  635. }
  636. protected override bool fStartUnGrip(object[] param)
  637. {
  638. lock (_locker)
  639. {
  640. _lstMoveHandler.AddLast(new JelAlignerMoveHandler(this, "WDF"));
  641. _lstMoveHandler.AddLast(new JelAlignerReadHandler(this, ""));
  642. }
  643. _diStartUngrip = DateTime.Now;
  644. return true;
  645. }
  646. private DateTime _diStartUngrip;
  647. protected override bool fMonitorUnGrip(object[] param)
  648. {
  649. IsBusy = false;
  650. if (DateTime.Now - _diStartUngrip > TimeSpan.FromSeconds(10))
  651. OnError("UnGrip timeout");
  652. if (_lstMoveHandler.Count != 0 || _connection.IsBusy || XAxisStatus != JelAxisStatus.NormalEnd
  653. || YAxisAndThetaAxisStatus != JelAxisStatus.NormalEnd)
  654. {
  655. if (_lstMoveHandler.Count == 0 && !_connection.IsBusy)
  656. _connection.Execute(new JelAlignerReadHandler(this, ""));
  657. return false;
  658. }
  659. _doLifterPinUp.SetTrigger(true, out _);
  660. _doLifterPinHome.SetTrigger(false, out _);
  661. if (_diLifterPinHome.Value || !_diLifterPinUp.Value)
  662. return false;
  663. return true;
  664. }
  665. protected override bool fStartGrip(object[] param)
  666. {
  667. lock (_locker)
  668. {
  669. _lstMoveHandler.AddLast(new JelAlignerMoveHandler(this, "WUC"));
  670. _lstMoveHandler.AddLast(new JelAlignerReadHandler(this, ""));
  671. }
  672. _diStartUngrip = DateTime.Now;
  673. return true;
  674. }
  675. protected override bool fMonitorGrip(object[] param)
  676. {
  677. IsBusy = false;
  678. if (DateTime.Now - _diStartUngrip > TimeSpan.FromSeconds(10))
  679. OnError("Grip timeout");
  680. _doLifterPinUp.SetTrigger(false, out _);
  681. _doLifterPinHome.SetTrigger(true, out _);
  682. if (!_diLifterPinHome.Value || _diLifterPinUp.Value)
  683. return false;
  684. if (_lstMoveHandler.Count == 0
  685. && !_connection.IsBusy)
  686. {
  687. if (XAxisStatus == JelAxisStatus.NormalEnd && YAxisAndThetaAxisStatus == JelAxisStatus.NormalEnd)
  688. {
  689. return true;
  690. }
  691. else
  692. {
  693. _connection.Execute(new JelAlignerReadHandler(this, ""));
  694. }
  695. }
  696. return false;
  697. }
  698. protected override bool fResetToReady(object[] param)
  699. {
  700. return true;
  701. }
  702. protected override bool fError(object[] param)
  703. {
  704. return true;
  705. }
  706. public override void OnError(string errortext)
  707. {
  708. _isAligned = false;
  709. _isOnHomedPostion = false;
  710. _lstMonitorHandler.Clear();
  711. _lstMoveHandler.Clear();
  712. base.OnError(errortext);
  713. }
  714. public override bool IsNeedRelease
  715. {
  716. get
  717. {
  718. return true;
  719. }
  720. }
  721. protected override bool fStartPrepareAccept(object[] param)
  722. {
  723. _dtActionStart = DateTime.Now;
  724. lock (_locker)
  725. {
  726. _lstMonitorHandler.AddLast(new JelAlignerRawCommandHandler(this, $"${BodyNumber}RD\r"));
  727. _lstMoveHandler.AddLast(new JelAlignerMoveHandler(this, "WMC"));
  728. _lstMoveHandler.AddLast(new JelAlignerReadHandler(this, ""));
  729. }
  730. return true;
  731. }
  732. protected override bool fMonitorPrepareAccept(object[] param)
  733. {
  734. if (DateTime.Now - _dtActionStart > TimeSpan.FromSeconds((double)TimelimitAlginerHome))
  735. OnError("Home timeout");
  736. if (_lstMoveHandler.Count == 0
  737. && !_connection.IsBusy && XAxisStatus == JelAxisStatus.NormalEnd
  738. && YAxisAndThetaAxisStatus == JelAxisStatus.NormalEnd)
  739. {
  740. IsBusy = false;
  741. _isAligned = false;
  742. _isOnHomedPostion = true;
  743. return true;
  744. }
  745. if (_lstMoveHandler.Count == 0 && !_connection.IsBusy)
  746. _connection.Execute(new JelAlignerReadHandler(this, ""));
  747. return false;
  748. }
  749. }
  750. }