IoCoolingBuffer.cs 48 KB

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