CANPolicy.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737
  1. using System;
  2. using System.Text.RegularExpressions;
  3. using Aitex.Core.RT.DataCenter;
  4. using Aitex.Core.RT.Device;
  5. using Aitex.Core.RT.Device.Unit;
  6. using Aitex.Core.RT.Log;
  7. using Aitex.Core.Util;
  8. using Aitex.Sorter.Common;
  9. using MECF.Framework.Common.Equipment;
  10. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.BufferStations;
  11. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.LoadPorts;
  12. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robot;
  13. namespace Aitex.Sorter.RT.EFEMs.Servers
  14. {
  15. /// <summary>
  16. /// Communication establish is not completed
  17. /// </summary>
  18. public class InitNoReadyPolicy : CheckImp, IPolicy
  19. {
  20. public InitNoReadyPolicy()
  21. {
  22. }
  23. public bool Check(string device, out string reason)
  24. {
  25. reason = string.Empty;
  26. var isReady = Singleton<EfemEntity>.Instance.IsCommunicationOk;
  27. if (!isReady)
  28. {
  29. reason = "NOREADY";
  30. return false;
  31. }
  32. return true;
  33. }
  34. }
  35. /// <summary>
  36. /// Communication establish is not completed
  37. /// </summary>
  38. public class NoReadyPolicy : CheckImp, IPolicy
  39. {
  40. public NoReadyPolicy()
  41. {
  42. }
  43. public bool Check(string device, out string reason)
  44. {
  45. reason = string.Empty;
  46. var isReady = Singleton<EfemEntity>.Instance.IsCommunicationOk;
  47. if (!isReady)
  48. {
  49. reason = "NOREADY";
  50. return false;
  51. }
  52. return true;
  53. }
  54. }
  55. /// <summary>
  56. /// NOINITCMPL No Initialize Completed - EFEM is not initialized.
  57. /// </summary>
  58. public class NoInitCompletedPolicy : CheckImp, IPolicy
  59. {
  60. public NoInitCompletedPolicy()
  61. {
  62. }
  63. public bool Check(string device, out string reason)
  64. {
  65. reason = string.Empty;
  66. if (device == DeviceName.SignalTower)
  67. {
  68. return true;
  69. }
  70. var entity = GetEntity(device);
  71. if (entity == null)
  72. {
  73. return true;
  74. }
  75. if (device == DeviceName.Buffer1 || device == DeviceName.Buffer2 || device == DeviceName.Buffer3 ||
  76. device == DeviceName.Buffer4)
  77. {
  78. entity = GetEntity(DeviceName.System);
  79. }
  80. if (!entity.Initialized)
  81. {
  82. reason = "NOINITCMPL";
  83. return false;
  84. }
  85. return true;
  86. }
  87. }
  88. /// <summary>
  89. /// NOORGCMPL No Origin Search Completed - Robot origin search is not performed.
  90. /// </summary>
  91. public class NoOriginCompletedPolicy : CheckImp, IPolicy
  92. {
  93. public NoOriginCompletedPolicy()
  94. {
  95. }
  96. public bool Check(string device, out string reason)
  97. {
  98. reason = string.Empty;
  99. IServerModule entity = GetEntity(device);
  100. if (entity == null)
  101. {
  102. return true;
  103. }
  104. if (device == DeviceName.Buffer1 || device == DeviceName.Buffer2 || device == DeviceName.Buffer3 ||
  105. device == DeviceName.Buffer4)
  106. {
  107. entity = GetEntity(DeviceName.System);
  108. }
  109. if (!entity.OriginSearched)
  110. {
  111. reason = "NOORGCMPL";
  112. return false;
  113. }
  114. return true;
  115. }
  116. }
  117. /// <summary>
  118. /// Insufficient vacuum source pressure
  119. /// </summary>
  120. public class VacPolicy : CheckImp, IPolicy
  121. {
  122. public VacPolicy()
  123. {
  124. }
  125. public bool Check(string device, out string reason)
  126. {
  127. reason = string.Empty;
  128. if (Singleton<EfemEntity>.Instance.EfemDevice.CheckVacuumError())
  129. {
  130. reason = "VAC";
  131. return false;
  132. }
  133. return true;
  134. }
  135. }
  136. /// <summary>
  137. /// AIR Insufficient air source pressure
  138. /// </summary>
  139. public class AirPolicy : CheckImp, IPolicy
  140. {
  141. public AirPolicy()
  142. {
  143. }
  144. public bool Check(string device, out string reason)
  145. {
  146. reason = string.Empty;
  147. if (device == DeviceName.SignalTower)
  148. {
  149. return true;
  150. }
  151. if (!Enum.TryParse(device, out ModuleName moduleName))
  152. {
  153. reason = PARAM_NG;
  154. return false;
  155. }
  156. if (ModuleHelper.IsLoadPort(moduleName))
  157. {
  158. var sensor = DEVICE.GetDevice<IoSensor>("SensorAirPressureErrorForLoadport");
  159. if (sensor == null || sensor.Value)
  160. {
  161. return true;
  162. }
  163. reason = "AIR";
  164. return false;
  165. }
  166. if (moduleName == ModuleName.Robot || moduleName == ModuleName.System)
  167. {
  168. var sensor = DEVICE.GetDevice<IoSensor>("SensorAirPressureErrorForRobot");
  169. if (sensor == null || sensor.Value)
  170. {
  171. return true;
  172. }
  173. reason = "AIR";
  174. return false;
  175. }
  176. reason = "";
  177. return true;
  178. }
  179. }
  180. /// <summary>
  181. /// EMS Stop made by EMS message
  182. /// </summary>
  183. public class EMSPolicy : CheckImp, IPolicy
  184. {
  185. public EMSPolicy()
  186. {
  187. }
  188. public bool Check(string device, out string reason)
  189. {
  190. reason = string.Empty;
  191. if (Singleton<EfemEntity>.Instance.EfemDevice.IsEMSStop)
  192. {
  193. reason = "EMS";
  194. return false;
  195. }
  196. return true;
  197. }
  198. }
  199. /// <summary>
  200. /// ERROR Error stop
  201. /// </summary>
  202. public class ErrorPolicy : CheckImp, IPolicy
  203. {
  204. public ErrorPolicy()
  205. {
  206. }
  207. public bool Check(string device, out string reason)
  208. {
  209. reason = string.Empty;
  210. if (Singleton<EfemEntity>.Instance.EfemDevice.CheckIsError(ModuleHelper.Converter(device)))
  211. {
  212. reason = "ERROR";
  213. return false;
  214. }
  215. return true;
  216. }
  217. }
  218. /// <summary>
  219. /// BUSY Busy (Transfer system is in use)
  220. /// </summary>
  221. public class BusyPolicy : CheckImp, IPolicy
  222. {
  223. public BusyPolicy()
  224. {
  225. }
  226. public bool Check(string device, out string reason)
  227. {
  228. reason = string.Empty;
  229. if (device == DeviceName.SignalTower)
  230. {
  231. return true;
  232. }
  233. IServerModule entity = GetEntity(device);
  234. if (entity.Busy || entity.InUsed)
  235. {
  236. if (entity.Busy)
  237. LOG.Write($"BusyPolicy {device} is Busy");
  238. if (entity.InUsed)
  239. LOG.Write($"BusyPolicy {device} is InUsed");
  240. reason = "BUSY";
  241. return false;
  242. }
  243. return true;
  244. }
  245. }
  246. public class InitBusyPolicy : CheckImp, IPolicy
  247. {
  248. public InitBusyPolicy()
  249. {
  250. }
  251. public bool Check(string device, out string reason)
  252. {
  253. reason = string.Empty;
  254. if (device == DeviceName.SignalTower)
  255. {
  256. return true;
  257. }
  258. IServerModule entity = GetEntity(device);
  259. if (entity is RobotServerModule)
  260. {
  261. if ((entity.Busy || entity.InUsed) && (!entity.Error))
  262. {
  263. if (entity.Busy)
  264. {
  265. LOG.Write($"BusyPolicy {device} is Busy");
  266. }
  267. if (entity.InUsed)
  268. {
  269. LOG.Write($"BusyPolicy {device} is InUsed");
  270. }
  271. reason = "BUSY";
  272. return false;
  273. }
  274. }
  275. else if (entity.Busy || entity.InUsed)
  276. {
  277. if (entity.Busy)
  278. LOG.Write($"BusyPolicy {device} is Busy");
  279. if (entity.InUsed)
  280. LOG.Write($"BusyPolicy {device} is InUsed");
  281. reason = "BUSY";
  282. return false;
  283. }
  284. return true;
  285. }
  286. }
  287. /// <summary>
  288. /// NOLINK Communication with unit is not established
  289. /// </summary>
  290. public class LinkPolicy : CheckImp, IPolicy
  291. {
  292. public LinkPolicy()
  293. {
  294. }
  295. public bool Check(string device, out string reason)
  296. {
  297. reason = string.Empty;
  298. if (device == DeviceName.SignalTower)
  299. {
  300. return true;
  301. }
  302. IServerModule entity = GetEntity(device);
  303. if (!entity.IsLinkOk)
  304. {
  305. reason = "NOLINK";
  306. return false;
  307. }
  308. return true;
  309. }
  310. }
  311. /// <summary>
  312. /// REMOVE Port is not available
  313. /// </summary>
  314. public class RemovePolicy : CheckImp, IPolicy
  315. {
  316. public RemovePolicy()
  317. {
  318. }
  319. public bool Check(string device, out string reason)
  320. {
  321. reason = string.Empty;
  322. if (device == DeviceName.SignalTower)
  323. {
  324. return true;
  325. }
  326. if (ModuleHelper.IsLoadPort((ModuleName)Enum.Parse(typeof(ModuleName), device)))
  327. {
  328. string pattern = "[1-9]\\d*";
  329. Regex rgx = new Regex(pattern);
  330. var match = int.Parse(rgx.Match(device).ToString());
  331. if (match > LoadPortQuantity)
  332. {
  333. reason = "REMOVE";
  334. return false;
  335. }
  336. }
  337. IServerModule entity = GetEntity(device);
  338. if (entity == null || entity.Disabled)
  339. {
  340. reason = "REMOVE";
  341. return false;
  342. }
  343. return true;
  344. }
  345. }
  346. /// <summary>
  347. /// CMPL Operation made by message is completed
  348. /// </summary>
  349. public class CMPLPolicy : CheckImp, IPolicy
  350. {
  351. public CMPLPolicy()
  352. {
  353. }
  354. public bool Check(string device, out string reason)
  355. {
  356. reason = string.Empty;
  357. IServerModule entity = GetEntity(device);
  358. if (!entity.Busy)
  359. {
  360. reason = "CMPL";
  361. return false;
  362. }
  363. return true;
  364. }
  365. }
  366. /// <summary>
  367. /// CLOSE Pod is closed
  368. /// </summary>
  369. public class ClosePolicy : CheckImp, IPolicy
  370. {
  371. public ClosePolicy()
  372. {
  373. }
  374. public bool Check(string device, out string reason)
  375. {
  376. reason = string.Empty;
  377. if (ModuleHelper.IsLoadPort(ModuleHelper.Converter(device)))
  378. {
  379. LoadPort _device = DEVICE.GetDevice<LoadPort>(device);
  380. if (_device.DoorState == FoupDoorState.Close)
  381. {
  382. reason = "CLOSE";
  383. return false;
  384. }
  385. }
  386. return true;
  387. }
  388. }
  389. /// <summary>
  390. /// NOMAPCMPL Wafer mapping is not completed
  391. /// </summary>
  392. public class NoWaferMappingCompletedPolicy : CheckImp, IPolicy
  393. {
  394. public NoWaferMappingCompletedPolicy()
  395. {
  396. }
  397. public bool Check(string device, out string reason)
  398. {
  399. reason = string.Empty;
  400. if (!Singleton<EfemEntity>.Instance.EfemDevice.CheckIsMapped(ModuleHelper.Converter(device)))
  401. {
  402. reason = "NOMAPCMPL";
  403. return false;
  404. }
  405. return true;
  406. }
  407. }
  408. /// <summary>
  409. /// NONPOD No necessary pod
  410. /// </summary>
  411. public class NoPodPolicy : CheckImp, IPolicy
  412. {
  413. public NoPodPolicy()
  414. {
  415. }
  416. public bool Check(string device, out string reason)
  417. {
  418. reason = string.Empty;
  419. if (device == DeviceName.SignalTower)
  420. {
  421. return true;
  422. }
  423. if (ModuleHelper.IsLoadPort(ModuleHelper.Converter(device)))
  424. {
  425. LoadPort _device = DEVICE.GetDevice<LoadPort>(device);
  426. if (_device.CassetteState != LoadportCassetteState.Normal)
  427. {
  428. reason = "NONPOD";
  429. return false;
  430. }
  431. }
  432. return true;
  433. }
  434. }
  435. /// <summary>
  436. /// POD Unnecessary pod has already existed
  437. /// </summary>
  438. public class PodPolicy : CheckImp, IPolicy
  439. {
  440. public PodPolicy()
  441. {
  442. }
  443. public bool Check(string device, out string reason)
  444. {
  445. reason = string.Empty;
  446. if (ModuleHelper.IsLoadPort(ModuleHelper.Converter(device)))
  447. {
  448. LoadPort _device = DEVICE.GetDevice<LoadPort>(device);
  449. if (_device.CassetteState == LoadportCassetteState.Normal)
  450. {
  451. reason = "POD";
  452. return false;
  453. }
  454. }
  455. return true;
  456. }
  457. }
  458. /// <summary>
  459. /// Not in motion
  460. /// </summary>
  461. public class NoMovingPolicy : CheckImp, IPolicy
  462. {
  463. public NoMovingPolicy()
  464. {
  465. }
  466. public bool Check(string device, out string reason)
  467. {
  468. reason = string.Empty;
  469. IServerModule entity = GetEntity(device);
  470. if (!entity.Busy)
  471. {
  472. reason = "NOTINMOTION";
  473. return false;
  474. }
  475. return true;
  476. }
  477. }
  478. /// <summary>
  479. /// HOLD Hold
  480. /// </summary>
  481. public class HoldPolicy : CheckImp, IPolicy
  482. {
  483. public HoldPolicy()
  484. {
  485. }
  486. public bool Check(string device, out string reason)
  487. {
  488. reason = string.Empty;
  489. bool isHold = (bool)DATA.Poll(ModuleName.System.ToString(), ParamName.IsHold);
  490. if (isHold)
  491. {
  492. reason = "HOLD";
  493. return false;
  494. }
  495. return true;
  496. }
  497. }
  498. /// <summary>
  499. ///NOHOLD Not being held ○
  500. /// </summary>
  501. public class NoHoldPolicy : CheckImp, IPolicy
  502. {
  503. public NoHoldPolicy()
  504. {
  505. }
  506. public bool Check(string device, out string reason)
  507. {
  508. reason = string.Empty;
  509. bool isHold = (bool)DATA.Poll(ModuleName.System.ToString(), ParamName.IsHold);
  510. if (!isHold)
  511. {
  512. reason = "NOHOLD";
  513. return false;
  514. }
  515. return true;
  516. }
  517. }
  518. /// <summary>
  519. ///LLCLOSE LL door is closed
  520. /// </summary>
  521. public class LLDoorClosedPolicy : CheckImp, IPolicy
  522. {
  523. public LLDoorClosedPolicy()
  524. {
  525. }
  526. public bool Check(string device, out string reason)
  527. {
  528. reason = string.Empty;
  529. if (Singleton<EfemEntity>.Instance.EfemDevice.CheckLoadLockDoorClosed())
  530. {
  531. reason = "LLCLOSE";
  532. return false;
  533. }
  534. return true;
  535. }
  536. }
  537. /// <summary>
  538. ///LLNOEXTEND Finger cannot be inserted into LL
  539. /// </summary>
  540. public class LLNoExtenedPolicy : CheckImp, IPolicy
  541. {
  542. public LLNoExtenedPolicy()
  543. {
  544. }
  545. public bool Check(string device, out string reason)
  546. {
  547. reason = string.Empty;
  548. if (Singleton<EfemEntity>.Instance.EfemDevice.CheckLLCanNotExtended())
  549. {
  550. reason = "LLNOEXTEND";
  551. return false;
  552. }
  553. return true;
  554. }
  555. }
  556. /// <summary>
  557. ///MAINTENANCE Key switch is set to "Mainte"
  558. /// </summary>
  559. public class MaintenancePolicy : CheckImp, IPolicy
  560. {
  561. public MaintenancePolicy()
  562. {
  563. }
  564. public bool Check(string device, out string reason)
  565. {
  566. reason = string.Empty;
  567. if (Singleton<EfemEntity>.Instance.EfemDevice.IsMaintenanceMode || !Singleton<EfemEntity>.Instance.IsOnlineMode)
  568. {
  569. reason = "MAINTENANCE";
  570. return false;
  571. }
  572. return true;
  573. }
  574. }
  575. /// <summary>
  576. ///ARMEXTEND Finger is being inserted in pod
  577. /// </summary>
  578. public class ArmExtendPolicy : CheckImp, IPolicy
  579. {
  580. public ArmExtendPolicy()
  581. {
  582. }
  583. public bool Check(string device, out string reason)
  584. {
  585. reason = string.Empty;
  586. if (Singleton<EfemEntity>.Instance.EfemDevice.CheckArmExtended(ModuleName.Robot, device))
  587. {
  588. reason = "ARMEXTEND";
  589. return false;
  590. }
  591. return true;
  592. }
  593. }
  594. /// <summary>
  595. ///DRPOWERDOWN Drive power error
  596. /// </summary>
  597. public class PowerDownPolicy : CheckImp, IPolicy
  598. {
  599. public PowerDownPolicy()
  600. {
  601. }
  602. public bool Check(string device, out string reason)
  603. {
  604. reason = string.Empty;
  605. if (Singleton<EfemEntity>.Instance.EfemDevice.IsMaintenanceMode)
  606. {
  607. reason = "DRPOWERDOWN";
  608. return false;
  609. }
  610. return true;
  611. }
  612. }
  613. /// <summary>
  614. ///NOPOS Inoperable position
  615. /// </summary>
  616. public class NoPosPolicy : CheckImp, IPolicy
  617. {
  618. public NoPosPolicy()
  619. {
  620. }
  621. public bool Check(string device, out string reason)
  622. {
  623. reason = string.Empty;
  624. IServerModule entity = GetEntity(device);
  625. if (ModuleHelper.IsLoadLock((ModuleName)Enum.Parse(typeof(ModuleName), device)))
  626. {
  627. var loadPort = DEVICE.GetDevice<LoadPort>(ModuleName.LP1.ToString());
  628. if (loadPort.DoorState == FoupDoorState.Close && loadPort.ClampState == FoupClampState.Open)
  629. {
  630. reason = "NOPOS";
  631. return false;
  632. }
  633. }
  634. return true;
  635. }
  636. }
  637. /// <summary>
  638. ///NoFuncPolicy Inoperable position
  639. /// </summary>
  640. public class NoFuncPolicy : CheckImp, IPolicy
  641. {
  642. public NoFuncPolicy()
  643. {
  644. }
  645. public bool Check(string device, out string reason)
  646. {
  647. reason = string.Empty;
  648. if (Singleton<EfemEntity>.Instance.EfemDevice.IsMaintenanceMode || !Singleton<EfemEntity>.Instance.IsOnlineMode)//?
  649. {
  650. reason = "NOFUNC";
  651. return false;
  652. }
  653. return true;
  654. }
  655. }
  656. }