StandardHotReservoirDevice.cs 99 KB

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