CANPolicy.cs 21 KB

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