CompactMembranMetalDevice.cs 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031
  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.UI.Control;
  7. using Aitex.Core.Util;
  8. using MECF.Framework.Common.Beckhoff.IOAxis;
  9. using MECF.Framework.Common.Beckhoff.ModuleIO;
  10. using MECF.Framework.Common.CommonData;
  11. using MECF.Framework.Common.CommonData.Metal;
  12. using MECF.Framework.Common.Persistent.Reservoirs;
  13. using MECF.Framework.Common.TwinCat;
  14. using System;
  15. using System.Collections.Generic;
  16. using System.Globalization;
  17. using System.Linq;
  18. using System.Reflection;
  19. using System.Text;
  20. using System.Threading.Tasks;
  21. using MECF.Framework.Common.ToolLayout;
  22. using MECF.Framework.Common.Layout;
  23. using Aitex.Core.RT.SCCore;
  24. using System.Diagnostics;
  25. using CyberX8_Core;
  26. using CyberX8_RT.Devices.Metal;
  27. using CyberX8_RT.Devices.Reservoir;
  28. using MECF.Framework.Common.IOCore;
  29. namespace CyberX8_RT.Devices.Metal
  30. {
  31. public class CompactMembranMetalDevice : MetalCellDevice
  32. {
  33. private enum ANCellStatus
  34. {
  35. Unknow,
  36. Filling,
  37. Emptying,
  38. Full,
  39. Empty
  40. }
  41. private enum ANCellOperation
  42. {
  43. None,
  44. Fill,
  45. Drain
  46. }
  47. #region 常量
  48. private const string SIDE_A = "SideA";
  49. private const string SIDE_B = "SideB";
  50. private const string AN_A_PINENABLE = "ANAPinEnable";
  51. private const string AN_B_PINENABLE = "ANBPinEnable";
  52. private const string AN_A_POUTENABLE = "ANAPoutEnable";
  53. private const string AN_B_POUTENABLE = "ANBPoutEnable";
  54. private const string CELL_FLOW = "CellFlow";
  55. private const string WH_CLAMP = "WHClamp";
  56. private const string WH_UNCLAMP = "WHUnclamp";
  57. private const string CELL_FLOW_VALVE = "CellFlowValve";
  58. private const string COUNTER_VALUE = "CounterValue";
  59. private const string COUNTER_START = "Start";
  60. private const string COUNTER_STOP = "Stop";
  61. private const string COUNTER_RESET = "Reset";
  62. private const string AN_A_CELL_FLOW = "ANACellFlow";
  63. private const string AN_B_CELL_FLOW = "ANBCellFlow";
  64. #endregion
  65. #region 内部变量
  66. /// <summary>
  67. /// 设备数据
  68. /// </summary>
  69. private CompactMembranMetalDeviceData _metalDeviceData = new CompactMembranMetalDeviceData();
  70. /// <summary>
  71. /// 变量是否初始化字典
  72. /// </summary>
  73. private Dictionary<string, bool> _variableInitializeDic = new Dictionary<string, bool>();
  74. /// <summary>
  75. /// 阳极A面cellFlow
  76. /// </summary>
  77. private CounterFlowData _anACellFlow = new CounterFlowData();
  78. /// <summary>
  79. /// 阳极B面cellFlow
  80. /// </summary>
  81. private CounterFlowData _anBCellFlow = new CounterFlowData();
  82. /// <summary>
  83. /// Counter字典
  84. /// </summary>
  85. private Dictionary<string, CounterFlowData> _nameCounterFlowData = new Dictionary<string, CounterFlowData>();
  86. /// <summary>
  87. /// 当前阳极A面操作
  88. /// </summary>
  89. private ANCellOperation _currentANACellOperation;
  90. /// <summary>
  91. /// 当前阳机B面操作
  92. /// </summary>
  93. private ANCellOperation _currentANBCellOperation;
  94. /// <summary>
  95. /// AN Fill Routine
  96. /// </summary>
  97. private CompactMembranFillRoutine _anANACellFillRoutine;
  98. /// <summary>
  99. /// 阳机B面Fill Routine
  100. /// </summary>
  101. private CompactMembranFillRoutine _anANBCellFillRoutine;
  102. /// <summary>
  103. /// 阳极A面流量总数值
  104. /// </summary>
  105. private double _anATotalFillFlow = 0;
  106. /// <summary>
  107. /// 阳极B面流量总数值
  108. /// </summary>
  109. private double _anBTotalFillFlow = 0;
  110. /// <summary>
  111. /// 阳极A面Drain时间
  112. /// </summary>
  113. private DateTime _anADrainTime = DateTime.Now;
  114. /// <summary>
  115. /// 阳极B面Drain时间
  116. /// </summary>
  117. private DateTime _anBDrainTime = DateTime.Now;
  118. /// <summary>
  119. /// Flow Valve计时
  120. /// </summary>
  121. private Stopwatch _flowValveStopWatch = new Stopwatch();
  122. /// <summary>
  123. /// ANA Flow Valve计时
  124. /// </summary>
  125. private Stopwatch _anaFlowValveStopWatch = new Stopwatch();
  126. /// <summary>
  127. /// ANB Flow Valve计时
  128. /// </summary>
  129. private Stopwatch _anbFlowValveStopWatch = new Stopwatch();
  130. #endregion
  131. #region 属性
  132. /// <summary>
  133. /// 设备数据
  134. /// </summary>
  135. public CompactMembranMetalDeviceData MetalDeviceData { get { return _metalDeviceData; } }
  136. /// <summary>
  137. /// 阳极A面CellFlow
  138. /// </summary>
  139. public CounterFlowData ANACellFlow { get { return _anACellFlow; } }
  140. /// <summary>
  141. /// 阳极B面CellFlow
  142. /// </summary>
  143. public CounterFlowData ANBCellFlow { get { return _anBCellFlow; } }
  144. /// <summary>
  145. /// Flow Valve稳定状态
  146. /// </summary>
  147. public bool FlowValveStable { get { return _metalDeviceData.CellFlowValve && _flowValveStopWatch.ElapsedMilliseconds >= 3000; } }
  148. /// <summary>
  149. /// ANA Flow 稳定状态
  150. /// </summary>
  151. public bool ANAFlowValveStable { get { return _metalDeviceData.ANAPinEnable && _anaFlowValveStopWatch.ElapsedMilliseconds >= 3000; } }
  152. /// <summary>
  153. /// ANB Flow 稳定状态
  154. /// </summary>
  155. public bool ANBFlowValveStable { get { return _metalDeviceData.ANBPinEnable && _anbFlowValveStopWatch.ElapsedMilliseconds >= 3000; } }
  156. #endregion
  157. /// <summary>
  158. /// 构造函数
  159. /// </summary>
  160. /// <param name="moduleName"></param>
  161. public CompactMembranMetalDevice(string moduleName) : base(moduleName)
  162. {
  163. }
  164. /// <summary>
  165. /// 初始化
  166. /// </summary>
  167. /// <returns></returns>
  168. public override bool Initialize()
  169. {
  170. base.Initialize();
  171. InitializeRoutine();
  172. SubscribeValueAction();
  173. SubscribeData();
  174. return true;
  175. }
  176. /// <summary>
  177. /// 初始化Routine
  178. /// </summary>
  179. private void InitializeRoutine()
  180. {
  181. _anANACellFillRoutine = new CompactMembranFillRoutine(Module, "A");
  182. _anANBCellFillRoutine = new CompactMembranFillRoutine(Module, "B");
  183. }
  184. /// <summary>
  185. /// 订阅数据
  186. /// </summary>
  187. private void SubscribeData()
  188. {
  189. DATA.Subscribe($"{Module}.MetalData", () => _metalDeviceData, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  190. DATA.Subscribe($"{Module}.SideAFlow", () => ANACellFlow.CounterValue, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  191. DATA.Subscribe($"{Module}.SideAFlowStatus", () => ANACellFlow.Status, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  192. DATA.Subscribe($"{Module}.SideBFlow", () => ANBCellFlow.CounterValue, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  193. DATA.Subscribe($"{Module}.SideBFlowStatus", () => ANBCellFlow.Status, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  194. DATA.Subscribe($"{Module}.CellFlow", () => MetalDeviceData.CellFlow, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  195. DATA.Subscribe($"{Module}.ANBPinEnable", () => _metalDeviceData.ANBPinEnable, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  196. DATA.Subscribe($"{Module}.ANAPinEnable", () => _metalDeviceData.ANAPinEnable, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  197. DATA.Subscribe($"{Module}.ANAPoutEnable", () => _metalDeviceData.ANAPoutEnable, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  198. DATA.Subscribe($"{Module}.ANBPoutEnable", () => _metalDeviceData.ANBPoutEnable, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  199. DATA.Subscribe($"{Module}.CellFlowEnable", () => _metalDeviceData.CellFlowValve, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  200. DATA.Subscribe($"{Module}.WaferShuttleClamped", () => _metalDeviceData.WHClamp, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  201. DATA.Subscribe($"{Module}.WaferShuttleUnclamped", () => _metalDeviceData.WHUnclamp, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  202. }
  203. /// <summary>
  204. /// 订阅变量数值发生变化
  205. /// </summary>
  206. private void SubscribeValueAction()
  207. {
  208. BeckhoffIoSubscribeUpdateVariable(AN_A_PINENABLE);
  209. BeckhoffIoSubscribeUpdateVariable(AN_B_PINENABLE);
  210. BeckhoffIoSubscribeUpdateVariable(AN_A_POUTENABLE);
  211. BeckhoffIoSubscribeUpdateVariable(AN_B_POUTENABLE);
  212. BeckhoffIoSubscribeUpdateVariable(CELL_FLOW);
  213. BeckhoffIoSubscribeUpdateVariable(WH_CLAMP);
  214. BeckhoffIoSubscribeUpdateVariable(WH_UNCLAMP);
  215. BeckhoffIoSubscribeUpdateVariable(CELL_FLOW_VALVE);
  216. BeckhoffCounterSubscribeUpdateVariable(AN_A_CELL_FLOW, ANACellFlow);
  217. BeckhoffCounter anACellFlowCounter = BeckhoffCounterManager.Instance.GetBeckhoffCounter($"{Module}.{AN_A_CELL_FLOW}");
  218. if (anACellFlowCounter != null)
  219. {
  220. ANACellFlow.Period = anACellFlowCounter.Period;
  221. }
  222. BeckhoffCounterSubscribeUpdateVariable(AN_B_CELL_FLOW, ANBCellFlow);
  223. BeckhoffCounter anBCellFlowCounter = BeckhoffCounterManager.Instance.GetBeckhoffCounter($"{Module}.{AN_B_CELL_FLOW}");
  224. if (anACellFlowCounter != null)
  225. {
  226. ANBCellFlow.Period = anBCellFlowCounter.Period;
  227. }
  228. }
  229. /// <summary>
  230. /// 订阅Operation
  231. /// </summary>
  232. protected override void InitializeOperation()
  233. {
  234. base.InitializeOperation();
  235. OP.Subscribe($"{Module}.ANAFillOn", AnSideAFillOn);
  236. OP.Subscribe($"{Module}.ANAFillOff", AnSideAFillOff);
  237. OP.Subscribe($"{Module}.ANBFillOn", AnSideBFillOn);
  238. OP.Subscribe($"{Module}.ANBFillOff", AnSideBFillOff);
  239. OP.Subscribe($"{Module}.ANADrainOn", AnSideADrainOn);
  240. OP.Subscribe($"{Module}.ANADrainOff", AnSideADrainOff);
  241. OP.Subscribe($"{Module}.ANBDrainOn", AnSideBDrainOn);
  242. OP.Subscribe($"{Module}.ANBDrainOff", AnSideBDrainOff);
  243. OP.Subscribe($"{Module}.WHClampOn", WHClampOn);
  244. OP.Subscribe($"{Module}.WHClampOff", WHClampOff);
  245. OP.Subscribe($"{Module}.WHUnclampOn", WHUnClampOn);
  246. OP.Subscribe($"{Module}.WHUnclampOff", WHUnClampOff);
  247. OP.Subscribe($"{Module}.CellFlowValveOn", CellFlowValveOn);
  248. OP.Subscribe($"{Module}.CellFlowValveOff", CellFlowValveOff);
  249. OP.Subscribe($"{Module}.WaferHolderClampOn", WaferHolderClampOn);
  250. OP.Subscribe($"{Module}.WaferHolderUnclampOn", WaferHolderUnclampOn);
  251. OP.Subscribe($"{Module}.WaferHolderDisconnect", WaferHolderDisConnect);
  252. OP.Subscribe($"{Module}.A.Fill", ANSideAFillOperation);
  253. OP.Subscribe($"{Module}.B.Fill", ANSideBFillOperation);
  254. OP.Subscribe($"{Module}.A.Stop", ANSideAStopOperation);
  255. OP.Subscribe($"{Module}.B.Stop", ANSideBStopOperation);
  256. OP.Subscribe($"{Module}.A.Drain", ANSideADrainOperation);
  257. OP.Subscribe($"{Module}.B.Drain", ANSideBDrainOperation);
  258. }
  259. /// <summary>
  260. /// 订阅IO变量
  261. /// </summary>
  262. /// <param name="variable"></param>
  263. private void BeckhoffIoSubscribeUpdateVariable(string variable)
  264. {
  265. _variableInitializeDic[variable] = false;
  266. IOModuleManager.Instance.SubscribeModuleVariable(Module, variable, UpdateVariableValue);
  267. }
  268. /// <summary>
  269. /// 更新变量数值
  270. /// </summary>
  271. /// <param name="variable"></param>
  272. /// <param name="value"></param>
  273. private void UpdateVariableValue(string variable, object value)
  274. {
  275. if (!_metalDeviceData.IsDataInitialized)
  276. {
  277. _metalDeviceData.IsDataInitialized = true;
  278. }
  279. PropertyInfo property = _metalDeviceData.GetType().GetProperty(variable);
  280. if (property != null)
  281. {
  282. property.SetValue(_metalDeviceData, value);
  283. }
  284. if (_variableInitializeDic.ContainsKey(variable) && !_variableInitializeDic[variable])
  285. {
  286. _variableInitializeDic[variable] = true;
  287. }
  288. if (variable == CELL_FLOW_VALVE)
  289. {
  290. bool bValue = (bool)value;
  291. if (bValue)
  292. {
  293. _flowValveStopWatch.Restart();
  294. }
  295. }
  296. else if (variable == AN_A_PINENABLE)
  297. {
  298. bool bValue = (bool)value;
  299. if (bValue)
  300. {
  301. _anaFlowValveStopWatch.Restart();
  302. }
  303. }
  304. else if (variable == AN_B_PINENABLE)
  305. {
  306. bool bValue = (bool)value;
  307. if (bValue)
  308. {
  309. _anbFlowValveStopWatch.Restart();
  310. }
  311. }
  312. }
  313. /// <summary>
  314. /// 订阅Counter变量
  315. /// </summary>
  316. /// <param name="variable"></param>
  317. private void BeckhoffCounterSubscribeUpdateVariable(string variable, CounterFlowData counterFlowData)
  318. {
  319. _nameCounterFlowData[$"{Module}.{variable}"] = counterFlowData;
  320. BeckhoffCounterManager.Instance.SubscribeModuleVariable($"{Module}.{variable}", COUNTER_VALUE, UpdateCounterVariableValue);
  321. BeckhoffCounterManager.Instance.SubscribeModuleVariable($"{Module}.{variable}", COUNTER_START, UpdateCounterVariableValue);
  322. BeckhoffCounterManager.Instance.SubscribeModuleVariable($"{Module}.{variable}", COUNTER_STOP, UpdateCounterVariableValue);
  323. BeckhoffCounterManager.Instance.SubscribeModuleVariable($"{Module}.{variable}", COUNTER_RESET, UpdateCounterVariableValue);
  324. }
  325. /// <summary>
  326. /// 更新变量数值
  327. /// </summary>
  328. /// <param name="variable"></param>
  329. /// <param name="value"></param>
  330. private void UpdateCounterVariableValue(string variable, object value)
  331. {
  332. string[] strAry = variable.Split('.');
  333. string lastVariable = strAry[strAry.Length - 1];
  334. PropertyInfo property = null;
  335. string key = variable.Replace($".{lastVariable}", "");
  336. if (_nameCounterFlowData.ContainsKey(key))
  337. {
  338. CounterFlowData counterFlowData = _nameCounterFlowData[key];
  339. if (counterFlowData != null)
  340. {
  341. property = counterFlowData.GetType().GetProperty(lastVariable);
  342. if (property != null)
  343. {
  344. property.SetValue(counterFlowData, value);
  345. }
  346. }
  347. }
  348. }
  349. #region Fill
  350. /// <summary>
  351. /// AN A面Fill On
  352. /// </summary>
  353. /// <param name="cmd"></param>
  354. /// <param name="param"></param>
  355. /// <returns></returns>
  356. public bool AnSideAFillOn(string cmd, object[] param)
  357. {
  358. string ioName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{AN_A_PINENABLE}");
  359. string countName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{AN_A_CELL_FLOW}");
  360. bool result = BeckhoffCounterManager.Instance.StartCounter(countName);
  361. if (result)
  362. {
  363. return BeckhoffIOManager.Instance.WriteIoValue(ioName, true);
  364. }
  365. else
  366. {
  367. return false;
  368. }
  369. }
  370. /// <summary>
  371. /// AN A面Fill Off
  372. /// </summary>
  373. /// <param name="cmd"></param>
  374. /// <param name="param"></param>
  375. /// <returns></returns>
  376. public bool AnSideAFillOff(string cmd, object[] param)
  377. {
  378. string ioName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{AN_A_PINENABLE}");
  379. string countName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{AN_A_CELL_FLOW}");
  380. bool result = BeckhoffCounterManager.Instance.StopCounter(countName);
  381. if (result)
  382. {
  383. result = BeckhoffCounterManager.Instance.ResetCounter(countName, 0);
  384. if (result)
  385. {
  386. return BeckhoffIOManager.Instance.WriteIoValue(ioName, false);
  387. }
  388. }
  389. return false;
  390. }
  391. /// <summary>
  392. /// AN B面Fill On
  393. /// </summary>
  394. /// <param name="cmd"></param>
  395. /// <param name="param"></param>
  396. /// <returns></returns>
  397. public bool AnSideBFillOn(string cmd, object[] param)
  398. {
  399. string ioName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{AN_B_PINENABLE}");
  400. string countName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{AN_B_CELL_FLOW}");
  401. bool result = BeckhoffCounterManager.Instance.StartCounter(countName);
  402. if (result)
  403. {
  404. return BeckhoffIOManager.Instance.WriteIoValue(ioName, true);
  405. }
  406. else
  407. {
  408. return false;
  409. }
  410. }
  411. /// <summary>
  412. /// AN B面Fill Off
  413. /// </summary>
  414. /// <param name="cmd"></param>
  415. /// <param name="param"></param>
  416. /// <returns></returns>
  417. public bool AnSideBFillOff(string cmd, object[] param)
  418. {
  419. string ioName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{AN_B_PINENABLE}");
  420. string countName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{AN_B_CELL_FLOW}");
  421. bool result = BeckhoffCounterManager.Instance.StopCounter(countName);
  422. if (result)
  423. {
  424. result = BeckhoffCounterManager.Instance.ResetCounter(countName, 0);
  425. if (result)
  426. {
  427. return BeckhoffIOManager.Instance.WriteIoValue(ioName, false);
  428. }
  429. }
  430. return false;
  431. }
  432. #endregion
  433. #region Drain
  434. /// <summary>
  435. /// AN A面Drain On
  436. /// </summary>
  437. /// <param name="cmd"></param>
  438. /// <param name="param"></param>
  439. /// <returns></returns>
  440. private bool AnSideADrainOn(string cmd, object[] param)
  441. {
  442. string ioName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{AN_A_POUTENABLE}");
  443. return BeckhoffIOManager.Instance.WriteIoValue(ioName, true);
  444. }
  445. /// <summary>
  446. /// AN A面Drain Off
  447. /// </summary>
  448. /// <param name="cmd"></param>
  449. /// <param name="param"></param>
  450. /// <returns></returns>
  451. public bool AnSideADrainOff(string cmd, object[] param)
  452. {
  453. string ioName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{AN_A_POUTENABLE}");
  454. return BeckhoffIOManager.Instance.WriteIoValue(ioName, false);
  455. }
  456. /// <summary>
  457. /// AN B面Drain On
  458. /// </summary>
  459. /// <param name="cmd"></param>
  460. /// <param name="param"></param>
  461. /// <returns></returns>
  462. private bool AnSideBDrainOn(string cmd, object[] param)
  463. {
  464. string ioName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{AN_B_POUTENABLE}");
  465. return BeckhoffIOManager.Instance.WriteIoValue(ioName, true);
  466. }
  467. /// <summary>
  468. /// AN A面Drain Off
  469. /// </summary>
  470. /// <param name="cmd"></param>
  471. /// <param name="param"></param>
  472. /// <returns></returns>
  473. public bool AnSideBDrainOff(string cmd, object[] param)
  474. {
  475. string ioName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{AN_B_POUTENABLE}");
  476. return BeckhoffIOManager.Instance.WriteIoValue(ioName, false);
  477. }
  478. #endregion
  479. #region WH Clamp
  480. /// <summary>
  481. /// WH Clamp On
  482. /// </summary>
  483. /// <param name="cmd"></param>
  484. /// <param name="param"></param>
  485. /// <returns></returns>
  486. private bool WHClampOn(string cmd, object[] param)
  487. {
  488. string ioName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{WH_CLAMP}");
  489. return BeckhoffIOManager.Instance.WriteIoValue(ioName, true);
  490. }
  491. /// <summary>
  492. /// WH Clamp Off
  493. /// </summary>
  494. /// <param name="cmd"></param>
  495. /// <param name="param"></param>
  496. /// <returns></returns>
  497. private bool WHClampOff(string cmd, object[] param)
  498. {
  499. string ioName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{WH_CLAMP}");
  500. return BeckhoffIOManager.Instance.WriteIoValue(ioName, false);
  501. }
  502. /// <summary>
  503. /// WH UnClamp On
  504. /// </summary>
  505. /// <param name="cmd"></param>
  506. /// <param name="param"></param>
  507. /// <returns></returns>
  508. private bool WHUnClampOn(string cmd, object[] param)
  509. {
  510. string ioName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{WH_UNCLAMP}");
  511. return BeckhoffIOManager.Instance.WriteIoValue(ioName, true);
  512. }
  513. /// <summary>
  514. /// WH UnClamp Off
  515. /// </summary>
  516. /// <param name="cmd"></param>
  517. /// <param name="param"></param>
  518. /// <returns></returns>
  519. private bool WHUnClampOff(string cmd, object[] param)
  520. {
  521. string ioName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{WH_UNCLAMP}");
  522. return BeckhoffIOManager.Instance.WriteIoValue(ioName, false);
  523. }
  524. /// <summary>
  525. /// Wafer Holder Clamp On
  526. /// </summary>
  527. /// <param name="cmd"></param>
  528. /// <param name="param"></param>
  529. /// <returns></returns>
  530. public bool WaferHolderClampOn(string cmd, object[] param)
  531. {
  532. string unclampIOName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{WH_UNCLAMP}");
  533. bool result = BeckhoffIOManager.Instance.WriteIoValue(unclampIOName, false);
  534. if (result)
  535. {
  536. string clampIOName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{WH_CLAMP}");
  537. return BeckhoffIOManager.Instance.WriteIoValue(clampIOName, true);
  538. }
  539. return false;
  540. }
  541. /// <summary>
  542. /// Wafer Holder Clamp On
  543. /// </summary>
  544. /// <param name="cmd"></param>
  545. /// <param name="param"></param>
  546. /// <returns></returns>
  547. public bool WaferHolderUnclampOn(string cmd, object[] param)
  548. {
  549. string clampIOName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{WH_CLAMP}");
  550. bool result = BeckhoffIOManager.Instance.WriteIoValue(clampIOName, false);
  551. if (result)
  552. {
  553. string unclampIOName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{WH_UNCLAMP}");
  554. return BeckhoffIOManager.Instance.WriteIoValue(unclampIOName, true);
  555. }
  556. return false;
  557. }
  558. /// <summary>
  559. /// Wafer Holder Disconnect
  560. /// </summary>
  561. /// <param name="cmd"></param>
  562. /// <param name="param"></param>
  563. /// <returns></returns>
  564. public bool WaferHolderDisConnect(string cmd, object[] param)
  565. {
  566. string clampIOName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{WH_CLAMP}");
  567. bool result = BeckhoffIOManager.Instance.WriteIoValue(clampIOName, false);
  568. if (result)
  569. {
  570. string unclampIOName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{WH_UNCLAMP}");
  571. return BeckhoffIOManager.Instance.WriteIoValue(unclampIOName, false);
  572. }
  573. return false;
  574. }
  575. #endregion
  576. #region Cell Flow Valve
  577. /// <summary>
  578. /// Cell Flow On
  579. /// </summary>
  580. /// <param name="cmd"></param>
  581. /// <param name="param"></param>
  582. /// <returns></returns>
  583. public bool CellFlowValveOn(string cmd, object[] param)
  584. {
  585. string ioName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{CELL_FLOW_VALVE}");
  586. return BeckhoffIOManager.Instance.WriteIoValue(ioName, true);
  587. }
  588. /// <summary>
  589. /// Cell Flow Off
  590. /// </summary>
  591. /// <param name="cmd"></param>
  592. /// <param name="param"></param>
  593. /// <returns></returns>
  594. public bool CellFlowValveOff(string cmd, object[] param)
  595. {
  596. string ioName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{CELL_FLOW_VALVE}");
  597. return BeckhoffIOManager.Instance.WriteIoValue(ioName, false);
  598. }
  599. #endregion
  600. #region AN Fill
  601. /// <summary>
  602. /// 阳极A面Fill
  603. /// </summary>
  604. /// <param name="cmd"></param>
  605. /// <param name="objects"></param>
  606. /// <returns></returns>
  607. private bool ANSideAFillOperation(string cmd, object[] objects)
  608. {
  609. if (_currentANACellOperation != ANCellOperation.None)
  610. {
  611. LOG.WriteLog(eEvent.ERR_METAL, Module, $"{Module} current is {_currentANACellOperation},cannot execute AN Side A Fill");
  612. return false;
  613. }
  614. bool result = _anANACellFillRoutine.Start() == RState.Running;
  615. if (result)
  616. {
  617. _currentANACellOperation = ANCellOperation.Fill;
  618. }
  619. return result;
  620. }
  621. /// <summary>
  622. /// 阳极B面Fill
  623. /// </summary>
  624. /// <param name="cmd"></param>
  625. /// <param name="objects"></param>
  626. /// <returns></returns>
  627. private bool ANSideBFillOperation(string cmd, object[] objects)
  628. {
  629. if (_currentANBCellOperation != ANCellOperation.None)
  630. {
  631. LOG.WriteLog(eEvent.ERR_METAL, Module, $"{Module} current is {_currentANBCellOperation},cannot execute AN Side B Fill");
  632. return false;
  633. }
  634. bool result = _anANBCellFillRoutine.Start() == RState.Running;
  635. if (result)
  636. {
  637. _currentANBCellOperation = ANCellOperation.Fill;
  638. }
  639. return result;
  640. }
  641. #endregion
  642. #region AN Drain
  643. /// <summary>
  644. /// 阳极A面Drain
  645. /// </summary>
  646. /// <param name="cmd"></param>
  647. /// <param name="objects"></param>
  648. /// <returns></returns>
  649. private bool ANSideADrainOperation(string cmd, object[] objects)
  650. {
  651. if (_currentANACellOperation != ANCellOperation.None)
  652. {
  653. LOG.WriteLog(eEvent.ERR_METAL, Module, $"{Module} current is {_currentANACellOperation},cannot execute AN Side A Drain");
  654. return false;
  655. }
  656. bool result = true;
  657. CompactMembranReservoirDevice reservoirDevice = GetReservoirDevice();
  658. if (CheckOtherMetalDeviceDrainStatus(reservoirDevice, "A"))
  659. {
  660. return false;
  661. }
  662. if (reservoirDevice != null && reservoirDevice.ReservoirData.ANADrainPump == 0)
  663. {
  664. result = reservoirDevice.AnADrainPumpOn("", null);
  665. }
  666. if (result)
  667. {
  668. result = AnSideADrainOn("", null);
  669. if (result)
  670. {
  671. ANACellFlow.Status = ANCellStatus.Emptying.ToString();
  672. _anATotalFillFlow = 0;
  673. _anADrainTime = DateTime.Now;
  674. }
  675. else
  676. {
  677. reservoirDevice.AnADrainPump(0);
  678. }
  679. }
  680. return result;
  681. }
  682. /// <summary>
  683. /// 其他Metal Drain是否打开
  684. /// </summary>
  685. /// <param name="reservoirDevice"></param>
  686. /// <param name="side"></param>
  687. /// <returns></returns>
  688. private bool CheckOtherMetalDeviceDrainStatus(CompactMembranReservoirDevice reservoirDevice, string side)
  689. {
  690. if (reservoirDevice == null)
  691. {
  692. return false;
  693. }
  694. ReservoirItem reservoirItem = ReservoirItemManager.Instance.GetReservoirItem(reservoirDevice.Module);
  695. if (reservoirItem != null)
  696. {
  697. foreach (var item in reservoirItem.MetalCells)
  698. {
  699. if (item.ModuleName != Module)
  700. {
  701. CompactMembranMetalDevice metalDevice = DEVICE.GetDevice<CompactMembranMetalDevice>(item.ModuleName);
  702. if (metalDevice != null)
  703. {
  704. if (side == "A" && metalDevice.MetalDeviceData.ANAPoutEnable)
  705. {
  706. LOG.WriteLog(eEvent.ERR_METAL, Module, $"{item.ModuleName} A Drain is on");
  707. return true;
  708. }
  709. if (side == "B" && metalDevice.MetalDeviceData.ANBPoutEnable)
  710. {
  711. LOG.WriteLog(eEvent.ERR_METAL, Module, $"{item.ModuleName} B Drain is on");
  712. return true;
  713. }
  714. }
  715. }
  716. }
  717. }
  718. return false;
  719. }
  720. /// <summary>
  721. /// 阳极A面Drain
  722. /// </summary>
  723. /// <param name="cmd"></param>
  724. /// <param name="objects"></param>
  725. /// <returns></returns>
  726. private bool ANSideBDrainOperation(string cmd, object[] objects)
  727. {
  728. if (_currentANBCellOperation != ANCellOperation.None)
  729. {
  730. LOG.WriteLog(eEvent.ERR_METAL, Module, $"{Module} current is {_currentANBCellOperation},cannot execute AN Side A Drain");
  731. return false;
  732. }
  733. bool result = true;
  734. CompactMembranReservoirDevice reservoirDevice = GetReservoirDevice();
  735. if (CheckOtherMetalDeviceDrainStatus(reservoirDevice, "B"))
  736. {
  737. return false;
  738. }
  739. if (reservoirDevice != null && reservoirDevice.ReservoirData.ANBDrainPump == 0)
  740. {
  741. result = reservoirDevice.AnBDrainPumpOn("", null);
  742. }
  743. if (result)
  744. {
  745. result = AnSideBDrainOn("", null);
  746. if (result)
  747. {
  748. ANBCellFlow.Status = ANCellStatus.Emptying.ToString();
  749. _anBTotalFillFlow = 0;
  750. _anBDrainTime = DateTime.Now;
  751. }
  752. else
  753. {
  754. reservoirDevice.AnBDrainPump(0);
  755. }
  756. }
  757. return result;
  758. }
  759. #endregion
  760. #region AN Stop
  761. /// <summary>
  762. /// 阳面A停止
  763. /// </summary>
  764. /// <param name="cmd"></param>
  765. /// <param name="objs"></param>
  766. /// <returns></returns>
  767. private bool ANSideAStopOperation(string cmd, object[] objs)
  768. {
  769. CompactMembranReservoirDevice reservoirDevice = GetReservoirDevice();
  770. if (reservoirDevice != null)
  771. {
  772. if (reservoirDevice.ReservoirData.ANPump != 0)
  773. {
  774. reservoirDevice.AnPump(0);
  775. }
  776. if (reservoirDevice.ReservoirData.ANADrainPump != 0)
  777. {
  778. reservoirDevice.AnADrainPump(0);
  779. }
  780. }
  781. if (MetalDeviceData.ANAPinEnable)
  782. {
  783. AnSideAFillOff("", null);
  784. }
  785. if (MetalDeviceData.ANAPoutEnable)
  786. {
  787. AnSideADrainOff("", null);
  788. }
  789. ANACellFlow.Status = ANCellStatus.Unknow.ToString();
  790. _anATotalFillFlow = 0;
  791. return true;
  792. }
  793. /// <summary>
  794. /// 阳面A停止
  795. /// </summary>
  796. /// <param name="cmd"></param>
  797. /// <param name="objs"></param>
  798. /// <returns></returns>
  799. private bool ANSideBStopOperation(string cmd, object[] objs)
  800. {
  801. CompactMembranReservoirDevice reservoirDevice = GetReservoirDevice();
  802. if (reservoirDevice != null)
  803. {
  804. if (reservoirDevice.ReservoirData.ANPump != 0)
  805. {
  806. reservoirDevice.AnPump(0);
  807. }
  808. if (reservoirDevice.ReservoirData.ANBDrainPump != 0)
  809. {
  810. reservoirDevice.AnBDrainPump(0);
  811. }
  812. }
  813. if (MetalDeviceData.ANBPinEnable)
  814. {
  815. AnSideBFillOff("", null);
  816. }
  817. if (MetalDeviceData.ANBPoutEnable)
  818. {
  819. AnSideBDrainOff("", null);
  820. }
  821. ANBCellFlow.Status = ANCellStatus.Unknow.ToString();
  822. _anBTotalFillFlow = 0;
  823. return true;
  824. }
  825. #endregion
  826. #region Timer定时器
  827. /// <summary>
  828. /// 定时器
  829. /// </summary>
  830. /// <returns></returns>
  831. public override bool OnTimer(int interval)
  832. {
  833. if (_currentANACellOperation == ANCellOperation.Fill)
  834. {
  835. SideFillRoutineMonitor(_anANACellFillRoutine, "A", ANACellFlow, ref _currentANACellOperation);
  836. }
  837. if (_currentANBCellOperation == ANCellOperation.Fill)
  838. {
  839. SideFillRoutineMonitor(_anANBCellFillRoutine, "B", ANBCellFlow, ref _currentANBCellOperation);
  840. }
  841. //正在Filing
  842. if (ANACellFlow.Status == ANCellStatus.Filling.ToString())
  843. {
  844. JudgeFillFull(ANACellFlow, interval, ref _anATotalFillFlow);
  845. }
  846. if (ANBCellFlow.Status == ANCellStatus.Filling.ToString())
  847. {
  848. JudgeFillFull(ANBCellFlow, interval, ref _anBTotalFillFlow);
  849. }
  850. if (ANACellFlow.Status == ANCellStatus.Emptying.ToString())
  851. {
  852. JudgeDrainEmpty("A");
  853. }
  854. if (ANBCellFlow.Status == ANCellStatus.Emptying.ToString())
  855. {
  856. JudgeDrainEmpty("B");
  857. }
  858. return true;
  859. }
  860. /// <summary>
  861. /// 单面Fill Routine监控
  862. /// </summary>
  863. /// <param name="routine"></param>
  864. /// <param name="side"></param>
  865. /// <param name="operation"></param>
  866. private void SideFillRoutineMonitor(IRoutine routine, string side, CounterFlowData counterFlowData, ref ANCellOperation operation)
  867. {
  868. RState state = routine.Monitor();
  869. if (state == RState.Failed || state == RState.Timeout)
  870. {
  871. CloseReservoirPumpAndMetalFill(side);
  872. operation = ANCellOperation.None;
  873. }
  874. else if (state == RState.End)
  875. {
  876. counterFlowData.Status = ANCellStatus.Filling.ToString();
  877. operation = ANCellOperation.None;
  878. }
  879. }
  880. /// <summary>
  881. /// 判定是否fill Full
  882. /// </summary>
  883. private void JudgeFillFull(CounterFlowData counterFlowData, int interval, ref double totalFillFlow)
  884. {
  885. double anodeFillVolume = SC.GetValue<double>($"Metal.AnodeFillVolume");
  886. totalFillFlow += counterFlowData.CounterValue / 60 * ((double)interval / 1000);
  887. if (totalFillFlow >= anodeFillVolume)
  888. {
  889. counterFlowData.Status = "Full";
  890. }
  891. }
  892. /// <summary>
  893. /// 判定是否Drain Empty
  894. /// </summary>
  895. /// <param name="counterFlowData"></param>
  896. private void JudgeDrainEmpty(string side)
  897. {
  898. if (side == "A")
  899. {
  900. JudgeSideADrain(ANACellFlow, _anADrainTime);
  901. if (ANACellFlow.Status == ANCellStatus.Empty.ToString())
  902. {
  903. CompactMembranReservoirDevice reservoirDevice = GetReservoirDevice();
  904. if (reservoirDevice != null)
  905. {
  906. reservoirDevice.AnADrainPump(0);
  907. }
  908. AnSideADrainOff("", null);
  909. }
  910. }
  911. else
  912. {
  913. JudgeSideADrain(ANBCellFlow, _anBDrainTime);
  914. if (ANBCellFlow.Status == ANCellStatus.Empty.ToString())
  915. {
  916. CompactMembranReservoirDevice reservoirDevice = GetReservoirDevice();
  917. if (reservoirDevice != null)
  918. {
  919. reservoirDevice.AnBDrainPump(0);
  920. }
  921. AnSideBDrainOff("", null);
  922. }
  923. }
  924. }
  925. /// <summary>
  926. /// 判定单面Drain的情况
  927. /// </summary>
  928. /// <param name="counterFlowData"></param>
  929. /// <param name="drainDateTime"></param>
  930. private void JudgeSideADrain(CounterFlowData counterFlowData, DateTime drainDateTime)
  931. {
  932. double anodeDrainTime = SC.GetValue<double>("Metal.AnodeDrainTime");
  933. if (DateTime.Now.Subtract(drainDateTime).TotalMilliseconds >= anodeDrainTime * 1000)
  934. {
  935. counterFlowData.Status = ANCellStatus.Empty.ToString();
  936. }
  937. }
  938. /// <summary>
  939. /// 关闭Reservoir Pump和Metal Fill
  940. /// </summary>
  941. private void CloseReservoirPumpAndMetalFill(string side)
  942. {
  943. CompactMembranReservoirDevice reservoirDevice = GetReservoirDevice();
  944. if (reservoirDevice != null)
  945. {
  946. reservoirDevice.AnPump(0);
  947. if (side == "A")
  948. {
  949. AnSideAFillOff("", null);
  950. }
  951. else
  952. {
  953. AnSideBDrainOff("", null);
  954. }
  955. }
  956. }
  957. /// <summary>
  958. /// 获取Reservoir设备
  959. /// </summary>
  960. /// <returns></returns>
  961. private CompactMembranReservoirDevice GetReservoirDevice()
  962. {
  963. string reservoir = ReservoirItemManager.Instance.GetReservoirByMetal(Module);
  964. return DEVICE.GetDevice<CompactMembranReservoirDevice>(reservoir);
  965. }
  966. #endregion
  967. /// <summary>
  968. /// Enter Disabled Operation
  969. /// </summary>
  970. /// <returns></returns>
  971. public void EnterDisabledOperation()
  972. {
  973. ANSideAStopOperation("", null);
  974. ANSideBStopOperation("", null);
  975. if (_metalDeviceData.CellFlowValve)
  976. {
  977. CellFlowValveOff("", null);
  978. }
  979. }
  980. #region 设备接口
  981. public override void Monitor()
  982. {
  983. }
  984. public override void Reset()
  985. {
  986. }
  987. public override void Terminate()
  988. {
  989. }
  990. #endregion
  991. }
  992. }