StandardHotReservoirDevice.cs 95 KB

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