PlatingCellDevice.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445
  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.Persistent.Reservoirs;
  7. using MECF.Framework.Common.ToolLayout;
  8. using PunkHPX8_Core;
  9. using PunkHPX8_RT.Devices.LinMot;
  10. using PunkHPX8_RT.Devices.PowerSupplier;
  11. using PunkHPX8_RT.Modules;
  12. using System;
  13. using System.Collections.Generic;
  14. using System.Linq;
  15. using System.Text;
  16. using System.Threading.Tasks;
  17. namespace PunkHPX8_RT.Devices.PlatingCell
  18. {
  19. public class PlatingCellDevice : BaseDevice, IDevice
  20. {
  21. #region 常量
  22. private const string PERSISTENT_VALUE = "PersistentValue";
  23. private const string AUTO = "Auto";
  24. private const string MANUAL = "Manual";
  25. private const string STRATUS = "Stratus";
  26. private const string DISABLED = "Disabled";
  27. #endregion
  28. #region 内部变量
  29. /// <summary>
  30. /// 操作当前状态
  31. /// </summary>
  32. protected RState _status;
  33. /// <summary>
  34. /// 持久化数据
  35. /// </summary>
  36. protected PlatingCellPersistentValue _persistentValue;
  37. /// <summary>
  38. /// A面PowerSupplier
  39. /// </summary>
  40. protected CellPowerSupplier _sideAPowerSupplier;
  41. /// <summary>
  42. /// B面PowerSupplier
  43. /// </summary>
  44. protected CellPowerSupplier _sideBPowerSupplier;
  45. /// <summary>
  46. /// Linmot
  47. /// </summary>
  48. protected LinMotAxis _linmotAxis;
  49. /// <summary>
  50. /// PlatingCell项
  51. /// </summary>
  52. private PlatingCellItem _platingCellItem;
  53. #endregion
  54. #region 属性
  55. /// <summary>
  56. /// 状态
  57. /// </summary>
  58. public RState Status { get { return _status; } }
  59. /// <summary>
  60. /// 是否禁用
  61. /// </summary>
  62. public bool IsDisable { get { return _persistentValue == null || _persistentValue.OperatingMode == DISABLED; } }
  63. /// <summary>
  64. /// 操作模式
  65. /// </summary>
  66. public string OperationMode { get { return _persistentValue.OperatingMode; } }
  67. /// <summary>
  68. /// 工程模式
  69. /// </summary>
  70. public string EngineerMode { get { return _persistentValue.RecipeOperatingMode; } }
  71. /// <summary>
  72. /// A面PowerSupplier
  73. /// </summary>
  74. public CellPowerSupplier SideAPowerSupplier { get { return _sideAPowerSupplier; } }
  75. /// <summary>
  76. /// B面PowerSupplier
  77. /// </summary>
  78. public CellPowerSupplier SideBPowerSupplier { get { return _sideBPowerSupplier; } }
  79. /// <summary>
  80. /// 是否为Auto
  81. /// </summary>
  82. public bool IsAuto { get { return _persistentValue != null ? _persistentValue.OperatingMode == AUTO : false; } }
  83. /// <summary>
  84. /// 是否为Auto
  85. /// </summary>
  86. public bool IsManual { get { return _persistentValue != null ? _persistentValue.OperatingMode == MANUAL : false; } }
  87. /// <summary>
  88. /// linmot motor on
  89. /// </summary>
  90. public bool IsLinmotMotorOn { get { return _linmotAxis != null ? _linmotAxis.IsMotorOn : false; } }
  91. /// <summary>
  92. /// Linmot当前位置
  93. /// </summary>
  94. public double LinmotPosition { get { return _linmotAxis != null ? _linmotAxis.CurrentPosition : 0; } }
  95. #endregion
  96. /// <summary>
  97. /// 构造函数
  98. /// </summary>
  99. /// <param name="moduleName"></param>
  100. public PlatingCellDevice(string moduleName) : base(moduleName, moduleName, moduleName, moduleName)
  101. {
  102. }
  103. /// <summary>
  104. /// 初始化
  105. /// </summary>
  106. /// <returns></returns>
  107. public virtual bool Initialize()
  108. {
  109. InitializeParameter();
  110. SubscribeData();
  111. InitializeOperation();
  112. return true;
  113. }
  114. /// <summary>
  115. /// 定时器执行
  116. /// </summary>
  117. public virtual bool OnTimer(int interval)
  118. {
  119. return true;
  120. }
  121. /// <summary>
  122. /// 初始化参数
  123. /// </summary>
  124. private void InitializeParameter()
  125. {
  126. _persistentValue = PlatingCellPersistentManager.Instance.GetPlatingCellPersistentValue(Module);
  127. if (_persistentValue == null)
  128. {
  129. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, "Persistent Value Object is not exist");
  130. }
  131. _platingCellItem = PlatingCellItemManager.Instance.GetPlatingCellItem(Module);
  132. if (_platingCellItem != null)
  133. {
  134. _sideAPowerSupplier = DEVICE.GetDevice<CellPowerSupplier>(_platingCellItem.PlatingPowerSupplyAID);
  135. _sideBPowerSupplier = DEVICE.GetDevice<CellPowerSupplier>(_platingCellItem.PlatingPowerSupplyBID);
  136. _linmotAxis = DEVICE.GetDevice<LinMotAxis>(_platingCellItem.LinmotID);
  137. }
  138. }
  139. /// <summary>
  140. /// 订阅数据
  141. /// </summary>
  142. private void SubscribeData()
  143. {
  144. DATA.Subscribe($"{Module}.{PERSISTENT_VALUE}", () => _persistentValue, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  145. DATA.Subscribe($"{Module}.SideAPowerSupplierData", () => _sideAPowerSupplier.PowerSupplierData, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  146. DATA.Subscribe($"{Module}.SideBPowerSupplierData", () => _sideBPowerSupplier.PowerSupplierData, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  147. DATA.Subscribe($"{Module}.SideAPowerSupplier.ID", () => _sideAPowerSupplier.Module, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  148. DATA.Subscribe($"{Module}.SideAPowerSupplier.IsConnected", () => _sideAPowerSupplier.IsConnected, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  149. DATA.Subscribe($"{Module}.SideAPowerSupplier.Voltage", () => _sideAPowerSupplier.PowerSupplierData.Voltage, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  150. DATA.Subscribe($"{Module}.SideAPowerSupplier.Current", () => _sideAPowerSupplier.PowerSupplierData.Current, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  151. DATA.Subscribe($"{Module}.SideAPowerSupplier.SetPoint", () => _sideAPowerSupplier.PowerSupplierData.SetPoint, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  152. DATA.Subscribe($"{Module}.SideAPowerSupplier.RunModel", () => _sideAPowerSupplier.PowerSupplierData.PowerRunModelContent, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  153. DATA.Subscribe($"{Module}.SideAPowerSupplier.PowerControl", () => _sideAPowerSupplier.PowerSupplierData.PowerControlContent, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  154. DATA.Subscribe($"{Module}.SideAPowerSupplier.PowerStatus", () => _sideAPowerSupplier.PowerSupplierData.PowerStatusContent, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  155. DATA.Subscribe($"{Module}.SideAPowerSupplier.Enable", () => _sideBPowerSupplier.PowerSupplierData.Enabled, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  156. DATA.Subscribe($"{Module}.SideBPowerSupplier.ID", () => _sideBPowerSupplier.Module, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  157. DATA.Subscribe($"{Module}.SideBPowerSupplier.IsConnected", () => _sideAPowerSupplier.IsConnected, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  158. DATA.Subscribe($"{Module}.SideBPowerSupplier.Voltage", () => _sideBPowerSupplier.PowerSupplierData.Voltage, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  159. DATA.Subscribe($"{Module}.SideBPowerSupplier.Current", () => _sideBPowerSupplier.PowerSupplierData.Current, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  160. DATA.Subscribe($"{Module}.SideBPowerSupplier.SetPoint", () => _sideBPowerSupplier.PowerSupplierData.SetPoint, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  161. DATA.Subscribe($"{Module}.SideBPowerSupplier.RunModel", () => _sideBPowerSupplier.PowerSupplierData.PowerRunModelContent, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  162. DATA.Subscribe($"{Module}.SideBPowerSupplier.PowerControl", () => _sideBPowerSupplier.PowerSupplierData.PowerControlContent, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  163. DATA.Subscribe($"{Module}.SideBPowerSupplier.PowerStatus", () => _sideBPowerSupplier.PowerSupplierData.PowerStatusContent, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  164. DATA.Subscribe($"{Module}.SideBPowerSupplier.Enable", () => _sideBPowerSupplier.PowerSupplierData.Enabled, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  165. DATA.Subscribe($"{Module}.Linmot.ID", () => _linmotAxis.Module, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  166. DATA.Subscribe($"{Module}.Linmot.IsMotorOn", () => _linmotAxis.IsMotorOn, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  167. DATA.Subscribe($"{Module}.Linmot.IsError", () => _linmotAxis.IsError, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  168. DATA.Subscribe($"{Module}.Linmot.IsSwitchOn", () => _linmotAxis.IsSwitchOn, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  169. DATA.Subscribe($"{Module}.Linmot.CurveSpeed", () => _linmotAxis.CurveSpeed, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  170. DATA.Subscribe($"{Module}.Linmot.ErrorCode", () => _linmotAxis.ErrorCode, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  171. DATA.Subscribe($"{Module}.Linmot.CurrentPosition", () => _linmotAxis.CurrentPosition, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  172. }
  173. /// <summary>
  174. /// 初始化操作
  175. /// </summary>
  176. protected virtual void InitializeOperation()
  177. {
  178. OP.Subscribe($"{Module}.DisabledAction", DisabledOperation);
  179. OP.Subscribe($"{Module}.ManualAction", ManualOperation);
  180. OP.Subscribe($"{Module}.AutoAction", AutoOperation);
  181. OP.Subscribe($"{Module}.EngineeringModeAction", EngineeringModeOperation);
  182. OP.Subscribe($"{Module}.ProductionModeAction", ProductionModeOperation);
  183. OP.Subscribe($"{Module}.SetPlatingCellWaferSize", (cmd, args) => { return SetPlatingCellWaferSize(cmd, args); });
  184. }
  185. /// <summary>
  186. /// 开始Curve
  187. /// </summary>
  188. /// <param name="speed"></param>
  189. /// <returns></returns>
  190. public bool StartCurveMotion(int speed)
  191. {
  192. if (_linmotAxis != null)
  193. {
  194. return _linmotAxis.StartCurve(speed);
  195. }
  196. else
  197. {
  198. LOG.WriteLog(eEvent.ERR_METAL, Module, "linmot is null");
  199. return false;
  200. }
  201. }
  202. /// <summary>
  203. /// 开始Curve
  204. /// </summary>
  205. /// <param name="speed"></param>
  206. /// <returns></returns>
  207. public bool ChangeCurveSpeedMotion(int speed)
  208. {
  209. if (_linmotAxis != null)
  210. {
  211. return _linmotAxis.ChangeCurveSpeed(speed);
  212. }
  213. else
  214. {
  215. LOG.WriteLog(eEvent.ERR_METAL, Module, "linmot is null");
  216. return false;
  217. }
  218. }
  219. /// <summary>
  220. /// ResetLinmot
  221. /// </summary>
  222. /// <returns></returns>
  223. public bool ResetLinmot()
  224. {
  225. if (_linmotAxis != null)
  226. {
  227. return _linmotAxis.ResetOperation("", false);
  228. }
  229. else
  230. {
  231. LOG.WriteLog(eEvent.ERR_METAL, Module, "linmot is null");
  232. return false;
  233. }
  234. }
  235. /// <summary>
  236. /// 检验Linmot Routine状态是否为结束状态
  237. /// </summary>
  238. /// <returns></returns>
  239. public bool CheckLinmotRoutineEnd()
  240. {
  241. if (_linmotAxis != null)
  242. {
  243. return _linmotAxis.Status == RState.End;
  244. }
  245. else
  246. {
  247. LOG.WriteLog(eEvent.ERR_METAL, Module, "linmot is null");
  248. return false;
  249. }
  250. }
  251. /// <summary>
  252. /// 检验Linmot Routine状态是否为错误状态
  253. /// </summary>
  254. /// <returns></returns>
  255. public bool CheckLinmotRoutineError()
  256. {
  257. if (_linmotAxis != null)
  258. {
  259. return _linmotAxis.Status == RState.Failed || _linmotAxis.Status == RState.Timeout;
  260. }
  261. else
  262. {
  263. return false;
  264. }
  265. }
  266. /// <summary>
  267. /// 停止Linmot
  268. /// </summary>
  269. /// <returns></returns>
  270. public bool StopLinmot()
  271. {
  272. if (_linmotAxis != null)
  273. {
  274. return _linmotAxis.StopOperation("", null);
  275. }
  276. else
  277. {
  278. LOG.WriteLog(eEvent.ERR_METAL, Module, "linmot is null");
  279. return false;
  280. }
  281. }
  282. #region Operation
  283. /// <summary>
  284. /// DisabledAction
  285. /// </summary>
  286. /// <param name="cmd"></param>
  287. /// <param name="param"></param>
  288. /// <returns></returns>
  289. public bool DisabledOperation(string cmd, object[] args)
  290. {
  291. //string currentOperation = "Disabled";
  292. //MetalEntity metalEntity = Singleton<RouteManager>.Instance.GetModule<MetalEntity>(Module);
  293. //if (metalEntity != null && _persistentValue != null && _persistentValue.OperatingMode != currentOperation)
  294. //{
  295. // string preOperation = _persistentValue.OperatingMode;
  296. // if (metalEntity.IsBusy)
  297. // {
  298. // LOG.WriteLog(eEvent.ERR_METAL, Module, $"{Module} is Busy, can't switch to Disabled mode");
  299. // return false;
  300. // }
  301. // if (SchedulerMetalTimeManager.Instance.Contained(Module))
  302. // {
  303. // LOG.WriteLog(eEvent.ERR_METAL, Module, $"{Module} is in scheduler, can't switch to Disabled mode");
  304. // return false;
  305. // }
  306. // metalEntity.EnterInit();
  307. // _persistentValue.OperatingMode = currentOperation;
  308. // LOG.WriteLog(eEvent.INFO_METAL, Module, $"Operating mode is switched from {preOperation} to {currentOperation}");
  309. //}
  310. //MetalPersistentManager.Instance.UpdatePersistentValue(Module);
  311. return true;
  312. }
  313. /// <summary>
  314. /// ManualAction
  315. /// </summary>
  316. /// <param name="cmd"></param>
  317. /// <param name="param"></param>
  318. /// <returns></returns>
  319. public bool ManualOperation(string cmd, object[] args)
  320. {
  321. //string currentOperation = "Manual";
  322. //MetalEntity metalEntity = Singleton<RouteManager>.Instance.GetModule<MetalEntity>(Module);
  323. //if (metalEntity != null && _persistentValue != null && _persistentValue.OperatingMode != currentOperation)
  324. //{
  325. // string preOperation = _persistentValue.OperatingMode;
  326. // if (metalEntity.IsBusy)
  327. // {
  328. // LOG.WriteLog(eEvent.ERR_METAL, Module, $"{Module} is Busy, can't switch to Manual mode");
  329. // return false;
  330. // }
  331. // if (SchedulerMetalTimeManager.Instance.Contained(Module))
  332. // {
  333. // LOG.WriteLog(eEvent.ERR_METAL, Module, $"{Module} is in scheduler, can't switch to Manual mode");
  334. // return false;
  335. // }
  336. // metalEntity.EnterInit();
  337. // _persistentValue.OperatingMode = currentOperation;
  338. // LOG.WriteLog(eEvent.INFO_METAL, Module, $"Operating mode is switched from {preOperation} to {currentOperation}");
  339. //}
  340. //MetalPersistentManager.Instance.UpdatePersistentValue(Module);
  341. return true;
  342. }
  343. /// <summary>
  344. /// AutoAction
  345. /// </summary>
  346. /// <param name="cmd"></param>
  347. /// <param name="param"></param>
  348. /// <returns></returns>
  349. public bool AutoOperation(string cmd, object[] args)
  350. {
  351. //string currentOperation = "Auto";
  352. //MetalEntity metalEntity = Singleton<RouteManager>.Instance.GetModule<MetalEntity>(Module);
  353. //if (metalEntity != null && _persistentValue != null && _persistentValue.OperatingMode != currentOperation)
  354. //{
  355. // string preOperation = _persistentValue.OperatingMode;
  356. // if (metalEntity.IsBusy)
  357. // {
  358. // LOG.WriteLog(eEvent.ERR_METAL, Module, $"{Module} is Busy, can't switch to Auto mode");
  359. // return false;
  360. // }
  361. // metalEntity.EnterInit();
  362. // _persistentValue.OperatingMode = currentOperation;
  363. // LOG.WriteLog(eEvent.INFO_METAL, Module, $"Operating mode is switched from {preOperation} to {currentOperation}");
  364. //}
  365. //MetalPersistentManager.Instance.UpdatePersistentValue(Module);
  366. return true;
  367. }
  368. /// <summary>
  369. /// EngineeringModeAction
  370. /// </summary>
  371. /// <param name="cmd"></param>
  372. /// <param name="param"></param>
  373. /// <returns></returns>
  374. private bool EngineeringModeOperation(string cmd, object[] args)
  375. {
  376. string currentRecipeOperation = "Engineering";
  377. if (_persistentValue != null)
  378. {
  379. _persistentValue.RecipeOperatingMode = currentRecipeOperation;
  380. }
  381. PlatingCellPersistentManager.Instance.UpdatePersistentValue(Module);
  382. return true;
  383. }
  384. /// <summary>
  385. /// ProductionAction
  386. /// </summary>
  387. /// <param name="cmd"></param>
  388. /// <param name="param"></param>
  389. /// <returns></returns>
  390. private bool ProductionModeOperation(string cmd, object[] args)
  391. {
  392. string currentRecipeOperation = "Production";
  393. if (_persistentValue != null)
  394. {
  395. _persistentValue.RecipeOperatingMode = currentRecipeOperation;
  396. }
  397. PlatingCellPersistentManager.Instance.UpdatePersistentValue(Module);
  398. return true;
  399. }
  400. private bool SetPlatingCellWaferSize(string cmd, object[] args)
  401. {
  402. string metalWaferSize = args[0] as string;
  403. if (_persistentValue != null)
  404. {
  405. _persistentValue.PlatingCellWaferSize = int.Parse(metalWaferSize);
  406. }
  407. PlatingCellPersistentManager.Instance.UpdatePersistentValue(Module);
  408. return true;
  409. }
  410. #endregion
  411. public virtual void Monitor()
  412. {
  413. }
  414. public virtual void Reset()
  415. {
  416. }
  417. public virtual void Terminate()
  418. {
  419. }
  420. }
  421. }