JelAlignerWithCylinderSmec.cs 29 KB

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