VpwCellDevice.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613
  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}.VacuumValve", () => CommonData.VacuumValve, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  153. DATA.Subscribe($"{Module}.{LOOPDO_VALUE}", ()=> { return GetLoopDOValue(); }, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  154. }
  155. /// <summary>
  156. /// 获取Loop do数值
  157. /// </summary>
  158. /// <returns></returns>
  159. private double GetLoopDOValue()
  160. {
  161. if (_resistivityController != null)
  162. {
  163. string value = _resistivityController.ResisitivityValue;
  164. if (double.TryParse(value, out _resistivityValue))
  165. {
  166. return _resistivityValue;
  167. }
  168. else
  169. {
  170. _resistivityValue = 0;
  171. return 0;
  172. }
  173. }
  174. else
  175. {
  176. return 0;
  177. }
  178. }
  179. /// <summary>
  180. /// 订阅数据
  181. /// </summary>
  182. private void SubscribeValueAction()
  183. {
  184. IoSubscribeUpdateVariable(DIW_FLOW);
  185. IoSubscribeUpdateVariable(DRAIN_VALVE);
  186. IoSubscribeUpdateVariable(VACUUM_PRESSURE);
  187. IoSubscribeUpdateVariable(VACUUM_VALVE);
  188. IoSubscribeUpdateVariable(VENT_VALVE);
  189. IoSubscribeUpdateVariable(FLOW_DRIP);
  190. IoSubscribeUpdateVariable(FLOW_LARGE);
  191. IoSubscribeUpdateVariable(FLOW_SMALL);
  192. }
  193. /// <summary>
  194. /// 初始化变量
  195. /// </summary>
  196. /// <param name="variable"></param>
  197. private void IoSubscribeUpdateVariable(string variable)
  198. {
  199. _variableInitializeDic[variable] = false;
  200. IOModuleManager.Instance.SubscribeModuleVariable(Module, variable, UpdateVariableValue);
  201. }
  202. /// <summary>
  203. /// 更新变量数值
  204. /// </summary>
  205. /// <param name="variable"></param>
  206. /// <param name="value"></param>
  207. private void UpdateVariableValue(string variable, object value)
  208. {
  209. PropertyInfo property = _commonData.GetType().GetProperty(variable);
  210. if (property != null)
  211. {
  212. property.SetValue(_commonData, value);
  213. if (variable == VACUUM_PRESSURE)
  214. {
  215. double torr = UnitUtil.ConvertToTorr((double)value);
  216. property.SetValue(_commonData, torr);
  217. }
  218. }
  219. if (_variableInitializeDic.ContainsKey(variable) && !_variableInitializeDic[variable])
  220. {
  221. _variableInitializeDic[variable] = true;
  222. }
  223. }
  224. /// <summary>
  225. /// 初始化OP
  226. /// </summary>
  227. private void InitializeOperation()
  228. {
  229. OP.Subscribe($"{Module}.FlowDripOn", (cmd,para)=> { return FlowDripOn(); });
  230. OP.Subscribe($"{Module}.FlowDripOff", (cmd, para) => { return FlowDripOff(); });
  231. OP.Subscribe($"{Module}.FlowSmallOn", (cmd, para) => { return FlowSmallOn(); });
  232. OP.Subscribe($"{Module}.FlowSmallOff", (cmd, para) => { return FlowSmallOff(); });
  233. OP.Subscribe($"{Module}.FlowLargeOn", (cmd, para) => { return FlowLargeOn(); });
  234. OP.Subscribe($"{Module}.FlowLargeOff", (cmd, para) => { return FlowLargeOff(); });
  235. OP.Subscribe($"{Module}.VentValveOn", (cmd, para) => { return VentValveOn(); });
  236. OP.Subscribe($"{Module}.VentValveOff", (cmd, para) => { return VentValveOff(); });
  237. OP.Subscribe($"{Module}.DrainValveOn", (cmd, para) => { return DrainValveOn(); });
  238. OP.Subscribe($"{Module}.DrainValveOff", (cmd, para) => { return DrainValveOff(); });
  239. OP.Subscribe($"{Module}.VacuumValveOn", (cmd, para) => { return VacuumValveOn(); });
  240. OP.Subscribe($"{Module}.VacuumValveOff", (cmd, para) => { return VacuumValveOff(); });
  241. OP.Subscribe($"{Module}.DisabledAction", DisabledOperation);
  242. OP.Subscribe($"{Module}.ManualAction", ManualOperation);
  243. OP.Subscribe($"{Module}.AutoAction", AutoOperation);
  244. OP.Subscribe($"{Module}.EngineeringModeAction", EngineeringModeOperation);
  245. OP.Subscribe($"{Module}.ProductionModeAction", ProductionModeOperation);
  246. }
  247. #endregion
  248. #region Action
  249. #region Flow
  250. /// <summary>
  251. /// Flow Drip on
  252. /// </summary>
  253. /// <returns></returns>
  254. public bool FlowDripOn()
  255. {
  256. return WriteVariableValue(FLOW_DRIP, true);
  257. }
  258. /// <summary>
  259. /// Flow Drip Off
  260. /// </summary>
  261. /// <returns></returns>
  262. public bool FlowDripOff()
  263. {
  264. return WriteVariableValue(FLOW_DRIP, false);
  265. }
  266. /// <summary>
  267. /// Flow Small On
  268. /// </summary>
  269. /// <returns></returns>
  270. public bool FlowSmallOn()
  271. {
  272. return WriteVariableValue(FLOW_SMALL, true);
  273. }
  274. /// <summary>
  275. /// Flow Small Off
  276. /// </summary>
  277. /// <returns></returns>
  278. public bool FlowSmallOff()
  279. {
  280. return WriteVariableValue(FLOW_SMALL, false);
  281. }
  282. /// <summary>
  283. /// Flow Large On
  284. /// </summary>
  285. /// <returns></returns>
  286. public bool FlowLargeOn()
  287. {
  288. return WriteVariableValue(FLOW_LARGE, true);
  289. }
  290. /// <summary>
  291. /// Flow Large Off
  292. /// </summary>
  293. /// <returns></returns>
  294. public bool FlowLargeOff()
  295. {
  296. return WriteVariableValue(FLOW_LARGE, false);
  297. }
  298. #endregion
  299. #region Mode Switch
  300. /// <summary>
  301. /// DisabledAction
  302. /// </summary>
  303. /// <param name="cmd"></param>
  304. /// <param name="param"></param>
  305. /// <returns></returns>
  306. private bool DisabledOperation(string cmd, object[] args)
  307. {
  308. string currentOperation = "Disabled";
  309. VpwCellEntity vpwCellEntity = Singleton<RouteManager>.Instance.GetModule<VpwCellEntity>(Module);
  310. if (vpwCellEntity != null && _vpwCellPersistentValue != null && _vpwCellPersistentValue.OperatingMode != currentOperation)
  311. {
  312. string preOperation = _vpwCellPersistentValue.OperatingMode;
  313. if (vpwCellEntity.IsBusy)
  314. {
  315. LOG.WriteLog(eEvent.ERR_VPWMAIN, Module, $"{Module} is Busy, can't switch to Disabled mode");
  316. return false;
  317. }
  318. vpwCellEntity.EnterInit();
  319. _vpwCellPersistentValue.OperatingMode = currentOperation;
  320. LOG.WriteLog(eEvent.INFO_VPWMAIN, Module, $"Operating mode is switched from {preOperation} to {currentOperation}");
  321. }
  322. VpwCellPersistentManager.Instance.UpdatePersistentValue(Module);
  323. return true;
  324. }
  325. /// <summary>
  326. /// ManualAction
  327. /// </summary>
  328. /// <param name="cmd"></param>
  329. /// <param name="param"></param>
  330. /// <returns></returns>
  331. private bool ManualOperation(string cmd, object[] args)
  332. {
  333. string currentOperation = "Manual";
  334. VpwCellEntity vpwCellEntity = Singleton<RouteManager>.Instance.GetModule<VpwCellEntity>(Module);
  335. if (vpwCellEntity != null && _vpwCellPersistentValue != null && _vpwCellPersistentValue.OperatingMode != currentOperation)
  336. {
  337. string preOperation = _vpwCellPersistentValue.OperatingMode;
  338. if (vpwCellEntity.IsBusy)
  339. {
  340. LOG.WriteLog(eEvent.ERR_VPWMAIN, Module, $"{Module} is Busy, can't switch to Manual mode");
  341. return false;
  342. }
  343. vpwCellEntity.EnterInit();
  344. _vpwCellPersistentValue.OperatingMode = currentOperation;
  345. LOG.WriteLog(eEvent.INFO_VPWMAIN, Module, $"Operating mode is switched from {preOperation} to {currentOperation}");
  346. }
  347. VpwCellPersistentManager.Instance.UpdatePersistentValue(Module);
  348. return true;
  349. }
  350. /// <summary>
  351. /// AutoAction
  352. /// </summary>
  353. /// <param name="cmd"></param>
  354. /// <param name="param"></param>
  355. /// <returns></returns>
  356. private bool AutoOperation(string cmd, object[] args)
  357. {
  358. string currentOperation = "Auto";
  359. VpwCellEntity vpwCellEntity = Singleton<RouteManager>.Instance.GetModule<VpwCellEntity>(Module);
  360. if (vpwCellEntity != null && _vpwCellPersistentValue != null && _vpwCellPersistentValue.OperatingMode != currentOperation)
  361. {
  362. string preOperation = _vpwCellPersistentValue.OperatingMode;
  363. if (vpwCellEntity.IsBusy)
  364. {
  365. LOG.WriteLog(eEvent.ERR_VPWMAIN, Module, $"{Module} is Busy, can't switch to Auto mode");
  366. return false;
  367. }
  368. vpwCellEntity.EnterInit();
  369. _vpwCellPersistentValue.OperatingMode = currentOperation;
  370. LOG.WriteLog(eEvent.INFO_VPWMAIN, Module, $"Operating mode is switched from {preOperation} to {currentOperation}");
  371. }
  372. VpwCellPersistentManager.Instance.UpdatePersistentValue(Module);
  373. return true;
  374. }
  375. /// <summary>
  376. /// EngineeringModeAction
  377. /// </summary>
  378. /// <param name="cmd"></param>
  379. /// <param name="param"></param>
  380. /// <returns></returns>
  381. private bool EngineeringModeOperation(string cmd, object[] args)
  382. {
  383. string currentRecipeOperation = "Engineering";
  384. if (_vpwCellPersistentValue != null)
  385. {
  386. _vpwCellPersistentValue.RecipeOperatingMode = currentRecipeOperation;
  387. }
  388. VpwCellPersistentManager.Instance.UpdatePersistentValue(Module);
  389. return true;
  390. }
  391. /// <summary>
  392. /// ProductionAction
  393. /// </summary>
  394. /// <param name="cmd"></param>
  395. /// <param name="param"></param>
  396. /// <returns></returns>
  397. private bool ProductionModeOperation(string cmd, object[] args)
  398. {
  399. string currentRecipeOperation = "Production";
  400. if (_vpwCellPersistentValue != null)
  401. {
  402. _vpwCellPersistentValue.RecipeOperatingMode = currentRecipeOperation;
  403. }
  404. VpwCellPersistentManager.Instance.UpdatePersistentValue(Module);
  405. return true;
  406. }
  407. #endregion
  408. #region Vent Valve
  409. /// <summary>
  410. /// Vent Valve On
  411. /// </summary>
  412. /// <returns></returns>
  413. public bool VentValveOn()
  414. {
  415. return WriteVariableValue(VENT_VALVE, true);
  416. }
  417. /// <summary>
  418. /// Vent Valve Off
  419. /// </summary>
  420. /// <returns></returns>
  421. public bool VentValveOff()
  422. {
  423. return WriteVariableValue(VENT_VALVE, false);
  424. }
  425. #endregion
  426. #region Drain Valve
  427. /// <summary>
  428. /// Drain Valve On
  429. /// </summary>
  430. /// <returns></returns>
  431. public bool DrainValveOn()
  432. {
  433. return WriteVariableValue(DRAIN_VALVE, true);
  434. }
  435. /// <summary>
  436. /// Drain Valve Off
  437. /// </summary>
  438. /// <returns></returns>
  439. public bool DrainValveOff()
  440. {
  441. return WriteVariableValue(DRAIN_VALVE, false);
  442. }
  443. #endregion
  444. #region Vacuum
  445. /// <summary>
  446. /// Vacuum valve on
  447. /// </summary>
  448. /// <returns></returns>
  449. public bool VacuumValveOn()
  450. {
  451. return WriteVariableValue(VACUUM_VALVE, true);
  452. }
  453. /// <summary>
  454. /// Vacuum valve off
  455. /// </summary>
  456. /// <returns></returns>
  457. public bool VacuumValveOff()
  458. {
  459. return WriteVariableValue(VACUUM_VALVE, false);
  460. }
  461. #endregion
  462. /// <summary>
  463. /// 写变量
  464. /// </summary>
  465. /// <param name="variable"></param>
  466. /// <param name="value"></param>
  467. /// <returns></returns>
  468. private bool WriteVariableValue(string variable, object value)
  469. {
  470. string ioName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{variable}");
  471. return IOModuleManager.Instance.WriteIoValue(ioName, value);
  472. }
  473. #endregion
  474. #region Axis
  475. /// <summary>
  476. /// 电机是否上电
  477. /// </summary>
  478. /// <returns></returns>
  479. public bool CheckRotationSwitchOn()
  480. {
  481. return _rotationAxis.IsSwitchOn;
  482. }
  483. /// <summary>
  484. /// Home rotation
  485. /// </summary>
  486. /// <returns></returns>
  487. public bool HomeRotation()
  488. {
  489. return _rotationAxis.Home();
  490. }
  491. /// <summary>
  492. /// 检验Rotation Home结果
  493. /// </summary>
  494. /// <returns></returns>
  495. public bool CheckHomeEndStatus()
  496. {
  497. return CheckRotationEndStatus() && _rotationAxis.IsHomed;
  498. }
  499. /// <summary>
  500. /// 检验Rotation结束状态
  501. /// </summary>
  502. /// <returns></returns>
  503. public bool CheckRotationEndStatus()
  504. {
  505. return _rotationAxis.Status == PunkHPX8_Core.RState.End;
  506. }
  507. /// <summary>
  508. /// 检验Rotation失败状态
  509. /// </summary>
  510. /// <returns></returns>
  511. public bool CheckRotationStopStatus()
  512. {
  513. return _rotationAxis.Status == PunkHPX8_Core.RState.Failed;
  514. }
  515. /// <summary>
  516. /// 设置速度
  517. /// </summary>
  518. /// <param name="speed"></param>
  519. /// <returns></returns>
  520. public bool SetRotationSpeed(int speed)
  521. {
  522. _rotationAxis.SetProfileSpeed(speed);
  523. return true;
  524. }
  525. /// <summary>
  526. /// 改变速度
  527. /// </summary>
  528. /// <param name="speed"></param>
  529. /// <returns></returns>
  530. public bool ChangeRotationSpeed(int speed)
  531. {
  532. return _rotationAxis.ChangeSpeed(speed);
  533. }
  534. /// <summary>
  535. /// 电机运动
  536. /// </summary>
  537. /// <param name="position"></param>
  538. /// <returns></returns>
  539. public bool RotationProfilePosition(double position)
  540. {
  541. return _rotationAxis.ProfilePositionOperation(position);
  542. }
  543. /// <summary>
  544. /// 停止运动
  545. /// </summary>
  546. /// <returns></returns>
  547. public bool StopProfilePosition()
  548. {
  549. return _rotationAxis.StopPositionOperation();
  550. }
  551. /// <summary>
  552. /// 是否Rotation运动
  553. /// </summary>
  554. /// <returns></returns>
  555. public bool CheckRotationRunning()
  556. {
  557. return _rotationAxis.IsRun;
  558. }
  559. #endregion
  560. /// <summary>
  561. /// 定时器
  562. /// </summary>
  563. /// <returns></returns>
  564. public bool OnTimer()
  565. {
  566. if (_rotationAxis != null)
  567. {
  568. _rotationAxis.OnTimer();
  569. }
  570. return true;
  571. }
  572. /// <summary>
  573. /// 监控
  574. /// </summary>
  575. public void Monitor()
  576. {
  577. }
  578. public void Reset()
  579. {
  580. }
  581. public void Terminate()
  582. {
  583. }
  584. }
  585. }