StandardHotMetalDevice.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479
  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.ModuleIO;
  9. using MECF.Framework.Common.CommonData.Metal;
  10. using MECF.Framework.Common.Persistent.Reservoirs;
  11. using MECF.Framework.Common.TwinCat;
  12. using CyberX8_Core;
  13. using CyberX8_RT.Devices.LinMot;
  14. using CyberX8_RT.Devices.Prewet;
  15. using System;
  16. using System.Collections.Generic;
  17. using System.Linq;
  18. using System.Reflection;
  19. using System.Diagnostics;
  20. using MECF.Framework.Common.IOCore;
  21. using Aitex.Core.RT.SCCore;
  22. using CyberX8_RT.Devices.PowerSupplier;
  23. using MECF.Framework.Common.ToolLayout;
  24. namespace CyberX8_RT.Devices.Metal
  25. {
  26. public class StandardHotMetalDevice : MetalCellDevice
  27. {
  28. private enum MetalOperation
  29. {
  30. None,
  31. CellPumpOn
  32. }
  33. #region 常量
  34. private const string PERSISTENT_VALUE = "PersistentValue";
  35. private const string CELL_PUMP = "CellPump";
  36. private const string CELL_FLOW = "CellFlow";
  37. private const string WH_CLAMP = "WaferHolderClamp";
  38. private const string CIRCULATION = "Circulation";
  39. private const string REGULATE_PUMP_SIGNAL_IN = "RegulatePumpSignalIn";
  40. private const string REGULATE_PUMP_SPEED = "RegulatePumpSpeed";
  41. private const string REGULATE_PUMP = "RegulatPump";
  42. #endregion
  43. #region 内部变量
  44. /// <summary>
  45. /// 设备数据
  46. /// </summary>
  47. private StandardHotMetalDeviceData _metalDeviceData = new StandardHotMetalDeviceData();
  48. /// <summary>
  49. /// 变量是否初始化字典
  50. /// </summary>
  51. private Dictionary<string, bool> _variableInitializeDic = new Dictionary<string, bool>();
  52. /// <summary>
  53. /// Pump Routine
  54. /// </summary>
  55. private StandardHotMetalCellPumpRoutine _cellPumpRoutine;
  56. /// <summary>
  57. /// 当前操作
  58. /// </summary>
  59. private MetalOperation _currentOperation;
  60. /// <summary>
  61. /// Flow Valve计时
  62. /// </summary>
  63. private Stopwatch _flowValveStopWatch = new Stopwatch();
  64. /// <summary>
  65. /// 调速泵Pump速度
  66. /// </summary>
  67. private double _regulatePumpSpeed;
  68. /// <summary>
  69. /// 是否为调速类型的pump
  70. /// </summary>
  71. private bool _isRegulatePump = false;
  72. /// <summary>
  73. /// Metal项
  74. /// </summary>
  75. private MetalItem _metalItem;
  76. #endregion
  77. #region 属性
  78. /// <summary>
  79. /// 设备数据
  80. /// </summary>
  81. public StandardHotMetalDeviceData MetalDeviceData { get { return _metalDeviceData; } }
  82. /// <summary>
  83. /// 是否调速泵
  84. /// </summary>
  85. public bool IsRegulatePump { get { return _isRegulatePump; } }
  86. /// <summary>
  87. /// Flow Valve稳定状态
  88. /// </summary>
  89. public bool FlowValveStable { get { return _metalDeviceData.Circulation && _flowValveStopWatch.ElapsedMilliseconds >= 3000; } }
  90. #endregion
  91. /// <summary>
  92. /// 构造函数
  93. /// </summary>
  94. /// <param name="moduleName"></param>
  95. public StandardHotMetalDevice(string moduleName) : base(moduleName)
  96. {
  97. }
  98. /// <summary>
  99. /// 初始化
  100. /// </summary>
  101. /// <returns></returns>
  102. public override bool Initialize()
  103. {
  104. base.Initialize();
  105. InitializeParameter();
  106. InitializeRoutine();
  107. SubscribeValueAction();
  108. SubscribeData();
  109. return true;
  110. }
  111. /// <summary>
  112. /// 初始化参数
  113. /// </summary>
  114. private void InitializeParameter()
  115. {
  116. _persistentValue = MetalPersistentManager.Instance.GetMetalPersistentValue(Module);
  117. if (_persistentValue == null)
  118. {
  119. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, "Persistent Value Object is not exist");
  120. }
  121. _metalItem = MetalItemManager.Instance.GetMetalItem(Module);
  122. if (_metalItem != null)
  123. {
  124. _isRegulatePump = "Regulate" == _metalItem.PumpType;
  125. }
  126. _regulatePumpSpeed = SC.GetValue<double>("Reservoir.DefaultPumpSpeed");
  127. }
  128. /// <summary>
  129. /// 初始化Routine
  130. /// </summary>
  131. private void InitializeRoutine()
  132. {
  133. _cellPumpRoutine = new StandardHotMetalCellPumpRoutine(Module.ToString());
  134. }
  135. /// <summary>
  136. /// 订阅数据
  137. /// </summary>
  138. private void SubscribeData()
  139. {
  140. DATA.Subscribe($"{Module}.MetalData", () => _metalDeviceData, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  141. DATA.Subscribe($"{Module}.CellPumpEnable", () => _metalDeviceData.CellPump, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  142. DATA.Subscribe($"{Module}.WaferShuttleClamped", () => _metalDeviceData.WaferHolderClamp, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  143. DATA.Subscribe($"{Module}.CellFlow", () => _metalDeviceData.CellFlow, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  144. DATA.Subscribe($"{Module}.Circulation", () => _metalDeviceData.Circulation, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  145. DATA.Subscribe($"{Module}.IsRegulatePump", () => _isRegulatePump, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  146. DATA.Subscribe($"{Module}.PumpSpeed", () => _regulatePumpSpeed, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  147. }
  148. /// <summary>
  149. /// 订阅变量数值发生变化
  150. /// </summary>
  151. private void SubscribeValueAction()
  152. {
  153. BeckhoffIoSubscribeUpdateVariable(CELL_PUMP);
  154. BeckhoffIoSubscribeUpdateVariable(CELL_FLOW);
  155. BeckhoffIoSubscribeUpdateVariable(WH_CLAMP);
  156. BeckhoffIoSubscribeUpdateVariable(CIRCULATION);
  157. BeckhoffIoSubscribeUpdateVariable(REGULATE_PUMP_SIGNAL_IN);
  158. }
  159. /// <summary>
  160. /// 订阅Operation
  161. /// </summary>
  162. protected override void InitializeOperation()
  163. {
  164. base.InitializeOperation();
  165. OP.Subscribe($"{Module}.PumpEnable", OpenPump);
  166. OP.Subscribe($"{Module}.PumpDisable", ClosePump);
  167. OP.Subscribe($"{Module}.CellSwitchToBypass", (cmd, args) => { return SwitchToBypass(cmd, args); });
  168. OP.Subscribe($"{Module}.CellSwitchToFlow", (cmd, args) => { return SwitchToFlow(cmd, args); });
  169. OP.Subscribe($"{Module}.ClampOn", (cmd, args) => { return WaferHolderClampOn(cmd, args); });
  170. OP.Subscribe($"{Module}.ClampOff", (cmd, args) => { return WaferHolderClampOff(cmd, args); });
  171. OP.Subscribe($"{Module}.WaferHolderClampOn", (cmd, args) => { return WaferHolderClampOn(cmd, args); });
  172. OP.Subscribe($"{Module}.WaferHolderUnclampOn", (cmd, args) => { return WaferHolderClampOff(cmd, args); });
  173. OP.Subscribe($"{Module}.RegulatPumpSpeed", RegulatePumpSpeedOperation);
  174. }
  175. /// <summary>
  176. /// 订阅IO变量
  177. /// </summary>
  178. /// <param name="variable"></param>
  179. private void BeckhoffIoSubscribeUpdateVariable(string variable)
  180. {
  181. _variableInitializeDic[variable] = false;
  182. IOModuleManager.Instance.SubscribeModuleVariable(Module, variable, UpdateVariableValue);
  183. }
  184. /// <summary>
  185. /// 更新变量数值
  186. /// </summary>
  187. /// <param name="variable"></param>
  188. /// <param name="value"></param>
  189. private void UpdateVariableValue(string variable, object value)
  190. {
  191. if (!_metalDeviceData.IsDataInitialized)
  192. {
  193. _metalDeviceData.IsDataInitialized = true;
  194. }
  195. PropertyInfo property = _metalDeviceData.GetType().GetProperty(variable);
  196. if (property != null)
  197. {
  198. property.SetValue(_metalDeviceData, value);
  199. }
  200. if (_variableInitializeDic.ContainsKey(variable) && !_variableInitializeDic[variable])
  201. {
  202. _variableInitializeDic[variable] = true;
  203. }
  204. if (variable == CIRCULATION)
  205. {
  206. bool bValue = (bool)value;
  207. if (bValue)
  208. {
  209. _flowValveStopWatch.Restart();
  210. }
  211. }
  212. }
  213. public bool OpenPump(string cmd, Object[] args)
  214. {
  215. bool result = false;
  216. if (_isRegulatePump)
  217. {
  218. result = RegulatePumpOn(cmd, args);
  219. }
  220. else
  221. {
  222. result = PumpOnOperation(cmd, args);
  223. }
  224. return result;
  225. }
  226. public bool ClosePump(string cmd, Object[] args)
  227. {
  228. bool result = false;
  229. if (_isRegulatePump)
  230. {
  231. result = RegulatePumpOff(cmd, args);
  232. }
  233. else
  234. {
  235. result = PumpOffOperation(cmd, args);
  236. }
  237. return result;
  238. }
  239. #region Regulat Pump
  240. /// <summary>
  241. /// 调速pump
  242. /// </summary>
  243. /// <param name="cmd"></param>
  244. /// <param name="args"></param>
  245. /// <returns></returns>
  246. private bool RegulatePumpSpeedOperation(string cmd, object[] args)
  247. {
  248. double MaxPumpSpeed = 0;
  249. if (SC.ContainsItem("Reservoir.MaxPumpSpeed"))
  250. {
  251. MaxPumpSpeed = SC.GetValue<double>("Reservoir.MaxPumpSpeed");
  252. }
  253. if (double.TryParse(args[0].ToString(), out double speed))
  254. {
  255. _regulatePumpSpeed = speed;
  256. if (_regulatePumpSpeed > MaxPumpSpeed)
  257. {
  258. _regulatePumpSpeed = SC.GetValue<double>("Reservoir.DefaultPumpSpeed");//恢复成默认泵速
  259. LOG.WriteLog(eEvent.WARN_METAL, Module, $"Pump speed:{_regulatePumpSpeed} is over max pump speed {MaxPumpSpeed}!");
  260. return false;
  261. }
  262. return RegulatePumpSpeed(_regulatePumpSpeed);
  263. }
  264. else
  265. {
  266. LOG.WriteLog(eEvent.ERR_METAL, Module, $"{args[0]} is nor invalid speed");
  267. return false;
  268. }
  269. }
  270. /// <summary>
  271. /// 设置泵速
  272. /// </summary>
  273. /// <param name="PumpSpeed"></param>
  274. /// <returns></returns>
  275. public bool RegulatePumpSpeed(double PumpSpeed)
  276. {
  277. string ioName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{REGULATE_PUMP_SPEED}");
  278. return IOModuleManager.Instance.WriteIoValue(ioName, PumpSpeed);
  279. }
  280. /// <summary>
  281. /// Pump On
  282. /// </summary>
  283. /// <param name="cmd"></param>
  284. /// <param name="args"></param>
  285. /// <returns></returns>
  286. private bool RegulatePumpOn(string cmd, object[] args)
  287. {
  288. string enableIOName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{REGULATE_PUMP}");
  289. return IOModuleManager.Instance.WriteIoValue(enableIOName, true);
  290. }
  291. /// <summary>
  292. /// Pump Off
  293. /// </summary>
  294. /// <param name="cmd"></param>
  295. /// <param name="args"></param>
  296. /// <returns></returns>
  297. private bool RegulatePumpOff(string cmd, object[] args)
  298. {
  299. string ioName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{REGULATE_PUMP}");
  300. return IOModuleManager.Instance.WriteIoValue(ioName, false);
  301. }
  302. #endregion
  303. #region CellPump
  304. /// <summary>
  305. /// Cell Pump On操作
  306. /// </summary>
  307. /// <param name="cmd"></param>
  308. /// <param name="param"></param>
  309. /// <returns></returns>
  310. public bool PumpOnOperation(string cmd, object[] param)
  311. {
  312. if (_status == RState.Running)
  313. {
  314. LOG.WriteLog(eEvent.ERR_METAL, Module.ToString(), $"{Module} current execute {_currentOperation},cannot Pump On");
  315. return false;
  316. }
  317. _status = _cellPumpRoutine.Start(true);
  318. _currentOperation = MetalOperation.CellPumpOn;
  319. return _status == RState.Running;
  320. }
  321. /// <summary>
  322. /// Cell Pump Off操作
  323. /// </summary>
  324. /// <param name="cmd"></param>
  325. /// <param name="param"></param>
  326. /// <returns></returns>
  327. public bool PumpOffOperation(string cmd, object[] param)
  328. {
  329. return PumpOff();
  330. }
  331. /// <summary>
  332. /// Pump Off
  333. /// </summary>
  334. /// <returns></returns>
  335. public bool PumpOff()
  336. {
  337. if (_status == RState.Running && _currentOperation == MetalOperation.CellPumpOn)
  338. {
  339. IRoutine routine = GetCurrentRoutine();
  340. if (routine != null)
  341. {
  342. routine.Abort();
  343. }
  344. }
  345. string ioName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{CELL_PUMP}");
  346. return IOModuleManager.Instance.WriteIoValue(ioName, false);
  347. }
  348. #endregion
  349. #region WaferHolderClampOn
  350. /// <summary>
  351. /// Wafer Holder Clamp On
  352. /// </summary>
  353. /// <param name="cmd"></param>
  354. /// <param name="param"></param>
  355. /// <returns></returns>
  356. public bool WaferHolderClampOn(string cmd, object[] param)
  357. {
  358. string ioName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{WH_CLAMP}");
  359. return IOModuleManager.Instance.WriteIoValue(ioName, true);
  360. }
  361. #endregion
  362. #region WaferHolderClampOff
  363. /// <summary>
  364. /// Wafer Holder Clamp On
  365. /// </summary>
  366. /// <param name="cmd"></param>
  367. /// <param name="param"></param>
  368. /// <returns></returns>
  369. public bool WaferHolderClampOff(string cmd, object[] param)
  370. {
  371. string ioName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{WH_CLAMP}");
  372. return IOModuleManager.Instance.WriteIoValue(ioName, false);
  373. }
  374. #endregion
  375. #region circulation
  376. /// <summary>
  377. /// 切换至Bypass
  378. /// </summary>
  379. /// <returns></returns>
  380. public bool SwitchToBypass(string cmd, object[] param)
  381. {
  382. string ioName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{CIRCULATION}");
  383. return IOModuleManager.Instance.WriteIoValue(ioName, false);
  384. }
  385. /// <summary>
  386. /// 切换至Flow
  387. /// </summary>
  388. /// <returns></returns>
  389. public bool SwitchToFlow(string cmd, object[] param)
  390. {
  391. string ioName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{CIRCULATION}");
  392. return IOModuleManager.Instance.WriteIoValue(ioName, true);
  393. }
  394. #endregion
  395. /// <summary>
  396. /// Enter Disabled Operation
  397. /// </summary>
  398. /// <returns></returns>
  399. public void EnterDisabledOperation()
  400. {
  401. if (_metalDeviceData.CellPump)
  402. {
  403. ClosePump("", null);
  404. }
  405. }
  406. /// <summary>
  407. /// 定时器
  408. /// </summary>
  409. /// <returns></returns>
  410. public override bool OnTimer(int interval)
  411. {
  412. if (_status == RState.Running)
  413. {
  414. IRoutine routine = GetCurrentRoutine();
  415. if (routine != null)
  416. {
  417. RState rsState = routine.Monitor();
  418. if (rsState == RState.Failed || rsState == RState.Timeout)
  419. {
  420. _status = RState.Failed;
  421. ClosePump("", null);
  422. _currentOperation = MetalOperation.None;
  423. }
  424. else if (rsState == RState.End)
  425. {
  426. _status = RState.End;
  427. _currentOperation = MetalOperation.None;
  428. }
  429. }
  430. }
  431. return true;
  432. }
  433. /// <summary>
  434. /// 当前Routine;
  435. /// </summary>
  436. /// <returns></returns>
  437. private IRoutine GetCurrentRoutine()
  438. {
  439. switch (_currentOperation)
  440. {
  441. case MetalOperation.CellPumpOn:
  442. return _cellPumpRoutine;
  443. default:
  444. return null;
  445. }
  446. }
  447. #region 设备接口
  448. public override void Monitor()
  449. {
  450. }
  451. public override void Reset()
  452. {
  453. }
  454. public override void Terminate()
  455. {
  456. }
  457. #endregion
  458. }
  459. }