StandardHotReservoirDevice.cs 96 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031
  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's 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. }