StandardHotReservoirDevice.cs 102 KB

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