SrdCommonDevice.cs 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963
  1. using Aitex.Core.RT.DataCenter;
  2. using Aitex.Core.RT.Device;
  3. using Aitex.Core.RT.Event;
  4. using Aitex.Core.RT.Log;
  5. using Aitex.Core.RT.OperationCenter;
  6. using Aitex.Core.RT.Routine;
  7. using Aitex.Core.RT.SCCore;
  8. using Aitex.Core.Util;
  9. using MECF.Framework.Common.Beckhoff.ModuleIO;
  10. using MECF.Framework.Common.CommonData.SRD;
  11. using MECF.Framework.Common.Persistent.Prewet;
  12. using MECF.Framework.Common.Persistent.SRD;
  13. using MECF.Framework.Common.TwinCat;
  14. using CyberX8_Core;
  15. using System.Reflection;
  16. using CyberX8_RT.Modules.Rinse;
  17. using CyberX8_RT.Modules;
  18. using CyberX8_RT.Modules.SRD;
  19. using CyberX8_RT.Devices.AXIS;
  20. using MECF.Framework.Common.Persistent.Rinse;
  21. using System.Security.Principal;
  22. using MECF.Framework.Common.IOCore;
  23. using Aitex.Core.Common;
  24. namespace CyberX8_RT.Devices.SRD
  25. {
  26. public class SrdCommonDevice : BaseDevice, IDevice
  27. {
  28. /// <summary>
  29. /// Srd操作枚举
  30. /// </summary>
  31. private enum SrdCommonOperation
  32. {
  33. None,
  34. DoorClose,
  35. DoorOpen,
  36. ChuckVacuumOn,
  37. ChuckVacuumOff,
  38. LiftUpOn,
  39. LiftUpOff,
  40. FlippersIn,
  41. FlippersOut,
  42. ChuckATMClick
  43. }
  44. #region 常量
  45. private const string FLUID_CONTAINMENT = "FluidContainment";
  46. private const string VACUUM_VALUE = "VacuumValue";
  47. private const string WAFER_PRESENCE = "WaferPresence";
  48. private const string WAFER_PRESENCE_STATUS = "WaferPresenceStatus";
  49. private const string WATER_PRESSURE = "WaterPressure";
  50. private const string DOOR_CLOSE="DoorClose";
  51. private const string DOOR_CLOSED = "DoorClosed";
  52. private const string DOOR_OPENED = "DoorOpened";
  53. private const string WATER_ABOVE="WaterAbove";
  54. private const string WATER_BELOW = "WaterBelow";
  55. private const string CHUCK_VACUUM="ChuckVacuum";
  56. private const string EXHAUST_ON="ExhaustOn";
  57. private const string COMMON_DATA = "CommonData";
  58. private const string PERSISTENT_VALUE= "PersistentValue";
  59. private const string CHUCK_ATM_ON = "ChuckATMOn";
  60. private const string CHUCK_VACUUM_OK = "ChuckVacuumOK";
  61. private const string WAFER_PRESENT = "WaferPresent";
  62. private const string LIFT_UP = "LiftUp";
  63. private const string LIFT_UP_STATUS = "LiftUpStatus";
  64. private const string FLIPPER1_OUT_100_STATUS = "Flipper1Out100Status";
  65. private const string FLIPPER2_OUT_100_STATUS = "Flipper2Out100Status";
  66. private const string FLIPPER3_OUT_100_STATUS = "Flipper3Out100Status";
  67. private const string FLIPPER1_OUT_150_STATUS = "Flipper1Out150Status";
  68. private const string FLIPPER2_OUT_150_STATUS = "Flipper2Out150Status";
  69. private const string FLIPPER3_OUT_150_STATUS = "Flipper3Out150Status";
  70. private const string FLIPPER1_OUT_200_STATUS = "Flipper1Out200Status";
  71. private const string FLIPPER2_OUT_200_STATUS = "Flipper2Out200Status";
  72. private const string FLIPPER3_OUT_200_STATUS = "Flipper3Out200Status";
  73. private const string FLIPPERS_IN_100 = "FlippersIn100";
  74. private const string FLIPPERS_IN_150 = "FlippersIn150";
  75. private const string FLIPPERS_IN_200 = "FlippersIn200";
  76. private const string WATER_FLOW = "WaterFlow";
  77. private const string WATER_ON = "WaterOn";
  78. private const string N2_ON= "N2On";
  79. #endregion
  80. #region 内部变量
  81. /// <summary>
  82. /// Common数据
  83. /// </summary>
  84. private SrdCommonData _commonData = new SrdCommonData();
  85. /// <summary>
  86. /// 状态
  87. /// </summary>
  88. private RState _status;
  89. /// <summary>
  90. /// 当前操作
  91. /// </summary>
  92. private SrdCommonOperation _currentOperation;
  93. /// <summary>
  94. /// Wafer Presence
  95. /// </summary>
  96. private string _waferPresence;
  97. /// <summary>
  98. /// Persistent Value对象
  99. /// </summary>
  100. private SRDPersistentValue _srdPersistentValue;
  101. /// <summary>
  102. /// IsWaferPresence
  103. /// </summary>
  104. private bool _isWaferPresence = true;
  105. /// <summary>
  106. /// Total Device
  107. /// </summary>
  108. private TotalSRDDevice _totalSRDDevice;
  109. #region Routine
  110. /// <summary>
  111. /// Close Routine
  112. /// </summary>
  113. private SrdCommonDoorCloseRoutine _doorCloseRoutine;
  114. /// <summary>
  115. /// Vacuum Routine
  116. /// </summary>
  117. private SrdCommonChuckVacuumRoutine _chuckVacuumRoutine;
  118. /// <summary>
  119. /// Lift Up routine
  120. /// </summary>
  121. private SrdCommonLiftUpRoutine _liftUpRoutine;
  122. /// <summary>
  123. /// Flippers Routine
  124. /// </summary>
  125. private SrdCommonFlipperRoutine _flipperRoutine;
  126. /// <summary>
  127. /// Chuck ATM Click Routine
  128. /// </summary>
  129. private SrdCommonChuckATMRoutine _chuckATMRoutine;
  130. #endregion
  131. #endregion
  132. #region 属性
  133. /// <summary>
  134. /// Common数据
  135. /// </summary>
  136. public SrdCommonData CommonData
  137. {
  138. get { return _commonData; }
  139. }
  140. /// <summary>
  141. /// 状态
  142. /// </summary>
  143. public RState Status { get { return _status; } }
  144. /// <summary>
  145. /// Wafer Presence
  146. /// </summary>
  147. public string WaferPresence
  148. {
  149. get { return _waferPresence; }
  150. }
  151. /// <summary>
  152. /// IsWaferPresence
  153. /// </summary>
  154. public bool IsWaferPresence
  155. {
  156. get { return _isWaferPresence; }
  157. }
  158. #endregion
  159. /// <summary>
  160. /// 构造函数
  161. /// </summary>
  162. /// <param name="moduleName"></param>
  163. /// <param name="name"></param>
  164. public SrdCommonDevice(string moduleName) : base(moduleName, "Common", "Common", "Common")
  165. {
  166. }
  167. /// <summary>
  168. /// 初始化
  169. /// </summary>
  170. /// <returns></returns>
  171. public bool Initialize()
  172. {
  173. InitializeRoutine();
  174. SubscribeData();
  175. SubscribeValueAction();
  176. InitializeOperation();
  177. return true;
  178. }
  179. /// <summary>
  180. /// 初始化Routine
  181. /// </summary>
  182. private void InitializeRoutine()
  183. {
  184. _doorCloseRoutine = new SrdCommonDoorCloseRoutine(Module);
  185. _chuckVacuumRoutine = new SrdCommonChuckVacuumRoutine(Module);
  186. _liftUpRoutine = new SrdCommonLiftUpRoutine(Module);
  187. _flipperRoutine = new SrdCommonFlipperRoutine(Module);
  188. _chuckATMRoutine = new SrdCommonChuckATMRoutine(Module);
  189. }
  190. /// <summary>
  191. /// 订阅数据
  192. /// </summary>
  193. private void SubscribeData()
  194. {
  195. _srdPersistentValue = SRDPersistentManager.Instance.GetModulePersistentValue(Module);
  196. if(_srdPersistentValue==null)
  197. {
  198. LOG.WriteLog(eEvent.ERR_SRD, Module, "Persistent Value Object is not exist");
  199. }
  200. DATA.Subscribe($"{Module}.{PERSISTENT_VALUE}", () => _srdPersistentValue, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  201. DATA.Subscribe($"{Module}.{COMMON_DATA}", () => _commonData, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  202. DATA.Subscribe($"{Module}.{WAFER_PRESENCE_STATUS}", () => _waferPresence, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  203. DATA.Subscribe($"{Module}.IsWaferPresence", () => IsWaferPresence, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  204. }
  205. /// <summary>
  206. /// 订阅变量数值发生变化
  207. /// </summary>
  208. private void SubscribeValueAction()
  209. {
  210. IOModuleManager.Instance.SubscribeModuleVariable(Module, VACUUM_VALUE, UpdateVariableValue);
  211. IOModuleManager.Instance.SubscribeModuleVariable(Module, WAFER_PRESENCE, UpdateVariableValue);
  212. IOModuleManager.Instance.SubscribeModuleVariable(Module, DOOR_CLOSE, UpdateVariableValue);
  213. IOModuleManager.Instance.SubscribeModuleVariable(Module, DOOR_CLOSED, UpdateVariableValue);
  214. IOModuleManager.Instance.SubscribeModuleVariable(Module, DOOR_OPENED, UpdateVariableValue);
  215. IOModuleManager.Instance.SubscribeModuleVariable(Module, WATER_ABOVE, UpdateVariableValue);
  216. IOModuleManager.Instance.SubscribeModuleVariable(Module, WATER_BELOW, UpdateVariableValue);
  217. IOModuleManager.Instance.SubscribeModuleVariable(Module, CHUCK_VACUUM, UpdateVariableValue);
  218. IOModuleManager.Instance.SubscribeModuleVariable(Module, EXHAUST_ON, UpdateVariableValue);
  219. IOModuleManager.Instance.SubscribeModuleVariable(Module, CHUCK_ATM_ON, UpdateVariableValue);
  220. IOModuleManager.Instance.SubscribeModuleVariable(Module, CHUCK_VACUUM_OK, UpdateVariableValue);
  221. IOModuleManager.Instance.SubscribeModuleVariable(Module, WAFER_PRESENT, UpdateVariableValue);
  222. IOModuleManager.Instance.SubscribeModuleVariable(Module, LIFT_UP, UpdateVariableValue);
  223. IOModuleManager.Instance.SubscribeModuleVariable(Module, LIFT_UP_STATUS, UpdateVariableValue);
  224. IOModuleManager.Instance.SubscribeModuleVariable(Module, FLIPPER1_OUT_100_STATUS, UpdateVariableValue);
  225. IOModuleManager.Instance.SubscribeModuleVariable(Module, FLIPPER2_OUT_100_STATUS, UpdateVariableValue);
  226. IOModuleManager.Instance.SubscribeModuleVariable(Module, FLIPPER3_OUT_100_STATUS, UpdateVariableValue);
  227. IOModuleManager.Instance.SubscribeModuleVariable(Module, FLIPPER1_OUT_150_STATUS, UpdateVariableValue);
  228. IOModuleManager.Instance.SubscribeModuleVariable(Module, FLIPPER2_OUT_150_STATUS, UpdateVariableValue);
  229. IOModuleManager.Instance.SubscribeModuleVariable(Module, FLIPPER3_OUT_150_STATUS, UpdateVariableValue);
  230. IOModuleManager.Instance.SubscribeModuleVariable(Module, FLIPPER1_OUT_200_STATUS, UpdateVariableValue);
  231. IOModuleManager.Instance.SubscribeModuleVariable(Module, FLIPPER2_OUT_200_STATUS, UpdateVariableValue);
  232. IOModuleManager.Instance.SubscribeModuleVariable(Module, FLIPPER3_OUT_200_STATUS, UpdateVariableValue);
  233. IOModuleManager.Instance.SubscribeModuleVariable(Module, FLIPPERS_IN_100, UpdateVariableValue);
  234. IOModuleManager.Instance.SubscribeModuleVariable(Module, FLIPPERS_IN_150, UpdateVariableValue);
  235. IOModuleManager.Instance.SubscribeModuleVariable(Module, FLIPPERS_IN_200, UpdateVariableValue);
  236. IOModuleManager.Instance.SubscribeModuleVariable(Module, WATER_FLOW, UpdateVariableValue);
  237. IOModuleManager.Instance.SubscribeModuleVariable(Module, N2_ON, UpdateVariableValue);
  238. IOModuleManager.Instance.SubscribeModuleVariable(Module, WATER_ON, UpdateVariableValue);
  239. }
  240. /// <summary>
  241. /// 初始化操作
  242. /// </summary>
  243. private void InitializeOperation()
  244. {
  245. OP.Subscribe($"{Module}.{Name}.DoorClose", DoorCloseAction);
  246. OP.Subscribe($"{Module}.{Name}.DoorOpen", DoorOpenAction);
  247. OP.Subscribe($"{Module}.{Name}.WaterOn", WaterOnAction);
  248. OP.Subscribe($"{Module}.{Name}.WaterOff", WaterOffAction);
  249. OP.Subscribe($"{Module}.{Name}.ChuckVacuumOn", ChuckVacuumOnAction);
  250. OP.Subscribe($"{Module}.{Name}.ChuckVacuumOff", ChuckVacuumOffAction);
  251. OP.Subscribe($"{Module}.{Name}.N2On", N2OnAction);
  252. OP.Subscribe($"{Module}.{Name}.N2Off", N2OffAction);
  253. OP.Subscribe($"{Module}.{Name}.LiftUpOn", LiftUpOnAction);
  254. OP.Subscribe($"{Module}.{Name}.LiftUpOff", LiftUpOffAction);
  255. OP.Subscribe($"{Module}.{Name}.ChuckATMOn", ChuckATMOnAction);
  256. OP.Subscribe($"{Module}.{Name}.ChuckATMOff", ChuckATMOffAction);
  257. OP.Subscribe($"{Module}.{Name}.FlipperIn", FlipperInAction);
  258. OP.Subscribe($"{Module}.{Name}.FlipperOut", FlipperOutAction);
  259. OP.Subscribe($"{Module}.KeyDown", KeyDownAction);
  260. OP.Subscribe($"{Module}.DisabledAction", DisabledOperation);
  261. OP.Subscribe($"{Module}.ManualAction", ManualOperation);
  262. OP.Subscribe($"{Module}.AutoAction", AutoOperation);
  263. OP.Subscribe($"{Module}.EngineeringModeAction", EngineeringModeOperation);
  264. OP.Subscribe($"{Module}.ProductionModeAction", ProductionModeOperation);
  265. OP.Subscribe($"{Module}.UpdateIsWaferPresenceAction", UpdateIsWaferPresenceAction);
  266. }
  267. /// 更新变量数值
  268. /// </summary>
  269. /// <param name="variable"></param>
  270. /// <param name="value"></param>
  271. private void UpdateVariableValue(string variable, object value)
  272. {
  273. if(!CommonData.IsDataInitialized)
  274. {
  275. CommonData.IsDataInitialized = true;
  276. }
  277. PropertyInfo property = CommonData.GetType().GetProperty(variable);
  278. if (property != null)
  279. {
  280. property.SetValue(CommonData, value);
  281. }
  282. UpdateWaferPresence(variable, value);
  283. }
  284. /// <summary>
  285. /// 更新Wafer Presence
  286. /// </summary>
  287. private void UpdateWaferPresence(string variable,object value)
  288. {
  289. if (variable == WAFER_PRESENCE&&value is double)
  290. {
  291. UpdateWaferPresence((double)value);
  292. }
  293. }
  294. /// <summary>
  295. /// 更新Wafer Presence
  296. /// </summary>
  297. /// <param name="waferPresence"></param>
  298. private void UpdateWaferPresence(double waferPresence)
  299. {
  300. if (_srdPersistentValue != null)
  301. {
  302. if (waferPresence > _srdPersistentValue.EmptyThreshold)
  303. {
  304. _waferPresence = "Empty";
  305. }
  306. else if (waferPresence >= _srdPersistentValue.WellPlacedHighThreshold && waferPresence <= _srdPersistentValue.EmptyThreshold)
  307. {
  308. _waferPresence = "PoorlyPlaced";
  309. }
  310. else if (waferPresence < _srdPersistentValue.WellPlacedLowThreshold)
  311. {
  312. _waferPresence = "PoorlyPlaced";
  313. }
  314. else
  315. {
  316. _waferPresence = "WellPlaced";
  317. }
  318. }
  319. }
  320. #region Operation
  321. #region OperationStatus
  322. /// <summary>
  323. /// DisabledAction
  324. /// </summary>
  325. /// <param name="cmd"></param>
  326. /// <param name="param"></param>
  327. /// <returns></returns>
  328. private bool DisabledOperation(string cmd, object[] args)
  329. {
  330. string currentOperation = "Disabled";
  331. SRDEntity srdEntity = Singleton<RouteManager>.Instance.GetModule<SRDEntity>(Module);
  332. if (srdEntity == null || _srdPersistentValue == null) return false;
  333. if (_srdPersistentValue.OperatingMode != "Disabled") srdEntity.EnterInit();
  334. SRDPersistentManager.Instance.UpdateOperationModeValue(Module,currentOperation);
  335. return true;
  336. }
  337. /// <summary>
  338. /// ManualAction
  339. /// </summary>
  340. /// <param name="cmd"></param>
  341. /// <param name="param"></param>
  342. /// <returns></returns>
  343. private bool ManualOperation(string cmd, object[] args)
  344. {
  345. string currentOperation = "Manual";
  346. SRDEntity srdEntity = Singleton<RouteManager>.Instance.GetModule<SRDEntity>(Module);
  347. if (srdEntity == null || _srdPersistentValue == null) return false;
  348. if (_srdPersistentValue.OperatingMode == "Auto" && srdEntity.IsBusy)
  349. {
  350. LOG.WriteLog(eEvent.ERR_SRD, Module, $"{Module} is Busy, can't change to manual mode");
  351. return false;
  352. }
  353. if (_srdPersistentValue.OperatingMode != "Manual") srdEntity.EnterInit();
  354. SRDPersistentManager.Instance.UpdateOperationModeValue(Module,currentOperation);
  355. return true;
  356. }
  357. /// <summary>
  358. /// AutoAction
  359. /// </summary>
  360. /// <param name="cmd"></param>
  361. /// <param name="param"></param>
  362. /// <returns></returns>
  363. private bool AutoOperation(string cmd, object[] args)
  364. {
  365. string currentOperation = "Auto";
  366. SRDEntity srdEntity = Singleton<RouteManager>.Instance.GetModule<SRDEntity>(Module);
  367. if (srdEntity == null || _srdPersistentValue == null) return false;
  368. if (_srdPersistentValue.OperatingMode != "Auto") srdEntity.EnterInit();
  369. SRDPersistentManager.Instance.UpdateOperationModeValue(Module,currentOperation);
  370. return true;
  371. }
  372. /// <summary>
  373. /// EngineeringModeAction
  374. /// </summary>
  375. /// <param name="cmd"></param>
  376. /// <param name="param"></param>
  377. /// <returns></returns>
  378. private bool EngineeringModeOperation(string cmd, object[] args)
  379. {
  380. string currentRecipeOperation = "Engineering";
  381. SRDPersistentManager.Instance.UpdateRecipeOperationModeValue(Module, currentRecipeOperation);
  382. return true;
  383. }
  384. /// <summary>
  385. /// ProductionAction
  386. /// </summary>
  387. /// <param name="cmd"></param>
  388. /// <param name="param"></param>
  389. /// <returns></returns>
  390. private bool ProductionModeOperation(string cmd, object[] args)
  391. {
  392. string currentRecipeOperation = "Production";
  393. SRDPersistentManager.Instance.UpdateRecipeOperationModeValue(Module, currentRecipeOperation);
  394. return true;
  395. }
  396. #endregion
  397. #region keydown
  398. private bool KeyDownAction(string cmd, object[] args)
  399. {
  400. string variableName = args[0].ToString();
  401. PropertyInfo property = _srdPersistentValue.GetType().GetProperty(variableName);
  402. if(property!=null)
  403. {
  404. property.SetValue(_srdPersistentValue, args[1]);
  405. }
  406. SRDPersistentManager.Instance.UpdateModulePersistentValue(Module);
  407. UpdateWaferPresence(CommonData.WaferPresence);
  408. return true;
  409. }
  410. #endregion
  411. #region Door
  412. /// <summary>
  413. /// Door Close操作
  414. /// </summary>
  415. public bool DoorCloseAction(string cmd, object[] args)
  416. {
  417. if (!JudgeRunningState(SrdCommonOperation.DoorClose))
  418. {
  419. _currentOperation = SrdCommonOperation.DoorClose;
  420. _status = _doorCloseRoutine.Start(true);
  421. return _status==RState.Running;
  422. }
  423. else
  424. {
  425. return false;
  426. }
  427. }
  428. /// <summary>
  429. /// Door Open操作
  430. /// </summary>
  431. public bool DoorOpenAction(string cmd, object[] args)
  432. {
  433. if (!JudgeRunningState(SrdCommonOperation.DoorOpen))
  434. {
  435. _currentOperation = SrdCommonOperation.DoorOpen;
  436. _status = _doorCloseRoutine.Start(false);
  437. return _status==RState.Running;
  438. }
  439. else
  440. {
  441. return false;
  442. }
  443. }
  444. #endregion
  445. #region N2 On
  446. /// <summary>
  447. /// N2 On
  448. /// </summary>
  449. /// <param name="cmd"></param>
  450. /// <param name="args"></param>
  451. /// <returns></returns>
  452. public bool N2OnAction(string cmd, object[] args)
  453. {
  454. return N2On();
  455. }
  456. /// <summary>
  457. /// N2 Off
  458. /// </summary>
  459. /// <param name="cmd"></param>
  460. /// <param name="args"></param>
  461. /// <returns></returns>
  462. public bool N2OffAction(string cmd, object[] args)
  463. {
  464. return N2Off();
  465. }
  466. /// <summary>
  467. /// Exhaust On(不确认信号)
  468. /// </summary>
  469. /// <returns></returns>
  470. public bool N2On()
  471. {
  472. string ioName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{N2_ON}");
  473. return IOModuleManager.Instance.WriteIoValue(ioName, true);
  474. }
  475. /// <summary>
  476. /// Exhaust On(不确认信号)
  477. /// </summary>
  478. /// <returns></returns>
  479. public bool N2Off()
  480. {
  481. string ioName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{N2_ON}");
  482. return IOModuleManager.Instance.WriteIoValue(ioName, false);
  483. }
  484. #endregion
  485. #region Flipper
  486. /// <summary>
  487. /// FlipperIn
  488. /// </summary>
  489. /// <param name="cmd"></param>
  490. /// <param name="args"></param>
  491. /// <returns></returns>
  492. public bool FlipperInAction(string cmd, object[] args)
  493. {
  494. int waferSize = (int)args[0];
  495. if (!JudgeRunningState(SrdCommonOperation.FlippersIn))
  496. {
  497. _currentOperation = SrdCommonOperation.FlippersIn;
  498. _status = _flipperRoutine.Start(true, waferSize);
  499. return _status == RState.Running;
  500. }
  501. else
  502. {
  503. return false;
  504. }
  505. }
  506. /// <summary>
  507. /// FlipperOut
  508. /// </summary>
  509. /// <param name="cmd"></param>
  510. /// <param name="args"></param>
  511. /// <returns></returns>
  512. public bool FlipperOutAction(string cmd, object[] args)
  513. {
  514. int waferSize = (int)args[0];
  515. if (!JudgeRunningState(SrdCommonOperation.FlippersOut))
  516. {
  517. _currentOperation = SrdCommonOperation.FlippersOut;
  518. _status = _flipperRoutine.Start(false, waferSize);
  519. return _status == RState.Running;
  520. }
  521. else
  522. {
  523. return false;
  524. }
  525. }
  526. #endregion
  527. #region Water
  528. /// <summary>
  529. /// Water On操作
  530. /// </summary>
  531. public bool WaterOnAction(string cmd, object[] args)
  532. {
  533. return WaterOn();
  534. }
  535. /// <summary>
  536. /// water Off操作
  537. /// </summary>
  538. public bool WaterOffAction(string cmd, object[] args)
  539. {
  540. return WaterOff();
  541. }
  542. /// <summary>
  543. /// Water On(不确认信号)
  544. /// </summary>
  545. /// <returns></returns>
  546. public bool WaterOn()
  547. {
  548. string ioName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{WATER_ON}");
  549. return IOModuleManager.Instance.WriteIoValue(ioName, true);
  550. }
  551. /// <summary>
  552. /// Water Off(不确认信号)
  553. /// </summary>
  554. /// <returns></returns>
  555. public bool WaterOff()
  556. {
  557. string ioName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{WATER_ON}");
  558. return IOModuleManager.Instance.WriteIoValue(ioName, false);
  559. }
  560. #endregion
  561. #region Chuck Vacuum
  562. /// <summary>
  563. /// Chuck Vacuum操作
  564. /// </summary>
  565. public bool ChuckVacuumOnAction(string cmd, object[] args)
  566. {
  567. if (!JudgeRunningState(SrdCommonOperation.ChuckVacuumOn))
  568. {
  569. _currentOperation = SrdCommonOperation.ChuckVacuumOn;
  570. _status = _chuckVacuumRoutine.Start(false);
  571. return _status==RState.Running;
  572. }
  573. else
  574. {
  575. return false;
  576. }
  577. }
  578. /// <summary>
  579. /// chuck Vacuum Off操作
  580. /// </summary>
  581. public bool ChuckVacuumOffAction(string cmd, object[] args)
  582. {
  583. if (!JudgeRunningState(SrdCommonOperation.ChuckVacuumOff))
  584. {
  585. _currentOperation = SrdCommonOperation.ChuckVacuumOff;
  586. _status= _chuckVacuumRoutine.Start(true);
  587. return _status==RState.Running;
  588. }
  589. else
  590. {
  591. return false;
  592. }
  593. }
  594. #endregion
  595. #region LiftUp
  596. /// <summary>
  597. /// Lift Up On
  598. /// </summary>
  599. /// <param name="cmd"></param>
  600. /// <param name="args"></param>
  601. /// <returns></returns>
  602. public bool LiftUpOnAction(string cmd, object[] args)
  603. {
  604. if (!JudgeRunningState(SrdCommonOperation.LiftUpOn))
  605. {
  606. _currentOperation = SrdCommonOperation.LiftUpOn;
  607. _status = _liftUpRoutine.Start(true);
  608. return _status == RState.Running;
  609. }
  610. else
  611. {
  612. return false;
  613. }
  614. }
  615. /// <summary>
  616. /// Lift Up Off
  617. /// </summary>
  618. /// <param name="cmd"></param>
  619. /// <param name="args"></param>
  620. /// <returns></returns>
  621. public bool LiftUpOffAction(string cmd, object[] args)
  622. {
  623. if (!JudgeRunningState(SrdCommonOperation.LiftUpOff))
  624. {
  625. _currentOperation = SrdCommonOperation.LiftUpOff;
  626. _status = _liftUpRoutine.Start(false);
  627. return _status == RState.Running;
  628. }
  629. else
  630. {
  631. return false;
  632. }
  633. }
  634. #endregion
  635. #region ChuckATM
  636. /// <summary>
  637. /// Chuck ATM On
  638. /// </summary>
  639. /// <param name="cmd"></param>
  640. /// <param name="args"></param>
  641. /// <returns></returns>
  642. public bool ChuckATMOnAction(string cmd, object[] args)
  643. {
  644. return ChuckATM(true);
  645. }
  646. /// <summary>
  647. /// Chuck ATM Off
  648. /// </summary>
  649. /// <param name="cmd"></param>
  650. /// <param name="args"></param>
  651. /// <returns></returns>
  652. public bool ChuckATMOffAction(string cmd, object[] args)
  653. {
  654. return ChuckATM(false);
  655. }
  656. private bool ChuckATM(bool value)
  657. {
  658. string ioName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{CHUCK_ATM_ON}");
  659. return IOModuleManager.Instance.WriteIoValue(ioName, value);
  660. }
  661. /// <summary>
  662. /// Chuck ATM Routine
  663. /// </summary>
  664. /// <param name="cmd"></param>
  665. /// <param name="args"></param>
  666. /// <returns></returns>
  667. public bool ChuckATMAction(string cmd, object[] args)
  668. {
  669. if (!JudgeRunningState(SrdCommonOperation.ChuckATMClick))
  670. {
  671. _currentOperation = SrdCommonOperation.ChuckATMClick;
  672. _status = _chuckATMRoutine.Start();
  673. return _status == RState.Running;
  674. }
  675. else
  676. {
  677. return false;
  678. }
  679. }
  680. #endregion
  681. #region Water Above
  682. /// <summary>
  683. /// Water Above On操作
  684. /// </summary>
  685. public bool WaterAboveOnAction(string cmd, object[] args)
  686. {
  687. return WaterAboveOn();
  688. }
  689. /// <summary>
  690. /// water above Off操作
  691. /// </summary>
  692. public bool WaterAboveOffAction(string cmd, object[] args)
  693. {
  694. return WaterAboveOff();
  695. }
  696. /// <summary>
  697. /// Water Above On(不确认信号)
  698. /// </summary>
  699. /// <returns></returns>
  700. public bool WaterAboveOn()
  701. {
  702. string ioName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{WATER_ABOVE}");
  703. return IOModuleManager.Instance.WriteIoValue(ioName, true);
  704. }
  705. /// <summary>
  706. /// Water Above Off(不确认信号)
  707. /// </summary>
  708. /// <returns></returns>
  709. public bool WaterAboveOff()
  710. {
  711. string ioName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{WATER_ABOVE}");
  712. return IOModuleManager.Instance.WriteIoValue(ioName, false);
  713. }
  714. #endregion
  715. #region Water Below
  716. /// <summary>
  717. /// Water Below On操作
  718. /// </summary>
  719. public bool WaterBelowOnAction(string cmd, object[] args)
  720. {
  721. return WaterBelowOn();
  722. }
  723. /// <summary>
  724. /// water Below Off操作
  725. /// </summary>
  726. public bool WaterBelowOffAction(string cmd, object[] args)
  727. {
  728. return WaterBelowOff();
  729. }
  730. /// <summary>
  731. /// Water Below On(不确认信号)
  732. /// </summary>
  733. /// <returns></returns>
  734. public bool WaterBelowOn()
  735. {
  736. string ioName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{WATER_BELOW}");
  737. return IOModuleManager.Instance.WriteIoValue(ioName, true);
  738. }
  739. /// <summary>
  740. /// Water Below Off(不确认信号)
  741. /// </summary>
  742. /// <returns></returns>
  743. public bool WaterBelowOff()
  744. {
  745. string ioName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{WATER_BELOW}");
  746. return IOModuleManager.Instance.WriteIoValue(ioName, false);
  747. }
  748. #endregion
  749. /// <summary>
  750. /// Update IsWaferPresence 标志位
  751. /// </summary>
  752. /// <param name="cmd"></param>
  753. /// <param name="args"></param>
  754. /// <returns></returns>
  755. public bool UpdateIsWaferPresenceAction(string cmd, object[] args)
  756. {
  757. _isWaferPresence = (bool)args[0];
  758. return true;
  759. }
  760. /// <summary>
  761. /// 判定运行状态
  762. /// </summary>
  763. /// <returns></returns>
  764. private bool JudgeRunningState(SrdCommonOperation operation)
  765. {
  766. if (_status == RState.Running)
  767. {
  768. EV.PostAlarmLog($"{Module}", eEvent.ERR_SRD, $"{Module} current execute {_currentOperation},cannot {operation}");
  769. return true;
  770. }
  771. return false;
  772. }
  773. /// <summary>
  774. /// ErrorOperation
  775. /// </summary>
  776. public void EnterErrorOperation()
  777. {
  778. //关闭风扇
  779. if (CommonData.N2On)
  780. {
  781. bool result = N2OffAction("", null);
  782. if (!result)
  783. {
  784. LOG.WriteLog(eEvent.ERR_SRD, Module, "EnterError: N2 Off is failed");
  785. }
  786. }
  787. //关闭WaterAbove
  788. if (CommonData.WaterOn)
  789. {
  790. bool result = WaterOff();
  791. if (!result)
  792. {
  793. LOG.WriteLog(eEvent.INFO_SRD, Module, "EnterError: Water Off is failed");
  794. }
  795. }
  796. //停电机
  797. JetAxisBase _rotationAxis = DEVICE.GetDevice<JetAxisBase>($"{Module}.Rotation");
  798. if (_rotationAxis != null && _rotationAxis.IsRun) _rotationAxis.StopPositionOperation();
  799. }
  800. #endregion
  801. /// <summary>
  802. /// Rotation InterLock
  803. /// </summary>
  804. /// <returns></returns>
  805. public bool RotationInterLock()
  806. {
  807. if (!CommonData.DoorClosed)
  808. {
  809. LOG.WriteLog(eEvent.ERR_SRD, Module, "Door is not closed. Rotation can not position");
  810. return false;
  811. }
  812. //Check Flippers
  813. if (CommonData.FlippersIn150 || CommonData.FlippersIn200) //|| _srdCommon.CommonData.FlippersIn100
  814. {
  815. LOG.WriteLog(eEvent.ERR_SRD, Module, "FlippersIn is on. Rotation can not position");
  816. return false;
  817. }
  818. if (!CommonData.Flipper1Out150Status || !CommonData.Flipper2Out150Status || !CommonData.Flipper3Out150Status
  819. || !CommonData.Flipper1Out200Status || !CommonData.Flipper2Out200Status || !CommonData.Flipper3Out200Status)
  820. //|| !_srdCommon.CommonData.Flipper1Out100Status || !_srdCommon.CommonData.Flipper2Out100Status || !_srdCommon.CommonData.Flipper3Out100Status
  821. {
  822. LOG.WriteLog(eEvent.ERR_SRD, Module, "Flippers are at In position. Rotation can not position");
  823. return false;
  824. }
  825. return true;
  826. }
  827. /// <summary>
  828. /// 定时器
  829. /// </summary>
  830. /// <returns></returns>
  831. public bool OnTimer()
  832. {
  833. if (_status == RState.Running)
  834. {
  835. if (_currentOperation != SrdCommonOperation.None)
  836. {
  837. IRoutine routine = GetCurrentRoutine(_currentOperation);
  838. if (routine != null)
  839. {
  840. CheckRoutineState(routine, _currentOperation);
  841. }
  842. else
  843. {
  844. EndOperation();
  845. }
  846. }
  847. }
  848. //将公有的数据赋值于对象的数值
  849. if (_totalSRDDevice == null)
  850. {
  851. _totalSRDDevice = DEVICE.GetDevice<TotalSRDDevice>("SRD");
  852. }
  853. if (_totalSRDDevice != null)
  854. {
  855. CommonData.FluidContainment = _totalSRDDevice.FluidContainment;
  856. CommonData.WaterPressure = _totalSRDDevice.WaterPressure;
  857. }
  858. return true;
  859. }
  860. /// <summary>
  861. /// 获取当前操作对应的Routine
  862. /// </summary>
  863. /// <param name="currentOperation"></param>
  864. /// <returns></returns>
  865. private IRoutine GetCurrentRoutine(SrdCommonOperation currentOperation)
  866. {
  867. switch (currentOperation)
  868. {
  869. case SrdCommonOperation.DoorClose:
  870. case SrdCommonOperation.DoorOpen:
  871. return _doorCloseRoutine;
  872. case SrdCommonOperation.ChuckVacuumOn:
  873. case SrdCommonOperation.ChuckVacuumOff:
  874. return _chuckVacuumRoutine;
  875. case SrdCommonOperation.LiftUpOn:
  876. case SrdCommonOperation.LiftUpOff:
  877. return _liftUpRoutine;
  878. case SrdCommonOperation.FlippersIn:
  879. case SrdCommonOperation.FlippersOut:
  880. return _flipperRoutine;
  881. case SrdCommonOperation.ChuckATMClick:
  882. return _chuckATMRoutine;
  883. default:
  884. return null;
  885. }
  886. }
  887. /// <summary>
  888. /// 检验Routine状态
  889. /// </summary>
  890. /// <param name="routine"></param>
  891. /// <param name="currentOperation"></param>
  892. private void CheckRoutineState(IRoutine routine, SrdCommonOperation currentOperation)
  893. {
  894. RState state = routine.Monitor();
  895. if (state == RState.End)
  896. {
  897. EndOperation();
  898. }
  899. else if (state == RState.Failed || state == RState.Timeout)
  900. {
  901. LOG.WriteLog(eEvent.ERR_SRD, $"{Module}", $"{currentOperation} error");
  902. EndOperation();
  903. }
  904. }
  905. /// <summary>
  906. /// 结束操作
  907. /// </summary>
  908. private void EndOperation()
  909. {
  910. _status = RState.End;
  911. _currentOperation = SrdCommonOperation.None;
  912. }
  913. #region 设备接口
  914. /// <summary>
  915. /// 监控
  916. /// </summary>
  917. public void Monitor()
  918. {
  919. }
  920. public void Reset()
  921. {
  922. }
  923. public void Terminate()
  924. {
  925. }
  926. #endregion
  927. }
  928. }