StandardHotReservoirDevice.cs 99 KB

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