IoCoolingBuffer.cs 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237
  1. using System;
  2. using System.Xml;
  3. using Aitex.Core.Common;
  4. using Aitex.Core.Common.DeviceData;
  5. using Aitex.Core.RT.DataCenter;
  6. using Aitex.Core.RT.Event;
  7. using Aitex.Core.RT.IOCore;
  8. using Aitex.Core.RT.Log;
  9. using Aitex.Core.RT.OperationCenter;
  10. using Aitex.Core.RT.SCCore;
  11. using Aitex.Core.Util;
  12. using EFEM.RT.Devices.Flipper;
  13. using MECF.Framework.Common.Equipment;
  14. using MECF.Framework.Common.SubstrateTrackings;
  15. namespace Aitex.Core.RT.Device.Unit
  16. {
  17. public class IoCoolingBuffer : BaseDevice, IDevice
  18. {
  19. enum DeviceState
  20. {
  21. Init,
  22. Idle,
  23. Homing,
  24. MovingUp,
  25. MovingDown,
  26. Error,
  27. Disable,
  28. }
  29. public enum LiftState
  30. {
  31. Unknown = 0,
  32. Down = 1,
  33. Up = 2,
  34. Error = 3,
  35. }
  36. private DIAccessor _diLiftUp;
  37. private DIAccessor _diLiftDown;
  38. private DIAccessor _di3InchExtend;
  39. private DIAccessor _di3InchRetract;
  40. private DIAccessor _di4InchExtend;
  41. private DIAccessor _di4InchRetract;
  42. private DIAccessor _di6InchExtend;
  43. private DIAccessor _di6InchRetract;
  44. private DOAccessor _doLiftUp;
  45. private DOAccessor _doLiftDown;
  46. private DOAccessor _do3InchExtend;
  47. private DOAccessor _do3InchRetract;
  48. private DOAccessor _do4InchExtend;
  49. private DOAccessor _do4InchRetract;
  50. private DOAccessor _do6InchExtend;
  51. private DOAccessor _do6InchRetract;
  52. private DeviceState _state = DeviceState.Init;
  53. private DeviceTimer _timer = new DeviceTimer();
  54. private WaferSize _size = WaferSize.WS8;
  55. private SCConfigItem _scLiftUpTimeout;
  56. private SCConfigItem _scLiftDownTimeout;
  57. public bool Busy
  58. {
  59. get
  60. {
  61. return _state != DeviceState.Idle;
  62. }
  63. }
  64. public bool Moving
  65. {
  66. get
  67. {
  68. return _state != DeviceState.Idle && _state != DeviceState.Error;
  69. }
  70. }
  71. public bool Error
  72. {
  73. get
  74. {
  75. return _state == DeviceState.Error;
  76. }
  77. }
  78. //public bool IsUp
  79. //{
  80. // get
  81. // {
  82. // return _diLiftUp.Value && !_diLiftDown.Value;
  83. // }
  84. //}
  85. //public bool IsDown
  86. //{
  87. // get
  88. // {
  89. // return !_diLiftUp.Value && _diLiftDown.Value;
  90. // }
  91. //}
  92. public bool IsEnableMultiWaferSize
  93. {
  94. get
  95. {
  96. if (SC.ContainsItem("System.IsEnableMultiWaferSize"))
  97. return SC.GetValue<bool>("System.IsEnableMultiWaferSize");
  98. return false;
  99. }
  100. }
  101. public bool SamallPinDisable
  102. {
  103. get
  104. {
  105. if (SC.ContainsItem("System.SamallPinDisable"))
  106. return SC.GetValue<bool>("System.SamallPinDisable");
  107. return false;
  108. }
  109. }
  110. public bool Disable
  111. {
  112. get
  113. {
  114. if (SC.ContainsItem($"System.{Name}Disable"))
  115. {
  116. return SC.GetValue<bool>($"System.{Name}Disable");
  117. }
  118. return false;
  119. }
  120. }
  121. public bool IsEnableMultiWaferSizeShow
  122. {
  123. get
  124. {
  125. if (SC.ContainsItem("System.IsEnableMultiWaferSizeShow"))
  126. return SC.GetValue<bool>("System.IsEnableMultiWaferSizeShow");
  127. return false;
  128. }
  129. }
  130. public int CstSizeKind
  131. {
  132. get
  133. {
  134. return SC.GetValue<int>($"System.CstSizeKind");
  135. }
  136. }
  137. public LiftState Feedback3Inch
  138. {
  139. get
  140. {
  141. if (_di3InchExtend.Value && !_di3InchRetract.Value)
  142. return LiftState.Up;
  143. if (!_di3InchExtend.Value && _di3InchRetract.Value)
  144. return LiftState.Down;
  145. return LiftState.Unknown;
  146. }
  147. }
  148. public LiftState Feedback4Inch
  149. {
  150. get
  151. {
  152. //if (_di4InchExtend.Value && _di4InchRetract.Value)
  153. // return LiftState.Error;
  154. if (_di4InchExtend.Value && !_di4InchRetract.Value)
  155. return LiftState.Up;
  156. if (!_di4InchExtend.Value && _di4InchRetract.Value)
  157. return LiftState.Down;
  158. //if (!_di4InchExtend.Value && !_di4InchRetract.Value)
  159. return LiftState.Unknown;
  160. }
  161. }
  162. public LiftState Feedback6Inch
  163. {
  164. get
  165. {
  166. //if (_di4InchExtend.Value && _di4InchRetract.Value)
  167. // return LiftState.Error;
  168. if (_di6InchExtend !=null && _di6InchExtend.Value && !_di6InchRetract.Value)
  169. return LiftState.Up;
  170. if (_di6InchExtend != null && !_di6InchExtend.Value && _di6InchRetract.Value)
  171. return LiftState.Down;
  172. //if (!_di4InchExtend.Value && !_di4InchRetract.Value)
  173. return LiftState.Unknown;
  174. }
  175. }
  176. public LiftState FeedbackLift
  177. {
  178. get
  179. {
  180. //if (_diLiftUp.Value && _diLiftDown.Value)
  181. // return LiftState.Error;
  182. if (_diLiftUp.Value && !_diLiftDown.Value)
  183. return LiftState.Up;
  184. if (!_diLiftUp.Value && _diLiftDown.Value)
  185. return LiftState.Down;
  186. //if (!_di3InchExtend.Value && !_di3InchRetract.Value)
  187. return LiftState.Unknown;
  188. }
  189. }
  190. public LiftState SetPoint3Inch
  191. {
  192. get
  193. {
  194. //if (_do3InchExtend.Value && _do3InchRetract.Value)
  195. // return LiftState.Error;
  196. if (_do3InchExtend.Value && !_do3InchRetract.Value)
  197. return LiftState.Up;
  198. if (!_do3InchExtend.Value && _do3InchRetract.Value)
  199. return LiftState.Down;
  200. //if (!_do3InchExtend.Value && !_do3InchRetract.Value)
  201. return LiftState.Unknown;
  202. }
  203. }
  204. public LiftState SetPoint4Inch
  205. {
  206. get
  207. {
  208. //if (_do4InchExtend.Value && _do4InchRetract.Value)
  209. // return LiftState.Error;
  210. if (_do4InchExtend.Value && !_do4InchRetract.Value)
  211. return LiftState.Up;
  212. if (!_do4InchExtend.Value && _do4InchRetract.Value)
  213. return LiftState.Down;
  214. //if (!_do4InchExtend.Value && !_do4InchRetract.Value)
  215. return LiftState.Unknown;
  216. }
  217. }
  218. public LiftState SetPoint6Inch
  219. {
  220. get
  221. {
  222. //if (_do4InchExtend.Value && _do4InchRetract.Value)
  223. // return LiftState.Error;
  224. if (_do6InchExtend != null && _do6InchExtend.Value && !_do6InchRetract.Value)
  225. return LiftState.Up;
  226. if (_do6InchExtend != null &&!_do6InchExtend.Value && _do6InchRetract.Value)
  227. return LiftState.Down;
  228. //if (!_do4InchExtend.Value && !_do4InchRetract.Value)
  229. return LiftState.Unknown;
  230. }
  231. }
  232. public LiftState SetPointLift
  233. {
  234. get
  235. {
  236. //if (_doLiftUp.Value && _doLiftDown.Value)
  237. // return LiftState.Error;
  238. if (_doLiftUp.Value && !_doLiftDown.Value)
  239. return LiftState.Up;
  240. if (!_doLiftUp.Value && _doLiftDown.Value)
  241. return LiftState.Down;
  242. //if (!_do3InchExtend.Value && !_do3InchRetract.Value)
  243. return LiftState.Unknown;
  244. }
  245. }
  246. public IoCoolingBuffer(string module, XmlElement node, string ioModule = "")
  247. {
  248. base.Module = string.IsNullOrEmpty(node.GetAttribute("module")) ? module : node.GetAttribute("module");
  249. base.Name = node.GetAttribute("id");
  250. base.Display = node.GetAttribute("display");
  251. base.DeviceID = node.GetAttribute("schematicId");
  252. WaferManager.Instance.SubscribeLocation(Module, 1);
  253. _diLiftUp = ParseDiNode("diLiftUp", node, ioModule);
  254. _diLiftDown = ParseDiNode("diLiftDown", node, ioModule);
  255. _di3InchExtend = ParseDiNode("diAligner1Extend", node, ioModule);
  256. _di3InchRetract = ParseDiNode("diAligner1Retract", node, ioModule);
  257. _di4InchExtend = ParseDiNode("diAligner2Extend", node, ioModule);
  258. _di4InchRetract = ParseDiNode("diAligner2Retract", node, ioModule);
  259. _di6InchExtend = ParseDiNode("diAligner3Extend", node, ioModule);
  260. _di6InchRetract = ParseDiNode("diAligner3Retract", node, ioModule);
  261. _doLiftUp = ParseDoNode("doLiftUp", node, ioModule);
  262. _doLiftDown = ParseDoNode("doLiftDown", node, ioModule);
  263. _do3InchExtend = ParseDoNode("doAligner1Extend", node, ioModule);
  264. _do3InchRetract = ParseDoNode("doAligner1Retract", node, ioModule);
  265. _do4InchExtend = ParseDoNode("doAligner2Extend", node, ioModule);
  266. _do4InchRetract = ParseDoNode("doAligner2Retract", node, ioModule);
  267. _do6InchExtend = ParseDoNode("doAligner3Extend", node, ioModule);
  268. _do6InchRetract = ParseDoNode("doAligner3Retract", node, ioModule);
  269. _scLiftUpTimeout = ParseScNode("scUpTimeout", node);
  270. _scLiftDownTimeout = ParseScNode("scDownTimeout", node);
  271. DATA.Subscribe($"{module}.{module}.Status", () => _state.ToString());
  272. }
  273. public bool ManualOperation = false;
  274. public bool Initialize()
  275. {
  276. _state = DeviceState.Init;
  277. if (Module == "System")
  278. {
  279. LOG.Write($"IoCoolingBuffer module is System.");
  280. }
  281. DATA.Subscribe($"{Module}.{Name}.Feedback3Inch", () => _di3InchExtend != null ? Feedback3Inch.ToString(): LiftState.Unknown.ToString());
  282. DATA.Subscribe($"{Module}.{Name}.Feedback4Inch", () => _di4InchExtend != null ? Feedback4Inch.ToString() : LiftState.Unknown.ToString()) ;
  283. DATA.Subscribe($"{Module}.{Name}.Feedback6Inch", () => _di6InchExtend !=null ? Feedback6Inch.ToString() : LiftState.Unknown.ToString());
  284. DATA.Subscribe($"{Module}.{Name}.FeedbackLift", () => FeedbackLift.ToString());
  285. DATA.Subscribe($"{Module}.{Name}.SetPoint3Inch", () => _do6InchExtend != null ? SetPoint3Inch.ToString() : LiftState.Unknown.ToString());
  286. DATA.Subscribe($"{Module}.{Name}.SetPoint4Inch", () => _do4InchExtend != null ? SetPoint4Inch.ToString() : LiftState.Unknown.ToString());
  287. DATA.Subscribe($"{Module}.{Name}.SetPoint6Inch", () => _do6InchExtend != null ? SetPoint6Inch.ToString() : LiftState.Unknown.ToString());
  288. DATA.Subscribe($"{Module}.{Name}.SetPointLift", () => SetPointLift.ToString());
  289. DATA.Subscribe($"{Module}.{Name}.Status", () => _state.ToString());
  290. DATA.Subscribe($"{Module}.{Name}.WaferSizeByWafer", () => WaferManager.Instance.GetWaferSize(ModuleHelper.Converter(Module), 0));//WaferManager.Instance.GetWafer(ModuleHelper.Converter(Module), 0).Size.ToString());
  291. DATA.Subscribe($"{Module}.{Name}.WaferSizeBySetPoint", () => waferSize.ToString());
  292. OP.Subscribe($"{Module}.{Name}.MoveUp3", (string reason, object[] param) =>
  293. {
  294. ManualOperation = true;
  295. reason = "";
  296. return Move(WaferSize.WS3, true, out reason);
  297. });
  298. OP.Subscribe($"{Module}.{Name}.MoveUp4", (string reason, object[] param) =>
  299. {
  300. ManualOperation = true;
  301. reason = "";
  302. return Move(WaferSize.WS4, true, out reason);
  303. });
  304. OP.Subscribe($"{Module}.{Name}.MoveUp6", (string reason, object[] param) =>
  305. {
  306. ManualOperation = true;
  307. reason = "";
  308. return Move(WaferSize.WS6, true, out reason);
  309. });
  310. OP.Subscribe($"{Module}.{Name}.MoveUpLift", (string reason, object[] param) =>
  311. {
  312. ManualOperation = true;
  313. reason = "";
  314. return Move(WaferSize.WS8, true, out reason);
  315. });
  316. OP.Subscribe($"{Module}.{Name}.MoveDown3", (string reason, object[] param) =>
  317. {
  318. ManualOperation = true;
  319. reason = "";
  320. return Move(WaferSize.WS3, false, out reason);
  321. });
  322. OP.Subscribe($"{Module}.{Name}.MoveDown4", (string reason, object[] param) =>
  323. {
  324. ManualOperation = true;
  325. reason = "";
  326. return Move(WaferSize.WS4, false, out reason);
  327. });
  328. OP.Subscribe($"{Module}.{Name}.MoveDown6", (string reason, object[] param) =>
  329. {
  330. ManualOperation = true;
  331. reason = "";
  332. return Move(WaferSize.WS6, false, out reason);
  333. });
  334. OP.Subscribe($"{Module}.{Name}.MoveDownLift", (string reason, object[] param) =>
  335. {
  336. ManualOperation = true;
  337. reason = "";
  338. return Move(WaferSize.WS8, false, out reason);
  339. });
  340. return true;
  341. }
  342. public WaferSize waferSize
  343. {
  344. get
  345. {
  346. if (CstSizeKind == 1)
  347. {
  348. WaferSize size = WaferSize.WS0;
  349. switch (_size)
  350. {
  351. case WaferSize.WS4:
  352. size = WaferSize.WS3;
  353. break;
  354. case WaferSize.WS6:
  355. size = WaferSize.WS4;
  356. break;
  357. case WaferSize.WS8:
  358. size = WaferSize.WS6;
  359. break;
  360. }
  361. return size;
  362. }
  363. return _size;
  364. }
  365. }
  366. public void Monitor()
  367. {
  368. if (SC.ContainsItem($"System.{Name}Disable"))
  369. {
  370. if (SC.GetValue<bool>($"System.{Name}Disable"))
  371. {
  372. _state = DeviceState.Disable;
  373. return;
  374. }
  375. else
  376. {
  377. if(_state == DeviceState.Disable)
  378. _state = DeviceState.Idle;
  379. }
  380. }
  381. if (IsEnableMultiWaferSize)
  382. {
  383. switch (_state)
  384. {
  385. case DeviceState.MovingUp:
  386. if (ManualOperation||!IsEnableMultiWaferSizeShow)
  387. {
  388. switch (_size)
  389. {
  390. case WaferSize.WS0:
  391. case WaferSize.WS8:
  392. {
  393. if (CheckPinUp())
  394. {
  395. LOG.Write($"state:{_state.ToString()}");
  396. _state = DeviceState.Idle;
  397. ManualOperation = false;
  398. }
  399. else
  400. {
  401. if (_timer.IsTimeout())
  402. {
  403. EV.PostAlarmLog(Module, $"{Module} {Name} LiftPin Can not move up in {_scLiftUpTimeout.IntValue} seconds");
  404. _state = DeviceState.Error;
  405. ManualOperation = false;
  406. }
  407. else
  408. {
  409. if (CheckPinUp())
  410. {
  411. //Set3InchDown(out _);
  412. //Set4InchDown(out _);
  413. }
  414. }
  415. }
  416. }
  417. break;
  418. case WaferSize.WS6:
  419. {
  420. if (Check6InchUp())
  421. {
  422. LOG.Write($"state:{_state.ToString()}");
  423. _state = DeviceState.Idle;
  424. ManualOperation = false;
  425. }
  426. else
  427. {
  428. if (_timer.IsTimeout())
  429. {
  430. EV.PostAlarmLog(Module, $"{Module} {Name} 6InchPin Can not move up in {_scLiftUpTimeout.IntValue} seconds");
  431. _state = DeviceState.Error;
  432. ManualOperation = false;
  433. }
  434. else
  435. {
  436. if (Check6InchUp())
  437. {
  438. //Set3InchDown(out _);
  439. //Set4InchDown(out _);
  440. }
  441. }
  442. }
  443. }
  444. break;
  445. case WaferSize.WS4:
  446. {
  447. if (Check4InchUp())
  448. {
  449. LOG.Write($"state:{_state.ToString()}");
  450. _state = DeviceState.Idle;
  451. ManualOperation = false;
  452. }
  453. else
  454. {
  455. if (_timer.IsTimeout())
  456. {
  457. EV.PostAlarmLog(Module, $"{Module} {Name} 4InchPin Can not move up in {_scLiftUpTimeout.IntValue} seconds");
  458. _state = DeviceState.Error;
  459. ManualOperation = false;
  460. }
  461. else
  462. {
  463. if (Check4InchUp())
  464. {
  465. //Set3InchDown(out _);
  466. //Set4InchDown(out _);
  467. }
  468. }
  469. }
  470. }
  471. break;
  472. }
  473. }
  474. else
  475. {
  476. if (CheckPinUp() /*&& Check3InchDown() && Check4InchDown()*/)
  477. {
  478. LOG.Write($"state:{_state.ToString()}");
  479. _state = DeviceState.Idle;
  480. }
  481. else
  482. {
  483. if (_timer.IsTimeout())
  484. {
  485. EV.PostAlarmLog(Module, $"{Module} {Name} Can not move up in {_scLiftUpTimeout.IntValue} seconds");
  486. _state = DeviceState.Error;
  487. }
  488. else
  489. {
  490. if (CheckPinUp())
  491. {
  492. //Set3InchDown(out _);
  493. //Set4InchDown(out _);
  494. }
  495. }
  496. }
  497. }
  498. break;
  499. case DeviceState.MovingDown:
  500. if (ManualOperation ||!IsEnableMultiWaferSizeShow)
  501. {
  502. switch (_size)
  503. {
  504. case WaferSize.WS0:
  505. case WaferSize.WS8:
  506. {
  507. if (CheckPinDown())
  508. {
  509. LOG.Write($"state:{_state.ToString()}");
  510. _state = DeviceState.Idle;
  511. ManualOperation = false;
  512. }
  513. else
  514. {
  515. if (_timer.IsTimeout())
  516. {
  517. EV.PostAlarmLog(Module, $"{Module} {Name} LiftPin Can not move down in {_scLiftUpTimeout.IntValue} seconds");
  518. _state = DeviceState.Error;
  519. ManualOperation = false;
  520. }
  521. else
  522. {
  523. if (CheckPinDown())
  524. {
  525. //Set3InchDown(out _);
  526. //Set4InchDown(out _);
  527. }
  528. }
  529. }
  530. }
  531. break;
  532. case WaferSize.WS6:
  533. {
  534. if (Check6InchDown())
  535. {
  536. LOG.Write($"state:{_state.ToString()}");
  537. _state = DeviceState.Idle;
  538. ManualOperation = false;
  539. }
  540. else
  541. {
  542. if (_timer.IsTimeout())
  543. {
  544. EV.PostAlarmLog(Module, $"{Module} {Name} 6InchPin Can not move down in {_scLiftUpTimeout.IntValue} seconds");
  545. _state = DeviceState.Error;
  546. ManualOperation = false;
  547. }
  548. else
  549. {
  550. if (Check6InchDown())
  551. {
  552. //Set3InchDown(out _);
  553. //Set4InchDown(out _);
  554. }
  555. }
  556. }
  557. }
  558. break;
  559. case WaferSize.WS4:
  560. {
  561. if (Check4InchDown())
  562. {
  563. LOG.Write($"state:{_state.ToString()}");
  564. _state = DeviceState.Idle;
  565. ManualOperation = false;
  566. }
  567. else
  568. {
  569. if (_timer.IsTimeout())
  570. {
  571. EV.PostAlarmLog(Module, $"{Module} {Name} 4InchPin Can not move down in {_scLiftUpTimeout.IntValue} seconds");
  572. _state = DeviceState.Error;
  573. ManualOperation = false;
  574. }
  575. else
  576. {
  577. if (Check4InchDown())
  578. {
  579. //Set3InchDown(out _);
  580. //Set4InchDown(out _);
  581. }
  582. }
  583. }
  584. }
  585. break;
  586. }
  587. }
  588. else
  589. {
  590. bool guided = CheckGuided(_size);
  591. if (CheckPinDown() && guided)
  592. {
  593. _state = DeviceState.Idle;
  594. }
  595. else
  596. {
  597. if (_timer.IsTimeout())
  598. {
  599. EV.PostAlarmLog(Module, $"{Module} {Name} Can not move down in {_scLiftUpTimeout.IntValue} seconds");
  600. _state = DeviceState.Error;
  601. }
  602. else
  603. {
  604. if (guided)
  605. {
  606. SetPinDown(out _);
  607. }
  608. }
  609. }
  610. }
  611. break;
  612. case DeviceState.Homing:
  613. if (IsEnableMultiWaferSizeShow)
  614. {
  615. if (!SamallPinDisable)
  616. {
  617. if (Check6InchDown() && CheckPinDown())
  618. //if(CheckPinDown())
  619. _state = DeviceState.Idle;
  620. }
  621. else
  622. {
  623. if (Check4InchDown() && Check6InchDown() && CheckPinDown())
  624. //if(CheckPinDown())
  625. _state = DeviceState.Idle;
  626. }
  627. }
  628. else
  629. {
  630. if(CheckPinDown())
  631. _state = DeviceState.Idle;
  632. }
  633. break;
  634. default:
  635. break;
  636. }
  637. }
  638. else
  639. {
  640. switch (_state)
  641. {
  642. case DeviceState.MovingUp:
  643. if (CheckPinUp() /*&& Check3InchDown() && Check4InchDown()*/)
  644. {
  645. LOG.Write($"{Module} move pin up complete");
  646. LOG.Write($"state:{_state.ToString()}");
  647. _state = DeviceState.Idle;
  648. }
  649. else
  650. {
  651. if (_timer.IsTimeout())
  652. {
  653. EV.PostAlarmLog(Module, $"{Module} {Name} Can not move up in {_scLiftUpTimeout.IntValue} seconds");
  654. _state = DeviceState.Error;
  655. }
  656. else
  657. {
  658. if (CheckPinUp())
  659. {
  660. //Set3InchDown(out _);
  661. //Set4InchDown(out _);
  662. }
  663. }
  664. }
  665. break;
  666. case DeviceState.MovingDown:
  667. // bool guided = CheckGuided(_size);
  668. if (CheckPinDown()) //&& guided)
  669. {
  670. LOG.Write($"{Module} move pin down complete");
  671. LOG.Write($"state:{_state.ToString()}");
  672. _state = DeviceState.Idle;
  673. }
  674. else
  675. {
  676. if (_timer.IsTimeout())
  677. {
  678. EV.PostAlarmLog(Module, $"{Module} {Name} Can not move down in {_scLiftUpTimeout.IntValue} seconds");
  679. _state = DeviceState.Error;
  680. }
  681. else
  682. {
  683. if (CheckPinDown())
  684. {
  685. }
  686. //if (guided)
  687. //{
  688. // SetPinDown(out _);
  689. //}
  690. }
  691. }
  692. break;
  693. case DeviceState.Homing:
  694. //if (Check3InchDown() && Check4InchDown() && CheckPinDown())
  695. if (CheckPinDown())
  696. _state = DeviceState.Idle;
  697. break;
  698. default:
  699. break;
  700. }
  701. }
  702. }
  703. public void Terminate()
  704. {
  705. }
  706. public bool Home(out string reason)
  707. {
  708. ModuleName _module;
  709. if (!Enum.TryParse<ModuleName>(Module, out _module))
  710. {
  711. reason = $"{Module} isn't exist";
  712. return false;
  713. }
  714. if (_state != DeviceState.Error && _state != DeviceState.Idle && _state != DeviceState.Init)
  715. {
  716. reason = $"{Module} is in {_state} state.";
  717. return false;
  718. }
  719. if (_state == DeviceState.Disable)
  720. {
  721. reason = string.Empty;
  722. return true;
  723. }
  724. WaferInfo info = WaferManager.Instance.GetWafer(_module, 0);
  725. if (IsEnableMultiWaferSize && IsEnableMultiWaferSizeShow)
  726. {
  727. if(SamallPinDisable)
  728. _do4InchExtend.SetValue(false, out reason);
  729. if(_do6InchExtend!=null)
  730. _do6InchExtend.SetValue(false, out reason);
  731. _doLiftUp.SetValue(false, out reason);
  732. if (SamallPinDisable)
  733. _do4InchRetract.SetValue(true, out reason);
  734. if (_do6InchRetract != null)
  735. _do6InchRetract.SetValue(true, out reason);
  736. _doLiftDown.SetValue(true, out reason);
  737. }
  738. else
  739. { //_do3InchExtend.SetValue(false, out reason);
  740. //_do4InchExtend.SetValue(false, out reason);
  741. _doLiftUp.SetValue(false, out reason);
  742. //_do3InchRetract.SetValue(true, out reason);
  743. //_do4InchRetract.SetValue(true, out reason);
  744. _doLiftDown.SetValue(true, out reason);
  745. }
  746. _state = DeviceState.Homing;
  747. return true;
  748. }
  749. public bool Move(WaferSize size, bool up, out string reason)
  750. {
  751. _size = size;
  752. if(CstSizeKind==1)
  753. {
  754. switch(size)
  755. {
  756. case WaferSize.WS3:
  757. _size = WaferSize.WS4;
  758. break;
  759. case WaferSize.WS4:
  760. _size = WaferSize.WS6;
  761. break;
  762. case WaferSize.WS6:
  763. _size = WaferSize.WS8;
  764. break;
  765. }
  766. }
  767. if (up)
  768. {
  769. return MoveUp(out reason);
  770. }
  771. return MoveDown(out reason);
  772. }
  773. public bool Check3InchUp() { return Feedback3Inch == LiftState.Up; }
  774. public bool Check3InchDown() { return Feedback3Inch == LiftState.Down; }
  775. public bool Check4InchUp() { return Feedback4Inch == LiftState.Up; }
  776. public bool Check4InchDown() { return Feedback4Inch == LiftState.Down; }
  777. public bool Check6InchUp() { return Feedback6Inch == LiftState.Up; }
  778. public bool Check6InchDown() { return Feedback6Inch == LiftState.Down; }
  779. public bool CheckPinUp() { return FeedbackLift == LiftState.Up; }
  780. public bool CheckPinDown() { return FeedbackLift == LiftState.Down; }
  781. private bool Set3InchUp(out string reason)
  782. {
  783. if (SetPoint3Inch != LiftState.Up)
  784. EV.PostInfoLog(Module, $"{Module} move 3 inch up");
  785. return _do3InchExtend.SetValue(true, out reason) && _do3InchRetract.SetValue(false, out reason);
  786. }
  787. private bool Set3InchDown(out string reason)
  788. {
  789. if (SetPoint3Inch != LiftState.Down)
  790. EV.PostInfoLog(Module, $"{Module} move 3 inch down");
  791. return _do3InchExtend.SetValue(false, out reason) && _do3InchRetract.SetValue(true, out reason);
  792. }
  793. private bool Set4InchUp(out string reason)
  794. {
  795. if (SetPoint4Inch != LiftState.Up)
  796. EV.PostInfoLog(Module, $"{Module} move 4 inch up");
  797. return _do4InchExtend.SetValue(true, out reason) && _do4InchRetract.SetValue(false, out reason);
  798. }
  799. private bool Set4InchDown(out string reason)
  800. {
  801. if (SetPoint4Inch != LiftState.Down)
  802. EV.PostInfoLog(Module, $"{Module} move 4 inch down");
  803. return _do4InchExtend.SetValue(false, out reason) && _do4InchRetract.SetValue(true, out reason);
  804. }
  805. private bool Set6InchUp(out string reason)
  806. {
  807. if (SetPoint6Inch != LiftState.Up)
  808. EV.PostInfoLog(Module, $"{Module} move 6 inch up");
  809. return _do6InchExtend.SetValue(true, out reason) && _do6InchRetract.SetValue(false, out reason);
  810. }
  811. private bool Set6InchDown(out string reason)
  812. {
  813. if (SetPoint6Inch != LiftState.Down)
  814. EV.PostInfoLog(Module, $"{Module} move 6 inch down");
  815. return _do6InchExtend.SetValue(false, out reason) && _do6InchRetract.SetValue(true, out reason);
  816. }
  817. private bool SetPinUp(out string reason)
  818. {
  819. if (SetPointLift != LiftState.Up)
  820. EV.PostInfoLog(Module, $"{Module} move pin up");
  821. return _doLiftDown.SetValue(false, out reason) && _doLiftUp.SetValue(true, out reason);
  822. }
  823. private bool SetPinDown(out string reason)
  824. {
  825. if (SetPointLift != LiftState.Down)
  826. EV.PostInfoLog(Module, $"{Module} move pin down");
  827. return _doLiftUp.SetValue(false, out reason) && _doLiftDown.SetValue(true, out reason);
  828. }
  829. public bool CheckMovedUp()
  830. {
  831. // return CheckPinUp() && Check3InchDown() && Check4InchDown();
  832. return CheckPinUp();
  833. }
  834. public bool CheckMovedDown()
  835. {
  836. return CheckPinDown(); //&& CheckGuided(_size);
  837. }
  838. private bool CheckGuided(WaferSize size)
  839. {
  840. bool guided = false;
  841. switch (_size)
  842. {
  843. case WaferSize.WS0:
  844. case WaferSize.WS8:
  845. {
  846. if (!SamallPinDisable)
  847. guided = Check6InchDown();
  848. else
  849. guided = Check6InchDown() && Check4InchDown();
  850. }
  851. break;
  852. case WaferSize.WS6:
  853. {
  854. if (!SamallPinDisable)
  855. guided = Check6InchUp();
  856. else
  857. guided = Check6InchUp() && Check4InchDown();
  858. }
  859. break;
  860. case WaferSize.WS3:
  861. {
  862. guided = Check3InchUp() && Check4InchDown();
  863. }
  864. break;
  865. case WaferSize.WS4:
  866. {
  867. guided = Check6InchDown() && Check4InchUp();
  868. }
  869. break;
  870. }
  871. return guided;
  872. }
  873. private bool MoveUp(out string reason)
  874. {
  875. reason = string.Empty;
  876. bool ret = true;
  877. if (IsEnableMultiWaferSize)
  878. {
  879. if (ManualOperation|| !IsEnableMultiWaferSizeShow)
  880. {
  881. switch (_size)
  882. {
  883. case WaferSize.WS0:
  884. case WaferSize.WS8:
  885. {
  886. if (!SetPinUp(out reason))
  887. {
  888. ret = false;
  889. }
  890. }
  891. break;
  892. case WaferSize.WS6:
  893. {
  894. if (!Set6InchUp(out reason))
  895. {
  896. ret = false;
  897. }
  898. }
  899. break;
  900. case WaferSize.WS3:
  901. {
  902. if (!Set3InchUp(out reason))
  903. {
  904. ret = false;
  905. }
  906. }
  907. break;
  908. case WaferSize.WS4:
  909. {
  910. if (!Set4InchUp(out reason))
  911. {
  912. ret = false;
  913. }
  914. }
  915. break;
  916. }
  917. }
  918. else
  919. {
  920. switch (_size)
  921. {
  922. case WaferSize.WS0:
  923. case WaferSize.WS8:
  924. {
  925. if ((SamallPinDisable&&!Set4InchDown(out reason)) || !Set6InchDown(out reason) || !SetPinUp(out reason))
  926. {
  927. ret = false;
  928. }
  929. }
  930. break;
  931. case WaferSize.WS6:
  932. {
  933. if ((SamallPinDisable&&!Set4InchDown(out reason)) || !Set6InchUp(out reason) || !SetPinUp(out reason))
  934. {
  935. ret = false;
  936. }
  937. }
  938. break;
  939. case WaferSize.WS3:
  940. {
  941. if (!SetPinUp(out reason))//!Set3InchUp(out reason) || !Set4InchDown(out reason) || !SetPinUp(out reason))
  942. {
  943. ret = false;
  944. }
  945. }
  946. break;
  947. case WaferSize.WS4:
  948. {
  949. if (!Set6InchDown(out reason) || (!Set4InchUp(out reason)) || !SetPinUp(out reason))
  950. {
  951. ret = false;
  952. }
  953. }
  954. break;
  955. }
  956. // ManualOperation = false;
  957. }
  958. LOG.Write($"ret:{ret}");
  959. if (!ret)
  960. return false;
  961. _timer.Start(_scLiftUpTimeout.IntValue * 1000);
  962. _state = DeviceState.MovingUp;
  963. }
  964. else
  965. {
  966. switch (_size)
  967. {
  968. case WaferSize.WS0:
  969. case WaferSize.WS8:
  970. case WaferSize.WS6:
  971. {
  972. if (!SetPinUp(out reason))//!Set3InchDown(out reason) || !Set4InchDown(out reason) || !SetPinUp(out reason))
  973. {
  974. ret = false;
  975. }
  976. }
  977. break;
  978. case WaferSize.WS3:
  979. {
  980. if (!SetPinUp(out reason))//!Set3InchUp(out reason) || !Set4InchDown(out reason) || !SetPinUp(out reason))
  981. {
  982. ret = false;
  983. }
  984. }
  985. break;
  986. case WaferSize.WS4:
  987. {
  988. if (!SetPinUp(out reason))//!Set3InchDown(out reason) || !Set4InchUp(out reason) || !SetPinUp(out reason))
  989. {
  990. ret = false;
  991. }
  992. }
  993. break;
  994. }
  995. LOG.Write($"ret:{ret}");
  996. if (!ret)
  997. return false;
  998. _timer.Start(_scLiftUpTimeout.IntValue * 1000);
  999. _state = DeviceState.MovingUp;
  1000. }
  1001. return true;
  1002. }
  1003. private bool MoveDown(out string reason)
  1004. {
  1005. reason = string.Empty;
  1006. bool ret = true;
  1007. if (IsEnableMultiWaferSize)
  1008. {
  1009. if (ManualOperation|| !IsEnableMultiWaferSizeShow)
  1010. {
  1011. switch (_size)
  1012. {
  1013. case WaferSize.WS0:
  1014. case WaferSize.WS8:
  1015. {
  1016. if (!SetPinDown(out reason))
  1017. {
  1018. ret = false;
  1019. }
  1020. }
  1021. break;
  1022. case WaferSize.WS6:
  1023. {
  1024. if (!Set6InchDown(out reason))
  1025. {
  1026. ret = false;
  1027. }
  1028. }
  1029. break;
  1030. case WaferSize.WS3:
  1031. {
  1032. if (!SetPinDown(out reason))//!Set3InchUp(out reason) || Set4InchDown(out reason)||!SetPinDown(out reason))
  1033. {
  1034. ret = false;
  1035. }
  1036. }
  1037. break;
  1038. case WaferSize.WS4:
  1039. {
  1040. if (!Set4InchDown(out reason))
  1041. {
  1042. ret = false;
  1043. }
  1044. }
  1045. break;
  1046. }
  1047. }
  1048. else
  1049. {
  1050. switch (_size)
  1051. {
  1052. case WaferSize.WS0:
  1053. case WaferSize.WS8:
  1054. {
  1055. if ((SamallPinDisable&&!Set4InchDown(out reason)) || !Set6InchDown(out reason) || !SetPinDown(out reason))
  1056. {
  1057. ret = false;
  1058. }
  1059. }
  1060. break;
  1061. case WaferSize.WS6:
  1062. {
  1063. if (!Set6InchUp(out reason) ||(SamallPinDisable&&!Set4InchDown(out reason)) || !SetPinDown(out reason))
  1064. {
  1065. ret = false;
  1066. }
  1067. }
  1068. break;
  1069. case WaferSize.WS3:
  1070. {
  1071. if (!SetPinDown(out reason))//!Set3InchUp(out reason) || Set4InchDown(out reason)||!SetPinDown(out reason))
  1072. {
  1073. ret = false;
  1074. }
  1075. }
  1076. break;
  1077. case WaferSize.WS4:
  1078. {
  1079. if ((!Set4InchUp(out reason)) || !Set6InchDown(out reason) || !SetPinDown(out reason))
  1080. {
  1081. ret = false;
  1082. }
  1083. }
  1084. break;
  1085. }
  1086. //ManualOperation = false;
  1087. }
  1088. LOG.Write($"ret:{ret}");
  1089. if (!ret)
  1090. return false;
  1091. _timer.Start(_scLiftDownTimeout.IntValue * 1000);
  1092. _state = DeviceState.MovingDown;
  1093. }
  1094. else
  1095. {
  1096. switch (_size)
  1097. {
  1098. case WaferSize.WS0:
  1099. case WaferSize.WS8:
  1100. case WaferSize.WS6:
  1101. {
  1102. if (!SetPinDown(out reason)) //(!Set3InchDown(out reason) || !Set4InchDown(out reason)||!SetPinDown(out reason))
  1103. {
  1104. ret = false;
  1105. }
  1106. }
  1107. break;
  1108. case WaferSize.WS3:
  1109. {
  1110. if (!SetPinDown(out reason))//!Set3InchUp(out reason) || Set4InchDown(out reason)||!SetPinDown(out reason))
  1111. {
  1112. ret = false;
  1113. }
  1114. }
  1115. break;
  1116. case WaferSize.WS4:
  1117. {
  1118. if (!SetPinDown(out reason))//!Set4InchUp(out reason) || !Set3InchDown(out reason)||!SetPinDown(out reason))
  1119. {
  1120. ret = false;
  1121. }
  1122. }
  1123. break;
  1124. }
  1125. LOG.Write($"ret:{ret}");
  1126. if (!ret)
  1127. return false;
  1128. _timer.Start(_scLiftDownTimeout.IntValue * 1000);
  1129. _state = DeviceState.MovingDown;
  1130. }
  1131. return true;
  1132. }
  1133. public void Reset()
  1134. {
  1135. }
  1136. }
  1137. }