PlatingCellDevice.cs 16 KB

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