PlatingCellDevice.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463
  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.SCCore;
  6. using Aitex.Core.Util;
  7. using MECF.Framework.Common.Beckhoff.ModuleIO;
  8. using MECF.Framework.Common.CommonData.Metal;
  9. using MECF.Framework.Common.CommonData.PlatingCell;
  10. using MECF.Framework.Common.CommonData.Reservoir;
  11. using MECF.Framework.Common.IOCore;
  12. using MECF.Framework.Common.Persistent.Reservoirs;
  13. using MECF.Framework.Common.ToolLayout;
  14. using PunkHPX8_Core;
  15. using PunkHPX8_RT.Devices.LinMot;
  16. using PunkHPX8_RT.Devices.PowerSupplier;
  17. using PunkHPX8_RT.Devices.Reservoir;
  18. using PunkHPX8_RT.Modules;
  19. using PunkHPX8_RT.Modules.PlatingCell;
  20. using System;
  21. using System.Collections.Generic;
  22. using System.Linq;
  23. using System.Reflection;
  24. using System.Text;
  25. using System.Threading.Tasks;
  26. namespace PunkHPX8_RT.Devices.PlatingCell
  27. {
  28. public class PlatingCellDevice : BaseDevice, IDevice
  29. {
  30. #region 常量
  31. private const string PERSISTENT_VALUE = "PersistentValue";
  32. private const string PLATINGCELLDATA = "PlatingCellData";
  33. private const string AUTO = "Auto";
  34. private const string MANUAL = "Manual";
  35. private const string STRATUS = "Stratus";
  36. private const string DISABLED = "Disabled";
  37. private const string IS_HEAD_TILT = "IsHeadTilt";
  38. private const string IS_HEAD_VERTICAL = "IsHeadVertical";
  39. private const string CLAMSHELL_DISTANCE = "ClamShellDistance";
  40. private const string CLAMSHELL_CYLINDER_PRESSURE = "ClamShellCylinderPressure";
  41. private const string OVERFLOW_LEVEL = "OverFlowLevel";
  42. private const string CLAMSHELL_CLOSE = "ClamShellClose";
  43. private const string HEAD_TILT = "HeadTilt";
  44. #endregion
  45. #region 内部变量
  46. /// 变量是否初始化字典
  47. /// </summary>
  48. private Dictionary<string, bool> _variableInitializeDic = new Dictionary<string, bool>();
  49. /// <summary>
  50. /// 操作当前状态
  51. /// </summary>
  52. protected RState _status;
  53. /// <summary>
  54. /// 持久化数据
  55. /// </summary>
  56. protected PlatingCellPersistentValue _persistentValue;
  57. /// <summary>
  58. /// PlatingCell项
  59. /// </summary>
  60. private PlatingCellItem _platingCellItem;
  61. /// <summary>
  62. /// overflow
  63. /// </summary>
  64. private int _overflowLevelHigh = 85;
  65. private int _overflowLevelLow = 25;
  66. /// <summary>
  67. /// 对应reservoir的名字
  68. /// </summary>
  69. private string _reservoirName;
  70. #endregion
  71. #region 属性
  72. /// <summary>
  73. /// 状态
  74. /// </summary>
  75. public RState Status { get { return _status; } }
  76. /// <summary>
  77. /// 是否禁用
  78. /// </summary>
  79. public bool IsDisable { get { return _persistentValue == null || _persistentValue.OperatingMode == DISABLED; } }
  80. /// <summary>
  81. /// 操作模式
  82. /// </summary>
  83. public string OperationMode { get { return _persistentValue.OperatingMode; } }
  84. /// <summary>
  85. /// 工程模式
  86. /// </summary>
  87. public string EngineerMode { get { return _persistentValue.RecipeOperatingMode; } }
  88. /// <summary>
  89. /// 是否为Auto
  90. /// </summary>
  91. public bool IsAuto { get { return _persistentValue != null ? _persistentValue.OperatingMode == AUTO : false; } }
  92. /// <summary>
  93. /// 是否为Auto
  94. /// </summary>
  95. public bool IsManual { get { return _persistentValue != null ? _persistentValue.OperatingMode == MANUAL : false; } }
  96. #endregion
  97. #region 共享变量
  98. /// <summary>
  99. /// 数据
  100. /// </summary>
  101. protected PlatingCellData _platingCellData = new PlatingCellData();
  102. /// <summary>
  103. /// 对应reservoir数据
  104. /// </summary>
  105. protected ReservoirData _reservoirData = new ReservoirData();
  106. #endregion
  107. #region 属性
  108. /// <summary>
  109. /// 设备数据
  110. /// </summary>
  111. public PlatingCellData PlatingCellDeviceData { get { return _platingCellData; } }
  112. #endregion
  113. /// <summary>
  114. /// 构造函数
  115. /// </summary>
  116. /// <param name="moduleName"></param>
  117. public PlatingCellDevice(string moduleName) : base(moduleName, moduleName, moduleName, moduleName)
  118. {
  119. }
  120. /// <summary>
  121. /// 初始化
  122. /// </summary>
  123. /// <returns></returns>
  124. public virtual bool Initialize()
  125. {
  126. InitializeParameter();
  127. SubscribeData();
  128. InitializeOperation();
  129. SubscribeValueAction();
  130. return true;
  131. }
  132. /// <summary>
  133. /// 定时器执行
  134. /// </summary>
  135. public virtual bool OnTimer(int interval)
  136. {
  137. return true;
  138. }
  139. /// <summary>
  140. /// 初始化参数
  141. /// </summary>
  142. private void InitializeParameter()
  143. {
  144. _persistentValue = PlatingCellPersistentManager.Instance.GetPlatingCellPersistentValue(Module);
  145. if (_persistentValue == null)
  146. {
  147. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, "Persistent Value Object is not exist");
  148. }
  149. _platingCellItem = PlatingCellItemManager.Instance.GetPlatingCellItem(Module);
  150. if (_platingCellItem != null)
  151. {
  152. }
  153. _overflowLevelHigh = SC.GetValue<int>($"PlatingCell.OverflowLevelHigh");
  154. _overflowLevelLow = SC.GetValue<int>($"PlatingCell.OverflowLevelLow");
  155. _reservoirData = GetReservoirDevice().ReservoirData;
  156. _reservoirName = GetReservoirDevice().Module;
  157. }
  158. protected virtual void SubscribeValueAction()
  159. {
  160. IoSubscribeUpdateVariable(IS_HEAD_TILT);
  161. IoSubscribeUpdateVariable(IS_HEAD_VERTICAL);
  162. IoSubscribeUpdateVariable(CLAMSHELL_DISTANCE);
  163. IoSubscribeUpdateVariable(CLAMSHELL_CYLINDER_PRESSURE);
  164. IoSubscribeUpdateVariable(OVERFLOW_LEVEL);
  165. IoSubscribeUpdateVariable(CLAMSHELL_CLOSE);
  166. IoSubscribeUpdateVariable(HEAD_TILT);
  167. }
  168. /// <summary>
  169. /// 订阅IO变量
  170. /// </summary>
  171. /// <param name="variable"></param>
  172. protected void IoSubscribeUpdateVariable(string variable)
  173. {
  174. _variableInitializeDic[variable] = false;
  175. IOModuleManager.Instance.SubscribeModuleVariable(Module, variable, UpdateVariableValue);
  176. }
  177. /// <summary>
  178. /// 更新变量数值
  179. /// </summary>
  180. /// <param name="variable"></param>
  181. /// <param name="value"></param>
  182. private void UpdateVariableValue(string variable, object value)
  183. {
  184. if (!_platingCellData.IsDataInitialized)
  185. {
  186. _platingCellData.IsDataInitialized = true;
  187. }
  188. PropertyInfo property = _platingCellData.GetType().GetProperty(variable);
  189. if (property != null)
  190. {
  191. property.SetValue(_platingCellData, value);
  192. if (variable == OVERFLOW_LEVEL)
  193. {
  194. double waterLevel = CurrentToWaterLevel(Convert.ToDouble(value));
  195. _platingCellData.OverFlowLevel = waterLevel;
  196. if (_platingCellData.OverFlowLevel >= _overflowLevelHigh)
  197. {
  198. _platingCellData.OverFlowStatus = "High";
  199. }
  200. else if(_platingCellData.OverFlowLevel <= _overflowLevelLow)
  201. {
  202. _platingCellData.OverFlowStatus = "Empty";
  203. }
  204. else
  205. {
  206. _platingCellData.OverFlowStatus = "Full";
  207. }
  208. }
  209. }
  210. if (_variableInitializeDic.ContainsKey(variable) && !_variableInitializeDic[variable])
  211. {
  212. _variableInitializeDic[variable] = true;
  213. }
  214. }
  215. /// <summary>
  216. /// 把电流mA转成水深mm
  217. /// </summary>
  218. /// <param name="current"></param>
  219. private double CurrentToWaterLevel(double current)
  220. {
  221. double result = (current - 4) / 8 / 9.8 * 1000;
  222. return result;
  223. }
  224. /// <summary>
  225. /// 写变量
  226. /// </summary>
  227. /// <param name="variable"></param>
  228. /// <param name="value"></param>
  229. /// <returns></returns>
  230. protected bool WriteVariableValue(string variable, object value)
  231. {
  232. string ioName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{variable}");
  233. return IOModuleManager.Instance.WriteIoValue(ioName, value);
  234. }
  235. /// <summary>
  236. /// 订阅数据
  237. /// </summary>
  238. private void SubscribeData()
  239. {
  240. DATA.Subscribe($"{Module}.{PERSISTENT_VALUE}", () => _persistentValue, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  241. DATA.Subscribe($"{Module}.{PLATINGCELLDATA}", () => _platingCellData, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  242. DATA.Subscribe($"{Module}.ReservoirCommonData", () => _reservoirData, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  243. DATA.Subscribe($"{Module}.ReservoirName", () => _reservoirName, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  244. }
  245. /// <summary>
  246. /// 初始化操作
  247. /// </summary>
  248. protected virtual void InitializeOperation()
  249. {
  250. OP.Subscribe($"{Module}.DisabledAction", DisabledOperation);
  251. OP.Subscribe($"{Module}.ManualAction", ManualOperation);
  252. OP.Subscribe($"{Module}.AutoAction", AutoOperation);
  253. OP.Subscribe($"{Module}.EngineeringModeAction", EngineeringModeOperation);
  254. OP.Subscribe($"{Module}.ProductionModeAction", ProductionModeOperation);
  255. OP.Subscribe($"{Module}.SetPlatingCellWaferSize", (cmd, args) => { return SetPlatingCellWaferSize(cmd, args); });
  256. OP.Subscribe($"{Module}.ClamShellClose", (cmd, para) => { return ClamShellClose(); });
  257. OP.Subscribe($"{Module}.ClamShellOpen", (cmd, para) => { return ClamShellOpen(); });
  258. OP.Subscribe($"{Module}.HeadtTilt", (cmd, para) => { return HeadtTiltAction(); });
  259. OP.Subscribe($"{Module}.HeadVertical", (cmd, para) => { return HeadtVerticalAction(); });
  260. }
  261. #region Operation
  262. public bool ClamShellClose()
  263. {
  264. return WriteVariableValue(CLAMSHELL_CLOSE, true);
  265. }
  266. public bool ClamShellOpen()
  267. {
  268. return WriteVariableValue(CLAMSHELL_CLOSE, false);
  269. }
  270. public bool HeadtTiltAction()
  271. {
  272. return WriteVariableValue(HEAD_TILT, true);
  273. }
  274. public bool HeadtVerticalAction()
  275. {
  276. return WriteVariableValue(HEAD_TILT, false);
  277. }
  278. /// <summary>
  279. /// DisabledAction
  280. /// </summary>
  281. /// <param name="cmd"></param>
  282. /// <param name="param"></param>
  283. /// <returns></returns>
  284. public bool DisabledOperation(string cmd, object[] args)
  285. {
  286. string currentOperation = "Disabled";
  287. PlatingCellEntity platingCellEntity = Singleton<RouteManager>.Instance.GetModule<PlatingCellEntity>(Module);
  288. if (platingCellEntity != null && _persistentValue != null && _persistentValue.OperatingMode != currentOperation)
  289. {
  290. string preOperation = _persistentValue.OperatingMode;
  291. if (platingCellEntity.IsBusy)
  292. {
  293. LOG.WriteLog(eEvent.ERR_METAL, Module, $"{Module} is Busy, can't switch to Disabled mode");
  294. return false;
  295. }
  296. //if (SchedulerMetalTimeManager.Instance.Contained(Module))
  297. //{
  298. // LOG.WriteLog(eEvent.ERR_METAL, Module, $"{Module} is in scheduler, can't switch to Disabled mode");
  299. // return false;
  300. //}
  301. platingCellEntity.EnterInit();
  302. _persistentValue.OperatingMode = currentOperation;
  303. LOG.WriteLog(eEvent.INFO_METAL, Module, $"Operating mode is switched from {preOperation} to {currentOperation}");
  304. }
  305. PlatingCellPersistentManager.Instance.UpdatePersistentValue(Module);
  306. return true;
  307. }
  308. /// <summary>
  309. /// ManualAction
  310. /// </summary>
  311. /// <param name="cmd"></param>
  312. /// <param name="param"></param>
  313. /// <returns></returns>
  314. public bool ManualOperation(string cmd, object[] args)
  315. {
  316. string currentOperation = "Manual";
  317. PlatingCellEntity platingCellEntity = Singleton<RouteManager>.Instance.GetModule<PlatingCellEntity>(Module);
  318. if (platingCellEntity != null && _persistentValue != null && _persistentValue.OperatingMode != currentOperation)
  319. {
  320. string preOperation = _persistentValue.OperatingMode;
  321. if (platingCellEntity.IsBusy)
  322. {
  323. LOG.WriteLog(eEvent.ERR_METAL, Module, $"{Module} is Busy, can't switch to Manual mode");
  324. return false;
  325. }
  326. //if (SchedulerMetalTimeManager.Instance.Contained(Module))
  327. //{
  328. // LOG.WriteLog(eEvent.ERR_METAL, Module, $"{Module} is in scheduler, can't switch to Manual mode");
  329. // return false;
  330. //}
  331. platingCellEntity.EnterInit();
  332. _persistentValue.OperatingMode = currentOperation;
  333. LOG.WriteLog(eEvent.INFO_METAL, Module, $"Operating mode is switched from {preOperation} to {currentOperation}");
  334. }
  335. PlatingCellPersistentManager.Instance.UpdatePersistentValue(Module);
  336. return true;
  337. }
  338. /// <summary>
  339. /// AutoAction
  340. /// </summary>
  341. /// <param name="cmd"></param>
  342. /// <param name="param"></param>
  343. /// <returns></returns>
  344. public bool AutoOperation(string cmd, object[] args)
  345. {
  346. string currentOperation = "Auto";
  347. PlatingCellEntity platingCellEntity = Singleton<RouteManager>.Instance.GetModule<PlatingCellEntity>(Module);
  348. if (platingCellEntity != null && _persistentValue != null && _persistentValue.OperatingMode != currentOperation)
  349. {
  350. string preOperation = _persistentValue.OperatingMode;
  351. if (platingCellEntity.IsBusy)
  352. {
  353. LOG.WriteLog(eEvent.ERR_METAL, Module, $"{Module} is Busy, can't switch to Auto mode");
  354. return false;
  355. }
  356. platingCellEntity.EnterInit();
  357. _persistentValue.OperatingMode = currentOperation;
  358. LOG.WriteLog(eEvent.INFO_METAL, Module, $"Operating mode is switched from {preOperation} to {currentOperation}");
  359. }
  360. PlatingCellPersistentManager.Instance.UpdatePersistentValue(Module);
  361. return true;
  362. }
  363. /// <summary>
  364. /// EngineeringModeAction
  365. /// </summary>
  366. /// <param name="cmd"></param>
  367. /// <param name="param"></param>
  368. /// <returns></returns>
  369. private bool EngineeringModeOperation(string cmd, object[] args)
  370. {
  371. string currentRecipeOperation = "Engineering";
  372. if (_persistentValue != null)
  373. {
  374. _persistentValue.RecipeOperatingMode = currentRecipeOperation;
  375. }
  376. PlatingCellPersistentManager.Instance.UpdatePersistentValue(Module);
  377. return true;
  378. }
  379. /// <summary>
  380. /// ProductionAction
  381. /// </summary>
  382. /// <param name="cmd"></param>
  383. /// <param name="param"></param>
  384. /// <returns></returns>
  385. private bool ProductionModeOperation(string cmd, object[] args)
  386. {
  387. string currentRecipeOperation = "Production";
  388. if (_persistentValue != null)
  389. {
  390. _persistentValue.RecipeOperatingMode = currentRecipeOperation;
  391. }
  392. PlatingCellPersistentManager.Instance.UpdatePersistentValue(Module);
  393. return true;
  394. }
  395. private bool SetPlatingCellWaferSize(string cmd, object[] args)
  396. {
  397. string metalWaferSize = args[0] as string;
  398. if (_persistentValue != null)
  399. {
  400. _persistentValue.PlatingCellWaferSize = int.Parse(metalWaferSize);
  401. }
  402. PlatingCellPersistentManager.Instance.UpdatePersistentValue(Module);
  403. return true;
  404. }
  405. /// <summary>
  406. /// 获取Reservoir设备
  407. /// </summary>
  408. /// <returns></returns>
  409. private ReservoirDevice GetReservoirDevice()
  410. {
  411. string reservoir = ReservoirItemManager.Instance.GetReservoirByPlatingCell(Module);
  412. return DEVICE.GetDevice<ReservoirDevice>(reservoir);
  413. }
  414. #endregion
  415. public virtual void Monitor()
  416. {
  417. }
  418. public virtual void Reset()
  419. {
  420. }
  421. public virtual void Terminate()
  422. {
  423. }
  424. }
  425. }