RinseDevice.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510
  1. using Aitex.Core.RT.DataCenter;
  2. using Aitex.Core.RT.Device;
  3. using Aitex.Core.RT.Log;
  4. using Aitex.Core.RT.OperationCenter;
  5. using Aitex.Core.RT.Routine;
  6. using Aitex.Core.RT.SCCore;
  7. using Aitex.Core.Util;
  8. using MECF.Framework.Common.Algorithm;
  9. using MECF.Framework.Common.Beckhoff.ModuleIO;
  10. using MECF.Framework.Common.CommonData.Prewet;
  11. using MECF.Framework.Common.Device.ResistivityProbe;
  12. using MECF.Framework.Common.Device.Rinse;
  13. using MECF.Framework.Common.Persistent.Prewet;
  14. using MECF.Framework.Common.Persistent.Rinse;
  15. using MECF.Framework.Common.RecipeCenter;
  16. using MECF.Framework.Common.ToolLayout;
  17. using MECF.Framework.Common.TwinCat;
  18. using System.Collections.Generic;
  19. using System.Reflection;
  20. using CyberX8_RT.Modules;
  21. using CyberX8_RT.Modules.Rinse;
  22. using CyberX8_RT.Devices.Resistivity;
  23. using CyberX8_RT.Modules.Prewet;
  24. using MECF.Framework.Common.IOCore;
  25. namespace CyberX8_RT.Devices.Rinse
  26. {
  27. public class RinseDevice : BaseDevice, IDevice
  28. {
  29. private enum RinseOperation
  30. {
  31. None
  32. }
  33. #region 常量
  34. private const string WATER_LEVEL="WaterLevel";
  35. private const string WAFER_HOLDER_CLAMP="WaferHolderClamp";
  36. private const string N2_VALVE="N2Valve";
  37. private const string FILL_VALVE="FillValve";
  38. private const string DRAIN_VALVE="DrainValve";
  39. private const string WASTE_VALVE="WasteValve";
  40. private const string RESISTIVITY="Resistivity";
  41. private const string PERSISTENT_VALUE = "PersistentValue";
  42. private const string RINSEDATA = "RinseData";
  43. private const string RINSEITEM = "RinseItem";
  44. private const string RESISTIVITYVALUE = "Resistivity";
  45. #endregion
  46. #region 内部变量
  47. /// <summary>
  48. /// 数据
  49. /// </summary>
  50. private RinseData _rinseData = new RinseData();
  51. /// <summary>
  52. /// Rinse 持久性数值对象
  53. /// </summary>
  54. private RinsePersistentValue _rinsePersistentValue;
  55. /// <summary>
  56. /// 变量是否初始化字典
  57. /// </summary>
  58. private Dictionary<string, bool> _variableInitializeDic = new Dictionary<string, bool>();
  59. /// <summary>
  60. /// ByPass Inter Locks
  61. /// </summary>
  62. private bool _bypassInterLocks = false;
  63. /// <summary>
  64. /// RinseItem
  65. /// </summary>
  66. private RinseItem _rinseItem = new RinseItem();
  67. /// <summary>
  68. /// 工艺当前执行小步骤
  69. /// </summary>
  70. private string _currentStateMachine = "Init";
  71. /// <summary>
  72. /// 工艺当前执行大步骤
  73. /// </summary>
  74. private string _currentStatus = "Init";
  75. /// <summary>
  76. /// 水阻值
  77. /// </summary>
  78. private double _resistivityValue;
  79. /// <summary>
  80. /// 水阻计控制器
  81. /// </summary>
  82. private ResistivityController _resistivityController;
  83. #endregion
  84. #region 属性
  85. /// <summary>
  86. /// Rinse数据
  87. /// </summary>
  88. public RinseData RinseData { get { return _rinseData; } }
  89. /// <summary>
  90. /// 所有io变量是否初始化
  91. /// </summary>
  92. public bool IOInitialized { get { return AllIoVariableInitialized(); } }
  93. /// <summary>
  94. /// 所有io变量是否初始化
  95. /// </summary>
  96. public RinseItem RinseItem { get { return _rinseItem; } }
  97. /// <summary>
  98. /// 当前状态机
  99. /// </summary>
  100. public string CurrentStateMachine { get { return _currentStateMachine; } }
  101. #endregion
  102. /// <summary>
  103. /// 构造函数
  104. /// </summary>
  105. /// <param name="moduleName"></param>
  106. /// <param name="name"></param>
  107. public RinseDevice(string moduleName) : base(moduleName, moduleName, moduleName, moduleName)
  108. {
  109. }
  110. /// <summary>
  111. /// 初始化
  112. /// </summary>
  113. /// <returns></returns>
  114. public bool Initialize()
  115. {
  116. SubscribeData();
  117. SubscribeValueAction();
  118. InitializeOperation();
  119. return true;
  120. }
  121. /// <summary>
  122. /// 订阅数据
  123. /// </summary>
  124. private void SubscribeData()
  125. {
  126. _rinsePersistentValue = RinsePersistentManager.Instance.GetRinsePersistentValue(Module);
  127. if (_rinsePersistentValue == null)
  128. {
  129. LOG.WriteLog(eEvent.ERR_RINSE, Module, "Persistent Value Object is not exist");
  130. }
  131. _rinseItem = RinseItemManager.Instance.GetRinseItem(Module);
  132. _resistivityController = DEVICE.GetDevice<ResistivityController>(RinseItem.ResistivityID);
  133. DATA.Subscribe($"{Module}.{PERSISTENT_VALUE}", () => _rinsePersistentValue,SubscriptionAttribute.FLAG.IgnoreSaveDB);
  134. DATA.Subscribe($"{Module}.{RINSEDATA}", () => _rinseData, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  135. DATA.Subscribe($"{Module}.CurrentStateMachine", () => _currentStateMachine, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  136. DATA.Subscribe($"{Module}.CurrentStatus", () => _currentStatus, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  137. DATA.Subscribe($"{Module}.Resistivity.ID", () => _resistivityController?.Module, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  138. DATA.Subscribe($"{Module}.{RESISTIVITYVALUE}", () => {
  139. if (_resistivityController != null)
  140. {
  141. string value = _resistivityController.ResisitivityValue;
  142. if(double.TryParse(value, out _resistivityValue))
  143. {
  144. return _resistivityValue;
  145. }
  146. else
  147. {
  148. return 0;
  149. }
  150. }
  151. else
  152. {
  153. return 0;
  154. }
  155. }, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  156. DATA.Subscribe($"{Module}.WaterLevel", () => RinseData.WaterLevel, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  157. DATA.Subscribe($"{Module}.DIFillEnable",()=>RinseData.FillValve, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  158. DATA.Subscribe($"{Module}.DrainEnable", () => RinseData.DrainValve, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  159. DATA.Subscribe($"{Module}.N2Enable",()=>RinseData.N2Valve, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  160. DATA.Subscribe($"{Module}.WaferShuttleClamped",()=>RinseData.WaferHolderClamp, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  161. DATA.Subscribe($"{Module}.WasteEnable", () => RinseData.WasteValve, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  162. }
  163. /// <summary>
  164. /// 订阅变量数值发生变化
  165. /// </summary>
  166. private void SubscribeValueAction()
  167. {
  168. BeckhoffIoSubscribeUpdateVariable(WATER_LEVEL);
  169. BeckhoffIoSubscribeUpdateVariable(WASTE_VALVE);
  170. BeckhoffIoSubscribeUpdateVariable(WAFER_HOLDER_CLAMP);
  171. BeckhoffIoSubscribeUpdateVariable(N2_VALVE);
  172. BeckhoffIoSubscribeUpdateVariable(FILL_VALVE);
  173. BeckhoffIoSubscribeUpdateVariable(DRAIN_VALVE);
  174. }
  175. /// <summary>
  176. /// 初始化Operation
  177. /// </summary>
  178. private void InitializeOperation()
  179. {
  180. OP.Subscribe($"{Module}.ClampValveOn", (cmd, args) => { return WaferHolderClampValveOn(); });
  181. OP.Subscribe($"{Module}.ClampValveOff", (cmd, args) => { return WaferHolderClampValveOff(); });
  182. OP.Subscribe($"{Module}.N2ValveOn", (cmd, args) => { return N2ValveOn(); });
  183. OP.Subscribe($"{Module}.N2ValveOff", (cmd, args) => { return N2ValveOff(); });
  184. OP.Subscribe($"{Module}.FillValveOn", (cmd, args) => { return FillValveOn(); });
  185. OP.Subscribe($"{Module}.FillValveOff", (cmd, args) => { return FillValveOff(); });
  186. OP.Subscribe($"{Module}.DrainValveOn", (cmd, args) => { return DrainValveOn(); });
  187. OP.Subscribe($"{Module}.DrainValveOff", (cmd, args) => { return DrainValveOff(); });
  188. OP.Subscribe($"{Module}.WasteValveOn", (cmd, args) => { return WasteValveOff() ;});
  189. OP.Subscribe($"{Module}.WasteValveOff", (cmd, args) => { return WasteValveOn() ;});
  190. OP.Subscribe($"{Module}.ByPassInterLocks", (cms, args) => { _bypassInterLocks = (bool)(args[0]); return true; });
  191. OP.Subscribe($"{Module}.DisabledAction", DisabledOperation);
  192. OP.Subscribe($"{Module}.ManualAction", ManualOperation);
  193. OP.Subscribe($"{Module}.AutoAction", AutoOperation);
  194. OP.Subscribe($"{Module}.EngineeringModeAction", EngineeringModeOperation);
  195. OP.Subscribe($"{Module}.ProductionModeAction", ProductionModeOperation);
  196. }
  197. /// <summary>
  198. /// 订阅IO变量
  199. /// </summary>
  200. /// <param name="variable"></param>
  201. private void BeckhoffIoSubscribeUpdateVariable(string variable)
  202. {
  203. _variableInitializeDic[variable] = false;
  204. IOModuleManager.Instance.SubscribeModuleVariable(Module, variable, UpdateVariableValue);
  205. }
  206. /// <summary>
  207. /// 更新变量数值
  208. /// </summary>
  209. /// <param name="variable"></param>
  210. /// <param name="value"></param>
  211. private void UpdateVariableValue(string variable, object value)
  212. {
  213. if (!RinseData.IsDataInitialized)
  214. {
  215. RinseData.IsDataInitialized = true;
  216. }
  217. PropertyInfo property = RinseData.GetType().GetProperty(variable);
  218. if (property != null)
  219. {
  220. property.SetValue(RinseData, value);
  221. }
  222. if (_variableInitializeDic.ContainsKey(variable) && !_variableInitializeDic[variable])
  223. {
  224. _variableInitializeDic[variable] = true;
  225. }
  226. }
  227. /// <summary>
  228. /// 是否所有IO变量初始化完成
  229. /// </summary>
  230. /// <returns></returns>
  231. private bool AllIoVariableInitialized()
  232. {
  233. foreach (string item in _variableInitializeDic.Keys)
  234. {
  235. if (!_variableInitializeDic[item])
  236. {
  237. LOG.WriteLog(eEvent.ERR_DRYER, Module, $"{item} is not initialized");
  238. return false;
  239. }
  240. }
  241. return true;
  242. }
  243. #region Operation
  244. /// <summary>
  245. /// DisabledAction
  246. /// </summary>
  247. /// <param name="cmd"></param>
  248. /// <param name="param"></param>
  249. /// <returns></returns>
  250. private bool DisabledOperation(string cmd, object[] args)
  251. {
  252. string currentOperation = "Disabled";
  253. RinseEntity rinseEntity = Singleton<RouteManager>.Instance.GetModule<RinseEntity>(Module);
  254. if (rinseEntity != null && _rinsePersistentValue != null && _rinsePersistentValue.OperatingMode != currentOperation)
  255. {
  256. string preOperation = _rinsePersistentValue.OperatingMode;
  257. if (rinseEntity.IsBusy)
  258. {
  259. LOG.WriteLog(eEvent.ERR_RINSE, Module, $"{Module} is Busy, can't switch to Disabled mode");
  260. return false;
  261. }
  262. rinseEntity.EnterInit();
  263. _rinsePersistentValue.OperatingMode = currentOperation;
  264. LOG.WriteLog(eEvent.INFO_RINSE, Module, $"Operating mode is switched from {preOperation} to {currentOperation}");
  265. }
  266. RinsePersistentManager.Instance.UpdatePersistentValue(Module);
  267. return true;
  268. }
  269. /// <summary>
  270. /// ManualAction
  271. /// </summary>
  272. /// <param name="cmd"></param>
  273. /// <param name="param"></param>
  274. /// <returns></returns>
  275. private bool ManualOperation(string cmd, object[] args)
  276. {
  277. string currentOperation = "Manual";
  278. RinseEntity rinseEntity = Singleton<RouteManager>.Instance.GetModule<RinseEntity>(Module);
  279. if (rinseEntity != null && _rinsePersistentValue != null && _rinsePersistentValue.OperatingMode != currentOperation)
  280. {
  281. string preOperation = _rinsePersistentValue.OperatingMode;
  282. if (rinseEntity.IsBusy)
  283. {
  284. LOG.WriteLog(eEvent.ERR_RINSE, Module, $"{Module} is Busy, can't switch to Manual mode");
  285. return false;
  286. }
  287. rinseEntity.EnterInit();
  288. _rinsePersistentValue.OperatingMode = currentOperation;
  289. LOG.WriteLog(eEvent.INFO_RINSE, Module, $"Operating mode is switched from {preOperation} to {currentOperation}");
  290. }
  291. RinsePersistentManager.Instance.UpdatePersistentValue(Module);
  292. return true;
  293. }
  294. /// <summary>
  295. /// AutoAction
  296. /// </summary>
  297. /// <param name="cmd"></param>
  298. /// <param name="param"></param>
  299. /// <returns></returns>
  300. private bool AutoOperation(string cmd, object[] args)
  301. {
  302. string currentOperation = "Auto";
  303. RinseEntity rinseEntity = Singleton<RouteManager>.Instance.GetModule<RinseEntity>(Module);
  304. if (rinseEntity != null && _rinsePersistentValue != null && _rinsePersistentValue.OperatingMode != currentOperation)
  305. {
  306. string preOperation = _rinsePersistentValue.OperatingMode;
  307. if (rinseEntity.IsBusy)
  308. {
  309. LOG.WriteLog(eEvent.ERR_RINSE, Module, $"{Module} is Busy, can't switch to Auto mode");
  310. return false;
  311. }
  312. rinseEntity.EnterInit();
  313. _rinsePersistentValue.OperatingMode = currentOperation;
  314. LOG.WriteLog(eEvent.INFO_RINSE, Module, $"Operating mode is switched from {preOperation} to {currentOperation}");
  315. }
  316. RinsePersistentManager.Instance.UpdatePersistentValue(Module);
  317. return true;
  318. }
  319. /// <summary>
  320. /// EngineeringModeAction
  321. /// </summary>
  322. /// <param name="cmd"></param>
  323. /// <param name="param"></param>
  324. /// <returns></returns>
  325. private bool EngineeringModeOperation(string cmd, object[] args)
  326. {
  327. string currentRecipeOperation = "Engineering";
  328. _rinsePersistentValue.RecipeOperatingMode = currentRecipeOperation;
  329. RinsePersistentManager.Instance.UpdatePersistentValue(Module);
  330. return true;
  331. }
  332. /// <summary>
  333. /// ProductionAction
  334. /// </summary>
  335. /// <param name="cmd"></param>
  336. /// <param name="param"></param>
  337. /// <returns></returns>
  338. private bool ProductionModeOperation(string cmd, object[] args)
  339. {
  340. string currentRecipeOperation = "Production";
  341. _rinsePersistentValue.RecipeOperatingMode = currentRecipeOperation;
  342. RinsePersistentManager.Instance.UpdatePersistentValue(Module);
  343. return true;
  344. }
  345. #endregion
  346. /// <summary>
  347. /// 更新当前工艺小步骤
  348. /// </summary>
  349. /// <param name="tmp"></param>
  350. public void UpdateStateMachine(string tmp)
  351. {
  352. _currentStateMachine = tmp;
  353. }
  354. /// <summary>
  355. /// 更新当前工艺大步骤
  356. /// </summary>
  357. /// <param name="tmp"></param>
  358. public void UpdateStatus(string tmp)
  359. {
  360. _currentStatus = tmp;
  361. }
  362. #region Wafer Holder Clamp Valve
  363. /// <summary>
  364. /// Wafer Holder Clamp Valve On
  365. /// </summary>
  366. /// <returns></returns>
  367. public bool WaferHolderClampValveOn()
  368. {
  369. string ioName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{WAFER_HOLDER_CLAMP}");
  370. return IOModuleManager.Instance.WriteIoValue(ioName, true);
  371. }
  372. /// <summary>
  373. /// Wafer Holder Clamp Valve Off
  374. /// </summary>
  375. /// <returns></returns>
  376. public bool WaferHolderClampValveOff()
  377. {
  378. string ioName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{WAFER_HOLDER_CLAMP}");
  379. return IOModuleManager.Instance.WriteIoValue(ioName, false);
  380. }
  381. #endregion
  382. #region N2 Valve
  383. /// <summary>
  384. /// N2 Valve On
  385. /// </summary>
  386. /// <returns></returns>
  387. public bool N2ValveOn()
  388. {
  389. string ioName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{N2_VALVE}");
  390. return IOModuleManager.Instance.WriteIoValue(ioName, true);
  391. }
  392. /// <summary>
  393. /// N2 Valve Off
  394. /// </summary>
  395. /// <returns></returns>
  396. public bool N2ValveOff()
  397. {
  398. string ioName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{N2_VALVE}");
  399. return IOModuleManager.Instance.WriteIoValue(ioName, false);
  400. }
  401. #endregion
  402. #region Fill Valve
  403. /// <summary>
  404. /// Fill Valve On
  405. /// </summary>
  406. /// <returns></returns>
  407. public bool FillValveOn()
  408. {
  409. if(!_bypassInterLocks)
  410. {
  411. //Clamp Status必须为Clamped
  412. if(!_rinseData.WaferHolderClamp)
  413. {
  414. LOG.WriteLog(eEvent.ERR_RINSE, Module, "Clamp Status is not Clamped");
  415. return false;
  416. }
  417. }
  418. string ioName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{FILL_VALVE}");
  419. return IOModuleManager.Instance.WriteIoValue(ioName, true);
  420. }
  421. /// <summary>
  422. /// Fill Valve Off
  423. /// </summary>
  424. /// <returns></returns>
  425. public bool FillValveOff()
  426. {
  427. string ioName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{FILL_VALVE}");
  428. return IOModuleManager.Instance.WriteIoValue(ioName, false);
  429. }
  430. #endregion
  431. #region Drain Valve
  432. /// <summary>
  433. /// Drain Valve On
  434. /// </summary>
  435. /// <returns></returns>
  436. public bool DrainValveOn()
  437. {
  438. string ioName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{DRAIN_VALVE}");
  439. return IOModuleManager.Instance.WriteIoValue(ioName, true);
  440. }
  441. /// <summary>
  442. /// Drain Valve Off
  443. /// </summary>
  444. /// <returns></returns>
  445. public bool DrainValveOff()
  446. {
  447. string ioName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{DRAIN_VALVE}");
  448. return IOModuleManager.Instance.WriteIoValue(ioName, false);
  449. }
  450. #endregion
  451. #region Waste Valve
  452. /// <summary>
  453. /// Waste Valve On
  454. /// </summary>
  455. /// <returns></returns>
  456. public bool WasteValveOn()
  457. {
  458. string ioName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{WASTE_VALVE}");
  459. return IOModuleManager.Instance.WriteIoValue(ioName, true);
  460. }
  461. /// <summary>
  462. /// Waste Valve Off(等价于Metal Valve On)
  463. /// </summary>
  464. /// <returns></returns>
  465. public bool WasteValveOff()
  466. {
  467. string ioName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{WASTE_VALVE}");
  468. return IOModuleManager.Instance.WriteIoValue(ioName, false);
  469. }
  470. #endregion
  471. public void Monitor()
  472. {
  473. }
  474. public void Reset()
  475. {
  476. }
  477. public void Terminate()
  478. {
  479. }
  480. }
  481. }