ReservoirDevice.cs 58 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445
  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. _platingCellDevice.ManualOperation("", null); //切manual 把对应的platingcell 也切换成manual
  749. return true;
  750. }
  751. /// <summary>
  752. /// AutoAction
  753. /// </summary>
  754. /// <param name="cmd"></param>
  755. /// <param name="param"></param>
  756. /// <returns></returns>
  757. private bool AutoOperation(string cmd, object[] args)
  758. {
  759. string currentOperation = "Auto";
  760. string preOperation = _persistentValue.OperatingMode;
  761. _persistentValue.OperatingMode = currentOperation;
  762. LOG.WriteLog(eEvent.INFO_RESERVOIR, Module, $"Operating mode is switched from {preOperation} to {currentOperation}");
  763. ReservoirsPersistentManager.Instance.UpdatePersistentValue(Module);
  764. return true;
  765. }
  766. /// <summary>
  767. /// EngineeringModeAction
  768. /// </summary>
  769. /// <param name="cmd"></param>
  770. /// <param name="param"></param>
  771. /// <returns></returns>
  772. private bool EngineeringModeOperation(string cmd, object[] args)
  773. {
  774. string currentRecipeOperation = "Engineering";
  775. if (_persistentValue != null)
  776. {
  777. _persistentValue.RecipeOperatingMode = currentRecipeOperation;
  778. }
  779. ReservoirsPersistentManager.Instance.UpdatePersistentValue(Module);
  780. return true;
  781. }
  782. /// <summary>
  783. /// ProductionAction
  784. /// </summary>
  785. /// <param name="cmd"></param>
  786. /// <param name="param"></param>
  787. /// <returns></returns>
  788. private bool ProductionModeOperation(string cmd, object[] args)
  789. {
  790. string currentRecipeOperation = "Production";
  791. if (_persistentValue != null)
  792. {
  793. _persistentValue.RecipeOperatingMode = currentRecipeOperation;
  794. }
  795. ReservoirsPersistentManager.Instance.UpdatePersistentValue(Module);
  796. return true;
  797. }
  798. #endregion
  799. /// <summary>
  800. /// 加载Recipe
  801. /// </summary>
  802. /// <param name="cmd"></param>
  803. /// <param name="args"></param>
  804. /// <returns></returns>
  805. private bool LoadRecipeOperation(string cmd, object[] args)
  806. {
  807. _persistentValue.Recipe = args[0].ToString();
  808. string[] fileRoute = _persistentValue.Recipe.Split('\\');
  809. string recipeRoute = "";
  810. if (fileRoute.Length > 2)
  811. {
  812. recipeRoute = fileRoute[fileRoute.Length - 2];
  813. }
  814. _resRecipe = RecipeFileManager.Instance.LoadGenericityRecipe<ResRecipe>(_persistentValue.Recipe);
  815. ReservoirsPersistentManager.Instance.UpdatePersistentValue(Module.ToString());
  816. LOG.WriteLog(eEvent.INFO_RESERVOIR, Module.ToString(), $"Load {recipeRoute} Recipe {_resRecipe.Ppid} Success");
  817. return true;
  818. }
  819. /// <summary>
  820. /// 监控
  821. /// </summary>
  822. public void Monitor()
  823. {
  824. }
  825. #region CA Pump
  826. /// <summary>
  827. /// CA Pump调速
  828. /// </summary>
  829. /// <param name="cmd"></param>
  830. /// <param name="args"></param>
  831. /// <returns></returns>
  832. private bool CAPumpSpeedOperation(string cmd, object[] args)
  833. {
  834. double caMaxPumpSpeed = 0;
  835. if (SC.ContainsItem("Reservoir.CAMaxPumpSpeed"))
  836. {
  837. caMaxPumpSpeed = SC.GetValue<double>("Reservoir.CAMaxPumpSpeed");
  838. }
  839. if (double.TryParse(args[0].ToString(), out double speed))
  840. {
  841. _caPumpSpeed = speed;
  842. if (_caPumpSpeed > caMaxPumpSpeed)
  843. {
  844. LOG.WriteLog(eEvent.WARN_METAL, Module, $"CA pump speed:{_caPumpSpeed} is over CA max pump speed {caMaxPumpSpeed}!");
  845. return false;
  846. }
  847. return CAPumpSpeed(_caPumpSpeed);
  848. }
  849. else
  850. {
  851. LOG.WriteLog(eEvent.ERR_METAL, Module, $"{args[0]} is nor invalid speed");
  852. return false;
  853. }
  854. }
  855. /// <summary>
  856. /// 设置阴极泵速
  857. /// </summary>
  858. /// <param name="caPumpSpeed"></param>
  859. /// <returns></returns>
  860. public bool CAPumpSpeed(double caPumpSpeed)
  861. {
  862. string ioName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{CA_PUMP_SPEED}");
  863. return BeckhoffIOManager.Instance.WriteIoValue(ioName, caPumpSpeed);
  864. }
  865. /// <summary>
  866. /// 阴极Pump On
  867. /// </summary>
  868. /// <param name="cmd"></param>
  869. /// <param name="args"></param>
  870. /// <returns></returns>
  871. public bool CAPumpOn(string cmd, object[] args)
  872. {
  873. double caPumpSpeed = SC.GetValue<double>("Reservoir.CADefaultPumpSpeed");
  874. bool result = CAPumpSpeed(caPumpSpeed);
  875. if (result)
  876. {
  877. string enableIOName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{CA_PUMP_ENABLE}");
  878. return BeckhoffIOManager.Instance.WriteIoValue(enableIOName, true);
  879. }
  880. else
  881. {
  882. return false;
  883. }
  884. }
  885. /// <summary>
  886. /// 阴极Pump Off
  887. /// </summary>
  888. /// <param name="cmd"></param>
  889. /// <param name="args"></param>
  890. /// <returns></returns>
  891. public bool CAPumpOff(string cmd, object[] args)
  892. {
  893. string ioName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{CA_PUMP_ENABLE}");
  894. return BeckhoffIOManager.Instance.WriteIoValue(ioName, false);
  895. }
  896. #endregion
  897. #region Return Valve
  898. /// <summary>
  899. /// Return Valve
  900. /// </summary>
  901. /// <param name="cmd"></param>
  902. /// <param name="args"></param>
  903. /// <returns></returns>
  904. private bool ReturnValvePercentOperation(string cmd, object[] args)
  905. {
  906. if (double.TryParse(args[0].ToString(), out double percent))
  907. {
  908. _returnValvePercent = percent;
  909. return ReturnValvePercent(_returnValvePercent);
  910. }
  911. else
  912. {
  913. LOG.WriteLog(eEvent.ERR_METAL, Module, $"{args[0]} is invalid percent");
  914. return false;
  915. }
  916. }
  917. /// <summary>
  918. /// 设置比例
  919. /// </summary>
  920. /// <param name="caPumpSpeed"></param>
  921. /// <returns></returns>
  922. public bool ReturnValvePercent(double percent)
  923. {
  924. string ioName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{RETURN_VALVE_OPENING}");
  925. return BeckhoffIOManager.Instance.WriteIoValue(ioName, percent);
  926. }
  927. /// <summary>
  928. /// Return Valve On
  929. /// </summary>
  930. /// <param name="cmd"></param>
  931. /// <param name="args"></param>
  932. /// <returns></returns>
  933. public bool ReturnValveOn(string cmd, object[] args)
  934. {
  935. double percent = SC.GetValue<int>("Reservoir.ReturnOpenDefaultPercentage");
  936. return ReturnValvePercent(percent);
  937. }
  938. /// <summary>
  939. /// Return Valve Off
  940. /// </summary>
  941. /// <param name="cmd"></param>
  942. /// <param name="args"></param>
  943. /// <returns></returns>
  944. public bool ReturnValveOff()
  945. {
  946. return ReturnValvePercent(0);
  947. }
  948. #endregion
  949. /// <summary>
  950. /// CAIsolationOn
  951. /// </summary>
  952. /// <returns></returns>
  953. public bool CAIsolationOn()
  954. {
  955. return WriteVariableValue(CA_ISOLATION, true);
  956. }
  957. /// <summary>
  958. /// CAIsolationOff
  959. /// </summary>
  960. /// <returns></returns>
  961. public bool CAIsolationOff()
  962. {
  963. return WriteVariableValue(CA_ISOLATION, false);
  964. }
  965. /// <summary>
  966. /// ANIsolationOn
  967. /// </summary>
  968. /// <returns></returns>
  969. public bool ANIsolationOn()
  970. {
  971. return WriteVariableValue(AN_ISOLATION, true);
  972. }
  973. /// <summary>
  974. /// ANIsolationOff
  975. /// </summary>
  976. /// <returns></returns>
  977. public bool ANIsolationOff()
  978. {
  979. return WriteVariableValue(AN_ISOLATION, false);
  980. }
  981. /// <summary>
  982. /// DegasValveOn
  983. /// </summary>
  984. /// <returns></returns>
  985. public bool DegasValveOn()
  986. {
  987. return WriteVariableValue(DEGAS_ENABLE, true);
  988. }
  989. /// <summary>
  990. /// DegasValveOff
  991. /// </summary>
  992. /// <returns></returns>
  993. public bool DegasValveOff()
  994. {
  995. return WriteVariableValue(DEGAS_ENABLE, false);
  996. }
  997. /// <summary>
  998. /// HedValveOn
  999. /// </summary>
  1000. /// <returns></returns>
  1001. public bool HedValveOn()
  1002. {
  1003. return WriteVariableValue(HED_FLOW_ENABLE, true);
  1004. }
  1005. /// <summary>
  1006. /// HedValveOff
  1007. /// </summary>
  1008. /// <returns></returns>
  1009. public bool HedValveOff()
  1010. {
  1011. return WriteVariableValue(HED_FLOW_ENABLE, false);
  1012. }
  1013. /// <summary>
  1014. /// PhValveOn
  1015. /// </summary>
  1016. /// <returns></returns>
  1017. public bool PhValveOn()
  1018. {
  1019. return WriteVariableValue(PH_FLOW_VALVE, true);
  1020. }
  1021. /// <summary>
  1022. /// PhValveOff
  1023. /// </summary>
  1024. /// <returns></returns>
  1025. public bool PhValveOff()
  1026. {
  1027. return WriteVariableValue(PH_FLOW_VALVE, false);
  1028. }
  1029. /// <summary>
  1030. /// SampleOutValveOn
  1031. /// </summary>
  1032. /// <returns></returns>
  1033. public bool SampleOutValveOn()
  1034. {
  1035. return WriteVariableValue(SAMPLE_OUT, true);
  1036. }
  1037. /// <summary>
  1038. /// SampleOutValveOff
  1039. /// </summary>
  1040. /// <returns></returns>
  1041. public bool SampleOutValveOff()
  1042. {
  1043. return WriteVariableValue(SAMPLE_OUT, false);
  1044. }
  1045. #region CA DiReplen
  1046. /// <summary>
  1047. /// 阴极DI Replen On
  1048. /// </summary>
  1049. /// <param name="cmd"></param>
  1050. /// <param name="args"></param>
  1051. /// <returns></returns>
  1052. private bool CADiReplenOnOperation(string cmd, object[] args)
  1053. {
  1054. return CADiReplenOn();
  1055. }
  1056. /// <summary>
  1057. /// 阴极DI Replen On
  1058. /// </summary>
  1059. /// <param name="showError"></param>
  1060. /// <returns></returns>
  1061. private bool CADiReplenOn()
  1062. {
  1063. bool preCondition = CheckPreDiReplenCondition();
  1064. if (!preCondition)
  1065. {
  1066. return false;
  1067. }
  1068. if (IsCAHighLevel)
  1069. {
  1070. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"CAHighLevel is activate,Can't do CA_DIReple");
  1071. return false;
  1072. }
  1073. if (IsCALowLevel)
  1074. {
  1075. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"CALowLevel is activate,Can't do CA_DIReple");
  1076. return false;
  1077. }
  1078. if (ReservoirData.AnDiReplen)
  1079. {
  1080. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, "ANDiReplen is on");
  1081. return false;
  1082. }
  1083. string ioName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{CA_DI_REPLEN}");
  1084. return BeckhoffIOManager.Instance.WriteIoValue(ioName, true);
  1085. }
  1086. /// <summary>
  1087. /// 阴极DI Replen Off
  1088. /// </summary>
  1089. /// <param name="cmd"></param>
  1090. /// <param name="args"></param>
  1091. /// <returns></returns>
  1092. private bool CADiReplenOff(string cmd, object[] args)
  1093. {
  1094. string ioName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{CA_DI_REPLEN}");
  1095. bool result = BeckhoffIOManager.Instance.WriteIoValue(ioName, false);
  1096. if (result)
  1097. {
  1098. _persistentValue.IsDiReplenOn = false;
  1099. if (_currentDireplenOperation == DiReplenOperation.ManualCADiReplen || _currentDireplenOperation == DiReplenOperation.AutoCADiReplen)
  1100. {
  1101. _currentDireplenOperation = DiReplenOperation.None;
  1102. _persistentValue.LastTotalReplen = _persistentValue.TotalReplen;
  1103. ReservoirsPersistentManager.Instance.UpdatePersistentValue(Module);
  1104. }
  1105. }
  1106. return result;
  1107. }
  1108. /// <summary>
  1109. /// 检验DiReplen前置条件
  1110. /// </summary>
  1111. /// <returns></returns>
  1112. public bool CheckPreDiReplenCondition()
  1113. {
  1114. if (!CheckFacilitiesDiReplenStatus())
  1115. {
  1116. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, "Facilities DiReplen is Off, can't start auto diReplen");
  1117. return false;
  1118. }
  1119. SafetyDevice safetyDevice = DEVICE.GetDevice<SafetyDevice>("Safety");
  1120. if (safetyDevice != null && safetyDevice.SafetyData.Reservoir1CALevelHigh)
  1121. {
  1122. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"Safety high is Activate, can't start auto diReplen");
  1123. return false;
  1124. }
  1125. if (CheckOtherReservoirDiReplenStatus())
  1126. {
  1127. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"there is exist reservoir in diReplen, can't start auto diReplen");
  1128. return false;
  1129. }
  1130. return true;
  1131. }
  1132. /// <summary>
  1133. /// 检验总Di有没有开
  1134. /// </summary>
  1135. /// <returns></returns>
  1136. private bool CheckFacilitiesDiReplenStatus()
  1137. {
  1138. SystemFacilities systemFacilities = DEVICE.GetDevice<SystemFacilities>("System.Facilities");
  1139. if (systemFacilities != null)
  1140. {
  1141. return systemFacilities.DIReplenEnable;
  1142. }
  1143. return false;
  1144. }
  1145. /// <summary>
  1146. /// 检验是否其他Reservoir Direplen已经
  1147. /// </summary>
  1148. /// <returns></returns>
  1149. protected bool CheckOtherReservoirDiReplenStatus()
  1150. {
  1151. List<string> reservoirs = ReservoirItemManager.Instance.InstalledModules;
  1152. foreach (string item in reservoirs)
  1153. {
  1154. if (item != Module)
  1155. {
  1156. ReservoirItem reservoirItem = ReservoirItemManager.Instance.GetReservoirItem(item);
  1157. if (reservoirItem.SubType == ReservoirType.DegasMembrance.ToString())
  1158. {
  1159. DMReservoirDevice tmpDevice = DEVICE.GetDevice<DMReservoirDevice>(item);
  1160. if (tmpDevice.ReservoirData.AnDiReplen)
  1161. {
  1162. if (!_isOtherDIReplenWarnOn)
  1163. {
  1164. _isOtherDIReplenWarnOn = true;
  1165. LOG.WriteLog(eEvent.WARN_RESERVOIR, Module, $"{item} AN DiReplen valve is on. {Module} is waiting DiReplen");
  1166. }
  1167. return true;
  1168. }
  1169. if (tmpDevice.ReservoirData.CaDiReplen)
  1170. {
  1171. if (!_isOtherDIReplenWarnOn)
  1172. {
  1173. _isOtherDIReplenWarnOn = true;
  1174. LOG.WriteLog(eEvent.WARN_RESERVOIR, Module, $"{item} CA DiReplen valve is on. {Module} is waiting DiReplen");
  1175. }
  1176. return true;
  1177. }
  1178. }
  1179. }
  1180. }
  1181. _isOtherDIReplenWarnOn = false;
  1182. return false;
  1183. }
  1184. #endregion
  1185. #region DiReplen Operation
  1186. /// <summary>
  1187. /// 重置时长
  1188. /// </summary>
  1189. /// <param name="cmd"></param>
  1190. /// <param name="objs"></param>
  1191. /// <returns></returns>
  1192. private bool ResetTotalTime(string cmd, object[] objs)
  1193. {
  1194. _isDIReplenMaxTimeOut = false;
  1195. _isDIReplenPerfillTimeOut = false;
  1196. _persistentValue.TotalReplen = 0;
  1197. _persistentValue.LastTotalReplen = 0;
  1198. ReservoirsPersistentManager.Instance.UpdatePersistentValue(Module);
  1199. return true;
  1200. }
  1201. /// <summary>
  1202. /// 手动阴极注水
  1203. /// </summary>
  1204. /// <param name="cmd"></param>
  1205. /// <param name="args"></param>
  1206. /// <returns></returns>
  1207. private bool ManualCADiReplen(string cmd, object[] args)
  1208. {
  1209. return ManualDiReplen(CADiReplenOnOperation, DiReplenOperation.ManualCADiReplen, args[0].ToString());
  1210. }
  1211. /// <summary>
  1212. /// 手动注水
  1213. /// </summary>
  1214. /// <param name="direplenOn"></param>
  1215. /// <param name="direplenOperation"></param>
  1216. /// <returns></returns>
  1217. protected bool ManualDiReplen(Func<string, object[], bool> direplenOn, DiReplenOperation direplenOperation, string timeLength)
  1218. {
  1219. if (_currentDireplenOperation != DiReplenOperation.None)
  1220. {
  1221. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"current operation is {_currentDireplenOperation},cannot execute {direplenOperation}");
  1222. return false;
  1223. }
  1224. ReservoirEntity reservoirEntity = Singleton<RouteManager>.Instance.GetModule<ReservoirEntity>(Module);
  1225. if (!reservoirEntity.IsInitialized)
  1226. {
  1227. LOG.WriteLog(eEvent.WARN_RESERVOIR, Module, $"{Module} is not initialized. Can't start DiReplen");
  1228. return false;
  1229. }
  1230. if (_isDIReplenMaxTimeOut)
  1231. {
  1232. double diValveMaxOnTime = SC.GetValue<double>($"Reservoir.{Module}.DIValveMaxOnTime");
  1233. LOG.WriteLog(eEvent.WARN_RESERVOIR, Module, $"Direplen time over conifg's DIValveMaxOnTime:{diValveMaxOnTime} min");
  1234. return false;
  1235. }
  1236. if (_isDIReplenPerfillTimeOut)
  1237. {
  1238. double diValveMaxOnTimePerFill = SC.GetValue<double>($"Reservoir.{Module}.DIValveMaxOnTimePerFill");
  1239. LOG.WriteLog(eEvent.WARN_RESERVOIR, Module, $"Direplen time over conifg's DIValveMaxOnTimePerFill:{diValveMaxOnTimePerFill} min");
  1240. return false;
  1241. }
  1242. bool result = direplenOn("", null);
  1243. if (result)
  1244. {
  1245. _currentDireplenOperation = direplenOperation;
  1246. _persistentValue.DiReplenTime = DateTime.Now;
  1247. ReservoirsPersistentManager.Instance.UpdatePersistentValue(Module);
  1248. int.TryParse(timeLength, out _manualReplenSecond);
  1249. }
  1250. return result;
  1251. }
  1252. /// <summary>
  1253. /// 阴极自动流水
  1254. /// </summary>
  1255. /// <returns></returns>
  1256. public bool AutoCADiReplen()
  1257. {
  1258. if (IsCALowLevel)
  1259. {
  1260. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"CALowLevel is activate,Can't AutoANDireplen");
  1261. return false;
  1262. }
  1263. return AutoDireplen(CADiReplenOn, DiReplenOperation.AutoCADiReplen);
  1264. }
  1265. /// <summary>
  1266. /// 自动注水公共方法
  1267. /// </summary>
  1268. /// <returns></returns>
  1269. protected bool AutoDireplen(Func<bool> direplenOn, DiReplenOperation reservoirOperation)
  1270. {
  1271. if (_currentDireplenOperation != DiReplenOperation.None)
  1272. {
  1273. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"current operation is {_currentDireplenOperation},cannot execute {reservoirOperation}");
  1274. return false;
  1275. }
  1276. if (_resRecipe == null)
  1277. {
  1278. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"recipe is null");
  1279. return false;
  1280. }
  1281. bool result = direplenOn();
  1282. if (result)
  1283. {
  1284. _currentDireplenOperation = reservoirOperation;
  1285. _persistentValue.DiReplenTime = DateTime.Now;
  1286. }
  1287. return result;
  1288. }
  1289. #endregion
  1290. /// <summary>
  1291. /// 检验阴极是否highlevel
  1292. /// </summary>
  1293. public bool CheckCAHighLevelStatus()
  1294. {
  1295. return ReservoirData.CaWaterLevel > SC.GetValue<double>($"Reservoir.{Module}.CAHighLevel") ? true : false;
  1296. }
  1297. /// <summary>
  1298. /// 检验阴极是否lowlevel
  1299. /// </summary>
  1300. public bool CheckCALowLevelStatus()
  1301. {
  1302. return ReservoirData.CaWaterLevel < SC.GetValue<double>($"Reservoir.{Module}.CALowLevel") ? true : false;
  1303. }
  1304. /// <summary>
  1305. /// 检验CA是否需要注水
  1306. /// </summary>
  1307. /// <returns></returns>
  1308. public bool CheckCANeedDiReplen()
  1309. {
  1310. if (IsAuto && _resRecipe != null)
  1311. {
  1312. if (_resRecipe.DIReplenEnable && _resRecipe.DIReplenTimeRate == 0 && _resRecipe.DIReplenCurrentRate == 0)
  1313. {
  1314. double levelHysteresis = SC.GetValue<double>("Reservoir.LevelHysteresis");
  1315. return _reservoirData.CaLevel < _resRecipe.ReservoirCALevel - levelHysteresis;
  1316. }
  1317. return false;
  1318. }
  1319. else
  1320. {
  1321. return false;
  1322. }
  1323. }
  1324. public void Reset()
  1325. {
  1326. }
  1327. public void Terminate()
  1328. {
  1329. }
  1330. /// <summary>
  1331. /// Temperature Check
  1332. /// </summary>
  1333. private void TemperatureCheck()
  1334. {
  1335. ReservoirEntity reservoirEntity = Singleton<RouteManager>.Instance.GetModule<ReservoirEntity>(Module);
  1336. ReservoirItem reservoirItem = ReservoirItemManager.Instance.GetReservoirItem(Module);
  1337. TemperatureController temperatureController = DEVICE.GetDevice<TemperatureController>(reservoirItem.TCID);
  1338. if (temperatureController == null || temperatureController.TemperatureData == null || _resRecipe == null
  1339. || temperatureController.TemperatureData.ControlOperationModel != ENABLE) return;
  1340. double tempValue = temperatureController.TemperatureData.ReserviorTemperature;
  1341. if (tempValue > _resRecipe.TemperatureErrorHigh && !reservoirEntity.IsError)
  1342. {
  1343. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"{temperatureController.Name} temperature:{tempValue} is over recipe TemperatureErrorHigh parameter:{_resRecipe.TemperatureErrorHigh}");
  1344. reservoirEntity.PostMsg(ReservoirMsg.Error);
  1345. }
  1346. else if (tempValue < _resRecipe.TemperatureErrorLow && !reservoirEntity.IsError)
  1347. {
  1348. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"{temperatureController.Name} temperature:{tempValue} is less than recipe TemperatureErrorLow parameter:{_resRecipe.TemperatureErrorLow}");
  1349. reservoirEntity.PostMsg(ReservoirMsg.Error);
  1350. }
  1351. else if (tempValue > _resRecipe.TemperatureWarningHigh)
  1352. {
  1353. if (!_isTCControlWARN)
  1354. {
  1355. LOG.WriteLog(eEvent.WARN_RESERVOIR, Module, $"{temperatureController.Name} temperature:{tempValue} is over recipe TemperatureWarningHigh parameter:{_resRecipe.TemperatureWarningHigh}");
  1356. _isTCControlWARN = true;
  1357. AlarmListManager.Instance.AddWarn(Module,
  1358. $"Temperature", $"{Module} temperature:{tempValue} is large than recipe temperatureWarningHigh{_resRecipe.TemperatureWarningHigh}");
  1359. }
  1360. }
  1361. else if (tempValue < _resRecipe.TemperatureWarningLow)
  1362. {
  1363. if (!_isTCControlWARN)
  1364. {
  1365. LOG.WriteLog(eEvent.WARN_RESERVOIR, Module, $"{temperatureController.Name} temperature;{tempValue} is less than recipe TemperatureWarningLow parameter:{_resRecipe.TemperatureWarningLow}");
  1366. _isTCControlWARN = true;
  1367. AlarmListManager.Instance.AddWarn(Module,
  1368. $"Temperature", $"{Module} temperature:{tempValue} is lower than recipe temperatureWarningLow{_resRecipe.TemperatureWarningLow}");
  1369. }
  1370. }
  1371. else
  1372. {
  1373. _isTCControlWARN = false;
  1374. }
  1375. }
  1376. }
  1377. }