ReservoirDevice.cs 58 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444
  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.RecipeCenter;
  6. using Aitex.Core.RT.SCCore;
  7. using Aitex.Core.Util;
  8. using MECF.Framework.Common.Alarm;
  9. using MECF.Framework.Common.Algorithm;
  10. using MECF.Framework.Common.Beckhoff.ModuleIO;
  11. using MECF.Framework.Common.CommonData.PlatingCell;
  12. using MECF.Framework.Common.CommonData.Prewet;
  13. using MECF.Framework.Common.CommonData.Reservoir;
  14. using MECF.Framework.Common.IOCore;
  15. using MECF.Framework.Common.Persistent.Reservoirs;
  16. using MECF.Framework.Common.RecipeCenter;
  17. using MECF.Framework.Common.ToolLayout;
  18. using MECF.Framework.Common.TwinCat;
  19. using MECF.Framework.Common.Utilities;
  20. using PunkHPX8_Core;
  21. using PunkHPX8_RT.Devices.Facilities;
  22. using PunkHPX8_RT.Devices.PlatingCell;
  23. using PunkHPX8_RT.Devices.Safety;
  24. using PunkHPX8_RT.Devices.Temperature;
  25. using PunkHPX8_RT.Modules;
  26. using PunkHPX8_RT.Modules.Reservoir;
  27. using System;
  28. using System.Collections.Generic;
  29. using System.Linq;
  30. using System.Reflection;
  31. using System.ServiceModel.Security;
  32. using System.Text;
  33. using System.Threading.Tasks;
  34. using System.Windows.Documents;
  35. namespace PunkHPX8_RT.Devices.Reservoir
  36. {
  37. public class ReservoirDevice : BaseDevice, IDevice
  38. {
  39. protected enum DiReplenOperation
  40. {
  41. None,
  42. ManualANDiReplen,
  43. ManualCADiReplen,
  44. AutoANDiReplen,
  45. AutoCADiReplen
  46. }
  47. #region 常量
  48. protected const string AUTO = "Auto";
  49. protected const string MANUAL = "Manual";
  50. protected const string DISABLE = "Disable";
  51. protected const string CA_PUMP_RUNNING="CaPumpRunning";
  52. protected const string AN_TOWER_HIGH="AnTowerHigh";
  53. protected const string AN_TOWER_LOW="AnTowerLow";
  54. protected const string CA_LEVEL="CaLevel";
  55. protected const string CA_WATER_LEVEL="CaWaterLevel";
  56. protected const string AN_FLOW="AnFlow";
  57. protected const string AN_PUMP_ENABLE="AnPumpEnable";
  58. protected const string AN_PUMP_SPEED="AnPumpSpeed";
  59. protected const string CA_FLOW="CaFlow";
  60. protected const string CA_PUMP_ENABLE="CaPumpEnable";
  61. protected const string CA_PUMP_SPEED="CaPumpSpeed";
  62. protected const string RETURN_VALVE_OPENING="ReturnValveOpening";
  63. protected const string CA_DI_REPLEN="CaDiReplen";
  64. protected const string AN_DI_REPLEN="AnDiReplen";
  65. protected const string SAMPLE_OUT="SampleOut";
  66. protected const string DEGAS_ENABLE="DegasEnable";
  67. protected const string CA_ISOLATION="CaIsolation";
  68. protected const string AN_ISOLATION="AnIsolation";
  69. protected const string HED_FLOW="HedFlow";
  70. protected const string HED_FLOW_ENABLE="HedFlowEnable";
  71. protected const string PH_FLOW_VALVE="PhFlowValve";
  72. protected const string PH_VALUE="PhValue";
  73. private const int ENABLE = 5;
  74. #endregion
  75. #region 内部变量
  76. /// <summary>
  77. /// 变量是否初始化字典
  78. /// </summary>
  79. private Dictionary<string, bool> _variableInitializeDic = new Dictionary<string, bool>();
  80. /// <summary>
  81. /// 定时器
  82. /// </summary>
  83. private PeriodicJob _periodicJob;
  84. /// <summary>
  85. /// 阴极Pump速度
  86. /// </summary>
  87. private double _caPumpSpeed = 0;
  88. /// <summary>
  89. /// Return Valve比例
  90. /// </summary>
  91. private double _returnValvePercent = 0.5;
  92. /// <summary>
  93. /// CA Level取样平均值
  94. /// </summary>
  95. private double _avgCALevel;
  96. /// <summary>
  97. /// CA Level取样队列
  98. /// </summary>
  99. private Queue<double> _CALevelSamples;
  100. /// <summary>
  101. /// CA level计算平均值取样数
  102. /// </summary>
  103. private int _levelSampleCount;
  104. /// <summary>
  105. /// 上一时刻platingcell的overflow level
  106. /// </summary>
  107. private double _lastOverFlow;
  108. /// <summary>
  109. /// 当前调节return valve的时间
  110. /// </summary>
  111. private DateTime _adjustReturnvalveStartTime = DateTime.Now;
  112. /// <summary>
  113. /// 检查ca flow 的时间,用于自动打开degas valve
  114. /// </summary>
  115. private DateTime _caFlowCheckTime = DateTime.Now;
  116. /// <summary>
  117. /// ca泵速Helper
  118. /// </summary>
  119. private ReservoirCAPumpSpeedHelper _caPumpSpeedHelper;
  120. //TC是否报警
  121. private bool _isTCControlWARN = false;
  122. #endregion
  123. #region Trigger
  124. /// <summary>
  125. /// Low WaterLevel trigger
  126. /// </summary>
  127. private R_TRIG _caWaterLevelLowerTrigger=new R_TRIG();
  128. /// <summary>
  129. /// High WaterLevel trigger
  130. /// </summary>
  131. private R_TRIG _caWaterLevelHighTrigger = new R_TRIG();
  132. #endregion
  133. #region 共享变量
  134. protected DiReplenOperation _currentDireplenOperation = DiReplenOperation.None;
  135. /// <summary>
  136. /// 手动注水时间(秒)
  137. /// </summary>
  138. protected int _manualReplenSecond = 0;
  139. /// <summary>
  140. /// 数据
  141. /// </summary>
  142. protected ReservoirData _reservoirData = new ReservoirData();
  143. /// <summary>
  144. /// Prewet 持久性数值对象
  145. /// </summary>
  146. protected ReservoirsPersistentValue _persistentValue;
  147. /// <summary>
  148. /// platingcellData
  149. /// </summary>
  150. protected PlatingCellDevice _platingCellDevice;
  151. /// <summary>
  152. /// Recipe
  153. /// </summary>
  154. protected ResRecipe _resRecipe;
  155. /// <summary>
  156. /// 注水Helper
  157. /// </summary>
  158. protected ReservoirDiReplenHelper _direplenHelper;
  159. /// <summary>
  160. /// 累计补水是否超时
  161. /// </summary>
  162. protected bool _isDIReplenMaxTimeOut = false;
  163. /// <summary>
  164. /// 单次补水是否超时
  165. /// </summary>
  166. protected bool _isDIReplenPerfillTimeOut = false;
  167. /// <summary>
  168. /// 是否有其他DIReplen的警告
  169. /// </summary>
  170. private bool _isOtherDIReplenWarnOn = false;
  171. #endregion
  172. #region 属性
  173. /// <summary>
  174. /// 操作模式
  175. /// </summary>
  176. public string OperationMode { get { return _persistentValue.OperatingMode; } }
  177. /// <summary>
  178. /// 工程模式
  179. /// </summary>
  180. public string EngineerMode { get { return _persistentValue.RecipeOperatingMode; } }
  181. /// <summary>
  182. /// 是否自动
  183. /// </summary>
  184. public bool IsAuto { get { return _persistentValue.OperatingMode == AUTO; } }
  185. /// <summary>
  186. /// 数据
  187. /// </summary>
  188. public ReservoirData ReservoirData { get { return _reservoirData; } }
  189. /// <summary>
  190. /// 检验阴极是否highlevel
  191. /// </summary>
  192. public bool IsCAHighLevel { get { return CheckCAHighLevelStatus(); } }
  193. /// <summary>
  194. /// 检验阴极是否lowlevel
  195. /// </summary>
  196. public bool IsCALowLevel { get { return CheckCALowLevelStatus(); } }
  197. /// <summary>
  198. /// 当前Recipe
  199. /// </summary>
  200. public ResRecipe Recipe { get { return _resRecipe; } }
  201. /// <summary>
  202. /// 阴极是否需要补水
  203. /// </summary>
  204. public bool CANeedDiReplen { get { return CheckCANeedDiReplen(); } }
  205. /// <summary>
  206. /// 正在补水
  207. /// </summary>
  208. public bool IsDireplenOn { get { return _reservoirData.AnDiReplen || _reservoirData.CaDiReplen; } }
  209. /// <summary>
  210. /// 单次补水是否超时
  211. /// </summary>
  212. public bool IsDIReplenPerfillTimeOut { get { return _isDIReplenPerfillTimeOut; } }
  213. /// <summary>
  214. /// 累计补水是否超时
  215. /// </summary>
  216. public bool IsDIReplenMaxTimeOut { get { return _isDIReplenMaxTimeOut; } }
  217. /// <summary>
  218. /// 是否启动retrun valve自动调节开闭
  219. /// </summary>
  220. public bool IsStartAutoReturnValve { get; set; }
  221. #endregion
  222. /// <summary>
  223. /// 构造函数
  224. /// </summary>
  225. /// <param name="moduleName"></param>
  226. /// <param name="name"></param>
  227. public ReservoirDevice(string moduleName) : base(moduleName, moduleName, moduleName, moduleName)
  228. {
  229. _levelSampleCount = SC.GetValue<int>("Reservoir.LevelAvgSamples");
  230. _levelSampleCount = _levelSampleCount == 0 ? 20 : _levelSampleCount;
  231. _CALevelSamples = new Queue<double>(_levelSampleCount);
  232. }
  233. /// <summary>
  234. /// 初始化
  235. /// </summary>
  236. /// <returns></returns>
  237. public bool Initialize()
  238. {
  239. InitializeParameter();
  240. InitializeRoutine();
  241. SubscribeData();
  242. InitializeOperation();
  243. SubscribeValueAction();
  244. _periodicJob = new PeriodicJob(200, OnTimer, $"{Module}.Timer", true, true);
  245. return true;
  246. }
  247. /// <summary>
  248. /// 初始化参数
  249. /// </summary>
  250. private void InitializeParameter()
  251. {
  252. _persistentValue = ReservoirsPersistentManager.Instance.GetReservoirsPersistentValue(Module.ToString());
  253. if (_persistentValue == null)
  254. {
  255. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module.ToString(), "Persistent Value Object is not exist");
  256. }
  257. if (!string.IsNullOrEmpty(_persistentValue.Recipe))
  258. {
  259. _resRecipe = RecipeFileManager.Instance.LoadGenericityRecipe<ResRecipe>(_persistentValue.Recipe);
  260. }
  261. _direplenHelper = new ReservoirDiReplenHelper(Module, _persistentValue);
  262. _caPumpSpeedHelper = new ReservoirCAPumpSpeedHelper(Module, this);
  263. }
  264. /// <summary>
  265. /// 初始化Routine
  266. /// </summary>
  267. private void InitializeRoutine()
  268. {
  269. }
  270. /// <summary>
  271. /// 订阅数据
  272. /// </summary>
  273. protected virtual void SubscribeData()
  274. {
  275. DATA.Subscribe($"{Module}.ReservoirData", () => _reservoirData, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  276. DATA.Subscribe($"{Module}.PersistentValue", () => _persistentValue, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  277. DATA.Subscribe($"{Module}.CurrentRecipe", () => _resRecipe, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  278. DATA.Subscribe($"{Module}.IsCAHighLevel", () => IsCAHighLevel, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  279. DATA.Subscribe($"{Module}.IsCALowLevel", () => IsCALowLevel, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  280. DATA.Subscribe($"{Module}.AvgCALevel", () => _avgCALevel, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  281. DATA.Subscribe($"{Module}.DIValveMaxOnTime", () => SC.GetValue<double>($"Reservoir.{Module}.DIValveMaxOnTime") * 60, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  282. DATA.Subscribe($"{Module}.IsManualCAReplen", () => { return _currentDireplenOperation == DiReplenOperation.ManualCADiReplen; }, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  283. DATA.Subscribe($"{Module}.IsDIReplenPerfillTimeOut", () => _isDIReplenPerfillTimeOut, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  284. DATA.Subscribe($"{Module}.IsDIReplenMaxTimeOut", () => _isDIReplenMaxTimeOut, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  285. }
  286. /// <summary>
  287. /// 初始化Operation
  288. /// </summary>
  289. protected virtual void InitializeOperation()
  290. {
  291. OP.Subscribe($"{Module}.DisabledAction", DisabledOperation);
  292. OP.Subscribe($"{Module}.ManualAction", ManualOperation);
  293. OP.Subscribe($"{Module}.AutoAction", AutoOperation);
  294. OP.Subscribe($"{Module}.EngineeringModeAction", EngineeringModeOperation);
  295. OP.Subscribe($"{Module}.ProductionModeAction", ProductionModeOperation);
  296. OP.Subscribe($"{Module}.CAPumpEnable", CAPumpOn);
  297. OP.Subscribe($"{Module}.CAPumpSpeed", CAPumpSpeedOperation);
  298. OP.Subscribe($"{Module}.CAPumpDisable", CAPumpOff);
  299. OP.Subscribe($"{Module}.LoadRecipe", LoadRecipeOperation);
  300. OP.Subscribe($"{Module}.ReturnValveOn", ReturnValveOn);
  301. OP.Subscribe($"{Module}.ReturnValveOff", (cmd, para) => { return ReturnValveOff();});
  302. OP.Subscribe($"{Module}.ReturnValvePercent", ReturnValvePercentOperation);
  303. OP.Subscribe($"{Module}.CAIsolationOn", (cmd, para) => { return CAIsolationOn(); });
  304. OP.Subscribe($"{Module}.CAIsolationOff", (cmd, para) => { return CAIsolationOff(); });
  305. OP.Subscribe($"{Module}.ANIsolationOn", (cmd, para) => { return ANIsolationOn(); });
  306. OP.Subscribe($"{Module}.ANIsolationOff", (cmd, para) => { return ANIsolationOff(); });
  307. OP.Subscribe($"{Module}.CADiReplenOn", CADiReplenOnOperation);
  308. OP.Subscribe($"{Module}.CADiReplenOff", CADiReplenOff);
  309. OP.Subscribe($"{Module}.SampleOutValveOn", (cmd, para) => { return SampleOutValveOn(); });
  310. OP.Subscribe($"{Module}.SampleOutValveOff", (cmd, para) => { return SampleOutValveOff(); });
  311. OP.Subscribe($"{Module}.DegasValveOn", (cmd, para) => { return DegasValveOn(); });
  312. OP.Subscribe($"{Module}.DegasValveOff", (cmd, para) => { return DegasValveOff(); });
  313. OP.Subscribe($"{Module}.PhValveOn", (cmd, para) => { return PhValveOn(); });
  314. OP.Subscribe($"{Module}.PhValveOff", (cmd, para) => { return PhValveOff(); });
  315. OP.Subscribe($"{Module}.HedValveOn", (cmd, para) => { return HedValveOn(); });
  316. OP.Subscribe($"{Module}.HedValveOff", (cmd, para) => { return HedValveOff(); });
  317. OP.Subscribe($"{Module}.ResetTotalTime", ResetTotalTime);
  318. OP.Subscribe($"{Module}.ManualCADiReplen", ManualCADiReplen);
  319. }
  320. /// <summary>
  321. /// 订阅变量数值发生变化
  322. /// </summary>
  323. protected virtual void SubscribeValueAction()
  324. {
  325. IoSubscribeUpdateVariable(CA_PUMP_RUNNING);
  326. IoSubscribeUpdateVariable(AN_TOWER_HIGH);
  327. IoSubscribeUpdateVariable(AN_TOWER_LOW);
  328. IoSubscribeUpdateVariable(CA_LEVEL);
  329. IoSubscribeUpdateVariable(CA_WATER_LEVEL);
  330. IoSubscribeUpdateVariable(CA_PUMP_ENABLE);
  331. IoSubscribeUpdateVariable(CA_PUMP_SPEED);
  332. IoSubscribeUpdateVariable(CA_DI_REPLEN);
  333. IoSubscribeUpdateVariable(RETURN_VALVE_OPENING);
  334. IoSubscribeUpdateVariable(SAMPLE_OUT);
  335. IoSubscribeUpdateVariable(CA_ISOLATION);
  336. IoSubscribeUpdateVariable(AN_ISOLATION);
  337. IoSubscribeUpdateVariable(DEGAS_ENABLE);
  338. IoSubscribeUpdateVariable(CA_FLOW);
  339. }
  340. /// <summary>
  341. /// 订阅IO变量
  342. /// </summary>
  343. /// <param name="variable"></param>
  344. protected void IoSubscribeUpdateVariable(string variable)
  345. {
  346. _variableInitializeDic[variable] = false;
  347. IOModuleManager.Instance.SubscribeModuleVariable(Module, variable, UpdateVariableValue);
  348. }
  349. /// <summary>
  350. /// 更新变量数值
  351. /// </summary>
  352. /// <param name="variable"></param>
  353. /// <param name="value"></param>
  354. private void UpdateVariableValue(string variable, object value)
  355. {
  356. if (!_reservoirData.IsDataInitialized)
  357. {
  358. _reservoirData.IsDataInitialized = true;
  359. }
  360. PropertyInfo property = _reservoirData.GetType().GetProperty(variable);
  361. if (property != null)
  362. {
  363. property.SetValue(_reservoirData, value);
  364. if (variable == CA_WATER_LEVEL)
  365. {
  366. string caLevelCurve = SC.GetStringValue($"Reservoir.{Module}.CALevelCurve");
  367. ReservoirData.CaLevel = LevelCurveManager.Instance.CalculateLevelByWaterLevel(ReservoirData.CaWaterLevel, caLevelCurve);
  368. }
  369. if (variable == RETURN_VALVE_OPENING)
  370. {
  371. if (Convert.ToDouble(value) != 0)
  372. {
  373. ReservoirData.ReturnValveEnable = true;
  374. }
  375. else
  376. {
  377. ReservoirData.ReturnValveEnable = false;
  378. }
  379. }
  380. }
  381. if (_variableInitializeDic.ContainsKey(variable) && !_variableInitializeDic[variable])
  382. {
  383. _variableInitializeDic[variable] = true;
  384. }
  385. }
  386. /// <summary>
  387. /// 写变量
  388. /// </summary>
  389. /// <param name="variable"></param>
  390. /// <param name="value"></param>
  391. /// <returns></returns>
  392. protected bool WriteVariableValue(string variable, object value)
  393. {
  394. string ioName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{variable}");
  395. return IOModuleManager.Instance.WriteIoValue(ioName, value);
  396. }
  397. /// <summary>
  398. /// 定时器
  399. /// </summary>
  400. /// <returns></returns>
  401. protected virtual bool OnTimer()
  402. {
  403. CalculateCALevel();
  404. AdjustRetrunFlowValve();
  405. WaterLevelMonitor();
  406. DireplenMonitor();
  407. AutoOpenDegasValve();
  408. HedMonitor();
  409. AutoMonitor();
  410. PlatingcellTimer();
  411. return true;
  412. }
  413. #region timer
  414. /// <summary>
  415. /// 启动platingcell的定时器
  416. /// </summary>
  417. private void PlatingcellTimer()
  418. {
  419. ReservoirItem reservoirItem = ReservoirItemManager.Instance.GetReservoirItem(Module);
  420. if (reservoirItem != null)
  421. {
  422. List<PlatingCellItem> platingCellItems = reservoirItem.PlatingCells;
  423. if (platingCellItems != null && platingCellItems.Count > 0)
  424. {
  425. if (platingCellItems[0].Installed)
  426. {
  427. _platingCellDevice = DEVICE.GetDevice<PlatingCellDevice>(platingCellItems[0].ModuleName);
  428. if (_platingCellDevice != null)
  429. {
  430. _platingCellDevice.OnTimer(_periodicJob.Interval);
  431. }
  432. }
  433. }
  434. }
  435. }
  436. /// <summary>
  437. /// 处于Auto时要监控的逻辑
  438. /// </summary>
  439. protected virtual void AutoMonitor()
  440. {
  441. if (_persistentValue.OperatingMode == AUTO)
  442. {
  443. _caPumpSpeedHelper.Monitor(_resRecipe);
  444. TemperatureCheck();
  445. }
  446. }
  447. /// <summary>
  448. /// 监控TC
  449. /// </summary>
  450. private void HedMonitor()
  451. {
  452. double _cellFlowStartLowlimit = SC.GetValue<double>("PlatingCell.CellFlowStartLowLimit");
  453. if (_reservoirData.CaFlow < _cellFlowStartLowlimit)
  454. {
  455. CAFlowLowOperation();
  456. }
  457. }
  458. /// <summary>
  459. /// safety和ca flow满足条件,自动打开degas valve
  460. /// </summary>
  461. public void AutoOpenDegasValve()
  462. {
  463. if(Recipe!= null && ReservoirData.CaFlow >= Recipe.CAFlowSetPoint) //缺了safety的条件,待补充
  464. {
  465. int degasValveOpenIdlePeriod = SC.GetValue<int>($"Reservoir.DegasValveOpenIdlePeriod");
  466. if(DateTime.Now.Subtract(_caFlowCheckTime).TotalMinutes >= degasValveOpenIdlePeriod && !ReservoirData.DegasEnable)
  467. {
  468. DegasValveOn();
  469. }
  470. }
  471. else
  472. {
  473. _caFlowCheckTime = DateTime.Now;
  474. }
  475. }
  476. /// <summary>
  477. /// 自动调节retrun valve 开闭
  478. /// </summary>
  479. public void AdjustRetrunFlowValve()
  480. {
  481. ReservoirEntity reservoirEntity = Singleton<RouteManager>.Instance.GetModule<ReservoirEntity>(Module);
  482. if (reservoirEntity != null)
  483. {
  484. //retrun valve打开
  485. if (ReservoirData.ReturnValveEnable && _platingCellDevice!=null && (!reservoirEntity.IsInit && !reservoirEntity.IsError))
  486. {
  487. double overflow = _platingCellDevice.PlatingCellDeviceData.OverFlowLevel;
  488. int _overflowLevelDelta = SC.GetValue<int>($"Reservoir.{Module}.OverflowLevelDelta");
  489. int _overflowLevelCheckTime = SC.GetValue<int>($"Reservoir.{Module}.OverflowLevelCheckTime");
  490. int _retrunOpenHoldStep = SC.GetValue<int>($"Reservoir.{Module}.RetrunOpenHoldStep");
  491. int _retrunOpenRampStep = SC.GetValue<int>($"Reservoir.{Module}.RetrunOpenRampStep");
  492. bool _isFull = "Full".Equals(_platingCellDevice.PlatingCellDeviceData.OverFlowStatus);
  493. int adjustNumber = _isFull ? _retrunOpenHoldStep : _retrunOpenRampStep;
  494. if (_isFull) //full的情况
  495. {
  496. if (overflow > _lastOverFlow)//液位升高的情况
  497. {
  498. if (overflow - _lastOverFlow > _overflowLevelDelta && DateTime.Now.Subtract(_adjustReturnvalveStartTime).TotalMilliseconds > _overflowLevelCheckTime)
  499. {
  500. double percent = ReservoirData.ReturnValveOpening - adjustNumber;
  501. percent = percent >= 0 ? percent : 0;
  502. ReturnValvePercent(percent);
  503. _lastOverFlow = overflow;
  504. _adjustReturnvalveStartTime = DateTime.Now;
  505. }
  506. }
  507. else
  508. {
  509. if (_lastOverFlow - overflow > _overflowLevelDelta && DateTime.Now.Subtract(_adjustReturnvalveStartTime).TotalMilliseconds > _overflowLevelCheckTime)
  510. {
  511. double percent = ReservoirData.ReturnValveOpening + adjustNumber;
  512. percent = percent <= 100 ? percent : 100;
  513. ReturnValvePercent(percent);
  514. _lastOverFlow = overflow;
  515. _adjustReturnvalveStartTime = DateTime.Now;
  516. }
  517. }
  518. }
  519. else //empty或者high的情况
  520. {
  521. if ("High".Equals(_platingCellDevice.PlatingCellDeviceData.OverFlowStatus))
  522. {
  523. if (DateTime.Now.Subtract(_adjustReturnvalveStartTime).TotalMilliseconds > _overflowLevelCheckTime)
  524. {
  525. double percent = ReservoirData.ReturnValveOpening - adjustNumber;
  526. percent = percent >= 0 ? percent : 0;
  527. ReturnValvePercent(percent);
  528. _lastOverFlow = overflow;
  529. _adjustReturnvalveStartTime = DateTime.Now;
  530. }
  531. }
  532. else
  533. {
  534. if (DateTime.Now.Subtract(_adjustReturnvalveStartTime).TotalMilliseconds > _overflowLevelCheckTime)
  535. {
  536. double percent = ReservoirData.ReturnValveOpening + adjustNumber;
  537. percent = percent <= 100 ? percent : 100;
  538. ReturnValvePercent(percent);
  539. _lastOverFlow = overflow;
  540. _adjustReturnvalveStartTime = DateTime.Now;
  541. }
  542. }
  543. }
  544. }
  545. }
  546. }
  547. /// <summary>
  548. /// 计算CA
  549. /// </summary>
  550. private void CalculateCALevel()
  551. {
  552. if (ReservoirData != null)
  553. {
  554. if (_CALevelSamples.Count >= _levelSampleCount)
  555. {
  556. _CALevelSamples.Dequeue();
  557. _CALevelSamples.Enqueue(ReservoirData.CaLevel);
  558. }
  559. else
  560. {
  561. _CALevelSamples.Enqueue(ReservoirData.CaLevel);
  562. }
  563. _avgCALevel = _CALevelSamples.Count > 0 ? _CALevelSamples.Average() : 0;
  564. }
  565. }
  566. /// <summary>
  567. /// WaterLevel监控
  568. /// </summary>
  569. protected virtual void WaterLevelMonitor()
  570. {
  571. _caWaterLevelLowerTrigger.CLK = IsCALowLevel;
  572. if (_caWaterLevelLowerTrigger.Q)
  573. {
  574. ReservoirEntity reservoirEntity = Singleton<RouteManager>.Instance.GetModule<ReservoirEntity>(Module);
  575. string reason = $"Current CAWaterlevel:{ReservoirData.CaWaterLevel} is lower than CALowLevel Config:{SC.GetValue<double>($"Reservoir.{Module}.CALowLevel")}";
  576. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, reason);
  577. CALowLevelOperation();
  578. if (reservoirEntity.IsAuto && !AlarmListManager.Instance.IsContainDataError(Module, "CAWaterLevel"))
  579. {
  580. AlarmListManager.Instance.AddDataError(Module,
  581. $"CAWaterLevel", $"Current CAWaterlevel:{ReservoirData.CaWaterLevel} is lower than CALowLevel Config:{SC.GetValue<double>($"Reservoir.{Module}.CALowLevel")}");
  582. }
  583. if (!reservoirEntity.IsError) reservoirEntity.PostMsg(ReservoirMsg.Error);
  584. }
  585. _caWaterLevelHighTrigger.CLK = IsCAHighLevel;
  586. if (_caWaterLevelHighTrigger.Q)
  587. {
  588. HighLevelOperation();
  589. }
  590. }
  591. /// <summary>
  592. /// CA Low Level触发对应操作
  593. /// </summary>
  594. private void CAFlowLowOperation()
  595. {
  596. ReservoirItem reservoirItem = ReservoirItemManager.Instance.GetReservoirItem(Module);
  597. //禁用TC
  598. if (!string.IsNullOrEmpty(reservoirItem.TCID))
  599. {
  600. TemperatureController temperatureController = DEVICE.GetDevice<TemperatureController>(reservoirItem.TCID);
  601. if (temperatureController != null && temperatureController.TemperatureData.ControlOperationModel == (int)TemperatureEnumData.ENABLE)
  602. {
  603. temperatureController.DisableOperation("", null);
  604. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, "CA flow is lower than cellflowStartLowLimit,TC Disabled");
  605. }
  606. }
  607. }
  608. /// <summary>
  609. /// CA Low Level触发对应操作
  610. /// </summary>
  611. private void CALowLevelOperation()
  612. {
  613. ReservoirItem reservoirItem = ReservoirItemManager.Instance.GetReservoirItem(Module);
  614. if (_reservoirData.CaPumpEnable)
  615. {
  616. CAPumpOff("", null);
  617. }
  618. if (_reservoirData.CaIsolation)// 不确定是否是关闭cell flow
  619. {
  620. CAIsolationOff();
  621. }
  622. //禁用TC
  623. if (!string.IsNullOrEmpty(reservoirItem.TCID))
  624. {
  625. TemperatureController temperatureController = DEVICE.GetDevice<TemperatureController>(reservoirItem.TCID);
  626. if (temperatureController != null && temperatureController.TemperatureData.ControlOperationModel == (int)TemperatureEnumData.ENABLE)
  627. {
  628. temperatureController.DisableOperation("", null);
  629. }
  630. }
  631. ReservoirEntity reservoirEntity = Singleton<RouteManager>.Instance.GetModule<ReservoirEntity>(Module);
  632. if (!reservoirEntity.IsError) reservoirEntity.PostMsg(ReservoirMsg.Error);
  633. }
  634. /// <summary>
  635. /// High Level Common Operation
  636. /// </summary>
  637. private void HighLevelOperation()
  638. {
  639. ReservoirEntity reservoirEntity = Singleton<RouteManager>.Instance.GetModule<ReservoirEntity>(Module);
  640. SystemFacilities systemFacilities = DEVICE.GetDevice<SystemFacilities>("System.Facilities");
  641. if (systemFacilities != null)
  642. {
  643. if (systemFacilities.DIFillEnable) systemFacilities.DiFillDisableOperation("DIFillDisableOpeartion", null);
  644. if (systemFacilities.DIReplenEnable) systemFacilities.DiReplenDisableOperation("DiReplenDisableOperation", null);
  645. if (_reservoirData.CaDiReplen)
  646. {
  647. _currentDireplenOperation = DiReplenOperation.None;
  648. CADiReplenOff("", null);
  649. }
  650. }
  651. if (!reservoirEntity.IsError) reservoirEntity.PostMsg(ReservoirMsg.Error);
  652. if (reservoirEntity.IsAuto && !AlarmListManager.Instance.IsContainDataError(Module, "CAWaterLevel"))
  653. {
  654. AlarmListManager.Instance.AddDataError(Module,
  655. $"CAWaterLevel", $"Current CAWaterlevel:{ReservoirData.CaWaterLevel} is large than CAHighLevel Config:{SC.GetValue<double>($"Reservoir.{Module}.CAHighLevel")}");
  656. }
  657. }
  658. /// <summary>
  659. /// Direplen监控
  660. /// </summary>
  661. private void DireplenMonitor()
  662. {
  663. var facilities = DEVICE.GetDevice<SystemFacilities>("System.Facilities");
  664. //补水监控
  665. if (_direplenHelper != null)
  666. {
  667. _direplenHelper.MonitorPeriodTime(ref _isDIReplenMaxTimeOut);
  668. if (!_isDIReplenMaxTimeOut && !_isDIReplenPerfillTimeOut && facilities.DIFillEnable)
  669. {
  670. AutoDireplenMonitor();
  671. }
  672. }
  673. }
  674. /// <summary>
  675. /// 自动补水
  676. /// </summary>
  677. protected virtual void AutoDireplenMonitor()
  678. {
  679. if (_currentDireplenOperation == DiReplenOperation.ManualCADiReplen)
  680. {
  681. bool result = _direplenHelper.MonitorManualDiReplenComplete(_manualReplenSecond, CADiReplenOff, ref _isDIReplenMaxTimeOut);
  682. if (result)
  683. {
  684. _currentDireplenOperation = DiReplenOperation.None;
  685. }
  686. }
  687. if (_currentDireplenOperation == DiReplenOperation.AutoCADiReplen)
  688. {
  689. AutoDiReplenMonitor(CADiReplenOff, _reservoirData.CaLevel, _resRecipe.ReservoirCALevel, _resRecipe.DIReplenEnable,
  690. _resRecipe.DIReplenTimeRate, _resRecipe.DIReplenCurrentRate);
  691. }
  692. }
  693. /// <summary>
  694. /// 自动注水监控
  695. /// </summary>
  696. /// <param name="direplenOff"></param>
  697. /// <param name="level"></param>
  698. /// <param name="recipeLevel"></param>
  699. private void AutoDiReplenMonitor(Func<string, object[], bool> direplenOff, double level, double recipeLevel, bool replenEnable,
  700. int direplenTimeRate, int direplenCurrentRate)
  701. {
  702. //判断是否注水超时(包括单次和累计)
  703. bool result = _direplenHelper.AutoDiReplenMonitorTimeOut(direplenOff, ref _isDIReplenMaxTimeOut, ref _isDIReplenPerfillTimeOut);
  704. if (result)
  705. {
  706. _currentDireplenOperation = DiReplenOperation.None;
  707. }
  708. else
  709. {
  710. //按液位补水
  711. result = _direplenHelper.AutoDiReplenMonitorComplete(level, recipeLevel, replenEnable, direplenTimeRate, direplenCurrentRate, direplenOff);
  712. if (result)
  713. {
  714. _currentDireplenOperation = DiReplenOperation.None;
  715. }
  716. }
  717. }
  718. #endregion
  719. #region Mode switch
  720. /// <summary>
  721. /// DisabledAction
  722. /// </summary>
  723. /// <param name="cmd"></param>
  724. /// <param name="param"></param>
  725. /// <returns></returns>
  726. private bool DisabledOperation(string cmd, object[] args)
  727. {
  728. string currentOperation = "Disabled";
  729. string preOperation = _persistentValue.OperatingMode;
  730. _persistentValue.OperatingMode = currentOperation;
  731. LOG.WriteLog(eEvent.INFO_RESERVOIR, Module, $"Operating mode is switched from {preOperation} to {currentOperation}");
  732. ReservoirsPersistentManager.Instance.UpdatePersistentValue(Module);
  733. return true;
  734. }
  735. /// <summary>
  736. /// ManualAction
  737. /// </summary>
  738. /// <param name="cmd"></param>
  739. /// <param name="param"></param>
  740. /// <returns></returns>
  741. private bool ManualOperation(string cmd, object[] args)
  742. {
  743. string currentOperation = "Manual";
  744. string preOperation = _persistentValue.OperatingMode;
  745. _persistentValue.OperatingMode = currentOperation;
  746. LOG.WriteLog(eEvent.INFO_RESERVOIR, Module, $"Operating mode is switched from {preOperation} to {currentOperation}");
  747. ReservoirsPersistentManager.Instance.UpdatePersistentValue(Module);
  748. return true;
  749. }
  750. /// <summary>
  751. /// AutoAction
  752. /// </summary>
  753. /// <param name="cmd"></param>
  754. /// <param name="param"></param>
  755. /// <returns></returns>
  756. private bool AutoOperation(string cmd, object[] args)
  757. {
  758. string currentOperation = "Auto";
  759. string preOperation = _persistentValue.OperatingMode;
  760. _persistentValue.OperatingMode = currentOperation;
  761. LOG.WriteLog(eEvent.INFO_RESERVOIR, Module, $"Operating mode is switched from {preOperation} to {currentOperation}");
  762. ReservoirsPersistentManager.Instance.UpdatePersistentValue(Module);
  763. return true;
  764. }
  765. /// <summary>
  766. /// EngineeringModeAction
  767. /// </summary>
  768. /// <param name="cmd"></param>
  769. /// <param name="param"></param>
  770. /// <returns></returns>
  771. private bool EngineeringModeOperation(string cmd, object[] args)
  772. {
  773. string currentRecipeOperation = "Engineering";
  774. if (_persistentValue != null)
  775. {
  776. _persistentValue.RecipeOperatingMode = currentRecipeOperation;
  777. }
  778. ReservoirsPersistentManager.Instance.UpdatePersistentValue(Module);
  779. return true;
  780. }
  781. /// <summary>
  782. /// ProductionAction
  783. /// </summary>
  784. /// <param name="cmd"></param>
  785. /// <param name="param"></param>
  786. /// <returns></returns>
  787. private bool ProductionModeOperation(string cmd, object[] args)
  788. {
  789. string currentRecipeOperation = "Production";
  790. if (_persistentValue != null)
  791. {
  792. _persistentValue.RecipeOperatingMode = currentRecipeOperation;
  793. }
  794. ReservoirsPersistentManager.Instance.UpdatePersistentValue(Module);
  795. return true;
  796. }
  797. #endregion
  798. /// <summary>
  799. /// 加载Recipe
  800. /// </summary>
  801. /// <param name="cmd"></param>
  802. /// <param name="args"></param>
  803. /// <returns></returns>
  804. private bool LoadRecipeOperation(string cmd, object[] args)
  805. {
  806. _persistentValue.Recipe = args[0].ToString();
  807. string[] fileRoute = _persistentValue.Recipe.Split('\\');
  808. string recipeRoute = "";
  809. if (fileRoute.Length > 2)
  810. {
  811. recipeRoute = fileRoute[fileRoute.Length - 2];
  812. }
  813. _resRecipe = RecipeFileManager.Instance.LoadGenericityRecipe<ResRecipe>(_persistentValue.Recipe);
  814. ReservoirsPersistentManager.Instance.UpdatePersistentValue(Module.ToString());
  815. LOG.WriteLog(eEvent.INFO_RESERVOIR, Module.ToString(), $"Load {recipeRoute} Recipe {_resRecipe.Ppid} Success");
  816. return true;
  817. }
  818. /// <summary>
  819. /// 监控
  820. /// </summary>
  821. public void Monitor()
  822. {
  823. }
  824. #region CA Pump
  825. /// <summary>
  826. /// CA Pump调速
  827. /// </summary>
  828. /// <param name="cmd"></param>
  829. /// <param name="args"></param>
  830. /// <returns></returns>
  831. private bool CAPumpSpeedOperation(string cmd, object[] args)
  832. {
  833. double caMaxPumpSpeed = 0;
  834. if (SC.ContainsItem("Reservoir.CAMaxPumpSpeed"))
  835. {
  836. caMaxPumpSpeed = SC.GetValue<double>("Reservoir.CAMaxPumpSpeed");
  837. }
  838. if (double.TryParse(args[0].ToString(), out double speed))
  839. {
  840. _caPumpSpeed = speed;
  841. if (_caPumpSpeed > caMaxPumpSpeed)
  842. {
  843. LOG.WriteLog(eEvent.WARN_METAL, Module, $"CA pump speed:{_caPumpSpeed} is over CA max pump speed {caMaxPumpSpeed}!");
  844. return false;
  845. }
  846. return CAPumpSpeed(_caPumpSpeed);
  847. }
  848. else
  849. {
  850. LOG.WriteLog(eEvent.ERR_METAL, Module, $"{args[0]} is nor invalid speed");
  851. return false;
  852. }
  853. }
  854. /// <summary>
  855. /// 设置阴极泵速
  856. /// </summary>
  857. /// <param name="caPumpSpeed"></param>
  858. /// <returns></returns>
  859. public bool CAPumpSpeed(double caPumpSpeed)
  860. {
  861. string ioName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{CA_PUMP_SPEED}");
  862. return BeckhoffIOManager.Instance.WriteIoValue(ioName, caPumpSpeed);
  863. }
  864. /// <summary>
  865. /// 阴极Pump On
  866. /// </summary>
  867. /// <param name="cmd"></param>
  868. /// <param name="args"></param>
  869. /// <returns></returns>
  870. public bool CAPumpOn(string cmd, object[] args)
  871. {
  872. double caPumpSpeed = SC.GetValue<double>("Reservoir.CADefaultPumpSpeed");
  873. bool result = CAPumpSpeed(caPumpSpeed);
  874. if (result)
  875. {
  876. string enableIOName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{CA_PUMP_ENABLE}");
  877. return BeckhoffIOManager.Instance.WriteIoValue(enableIOName, true);
  878. }
  879. else
  880. {
  881. return false;
  882. }
  883. }
  884. /// <summary>
  885. /// 阴极Pump Off
  886. /// </summary>
  887. /// <param name="cmd"></param>
  888. /// <param name="args"></param>
  889. /// <returns></returns>
  890. public bool CAPumpOff(string cmd, object[] args)
  891. {
  892. string ioName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{CA_PUMP_ENABLE}");
  893. return BeckhoffIOManager.Instance.WriteIoValue(ioName, false);
  894. }
  895. #endregion
  896. #region Return Valve
  897. /// <summary>
  898. /// Return Valve
  899. /// </summary>
  900. /// <param name="cmd"></param>
  901. /// <param name="args"></param>
  902. /// <returns></returns>
  903. private bool ReturnValvePercentOperation(string cmd, object[] args)
  904. {
  905. if (double.TryParse(args[0].ToString(), out double percent))
  906. {
  907. _returnValvePercent = percent;
  908. return ReturnValvePercent(_returnValvePercent);
  909. }
  910. else
  911. {
  912. LOG.WriteLog(eEvent.ERR_METAL, Module, $"{args[0]} is invalid percent");
  913. return false;
  914. }
  915. }
  916. /// <summary>
  917. /// 设置比例
  918. /// </summary>
  919. /// <param name="caPumpSpeed"></param>
  920. /// <returns></returns>
  921. public bool ReturnValvePercent(double percent)
  922. {
  923. string ioName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{RETURN_VALVE_OPENING}");
  924. return BeckhoffIOManager.Instance.WriteIoValue(ioName, percent);
  925. }
  926. /// <summary>
  927. /// Return Valve On
  928. /// </summary>
  929. /// <param name="cmd"></param>
  930. /// <param name="args"></param>
  931. /// <returns></returns>
  932. public bool ReturnValveOn(string cmd, object[] args)
  933. {
  934. double percent = SC.GetValue<int>("Reservoir.ReturnOpenDefaultPercentage");
  935. return ReturnValvePercent(percent);
  936. }
  937. /// <summary>
  938. /// Return Valve Off
  939. /// </summary>
  940. /// <param name="cmd"></param>
  941. /// <param name="args"></param>
  942. /// <returns></returns>
  943. public bool ReturnValveOff()
  944. {
  945. return ReturnValvePercent(0);
  946. }
  947. #endregion
  948. /// <summary>
  949. /// CAIsolationOn
  950. /// </summary>
  951. /// <returns></returns>
  952. public bool CAIsolationOn()
  953. {
  954. return WriteVariableValue(CA_ISOLATION, true);
  955. }
  956. /// <summary>
  957. /// CAIsolationOff
  958. /// </summary>
  959. /// <returns></returns>
  960. public bool CAIsolationOff()
  961. {
  962. return WriteVariableValue(CA_ISOLATION, false);
  963. }
  964. /// <summary>
  965. /// ANIsolationOn
  966. /// </summary>
  967. /// <returns></returns>
  968. public bool ANIsolationOn()
  969. {
  970. return WriteVariableValue(AN_ISOLATION, true);
  971. }
  972. /// <summary>
  973. /// ANIsolationOff
  974. /// </summary>
  975. /// <returns></returns>
  976. public bool ANIsolationOff()
  977. {
  978. return WriteVariableValue(AN_ISOLATION, false);
  979. }
  980. /// <summary>
  981. /// DegasValveOn
  982. /// </summary>
  983. /// <returns></returns>
  984. public bool DegasValveOn()
  985. {
  986. return WriteVariableValue(DEGAS_ENABLE, true);
  987. }
  988. /// <summary>
  989. /// DegasValveOff
  990. /// </summary>
  991. /// <returns></returns>
  992. public bool DegasValveOff()
  993. {
  994. return WriteVariableValue(DEGAS_ENABLE, false);
  995. }
  996. /// <summary>
  997. /// HedValveOn
  998. /// </summary>
  999. /// <returns></returns>
  1000. public bool HedValveOn()
  1001. {
  1002. return WriteVariableValue(HED_FLOW_ENABLE, true);
  1003. }
  1004. /// <summary>
  1005. /// HedValveOff
  1006. /// </summary>
  1007. /// <returns></returns>
  1008. public bool HedValveOff()
  1009. {
  1010. return WriteVariableValue(HED_FLOW_ENABLE, false);
  1011. }
  1012. /// <summary>
  1013. /// PhValveOn
  1014. /// </summary>
  1015. /// <returns></returns>
  1016. public bool PhValveOn()
  1017. {
  1018. return WriteVariableValue(PH_FLOW_VALVE, true);
  1019. }
  1020. /// <summary>
  1021. /// PhValveOff
  1022. /// </summary>
  1023. /// <returns></returns>
  1024. public bool PhValveOff()
  1025. {
  1026. return WriteVariableValue(PH_FLOW_VALVE, false);
  1027. }
  1028. /// <summary>
  1029. /// SampleOutValveOn
  1030. /// </summary>
  1031. /// <returns></returns>
  1032. public bool SampleOutValveOn()
  1033. {
  1034. return WriteVariableValue(SAMPLE_OUT, true);
  1035. }
  1036. /// <summary>
  1037. /// SampleOutValveOff
  1038. /// </summary>
  1039. /// <returns></returns>
  1040. public bool SampleOutValveOff()
  1041. {
  1042. return WriteVariableValue(SAMPLE_OUT, false);
  1043. }
  1044. #region CA DiReplen
  1045. /// <summary>
  1046. /// 阴极DI Replen On
  1047. /// </summary>
  1048. /// <param name="cmd"></param>
  1049. /// <param name="args"></param>
  1050. /// <returns></returns>
  1051. private bool CADiReplenOnOperation(string cmd, object[] args)
  1052. {
  1053. return CADiReplenOn();
  1054. }
  1055. /// <summary>
  1056. /// 阴极DI Replen On
  1057. /// </summary>
  1058. /// <param name="showError"></param>
  1059. /// <returns></returns>
  1060. private bool CADiReplenOn()
  1061. {
  1062. bool preCondition = CheckPreDiReplenCondition();
  1063. if (!preCondition)
  1064. {
  1065. return false;
  1066. }
  1067. if (IsCAHighLevel)
  1068. {
  1069. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"CAHighLevel is activate,Can't do CA_DIReple");
  1070. return false;
  1071. }
  1072. if (IsCALowLevel)
  1073. {
  1074. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"CALowLevel is activate,Can't do CA_DIReple");
  1075. return false;
  1076. }
  1077. if (ReservoirData.AnDiReplen)
  1078. {
  1079. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, "ANDiReplen is on");
  1080. return false;
  1081. }
  1082. string ioName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{CA_DI_REPLEN}");
  1083. return BeckhoffIOManager.Instance.WriteIoValue(ioName, true);
  1084. }
  1085. /// <summary>
  1086. /// 阴极DI Replen Off
  1087. /// </summary>
  1088. /// <param name="cmd"></param>
  1089. /// <param name="args"></param>
  1090. /// <returns></returns>
  1091. private bool CADiReplenOff(string cmd, object[] args)
  1092. {
  1093. string ioName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{CA_DI_REPLEN}");
  1094. bool result = BeckhoffIOManager.Instance.WriteIoValue(ioName, false);
  1095. if (result)
  1096. {
  1097. _persistentValue.IsDiReplenOn = false;
  1098. if (_currentDireplenOperation == DiReplenOperation.ManualCADiReplen || _currentDireplenOperation == DiReplenOperation.AutoCADiReplen)
  1099. {
  1100. _currentDireplenOperation = DiReplenOperation.None;
  1101. _persistentValue.LastTotalReplen = _persistentValue.TotalReplen;
  1102. ReservoirsPersistentManager.Instance.UpdatePersistentValue(Module);
  1103. }
  1104. }
  1105. return result;
  1106. }
  1107. /// <summary>
  1108. /// 检验DiReplen前置条件
  1109. /// </summary>
  1110. /// <returns></returns>
  1111. public bool CheckPreDiReplenCondition()
  1112. {
  1113. if (!CheckFacilitiesDiReplenStatus())
  1114. {
  1115. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, "Facilities DiReplen is Off, can't start auto diReplen");
  1116. return false;
  1117. }
  1118. SafetyDevice safetyDevice = DEVICE.GetDevice<SafetyDevice>("Safety");
  1119. if (safetyDevice != null && safetyDevice.SafetyData.Reservoir1CALevelHigh)
  1120. {
  1121. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"Safety high is Activate, can't start auto diReplen");
  1122. return false;
  1123. }
  1124. if (CheckOtherReservoirDiReplenStatus())
  1125. {
  1126. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"there is exist reservoir in diReplen, can't start auto diReplen");
  1127. return false;
  1128. }
  1129. return true;
  1130. }
  1131. /// <summary>
  1132. /// 检验总Di有没有开
  1133. /// </summary>
  1134. /// <returns></returns>
  1135. private bool CheckFacilitiesDiReplenStatus()
  1136. {
  1137. SystemFacilities systemFacilities = DEVICE.GetDevice<SystemFacilities>("System.Facilities");
  1138. if (systemFacilities != null)
  1139. {
  1140. return systemFacilities.DIReplenEnable;
  1141. }
  1142. return false;
  1143. }
  1144. /// <summary>
  1145. /// 检验是否其他Reservoir Direplen已经
  1146. /// </summary>
  1147. /// <returns></returns>
  1148. protected bool CheckOtherReservoirDiReplenStatus()
  1149. {
  1150. List<string> reservoirs = ReservoirItemManager.Instance.InstalledModules;
  1151. foreach (string item in reservoirs)
  1152. {
  1153. if (item != Module)
  1154. {
  1155. ReservoirItem reservoirItem = ReservoirItemManager.Instance.GetReservoirItem(item);
  1156. if (reservoirItem.SubType == ReservoirType.DegasMembrance.ToString())
  1157. {
  1158. DMReservoirDevice tmpDevice = DEVICE.GetDevice<DMReservoirDevice>(item);
  1159. if (tmpDevice.ReservoirData.AnDiReplen)
  1160. {
  1161. if (!_isOtherDIReplenWarnOn)
  1162. {
  1163. _isOtherDIReplenWarnOn = true;
  1164. LOG.WriteLog(eEvent.WARN_RESERVOIR, Module, $"{item} AN DiReplen valve is on. {Module} is waiting DiReplen");
  1165. }
  1166. return true;
  1167. }
  1168. if (tmpDevice.ReservoirData.CaDiReplen)
  1169. {
  1170. if (!_isOtherDIReplenWarnOn)
  1171. {
  1172. _isOtherDIReplenWarnOn = true;
  1173. LOG.WriteLog(eEvent.WARN_RESERVOIR, Module, $"{item} CA DiReplen valve is on. {Module} is waiting DiReplen");
  1174. }
  1175. return true;
  1176. }
  1177. }
  1178. }
  1179. }
  1180. _isOtherDIReplenWarnOn = false;
  1181. return false;
  1182. }
  1183. #endregion
  1184. #region DiReplen Operation
  1185. /// <summary>
  1186. /// 重置时长
  1187. /// </summary>
  1188. /// <param name="cmd"></param>
  1189. /// <param name="objs"></param>
  1190. /// <returns></returns>
  1191. private bool ResetTotalTime(string cmd, object[] objs)
  1192. {
  1193. _isDIReplenMaxTimeOut = false;
  1194. _isDIReplenPerfillTimeOut = false;
  1195. _persistentValue.TotalReplen = 0;
  1196. _persistentValue.LastTotalReplen = 0;
  1197. ReservoirsPersistentManager.Instance.UpdatePersistentValue(Module);
  1198. return true;
  1199. }
  1200. /// <summary>
  1201. /// 手动阴极注水
  1202. /// </summary>
  1203. /// <param name="cmd"></param>
  1204. /// <param name="args"></param>
  1205. /// <returns></returns>
  1206. private bool ManualCADiReplen(string cmd, object[] args)
  1207. {
  1208. return ManualDiReplen(CADiReplenOnOperation, DiReplenOperation.ManualCADiReplen, args[0].ToString());
  1209. }
  1210. /// <summary>
  1211. /// 手动注水
  1212. /// </summary>
  1213. /// <param name="direplenOn"></param>
  1214. /// <param name="direplenOperation"></param>
  1215. /// <returns></returns>
  1216. protected bool ManualDiReplen(Func<string, object[], bool> direplenOn, DiReplenOperation direplenOperation, string timeLength)
  1217. {
  1218. if (_currentDireplenOperation != DiReplenOperation.None)
  1219. {
  1220. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"current operation is {_currentDireplenOperation},cannot execute {direplenOperation}");
  1221. return false;
  1222. }
  1223. ReservoirEntity reservoirEntity = Singleton<RouteManager>.Instance.GetModule<ReservoirEntity>(Module);
  1224. if (!reservoirEntity.IsInitialized)
  1225. {
  1226. LOG.WriteLog(eEvent.WARN_RESERVOIR, Module, $"{Module} is not initialized. Can't start DiReplen");
  1227. return false;
  1228. }
  1229. if (_isDIReplenMaxTimeOut)
  1230. {
  1231. double diValveMaxOnTime = SC.GetValue<double>($"Reservoir.{Module}.DIValveMaxOnTime");
  1232. LOG.WriteLog(eEvent.WARN_RESERVOIR, Module, $"Direplen time over conifg's DIValveMaxOnTime:{diValveMaxOnTime} min");
  1233. return false;
  1234. }
  1235. if (_isDIReplenPerfillTimeOut)
  1236. {
  1237. double diValveMaxOnTimePerFill = SC.GetValue<double>($"Reservoir.{Module}.DIValveMaxOnTimePerFill");
  1238. LOG.WriteLog(eEvent.WARN_RESERVOIR, Module, $"Direplen time over conifg's DIValveMaxOnTimePerFill:{diValveMaxOnTimePerFill} min");
  1239. return false;
  1240. }
  1241. bool result = direplenOn("", null);
  1242. if (result)
  1243. {
  1244. _currentDireplenOperation = direplenOperation;
  1245. _persistentValue.DiReplenTime = DateTime.Now;
  1246. ReservoirsPersistentManager.Instance.UpdatePersistentValue(Module);
  1247. int.TryParse(timeLength, out _manualReplenSecond);
  1248. }
  1249. return result;
  1250. }
  1251. /// <summary>
  1252. /// 阴极自动流水
  1253. /// </summary>
  1254. /// <returns></returns>
  1255. public bool AutoCADiReplen()
  1256. {
  1257. if (IsCALowLevel)
  1258. {
  1259. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"CALowLevel is activate,Can't AutoANDireplen");
  1260. return false;
  1261. }
  1262. return AutoDireplen(CADiReplenOn, DiReplenOperation.AutoCADiReplen);
  1263. }
  1264. /// <summary>
  1265. /// 自动注水公共方法
  1266. /// </summary>
  1267. /// <returns></returns>
  1268. protected bool AutoDireplen(Func<bool> direplenOn, DiReplenOperation reservoirOperation)
  1269. {
  1270. if (_currentDireplenOperation != DiReplenOperation.None)
  1271. {
  1272. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"current operation is {_currentDireplenOperation},cannot execute {reservoirOperation}");
  1273. return false;
  1274. }
  1275. if (_resRecipe == null)
  1276. {
  1277. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"recipe is null");
  1278. return false;
  1279. }
  1280. bool result = direplenOn();
  1281. if (result)
  1282. {
  1283. _currentDireplenOperation = reservoirOperation;
  1284. _persistentValue.DiReplenTime = DateTime.Now;
  1285. }
  1286. return result;
  1287. }
  1288. #endregion
  1289. /// <summary>
  1290. /// 检验阴极是否highlevel
  1291. /// </summary>
  1292. public bool CheckCAHighLevelStatus()
  1293. {
  1294. return ReservoirData.CaWaterLevel > SC.GetValue<double>($"Reservoir.{Module}.CAHighLevel") ? true : false;
  1295. }
  1296. /// <summary>
  1297. /// 检验阴极是否lowlevel
  1298. /// </summary>
  1299. public bool CheckCALowLevelStatus()
  1300. {
  1301. return ReservoirData.CaWaterLevel < SC.GetValue<double>($"Reservoir.{Module}.CALowLevel") ? true : false;
  1302. }
  1303. /// <summary>
  1304. /// 检验CA是否需要注水
  1305. /// </summary>
  1306. /// <returns></returns>
  1307. public bool CheckCANeedDiReplen()
  1308. {
  1309. if (IsAuto && _resRecipe != null)
  1310. {
  1311. if (_resRecipe.DIReplenEnable && _resRecipe.DIReplenTimeRate == 0 && _resRecipe.DIReplenCurrentRate == 0)
  1312. {
  1313. double levelHysteresis = SC.GetValue<double>("Reservoir.LevelHysteresis");
  1314. return _reservoirData.CaLevel < _resRecipe.ReservoirCALevel - levelHysteresis;
  1315. }
  1316. return false;
  1317. }
  1318. else
  1319. {
  1320. return false;
  1321. }
  1322. }
  1323. public void Reset()
  1324. {
  1325. }
  1326. public void Terminate()
  1327. {
  1328. }
  1329. /// <summary>
  1330. /// Temperature Check
  1331. /// </summary>
  1332. private void TemperatureCheck()
  1333. {
  1334. ReservoirEntity reservoirEntity = Singleton<RouteManager>.Instance.GetModule<ReservoirEntity>(Module);
  1335. ReservoirItem reservoirItem = ReservoirItemManager.Instance.GetReservoirItem(Module);
  1336. TemperatureController temperatureController = DEVICE.GetDevice<TemperatureController>(reservoirItem.TCID);
  1337. if (temperatureController == null || temperatureController.TemperatureData == null || _resRecipe == null
  1338. || temperatureController.TemperatureData.ControlOperationModel != ENABLE) return;
  1339. double tempValue = temperatureController.TemperatureData.ReserviorTemperature;
  1340. if (tempValue > _resRecipe.TemperatureErrorHigh && !reservoirEntity.IsError)
  1341. {
  1342. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"{temperatureController.Name} temperature:{tempValue} is over recipe TemperatureErrorHigh parameter:{_resRecipe.TemperatureErrorHigh}");
  1343. reservoirEntity.PostMsg(ReservoirMsg.Error);
  1344. }
  1345. else if (tempValue < _resRecipe.TemperatureErrorLow && !reservoirEntity.IsError)
  1346. {
  1347. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"{temperatureController.Name} temperature:{tempValue} is less than recipe TemperatureErrorLow parameter:{_resRecipe.TemperatureErrorLow}");
  1348. reservoirEntity.PostMsg(ReservoirMsg.Error);
  1349. }
  1350. else if (tempValue > _resRecipe.TemperatureWarningHigh)
  1351. {
  1352. if (!_isTCControlWARN)
  1353. {
  1354. LOG.WriteLog(eEvent.WARN_RESERVOIR, Module, $"{temperatureController.Name} temperature:{tempValue} is over recipe TemperatureWarningHigh parameter:{_resRecipe.TemperatureWarningHigh}");
  1355. _isTCControlWARN = true;
  1356. AlarmListManager.Instance.AddWarn(Module,
  1357. $"Temperature", $"{Module} temperature:{tempValue} is large than recipe temperatureWarningHigh{_resRecipe.TemperatureWarningHigh}");
  1358. }
  1359. }
  1360. else if (tempValue < _resRecipe.TemperatureWarningLow)
  1361. {
  1362. if (!_isTCControlWARN)
  1363. {
  1364. LOG.WriteLog(eEvent.WARN_RESERVOIR, Module, $"{temperatureController.Name} temperature;{tempValue} is less than recipe TemperatureWarningLow parameter:{_resRecipe.TemperatureWarningLow}");
  1365. _isTCControlWARN = true;
  1366. AlarmListManager.Instance.AddWarn(Module,
  1367. $"Temperature", $"{Module} temperature:{tempValue} is lower than recipe temperatureWarningLow{_resRecipe.TemperatureWarningLow}");
  1368. }
  1369. }
  1370. else
  1371. {
  1372. _isTCControlWARN = false;
  1373. }
  1374. }
  1375. }
  1376. }