JelAlignerEG.cs 32 KB

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