StandardHotReservoirDevice.cs 96 KB

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