VpwCellDevice.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612
  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.Util;
  6. using MECF.Framework.Common.Beckhoff.ModuleIO;
  7. using MECF.Framework.Common.CommonData.Prewet;
  8. using MECF.Framework.Common.CommonData.Vpw;
  9. using MECF.Framework.Common.IOCore;
  10. using MECF.Framework.Common.Persistent.SRD;
  11. using MECF.Framework.Common.Persistent.Temperature;
  12. using MECF.Framework.Common.Persistent.VpwCell;
  13. using MECF.Framework.Common.Persistent.VpwMain;
  14. using MECF.Framework.Common.ToolLayout;
  15. using MECF.Framework.Common.Utilities;
  16. using PunkHPX8_RT.Devices.AXIS;
  17. using PunkHPX8_RT.Devices.Resistivity;
  18. using PunkHPX8_RT.Devices.VpwMain;
  19. using PunkHPX8_RT.Modules;
  20. using PunkHPX8_RT.Modules.VpwMain;
  21. using System;
  22. using System.Collections.Generic;
  23. using System.Linq;
  24. using System.Reflection;
  25. using System.Text;
  26. using System.Threading.Tasks;
  27. namespace PunkHPX8_RT.Devices.VpwCell
  28. {
  29. public class VpwCellDevice : BaseDevice, IDevice
  30. {
  31. #region 常量
  32. private const string COMMON_DATA = "CommonData";
  33. private const string DIW_FLOW = "DiwFlow";
  34. private const string VACUUM_PRESSURE = "VacuumPressure";
  35. private const string FLOW_DRIP = "FlowDrip";
  36. private const string FLOW_SMALL = "FlowSmall";
  37. private const string FLOW_LARGE = "FlowLarge";
  38. private const string VACUUM_VALVE = "VacuumValve";
  39. private const string VENT_VALVE = "VentValve";
  40. private const string DRAIN_VALVE = "DrainValve";
  41. private const string PERSISTENT_VALUE = "PersistentValue";
  42. private const string LOOPDO_VALUE = "LoopDoValue";
  43. #endregion
  44. #region 内部变量
  45. /// <summary>
  46. /// 变量是否初始化字典
  47. /// </summary>
  48. private Dictionary<string, bool> _variableInitializeDic = new Dictionary<string, bool>();
  49. /// <summary>
  50. /// 数据
  51. /// </summary>
  52. private VpwCellCommonData _commonData=new VpwCellCommonData();
  53. /// Vpw main数据
  54. /// </summary>
  55. private VpwMainCommonData _mainCommonData = new VpwMainCommonData();
  56. /// <summary>
  57. /// 持久性数值
  58. /// </summary>
  59. private VpwCellPersistentValue _vpwCellPersistentValue;
  60. /// <summary>
  61. /// 水平电机
  62. /// </summary>
  63. private JetAxisBase _rotationAxis;
  64. /// <summary>
  65. /// 水阻计控制器
  66. /// </summary>
  67. private ResistivityController _resistivityController;
  68. /// <summary>
  69. /// 水阻值
  70. /// </summary>
  71. private double _resistivityValue;
  72. /// <summary>
  73. /// main device
  74. /// </summary>
  75. private VpwMainDevice _vpwMainDevice;
  76. #endregion
  77. #region 属性
  78. /// <summary>
  79. /// 数据
  80. /// </summary>
  81. public VpwCellCommonData CommonData { get { return _commonData; } }
  82. /// <summary>
  83. /// vpw main数据
  84. /// </summary>
  85. public VpwMainCommonData MainCommonData { get { return _mainCommonData; } }
  86. /// <summary>
  87. /// 操作模式
  88. /// </summary>
  89. public string OperationMode { get { return _vpwCellPersistentValue.OperatingMode; } }
  90. /// <summary>
  91. /// 工程模式
  92. /// </summary>
  93. public string EngineerMode { get { return _vpwCellPersistentValue.RecipeOperatingMode; } }
  94. /// <summary>
  95. /// LoopDO数值
  96. /// </summary>
  97. public double LoopDOValue { get { return GetLoopDOValue(); } }
  98. #endregion
  99. /// <summary>
  100. /// 构造函数
  101. /// </summary>
  102. /// <param name="moduleName"></param>
  103. public VpwCellDevice(string moduleName) : base(moduleName, moduleName, moduleName, moduleName)
  104. {
  105. }
  106. #region 初始化
  107. /// <summary>
  108. /// 初始化
  109. /// </summary>
  110. /// <returns></returns>
  111. public bool Initialize()
  112. {
  113. InitializeParameter();
  114. InitializeRoutine();
  115. SubscribeData();
  116. SubscribeValueAction();
  117. InitializeOperation();
  118. return true;
  119. }
  120. /// <summary>
  121. /// 初始化参数
  122. /// </summary>
  123. private void InitializeParameter()
  124. {
  125. _rotationAxis = DEVICE.GetDevice<JetAxisBase>($"{Module}.Rotation");
  126. _vpwCellPersistentValue = VpwCellPersistentManager.Instance.GetPersistentValue(Module);
  127. VpwCellItem vpwCellItem=VpwCellItemManager.Instance.GetVpwItem(Module);
  128. if (vpwCellItem != null)
  129. {
  130. _resistivityController = DEVICE.GetDevice<ResistivityController>(vpwCellItem.ResistivityID);
  131. }
  132. _vpwMainDevice = DEVICE.GetDevice<VpwMainDevice>($"VPWMain1");
  133. if(_vpwMainDevice != null)
  134. {
  135. _mainCommonData = _vpwMainDevice.CommonData;
  136. }
  137. }
  138. /// <summary>
  139. /// 初始化Routine
  140. /// </summary>
  141. private void InitializeRoutine()
  142. {
  143. }
  144. /// <summary>
  145. /// 订阅
  146. /// </summary>
  147. private void SubscribeData()
  148. {
  149. DATA.Subscribe($"{Module}.{COMMON_DATA}", () => CommonData, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  150. DATA.Subscribe($"{Module}.{PERSISTENT_VALUE}", () => _vpwCellPersistentValue, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  151. DATA.Subscribe($"{Module}.DiwCellFlow", () => CommonData.DiwFlow, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  152. DATA.Subscribe($"{Module}.{LOOPDO_VALUE}", ()=> { return GetLoopDOValue(); }, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  153. }
  154. /// <summary>
  155. /// 获取Loop do数值
  156. /// </summary>
  157. /// <returns></returns>
  158. private double GetLoopDOValue()
  159. {
  160. if (_resistivityController != null)
  161. {
  162. string value = _resistivityController.ResisitivityValue;
  163. if (double.TryParse(value, out _resistivityValue))
  164. {
  165. return _resistivityValue;
  166. }
  167. else
  168. {
  169. _resistivityValue = 0;
  170. return 0;
  171. }
  172. }
  173. else
  174. {
  175. return 0;
  176. }
  177. }
  178. /// <summary>
  179. /// 订阅数据
  180. /// </summary>
  181. private void SubscribeValueAction()
  182. {
  183. IoSubscribeUpdateVariable(DIW_FLOW);
  184. IoSubscribeUpdateVariable(DRAIN_VALVE);
  185. IoSubscribeUpdateVariable(VACUUM_PRESSURE);
  186. IoSubscribeUpdateVariable(VACUUM_VALVE);
  187. IoSubscribeUpdateVariable(VENT_VALVE);
  188. IoSubscribeUpdateVariable(FLOW_DRIP);
  189. IoSubscribeUpdateVariable(FLOW_LARGE);
  190. IoSubscribeUpdateVariable(FLOW_SMALL);
  191. }
  192. /// <summary>
  193. /// 初始化变量
  194. /// </summary>
  195. /// <param name="variable"></param>
  196. private void IoSubscribeUpdateVariable(string variable)
  197. {
  198. _variableInitializeDic[variable] = false;
  199. IOModuleManager.Instance.SubscribeModuleVariable(Module, variable, UpdateVariableValue);
  200. }
  201. /// <summary>
  202. /// 更新变量数值
  203. /// </summary>
  204. /// <param name="variable"></param>
  205. /// <param name="value"></param>
  206. private void UpdateVariableValue(string variable, object value)
  207. {
  208. PropertyInfo property = _commonData.GetType().GetProperty(variable);
  209. if (property != null)
  210. {
  211. property.SetValue(_commonData, value);
  212. if (variable == VACUUM_PRESSURE)
  213. {
  214. double torr = UnitUtil.ConvertToTorr((double)value);
  215. property.SetValue(_commonData, torr);
  216. }
  217. }
  218. if (_variableInitializeDic.ContainsKey(variable) && !_variableInitializeDic[variable])
  219. {
  220. _variableInitializeDic[variable] = true;
  221. }
  222. }
  223. /// <summary>
  224. /// 初始化OP
  225. /// </summary>
  226. private void InitializeOperation()
  227. {
  228. OP.Subscribe($"{Module}.FlowDripOn", (cmd,para)=> { return FlowDripOn(); });
  229. OP.Subscribe($"{Module}.FlowDripOff", (cmd, para) => { return FlowDripOff(); });
  230. OP.Subscribe($"{Module}.FlowSmallOn", (cmd, para) => { return FlowSmallOn(); });
  231. OP.Subscribe($"{Module}.FlowSmallOff", (cmd, para) => { return FlowSmallOff(); });
  232. OP.Subscribe($"{Module}.FlowLargeOn", (cmd, para) => { return FlowLargeOn(); });
  233. OP.Subscribe($"{Module}.FlowLargeOff", (cmd, para) => { return FlowLargeOff(); });
  234. OP.Subscribe($"{Module}.VentValveOn", (cmd, para) => { return VentValveOn(); });
  235. OP.Subscribe($"{Module}.VentValveOff", (cmd, para) => { return VentValveOff(); });
  236. OP.Subscribe($"{Module}.DrainValveOn", (cmd, para) => { return DrainValveOn(); });
  237. OP.Subscribe($"{Module}.DrainValveOff", (cmd, para) => { return DrainValveOff(); });
  238. OP.Subscribe($"{Module}.VacuumValveOn", (cmd, para) => { return VacuumValveOn(); });
  239. OP.Subscribe($"{Module}.VacuumValveOff", (cmd, para) => { return VacuumValveOff(); });
  240. OP.Subscribe($"{Module}.DisabledAction", DisabledOperation);
  241. OP.Subscribe($"{Module}.ManualAction", ManualOperation);
  242. OP.Subscribe($"{Module}.AutoAction", AutoOperation);
  243. OP.Subscribe($"{Module}.EngineeringModeAction", EngineeringModeOperation);
  244. OP.Subscribe($"{Module}.ProductionModeAction", ProductionModeOperation);
  245. }
  246. #endregion
  247. #region Action
  248. #region Flow
  249. /// <summary>
  250. /// Flow Drip on
  251. /// </summary>
  252. /// <returns></returns>
  253. public bool FlowDripOn()
  254. {
  255. return WriteVariableValue(FLOW_DRIP, true);
  256. }
  257. /// <summary>
  258. /// Flow Drip Off
  259. /// </summary>
  260. /// <returns></returns>
  261. public bool FlowDripOff()
  262. {
  263. return WriteVariableValue(FLOW_DRIP, false);
  264. }
  265. /// <summary>
  266. /// Flow Small On
  267. /// </summary>
  268. /// <returns></returns>
  269. public bool FlowSmallOn()
  270. {
  271. return WriteVariableValue(FLOW_SMALL, true);
  272. }
  273. /// <summary>
  274. /// Flow Small Off
  275. /// </summary>
  276. /// <returns></returns>
  277. public bool FlowSmallOff()
  278. {
  279. return WriteVariableValue(FLOW_SMALL, false);
  280. }
  281. /// <summary>
  282. /// Flow Large On
  283. /// </summary>
  284. /// <returns></returns>
  285. public bool FlowLargeOn()
  286. {
  287. return WriteVariableValue(FLOW_LARGE, true);
  288. }
  289. /// <summary>
  290. /// Flow Large Off
  291. /// </summary>
  292. /// <returns></returns>
  293. public bool FlowLargeOff()
  294. {
  295. return WriteVariableValue(FLOW_LARGE, false);
  296. }
  297. #endregion
  298. #region Mode Switch
  299. /// <summary>
  300. /// DisabledAction
  301. /// </summary>
  302. /// <param name="cmd"></param>
  303. /// <param name="param"></param>
  304. /// <returns></returns>
  305. private bool DisabledOperation(string cmd, object[] args)
  306. {
  307. string currentOperation = "Disabled";
  308. VpwCellEntity vpwCellEntity = Singleton<RouteManager>.Instance.GetModule<VpwCellEntity>(Module);
  309. if (vpwCellEntity != null && _vpwCellPersistentValue != null && _vpwCellPersistentValue.OperatingMode != currentOperation)
  310. {
  311. string preOperation = _vpwCellPersistentValue.OperatingMode;
  312. if (vpwCellEntity.IsBusy)
  313. {
  314. LOG.WriteLog(eEvent.ERR_VPWMAIN, Module, $"{Module} is Busy, can't switch to Disabled mode");
  315. return false;
  316. }
  317. vpwCellEntity.EnterInit();
  318. _vpwCellPersistentValue.OperatingMode = currentOperation;
  319. LOG.WriteLog(eEvent.INFO_VPWMAIN, Module, $"Operating mode is switched from {preOperation} to {currentOperation}");
  320. }
  321. VpwCellPersistentManager.Instance.UpdatePersistentValue(Module);
  322. return true;
  323. }
  324. /// <summary>
  325. /// ManualAction
  326. /// </summary>
  327. /// <param name="cmd"></param>
  328. /// <param name="param"></param>
  329. /// <returns></returns>
  330. private bool ManualOperation(string cmd, object[] args)
  331. {
  332. string currentOperation = "Manual";
  333. VpwCellEntity vpwCellEntity = Singleton<RouteManager>.Instance.GetModule<VpwCellEntity>(Module);
  334. if (vpwCellEntity != null && _vpwCellPersistentValue != null && _vpwCellPersistentValue.OperatingMode != currentOperation)
  335. {
  336. string preOperation = _vpwCellPersistentValue.OperatingMode;
  337. if (vpwCellEntity.IsBusy)
  338. {
  339. LOG.WriteLog(eEvent.ERR_VPWMAIN, Module, $"{Module} is Busy, can't switch to Manual mode");
  340. return false;
  341. }
  342. vpwCellEntity.EnterInit();
  343. _vpwCellPersistentValue.OperatingMode = currentOperation;
  344. LOG.WriteLog(eEvent.INFO_VPWMAIN, Module, $"Operating mode is switched from {preOperation} to {currentOperation}");
  345. }
  346. VpwCellPersistentManager.Instance.UpdatePersistentValue(Module);
  347. return true;
  348. }
  349. /// <summary>
  350. /// AutoAction
  351. /// </summary>
  352. /// <param name="cmd"></param>
  353. /// <param name="param"></param>
  354. /// <returns></returns>
  355. private bool AutoOperation(string cmd, object[] args)
  356. {
  357. string currentOperation = "Auto";
  358. VpwCellEntity vpwCellEntity = Singleton<RouteManager>.Instance.GetModule<VpwCellEntity>(Module);
  359. if (vpwCellEntity != null && _vpwCellPersistentValue != null && _vpwCellPersistentValue.OperatingMode != currentOperation)
  360. {
  361. string preOperation = _vpwCellPersistentValue.OperatingMode;
  362. if (vpwCellEntity.IsBusy)
  363. {
  364. LOG.WriteLog(eEvent.ERR_VPWMAIN, Module, $"{Module} is Busy, can't switch to Auto mode");
  365. return false;
  366. }
  367. vpwCellEntity.EnterInit();
  368. _vpwCellPersistentValue.OperatingMode = currentOperation;
  369. LOG.WriteLog(eEvent.INFO_VPWMAIN, Module, $"Operating mode is switched from {preOperation} to {currentOperation}");
  370. }
  371. VpwCellPersistentManager.Instance.UpdatePersistentValue(Module);
  372. return true;
  373. }
  374. /// <summary>
  375. /// EngineeringModeAction
  376. /// </summary>
  377. /// <param name="cmd"></param>
  378. /// <param name="param"></param>
  379. /// <returns></returns>
  380. private bool EngineeringModeOperation(string cmd, object[] args)
  381. {
  382. string currentRecipeOperation = "Engineering";
  383. if (_vpwCellPersistentValue != null)
  384. {
  385. _vpwCellPersistentValue.RecipeOperatingMode = currentRecipeOperation;
  386. }
  387. VpwCellPersistentManager.Instance.UpdatePersistentValue(Module);
  388. return true;
  389. }
  390. /// <summary>
  391. /// ProductionAction
  392. /// </summary>
  393. /// <param name="cmd"></param>
  394. /// <param name="param"></param>
  395. /// <returns></returns>
  396. private bool ProductionModeOperation(string cmd, object[] args)
  397. {
  398. string currentRecipeOperation = "Production";
  399. if (_vpwCellPersistentValue != null)
  400. {
  401. _vpwCellPersistentValue.RecipeOperatingMode = currentRecipeOperation;
  402. }
  403. VpwCellPersistentManager.Instance.UpdatePersistentValue(Module);
  404. return true;
  405. }
  406. #endregion
  407. #region Vent Valve
  408. /// <summary>
  409. /// Vent Valve On
  410. /// </summary>
  411. /// <returns></returns>
  412. public bool VentValveOn()
  413. {
  414. return WriteVariableValue(VENT_VALVE, true);
  415. }
  416. /// <summary>
  417. /// Vent Valve Off
  418. /// </summary>
  419. /// <returns></returns>
  420. public bool VentValveOff()
  421. {
  422. return WriteVariableValue(VENT_VALVE, false);
  423. }
  424. #endregion
  425. #region Drain Valve
  426. /// <summary>
  427. /// Drain Valve On
  428. /// </summary>
  429. /// <returns></returns>
  430. public bool DrainValveOn()
  431. {
  432. return WriteVariableValue(DRAIN_VALVE, true);
  433. }
  434. /// <summary>
  435. /// Drain Valve Off
  436. /// </summary>
  437. /// <returns></returns>
  438. public bool DrainValveOff()
  439. {
  440. return WriteVariableValue(DRAIN_VALVE, false);
  441. }
  442. #endregion
  443. #region Vacuum
  444. /// <summary>
  445. /// Vacuum valve on
  446. /// </summary>
  447. /// <returns></returns>
  448. public bool VacuumValveOn()
  449. {
  450. return WriteVariableValue(VACUUM_VALVE, true);
  451. }
  452. /// <summary>
  453. /// Vacuum valve off
  454. /// </summary>
  455. /// <returns></returns>
  456. public bool VacuumValveOff()
  457. {
  458. return WriteVariableValue(VACUUM_VALVE, false);
  459. }
  460. #endregion
  461. /// <summary>
  462. /// 写变量
  463. /// </summary>
  464. /// <param name="variable"></param>
  465. /// <param name="value"></param>
  466. /// <returns></returns>
  467. private bool WriteVariableValue(string variable, object value)
  468. {
  469. string ioName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{variable}");
  470. return IOModuleManager.Instance.WriteIoValue(ioName, value);
  471. }
  472. #endregion
  473. #region Axis
  474. /// <summary>
  475. /// 电机是否上电
  476. /// </summary>
  477. /// <returns></returns>
  478. public bool CheckRotationSwitchOn()
  479. {
  480. return _rotationAxis.IsSwitchOn;
  481. }
  482. /// <summary>
  483. /// Home rotation
  484. /// </summary>
  485. /// <returns></returns>
  486. public bool HomeRotation()
  487. {
  488. return _rotationAxis.Home();
  489. }
  490. /// <summary>
  491. /// 检验Rotation Home结果
  492. /// </summary>
  493. /// <returns></returns>
  494. public bool CheckHomeEndStatus()
  495. {
  496. return CheckRotationEndStatus() && _rotationAxis.IsHomed;
  497. }
  498. /// <summary>
  499. /// 检验Rotation结束状态
  500. /// </summary>
  501. /// <returns></returns>
  502. public bool CheckRotationEndStatus()
  503. {
  504. return _rotationAxis.Status == PunkHPX8_Core.RState.End;
  505. }
  506. /// <summary>
  507. /// 检验Rotation失败状态
  508. /// </summary>
  509. /// <returns></returns>
  510. public bool CheckRotationStopStatus()
  511. {
  512. return _rotationAxis.Status == PunkHPX8_Core.RState.Failed;
  513. }
  514. /// <summary>
  515. /// 设置速度
  516. /// </summary>
  517. /// <param name="speed"></param>
  518. /// <returns></returns>
  519. public bool SetRotationSpeed(int speed)
  520. {
  521. _rotationAxis.SetProfileSpeed(speed);
  522. return true;
  523. }
  524. /// <summary>
  525. /// 改变速度
  526. /// </summary>
  527. /// <param name="speed"></param>
  528. /// <returns></returns>
  529. public bool ChangeRotationSpeed(int speed)
  530. {
  531. return _rotationAxis.ChangeSpeed(speed);
  532. }
  533. /// <summary>
  534. /// 电机运动
  535. /// </summary>
  536. /// <param name="position"></param>
  537. /// <returns></returns>
  538. public bool RotationProfilePosition(double position)
  539. {
  540. return _rotationAxis.ProfilePositionOperation(position);
  541. }
  542. /// <summary>
  543. /// 停止运动
  544. /// </summary>
  545. /// <returns></returns>
  546. public bool StopProfilePosition()
  547. {
  548. return _rotationAxis.StopPositionOperation();
  549. }
  550. /// <summary>
  551. /// 是否Rotation运动
  552. /// </summary>
  553. /// <returns></returns>
  554. public bool CheckRotationRunning()
  555. {
  556. return _rotationAxis.IsRun;
  557. }
  558. #endregion
  559. /// <summary>
  560. /// 定时器
  561. /// </summary>
  562. /// <returns></returns>
  563. public bool OnTimer()
  564. {
  565. if (_rotationAxis != null)
  566. {
  567. _rotationAxis.OnTimer();
  568. }
  569. return true;
  570. }
  571. /// <summary>
  572. /// 监控
  573. /// </summary>
  574. public void Monitor()
  575. {
  576. }
  577. public void Reset()
  578. {
  579. }
  580. public void Terminate()
  581. {
  582. }
  583. }
  584. }