StandardHotReservoirDevice.cs 99 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119
  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. ReservoirEntity entity = Singleton<RouteManager>.Instance.GetModule<ReservoirEntity>(Module);
  1068. if (ReservoirData.WaterLevel > SC.GetValue<double>($"Reservoir.{Module}.HighLevel"))
  1069. {
  1070. if(entity!=null && !entity.IsError)
  1071. {
  1072. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, "Highlevel is activate");
  1073. }
  1074. return false;
  1075. }
  1076. if(!_reservoirData.LowLevel) //信号是相反的
  1077. {
  1078. if (entity != null && !entity.IsError)
  1079. {
  1080. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"WaterLevel low is Activate");
  1081. }
  1082. return false;
  1083. }
  1084. bool preCondition = CheckPreDiReplenCondition(showError);
  1085. if (!preCondition)
  1086. {
  1087. return false;
  1088. }
  1089. string ioName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{DI_REPLEN}");
  1090. bool result = IOModuleManager.Instance.WriteIoValue(ioName, true);
  1091. if (result)
  1092. {
  1093. _persistentValue.IsDiReplenOn = true;
  1094. }
  1095. return result;
  1096. }
  1097. /// <summary>
  1098. /// 打开继电器
  1099. /// </summary>
  1100. /// <returns></returns>
  1101. public void ResPowerOn()
  1102. {
  1103. bool result = false;
  1104. string ioName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{RESPOWERON}");
  1105. if (!string.IsNullOrEmpty(ioName))
  1106. {
  1107. result = IOModuleManager.Instance.WriteIoValue(ioName, true);
  1108. if (!result)
  1109. {
  1110. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"Open {Module} Power Relay failed");
  1111. }
  1112. }
  1113. ioName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{HEDPOWERON}");
  1114. if (!string.IsNullOrEmpty(ioName))
  1115. {
  1116. result = IOModuleManager.Instance.WriteIoValue(ioName, true);
  1117. if (!result)
  1118. {
  1119. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"Open {Module} Hed Power Relay failed");
  1120. }
  1121. }
  1122. }
  1123. /// <summary>
  1124. /// 检验DiReplen前置条件
  1125. /// </summary>
  1126. /// <returns></returns>
  1127. public bool CheckPreDiReplenCondition(bool showError)
  1128. {
  1129. if (!CheckFacilitiesDiReplenStatus() && showError)
  1130. {
  1131. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, "Facilities DiReplen is Off");
  1132. return false;
  1133. }
  1134. SafetyDevice safetyDevice = DEVICE.GetDevice<SafetyDevice>("Safety");
  1135. if (safetyDevice != null && safetyDevice.SafetyData.ReservoirHighLevel)
  1136. {
  1137. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"Safety high is Activate");
  1138. return false;
  1139. }
  1140. if (CheckOtherReservoirDiReplenStatus(showError))
  1141. {
  1142. return false;
  1143. }
  1144. return true;
  1145. }
  1146. /// <summary>
  1147. /// 检验总Di有没有开
  1148. /// </summary>
  1149. /// <returns></returns>
  1150. private bool CheckFacilitiesDiReplenStatus()
  1151. {
  1152. SystemFacilities systemFacilities = DEVICE.GetDevice<SystemFacilities>("System.Facilities");
  1153. if (systemFacilities != null)
  1154. {
  1155. return systemFacilities.DIReplenEnable;
  1156. }
  1157. return false;
  1158. }
  1159. /// <summary>
  1160. /// 检验是否其他Reservoir Direplen已经
  1161. /// </summary>
  1162. /// <returns></returns>
  1163. private bool CheckOtherReservoirDiReplenStatus(bool showError)
  1164. {
  1165. List<string> reservoirs = ReservoirItemManager.Instance.InstalledModules;
  1166. foreach (string item in reservoirs)
  1167. {
  1168. if (item != Module)
  1169. {
  1170. ReservoirItem reservoirItem = ReservoirItemManager.Instance.GetReservoirItem(item);
  1171. if (reservoirItem.SubType == STRATUS)
  1172. {
  1173. StandardHotReservoirDevice tmpDevice = DEVICE.GetDevice<StandardHotReservoirDevice>(item);
  1174. if (tmpDevice.ReservoirData.DiReplen && showError)
  1175. {
  1176. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"{item} direplen valve is on");
  1177. return true;
  1178. }
  1179. }
  1180. else
  1181. {
  1182. CompactMembranReservoirDevice tmpDevice = DEVICE.GetDevice<CompactMembranReservoirDevice>(item);
  1183. if (tmpDevice.ReservoirData.ANDiReplen && showError)
  1184. {
  1185. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"{item} ANDireplen valve is on");
  1186. return true;
  1187. }
  1188. if (tmpDevice.ReservoirData.CADiReplen && showError)
  1189. {
  1190. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"{item} CADireplen valve is on");
  1191. return true;
  1192. }
  1193. }
  1194. }
  1195. }
  1196. return false;
  1197. }
  1198. /// <summary>
  1199. /// DiReplen Off
  1200. /// </summary>
  1201. /// <param name="cmd"></param>
  1202. /// <param name="args"></param>
  1203. /// <returns></returns>
  1204. private bool DIReplenOff(string cmd, object[] args)
  1205. {
  1206. string ioName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{DI_REPLEN}");
  1207. bool result = IOModuleManager.Instance.WriteIoValue(ioName, false);
  1208. if (result)
  1209. {
  1210. _persistentValue.IsDiReplenOn = false;
  1211. if (_currentOperation == ReservoirOperation.ManualDiReplen || _currentOperation == ReservoirOperation.AutoDiReplen)
  1212. {
  1213. _currentOperation = ReservoirOperation.None;
  1214. _persistentValue.LastTotalReplen = _persistentValue.TotalReplen;
  1215. ReservoirsPersistentManager.Instance.UpdatePersistentValue(Module);
  1216. }
  1217. }
  1218. return result;
  1219. }
  1220. /// <summary>
  1221. /// 手动注水
  1222. /// </summary>
  1223. /// <param name="cmd"></param>
  1224. /// <param name="args"></param>
  1225. /// <returns></returns>
  1226. private bool ManualDiReplen(string cmd, object[] args)
  1227. {
  1228. if (_currentOperation != ReservoirOperation.None)
  1229. {
  1230. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"current operation is {_currentOperation},cannot execute ManualDireplen operation");
  1231. return false;
  1232. }
  1233. bool result = DIReplenOnOperation("", null);
  1234. if (result)
  1235. {
  1236. _currentOperation = ReservoirOperation.ManualDiReplen;
  1237. _persistentValue.DiReplenTime = DateTime.Now;
  1238. ReservoirsPersistentManager.Instance.UpdatePersistentValue(Module);
  1239. int.TryParse(args[0].ToString(), out _manualReplenSecond);
  1240. }
  1241. return result;
  1242. }
  1243. /// <summary>
  1244. /// 自动注水
  1245. /// </summary>
  1246. /// <returns></returns>
  1247. public bool AutoDireplen()
  1248. {
  1249. if (!_reservoirData.LowLevel && !_isAutoDIReplenError)
  1250. {
  1251. _isAutoDIReplenError = true;
  1252. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"LowLevel is activate,Can't AutoDireplen");
  1253. return false;
  1254. }
  1255. else
  1256. {
  1257. _isAutoDIReplenError = false;
  1258. }
  1259. if (_currentOperation != ReservoirOperation.None)
  1260. {
  1261. return false;
  1262. }
  1263. if (_resRecipe == null)
  1264. {
  1265. return false;
  1266. }
  1267. bool result = DIReplenOn(false);
  1268. if (result)
  1269. {
  1270. _currentOperation = ReservoirOperation.AutoDiReplen;
  1271. _persistentValue.DiReplenTime = DateTime.Now;
  1272. }
  1273. return result;
  1274. }
  1275. /// <summary>
  1276. /// 启动PH检测
  1277. /// </summary>
  1278. public bool StartDetectPHValve()
  1279. {
  1280. if (_persistentValue.OperatingMode == MANUAL)
  1281. {
  1282. return false;
  1283. }
  1284. _phState = _phRoutine.Start();
  1285. LOG.WriteLog(eEvent.INFO_RESERVOIR, Module, "Start Detect PH");
  1286. return true;
  1287. }
  1288. /// <summary>
  1289. /// 打开PH Valve
  1290. /// </summary>
  1291. /// <returns></returns>
  1292. public bool PHValveOn()
  1293. {
  1294. string ioName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{PH_FLOW_VALVE}");
  1295. return IOModuleManager.Instance.WriteIoValue(ioName, true);
  1296. }
  1297. /// <summary>
  1298. /// 关闭PH Valve
  1299. /// </summary>
  1300. /// <returns></returns>
  1301. public bool PHValveOff()
  1302. {
  1303. string ioName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{PH_FLOW_VALVE}");
  1304. return IOModuleManager.Instance.WriteIoValue(ioName, false);
  1305. }
  1306. /// <summary>
  1307. /// CAFlowRateCheck
  1308. /// </summary>
  1309. private void CAFlowRateCheck()
  1310. {
  1311. if (_resRecipe == null) return;
  1312. for (int i = 0; i < _metalDevices.Count; i++)
  1313. {
  1314. StandardHotMetalDevice hotMetalDevice = _metalDevices[i];
  1315. if (hotMetalDevice != null && !hotMetalDevice.IsDisable && hotMetalDevice.IsAuto)
  1316. {
  1317. if (hotMetalDevice.MetalDeviceData == null || !hotMetalDevice.MetalDeviceData.Circulation) continue;
  1318. if (!hotMetalDevice.FlowValveStable) continue;
  1319. MetalEntity metalEntity = Singleton<RouteManager>.Instance.GetModule<MetalEntity>(hotMetalDevice.Name);
  1320. double cellFlow = hotMetalDevice.MetalDeviceData.CellFlow;
  1321. if (cellFlow < _resRecipe.CAFlowRateErrorLow)
  1322. {
  1323. if (!metalEntity.IsError)
  1324. {
  1325. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"cell {hotMetalDevice.Name} cellflow:{cellFlow} is less than recipe's CAFlowRateErrorLow parameter:{_resRecipe.CAFlowRateErrorLow}");
  1326. metalEntity.PostMsg(MetalMsg.Error);
  1327. }
  1328. }
  1329. else if (cellFlow < _resRecipe.CAFlowRateWarningLow)
  1330. {
  1331. if (!_isCAFlowRateWARN[i])
  1332. {
  1333. LOG.WriteLog(eEvent.WARN_RESERVOIR, Module, $"cell {hotMetalDevice.Name} cellflow:{cellFlow} is less than recipe's CAFlowRateWarningLow parameter:{_resRecipe.CAFlowRateWarningLow}");
  1334. _isCAFlowRateWARN[i] = true;
  1335. }
  1336. }
  1337. else
  1338. {
  1339. _isCAFlowRateWARN[i] = false;
  1340. }
  1341. }
  1342. }
  1343. }
  1344. /// <summary>
  1345. /// Temperature Check
  1346. /// </summary>
  1347. private void TemperatureCheck()
  1348. {
  1349. ReservoirEntity reservoirEntity = Singleton<RouteManager>.Instance.GetModule<ReservoirEntity>(Module);
  1350. ReservoirItem reservoirItem = ReservoirItemManager.Instance.GetReservoirItem(Module);
  1351. TemperatureController temperatureController = DEVICE.GetDevice<TemperatureController>(reservoirItem.TCID);
  1352. if (temperatureController == null || temperatureController.TemperatureData == null || _resRecipe == null
  1353. || temperatureController.TemperatureData.ControlOperationModel != ENABLE) return;
  1354. double tempValue = temperatureController.TemperatureData.ReserviorTemperature;
  1355. if (tempValue > _resRecipe.TemperatureErrorHigh && !reservoirEntity.IsError)
  1356. {
  1357. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"{temperatureController.Name} temperature:{tempValue} is over recipe's TemperatureErrorHigh parameter:{_resRecipe.TemperatureErrorHigh}");
  1358. reservoirEntity.PostMsg(ReservoirMsg.Error);
  1359. }
  1360. else if (tempValue < _resRecipe.TemperatureErrorLow && !reservoirEntity.IsError)
  1361. {
  1362. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"{temperatureController.Name} temperature:{tempValue} is less than recipe's TemperatureErrorLow parameter:{_resRecipe.TemperatureErrorLow}");
  1363. reservoirEntity.PostMsg(ReservoirMsg.Error);
  1364. }
  1365. else if (tempValue > _resRecipe.TemperatureWarningHigh)
  1366. {
  1367. if (!_isTCControlWARN)
  1368. {
  1369. LOG.WriteLog(eEvent.WARN_RESERVOIR, Module, $"{temperatureController.Name} temperature:{tempValue} is over recipe's TemperatureWarningHigh parameter:{_resRecipe.TemperatureWarningHigh}");
  1370. _isTCControlWARN = true;
  1371. }
  1372. }
  1373. else if (tempValue < _resRecipe.TemperatureWarningLow)
  1374. {
  1375. if (!_isTCControlWARN)
  1376. {
  1377. LOG.WriteLog(eEvent.WARN_RESERVOIR, Module, $"{temperatureController.Name} temperature:{tempValue} is less than recipe's TemperatureWarningLow parameter:{_resRecipe.TemperatureWarningLow}");
  1378. _isTCControlWARN = true;
  1379. }
  1380. }
  1381. else
  1382. {
  1383. _isTCControlWARN = false;
  1384. }
  1385. }
  1386. /// <summary>
  1387. /// CMMPowerCheck
  1388. /// </summary>
  1389. private void CMMPowerCheck()
  1390. {
  1391. ReservoirEntity reservoirEntity = Singleton<RouteManager>.Instance.GetModule<ReservoirEntity>(Module);
  1392. ReservoirItem _reservoirItem = ReservoirItemManager.Instance.GetReservoirItem(Module.ToString());
  1393. if (!string.IsNullOrEmpty(_reservoirItem.CMMSupplyID))
  1394. {
  1395. CellPowerSupplier _powerSupplier = DEVICE.GetDevice<CellPowerSupplier>(_reservoirItem.CMMSupplyID);
  1396. if (_powerSupplier == null || _powerSupplier.PowerSupplierData == null || _resRecipe == null || !_resRecipe.CMMEnable || !_powerSupplier.PowerSupplierData.Enabled || _powerSupplier.PowerSupplierData.Current == 0) return;
  1397. //CMM Current Check
  1398. double current = _powerSupplier.PowerSupplierData.Current;
  1399. if (current > _resRecipe.CMMCurrentSetPoint * (1 + (double)_resRecipe.CMMCurrentFaultPercent / 100))
  1400. {
  1401. 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} %");
  1402. reservoirEntity.PostMsg(ReservoirMsg.Error);
  1403. if (_powerSupplier.PowerSupplierData.Enabled)
  1404. {
  1405. _powerSupplier.DisableOperation("", null);
  1406. _persistentValue.CMMStartTime = DateTime.MinValue;
  1407. ReservoirsPersistentManager.Instance.UpdatePersistentValue(Module);
  1408. }
  1409. }
  1410. else if (current < _resRecipe.CMMCurrentSetPoint * (1 - (double)_resRecipe.CMMCurrentFaultPercent / 100))
  1411. {
  1412. 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}%");
  1413. reservoirEntity.PostMsg(ReservoirMsg.Error);
  1414. if (_powerSupplier.PowerSupplierData.Enabled)
  1415. {
  1416. _powerSupplier.DisableOperation("", null);
  1417. _persistentValue.CMMStartTime = DateTime.MinValue;
  1418. ReservoirsPersistentManager.Instance.UpdatePersistentValue(Module);
  1419. }
  1420. }
  1421. else if (current > _resRecipe.CMMCurrentSetPoint * (1 + (double)_resRecipe.CMMCurrentWarningPercent / 100))
  1422. {
  1423. if (!_isCMMPowerCurrentWARN)
  1424. {
  1425. 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}%");
  1426. _isCMMPowerCurrentWARN = true;
  1427. }
  1428. }
  1429. else if (current < _resRecipe.CMMCurrentSetPoint * (1 - (double)_resRecipe.CMMCurrentWarningPercent / 100))
  1430. {
  1431. if (!_isCMMPowerCurrentWARN)
  1432. {
  1433. 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}%");
  1434. _isCMMPowerCurrentWARN = true;
  1435. }
  1436. }
  1437. else
  1438. {
  1439. _isCMMPowerCurrentWARN = false;
  1440. }
  1441. //CMM Voltage Check
  1442. double voltage = _powerSupplier.PowerSupplierData.Voltage;
  1443. if (voltage < _resRecipe.CMMMinVoltage)
  1444. {
  1445. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"{_powerSupplier.Name} voltage:{voltage} is less than recipe's CMMMinVoltage parameter:{_resRecipe.CMMMinVoltage}");
  1446. reservoirEntity.PostMsg(ReservoirMsg.Error);
  1447. if (_powerSupplier.PowerSupplierData.Enabled) _powerSupplier.DisableOperation("", null);
  1448. }
  1449. //CMM Flow Check
  1450. double flow = ReservoirData.Flow;
  1451. double cmmFlowHighFault = SC.GetValue<double>($"Reservoir.{Module}.CMMFlowHighFault");
  1452. double cmmFlowHighWarning = SC.GetValue<double>($"Reservoir.{Module}.CMMFlowHighWarning");
  1453. double cmmFlowLowFault = SC.GetValue<double>($"Reservoir.{Module}.CMMFlowLowFault");
  1454. double cmmFlowLowWarning = SC.GetValue<double>($"Reservoir.{Module}.CMMFlowLowWarning");
  1455. if (flow < cmmFlowLowFault)
  1456. {
  1457. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"{Module} CMM flow:{flow} is less than config item CMMFlowLowFault:{cmmFlowLowFault}");
  1458. if (_powerSupplier.PowerSupplierData.Enabled) _powerSupplier.DisableOperation("", null);
  1459. reservoirEntity.PostMsg(ReservoirMsg.Error);
  1460. }
  1461. else if (flow < cmmFlowLowWarning)
  1462. {
  1463. if (!_isCMMPowerFlowWARN)
  1464. {
  1465. LOG.WriteLog(eEvent.WARN_RESERVOIR, Module, $"{Module} CMM flow:{flow} is less than config item CMMFlowLowWarning:{cmmFlowLowWarning}");
  1466. _isCMMPowerFlowWARN = true;
  1467. }
  1468. }
  1469. else if (flow > cmmFlowHighFault)
  1470. {
  1471. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"{Module} CMM flow:{flow} is over config item CMMFlowHighFault:{cmmFlowLowFault}");
  1472. if (_powerSupplier.PowerSupplierData.Enabled) _powerSupplier.DisableOperation("", null);
  1473. reservoirEntity.PostMsg(ReservoirMsg.Error);
  1474. }
  1475. else if (flow > cmmFlowHighWarning)
  1476. {
  1477. if (!_isCMMPowerFlowWARN)
  1478. {
  1479. LOG.WriteLog(eEvent.WARN_RESERVOIR, Module, $"{Module} CMM flow:{flow} is over config item CMMFlowHighWarning:{cmmFlowLowWarning}");
  1480. _isCMMPowerFlowWARN = true;
  1481. }
  1482. }
  1483. else
  1484. {
  1485. _isCMMPowerFlowWARN = false;
  1486. }
  1487. }
  1488. }
  1489. #region DosingSystem
  1490. /// <summary>
  1491. /// 加载Replen Recipe
  1492. /// </summary>
  1493. /// <param name="cmd"></param>
  1494. /// <param name="args"></param>
  1495. /// <returns></returns>
  1496. private bool LoadDosingRecipeOperation(string cmd, object[] args)
  1497. {
  1498. string replenName = args[1].ToString();
  1499. int replenID = int.Parse(args[1].ToString().Substring(6, 1));
  1500. string replenRecipe = args[0].ToString();
  1501. _rdsRecipe[replenID - 1] = RecipeFileManager.Instance.LoadGenericityRecipe<RdsRecipe>(replenRecipe);
  1502. _replenDatas[replenID - 1].RecipeName = args[2].ToString();
  1503. LOG.WriteLog(eEvent.INFO_RESERVOIR, Module, $"Load Replen Recipe {_rdsRecipe[replenID - 1].Ppid} Success");
  1504. return true;
  1505. }
  1506. #region Replen Pump
  1507. /// <summary>
  1508. /// Replen Pump On 操作(根据PumpFactor和InitialDosingSpeed调速)
  1509. /// </summary>
  1510. /// <param name="cmd"></param>
  1511. /// <param name="args"></param>
  1512. /// <returns></returns>
  1513. public bool ReplenPumpOnOperation(string cmd, object[] args)
  1514. {
  1515. string replenName = args[0].ToString();
  1516. int replenID = int.Parse(args[0].ToString().Substring(6, 1));
  1517. //加载InitialDosingSpeed
  1518. double InitialDosingSpeed = 0;
  1519. if (SC.ContainsItem($"Reservoir.{Module}.InitialDosingSpeed"))
  1520. {
  1521. InitialDosingSpeed = SC.GetValue<double>($"Reservoir.{Module}.InitialDosingSpeed");
  1522. if (InitialDosingSpeed == 0)
  1523. {
  1524. _replenDatas[replenID - 1].ReplenPumpEnable = false;
  1525. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, "InitialDosingSpeed is zero. Can't open replen pump");
  1526. return false;
  1527. }
  1528. }
  1529. else
  1530. {
  1531. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, "Configuration item of InitialDosingSpeed doesn't exist!");
  1532. return false;
  1533. }
  1534. //加载ReplenPumpFactor
  1535. double PumpFactor = 0;
  1536. PumpFactor = _replenPersistentValue[replenName].ReplenPumpFactor;
  1537. if (PumpFactor == 0)
  1538. {
  1539. _replenDatas[replenID - 1].ReplenPumpEnable = false;
  1540. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, "PumpFactor is zero. Can't open replen pump");
  1541. return false;
  1542. }
  1543. //计算PumpSpeed(mL/min)
  1544. double replenPumpSpeed = InitialDosingSpeed * PumpFactor;
  1545. SCConfigItem item = SC.GetConfigItem($"Reservoir.{Module}.InitialDosingSpeed");
  1546. double speedMax = double.Parse(item.Max);
  1547. if (replenPumpSpeed > speedMax) replenPumpSpeed = speedMax;
  1548. bool result = ReplenPump(replenPumpSpeed / PUMP_SPEED_CONVERT, replenID);
  1549. if (!result)
  1550. {
  1551. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"Opening replen{replenID} pump is failed");
  1552. _replenDatas[replenID - 1].ReplenPumpSpeed = 0;
  1553. _replenDatas[replenID - 1].ReplenPumpEnable = false;
  1554. return false;
  1555. }
  1556. _replenDatas[replenID - 1].ReplenPumpSpeed = replenPumpSpeed;
  1557. _replenDatas[replenID - 1].ReplenPumpEnable = true;
  1558. LOG.WriteLog(eEvent.INFO_RESERVOIR, Module, $"Replen{replenID} pump is opened");
  1559. return true;
  1560. }
  1561. /// <summary>
  1562. /// Replen Pump Off操作
  1563. /// </summary>
  1564. /// <param name="cmd"></param>
  1565. /// <param name="args"></param>
  1566. /// <returns></returns>
  1567. public bool ReplenPumpOffOperation(string cmd, object[] args)
  1568. {
  1569. string replenName = args[0].ToString();
  1570. int replenID = int.Parse(args[0].ToString().Substring(6, 1));
  1571. bool result = ReplenPump(0, replenID);
  1572. if (!result)
  1573. {
  1574. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"Closing replen{replenID} pump is failed");
  1575. return false;
  1576. }
  1577. _replenDatas[replenID - 1].ReplenPumpSpeed = 0;
  1578. _replenDatas[replenID - 1].ReplenPumpEnable = false;
  1579. LOG.WriteLog(eEvent.INFO_RESERVOIR, Module, $"Replen{replenID} pump is closed");
  1580. return true;
  1581. }
  1582. /// <summary>
  1583. /// Replen Pump WriteIOValue
  1584. /// </summary>
  1585. /// <param name="speed"></param>
  1586. /// <returns></returns>
  1587. private bool ReplenPump(double speed, int replenNum)
  1588. {
  1589. string ioName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.Replen{replenNum}PumpSpeed");
  1590. return IOModuleManager.Instance.WriteIoValue(ioName, speed);
  1591. }
  1592. #endregion
  1593. /// <summary>
  1594. /// 设置PumpFactor
  1595. /// </summary>
  1596. /// <param name="cmd"></param>
  1597. /// <param name="args"></param>
  1598. /// <returns></returns>
  1599. public bool SetPumpFactor(string cmd, object[] args)
  1600. {
  1601. int replenID = int.Parse(args[0].ToString().Substring(6, 1));
  1602. double targetPumpFactor = (double)args[1];
  1603. _dosingSystemHelperLst[replenID - 1].SetPumpfactor(targetPumpFactor);
  1604. return true;
  1605. }
  1606. /// <summary>
  1607. /// 手动Dosing
  1608. /// </summary>
  1609. /// <param name="cmd"></param>
  1610. /// <param name="args"></param>
  1611. /// <returns></returns>
  1612. private bool ManualDosing(string cmd, object[] args)
  1613. {
  1614. ReservoirEntity reservoirEntity = Singleton<RouteManager>.Instance.GetModule<ReservoirEntity>(Module);
  1615. if (reservoirEntity == null || !_dosingCommonHelper.IsDosingSystemInitialized)
  1616. {
  1617. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, "Dosing System is not initialized!");
  1618. return true;
  1619. }
  1620. string replenName = args[0].ToString();
  1621. int replenID = int.Parse(args[0].ToString().Substring(6, 1));
  1622. double manualDosingVolume = (double)args[1];
  1623. if (manualDosingVolume == 0)
  1624. {
  1625. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, "Dosing Volume is zero, can't do manual dosing");
  1626. return false;
  1627. }
  1628. if (!CheckandUpdateBottleLevel(replenName, manualDosingVolume))
  1629. {
  1630. return false;
  1631. }
  1632. if (_replenPersistentValue[replenName].IsDosingRunning)
  1633. {
  1634. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, "Dosing is runnning, can't do manual dosing");
  1635. return false;
  1636. }
  1637. LOG.WriteLog(eEvent.INFO_RESERVOIR, Module, "ManualDosing starts now");
  1638. _currentDosingOperation[replenID - 1] = DosingOperation.ManualDosing;
  1639. bool result = _dosingSystemHelperLst[replenID - 1].StartDosing(manualDosingVolume, false);
  1640. return result;
  1641. }
  1642. /// <summary>
  1643. /// 停止手动Dosing
  1644. /// </summary>
  1645. /// <param name="cmd"></param>
  1646. /// <param name="args"></param>
  1647. /// <returns></returns>
  1648. private bool StopManualDosing(string cmd, object[] args)
  1649. {
  1650. string replenName = args[0].ToString();
  1651. int replenID = int.Parse(args[0].ToString().Substring(6, 1));
  1652. if (!_replenPersistentValue[replenName].IsDosingRunning)
  1653. {
  1654. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, "ManualDosing is not running. Can't stop!");
  1655. }
  1656. _currentDosingOperation[replenID - 1] = DosingOperation.None;
  1657. bool result = _dosingSystemHelperLst[replenID - 1].StopDosing();
  1658. if (result)
  1659. {
  1660. LOG.WriteLog(eEvent.INFO_RESERVOIR, Module, "ManualDosing has stopped now");
  1661. }
  1662. return result;
  1663. }
  1664. /// <summary>
  1665. /// 检查并更新BottleLevel状态
  1666. /// </summary>
  1667. /// <param name="replenName"></param>
  1668. /// <param name="targetVolume"></param>
  1669. public bool CheckandUpdateBottleLevel(string replenName, double targetVolume = -1, bool isError = true)
  1670. {
  1671. int replenId = int.Parse(replenName.Substring(6, 1));
  1672. double remainVolume = _replenPersistentValue[replenName].RemainDosingVolume;
  1673. bool result = true;
  1674. if (ReservoirData.ReplenLevel[replenId - 1])
  1675. {
  1676. ReplenDatas[replenId - 1].BottleLevel = DosingSystemHelper.BottleLevelState.Full.ToString();
  1677. if (targetVolume > remainVolume)
  1678. {
  1679. ReplenDatas[replenId - 1].BottleLevel = DosingSystemHelper.BottleLevelState.Warning.ToString();
  1680. if (isError)
  1681. {
  1682. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"Current Bottle is in Warning Level!");
  1683. }
  1684. result = false;
  1685. }
  1686. }
  1687. else
  1688. {
  1689. ReplenDatas[replenId - 1].BottleLevel = DosingSystemHelper.BottleLevelState.Empty.ToString();
  1690. if (isError)
  1691. {
  1692. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"Current Bottle is in Empty Level!");
  1693. }
  1694. result = false;
  1695. }
  1696. return result;
  1697. }
  1698. /// <summary>
  1699. /// Reset BottleVolume
  1700. /// </summary>
  1701. /// <param name="cmd"></param>
  1702. /// <param name="args"></param>
  1703. /// <returns></returns>
  1704. private bool ResetBottleVolume(string cmd, object[] args)
  1705. {
  1706. string replenName = args[0].ToString();
  1707. int replenID = int.Parse(args[0].ToString().Substring(6, 1));
  1708. if (SC.ContainsItem($"Reservoir.{Module}.BottleReserveVolume{replenID}"))
  1709. {
  1710. _replenPersistentValue[replenName].RemainDosingVolume = SC.GetValue<double>($"Reservoir.{Module}.BottleReserveVolume{replenID}");
  1711. }
  1712. ReplenPersistentManager.Instance.UpdatePersistentValue(Module, replenName);
  1713. LOG.WriteLog(eEvent.INFO_RESERVOIR, Module, $"Bottle Reserve Volume of Replen{replenID} has been reset now");
  1714. return true;
  1715. }
  1716. /// <summary>
  1717. /// DosingSystem初始化
  1718. /// </summary>
  1719. /// <param name="cmd"></param>
  1720. /// <param name="args"></param>
  1721. /// <returns></returns>
  1722. private bool DosingInitialize(string cmd, object[] args)
  1723. {
  1724. ReservoirEntity reservoirEntity = Singleton<RouteManager>.Instance.GetModule<ReservoirEntity>(Module);
  1725. if (reservoirEntity == null || !reservoirEntity.IsInitialized)
  1726. {
  1727. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"{Module} is not initialized");
  1728. return false;
  1729. }
  1730. return _dosingCommonHelper.DosingInitialize(); ;
  1731. }
  1732. /// <summary>
  1733. /// Enetr Init State
  1734. /// </summary>
  1735. /// <param name="cmd"></param>
  1736. /// <param name="args"></param>
  1737. /// <returns></returns>
  1738. private bool DosingEnterInit()
  1739. {
  1740. return _dosingCommonHelper.DosingEnterInit();
  1741. }
  1742. #endregion
  1743. /// <summary>
  1744. /// Enter Disabled Operation
  1745. /// </summary>
  1746. private void EnterDisabledOperation()
  1747. {
  1748. ReservoirItem _reservoirItem = ReservoirItemManager.Instance.GetReservoirItem(Module.ToString());
  1749. //关CMMPower
  1750. if (!string.IsNullOrEmpty(_reservoirItem.CMMSupplyID))
  1751. {
  1752. CellPowerSupplier powerSupplier = DEVICE.GetDevice<CellPowerSupplier>(_reservoirItem.CMMSupplyID);
  1753. if (powerSupplier != null && powerSupplier.PowerSupplierData.Enabled) powerSupplier.DisableOperation("", null);
  1754. }
  1755. //关TC
  1756. if (!string.IsNullOrEmpty(_reservoirItem.TCID))
  1757. {
  1758. TemperatureController temperatureController = DEVICE.GetDevice<TemperatureController>(_reservoirItem.TCID);
  1759. if (temperatureController != null) temperatureController.DisableOperation("", null);
  1760. }
  1761. _phRoutine.Abort();
  1762. if (_reservoirData.PHFlowValve)
  1763. {
  1764. PHValveOff();
  1765. }
  1766. if (_reservoirData.DiReplen)
  1767. {
  1768. DIReplenOff("", null);
  1769. }
  1770. }
  1771. /// <summary>
  1772. /// Set Export CMMUsage
  1773. /// </summary>
  1774. public void SetExportCMMUsage()
  1775. {
  1776. _isExportCMMUsage = true;
  1777. }
  1778. /// <summary>
  1779. /// ReservoirUsage监控
  1780. /// </summary>
  1781. public void ReservoirUsageMonitor()
  1782. {
  1783. ReservoirUsage reservoirUsage = ReservoirUsageManager.Instance.GetReservoirUsage(Module);
  1784. ReservoirEntity reservoirEntity = Singleton<RouteManager>.Instance.GetModule<ReservoirEntity>(Module);
  1785. if (reservoirUsage == null || reservoirEntity == null) return;
  1786. //reservoirTotalAmpHours Check
  1787. double reservoirTotalAmpHoursWarningLimit = 0;
  1788. if (SC.ContainsItem($"Reservoir.{Module}.ReservoirTotalAmpHoursWarningLimit"))
  1789. {
  1790. reservoirTotalAmpHoursWarningLimit = (double)SC.GetValue<double>($"Reservoir.{Module}.ReservoirTotalAmpHoursWarningLimit");
  1791. }
  1792. double reservoirTotalAmpHoursFaultLimit = 0;
  1793. if (SC.ContainsItem($"Reservoir.{Module}.ReservoirTotalAmpHoursFaultLimit"))
  1794. {
  1795. reservoirTotalAmpHoursFaultLimit = (double)SC.GetValue<double>($"Reservoir.{Module}.ReservoirTotalAmpHoursFaultLimit");
  1796. }
  1797. if (reservoirUsage.TotalUsage > reservoirTotalAmpHoursFaultLimit && reservoirTotalAmpHoursFaultLimit != 0)
  1798. {
  1799. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"{Module} Total Usage(AHr):{reservoirUsage.TotalUsage} is over config item ReservoirTotalAmpHoursFaultLimit:{reservoirTotalAmpHoursFaultLimit}");
  1800. reservoirEntity.PostMsg(ReservoirMsg.Error);
  1801. AlarmListManager.Instance.AddDataError(Module,
  1802. $"TotalUsage", $"{Module} usage:{reservoirUsage.TotalUsage} is over ReservoirTotalAmpHoursFaultLimit:{reservoirTotalAmpHoursFaultLimit}");
  1803. }
  1804. else if (reservoirUsage.TotalUsage > reservoirTotalAmpHoursWarningLimit && reservoirTotalAmpHoursWarningLimit != 0)
  1805. {
  1806. LOG.WriteLog(eEvent.WARN_RESERVOIR, Module, $"{Module} Total Usage(AHr):{reservoirUsage.TotalUsage} is over config item ReservoirTotalAmpHoursWarningLimit:{reservoirTotalAmpHoursWarningLimit}");
  1807. AlarmListManager.Instance.AddWarn(Module,
  1808. $"TotalUsage", $"{Module} usage:{reservoirUsage.TotalUsage} is over ReservoirTotalAmpHoursWarningLimit:{reservoirTotalAmpHoursWarningLimit}");
  1809. }
  1810. //MembraneTotalAmpHoursCheck
  1811. double membraneTotalAmpHoursWarningLimit = 0;
  1812. if (SC.ContainsItem($"Reservoir.{Module}.MembraneTotalAmpHoursWarningLimit"))
  1813. {
  1814. membraneTotalAmpHoursWarningLimit = (double)SC.GetValue<double>($"Reservoir.{Module}.MembraneTotalAmpHoursWarningLimit");
  1815. }
  1816. double membraneTotalAmpHoursFaultLimit = 0;
  1817. if (SC.ContainsItem($"Reservoir.{Module}.MembraneTotalAmpHoursFaultLimit"))
  1818. {
  1819. membraneTotalAmpHoursFaultLimit = (double)SC.GetValue<double>($"Reservoir.{Module}.MembraneTotalAmpHoursFaultLimit");
  1820. }
  1821. if (reservoirUsage.MembranceUsage > membraneTotalAmpHoursFaultLimit && membraneTotalAmpHoursFaultLimit != 0)
  1822. {
  1823. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"{Module} Membrane Usage(AHr):{reservoirUsage.MembranceUsage} is over config item MembraneTotalAmpHoursFaultLimit:{membraneTotalAmpHoursFaultLimit}");
  1824. reservoirEntity.PostMsg(ReservoirMsg.Error);
  1825. AlarmListManager.Instance.AddDataError(Module,
  1826. $"MembraneUsage", $"{Module} usage:{reservoirUsage.MembranceUsage} is over MembraneTotalAmpHoursFaultLimit:{membraneTotalAmpHoursFaultLimit}");
  1827. }
  1828. else if (reservoirUsage.MembranceUsage > membraneTotalAmpHoursWarningLimit && membraneTotalAmpHoursWarningLimit != 0)
  1829. {
  1830. LOG.WriteLog(eEvent.WARN_RESERVOIR, Module, $"{Module} Membrane Usage(AHr):{reservoirUsage.MembranceUsage} is over config item MembraneTotalAmpHoursWarningLimit:{membraneTotalAmpHoursWarningLimit}");
  1831. AlarmListManager.Instance.AddWarn(Module,
  1832. $"MembraneUsage", $"{Module} usage:{reservoirUsage.MembranceUsage} is over MembraneTotalAmpHoursWarningLimit:{membraneTotalAmpHoursWarningLimit}");
  1833. }
  1834. //ANBathTotalAmpHoursCheck
  1835. //double anBathTotalAmpHoursWarningLimit = 0;
  1836. //if (SC.ContainsItem($"Reservoir.{Module}.ANBathTotalAmpHoursWarningLimit"))
  1837. //{
  1838. // anBathTotalAmpHoursWarningLimit = (double)SC.GetValue<double>($"Reservoir.{Module}.ANBathTotalAmpHoursWarningLimit");
  1839. //}
  1840. //double anBathTotalAmpHoursFaultLimit = 0;
  1841. //if (SC.ContainsItem($"Reservoir.{Module}.ANBathTotalAmpHoursFaultLimit"))
  1842. //{
  1843. // anBathTotalAmpHoursFaultLimit = (double)SC.GetValue<double>($"Reservoir.{Module}.ANBathTotalAmpHoursFaultLimit");
  1844. //}
  1845. //if (reservoirUsage.AnodeUsage > anBathTotalAmpHoursFaultLimit && anBathTotalAmpHoursFaultLimit != 0)
  1846. //{
  1847. // LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"{Module} Anolyte Bath Usage(AHr):{reservoirUsage.AnodeUsage} is over config item ANBathTotalAmpHoursFaultLimit:{anBathTotalAmpHoursFaultLimit}");
  1848. // reservoirEntity.PostMsg(ReservoirMsg.Error);
  1849. // AlarmListManager.Instance.AddDataError(Module,
  1850. // $"AnodeUsage", $"{Module} usage:{reservoirUsage.AnodeUsage} is over ANBathTotalAmpHoursFaultLimit:{anBathTotalAmpHoursFaultLimit}");
  1851. //}
  1852. //else if (reservoirUsage.AnodeUsage > anBathTotalAmpHoursWarningLimit && anBathTotalAmpHoursWarningLimit != 0)
  1853. //{
  1854. // LOG.WriteLog(eEvent.WARN_RESERVOIR, Module, $"{Module} Anolyte Bath Usage(AHr):{reservoirUsage.AnodeUsage} is over config item ANBathTotalAmpHoursWarningLimit:{anBathTotalAmpHoursWarningLimit}");
  1855. // AlarmListManager.Instance.AddWarn(Module,
  1856. // $"AnodeUsage", $"{Module} usage:{reservoirUsage.AnodeUsage} is over ANBathTotalAmpHoursWarningLimit:{anBathTotalAmpHoursWarningLimit}");
  1857. //}
  1858. //BathTotalAmpHoursCheck
  1859. double bathTotalAmpHoursWarningLimit = 0;
  1860. if (SC.ContainsItem($"Reservoir.{Module}.BathTotalAmpHoursWarningLimit"))
  1861. {
  1862. bathTotalAmpHoursWarningLimit = (double)SC.GetValue<double>($"Reservoir.{Module}.BathTotalAmpHoursWarningLimit");
  1863. }
  1864. double bathTotalAmpHoursFaultLimit = 0;
  1865. if (SC.ContainsItem($"Reservoir.{Module}.BathTotalAmpHoursFaultLimit"))
  1866. {
  1867. bathTotalAmpHoursFaultLimit = (double)SC.GetValue<double>($"Reservoir.{Module}.BathTotalAmpHoursFaultLimit");
  1868. }
  1869. if (reservoirUsage.BathUsage > bathTotalAmpHoursFaultLimit && bathTotalAmpHoursFaultLimit != 0)
  1870. {
  1871. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"{Module} Bath Usage(AHr):{reservoirUsage.BathUsage} is over config item BathTotalAmpHoursFaultLimit:{bathTotalAmpHoursFaultLimit}");
  1872. reservoirEntity.PostMsg(ReservoirMsg.Error);
  1873. AlarmListManager.Instance.AddDataError(Module,
  1874. $"BathUsage", $"{Module} usage:{reservoirUsage.BathUsage} is over BathTotalAmpHoursFaultLimit:{bathTotalAmpHoursFaultLimit}");
  1875. }
  1876. else if (reservoirUsage.BathUsage > bathTotalAmpHoursWarningLimit && bathTotalAmpHoursWarningLimit != 0)
  1877. {
  1878. LOG.WriteLog(eEvent.WARN_RESERVOIR, Module, $"{Module} Bath Usage(AHr):{reservoirUsage.BathUsage} is over config item BathTotalAmpHoursWarningLimit:{bathTotalAmpHoursWarningLimit}");
  1879. AlarmListManager.Instance.AddWarn(Module,
  1880. $"BathUsage", $"{Module} usage:{reservoirUsage.BathUsage} is over BathTotalAmpHoursWarningLimit:{bathTotalAmpHoursWarningLimit}");
  1881. }
  1882. //BathTotalDaysCheck
  1883. int bathTotalDaysWarningLimit = 0;
  1884. if (SC.ContainsItem($"Reservoir.{Module}.BathTotalDaysWarningLimit"))
  1885. {
  1886. bathTotalDaysWarningLimit = SC.GetValue<int>($"Reservoir.{Module}.BathTotalDaysWarningLimit");
  1887. }
  1888. int bathTotalDaysFaultLimit = 0;
  1889. if (SC.ContainsItem($"Reservoir.{Module}.BathTotalDaysFaultLimit"))
  1890. {
  1891. bathTotalDaysFaultLimit = SC.GetValue<int>($"Reservoir.{Module}.BathTotalDaysFaultLimit");
  1892. }
  1893. if (reservoirUsage.BathUsageDays > bathTotalDaysFaultLimit && bathTotalDaysFaultLimit != 0)
  1894. {
  1895. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"{Module} Bath Usage(Days):{reservoirUsage.BathUsageDays} is over config item BathTotalDaysFaultLimit:{bathTotalDaysFaultLimit}");
  1896. reservoirEntity.PostMsg(ReservoirMsg.Error);
  1897. AlarmListManager.Instance.AddDataError(Module,
  1898. $"BathUsageDays", $"{Module} usage:{reservoirUsage.BathUsageDays} is over BathTotalDaysFaultLimit:{bathTotalDaysFaultLimit}");
  1899. }
  1900. else if (reservoirUsage.BathUsageDays > bathTotalDaysWarningLimit && bathTotalDaysWarningLimit != 0)
  1901. {
  1902. LOG.WriteLog(eEvent.WARN_RESERVOIR, Module, $"{Module} Bath Usage(Days):{reservoirUsage.BathUsage} is over config item BathTotalDaysWarningLimit:{bathTotalDaysWarningLimit}");
  1903. AlarmListManager.Instance.AddWarn(Module,
  1904. $"BathUsageDays", $"{Module} usage:{reservoirUsage.BathUsageDays} is over BathTotalDaysWarningLimit:{bathTotalDaysWarningLimit}");
  1905. }
  1906. //ReservoirTotalWafersCheck
  1907. int reservoirTotalWafersWarningLimit = 0;
  1908. if (SC.ContainsItem($"Reservoir.{Module}.ReservoirTotalWafersWarningLimit"))
  1909. {
  1910. reservoirTotalWafersWarningLimit = SC.GetValue<int>($"Reservoir.{Module}.ReservoirTotalWafersWarningLimit");
  1911. }
  1912. int reservoirTotalWafersFaultLimit = 0;
  1913. if (SC.ContainsItem($"Reservoir.{Module}.ReservoirTotalWafersFaultLimit"))
  1914. {
  1915. reservoirTotalWafersFaultLimit = SC.GetValue<int>($"Reservoir.{Module}.ReservoirTotalWafersFaultLimit");
  1916. }
  1917. if (reservoirUsage.TotalWafers > reservoirTotalWafersFaultLimit && reservoirTotalWafersFaultLimit != 0)
  1918. {
  1919. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"{Module} Total Wafers:{reservoirUsage.TotalWafers} is over config item ReservoirTotalWafersFaultLimit:{reservoirTotalWafersFaultLimit}");
  1920. reservoirEntity.PostMsg(ReservoirMsg.Error);
  1921. AlarmListManager.Instance.AddDataError(Module,
  1922. $"TotalWafers", $"{Module} usage:{reservoirUsage.TotalWafers} is over ReservoirTotalWafersFaultLimit:{reservoirTotalWafersFaultLimit}");
  1923. }
  1924. else if (reservoirUsage.TotalWafers > reservoirTotalWafersWarningLimit && reservoirTotalWafersWarningLimit != 0)
  1925. {
  1926. LOG.WriteLog(eEvent.WARN_RESERVOIR, Module, $"{Module} Total Wafers:{reservoirUsage.TotalWafers} is over config item ReservoirTotalWafersWarningLimit:{reservoirTotalWafersWarningLimit}");
  1927. AlarmListManager.Instance.AddWarn(Module,
  1928. $"TotalWafers", $"{Module} usage:{reservoirUsage.TotalWafers} is over ReservoirTotalWafersWarningLimit:{reservoirTotalWafersWarningLimit}");
  1929. }
  1930. //CMMAnodeTotalAmpHoursCheck
  1931. double cmmAnodeTotalAmpHoursWarningLimit = 0;
  1932. if (SC.ContainsItem($"Reservoir.{Module}.CMMAnodeTotalAmpHoursWarningLimit"))
  1933. {
  1934. cmmAnodeTotalAmpHoursWarningLimit = (double)SC.GetValue<double>($"Reservoir.{Module}.CMMAnodeTotalAmpHoursWarningLimit");
  1935. }
  1936. double cmmAnodeTotalAmpHoursFaultLimit = 0;
  1937. if (SC.ContainsItem($"Reservoir.{Module}.CMMAnodeTotalAmpHoursFaultLimit"))
  1938. {
  1939. cmmAnodeTotalAmpHoursFaultLimit = (double)SC.GetValue<double>($"Reservoir.{Module}.CMMAnodeTotalAmpHoursFaultLimit");
  1940. }
  1941. if (reservoirUsage.CMMAnodeUsage > cmmAnodeTotalAmpHoursFaultLimit && cmmAnodeTotalAmpHoursFaultLimit != 0)
  1942. {
  1943. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"{Module} CMM Anode Usage(AHr):{reservoirUsage.CMMAnodeUsage} is over config item CMMAnodeTotalAmpHoursFaultLimit:{cmmAnodeTotalAmpHoursFaultLimit}");
  1944. reservoirEntity.PostMsg(ReservoirMsg.Error);
  1945. AlarmListManager.Instance.AddDataError(Module,
  1946. $"CMMAnodeUsage", $"{Module} CMM Anode Usage(AHr):{reservoirUsage.CMMAnodeUsage} is over CMMAnodeTotalAmpHoursFaultLimit:{cmmAnodeTotalAmpHoursFaultLimit}");
  1947. }
  1948. else if (reservoirUsage.CMMAnodeUsage > cmmAnodeTotalAmpHoursWarningLimit && cmmAnodeTotalAmpHoursWarningLimit != 0)
  1949. {
  1950. LOG.WriteLog(eEvent.WARN_RESERVOIR, Module, $"{Module} CMM Anode Usage(AHr):{reservoirUsage.CMMAnodeUsage} is over config item CMMAnodeTotalAmpHoursWarningLimit:{cmmAnodeTotalAmpHoursWarningLimit}");
  1951. AlarmListManager.Instance.AddWarn(Module,
  1952. $"CMMAnodeUsage", $"{Module} CMM Anode Usage(AHr):{reservoirUsage.CMMAnodeUsage} is over CMMAnodeTotalAmpHoursWarningLimit:{cmmAnodeTotalAmpHoursWarningLimit}");
  1953. }
  1954. //CMMCathodeTotalAmpHoursCheck
  1955. double cmmCathodeTotalAmpHoursWarningLimit = 0;
  1956. if (SC.ContainsItem($"Reservoir.{Module}.CMMCathodeTotalAmpHoursWarningLimit"))
  1957. {
  1958. cmmCathodeTotalAmpHoursWarningLimit = (double)SC.GetValue<double>($"Reservoir.{Module}.CMMCathodeTotalAmpHoursWarningLimit");
  1959. }
  1960. double cmmCathodeTotalAmpHoursFaultLimit = 0;
  1961. if (SC.ContainsItem($"Reservoir.{Module}.CMMCathodeTotalAmpHoursFaultLimit"))
  1962. {
  1963. cmmCathodeTotalAmpHoursFaultLimit = (double)SC.GetValue<double>($"Reservoir.{Module}.CMMCathodeTotalAmpHoursFaultLimit");
  1964. }
  1965. if (reservoirUsage.CMMMembranceUsage > cmmCathodeTotalAmpHoursFaultLimit && cmmCathodeTotalAmpHoursFaultLimit != 0)
  1966. {
  1967. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"{Module} CMM Cathode Usage(AHr):{reservoirUsage.CMMMembranceUsage} is over config item CMMCathodeTotalAmpHoursFaultLimit:{cmmCathodeTotalAmpHoursFaultLimit}");
  1968. reservoirEntity.PostMsg(ReservoirMsg.Error);
  1969. AlarmListManager.Instance.AddDataError(Module,
  1970. $"CMMCathodeUsage", $"{Module} CMM Cathode Usage(AHr):{reservoirUsage.CMMMembranceUsage} is over CMMCathodeTotalAmpHoursFaultLimit:{cmmCathodeTotalAmpHoursFaultLimit}");
  1971. }
  1972. else if (reservoirUsage.CMMMembranceUsage > cmmCathodeTotalAmpHoursWarningLimit && cmmCathodeTotalAmpHoursWarningLimit != 0)
  1973. {
  1974. LOG.WriteLog(eEvent.WARN_RESERVOIR, Module, $"{Module} CMM Cathode Usage(AHr):{reservoirUsage.CMMMembranceUsage} is over config item CMMCathodeTotalAmpHoursWarningLimit:{cmmCathodeTotalAmpHoursWarningLimit}");
  1975. AlarmListManager.Instance.AddWarn(Module,
  1976. $"CMMCathodeUsage", $"{Module} CMM Cathode Usage(AHr):{reservoirUsage.CMMMembranceUsage} is over CMMCathodeTotalAmpHoursWarningLimit:{cmmCathodeTotalAmpHoursWarningLimit}");
  1977. }
  1978. }
  1979. #endregion
  1980. /// <summary>
  1981. /// 订阅变量数值发生变化
  1982. /// </summary>
  1983. private void SubscribeValueAction()
  1984. {
  1985. BeckhoffIoSubscribeUpdateVariable(FLOW);
  1986. BeckhoffIoSubscribeUpdateVariable(HED_FLOW);
  1987. BeckhoffIoSubscribeUpdateVariable(DI_REPLEN);
  1988. BeckhoffIoSubscribeUpdateVariable(PH_FLOW_VALVE);
  1989. BeckhoffIoSubscribeUpdateVariable(PH_VALUE);
  1990. BeckhoffIoSubscribeUpdateVariable(WATER_LEVEL);
  1991. BeckhoffIoSubscribeUpdateVariable(LOW_LEVEL);
  1992. BeckhoffIoSubscribeUpdateVariable(HIGH_LEVEL);
  1993. BeckhoffIoSubscribeUpdateVariable(SAFETY_HIGH_LEVEL);
  1994. BeckhoffIoSubscribeUpdateVariable(RESPOWERON);
  1995. BeckhoffIoSubscribeUpdateVariable(HEDPOWERON);
  1996. for (int i = 0; i < _replenNum; i++)
  1997. {
  1998. BeckhoffIoSubscribeUpdateVariable($"Replen{i + 1}Level");
  1999. }
  2000. }
  2001. /// <summary>
  2002. /// 订阅IO变量
  2003. /// </summary>
  2004. /// <param name="variable"></param>
  2005. private void BeckhoffIoSubscribeUpdateVariable(string variable)
  2006. {
  2007. _variableInitializeDic[variable] = false;
  2008. IOModuleManager.Instance.SubscribeModuleVariable(Module, variable, UpdateVariableValue);
  2009. }
  2010. /// <summary>
  2011. /// 更新变量数值
  2012. /// </summary>
  2013. /// <param name="variable"></param>
  2014. /// <param name="value"></param>
  2015. private void UpdateVariableValue(string variable, object value)
  2016. {
  2017. if (!ReservoirData.IsDataInitialized)
  2018. {
  2019. ReservoirData.IsDataInitialized = true;
  2020. }
  2021. PropertyInfo property = ReservoirData.GetType().GetProperty(variable);
  2022. if (property != null)
  2023. {
  2024. property.SetValue(_reservoirData, value);
  2025. if (variable == WATER_LEVEL)
  2026. {
  2027. string levelCurve = SC.GetStringValue($"Reservoir.{Module}.LevelCurve");
  2028. ReservoirData.Level = LevelCurveManager.Instance.CalculateLevelByWaterLevel(ReservoirData.WaterLevel, levelCurve);
  2029. }
  2030. }
  2031. if (variable.Contains("Replen") && variable.Substring(0, 6) == "Replen")
  2032. {
  2033. property = ReservoirData.GetType().GetProperty(REPLEN_LEVEL);
  2034. _replenLevelLst[int.Parse(variable.Substring(6, 1)) - 1] = (bool)value;
  2035. property.SetValue(_reservoirData, _replenLevelLst);
  2036. }
  2037. if (_variableInitializeDic.ContainsKey(variable) && !_variableInitializeDic[variable])
  2038. {
  2039. _variableInitializeDic[variable] = true;
  2040. }
  2041. }
  2042. /// <summary>
  2043. /// 是否所有IO变量初始化完成
  2044. /// </summary>
  2045. /// <returns></returns>
  2046. private bool AllIoVariableInitialized()
  2047. {
  2048. foreach (string item in _variableInitializeDic.Keys)
  2049. {
  2050. if (!_variableInitializeDic[item])
  2051. {
  2052. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"{item} is not initialized");
  2053. return false;
  2054. }
  2055. }
  2056. return true;
  2057. }
  2058. public void Monitor()
  2059. {
  2060. }
  2061. public void Reset()
  2062. {
  2063. }
  2064. public void Terminate()
  2065. {
  2066. }
  2067. }
  2068. }