PlatingCellDevice.cs 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919
  1. using Aitex.Core.RT.DataCenter;
  2. using Aitex.Core.RT.Device;
  3. using Aitex.Core.RT.Event;
  4. using Aitex.Core.RT.Log;
  5. using Aitex.Core.RT.OperationCenter;
  6. using Aitex.Core.RT.Routine;
  7. using Aitex.Core.RT.SCCore;
  8. using Aitex.Core.Util;
  9. using MECF.Framework.Common.Beckhoff.ModuleIO;
  10. using MECF.Framework.Common.CommonData.PlatingCell;
  11. using MECF.Framework.Common.CommonData.Reservoir;
  12. using MECF.Framework.Common.Equipment;
  13. using MECF.Framework.Common.IOCore;
  14. using MECF.Framework.Common.Persistent.Reservoirs;
  15. using MECF.Framework.Common.ToolLayout;
  16. using MECF.Framework.RT.Core.Equipments;
  17. using PunkHPX8_Core;
  18. using PunkHPX8_RT.Devices.AXIS;
  19. using PunkHPX8_RT.Devices.Facilities;
  20. using PunkHPX8_RT.Devices.LinMot;
  21. using PunkHPX8_RT.Devices.PowerSupplier;
  22. using PunkHPX8_RT.Devices.Reservoir;
  23. using PunkHPX8_RT.Devices.SRD;
  24. using PunkHPX8_RT.Devices.VpwMain;
  25. using PunkHPX8_RT.Modules;
  26. using PunkHPX8_RT.Modules.PlatingCell;
  27. using PunkHPX8_RT.Modules.Reservoir;
  28. using System;
  29. using System.Collections.Generic;
  30. using System.Linq;
  31. using System.Reflection;
  32. using System.Text;
  33. using System.Threading.Tasks;
  34. using System.Windows.Media.Animation;
  35. namespace PunkHPX8_RT.Devices.PlatingCell
  36. {
  37. public class PlatingCellDevice : BaseDevice, IDevice
  38. {
  39. /// <summary>
  40. /// Srd操作枚举
  41. /// </summary>
  42. private enum PlatingCellCommonOperation
  43. {
  44. None,
  45. ClamShellClose,
  46. ClamShellOpen,
  47. BiRotation,
  48. }
  49. #region 常量
  50. private const string PERSISTENT_VALUE = "PersistentValue";
  51. private const string PLATINGCELLDATA = "PlatingCellData";
  52. private const string AUTO = "Auto";
  53. private const string MANUAL = "Manual";
  54. private const string STRATUS = "Stratus";
  55. private const string DISABLED = "Disabled";
  56. private const string IS_HEAD_TILT = "IsHeadTilt";
  57. private const string IS_HEAD_VERTICAL = "IsHeadVertical";
  58. private const string CLAMSHELL_DISTANCE = "ClamShellDistance";
  59. private const string CLAMSHELL_CYLINDER_PRESSURE = "ClamShellCylinderPressure";
  60. private const string OVERFLOW_LEVEL = "OverFlowLevel";
  61. private const string CLAMSHELL_CLOSE = "ClamShellClose";
  62. private const string HEAD_TILT = "HeadTilt";
  63. private const string CCR_ENABLE = "CCREnable";
  64. private const string RINSE_ENABLE = "RinseEnable";
  65. #endregion
  66. #region 内部变量
  67. /// <summary>
  68. /// 当前操作
  69. /// </summary>
  70. private PlatingCellCommonOperation _currentOperation;
  71. /// <summary>
  72. /// clamshell routine操作
  73. /// </summary>
  74. private ClamShellCloseRoutine _closeRoutine;
  75. /// <summary>
  76. /// 电机双向旋转操作
  77. /// </summary>
  78. private RotationBiDirectionRoutine _biDirectionRoutine;
  79. /// 变量是否初始化字典
  80. /// </summary>
  81. private Dictionary<string, bool> _variableInitializeDic = new Dictionary<string, bool>();
  82. /// <summary>
  83. /// 操作当前状态
  84. /// </summary>
  85. protected RState _status;
  86. /// <summary>
  87. /// 持久化数据
  88. /// </summary>
  89. protected PlatingCellPersistentValue _persistentValue;
  90. /// <summary>
  91. /// PlatingCell项
  92. /// </summary>
  93. private PlatingCellItem _platingCellItem;
  94. /// <summary>
  95. /// overflow
  96. /// </summary>
  97. private int _overflowLevelHigh = 85;
  98. private int _overflowLevelLow = 25;
  99. /// <summary>
  100. /// 对应reservoir的名字
  101. /// </summary>
  102. private string _reservoirName;
  103. /// <summary>
  104. /// PowerSupplier
  105. /// </summary>
  106. protected CellPowerSupplier _powerSupplier;
  107. /// <summary>
  108. /// vertical电机
  109. /// </summary>
  110. private JetAxisBase _verticalAxis;
  111. /// <summary>
  112. /// vertical电机
  113. /// </summary>
  114. private JetAxisBase _rotationAxis;
  115. /// <summary>
  116. /// CCR当前执行步骤
  117. /// </summary>
  118. private string _currentCCRStep = "";
  119. /// <summary>
  120. /// CCR当前剩余时间
  121. /// </summary>
  122. private double _timeRemain;
  123. /// <summary>
  124. /// 对应reservoir槽体化学液
  125. /// </summary>
  126. private string _reservoirChemistry;
  127. /// <summary>
  128. /// clamshell open sensor config
  129. /// </summary>
  130. private int _openSensor = 55;
  131. /// <summary>
  132. /// clamshell close sensor config
  133. /// </summary>
  134. private int _closeSensor = 5;
  135. #endregion
  136. #region 属性
  137. /// <summary>
  138. /// 状态
  139. /// </summary>
  140. public RState Status { get { return _status; } }
  141. /// <summary>
  142. /// 是否禁用
  143. /// </summary>
  144. public bool IsDisable { get { return _persistentValue == null || _persistentValue.OperatingMode == DISABLED; } }
  145. /// <summary>
  146. /// 操作模式
  147. /// </summary>
  148. public string OperationMode { get { return _persistentValue.OperatingMode; } }
  149. /// <summary>
  150. /// 工程模式
  151. /// </summary>
  152. public string EngineerMode { get { return _persistentValue.RecipeOperatingMode; } }
  153. /// <summary>
  154. /// 是否为Auto
  155. /// </summary>
  156. public bool IsAuto { get { return _persistentValue != null ? _persistentValue.OperatingMode == AUTO : false; } }
  157. /// <summary>
  158. /// 是否为Auto
  159. /// </summary>
  160. public bool IsManual { get { return _persistentValue != null ? _persistentValue.OperatingMode == MANUAL : false; } }
  161. /// <summary>
  162. /// PowerSupplier
  163. /// </summary>
  164. public CellPowerSupplier PowerSupplier { get { return _powerSupplier; } }
  165. #endregion
  166. #region 共享变量
  167. /// <summary>
  168. /// 数据
  169. /// </summary>
  170. protected PlatingCellData _platingCellData = new PlatingCellData();
  171. /// <summary>
  172. /// 对应reservoir数据
  173. /// </summary>
  174. protected ReservoirData _reservoirData = new ReservoirData();
  175. #endregion
  176. #region 共享属性
  177. /// <summary>
  178. /// 设备数据
  179. /// </summary>
  180. public PlatingCellData PlatingCellDeviceData { get { return _platingCellData; } }
  181. #endregion
  182. /// <summary>
  183. /// 构造函数
  184. /// </summary>
  185. /// <param name="moduleName"></param>
  186. public PlatingCellDevice(string moduleName) : base(moduleName, moduleName, moduleName, moduleName)
  187. {
  188. }
  189. /// <summary>
  190. /// 初始化
  191. /// </summary>
  192. /// <returns></returns>
  193. public virtual bool Initialize()
  194. {
  195. InitializeParameter();
  196. SubscribeData();
  197. InitializeOperation();
  198. SubscribeValueAction();
  199. InitializeRoutine();
  200. return true;
  201. }
  202. /// <summary>
  203. /// 初始化Routine
  204. /// </summary>
  205. private void InitializeRoutine()
  206. {
  207. _closeRoutine = new ClamShellCloseRoutine(Module);
  208. _biDirectionRoutine = new RotationBiDirectionRoutine(Module);
  209. }
  210. /// <summary>
  211. /// 定时器执行
  212. /// </summary>
  213. public bool OnTimer(int interval)
  214. {
  215. if (_verticalAxis != null)
  216. {
  217. _verticalAxis.OnTimer();
  218. }
  219. else
  220. {
  221. if ("PlatingCell1".Equals(Module) || "PlatingCell2".Equals(Module))
  222. {
  223. _verticalAxis = DEVICE.GetDevice<JetAxisBase>("PlatingCell1_2.Vertical");
  224. }
  225. else
  226. {
  227. _verticalAxis = DEVICE.GetDevice<JetAxisBase>("PlatingCell3_4.Vertical");
  228. }
  229. }
  230. if (_rotationAxis != null)
  231. {
  232. _rotationAxis.OnTimer();
  233. }
  234. if (_status == RState.Running)
  235. {
  236. if (_currentOperation != PlatingCellCommonOperation.None)
  237. {
  238. IRoutine routine = GetCurrentRoutine(_currentOperation);
  239. if (routine != null)
  240. {
  241. CheckRoutineState(routine, _currentOperation);
  242. }
  243. else
  244. {
  245. EndOperation();
  246. }
  247. }
  248. }
  249. return true;
  250. }
  251. /// <summary>
  252. /// 获取当前操作对应的Routine
  253. /// </summary>
  254. /// <param name="currentOperation"></param>
  255. /// <returns></returns>
  256. private IRoutine GetCurrentRoutine(PlatingCellCommonOperation currentOperation)
  257. {
  258. switch (currentOperation)
  259. {
  260. case PlatingCellCommonOperation.ClamShellOpen:
  261. case PlatingCellCommonOperation.ClamShellClose:
  262. return _closeRoutine;
  263. case PlatingCellCommonOperation.BiRotation:
  264. return _biDirectionRoutine;
  265. default:
  266. return null;
  267. }
  268. }
  269. /// <summary>
  270. /// 检验Routine状态
  271. /// </summary>
  272. /// <param name="routine"></param>
  273. /// <param name="currentOperation"></param>
  274. private void CheckRoutineState(IRoutine routine, PlatingCellCommonOperation currentOperation)
  275. {
  276. RState state = routine.Monitor();
  277. if (state == RState.End)
  278. {
  279. EndOperation();
  280. }
  281. else if (state == RState.Failed || state == RState.Timeout)
  282. {
  283. LOG.WriteLog(eEvent.ERR_SRD, $"{Module}", $"{currentOperation} error");
  284. _status = RState.Failed;
  285. _currentOperation = PlatingCellCommonOperation.None;
  286. }
  287. }
  288. /// <summary>
  289. /// 结束操作
  290. /// </summary>
  291. private void EndOperation()
  292. {
  293. _status = RState.End;
  294. _currentOperation = PlatingCellCommonOperation.None;
  295. }
  296. /// <summary>
  297. /// 初始化参数
  298. /// </summary>
  299. private void InitializeParameter()
  300. {
  301. _persistentValue = PlatingCellPersistentManager.Instance.GetPlatingCellPersistentValue(Module);
  302. if (_persistentValue == null)
  303. {
  304. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, "Persistent Value Object is not exist");
  305. }
  306. _platingCellItem = PlatingCellItemManager.Instance.GetPlatingCellItem(Module);
  307. if (_platingCellItem != null)
  308. {
  309. }
  310. _platingCellItem = PlatingCellItemManager.Instance.GetPlatingCellItem(Module);
  311. if (_platingCellItem != null)
  312. {
  313. _powerSupplier = DEVICE.GetDevice<CellPowerSupplier>(_platingCellItem.PlatingPowerSupplyID);
  314. }
  315. _overflowLevelHigh = SC.GetValue<int>($"PlatingCell.OverflowLevelHigh");
  316. _overflowLevelLow = SC.GetValue<int>($"PlatingCell.OverflowLevelLow");
  317. _openSensor = SC.GetValue<int>("PlatingCell.ClamShellOpenDistanceThreshold");
  318. _closeSensor = SC.GetValue<int>("PlatingCell.ClamShellCloseDistanceThreshold");
  319. _reservoirData = GetReservoirDevice().ReservoirData;
  320. _reservoirName = GetReservoirDevice().Module;
  321. _rotationAxis = DEVICE.GetDevice<JetAxisBase>($"{Module}.Rotation");
  322. }
  323. protected virtual void SubscribeValueAction()
  324. {
  325. IoSubscribeUpdateVariable(IS_HEAD_TILT);
  326. IoSubscribeUpdateVariable(IS_HEAD_VERTICAL);
  327. IoSubscribeUpdateVariable(CLAMSHELL_DISTANCE);
  328. IoSubscribeUpdateVariable(CLAMSHELL_CYLINDER_PRESSURE);
  329. IoSubscribeUpdateVariable(OVERFLOW_LEVEL);
  330. IoSubscribeUpdateVariable(CLAMSHELL_CLOSE);
  331. IoSubscribeUpdateVariable(HEAD_TILT);
  332. IoSubscribeUpdateVariable(CCR_ENABLE);
  333. IoSubscribeUpdateVariable(RINSE_ENABLE);
  334. }
  335. /// <summary>
  336. /// 订阅IO变量
  337. /// </summary>
  338. /// <param name="variable"></param>
  339. protected void IoSubscribeUpdateVariable(string variable)
  340. {
  341. _variableInitializeDic[variable] = false;
  342. IOModuleManager.Instance.SubscribeModuleVariable(Module, variable, UpdateVariableValue);
  343. }
  344. /// <summary>
  345. /// 更新变量数值
  346. /// </summary>
  347. /// <param name="variable"></param>
  348. /// <param name="value"></param>
  349. private void UpdateVariableValue(string variable, object value)
  350. {
  351. if (!_platingCellData.IsDataInitialized)
  352. {
  353. _platingCellData.IsDataInitialized = true;
  354. }
  355. PropertyInfo property = _platingCellData.GetType().GetProperty(variable);
  356. if (property != null)
  357. {
  358. property.SetValue(_platingCellData, value);
  359. if (variable == OVERFLOW_LEVEL)
  360. {
  361. string LevelCurve = SC.GetStringValue($"PlatingCell.OverFlowLevelCurve");
  362. double waterLevel = PlatingCellOverflowLevelCurve.Instance.CalculateLevelByCurrent(Convert.ToDouble(value), LevelCurve);
  363. //double waterLevel = CurrentToWaterLevel(Convert.ToDouble(value));
  364. _platingCellData.OverFlowLevel = waterLevel;
  365. if (_platingCellData.OverFlowLevel >= _overflowLevelHigh)
  366. {
  367. _platingCellData.OverFlowStatus = "High";
  368. }
  369. else if(_platingCellData.OverFlowLevel <= _overflowLevelLow)
  370. {
  371. _platingCellData.OverFlowStatus = "Empty";
  372. }
  373. else
  374. {
  375. _platingCellData.OverFlowStatus = "Full";
  376. }
  377. }
  378. if(variable == CLAMSHELL_DISTANCE)
  379. {
  380. double distance = Convert.ToDouble(value);
  381. if(distance >= _closeSensor)
  382. {
  383. _platingCellData.ClamShellClosed = true;
  384. _platingCellData.ClamShellOpened = false;
  385. }
  386. if(distance <= _openSensor)
  387. {
  388. _platingCellData.ClamShellClosed = false;
  389. _platingCellData.ClamShellOpened = true;
  390. }
  391. }
  392. }
  393. if (_variableInitializeDic.ContainsKey(variable) && !_variableInitializeDic[variable])
  394. {
  395. _variableInitializeDic[variable] = true;
  396. }
  397. }
  398. /// <summary>
  399. /// 把电流mA转成水深mm
  400. /// </summary>
  401. /// <param name="current"></param>
  402. private double CurrentToWaterLevel(double current)
  403. {
  404. double result = (current - 4) / 8 / 9.8 * 1000;
  405. return result;
  406. }
  407. /// <summary>
  408. /// 写变量
  409. /// </summary>
  410. /// <param name="variable"></param>
  411. /// <param name="value"></param>
  412. /// <returns></returns>
  413. protected bool WriteVariableValue(string variable, object value)
  414. {
  415. string ioName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{variable}");
  416. return IOModuleManager.Instance.WriteIoValue(ioName, value);
  417. }
  418. /// <summary>
  419. /// 订阅数据
  420. /// </summary>
  421. private void SubscribeData()
  422. {
  423. DATA.Subscribe($"{Module}.{PERSISTENT_VALUE}", () => _persistentValue, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  424. DATA.Subscribe($"{Module}.{PLATINGCELLDATA}", () => _platingCellData, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  425. DATA.Subscribe($"{Module}.ReservoirCommonData", () => _reservoirData, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  426. DATA.Subscribe($"{Module}.ReservoirName", () => _reservoirName, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  427. DATA.Subscribe($"{Module}.CurrentCCRStep", () => _currentCCRStep, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  428. DATA.Subscribe($"{Module}.CurrentCCRTimeRemain", () => _timeRemain, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  429. DATA.Subscribe($"{Module}.ReservoirChemistry", () => _reservoirChemistry, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  430. DATA.Subscribe($"{Module}.PowerSupplierData", () => _powerSupplier.PowerSupplierData, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  431. DATA.Subscribe($"{Module}.PowerSupplier.ID", () => _powerSupplier.Module, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  432. DATA.Subscribe($"{Module}.PowerSupplier.IsConnected", () => _powerSupplier.IsConnected, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  433. DATA.Subscribe($"{Module}.PowerSupplier.Voltage", () => _powerSupplier.PowerSupplierData.Voltage, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  434. DATA.Subscribe($"{Module}.PowerSupplier.Current", () => _powerSupplier.PowerSupplierData.Current, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  435. DATA.Subscribe($"{Module}.PowerSupplier.SetPoint", () => _powerSupplier.PowerSupplierData.SetPoint, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  436. DATA.Subscribe($"{Module}.PowerSupplier.RunModel", () => _powerSupplier.PowerSupplierData.PowerRunModelContent, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  437. DATA.Subscribe($"{Module}.PowerSupplier.PowerControl", () => _powerSupplier.PowerSupplierData.PowerControlContent, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  438. DATA.Subscribe($"{Module}.PowerSupplier.PowerStatus", () => _powerSupplier.PowerSupplierData.PowerStatusContent, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  439. DATA.Subscribe($"{Module}.PowerSupplier.Enable", () => _powerSupplier.PowerSupplierData.Enabled, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  440. DATA.Subscribe($"{Module}.PowerSupplier.PowerGrade", () => _powerSupplier.PowerSupplierData.PowerGradeContent, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  441. }
  442. /// <summary>
  443. /// 初始化操作
  444. /// </summary>
  445. protected virtual void InitializeOperation()
  446. {
  447. OP.Subscribe($"{Module}.DisabledAction", DisabledOperation);
  448. OP.Subscribe($"{Module}.ManualAction", ManualOperation);
  449. OP.Subscribe($"{Module}.AutoAction", AutoOperation);
  450. OP.Subscribe($"{Module}.EngineeringModeAction", EngineeringModeOperation);
  451. OP.Subscribe($"{Module}.ProductionModeAction", ProductionModeOperation);
  452. OP.Subscribe($"{Module}.SetPlatingCellWaferSize", (cmd, args) => { return SetPlatingCellWaferSize(cmd, args); });
  453. OP.Subscribe($"{Module}.ClamShellClose", (cmd, para) => { return ClamShellClose(); });
  454. OP.Subscribe($"{Module}.ClamShellOpen", (cmd, para) => { return ClamShellOpen(); });
  455. OP.Subscribe($"{Module}.HeadtTilt", (cmd, para) => { return HeadtTiltAction(); });
  456. OP.Subscribe($"{Module}.HeadVertical", (cmd, para) => { return HeadtVerticalAction(); });
  457. OP.Subscribe($"{Module}.CCREnable", (cmd, para) => { return CCREnableAction(); });
  458. OP.Subscribe($"{Module}.CCRDisable", (cmd, para) => { return CCRDisableAction(); });
  459. OP.Subscribe($"{Module}.RinseEnable", (cmd, para) => { return RinseEnableAction(); });
  460. OP.Subscribe($"{Module}.RinseDisable", (cmd, para) => { return RinseDisableAction(); });
  461. OP.Subscribe($"{Module}.StartRotation", StartRotationAction);
  462. OP.Subscribe($"{Module}.StopRotation", StopRotationAction);
  463. OP.Subscribe($"{Module}.StartBiRotation", StartBiRotationAction);
  464. }
  465. #region Operation
  466. private bool StartRotationAction(string cmd, object[] args)
  467. {
  468. if (args.Length < 2 && (int)args[0] < 0 && (int)args[1] < 0)
  469. {
  470. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, $"Start rotation paramater is wrong");
  471. return false;
  472. }
  473. double targetPostion = (int)args[0] * 6 * (int)args[1];
  474. object[] param = new object[] { "", targetPostion };
  475. int degSpeed = (int)args[0] * 6;
  476. SetRotationSpeed(degSpeed);
  477. double AfterChangetargetPostion = (int)args[0] * 6 * (int)args[1];
  478. return RotationProfilePosition(AfterChangetargetPostion);
  479. }
  480. private bool StartBiRotationAction(string cmd, object[] args)
  481. {
  482. int _rotationTime = (int)args[0];
  483. int _frequency = (int)args[1];
  484. int _speed = (int)args[2];
  485. if (!JudgeRunningState(PlatingCellCommonOperation.BiRotation))
  486. {
  487. _currentOperation = PlatingCellCommonOperation.BiRotation;
  488. _status = _biDirectionRoutine.Start(_rotationTime, _frequency, _speed);
  489. return _status == RState.Running;
  490. }
  491. else
  492. {
  493. return false;
  494. }
  495. }
  496. private bool StopRotationAction(string cmd, object[] args)
  497. {
  498. return _rotationAxis.StopPositionOperation();
  499. }
  500. //public bool ClamShellClose()
  501. //{
  502. // return WriteVariableValue(CLAMSHELL_CLOSE, true);
  503. //}
  504. //public bool ClamShellOpen()
  505. //{
  506. // return WriteVariableValue(CLAMSHELL_CLOSE, false);
  507. //}
  508. public bool HeadtTiltAction()
  509. {
  510. return WriteVariableValue(HEAD_TILT, true);
  511. }
  512. public bool HeadtVerticalAction()
  513. {
  514. return WriteVariableValue(HEAD_TILT, false);
  515. }
  516. public bool CCREnableAction()
  517. {
  518. return WriteVariableValue(CCR_ENABLE, true);
  519. }
  520. public bool CCRDisableAction()
  521. {
  522. return WriteVariableValue(CCR_ENABLE, false);
  523. }
  524. public bool RinseEnableAction()
  525. {
  526. return WriteVariableValue(RINSE_ENABLE, true);
  527. }
  528. public bool RinseDisableAction()
  529. {
  530. return WriteVariableValue(RINSE_ENABLE, false);
  531. }
  532. #region ClamShell Close
  533. /// <summary>
  534. /// ClamShell Close
  535. /// </summary>
  536. /// <param name="cmd"></param>
  537. /// <param name="args"></param>
  538. /// <returns></returns>
  539. public bool ClamShellClose()
  540. {
  541. SystemFacilities facilities = DEVICE.GetDevice<SystemFacilities>("System.Facilities");
  542. if (facilities != null && facilities.CDAEnable &&
  543. !facilities.FacilitiesDataDic["CDA1Pressure"].IsError &&
  544. !facilities.FacilitiesDataDic["CDA2Pressure"].IsError)
  545. {
  546. if (!JudgeRunningState(PlatingCellCommonOperation.ClamShellClose))
  547. {
  548. _currentOperation = PlatingCellCommonOperation.ClamShellClose;
  549. _status = _closeRoutine.Start(true);
  550. return _status == RState.Running;
  551. }
  552. else
  553. {
  554. return false;
  555. }
  556. }
  557. else
  558. {
  559. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, $"facility CDA is abnormal,can not do clamShell close");
  560. return false;
  561. }
  562. }
  563. /// <summary>
  564. /// ClamShell Open
  565. /// </summary>
  566. /// <param name="cmd"></param>
  567. /// <param name="args"></param>
  568. /// <returns></returns>
  569. public bool ClamShellOpen()
  570. {
  571. SystemFacilities facilities = DEVICE.GetDevice<SystemFacilities>("System.Facilities");
  572. if(facilities != null && facilities.CDAEnable &&
  573. !facilities.FacilitiesDataDic["CDA1Pressure"].IsError &&
  574. !facilities.FacilitiesDataDic["CDA2Pressure"].IsError)
  575. {
  576. if (!JudgeRunningState(PlatingCellCommonOperation.ClamShellOpen))
  577. {
  578. _currentOperation = PlatingCellCommonOperation.ClamShellOpen;
  579. _status = _closeRoutine.Start(false);
  580. return _status == RState.Running;
  581. }
  582. else
  583. {
  584. return false;
  585. }
  586. }
  587. else
  588. {
  589. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, $"facility CDA is abnormal,can not do clamShell open");
  590. return false;
  591. }
  592. }
  593. /// <summary>
  594. /// 判定运行状态
  595. /// </summary>
  596. /// <returns></returns>
  597. private bool JudgeRunningState(PlatingCellCommonOperation operation)
  598. {
  599. if (_status == RState.Running)
  600. {
  601. EV.PostAlarmLog($"{Module}", eEvent.ERR_PLATINGCELL, $"{Module} current execute {_currentOperation},cannot {operation}");
  602. return true;
  603. }
  604. return false;
  605. }
  606. #endregion
  607. /// <summary>
  608. /// DisabledAction
  609. /// </summary>
  610. /// <param name="cmd"></param>
  611. /// <param name="param"></param>
  612. /// <returns></returns>
  613. public bool DisabledOperation(string cmd, object[] args)
  614. {
  615. string currentOperation = "Disabled";
  616. PlatingCellEntity platingCellEntity = Singleton<RouteManager>.Instance.GetModule<PlatingCellEntity>(Module);
  617. if (platingCellEntity != null && _persistentValue != null && _persistentValue.OperatingMode != currentOperation)
  618. {
  619. string preOperation = _persistentValue.OperatingMode;
  620. if (platingCellEntity.IsBusy)
  621. {
  622. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, $"{Module} is Busy, can't switch to Disabled mode");
  623. return false;
  624. }
  625. //if (SchedulerMetalTimeManager.Instance.Contained(Module))
  626. //{
  627. // LOG.WriteLog(eEvent.ERR_METAL, Module, $"{Module} is in scheduler, can't switch to Disabled mode");
  628. // return false;
  629. //}
  630. platingCellEntity.EnterInit();
  631. _persistentValue.OperatingMode = currentOperation;
  632. LOG.WriteLog(eEvent.INFO_PLATINGCELL, Module, $"Operating mode is switched from {preOperation} to {currentOperation}");
  633. }
  634. PlatingCellPersistentManager.Instance.UpdatePersistentValue(Module);
  635. return true;
  636. }
  637. /// <summary>
  638. /// ManualAction
  639. /// </summary>
  640. /// <param name="cmd"></param>
  641. /// <param name="param"></param>
  642. /// <returns></returns>
  643. public bool ManualOperation(string cmd, object[] args)
  644. {
  645. string currentOperation = "Manual";
  646. PlatingCellEntity platingCellEntity = Singleton<RouteManager>.Instance.GetModule<PlatingCellEntity>(Module);
  647. if (platingCellEntity != null && _persistentValue != null && _persistentValue.OperatingMode != currentOperation)
  648. {
  649. string preOperation = _persistentValue.OperatingMode;
  650. if (platingCellEntity.IsBusy)
  651. {
  652. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, $"{Module} is Busy, can't switch to Manual mode");
  653. return false;
  654. }
  655. //if (SchedulerMetalTimeManager.Instance.Contained(Module))
  656. //{
  657. // LOG.WriteLog(eEvent.ERR_METAL, Module, $"{Module} is in scheduler, can't switch to Manual mode");
  658. // return false;
  659. //}
  660. platingCellEntity.EnterInit();
  661. _persistentValue.OperatingMode = currentOperation;
  662. LOG.WriteLog(eEvent.INFO_PLATINGCELL, Module, $"Operating mode is switched from {preOperation} to {currentOperation}");
  663. }
  664. PlatingCellPersistentManager.Instance.UpdatePersistentValue(Module);
  665. return true;
  666. }
  667. /// <summary>
  668. /// AutoAction
  669. /// </summary>
  670. /// <param name="cmd"></param>
  671. /// <param name="param"></param>
  672. /// <returns></returns>
  673. public bool AutoOperation(string cmd, object[] args)
  674. {
  675. string currentOperation = "Auto";
  676. ReservoirEntity reservoirEntity = Singleton<RouteManager>.Instance.GetModule<ReservoirEntity>(_reservoirName);
  677. if (reservoirEntity!=null && reservoirEntity.PersistentValue.OperatingMode!="Auto")
  678. {
  679. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, $"{_reservoirName} not in Auto mode, can't switch to Auto mode");
  680. return false;
  681. }
  682. PlatingCellEntity platingCellEntity = Singleton<RouteManager>.Instance.GetModule<PlatingCellEntity>(Module);
  683. if (platingCellEntity != null && _persistentValue != null && _persistentValue.OperatingMode != currentOperation)
  684. {
  685. string preOperation = _persistentValue.OperatingMode;
  686. if (platingCellEntity.IsBusy)
  687. {
  688. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, $"{Module} is Busy, can't switch to Auto mode");
  689. return false;
  690. }
  691. platingCellEntity.EnterInit();
  692. _persistentValue.OperatingMode = currentOperation;
  693. LOG.WriteLog(eEvent.INFO_PLATINGCELL, Module, $"Operating mode is switched from {preOperation} to {currentOperation}");
  694. }
  695. PlatingCellPersistentManager.Instance.UpdatePersistentValue(Module);
  696. return true;
  697. }
  698. /// <summary>
  699. /// EngineeringModeAction
  700. /// </summary>
  701. /// <param name="cmd"></param>
  702. /// <param name="param"></param>
  703. /// <returns></returns>
  704. private bool EngineeringModeOperation(string cmd, object[] args)
  705. {
  706. string currentRecipeOperation = "Engineering";
  707. if (_persistentValue != null)
  708. {
  709. _persistentValue.RecipeOperatingMode = currentRecipeOperation;
  710. }
  711. PlatingCellPersistentManager.Instance.UpdatePersistentValue(Module);
  712. return true;
  713. }
  714. /// <summary>
  715. /// ProductionAction
  716. /// </summary>
  717. /// <param name="cmd"></param>
  718. /// <param name="param"></param>
  719. /// <returns></returns>
  720. private bool ProductionModeOperation(string cmd, object[] args)
  721. {
  722. string currentRecipeOperation = "Production";
  723. if (_persistentValue != null)
  724. {
  725. _persistentValue.RecipeOperatingMode = currentRecipeOperation;
  726. }
  727. PlatingCellPersistentManager.Instance.UpdatePersistentValue(Module);
  728. return true;
  729. }
  730. private bool SetPlatingCellWaferSize(string cmd, object[] args)
  731. {
  732. string metalWaferSize = args[0] as string;
  733. if (_persistentValue != null)
  734. {
  735. _persistentValue.PlatingCellWaferSize = int.Parse(metalWaferSize);
  736. }
  737. PlatingCellPersistentManager.Instance.UpdatePersistentValue(Module);
  738. return true;
  739. }
  740. /// <summary>
  741. /// 获取Reservoir设备
  742. /// </summary>
  743. /// <returns></returns>
  744. private ReservoirDevice GetReservoirDevice()
  745. {
  746. string reservoir = ReservoirItemManager.Instance.GetReservoirByPlatingCell(Module);
  747. return DEVICE.GetDevice<ReservoirDevice>(reservoir);
  748. }
  749. /// <summary>
  750. /// CCR当前步骤
  751. /// </summary>
  752. /// <param name="tmp"></param>
  753. public void UpdateStatus(string tmp)
  754. {
  755. _currentCCRStep = tmp;
  756. }
  757. /// <summary>
  758. /// CCR当前步骤剩余时间
  759. /// </summary>
  760. /// <param name="tmp"></param>
  761. public void UpdateCCRTimeRemain(double timeRemain)
  762. {
  763. _timeRemain = timeRemain;
  764. }
  765. #endregion
  766. #region RotationAxis
  767. /// <summary>
  768. /// 电机是否上电
  769. /// </summary>
  770. /// <returns></returns>
  771. public bool CheckRotationSwitchOn()
  772. {
  773. return _rotationAxis.IsSwitchOn;
  774. }
  775. /// <summary>
  776. /// Home rotation
  777. /// </summary>
  778. /// <returns></returns>
  779. public bool HomeRotation()
  780. {
  781. return _rotationAxis.Home();
  782. }
  783. /// <summary>
  784. /// 检验Rotation Home结果
  785. /// </summary>
  786. /// <returns></returns>
  787. public bool CheckHomeEndStatus()
  788. {
  789. return CheckRotationEndStatus() && _rotationAxis.IsHomed;
  790. }
  791. /// <summary>
  792. /// 检验Rotation结束状态
  793. /// </summary>
  794. /// <returns></returns>
  795. public bool CheckRotationEndStatus()
  796. {
  797. return _rotationAxis.Status == PunkHPX8_Core.RState.End;
  798. }
  799. /// <summary>
  800. /// 检验Rotation失败状态
  801. /// </summary>
  802. /// <returns></returns>
  803. public bool CheckRotationStopStatus()
  804. {
  805. return _rotationAxis.Status == PunkHPX8_Core.RState.Failed;
  806. }
  807. /// <summary>
  808. /// 设置速度
  809. /// </summary>
  810. /// <param name="speed"></param>
  811. /// <returns></returns>
  812. public bool SetRotationSpeed(int speed)
  813. {
  814. _rotationAxis.SetProfileSpeed(speed);
  815. return true;
  816. }
  817. /// <summary>
  818. /// 改变速度
  819. /// </summary>
  820. /// <param name="speed"></param>
  821. /// <returns></returns>
  822. public bool ChangeRotationSpeed(int speed)
  823. {
  824. return _rotationAxis.ChangeSpeed(speed);
  825. }
  826. /// <summary>
  827. /// 电机运动
  828. /// </summary>
  829. /// <param name="position"></param>
  830. /// <returns></returns>
  831. public bool RotationProfilePosition(double position)
  832. {
  833. return _rotationAxis.ProfilePositionOperation(position);
  834. }
  835. /// <summary>
  836. /// 停止运动
  837. /// </summary>
  838. /// <returns></returns>
  839. public bool StopProfilePosition()
  840. {
  841. return _rotationAxis.StopPositionOperation();
  842. }
  843. /// <summary>
  844. /// 是否Rotation运动
  845. /// </summary>
  846. /// <returns></returns>
  847. public bool CheckRotationRunning()
  848. {
  849. return _rotationAxis.IsRun;
  850. }
  851. #endregion
  852. public virtual void Monitor()
  853. {
  854. }
  855. public virtual void Reset()
  856. {
  857. }
  858. public virtual void Terminate()
  859. {
  860. }
  861. }
  862. }