PlatingCellDevice.cs 14 KB

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