StandardHotReservoirDevice.cs 94 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000
  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.Beckhoff.ModuleIO;
  9. using MECF.Framework.Common.CommonData.Reservoir;
  10. using MECF.Framework.Common.Persistent.Reservoirs;
  11. using MECF.Framework.Common.RecipeCenter;
  12. using MECF.Framework.Common.ToolLayout;
  13. using MECF.Framework.Common.TwinCat;
  14. using CyberX8_Core;
  15. using CyberX8_RT.Devices.Facilities;
  16. using CyberX8_RT.Devices.Metal;
  17. using CyberX8_RT.Modules.Reservoir;
  18. using System;
  19. using System.Collections.Generic;
  20. using System.Reflection;
  21. using CyberX8_RT.Modules;
  22. using System.Collections.ObjectModel;
  23. using CyberX8_RT.Devices.Dose;
  24. using CyberX8_RT.Modules.Metal;
  25. using CyberX8_RT.Devices.Temperature;
  26. using CyberX8_RT.Devices.PowerSupplier;
  27. using System.Linq;
  28. using CyberX8_RT.Devices.Safety;
  29. using MECF.Framework.Common.ProcessCell;
  30. using MECF.Framework.Common.Alarm;
  31. using MECF.Framework.Common.IOCore;
  32. namespace CyberX8_RT.Devices.Reservoir
  33. {
  34. public class StandardHotReservoirDevice : BaseDevice, IDevice
  35. {
  36. private enum ReservoirOperation
  37. {
  38. None,
  39. ManualDiReplen,
  40. AutoDiReplen
  41. }
  42. private enum DosingOperation
  43. {
  44. None,
  45. ManualDosing,
  46. AutoDosing,
  47. }
  48. #region 常量
  49. private const string AUTO = "Auto";
  50. private const string MANUAL = "Manual";
  51. private const string DISABLE = "Disable";
  52. private const string STRATUS = "Stratus";
  53. private const string PERSISTENT_VALUE = "PersistentValue";
  54. private const string FLOW = "Flow";
  55. private const string HED_FLOW = "HedFlow";
  56. private const string PH_FLOW_VALVE = "PHFlowValve";
  57. private const string PH_VALUE = "PHValue";
  58. private const string WATER_LEVEL = "WaterLevel";
  59. private const string LOW_LEVEL = "LowLevel";
  60. private const string HIGH_LEVEL = "HighLevel";
  61. private const string SAFETY_HIGH_LEVEL = "SafetyHighLevel";
  62. private const string DI_REPLEN = "DiReplen";
  63. private const string RESERVOIRDEVICEDATA = "ReservoirDeviceData";
  64. private const string REPLEN_LEVEL = "ReplenLevel";
  65. private const double PUMP_SPEED_CONVERT = 0.0672;
  66. private const int ENABLE = 5;
  67. #endregion
  68. #region 内部变量
  69. /// <summary>
  70. /// Level取样平均值
  71. /// </summary>
  72. private double _avgLevel;
  73. /// <summary>
  74. /// AN Level取样队列
  75. /// </summary>
  76. private Queue<double> _LevelSamples;
  77. /// <summary>
  78. /// Level计算平均值取样数
  79. /// </summary>
  80. private int levelSampleCount;
  81. /// <summary>
  82. /// Prewet 持久性数值对象
  83. /// </summary>
  84. private ReservoirsPersistentValue _persistentValue;
  85. /// <summary>
  86. /// 定时器Job
  87. /// </summary>
  88. PeriodicJob _periodicJob = null;
  89. /// <summary>
  90. /// 变量是否初始化字典
  91. /// </summary>
  92. private Dictionary<string, bool> _variableInitializeDic = new Dictionary<string, bool>();
  93. /// <summary>
  94. /// Reservoir数据
  95. /// </summary>
  96. private StandardHotReservoirData _reservoirData = new StandardHotReservoirData();
  97. /// <summary>
  98. /// 当前操作
  99. /// </summary>
  100. private ReservoirOperation _currentOperation = ReservoirOperation.None;
  101. /// <summary>
  102. /// 手动注水时间(秒)
  103. /// </summary>
  104. private int _manualReplenSecond = 0;
  105. /// <summary>
  106. /// 注水是否出错
  107. /// </summary>
  108. private bool _isDiReplenInFault = false;
  109. /// <summary>
  110. /// Recipe
  111. /// </summary>
  112. private ResRecipe _resRecipe;
  113. /// <summary>
  114. /// 平均PH值
  115. /// </summary>
  116. private double _avaragePH;
  117. /// <summary>
  118. /// PH Routine
  119. /// </summary>
  120. private StandardHotPHRoutine _phRoutine;
  121. /// <summary>
  122. /// PH Routine状态
  123. /// </summary>
  124. private RState _phState = RState.Init;
  125. /// <summary>
  126. /// PH结束时间
  127. /// </summary>
  128. private DateTime _phRoutineEndTime = DateTime.Now;
  129. /// <summary>
  130. /// Direplen 逻辑对象
  131. /// </summary>
  132. private ReservoirDiReplenHelper _direplenHelper;
  133. /// <summary>
  134. /// Replen数量
  135. /// </summary>
  136. private int _replenNum = 0;
  137. /// <summary>
  138. /// Dose Replen数据
  139. /// </summary>
  140. private ReplenData[] _replenDatas;
  141. /// <summary>
  142. /// ReplenType
  143. /// </summary>
  144. private string _replenType;
  145. /// <summary>
  146. /// Replen Recipe集合
  147. /// </summary>
  148. private RdsRecipe[] _rdsRecipe;
  149. /// <summary>
  150. /// DosingSystemHelper对象列表
  151. /// </summary>
  152. private List<DosingSystemHelper> _dosingSystemHelperLst;
  153. /// <summary>
  154. /// ReplenLevel 列表
  155. /// </summary>
  156. private List<bool> _replenLevelLst;
  157. /// <summary>
  158. /// 当前操作
  159. /// </summary>
  160. private List<DosingOperation> _currentDosingOperation;
  161. /// <summary>
  162. /// 配置的metal device集合
  163. /// </summary>
  164. private ObservableCollection<StandardHotMetalDevice> _metalDevices = new ObservableCollection<StandardHotMetalDevice>();
  165. /// <summary>
  166. /// Replen Persistent Value
  167. /// </summary>
  168. private Dictionary<string, ReplenPersistentValue> _replenPersistentValue = new Dictionary<string, ReplenPersistentValue>();
  169. /// <summary>
  170. /// DosingCommonHelper
  171. /// </summary>
  172. private DosingCommonHelper _dosingCommonHelper;
  173. /// <summary>
  174. /// WarningFlag
  175. /// </summary>
  176. private List<bool> _isCAFlowRateWARN;
  177. /// <summary>
  178. /// CMM Flow High Error
  179. /// </summary>
  180. private double _reservoirCMMFlowHighError;
  181. /// <summary>
  182. /// CMM Flow Low Error
  183. /// </summary>
  184. private double _reservoirCMMFlowLowError;
  185. /// <summary>
  186. /// ErrorMessage
  187. /// </summary>
  188. private bool _isTCControlWARN = false;
  189. private bool _isCMMPowerCurrentWARN = false;
  190. private bool _isCMMPowerFlowWARN = false;
  191. private bool _isExportCMMUsage = false;
  192. private bool _isAutoDIReplenError = false;
  193. private bool _isSafetyHigh = false;
  194. private bool _isSystemAutoMode = false;
  195. /// <summary>
  196. /// 用于控制打印错误log
  197. /// </summary>
  198. private HashSet<string> errorLogSet = new HashSet<string>();
  199. #endregion
  200. #region 属性
  201. /// <summary>
  202. /// 数据
  203. /// </summary>
  204. public StandardHotReservoirData ReservoirData { get { return _reservoirData; } }
  205. /// <summary>
  206. /// Replen数据
  207. /// </summary>
  208. public ReplenData[] ReplenDatas { get { return _replenDatas; } }
  209. /// <summary>
  210. /// DosingSystemHelper对象列表
  211. /// </summary>
  212. public List<DosingSystemHelper> DosingSystemHelpers { get { return _dosingSystemHelperLst; } }
  213. /// <summary>
  214. /// Replen数量
  215. /// </summary>
  216. public int ReplenNum { get { return _replenNum; } }
  217. /// <summary>
  218. /// 操作模式
  219. /// </summary>
  220. public string OperationMode { get { return _persistentValue.OperatingMode; } }
  221. /// <summary>
  222. /// 工程模式
  223. /// </summary>
  224. public string EngineerMode { get { return _persistentValue.RecipeOperatingMode; } }
  225. /// <summary>
  226. /// 是否自动
  227. /// </summary>
  228. public bool IsAuto { get { return _persistentValue.OperatingMode == AUTO; } }
  229. /// <summary>
  230. /// 是否需要补水
  231. /// </summary>
  232. public bool NeedAutoDireplen { get { return GetNeedAutoDireplen(); } }
  233. /// <summary>
  234. /// 正在补水
  235. /// </summary>
  236. public bool IsDireplenOn { get { return _reservoirData.DiReplen; } }
  237. /// <summary>
  238. /// 平均PH数值
  239. /// </summary>
  240. public double AveragePH { get { return _avaragePH; } set { _avaragePH = value; } }
  241. /// <summary>
  242. /// 当前Recipe
  243. /// </summary>
  244. public ResRecipe Recipe { get { return _resRecipe; } }
  245. /// <summary>
  246. /// 当前Rds Recipe
  247. /// </summary>
  248. public RdsRecipe[] RdsRecipe { get { return _rdsRecipe; } }
  249. #endregion
  250. /// <summary>
  251. /// 初始化成功清除对应的错误log
  252. /// </summary>
  253. /// <param name="module"></param>
  254. public void ClearErrorLogSet(string module)
  255. {
  256. // 使用构造函数复制 HashSet
  257. HashSet<string> newHashSet = new HashSet<string>(errorLogSet);
  258. foreach (var item in newHashSet)
  259. {
  260. if (item.Contains(module))
  261. {
  262. errorLogSet.Remove(item);
  263. }
  264. }
  265. }
  266. /// <summary>
  267. /// 构造函数
  268. /// </summary>
  269. /// <param name="moduleName"></param>
  270. /// <param name="name"></param>
  271. public StandardHotReservoirDevice(string moduleName) : base(moduleName, moduleName, moduleName, moduleName)
  272. {
  273. levelSampleCount = SC.GetValue<int>("Reservoir.LevelAvgSamples");
  274. levelSampleCount = levelSampleCount == 0 ? 20 : levelSampleCount;
  275. _LevelSamples = new Queue<double>(levelSampleCount);
  276. _periodicJob = new PeriodicJob(100, OnTimer, $"{Module}.OnTimer", true);
  277. }
  278. /// <summary>
  279. /// 定时器
  280. /// </summary>
  281. /// <returns></returns>
  282. private bool OnTimer()
  283. {
  284. //计算AN/CA level的平均值
  285. if (ReservoirData != null)
  286. {
  287. //AN
  288. if (_LevelSamples.Count >= levelSampleCount)
  289. {
  290. _LevelSamples.Dequeue();
  291. _LevelSamples.Enqueue(ReservoirData.Level);
  292. }
  293. else
  294. {
  295. _LevelSamples.Enqueue(ReservoirData.Level);
  296. }
  297. _avgLevel = _LevelSamples.Count > 0 ? _LevelSamples.Average() : 0;
  298. }
  299. foreach (StandardHotMetalDevice device in _metalDevices)
  300. {
  301. device.OnTimer(_periodicJob.Interval);
  302. }
  303. ReservoirEntity reservoirEntity = Singleton<RouteManager>.Instance.GetModule<ReservoirEntity>(Module);
  304. //报错停DosingSystem
  305. //if (_replenType != "" && _replenNum != 0 && reservoirEntity != null && reservoirEntity.IsError)
  306. //{
  307. // for (int i = 0; i < _replenNum; i++)
  308. // {
  309. // string replenName = "Replen" + (i + 1).ToString();
  310. // if (_replenPersistentValue[replenName].IsDosingRunning)
  311. // {
  312. // _dosingSystemHelperLst[i].StopDosing();
  313. // _currentDosingOperation[i] = DosingOperation.None;
  314. // }
  315. // }
  316. //}
  317. /// <summary>
  318. /// WaterLevelMonitor
  319. /// </summary>
  320. WaterLevelMonitor();
  321. //触发Safetyhigh将reservoir切成error
  322. SafetyDevice safetyDevice = DEVICE.GetDevice<SafetyDevice>("Safety");
  323. if (safetyDevice != null && safetyDevice.SafetyData.ReservoirHighLevel && !_isSafetyHigh)
  324. {
  325. _isSafetyHigh = true;
  326. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"Safety high is Activate");
  327. reservoirEntity.PostMsg(ReservoirMsg.Error);
  328. }
  329. else
  330. {
  331. _isSafetyHigh = false;
  332. }
  333. //DIReplen
  334. if (_direplenHelper != null)
  335. {
  336. _direplenHelper.MonitorPeriodTime();
  337. if (_currentOperation == ReservoirOperation.ManualDiReplen && _reservoirData.DiReplen)
  338. {
  339. bool result = _direplenHelper.MonitorManualDiReplenComplete(_manualReplenSecond, DIReplenOff);
  340. if (result)
  341. {
  342. _currentOperation = ReservoirOperation.None;
  343. }
  344. }
  345. else if (_currentOperation == ReservoirOperation.AutoDiReplen && _reservoirData.DiReplen)
  346. {
  347. bool result = _direplenHelper.AutoDiReplenMonitorTimeOut(DIReplenOff);
  348. if (result)
  349. {
  350. _currentOperation = ReservoirOperation.None;
  351. //触发注水异常信号
  352. _isDiReplenInFault = true;
  353. }
  354. else
  355. {
  356. //按液位补水
  357. result = _direplenHelper.AutoDiReplenMonitorComplete(_reservoirData.Level, _resRecipe.ReservoirCALevel, _resRecipe.DIReplenEnable,
  358. _resRecipe.DIReplenTimeRate, _resRecipe.DIReplenCurrentRate, DIReplenOff);
  359. if (result)
  360. {
  361. _currentOperation = ReservoirOperation.None;
  362. }
  363. }
  364. }
  365. }
  366. if (reservoirEntity == null || !reservoirEntity.IsInitialized)
  367. {
  368. return true;
  369. }
  370. if (_persistentValue.OperatingMode == AUTO)
  371. {
  372. CAFlowRateCheck();
  373. TemperatureCheck();
  374. CMMPowerCheck();
  375. //CMM用电量记录
  376. if (_isExportCMMUsage && _persistentValue.CMMStartTime != DateTime.MinValue)
  377. {
  378. ReservoirItem reservoirItem = ReservoirItemManager.Instance.GetReservoirItem(Module);
  379. if (!string.IsNullOrEmpty(reservoirItem.CMMSupplyID) && _resRecipe != null && _resRecipe.CMMEnable)
  380. {
  381. CellPowerSupplier powerSupplier = DEVICE.GetDevice<CellPowerSupplier>(reservoirItem.CMMSupplyID);
  382. double cmmUsage = powerSupplier.PowerSupplierData.Current * DateTime.Now.Subtract(_persistentValue.CMMStartTime).TotalHours;
  383. ReservoirUsageManager.Instance.UpdateReservoirCMMUsage(Module, Math.Round(cmmUsage, 3));
  384. _persistentValue.CMMStartTime = DateTime.Now;
  385. ReservoirsPersistentManager.Instance.UpdatePersistentValue(Module);
  386. _isExportCMMUsage = false;
  387. }
  388. }
  389. }
  390. if (_phState == RState.Running)
  391. {
  392. _phState = _phRoutine.Monitor();
  393. if (_phState == RState.End)
  394. {
  395. _phRoutineEndTime = DateTime.Now;
  396. }
  397. }
  398. else if (_phState != RState.Init)
  399. {
  400. double phUpdatePeriod = SC.GetValue<double>("Reservoir.PHUpdatePeriod");
  401. if (DateTime.Now.Subtract(_phRoutineEndTime).TotalMilliseconds >= phUpdatePeriod * 1000)
  402. {
  403. StartDetectPHValve();
  404. }
  405. }
  406. //if (_replenType != "" && _replenNum != 0)
  407. //{
  408. // //DosingSystem 状态监控
  409. // _dosingCommonHelper.DoseStatusMonitor();
  410. // //Dosing监控
  411. // if (_dosingCommonHelper.IsDosingSystemInitialized)
  412. // {
  413. // if (_replenPersistentValue["Replen1"].OperatingMode == "Manual")
  414. // {
  415. // //ManualDosing
  416. // _dosingCommonHelper.ManualDoseSystemMonitor();
  417. // }
  418. // if (_replenPersistentValue["Replen1"].OperatingMode == "Auto")
  419. // {
  420. // //AutoDosing
  421. // _dosingCommonHelper.AutoDoseSystemMonitor();
  422. // }
  423. // else
  424. // {
  425. // _dosingCommonHelper.CheckDoseOperation();
  426. // }
  427. // }
  428. //}
  429. return true;
  430. }
  431. /// <summary>
  432. /// Low Level 触发操作
  433. /// </summary>
  434. private void LowLevelOperation()
  435. {
  436. if (!_reservoirData.LowLevel) //true是正常的
  437. {
  438. ReservoirItem reservoirItem = ReservoirItemManager.Instance.GetReservoirItem(Module);
  439. foreach (var metalDevice in _metalDevices)
  440. {
  441. if (metalDevice.MetalDeviceData.Circulation)
  442. {
  443. metalDevice.SwitchToBypass($"{metalDevice.Name}.SwitchToBypass", null);
  444. }
  445. if (metalDevice.MetalDeviceData.CellFlow > 0)
  446. {
  447. metalDevice.PumpOff();
  448. }
  449. //水位过低时将起对应的metal也要切成error
  450. MetalEntity metalEntity = Singleton<RouteManager>.Instance.GetModule<MetalEntity>(metalDevice.DeviceID);
  451. if (metalEntity != null && !metalEntity.IsError)
  452. {
  453. metalEntity.PostMsg(MetalMsg.Error);
  454. }
  455. }
  456. //禁用TC
  457. if (!String.IsNullOrEmpty(reservoirItem.TCID))
  458. {
  459. TemperatureController temperatureController = DEVICE.GetDevice<TemperatureController>(reservoirItem.TCID);
  460. if (temperatureController != null && temperatureController.TemperatureData.ControlOperationModel == 5)
  461. {
  462. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"Lowlevel was activate");
  463. temperatureController.DisableOperation("", null);
  464. }
  465. }
  466. }
  467. }
  468. /// <summary>
  469. /// High Level 触发操作
  470. /// </summary>
  471. private void HighLevelOperation()
  472. {
  473. SystemFacilities systemFacilities = DEVICE.GetDevice<SystemFacilities>("System.Facilities");
  474. if (systemFacilities != null)
  475. {
  476. if (systemFacilities.DIFillEnable) systemFacilities.DiFillDisableOperation("DIFillDisableOpeartion", null);
  477. if (systemFacilities.DIReplenEnable) systemFacilities.DiReplenDisableOperation("DiReplenDisableOperation", null);
  478. if (ReservoirData.DiReplen)
  479. {
  480. _currentOperation = ReservoirOperation.None;
  481. DIReplenOff("", null);
  482. }
  483. }
  484. }
  485. /// <summary>
  486. /// WaterLevelMonitor
  487. /// </summary>
  488. private void WaterLevelMonitor()
  489. {
  490. ReservoirEntity reservoirEntity = Singleton<RouteManager>.Instance.GetModule<ReservoirEntity>(Module);
  491. _isSystemAutoMode = reservoirEntity.IsAuto;
  492. //触发水位过高或者过低将reservoir切成error
  493. if (!_reservoirData.LowLevel)
  494. {
  495. if (!errorLogSet.Contains($"{Module}.WaterLevel"))
  496. {
  497. errorLogSet.Add($"{Module}.WaterLevel");
  498. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"WaterLevel low is Activate");
  499. }
  500. LowLevelOperation();
  501. if (!reservoirEntity.IsError)
  502. {
  503. reservoirEntity.PostMsg(ReservoirMsg.Error);
  504. }
  505. if (_isSystemAutoMode && !AlarmListManager.Instance.IsContainDataError(Module, "WaterLevel"))
  506. {
  507. AlarmListManager.Instance.AddDataError(Module,
  508. $"WaterLevel", $"WaterLevel low is Activate");
  509. }
  510. }
  511. else if (ReservoirData.WaterLevel > SC.GetValue<double>($"Reservoir.{Module}.HighLevel"))
  512. {
  513. if (!errorLogSet.Contains($"{Module}.WaterLevel"))
  514. {
  515. errorLogSet.Add($"{Module}.WaterLevel");
  516. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"WaterLevel:{ReservoirData.WaterLevel} is larger than HighLevel Config:{SC.GetValue<double>($"Reservoir.{Module}.HighLevel")}");
  517. }
  518. HighLevelOperation();
  519. if (!reservoirEntity.IsError)
  520. {
  521. reservoirEntity.PostMsg(ReservoirMsg.Error);
  522. }
  523. if (_isSystemAutoMode && !AlarmListManager.Instance.IsContainDataError(Module, "WaterLevel"))
  524. {
  525. AlarmListManager.Instance.AddDataError(Module,
  526. $"WaterLevel", $"WaterLevel:{ReservoirData.WaterLevel} is larger than HighLevel Config:{SC.GetValue<double>($"Reservoir.{Module}.HighLevel")}");
  527. }
  528. }
  529. //水位触发reservoir里面的high/low将对应的reservoir切成error
  530. if (_resRecipe == null) return;
  531. if (ReservoirData.Level < _resRecipe.CALevelErrorLow)
  532. {
  533. if (!errorLogSet.Contains($"{Module}.Level"))
  534. {
  535. errorLogSet.Add($"{Module}.Level");
  536. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"Current level:{ReservoirData.Level} is lower than recipe's CA Errorlow paramater:{_resRecipe.CALevelErrorLow}");
  537. }
  538. if (!reservoirEntity.IsError)
  539. {
  540. reservoirEntity.PostMsg(ReservoirMsg.Error);
  541. }
  542. if (_isSystemAutoMode && !AlarmListManager.Instance.IsContainDataError(Module, "Level"))
  543. {
  544. AlarmListManager.Instance.AddDataError(Module,
  545. $"Level", $"Current level:{ReservoirData.Level} is lower than recipe's CA Errorlow paramater:{_resRecipe.CALevelErrorLow}");
  546. }
  547. }
  548. else if (ReservoirData.Level > _resRecipe.CALevelErrorHigh)
  549. {
  550. if (!errorLogSet.Contains($"{Module}.Level"))
  551. {
  552. errorLogSet.Add($"{Module}.Level");
  553. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"Current level:{ReservoirData.Level} is larger than recipe's CA ErrorHigh paramater:{_resRecipe.CALevelErrorHigh}");
  554. }
  555. if (!reservoirEntity.IsError)
  556. {
  557. reservoirEntity.PostMsg(ReservoirMsg.Error);
  558. }
  559. if (_isSystemAutoMode && !AlarmListManager.Instance.IsContainDataError(Module, "Level"))
  560. {
  561. AlarmListManager.Instance.AddDataError(Module,
  562. $"Level", $"Current level:{ReservoirData.Level} is larger than recipe's CA ErrorHigh paramater:{_resRecipe.CALevelErrorHigh}");
  563. }
  564. }
  565. }
  566. /// <summary>
  567. /// 获取是否需要补水
  568. /// </summary>
  569. /// <returns></returns>
  570. private bool GetNeedAutoDireplen()
  571. {
  572. if (IsAuto && _resRecipe != null)
  573. {
  574. if (_resRecipe.DIReplenEnable && _resRecipe.DIReplenCurrentRate == 0 && _resRecipe.DIReplenTimeRate == 0)
  575. {
  576. double levelHysteresis = SC.GetValue<double>("Reservoir.LevelHysteresis");
  577. return ReservoirData.Level < _resRecipe.ReservoirCALevel - levelHysteresis;
  578. }
  579. return false;
  580. }
  581. else
  582. {
  583. return false;
  584. }
  585. }
  586. /// <summary>
  587. /// 初始化
  588. /// </summary>
  589. /// <returns></returns>
  590. public bool Initialize()
  591. {
  592. InitializeRoutine();
  593. InitializeParameter();
  594. SubscribeData();
  595. InitializeOperation();
  596. SubscribeValueAction();
  597. return true;
  598. }
  599. /// <summary>
  600. /// 初始化routine
  601. /// </summary>
  602. private void InitializeRoutine()
  603. {
  604. _phRoutine = new StandardHotPHRoutine(Module);
  605. }
  606. /// <summary>
  607. /// 初始化参数
  608. /// </summary>
  609. private void InitializeParameter()
  610. {
  611. _persistentValue = ReservoirsPersistentManager.Instance.GetReservoirsPersistentValue(Module.ToString());
  612. if (_persistentValue == null)
  613. {
  614. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module.ToString(), "Persistent Value Object is not exist");
  615. }
  616. else
  617. {
  618. if (!string.IsNullOrEmpty(_persistentValue.Recipe))
  619. {
  620. _resRecipe = RecipeFileManager.Instance.LoadGenericityRecipe<ResRecipe>(_persistentValue.Recipe);
  621. }
  622. _direplenHelper = new ReservoirDiReplenHelper(Module, _persistentValue);
  623. }
  624. ReservoirItem reservoirItem = ReservoirItemManager.Instance.GetReservoirItem(Module.ToString());
  625. if (reservoirItem != null)
  626. {
  627. foreach (var item in reservoirItem.MetalCells)
  628. {
  629. if (item.ModuleName != Module)
  630. {
  631. StandardHotMetalDevice metalDevice = DEVICE.GetDevice<StandardHotMetalDevice>(item.ModuleName);
  632. if (metalDevice != null)
  633. {
  634. _metalDevices.Add(metalDevice);
  635. }
  636. }
  637. }
  638. }
  639. _isCAFlowRateWARN = new List<bool>(new bool[_metalDevices.Count]);
  640. //DosingSystem数据初始化
  641. _replenType = reservoirItem.ChemReplenType;
  642. _replenNum = reservoirItem.ChemReplenPumps;
  643. if (_replenType != "" && _replenNum != 0)
  644. {
  645. _replenDatas = new ReplenData[_replenNum];
  646. _rdsRecipe = new RdsRecipe[_replenNum];
  647. _replenLevelLst = new List<bool>(new bool[_replenNum]);
  648. _currentDosingOperation = new List<DosingOperation>();
  649. for (int i = 0; i < _replenNum; i++)
  650. {
  651. string replenName = "Replen" + (i + 1).ToString();
  652. _replenDatas[i] = new ReplenData();
  653. _replenDatas[i].ReplenName = replenName;
  654. _replenDatas[i].RecipeName = "";
  655. _replenDatas[i].BottleLevel = DosingSystemHelper.BottleLevelState.Empty.ToString();
  656. _replenDatas[i].IsAutoDosingError = false;
  657. if (_dosingSystemHelperLst == null) _dosingSystemHelperLst = new List<DosingSystemHelper>();
  658. _dosingSystemHelperLst.Add(new DosingSystemHelper(Module, _replenDatas[i].ReplenName));
  659. _currentDosingOperation.Add(DosingOperation.None);
  660. _replenPersistentValue[replenName] = ReplenPersistentManager.Instance.GetReplenPersistentValue(Module, replenName);
  661. }
  662. _dosingCommonHelper = new DosingCommonHelper(Module, _replenNum);
  663. }
  664. }
  665. /// <summary>
  666. /// 订阅数据
  667. /// </summary>
  668. private void SubscribeData()
  669. {
  670. DATA.Subscribe($"{Module}.DIValveMaxOnTime", () => SC.GetValue<double>($"Reservoir.{Module}.DIValveMaxOnTime") * 60, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  671. DATA.Subscribe($"{Module}.IsManualReplen", () => { return _currentOperation == ReservoirOperation.ManualDiReplen; }, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  672. DATA.Subscribe($"{Module}.ReservoirData", () => _reservoirData, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  673. DATA.Subscribe($"{Module}.ReservoirAverageLevel", () => _avgLevel, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  674. DATA.Subscribe($"{Module}.{PERSISTENT_VALUE}", () => _persistentValue, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  675. DATA.Subscribe($"{Module}.ReplenPersistentValue", () => _replenPersistentValue, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  676. DATA.Subscribe($"{Module}.PHValue", () => _avaragePH, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  677. DATA.Subscribe($"{Module}.CurrentRecipe", () => _resRecipe, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  678. DATA.Subscribe($"{Module}.ReplenType", () => _replenType, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  679. DATA.Subscribe($"{Module}.ReplenNum", () => _replenNum, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  680. DATA.Subscribe($"{Module}.ReplenDatas", () => _replenDatas, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  681. DATA.Subscribe($"{Module}.DosingSystemState", () => _dosingCommonHelper != null ? _dosingCommonHelper.DosingSystemState : null, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  682. DATA.Subscribe($"{Module}.RecipeName", () => (_resRecipe != null ? _resRecipe.Ppid : ""), SubscriptionAttribute.FLAG.IgnoreSaveDB);
  683. DATA.Subscribe($"{Module}.HedFlow", () => _reservoirData.HedFlow, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  684. DATA.Subscribe($"{Module}.PHEnable", () => _reservoirData.PHFlowValve, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  685. DATA.Subscribe($"{Module}.IsDIReplenInFault", () => _isDiReplenInFault, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  686. }
  687. /// <summary>
  688. /// 初始化操作
  689. /// </summary>
  690. private void InitializeOperation()
  691. {
  692. OP.Subscribe($"{Module}.DisabledAction", DisabledOperation);
  693. OP.Subscribe($"{Module}.ManualAction", ManualOperation);
  694. OP.Subscribe($"{Module}.AutoAction", AutoOperation);
  695. OP.Subscribe($"{Module}.EngineeringModeAction", EngineeringModeOperation);
  696. OP.Subscribe($"{Module}.ProductionModeAction", ProductionModeOperation);
  697. OP.Subscribe($"{Module}.DiReplenOn", DIReplenOnOperation);
  698. OP.Subscribe($"{Module}.DiReplenOff", DIReplenOff);
  699. OP.Subscribe($"{Module}.ManualDiReplen", ManualDiReplen);
  700. OP.Subscribe($"{Module}.ResetTotalTime", ResetTotalTime);
  701. OP.Subscribe($"{Module}.LoadRecipe", LoadRecipeOperation);
  702. OP.Subscribe($"{Module}.LoadDosingRecipe", LoadDosingRecipeOperation);
  703. OP.Subscribe($"{Module}.ReplenPumpOn", ReplenPumpOnOperation);
  704. OP.Subscribe($"{Module}.ReplenPumpOff", ReplenPumpOffOperation);
  705. OP.Subscribe($"{Module}.SetPumpFactor", SetPumpFactor);
  706. OP.Subscribe($"{Module}.ManualDosing", ManualDosing);
  707. OP.Subscribe($"{Module}.StopManualDosing", StopManualDosing);
  708. OP.Subscribe($"{Module}.ResetBottleVolume", ResetBottleVolume);
  709. OP.Subscribe($"{Module}.DosingInitialize", DosingInitialize);
  710. }
  711. #region Operation
  712. /// <summary>
  713. /// 重置时长
  714. /// </summary>
  715. /// <param name="cmd"></param>
  716. /// <param name="objs"></param>
  717. /// <returns></returns>
  718. private bool ResetTotalTime(string cmd, object[] objs)
  719. {
  720. _persistentValue.TotalReplen = 0;
  721. _persistentValue.LastTotalReplen = 0;
  722. ReservoirsPersistentManager.Instance.UpdatePersistentValue(Module);
  723. return true;
  724. }
  725. /// <summary>
  726. /// DisabledAction
  727. /// </summary>
  728. /// <param name="cmd"></param>
  729. /// <param name="param"></param>
  730. /// <returns></returns>
  731. private bool DisabledOperation(string cmd, object[] args)
  732. {
  733. string currentOperation = "Disabled";
  734. if (args.Length >= 1 && (bool)args[0])
  735. {
  736. foreach (var replenData in ReplenDatas)
  737. {
  738. if (_replenPersistentValue != null && _replenPersistentValue[replenData.ReplenName] != null)
  739. {
  740. _replenPersistentValue[replenData.ReplenName].OperatingMode = currentOperation;
  741. ReplenPersistentManager.Instance.UpdatePersistentValue(Module, replenData.ReplenName);
  742. }
  743. }
  744. for (int i = 0; i < _replenNum; i++)
  745. {
  746. string replenName = "Replen" + (i + 1).ToString();
  747. if (_replenPersistentValue[replenName].IsDosingRunning)
  748. {
  749. _dosingSystemHelperLst[i].StopDosing();
  750. _currentDosingOperation[i] = DosingOperation.None;
  751. }
  752. }
  753. DosingEnterInit();
  754. }
  755. else
  756. {
  757. ReservoirEntity reservoirEntity = Singleton<RouteManager>.Instance.GetModule<ReservoirEntity>(Module);
  758. if (_persistentValue != null && reservoirEntity != null && _persistentValue.OperatingMode != currentOperation)
  759. {
  760. string preOperation = _persistentValue.OperatingMode;
  761. if (reservoirEntity.IsBusy)
  762. {
  763. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"{Module} is Busy, can't switch to Disabled mode");
  764. return false;
  765. }
  766. if (_persistentValue.OperatingMode == "Auto" && reservoirEntity.IsMetalBusy)
  767. {
  768. string busymodule = "";
  769. if (_metalDevices != null)
  770. {
  771. foreach (var item in _metalDevices)
  772. {
  773. MetalEntity metalEntity = Singleton<RouteManager>.Instance.GetModule<MetalEntity>(item.Module.ToString());
  774. if (metalEntity != null && metalEntity.IsBusy)
  775. {
  776. busymodule += metalEntity.Module.ToString() + "/";
  777. }
  778. }
  779. }
  780. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"{busymodule} is Busy, can't switch to Disabled mode");
  781. return false;
  782. }
  783. foreach (var metalDevice in _metalDevices)
  784. {
  785. metalDevice.DisabledOperation("", null);
  786. MetalEntity metalEntity = Singleton<RouteManager>.Instance.GetModule<MetalEntity>(metalDevice.Module);
  787. metalEntity.AbortRecipe(null);
  788. metalDevice.EnterDisabledOperation();
  789. }
  790. EnterDisabledOperation();
  791. reservoirEntity.EnterInit();
  792. _persistentValue.OperatingMode = currentOperation;
  793. LOG.WriteLog(eEvent.INFO_RESERVOIR, Module, $"Operating mode is switched from {preOperation} to {currentOperation}");
  794. }
  795. ReservoirsPersistentManager.Instance.UpdatePersistentValue(Module);
  796. _currentOperation = ReservoirOperation.None;
  797. }
  798. return true;
  799. }
  800. /// <summary>
  801. /// ManualAction
  802. /// </summary>
  803. /// <param name="cmd"></param>
  804. /// <param name="param"></param>
  805. /// <returns></returns>
  806. private bool ManualOperation(string cmd, object[] args)
  807. {
  808. string currentOperation = "Manual";
  809. if (args.Length >= 1 && (bool)args[0])
  810. {
  811. foreach (var replenData in ReplenDatas)
  812. {
  813. if (_replenPersistentValue != null && _replenPersistentValue[replenData.ReplenName] != null)
  814. {
  815. _replenPersistentValue[replenData.ReplenName].OperatingMode = currentOperation;
  816. ReplenPersistentManager.Instance.UpdatePersistentValue(Module, replenData.ReplenName);
  817. }
  818. }
  819. DosingEnterInit();
  820. }
  821. else
  822. {
  823. ReservoirEntity reservoirEntity = Singleton<RouteManager>.Instance.GetModule<ReservoirEntity>(Module);
  824. if (_persistentValue != null && reservoirEntity != null && _persistentValue.OperatingMode != currentOperation)
  825. {
  826. string preOperation = _persistentValue.OperatingMode;
  827. if (reservoirEntity.IsBusy)
  828. {
  829. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"{Module} is Busy, can't switch to Manual mode");
  830. return false;
  831. }
  832. if (_persistentValue.OperatingMode == "Auto" && reservoirEntity.IsMetalBusy)
  833. {
  834. string busymodule = "";
  835. if (_metalDevices != null)
  836. {
  837. foreach (var item in _metalDevices)
  838. {
  839. MetalEntity metalEntity = Singleton<RouteManager>.Instance.GetModule<MetalEntity>(item.Module.ToString());
  840. if (metalEntity != null && metalEntity.IsBusy)
  841. {
  842. busymodule += metalEntity.Module.ToString() + "/";
  843. }
  844. }
  845. }
  846. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"{busymodule} is Busy, can't switch to Manual mode");
  847. return false;
  848. }
  849. foreach (var metalDevice in _metalDevices)
  850. {
  851. metalDevice.ManualOperation("", null);
  852. }
  853. reservoirEntity.EnterInit();
  854. if (_reservoirData.DiReplen) DIReplenOff("", null);
  855. _persistentValue.OperatingMode = currentOperation;
  856. LOG.WriteLog(eEvent.INFO_RESERVOIR, Module, $"Operating mode is switched from {preOperation} to {currentOperation}");
  857. }
  858. ReservoirsPersistentManager.Instance.UpdatePersistentValue(Module);
  859. _currentOperation = ReservoirOperation.None;
  860. }
  861. return true;
  862. }
  863. /// <summary>
  864. /// AutoAction
  865. /// </summary>
  866. /// <param name="cmd"></param>
  867. /// <param name="param"></param>
  868. /// <returns></returns>
  869. private bool AutoOperation(string cmd, object[] args)
  870. {
  871. if (!_reservoirData.LowLevel)
  872. {
  873. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"Lowlevel was activated, can't switch to Auto mode");
  874. return false;
  875. }
  876. string currentOperation = "Auto";
  877. if (args.Length >= 1 && (bool)args[0])
  878. {
  879. foreach (var replenData in ReplenDatas)
  880. {
  881. if (_replenPersistentValue != null && _replenPersistentValue[replenData.ReplenName] != null)
  882. {
  883. _replenPersistentValue[replenData.ReplenName].OperatingMode = currentOperation;
  884. ReplenPersistentManager.Instance.UpdatePersistentValue(Module, replenData.ReplenName);
  885. }
  886. }
  887. DosingEnterInit();
  888. }
  889. else
  890. {
  891. ReservoirEntity reservoirEntity = Singleton<RouteManager>.Instance.GetModule<ReservoirEntity>(Module);
  892. if (_persistentValue != null && reservoirEntity != null && _persistentValue.OperatingMode != currentOperation)
  893. {
  894. string preOperation = _persistentValue.OperatingMode;
  895. if (reservoirEntity.IsBusy)
  896. {
  897. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"{Module} is Busy, can't switch to Auto mode");
  898. return false;
  899. }
  900. reservoirEntity.EnterInit();
  901. _persistentValue.OperatingMode = currentOperation;
  902. if (_reservoirData.DiReplen) DIReplenOff("", null);
  903. _isDiReplenInFault = false;
  904. LOG.WriteLog(eEvent.INFO_RESERVOIR, Module, $"Operating mode is switched from {preOperation} to {currentOperation}");
  905. }
  906. ReservoirsPersistentManager.Instance.UpdatePersistentValue(Module);
  907. }
  908. return true;
  909. }
  910. /// <summary>
  911. /// EngineeringModeAction
  912. /// </summary>
  913. /// <param name="cmd"></param>
  914. /// <param name="param"></param>
  915. /// <returns></returns>
  916. private bool EngineeringModeOperation(string cmd, object[] args)
  917. {
  918. string currentRecipeOperation = "Engineering";
  919. if (_persistentValue != null)
  920. {
  921. _persistentValue.RecipeOperatingMode = currentRecipeOperation;
  922. }
  923. ReservoirsPersistentManager.Instance.UpdatePersistentValue(Module);
  924. return true;
  925. }
  926. /// <summary>
  927. /// ProductionAction
  928. /// </summary>
  929. /// <param name="cmd"></param>
  930. /// <param name="param"></param>
  931. /// <returns></returns>
  932. private bool ProductionModeOperation(string cmd, object[] args)
  933. {
  934. string currentRecipeOperation = "Production";
  935. if (_persistentValue != null)
  936. {
  937. _persistentValue.RecipeOperatingMode = currentRecipeOperation;
  938. }
  939. ReservoirsPersistentManager.Instance.UpdatePersistentValue(Module);
  940. return true;
  941. }
  942. /// <summary>
  943. /// 加载Recipe
  944. /// </summary>
  945. /// <param name="cmd"></param>
  946. /// <param name="args"></param>
  947. /// <returns></returns>
  948. private bool LoadRecipeOperation(string cmd, object[] args)
  949. {
  950. _persistentValue.Recipe = args[0].ToString();
  951. string[] fileRoute = _persistentValue.Recipe.Split('\\');
  952. string recipeRoute = "";
  953. if (fileRoute.Length > 2)
  954. {
  955. recipeRoute = fileRoute[fileRoute.Length - 2];
  956. }
  957. try
  958. {
  959. _resRecipe = RecipeFileManager.Instance.LoadGenericityRecipe<ResRecipe>(_persistentValue.Recipe);
  960. ReservoirsPersistentManager.Instance.UpdatePersistentValue(Module.ToString());
  961. LOG.WriteLog(eEvent.INFO_RESERVOIR, Module, $"Load {recipeRoute} Recipe {_resRecipe.Ppid} Success");
  962. }
  963. catch
  964. {
  965. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"Load {recipeRoute} Recipe {_persistentValue.Recipe} failed");
  966. }
  967. return true;
  968. }
  969. /// <summary>
  970. /// DiReplen On
  971. /// </summary>
  972. /// <param name="cmd"></param>
  973. /// <param name="args"></param>
  974. /// <returns></returns>
  975. public bool DIReplenOnOperation(string cmd, object[] args)
  976. {
  977. return DIReplenOn(true);
  978. }
  979. /// <summary>
  980. /// 自动注水
  981. /// </summary>
  982. /// <returns></returns>
  983. public bool DIReplenOn(bool showError)
  984. {
  985. if (ReservoirData.WaterLevel > SC.GetValue<double>($"Reservoir.{Module}.HighLevel"))
  986. {
  987. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, "Highlevel is activate");
  988. return false;
  989. }
  990. if (!_reservoirData.LowLevel) //信号是相反的
  991. {
  992. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"WaterLevel low is Activate");
  993. return false;
  994. }
  995. bool preCondition = CheckPreDiReplenCondition(showError);
  996. if (!preCondition)
  997. {
  998. return false;
  999. }
  1000. string ioName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{DI_REPLEN}");
  1001. bool result = IOModuleManager.Instance.WriteIoValue(ioName, true);
  1002. if (result)
  1003. {
  1004. _persistentValue.IsDiReplenOn = true;
  1005. }
  1006. return result;
  1007. }
  1008. /// <summary>
  1009. /// 检验DiReplen前置条件
  1010. /// </summary>
  1011. /// <returns></returns>
  1012. public bool CheckPreDiReplenCondition(bool showError)
  1013. {
  1014. if (!CheckFacilitiesDiReplenStatus() && showError)
  1015. {
  1016. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, "Facilities DiReplen is Off");
  1017. return false;
  1018. }
  1019. SafetyDevice safetyDevice = DEVICE.GetDevice<SafetyDevice>("Safety");
  1020. if (safetyDevice != null && safetyDevice.SafetyData.ReservoirHighLevel)
  1021. {
  1022. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"Safety high is Activate");
  1023. return false;
  1024. }
  1025. if (CheckOtherReservoirDiReplenStatus(showError))
  1026. {
  1027. return false;
  1028. }
  1029. return true;
  1030. }
  1031. /// <summary>
  1032. /// 检验总Di有没有开
  1033. /// </summary>
  1034. /// <returns></returns>
  1035. private bool CheckFacilitiesDiReplenStatus()
  1036. {
  1037. SystemFacilities systemFacilities = DEVICE.GetDevice<SystemFacilities>("System.Facilities");
  1038. if (systemFacilities != null)
  1039. {
  1040. return systemFacilities.DIReplenEnable;
  1041. }
  1042. return false;
  1043. }
  1044. /// <summary>
  1045. /// 检验是否其他Reservoir Direplen已经
  1046. /// </summary>
  1047. /// <returns></returns>
  1048. private bool CheckOtherReservoirDiReplenStatus(bool showError)
  1049. {
  1050. List<string> reservoirs = ReservoirItemManager.Instance.InstalledModules;
  1051. foreach (string item in reservoirs)
  1052. {
  1053. if (item != Module)
  1054. {
  1055. ReservoirItem reservoirItem = ReservoirItemManager.Instance.GetReservoirItem(item);
  1056. if (reservoirItem.SubType == STRATUS)
  1057. {
  1058. StandardHotReservoirDevice tmpDevice = DEVICE.GetDevice<StandardHotReservoirDevice>(item);
  1059. if (tmpDevice.ReservoirData.DiReplen && showError)
  1060. {
  1061. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"{item} direplen valve is on");
  1062. return true;
  1063. }
  1064. }
  1065. else
  1066. {
  1067. CompactMembranReservoirDevice tmpDevice = DEVICE.GetDevice<CompactMembranReservoirDevice>(item);
  1068. if (tmpDevice.ReservoirData.ANDiReplen && showError)
  1069. {
  1070. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"{item} ANDireplen valve is on");
  1071. return true;
  1072. }
  1073. if (tmpDevice.ReservoirData.CADiReplen && showError)
  1074. {
  1075. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"{item} CADireplen valve is on");
  1076. return true;
  1077. }
  1078. }
  1079. }
  1080. }
  1081. return false;
  1082. }
  1083. /// <summary>
  1084. /// DiReplen Off
  1085. /// </summary>
  1086. /// <param name="cmd"></param>
  1087. /// <param name="args"></param>
  1088. /// <returns></returns>
  1089. private bool DIReplenOff(string cmd, object[] args)
  1090. {
  1091. string ioName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{DI_REPLEN}");
  1092. bool result = IOModuleManager.Instance.WriteIoValue(ioName, false);
  1093. if (result)
  1094. {
  1095. _persistentValue.IsDiReplenOn = false;
  1096. if (_currentOperation == ReservoirOperation.ManualDiReplen || _currentOperation == ReservoirOperation.AutoDiReplen)
  1097. {
  1098. _currentOperation = ReservoirOperation.None;
  1099. _persistentValue.LastTotalReplen = _persistentValue.TotalReplen;
  1100. ReservoirsPersistentManager.Instance.UpdatePersistentValue(Module);
  1101. }
  1102. }
  1103. return result;
  1104. }
  1105. /// <summary>
  1106. /// 手动注水
  1107. /// </summary>
  1108. /// <param name="cmd"></param>
  1109. /// <param name="args"></param>
  1110. /// <returns></returns>
  1111. private bool ManualDiReplen(string cmd, object[] args)
  1112. {
  1113. if (_currentOperation != ReservoirOperation.None)
  1114. {
  1115. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"current operation is {_currentOperation},cannot execute ManualDireplen operation");
  1116. return false;
  1117. }
  1118. bool result = DIReplenOnOperation("", null);
  1119. if (result)
  1120. {
  1121. _currentOperation = ReservoirOperation.ManualDiReplen;
  1122. _persistentValue.DiReplenTime = DateTime.Now;
  1123. ReservoirsPersistentManager.Instance.UpdatePersistentValue(Module);
  1124. int.TryParse(args[0].ToString(), out _manualReplenSecond);
  1125. }
  1126. return result;
  1127. }
  1128. /// <summary>
  1129. /// 自动注水
  1130. /// </summary>
  1131. /// <returns></returns>
  1132. public bool AutoDireplen()
  1133. {
  1134. if (!_reservoirData.LowLevel && !_isAutoDIReplenError)
  1135. {
  1136. _isAutoDIReplenError = true;
  1137. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"LowLevel is activate,Can't AutoDireplen");
  1138. return false;
  1139. }
  1140. else
  1141. {
  1142. _isAutoDIReplenError = false;
  1143. }
  1144. if (_currentOperation != ReservoirOperation.None)
  1145. {
  1146. return false;
  1147. }
  1148. if (_resRecipe == null)
  1149. {
  1150. return false;
  1151. }
  1152. bool result = DIReplenOn(false);
  1153. if (result)
  1154. {
  1155. _currentOperation = ReservoirOperation.AutoDiReplen;
  1156. _persistentValue.DiReplenTime = DateTime.Now;
  1157. }
  1158. return result;
  1159. }
  1160. /// <summary>
  1161. /// 启动PH检测
  1162. /// </summary>
  1163. public bool StartDetectPHValve()
  1164. {
  1165. if (_persistentValue.OperatingMode == MANUAL)
  1166. {
  1167. return false;
  1168. }
  1169. _phState = _phRoutine.Start();
  1170. LOG.WriteLog(eEvent.INFO_RESERVOIR, Module, "Start Detect PH");
  1171. return true;
  1172. }
  1173. /// <summary>
  1174. /// 打开PH Valve
  1175. /// </summary>
  1176. /// <returns></returns>
  1177. public bool PHValveOn()
  1178. {
  1179. string ioName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{PH_FLOW_VALVE}");
  1180. return IOModuleManager.Instance.WriteIoValue(ioName, true);
  1181. }
  1182. /// <summary>
  1183. /// 关闭PH Valve
  1184. /// </summary>
  1185. /// <returns></returns>
  1186. public bool PHValveOff()
  1187. {
  1188. string ioName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{PH_FLOW_VALVE}");
  1189. return IOModuleManager.Instance.WriteIoValue(ioName, false);
  1190. }
  1191. /// <summary>
  1192. /// CAFlowRateCheck
  1193. /// </summary>
  1194. private void CAFlowRateCheck()
  1195. {
  1196. if (_resRecipe == null) return;
  1197. for (int i = 0; i < _metalDevices.Count; i++)
  1198. {
  1199. StandardHotMetalDevice hotMetalDevice = _metalDevices[i];
  1200. if (hotMetalDevice != null && !hotMetalDevice.IsDisable && hotMetalDevice.IsAuto)
  1201. {
  1202. if (hotMetalDevice.MetalDeviceData == null || !hotMetalDevice.MetalDeviceData.Circulation) continue;
  1203. if (!hotMetalDevice.FlowValveStable) continue;
  1204. MetalEntity metalEntity = Singleton<RouteManager>.Instance.GetModule<MetalEntity>(hotMetalDevice.Name);
  1205. double cellFlow = hotMetalDevice.MetalDeviceData.CellFlow;
  1206. if (cellFlow < _resRecipe.CAFlowRateErrorLow)
  1207. {
  1208. if (!metalEntity.IsError)
  1209. {
  1210. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"cell {hotMetalDevice.Name} cellflow:{cellFlow} is less than recipe's CAFlowRateErrorLow parameter:{_resRecipe.CAFlowRateErrorLow}");
  1211. metalEntity.PostMsg(MetalMsg.Error);
  1212. }
  1213. }
  1214. else if (cellFlow < _resRecipe.CAFlowRateWarningLow)
  1215. {
  1216. if (!_isCAFlowRateWARN[i])
  1217. {
  1218. LOG.WriteLog(eEvent.WARN_RESERVOIR, Module, $"cell {hotMetalDevice.Name} cellflow:{cellFlow} is less than recipe's CAFlowRateWarningLow parameter:{_resRecipe.CAFlowRateWarningLow}");
  1219. _isCAFlowRateWARN[i] = true;
  1220. }
  1221. }
  1222. else
  1223. {
  1224. _isCAFlowRateWARN[i] = false;
  1225. }
  1226. }
  1227. }
  1228. }
  1229. /// <summary>
  1230. /// Temperature Check
  1231. /// </summary>
  1232. private void TemperatureCheck()
  1233. {
  1234. ReservoirEntity reservoirEntity = Singleton<RouteManager>.Instance.GetModule<ReservoirEntity>(Module);
  1235. ReservoirItem reservoirItem = ReservoirItemManager.Instance.GetReservoirItem(Module);
  1236. TemperatureController temperatureController = DEVICE.GetDevice<TemperatureController>(reservoirItem.TCID);
  1237. if (temperatureController == null || temperatureController.TemperatureData == null || _resRecipe == null
  1238. || temperatureController.TemperatureData.ControlOperationModel != ENABLE) return;
  1239. double tempValue = temperatureController.TemperatureData.ReserviorTemperature;
  1240. if (tempValue > _resRecipe.TemperatureErrorHigh && !reservoirEntity.IsError)
  1241. {
  1242. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"{temperatureController.Name} temperature:{tempValue} is over recipe's TemperatureErrorHigh parameter:{_resRecipe.TemperatureErrorHigh}");
  1243. reservoirEntity.PostMsg(ReservoirMsg.Error);
  1244. }
  1245. else if (tempValue < _resRecipe.TemperatureErrorLow && !reservoirEntity.IsError)
  1246. {
  1247. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"{temperatureController.Name} temperature:{tempValue} is less than recipe's TemperatureErrorLow parameter:{_resRecipe.TemperatureErrorLow}");
  1248. reservoirEntity.PostMsg(ReservoirMsg.Error);
  1249. }
  1250. else if (tempValue > _resRecipe.TemperatureWarningHigh)
  1251. {
  1252. if (!_isTCControlWARN)
  1253. {
  1254. LOG.WriteLog(eEvent.WARN_RESERVOIR, Module, $"{temperatureController.Name} temperature:{tempValue} is over recipe's TemperatureWarningHigh parameter:{_resRecipe.TemperatureWarningHigh}");
  1255. _isTCControlWARN = true;
  1256. }
  1257. }
  1258. else if (tempValue < _resRecipe.TemperatureWarningLow)
  1259. {
  1260. if (!_isTCControlWARN)
  1261. {
  1262. LOG.WriteLog(eEvent.WARN_RESERVOIR, Module, $"{temperatureController.Name} temperature:{tempValue} is less than recipe's TemperatureWarningLow parameter:{_resRecipe.TemperatureWarningLow}");
  1263. _isTCControlWARN = true;
  1264. }
  1265. }
  1266. else
  1267. {
  1268. _isTCControlWARN = false;
  1269. }
  1270. }
  1271. /// <summary>
  1272. /// CMMPowerCheck
  1273. /// </summary>
  1274. private void CMMPowerCheck()
  1275. {
  1276. ReservoirEntity reservoirEntity = Singleton<RouteManager>.Instance.GetModule<ReservoirEntity>(Module);
  1277. ReservoirItem _reservoirItem = ReservoirItemManager.Instance.GetReservoirItem(Module.ToString());
  1278. if (!string.IsNullOrEmpty(_reservoirItem.CMMSupplyID))
  1279. {
  1280. CellPowerSupplier _powerSupplier = DEVICE.GetDevice<CellPowerSupplier>(_reservoirItem.CMMSupplyID);
  1281. if (_powerSupplier == null || _powerSupplier.PowerSupplierData == null || _resRecipe == null || !_resRecipe.CMMEnable || !_powerSupplier.PowerSupplierData.Enabled || _powerSupplier.PowerSupplierData.Current == 0) return;
  1282. //CMM Current Check
  1283. double current = _powerSupplier.PowerSupplierData.Current;
  1284. if (current > _resRecipe.CMMCurrentSetPoint * (1 + (double)_resRecipe.CMMCurrentFaultPercent / 100))
  1285. {
  1286. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"{_powerSupplier.Name} current:{current} is over error upper limit:{_resRecipe.CMMCurrentSetPoint * (1 + (double)_resRecipe.CMMCurrentFaultPercent / 100)} based on recipe's CMMCurrentFaultPercent parameter:{_resRecipe.CMMCurrentFaultPercent} %");
  1287. reservoirEntity.PostMsg(ReservoirMsg.Error);
  1288. if (_powerSupplier.PowerSupplierData.Enabled)
  1289. {
  1290. _powerSupplier.DisableOperation("", null);
  1291. _persistentValue.CMMStartTime = DateTime.MinValue;
  1292. ReservoirsPersistentManager.Instance.UpdatePersistentValue(Module);
  1293. }
  1294. }
  1295. else if (current < _resRecipe.CMMCurrentSetPoint * (1 - (double)_resRecipe.CMMCurrentFaultPercent / 100))
  1296. {
  1297. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"{_powerSupplier.Name} current:{current} is less than error lower limit:{_resRecipe.CMMCurrentSetPoint * (1 - (double)_resRecipe.CMMCurrentFaultPercent / 100)} based on recipe's CMMCurrentFaultPercent parameter:{_resRecipe.CMMCurrentFaultPercent}%");
  1298. reservoirEntity.PostMsg(ReservoirMsg.Error);
  1299. if (_powerSupplier.PowerSupplierData.Enabled)
  1300. {
  1301. _powerSupplier.DisableOperation("", null);
  1302. _persistentValue.CMMStartTime = DateTime.MinValue;
  1303. ReservoirsPersistentManager.Instance.UpdatePersistentValue(Module);
  1304. }
  1305. }
  1306. else if (current > _resRecipe.CMMCurrentSetPoint * (1 + (double)_resRecipe.CMMCurrentWarningPercent / 100))
  1307. {
  1308. if (!_isCMMPowerCurrentWARN)
  1309. {
  1310. LOG.WriteLog(eEvent.WARN_RESERVOIR, Module, $"{_powerSupplier.Name} current:{current} is over warning upper limit:{_resRecipe.CMMCurrentSetPoint * (1 + (double)_resRecipe.CMMCurrentWarningPercent / 100)} based on recipe's CMMCurrentWarningPercent parameter:{_resRecipe.CMMCurrentWarningPercent}%");
  1311. _isCMMPowerCurrentWARN = true;
  1312. }
  1313. }
  1314. else if (current < _resRecipe.CMMCurrentSetPoint * (1 - (double)_resRecipe.CMMCurrentWarningPercent / 100))
  1315. {
  1316. if (!_isCMMPowerCurrentWARN)
  1317. {
  1318. LOG.WriteLog(eEvent.WARN_RESERVOIR, Module, $"{_powerSupplier.Name} current:{current} is less than warning lower limit{_resRecipe.CMMCurrentSetPoint * (1 - (double)_resRecipe.CMMCurrentWarningPercent / 100)} based on recipe's CMMCurrentWarningPercent parameter:{_resRecipe.CMMCurrentWarningPercent}%");
  1319. _isCMMPowerCurrentWARN = true;
  1320. }
  1321. }
  1322. else
  1323. {
  1324. _isCMMPowerCurrentWARN = false;
  1325. }
  1326. //CMM Voltage Check
  1327. double voltage = _powerSupplier.PowerSupplierData.Voltage;
  1328. if (voltage < _resRecipe.CMMMinVoltage)
  1329. {
  1330. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"{_powerSupplier.Name} voltage:{voltage} is less than recipe's CMMMinVoltage parameter:{_resRecipe.CMMMinVoltage}");
  1331. reservoirEntity.PostMsg(ReservoirMsg.Error);
  1332. if (_powerSupplier.PowerSupplierData.Enabled) _powerSupplier.DisableOperation("", null);
  1333. }
  1334. //CMM Flow Check
  1335. double flow = ReservoirData.Flow;
  1336. double cmmFlowHighFault = SC.GetValue<double>($"Reservoir.{Module}.CMMFlowHighFault");
  1337. double cmmFlowHighWarning = SC.GetValue<double>($"Reservoir.{Module}.CMMFlowHighWarning");
  1338. double cmmFlowLowFault = SC.GetValue<double>($"Reservoir.{Module}.CMMFlowLowFault");
  1339. double cmmFlowLowWarning = SC.GetValue<double>($"Reservoir.{Module}.CMMFlowLowWarning");
  1340. if (flow < cmmFlowLowFault)
  1341. {
  1342. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"{Module} CMM flow:{flow} is less than config item CMMFlowLowFault:{cmmFlowLowFault}");
  1343. if (_powerSupplier.PowerSupplierData.Enabled) _powerSupplier.DisableOperation("", null);
  1344. reservoirEntity.PostMsg(ReservoirMsg.Error);
  1345. }
  1346. else if (flow < cmmFlowLowWarning)
  1347. {
  1348. if (!_isCMMPowerFlowWARN)
  1349. {
  1350. LOG.WriteLog(eEvent.WARN_RESERVOIR, Module, $"{Module} CMM flow:{flow} is less than config item CMMFlowLowWarning:{cmmFlowLowWarning}");
  1351. _isCMMPowerFlowWARN = true;
  1352. }
  1353. }
  1354. else if (flow > cmmFlowHighFault)
  1355. {
  1356. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"{Module} CMM flow:{flow} is over config item CMMFlowHighFault:{cmmFlowLowFault}");
  1357. if (_powerSupplier.PowerSupplierData.Enabled) _powerSupplier.DisableOperation("", null);
  1358. reservoirEntity.PostMsg(ReservoirMsg.Error);
  1359. }
  1360. else if (flow > cmmFlowHighWarning)
  1361. {
  1362. if (!_isCMMPowerFlowWARN)
  1363. {
  1364. LOG.WriteLog(eEvent.WARN_RESERVOIR, Module, $"{Module} CMM flow:{flow} is over config item CMMFlowHighWarning:{cmmFlowLowWarning}");
  1365. _isCMMPowerFlowWARN = true;
  1366. }
  1367. }
  1368. else
  1369. {
  1370. _isCMMPowerFlowWARN = false;
  1371. }
  1372. }
  1373. }
  1374. #region DosingSystem
  1375. /// <summary>
  1376. /// 加载Replen Recipe
  1377. /// </summary>
  1378. /// <param name="cmd"></param>
  1379. /// <param name="args"></param>
  1380. /// <returns></returns>
  1381. private bool LoadDosingRecipeOperation(string cmd, object[] args)
  1382. {
  1383. string replenName = args[1].ToString();
  1384. int replenID = int.Parse(args[1].ToString().Substring(6, 1));
  1385. string replenRecipe = args[0].ToString();
  1386. _rdsRecipe[replenID - 1] = RecipeFileManager.Instance.LoadGenericityRecipe<RdsRecipe>(replenRecipe);
  1387. _replenDatas[replenID - 1].RecipeName = args[2].ToString();
  1388. LOG.WriteLog(eEvent.INFO_RESERVOIR, Module, $"Load Replen Recipe {_rdsRecipe[replenID - 1].Ppid} Success");
  1389. return true;
  1390. }
  1391. #region Replen Pump
  1392. /// <summary>
  1393. /// Replen Pump On 操作(根据PumpFactor和InitialDosingSpeed调速)
  1394. /// </summary>
  1395. /// <param name="cmd"></param>
  1396. /// <param name="args"></param>
  1397. /// <returns></returns>
  1398. public bool ReplenPumpOnOperation(string cmd, object[] args)
  1399. {
  1400. string replenName = args[0].ToString();
  1401. int replenID = int.Parse(args[0].ToString().Substring(6, 1));
  1402. //加载InitialDosingSpeed
  1403. double InitialDosingSpeed = 0;
  1404. if (SC.ContainsItem($"Reservoir.{Module}.InitialDosingSpeed"))
  1405. {
  1406. InitialDosingSpeed = SC.GetValue<double>($"Reservoir.{Module}.InitialDosingSpeed");
  1407. if (InitialDosingSpeed == 0)
  1408. {
  1409. _replenDatas[replenID - 1].ReplenPumpEnable = false;
  1410. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, "InitialDosingSpeed is zero. Can't open replen pump");
  1411. return false;
  1412. }
  1413. }
  1414. else
  1415. {
  1416. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, "Configuration item of InitialDosingSpeed doesn't exist!");
  1417. return false;
  1418. }
  1419. //加载ReplenPumpFactor
  1420. double PumpFactor = 0;
  1421. PumpFactor = _replenPersistentValue[replenName].ReplenPumpFactor;
  1422. if (PumpFactor == 0)
  1423. {
  1424. _replenDatas[replenID - 1].ReplenPumpEnable = false;
  1425. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, "PumpFactor is zero. Can't open replen pump");
  1426. return false;
  1427. }
  1428. //计算PumpSpeed(mL/min)
  1429. double replenPumpSpeed = InitialDosingSpeed * PumpFactor;
  1430. SCConfigItem item = SC.GetConfigItem($"Reservoir.{Module}.InitialDosingSpeed");
  1431. double speedMax = double.Parse(item.Max);
  1432. if (replenPumpSpeed > speedMax) replenPumpSpeed = speedMax;
  1433. bool result = ReplenPump(replenPumpSpeed / PUMP_SPEED_CONVERT, replenID);
  1434. if (!result)
  1435. {
  1436. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"Opening replen{replenID} pump is failed");
  1437. _replenDatas[replenID - 1].ReplenPumpSpeed = 0;
  1438. _replenDatas[replenID - 1].ReplenPumpEnable = false;
  1439. return false;
  1440. }
  1441. _replenDatas[replenID - 1].ReplenPumpSpeed = replenPumpSpeed;
  1442. _replenDatas[replenID - 1].ReplenPumpEnable = true;
  1443. LOG.WriteLog(eEvent.INFO_RESERVOIR, Module, $"Replen{replenID} pump is opened");
  1444. return true;
  1445. }
  1446. /// <summary>
  1447. /// Replen Pump Off操作
  1448. /// </summary>
  1449. /// <param name="cmd"></param>
  1450. /// <param name="args"></param>
  1451. /// <returns></returns>
  1452. public bool ReplenPumpOffOperation(string cmd, object[] args)
  1453. {
  1454. string replenName = args[0].ToString();
  1455. int replenID = int.Parse(args[0].ToString().Substring(6, 1));
  1456. bool result = ReplenPump(0, replenID);
  1457. if (!result)
  1458. {
  1459. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"Closing replen{replenID} pump is failed");
  1460. return false;
  1461. }
  1462. _replenDatas[replenID - 1].ReplenPumpSpeed = 0;
  1463. _replenDatas[replenID - 1].ReplenPumpEnable = false;
  1464. LOG.WriteLog(eEvent.INFO_RESERVOIR, Module, $"Replen{replenID} pump is closed");
  1465. return true;
  1466. }
  1467. /// <summary>
  1468. /// Replen Pump WriteIOValue
  1469. /// </summary>
  1470. /// <param name="speed"></param>
  1471. /// <returns></returns>
  1472. private bool ReplenPump(double speed, int replenNum)
  1473. {
  1474. string ioName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.Replen{replenNum}PumpSpeed");
  1475. return IOModuleManager.Instance.WriteIoValue(ioName, speed);
  1476. }
  1477. #endregion
  1478. /// <summary>
  1479. /// 设置PumpFactor
  1480. /// </summary>
  1481. /// <param name="cmd"></param>
  1482. /// <param name="args"></param>
  1483. /// <returns></returns>
  1484. public bool SetPumpFactor(string cmd, object[] args)
  1485. {
  1486. int replenID = int.Parse(args[0].ToString().Substring(6, 1));
  1487. double targetPumpFactor = (double)args[1];
  1488. _dosingSystemHelperLst[replenID - 1].SetPumpfactor(targetPumpFactor);
  1489. return true;
  1490. }
  1491. /// <summary>
  1492. /// 手动Dosing
  1493. /// </summary>
  1494. /// <param name="cmd"></param>
  1495. /// <param name="args"></param>
  1496. /// <returns></returns>
  1497. private bool ManualDosing(string cmd, object[] args)
  1498. {
  1499. ReservoirEntity reservoirEntity = Singleton<RouteManager>.Instance.GetModule<ReservoirEntity>(Module);
  1500. if (reservoirEntity == null || !_dosingCommonHelper.IsDosingSystemInitialized)
  1501. {
  1502. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, "Dosing System is not initialized!");
  1503. return true;
  1504. }
  1505. string replenName = args[0].ToString();
  1506. int replenID = int.Parse(args[0].ToString().Substring(6, 1));
  1507. double manualDosingVolume = (double)args[1];
  1508. if (manualDosingVolume == 0)
  1509. {
  1510. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, "Dosing Volume is zero, can't do manual dosing");
  1511. return false;
  1512. }
  1513. if (!CheckandUpdateBottleLevel(replenName, manualDosingVolume))
  1514. {
  1515. return false;
  1516. }
  1517. if (_replenPersistentValue[replenName].IsDosingRunning)
  1518. {
  1519. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, "Dosing is runnning, can't do manual dosing");
  1520. return false;
  1521. }
  1522. LOG.WriteLog(eEvent.INFO_RESERVOIR, Module, "ManualDosing starts now");
  1523. _currentDosingOperation[replenID - 1] = DosingOperation.ManualDosing;
  1524. bool result = _dosingSystemHelperLst[replenID - 1].StartDosing(manualDosingVolume, false);
  1525. return result;
  1526. }
  1527. /// <summary>
  1528. /// 停止手动Dosing
  1529. /// </summary>
  1530. /// <param name="cmd"></param>
  1531. /// <param name="args"></param>
  1532. /// <returns></returns>
  1533. private bool StopManualDosing(string cmd, object[] args)
  1534. {
  1535. string replenName = args[0].ToString();
  1536. int replenID = int.Parse(args[0].ToString().Substring(6, 1));
  1537. if (!_replenPersistentValue[replenName].IsDosingRunning)
  1538. {
  1539. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, "ManualDosing is not running. Can't stop!");
  1540. }
  1541. _currentDosingOperation[replenID - 1] = DosingOperation.None;
  1542. bool result = _dosingSystemHelperLst[replenID - 1].StopDosing();
  1543. if (result)
  1544. {
  1545. LOG.WriteLog(eEvent.INFO_RESERVOIR, Module, "ManualDosing has stopped now");
  1546. }
  1547. return result;
  1548. }
  1549. /// <summary>
  1550. /// 检查并更新BottleLevel状态
  1551. /// </summary>
  1552. /// <param name="replenName"></param>
  1553. /// <param name="targetVolume"></param>
  1554. public bool CheckandUpdateBottleLevel(string replenName, double targetVolume = -1, bool isError = true)
  1555. {
  1556. int replenId = int.Parse(replenName.Substring(6, 1));
  1557. double remainVolume = _replenPersistentValue[replenName].RemainDosingVolume;
  1558. bool result = true;
  1559. if (ReservoirData.ReplenLevel[replenId - 1])
  1560. {
  1561. ReplenDatas[replenId - 1].BottleLevel = DosingSystemHelper.BottleLevelState.Full.ToString();
  1562. if (targetVolume > remainVolume)
  1563. {
  1564. ReplenDatas[replenId - 1].BottleLevel = DosingSystemHelper.BottleLevelState.Warning.ToString();
  1565. if (isError)
  1566. {
  1567. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"Current Bottle is in Warning Level!");
  1568. }
  1569. result = false;
  1570. }
  1571. }
  1572. else
  1573. {
  1574. ReplenDatas[replenId - 1].BottleLevel = DosingSystemHelper.BottleLevelState.Empty.ToString();
  1575. if (isError)
  1576. {
  1577. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"Current Bottle is in Empty Level!");
  1578. }
  1579. result = false;
  1580. }
  1581. return result;
  1582. }
  1583. /// <summary>
  1584. /// Reset BottleVolume
  1585. /// </summary>
  1586. /// <param name="cmd"></param>
  1587. /// <param name="args"></param>
  1588. /// <returns></returns>
  1589. private bool ResetBottleVolume(string cmd, object[] args)
  1590. {
  1591. string replenName = args[0].ToString();
  1592. int replenID = int.Parse(args[0].ToString().Substring(6, 1));
  1593. if (SC.ContainsItem($"Reservoir.{Module}.BottleReserveVolume{replenID}"))
  1594. {
  1595. _replenPersistentValue[replenName].RemainDosingVolume = SC.GetValue<double>($"Reservoir.{Module}.BottleReserveVolume{replenID}");
  1596. }
  1597. ReplenPersistentManager.Instance.UpdatePersistentValue(Module, replenName);
  1598. LOG.WriteLog(eEvent.INFO_RESERVOIR, Module, $"Bottle Reserve Volume of Replen{replenID} has been reset now");
  1599. return true;
  1600. }
  1601. /// <summary>
  1602. /// DosingSystem初始化
  1603. /// </summary>
  1604. /// <param name="cmd"></param>
  1605. /// <param name="args"></param>
  1606. /// <returns></returns>
  1607. private bool DosingInitialize(string cmd, object[] args)
  1608. {
  1609. ReservoirEntity reservoirEntity = Singleton<RouteManager>.Instance.GetModule<ReservoirEntity>(Module);
  1610. if (reservoirEntity == null || !reservoirEntity.IsInitialized)
  1611. {
  1612. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"{Module} is not initialized");
  1613. return false;
  1614. }
  1615. return _dosingCommonHelper.DosingInitialize(); ;
  1616. }
  1617. /// <summary>
  1618. /// Enetr Init State
  1619. /// </summary>
  1620. /// <param name="cmd"></param>
  1621. /// <param name="args"></param>
  1622. /// <returns></returns>
  1623. private bool DosingEnterInit()
  1624. {
  1625. return _dosingCommonHelper.DosingEnterInit();
  1626. }
  1627. #endregion
  1628. /// <summary>
  1629. /// Enter Disabled Operation
  1630. /// </summary>
  1631. private void EnterDisabledOperation()
  1632. {
  1633. ReservoirItem _reservoirItem = ReservoirItemManager.Instance.GetReservoirItem(Module.ToString());
  1634. //关CMMPower
  1635. if (!string.IsNullOrEmpty(_reservoirItem.CMMSupplyID))
  1636. {
  1637. CellPowerSupplier powerSupplier = DEVICE.GetDevice<CellPowerSupplier>(_reservoirItem.CMMSupplyID);
  1638. if (powerSupplier != null && powerSupplier.PowerSupplierData.Enabled) powerSupplier.DisableOperation("", null);
  1639. }
  1640. //关TC
  1641. if (!string.IsNullOrEmpty(_reservoirItem.TCID))
  1642. {
  1643. TemperatureController temperatureController = DEVICE.GetDevice<TemperatureController>(_reservoirItem.TCID);
  1644. if (temperatureController != null) temperatureController.DisableOperation("", null);
  1645. }
  1646. _phRoutine.Abort();
  1647. if (_reservoirData.PHFlowValve)
  1648. {
  1649. PHValveOff();
  1650. }
  1651. if (_reservoirData.DiReplen)
  1652. {
  1653. DIReplenOff("", null);
  1654. }
  1655. }
  1656. /// <summary>
  1657. /// Set Export CMMUsage
  1658. /// </summary>
  1659. public void SetExportCMMUsage()
  1660. {
  1661. _isExportCMMUsage = true;
  1662. }
  1663. /// <summary>
  1664. /// ReservoirUsage监控
  1665. /// </summary>
  1666. public void ReservoirUsageMonitor()
  1667. {
  1668. ReservoirUsage reservoirUsage = ReservoirUsageManager.Instance.GetReservoirUsage(Module);
  1669. ReservoirEntity reservoirEntity = Singleton<RouteManager>.Instance.GetModule<ReservoirEntity>(Module);
  1670. if (reservoirUsage == null || reservoirEntity == null) return;
  1671. //reservoirTotalAmpHours Check
  1672. double reservoirTotalAmpHoursWarningLimit = 0;
  1673. if (SC.ContainsItem($"Reservoir.{Module}.ReservoirTotalAmpHoursWarningLimit"))
  1674. {
  1675. reservoirTotalAmpHoursWarningLimit = (double)SC.GetValue<double>($"Reservoir.{Module}.ReservoirTotalAmpHoursWarningLimit");
  1676. }
  1677. double reservoirTotalAmpHoursFaultLimit = 0;
  1678. if (SC.ContainsItem($"Reservoir.{Module}.ReservoirTotalAmpHoursFaultLimit"))
  1679. {
  1680. reservoirTotalAmpHoursFaultLimit = (double)SC.GetValue<double>($"Reservoir.{Module}.ReservoirTotalAmpHoursFaultLimit");
  1681. }
  1682. if (reservoirUsage.TotalUsage > reservoirTotalAmpHoursFaultLimit && reservoirTotalAmpHoursFaultLimit != 0)
  1683. {
  1684. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"{Module} Total Usage(AHr):{reservoirUsage.TotalUsage} is over config item ReservoirTotalAmpHoursFaultLimit:{reservoirTotalAmpHoursFaultLimit}");
  1685. reservoirEntity.PostMsg(ReservoirMsg.Error);
  1686. AlarmListManager.Instance.AddDataError(Module,
  1687. $"TotalUsage", $"{Module} usage:{reservoirUsage.TotalUsage} is over ReservoirTotalAmpHoursFaultLimit:{reservoirTotalAmpHoursFaultLimit}");
  1688. }
  1689. else if (reservoirUsage.TotalUsage > reservoirTotalAmpHoursWarningLimit && reservoirTotalAmpHoursWarningLimit != 0)
  1690. {
  1691. LOG.WriteLog(eEvent.WARN_RESERVOIR, Module, $"{Module} Total Usage(AHr):{reservoirUsage.TotalUsage} is over config item ReservoirTotalAmpHoursWarningLimit:{reservoirTotalAmpHoursWarningLimit}");
  1692. AlarmListManager.Instance.AddWarn(Module,
  1693. $"TotalUsage", $"{Module} usage:{reservoirUsage.TotalUsage} is over ReservoirTotalAmpHoursWarningLimit:{reservoirTotalAmpHoursWarningLimit}");
  1694. }
  1695. //MembraneTotalAmpHoursCheck
  1696. double membraneTotalAmpHoursWarningLimit = 0;
  1697. if (SC.ContainsItem($"Reservoir.{Module}.MembraneTotalAmpHoursWarningLimit"))
  1698. {
  1699. membraneTotalAmpHoursWarningLimit = (double)SC.GetValue<double>($"Reservoir.{Module}.MembraneTotalAmpHoursWarningLimit");
  1700. }
  1701. double membraneTotalAmpHoursFaultLimit = 0;
  1702. if (SC.ContainsItem($"Reservoir.{Module}.MembraneTotalAmpHoursFaultLimit"))
  1703. {
  1704. membraneTotalAmpHoursFaultLimit = (double)SC.GetValue<double>($"Reservoir.{Module}.MembraneTotalAmpHoursFaultLimit");
  1705. }
  1706. if (reservoirUsage.MembranceUsage > membraneTotalAmpHoursFaultLimit && membraneTotalAmpHoursFaultLimit != 0)
  1707. {
  1708. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"{Module} Membrane Usage(AHr):{reservoirUsage.MembranceUsage} is over config item MembraneTotalAmpHoursFaultLimit:{membraneTotalAmpHoursFaultLimit}");
  1709. reservoirEntity.PostMsg(ReservoirMsg.Error);
  1710. AlarmListManager.Instance.AddDataError(Module,
  1711. $"MembraneUsage", $"{Module} usage:{reservoirUsage.MembranceUsage} is over MembraneTotalAmpHoursFaultLimit:{membraneTotalAmpHoursFaultLimit}");
  1712. }
  1713. else if (reservoirUsage.MembranceUsage > membraneTotalAmpHoursWarningLimit && membraneTotalAmpHoursWarningLimit != 0)
  1714. {
  1715. LOG.WriteLog(eEvent.WARN_RESERVOIR, Module, $"{Module} Membrane Usage(AHr):{reservoirUsage.MembranceUsage} is over config item MembraneTotalAmpHoursWarningLimit:{membraneTotalAmpHoursWarningLimit}");
  1716. AlarmListManager.Instance.AddWarn(Module,
  1717. $"MembraneUsage", $"{Module} usage:{reservoirUsage.MembranceUsage} is over MembraneTotalAmpHoursWarningLimit:{membraneTotalAmpHoursWarningLimit}");
  1718. }
  1719. //ANBathTotalAmpHoursCheck
  1720. double anBathTotalAmpHoursWarningLimit = 0;
  1721. if (SC.ContainsItem($"Reservoir.{Module}.ANBathTotalAmpHoursWarningLimit"))
  1722. {
  1723. anBathTotalAmpHoursWarningLimit = (double)SC.GetValue<double>($"Reservoir.{Module}.ANBathTotalAmpHoursWarningLimit");
  1724. }
  1725. double anBathTotalAmpHoursFaultLimit = 0;
  1726. if (SC.ContainsItem($"Reservoir.{Module}.ANBathTotalAmpHoursFaultLimit"))
  1727. {
  1728. anBathTotalAmpHoursFaultLimit = (double)SC.GetValue<double>($"Reservoir.{Module}.ANBathTotalAmpHoursFaultLimit");
  1729. }
  1730. if (reservoirUsage.AnodeUsage > anBathTotalAmpHoursFaultLimit && anBathTotalAmpHoursFaultLimit != 0)
  1731. {
  1732. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"{Module} Anolyte Bath Usage(AHr):{reservoirUsage.AnodeUsage} is over config item ANBathTotalAmpHoursFaultLimit:{anBathTotalAmpHoursFaultLimit}");
  1733. reservoirEntity.PostMsg(ReservoirMsg.Error);
  1734. AlarmListManager.Instance.AddDataError(Module,
  1735. $"AnodeUsage", $"{Module} usage:{reservoirUsage.AnodeUsage} is over ANBathTotalAmpHoursFaultLimit:{anBathTotalAmpHoursFaultLimit}");
  1736. }
  1737. else if (reservoirUsage.AnodeUsage > anBathTotalAmpHoursWarningLimit && anBathTotalAmpHoursWarningLimit != 0)
  1738. {
  1739. LOG.WriteLog(eEvent.WARN_RESERVOIR, Module, $"{Module} Anolyte Bath Usage(AHr):{reservoirUsage.AnodeUsage} is over config item ANBathTotalAmpHoursWarningLimit:{anBathTotalAmpHoursWarningLimit}");
  1740. AlarmListManager.Instance.AddWarn(Module,
  1741. $"AnodeUsage", $"{Module} usage:{reservoirUsage.AnodeUsage} is over ANBathTotalAmpHoursWarningLimit:{anBathTotalAmpHoursWarningLimit}");
  1742. }
  1743. //BathTotalAmpHoursCheck
  1744. double bathTotalAmpHoursWarningLimit = 0;
  1745. if (SC.ContainsItem($"Reservoir.{Module}.BathTotalAmpHoursWarningLimit"))
  1746. {
  1747. bathTotalAmpHoursWarningLimit = (double)SC.GetValue<double>($"Reservoir.{Module}.BathTotalAmpHoursWarningLimit");
  1748. }
  1749. double bathTotalAmpHoursFaultLimit = 0;
  1750. if (SC.ContainsItem($"Reservoir.{Module}.BathTotalAmpHoursFaultLimit"))
  1751. {
  1752. bathTotalAmpHoursFaultLimit = (double)SC.GetValue<double>($"Reservoir.{Module}.BathTotalAmpHoursFaultLimit");
  1753. }
  1754. if (reservoirUsage.BathUsage > bathTotalAmpHoursFaultLimit && bathTotalAmpHoursFaultLimit != 0)
  1755. {
  1756. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"{Module} Bath Usage(AHr):{reservoirUsage.BathUsage} is over config item BathTotalAmpHoursFaultLimit:{bathTotalAmpHoursFaultLimit}");
  1757. reservoirEntity.PostMsg(ReservoirMsg.Error);
  1758. AlarmListManager.Instance.AddDataError(Module,
  1759. $"BathUsage", $"{Module} usage:{reservoirUsage.BathUsage} is over BathTotalAmpHoursFaultLimit:{bathTotalAmpHoursFaultLimit}");
  1760. }
  1761. else if (reservoirUsage.BathUsage > bathTotalAmpHoursWarningLimit && bathTotalAmpHoursWarningLimit != 0)
  1762. {
  1763. LOG.WriteLog(eEvent.WARN_RESERVOIR, Module, $"{Module} Bath Usage(AHr):{reservoirUsage.BathUsage} is over config item BathTotalAmpHoursWarningLimit:{bathTotalAmpHoursWarningLimit}");
  1764. AlarmListManager.Instance.AddWarn(Module,
  1765. $"BathUsage", $"{Module} usage:{reservoirUsage.BathUsage} is over BathTotalAmpHoursWarningLimit:{bathTotalAmpHoursWarningLimit}");
  1766. }
  1767. //BathTotalDaysCheck
  1768. int bathTotalDaysWarningLimit = 0;
  1769. if (SC.ContainsItem($"Reservoir.{Module}.BathTotalDaysWarningLimit"))
  1770. {
  1771. bathTotalDaysWarningLimit = SC.GetValue<int>($"Reservoir.{Module}.BathTotalDaysWarningLimit");
  1772. }
  1773. int bathTotalDaysFaultLimit = 0;
  1774. if (SC.ContainsItem($"Reservoir.{Module}.BathTotalDaysFaultLimit"))
  1775. {
  1776. bathTotalDaysFaultLimit = SC.GetValue<int>($"Reservoir.{Module}.BathTotalDaysFaultLimit");
  1777. }
  1778. if (reservoirUsage.BathUsageDays > bathTotalDaysFaultLimit && bathTotalDaysFaultLimit != 0)
  1779. {
  1780. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"{Module} Bath Usage(Days):{reservoirUsage.BathUsageDays} is over config item BathTotalDaysFaultLimit:{bathTotalDaysFaultLimit}");
  1781. reservoirEntity.PostMsg(ReservoirMsg.Error);
  1782. AlarmListManager.Instance.AddDataError(Module,
  1783. $"BathUsageDays", $"{Module} usage:{reservoirUsage.BathUsageDays} is over BathTotalDaysFaultLimit:{bathTotalDaysFaultLimit}");
  1784. }
  1785. else if (reservoirUsage.BathUsageDays > bathTotalDaysWarningLimit && bathTotalDaysWarningLimit != 0)
  1786. {
  1787. LOG.WriteLog(eEvent.WARN_RESERVOIR, Module, $"{Module} Bath Usage(Days):{reservoirUsage.BathUsage} is over config item BathTotalDaysWarningLimit:{bathTotalDaysWarningLimit}");
  1788. AlarmListManager.Instance.AddWarn(Module,
  1789. $"BathUsageDays", $"{Module} usage:{reservoirUsage.BathUsageDays} is over BathTotalDaysWarningLimit:{bathTotalDaysWarningLimit}");
  1790. }
  1791. //ReservoirTotalWafersCheck
  1792. int reservoirTotalWafersWarningLimit = 0;
  1793. if (SC.ContainsItem($"Reservoir.{Module}.ReservoirTotalWafersWarningLimit"))
  1794. {
  1795. reservoirTotalWafersWarningLimit = SC.GetValue<int>($"Reservoir.{Module}.ReservoirTotalWafersWarningLimit");
  1796. }
  1797. int reservoirTotalWafersFaultLimit = 0;
  1798. if (SC.ContainsItem($"Reservoir.{Module}.ReservoirTotalWafersFaultLimit"))
  1799. {
  1800. reservoirTotalWafersFaultLimit = SC.GetValue<int>($"Reservoir.{Module}.ReservoirTotalWafersFaultLimit");
  1801. }
  1802. if (reservoirUsage.TotalWafers > reservoirTotalWafersFaultLimit && reservoirTotalWafersFaultLimit != 0)
  1803. {
  1804. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"{Module} Total Wafers:{reservoirUsage.TotalWafers} is over config item ReservoirTotalWafersFaultLimit:{reservoirTotalWafersFaultLimit}");
  1805. reservoirEntity.PostMsg(ReservoirMsg.Error);
  1806. AlarmListManager.Instance.AddDataError(Module,
  1807. $"TotalWafers", $"{Module} usage:{reservoirUsage.TotalWafers} is over ReservoirTotalWafersFaultLimit:{reservoirTotalWafersFaultLimit}");
  1808. }
  1809. else if (reservoirUsage.TotalWafers > reservoirTotalWafersWarningLimit && reservoirTotalWafersWarningLimit != 0)
  1810. {
  1811. LOG.WriteLog(eEvent.WARN_RESERVOIR, Module, $"{Module} Total Wafers:{reservoirUsage.TotalWafers} is over config item ReservoirTotalWafersWarningLimit:{reservoirTotalWafersWarningLimit}");
  1812. AlarmListManager.Instance.AddWarn(Module,
  1813. $"TotalWafers", $"{Module} usage:{reservoirUsage.TotalWafers} is over ReservoirTotalWafersWarningLimit:{reservoirTotalWafersWarningLimit}");
  1814. }
  1815. //CMMAnodeTotalAmpHoursCheck
  1816. double cmmAnodeTotalAmpHoursWarningLimit = 0;
  1817. if (SC.ContainsItem($"Reservoir.{Module}.CMMAnodeTotalAmpHoursWarningLimit"))
  1818. {
  1819. cmmAnodeTotalAmpHoursWarningLimit = (double)SC.GetValue<double>($"Reservoir.{Module}.CMMAnodeTotalAmpHoursWarningLimit");
  1820. }
  1821. double cmmAnodeTotalAmpHoursFaultLimit = 0;
  1822. if (SC.ContainsItem($"Reservoir.{Module}.CMMAnodeTotalAmpHoursFaultLimit"))
  1823. {
  1824. cmmAnodeTotalAmpHoursFaultLimit = (double)SC.GetValue<double>($"Reservoir.{Module}.CMMAnodeTotalAmpHoursFaultLimit");
  1825. }
  1826. if (reservoirUsage.CMMAnodeUsage > cmmAnodeTotalAmpHoursFaultLimit && cmmAnodeTotalAmpHoursFaultLimit != 0)
  1827. {
  1828. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"{Module} CMM Anode Usage(AHr):{reservoirUsage.CMMAnodeUsage} is over config item CMMAnodeTotalAmpHoursFaultLimit:{cmmAnodeTotalAmpHoursFaultLimit}");
  1829. reservoirEntity.PostMsg(ReservoirMsg.Error);
  1830. AlarmListManager.Instance.AddDataError(Module,
  1831. $"CMMAnodeUsage", $"{Module} CMM Anode Usage(AHr):{reservoirUsage.CMMAnodeUsage} is over CMMAnodeTotalAmpHoursFaultLimit:{cmmAnodeTotalAmpHoursFaultLimit}");
  1832. }
  1833. else if (reservoirUsage.CMMAnodeUsage > cmmAnodeTotalAmpHoursWarningLimit && cmmAnodeTotalAmpHoursWarningLimit != 0)
  1834. {
  1835. LOG.WriteLog(eEvent.WARN_RESERVOIR, Module, $"{Module} CMM Anode Usage(AHr):{reservoirUsage.CMMAnodeUsage} is over config item CMMAnodeTotalAmpHoursWarningLimit:{cmmAnodeTotalAmpHoursWarningLimit}");
  1836. AlarmListManager.Instance.AddWarn(Module,
  1837. $"CMMAnodeUsage", $"{Module} CMM Anode Usage(AHr):{reservoirUsage.CMMAnodeUsage} is over CMMAnodeTotalAmpHoursWarningLimit:{cmmAnodeTotalAmpHoursWarningLimit}");
  1838. }
  1839. //CMMCathodeTotalAmpHoursCheck
  1840. double cmmCathodeTotalAmpHoursWarningLimit = 0;
  1841. if (SC.ContainsItem($"Reservoir.{Module}.CMMCathodeTotalAmpHoursWarningLimit"))
  1842. {
  1843. cmmCathodeTotalAmpHoursWarningLimit = (double)SC.GetValue<double>($"Reservoir.{Module}.CMMCathodeTotalAmpHoursWarningLimit");
  1844. }
  1845. double cmmCathodeTotalAmpHoursFaultLimit = 0;
  1846. if (SC.ContainsItem($"Reservoir.{Module}.CMMCathodeTotalAmpHoursFaultLimit"))
  1847. {
  1848. cmmCathodeTotalAmpHoursFaultLimit = (double)SC.GetValue<double>($"Reservoir.{Module}.CMMCathodeTotalAmpHoursFaultLimit");
  1849. }
  1850. if (reservoirUsage.CMMMembranceUsage > cmmCathodeTotalAmpHoursFaultLimit && cmmCathodeTotalAmpHoursFaultLimit != 0)
  1851. {
  1852. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"{Module} CMM Cathode Usage(AHr):{reservoirUsage.CMMMembranceUsage} is over config item CMMCathodeTotalAmpHoursFaultLimit:{cmmCathodeTotalAmpHoursFaultLimit}");
  1853. reservoirEntity.PostMsg(ReservoirMsg.Error);
  1854. AlarmListManager.Instance.AddDataError(Module,
  1855. $"CMMCathodeUsage", $"{Module} CMM Cathode Usage(AHr):{reservoirUsage.CMMMembranceUsage} is over CMMCathodeTotalAmpHoursFaultLimit:{cmmCathodeTotalAmpHoursFaultLimit}");
  1856. }
  1857. else if (reservoirUsage.CMMMembranceUsage > cmmCathodeTotalAmpHoursWarningLimit && cmmCathodeTotalAmpHoursWarningLimit != 0)
  1858. {
  1859. LOG.WriteLog(eEvent.WARN_RESERVOIR, Module, $"{Module} CMM Cathode Usage(AHr):{reservoirUsage.CMMMembranceUsage} is over config item CMMCathodeTotalAmpHoursWarningLimit:{cmmCathodeTotalAmpHoursWarningLimit}");
  1860. AlarmListManager.Instance.AddWarn(Module,
  1861. $"CMMCathodeUsage", $"{Module} CMM Cathode Usage(AHr):{reservoirUsage.CMMMembranceUsage} is over CMMCathodeTotalAmpHoursWarningLimit:{cmmCathodeTotalAmpHoursWarningLimit}");
  1862. }
  1863. }
  1864. #endregion
  1865. /// <summary>
  1866. /// 订阅变量数值发生变化
  1867. /// </summary>
  1868. private void SubscribeValueAction()
  1869. {
  1870. BeckhoffIoSubscribeUpdateVariable(FLOW);
  1871. BeckhoffIoSubscribeUpdateVariable(HED_FLOW);
  1872. BeckhoffIoSubscribeUpdateVariable(DI_REPLEN);
  1873. BeckhoffIoSubscribeUpdateVariable(PH_FLOW_VALVE);
  1874. BeckhoffIoSubscribeUpdateVariable(PH_VALUE);
  1875. BeckhoffIoSubscribeUpdateVariable(WATER_LEVEL);
  1876. BeckhoffIoSubscribeUpdateVariable(LOW_LEVEL);
  1877. BeckhoffIoSubscribeUpdateVariable(HIGH_LEVEL);
  1878. BeckhoffIoSubscribeUpdateVariable(SAFETY_HIGH_LEVEL);
  1879. for (int i = 0; i < _replenNum; i++)
  1880. {
  1881. BeckhoffIoSubscribeUpdateVariable($"Replen{i + 1}Level");
  1882. }
  1883. }
  1884. /// <summary>
  1885. /// 订阅IO变量
  1886. /// </summary>
  1887. /// <param name="variable"></param>
  1888. private void BeckhoffIoSubscribeUpdateVariable(string variable)
  1889. {
  1890. _variableInitializeDic[variable] = false;
  1891. IOModuleManager.Instance.SubscribeModuleVariable(Module, variable, UpdateVariableValue);
  1892. }
  1893. /// <summary>
  1894. /// 更新变量数值
  1895. /// </summary>
  1896. /// <param name="variable"></param>
  1897. /// <param name="value"></param>
  1898. private void UpdateVariableValue(string variable, object value)
  1899. {
  1900. if (!ReservoirData.IsDataInitialized)
  1901. {
  1902. ReservoirData.IsDataInitialized = true;
  1903. }
  1904. PropertyInfo property = ReservoirData.GetType().GetProperty(variable);
  1905. if (property != null)
  1906. {
  1907. property.SetValue(_reservoirData, value);
  1908. if (variable == WATER_LEVEL)
  1909. {
  1910. string levelCurve = SC.GetStringValue($"Reservoir.{Module}.LevelCurve");
  1911. ReservoirData.Level = LevelCurveManager.Instance.CalculateLevelByWaterLevel(ReservoirData.WaterLevel, levelCurve);
  1912. }
  1913. }
  1914. if (variable.Contains("Replen") && variable.Substring(0, 6) == "Replen")
  1915. {
  1916. property = ReservoirData.GetType().GetProperty(REPLEN_LEVEL);
  1917. _replenLevelLst[int.Parse(variable.Substring(6, 1)) - 1] = (bool)value;
  1918. property.SetValue(_reservoirData, _replenLevelLst);
  1919. }
  1920. if (_variableInitializeDic.ContainsKey(variable) && !_variableInitializeDic[variable])
  1921. {
  1922. _variableInitializeDic[variable] = true;
  1923. }
  1924. }
  1925. /// <summary>
  1926. /// 是否所有IO变量初始化完成
  1927. /// </summary>
  1928. /// <returns></returns>
  1929. private bool AllIoVariableInitialized()
  1930. {
  1931. foreach (string item in _variableInitializeDic.Keys)
  1932. {
  1933. if (!_variableInitializeDic[item])
  1934. {
  1935. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"{item} is not initialized");
  1936. return false;
  1937. }
  1938. }
  1939. return true;
  1940. }
  1941. public void Monitor()
  1942. {
  1943. }
  1944. public void Reset()
  1945. {
  1946. }
  1947. public void Terminate()
  1948. {
  1949. }
  1950. }
  1951. }