StandardHotReservoirDevice.cs 72 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633
  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.IOCore;
  30. namespace CyberX8_RT.Devices.Reservoir
  31. {
  32. public class StandardHotReservoirDevice : BaseDevice, IDevice
  33. {
  34. private enum ReservoirOperation
  35. {
  36. None,
  37. ManualDiReplen,
  38. AutoDiReplen
  39. }
  40. private enum DosingOperation
  41. {
  42. None,
  43. ManualDosing,
  44. AutoDosing,
  45. }
  46. #region 常量
  47. private const string AUTO = "Auto";
  48. private const string MANUAL = "Manual";
  49. private const string DISABLE = "Disable";
  50. private const string STRATUS = "Stratus";
  51. private const string PERSISTENT_VALUE = "PersistentValue";
  52. private const string FLOW = "Flow";
  53. private const string HED_FLOW = "HedFlow";
  54. private const string PH_FLOW_VALVE = "PHFlowValve";
  55. private const string PH_VALUE = "PHValue";
  56. private const string WATER_LEVEL = "WaterLevel";
  57. private const string LOW_LEVEL = "LowLevel";
  58. private const string HIGH_LEVEL = "HighLevel";
  59. private const string DI_REPLEN = "DiReplen";
  60. private const string RESERVOIRDEVICEDATA = "ReservoirDeviceData";
  61. private const string REPLEN_LEVEL = "ReplenLevel";
  62. private const double PUMP_SPEED_CONVERT = 0.0672;
  63. private const int ENABLE = 5;
  64. #endregion
  65. #region 内部变量
  66. /// <summary>
  67. /// Level取样平均值
  68. /// </summary>
  69. private double _avgLevel;
  70. /// <summary>
  71. /// AN Level取样队列
  72. /// </summary>
  73. private Queue<double> _LevelSamples;
  74. /// <summary>
  75. /// Level计算平均值取样数
  76. /// </summary>
  77. private int levelSampleCount;
  78. /// <summary>
  79. /// Prewet 持久性数值对象
  80. /// </summary>
  81. private ReservoirsPersistentValue _persistentValue;
  82. /// <summary>
  83. /// 定时器Job
  84. /// </summary>
  85. PeriodicJob _periodicJob = null;
  86. /// <summary>
  87. /// 变量是否初始化字典
  88. /// </summary>
  89. private Dictionary<string, bool> _variableInitializeDic = new Dictionary<string, bool>();
  90. /// <summary>
  91. /// Reservoir数据
  92. /// </summary>
  93. private StandardHotReservoirData _reservoirData = new StandardHotReservoirData();
  94. /// <summary>
  95. /// 当前操作
  96. /// </summary>
  97. private ReservoirOperation _currentOperation = ReservoirOperation.None;
  98. /// <summary>
  99. /// 手动注水时间(秒)
  100. /// </summary>
  101. private int _manualReplenSecond = 0;
  102. /// <summary>
  103. /// Recipe
  104. /// </summary>
  105. private ResRecipe _resRecipe;
  106. /// <summary>
  107. /// 平均PH值
  108. /// </summary>
  109. private double _avaragePH;
  110. /// <summary>
  111. /// PH Routine
  112. /// </summary>
  113. private StandardHotPHRoutine _phRoutine;
  114. /// <summary>
  115. /// PH Routine状态
  116. /// </summary>
  117. private RState _phState=RState.Init;
  118. /// <summary>
  119. /// PH结束时间
  120. /// </summary>
  121. private DateTime _phRoutineEndTime=DateTime.Now;
  122. /// <summary>
  123. /// Direplen 逻辑对象
  124. /// </summary>
  125. private ReservoirDiReplenHelper _direplenHelper;
  126. /// <summary>
  127. /// Replen数量
  128. /// </summary>
  129. private int _replenNum = 0;
  130. /// <summary>
  131. /// Dose Replen数据
  132. /// </summary>
  133. private ReplenData[] _replenDatas;
  134. /// <summary>
  135. /// ReplenType
  136. /// </summary>
  137. private string _replenType;
  138. /// <summary>
  139. /// Replen Recipe集合
  140. /// </summary>
  141. private RdsRecipe[] _rdsRecipe;
  142. /// <summary>
  143. /// DosingSystemHelper对象列表
  144. /// </summary>
  145. private List<DosingSystemHelper> _dosingSystemHelperLst;
  146. /// <summary>
  147. /// ReplenLevel 列表
  148. /// </summary>
  149. private List<bool> _replenLevelLst;
  150. /// <summary>
  151. /// 当前操作
  152. /// </summary>
  153. private List<DosingOperation> _currentDosingOperation;
  154. /// <summary>
  155. /// 配置的metal device集合
  156. /// </summary>
  157. private ObservableCollection<StandardHotMetalDevice> _metalDevices = new ObservableCollection<StandardHotMetalDevice>();
  158. /// <summary>
  159. /// Replen Persistent Value
  160. /// </summary>
  161. private Dictionary<string, ReplenPersistentValue> _replenPersistentValue = new Dictionary<string, ReplenPersistentValue>();
  162. /// <summary>
  163. /// DosingCommonHelper
  164. /// </summary>
  165. private DosingCommonHelper _dosingCommonHelper;
  166. /// <summary>
  167. /// WarningFlag
  168. /// </summary>
  169. private List<bool> _isCAFlowRateWARN;
  170. /// <summary>
  171. /// CMM Flow High Error
  172. /// </summary>
  173. private double _reservoirCMMFlowHighError;
  174. /// <summary>
  175. /// CMM Flow Low Error
  176. /// </summary>
  177. private double _reservoirCMMFlowLowError;
  178. private bool _isTCControlWARN = false;
  179. private bool _isCMMPowerCurrentWARN = false;
  180. private bool _isCMMPowerFlowWARN = false;
  181. private bool _isExportCMMUsage = false;
  182. private bool _isAutoDIReplenError = false;
  183. #endregion
  184. #region 属性
  185. /// <summary>
  186. /// 数据
  187. /// </summary>
  188. public StandardHotReservoirData ReservoirData { get { return _reservoirData; } }
  189. /// <summary>
  190. /// Replen数据
  191. /// </summary>
  192. public ReplenData[] ReplenDatas { get { return _replenDatas; } }
  193. /// <summary>
  194. /// DosingSystemHelper对象列表
  195. /// </summary>
  196. public List<DosingSystemHelper> DosingSystemHelpers { get { return _dosingSystemHelperLst; }}
  197. /// <summary>
  198. /// Replen数量
  199. /// </summary>
  200. public int ReplenNum { get { return _replenNum; } }
  201. /// <summary>
  202. /// 操作模式
  203. /// </summary>
  204. public string OperationMode { get { return _persistentValue.OperatingMode; } }
  205. /// <summary>
  206. /// 工程模式
  207. /// </summary>
  208. public string EngineerMode { get { return _persistentValue.RecipeOperatingMode; } }
  209. /// <summary>
  210. /// 是否自动
  211. /// </summary>
  212. public bool IsAuto { get { return _persistentValue.OperatingMode == AUTO; } }
  213. /// <summary>
  214. /// 是否需要补水
  215. /// </summary>
  216. public bool NeedAutoDireplen { get { return GetNeedAutoDireplen(); } }
  217. /// <summary>
  218. /// 正在补水
  219. /// </summary>
  220. public bool IsDireplenOn { get { return _reservoirData.DiReplen; } }
  221. /// <summary>
  222. /// 平均PH数值
  223. /// </summary>
  224. public double AveragePH { get { return _avaragePH; } set { _avaragePH = value; } }
  225. /// <summary>
  226. /// 当前Recipe
  227. /// </summary>
  228. public ResRecipe Recipe { get { return _resRecipe; } }
  229. /// <summary>
  230. /// 当前Rds Recipe
  231. /// </summary>
  232. public RdsRecipe[] RdsRecipe { get { return _rdsRecipe; } }
  233. #endregion
  234. /// <summary>
  235. /// 构造函数
  236. /// </summary>
  237. /// <param name="moduleName"></param>
  238. /// <param name="name"></param>
  239. public StandardHotReservoirDevice(string moduleName) : base(moduleName, moduleName, moduleName, moduleName)
  240. {
  241. levelSampleCount = SC.GetValue<int>("Reservoir.LevelAvgSamples");
  242. levelSampleCount = levelSampleCount == 0 ? 20 : levelSampleCount;
  243. _LevelSamples = new Queue<double>(levelSampleCount);
  244. _periodicJob = new PeriodicJob(100, OnTimer, $"{Module}.OnTimer", true);
  245. _reservoirCMMFlowHighError = SC.GetValue<double>("Reservoir.CMM.CMMFlowHighFault");
  246. _reservoirCMMFlowLowError = SC.GetValue<double>("Reservoir.CMM.CMMFlowLowFault");
  247. }
  248. /// <summary>
  249. /// 定时器
  250. /// </summary>
  251. /// <returns></returns>
  252. private bool OnTimer()
  253. {
  254. //计算AN/CA level的平均值
  255. if (ReservoirData != null)
  256. {
  257. //AN
  258. if (_LevelSamples.Count >= levelSampleCount)
  259. {
  260. _LevelSamples.Dequeue();
  261. _LevelSamples.Enqueue(ReservoirData.Level);
  262. }
  263. else
  264. {
  265. _LevelSamples.Enqueue(ReservoirData.Level);
  266. }
  267. _avgLevel = _LevelSamples.Count > 0 ? _LevelSamples.Average() : 0;
  268. }
  269. foreach (StandardHotMetalDevice device in _metalDevices)
  270. {
  271. device.OnTimer(_periodicJob.Interval);
  272. }
  273. ReservoirEntity reservoirEntity = Singleton<RouteManager>.Instance.GetModule<ReservoirEntity>(Module);
  274. //报错停DosingSystem
  275. if (_replenType != "" && _replenNum != 0 && reservoirEntity != null && reservoirEntity.IsError)
  276. {
  277. for (int i = 0; i < _replenNum; i++)
  278. {
  279. string replenName = "Replen" + (i + 1).ToString();
  280. if (_replenPersistentValue[replenName].IsDosingRunning)
  281. {
  282. _dosingSystemHelperLst[i].StopDosing();
  283. _currentDosingOperation[i] = DosingOperation.None;
  284. }
  285. }
  286. }
  287. //触发水位过高或者过低将reservoir切成error
  288. if (!_reservoirData.LowLevel || ReservoirData.WaterLevel > SC.GetValue<double>($"Reservoir.{Module}.HighLevel"))
  289. {
  290. if (!_reservoirData.LowLevel && !reservoirEntity.IsError)
  291. {
  292. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"WaterLevel low is Activate");
  293. }
  294. if(ReservoirData.WaterLevel > SC.GetValue<double>($"Reservoir.{Module}.HighLevel") && !reservoirEntity.IsError)
  295. {
  296. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"WaterLevel:{ReservoirData.WaterLevel} is larger than HighLevel Config:{SC.GetValue<double>($"Reservoir.{Module}.HighLevel")}");
  297. SystemFacilities systemFacilities = DEVICE.GetDevice<SystemFacilities>("System.Facilities");
  298. if (systemFacilities != null)
  299. {
  300. systemFacilities.DiFillDisableOperation("DIFillDisableOpeartion", null);
  301. systemFacilities.DiReplenDisableOperation("DiReplenDisableOperation", null);
  302. if (ReservoirData.DiReplen)
  303. {
  304. _currentOperation = ReservoirOperation.None;
  305. DIReplenOff("", null);
  306. }
  307. }
  308. }
  309. reservoirEntity.PostMsg(ReservoirMsg.Error);
  310. }
  311. if (!_reservoirData.LowLevel) //true是正常的
  312. {
  313. ReservoirItem reservoirItem = ReservoirItemManager.Instance.GetReservoirItem(Module);
  314. foreach (var metalDevice in _metalDevices)
  315. {
  316. if (metalDevice.MetalDeviceData.Circulation)
  317. {
  318. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"Lowlevel was activate");
  319. metalDevice.SwitchToBypass($"{metalDevice.Name}.SwitchToBypass", null);
  320. }
  321. if (metalDevice.MetalDeviceData.CellFlow > 0)
  322. {
  323. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"Lowlevel was activate");
  324. metalDevice.PumpOff();
  325. }
  326. //水位过低时将起对应的metal也要切成error
  327. MetalEntity metalEntity = Singleton<RouteManager>.Instance.GetModule<MetalEntity>(metalDevice.DeviceID);
  328. if (metalEntity != null && !metalEntity.IsError)
  329. {
  330. metalEntity.PostMsg(MetalMsg.Error);
  331. }
  332. }
  333. //禁用TC
  334. if (!String.IsNullOrEmpty(reservoirItem.TCID))
  335. {
  336. TemperatureController temperatureController = DEVICE.GetDevice<TemperatureController>(reservoirItem.TCID);
  337. if (temperatureController != null && temperatureController.TemperatureData.ControlOperationModel == 5)
  338. {
  339. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"Lowlevel was activate");
  340. temperatureController.DisableOperation("", null);
  341. }
  342. }
  343. }
  344. //水位触发reservoir里面的high/low将对应的reservoir切成error
  345. if (_resRecipe != null && (ReservoirData.Level < _resRecipe.CALevelErrorLow || ReservoirData.Level > _resRecipe.CALevelErrorHigh))
  346. {
  347. if (ReservoirData.Level < _resRecipe.CALevelErrorLow && !reservoirEntity.IsError)
  348. {
  349. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"Current level:{ReservoirData.Level} is lower than recipe's CA Errorlow paramater:{_resRecipe.CALevelErrorLow}");
  350. }
  351. if (ReservoirData.Level > _resRecipe.CALevelErrorHigh && !reservoirEntity.IsError)
  352. {
  353. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"Current level:{ReservoirData.Level} is larger than recipe's CA Errorlow paramater:{_resRecipe.CALevelErrorHigh}");
  354. }
  355. reservoirEntity.PostMsg(ReservoirMsg.Error);
  356. }
  357. //触发Safetyhigh将reservoir切成error
  358. SafetyDevice safetyDevice = DEVICE.GetDevice<SafetyDevice>("Safety");
  359. if (safetyDevice != null && safetyDevice.SafetyData.ReservoirHighLevel && !reservoirEntity.IsError)
  360. {
  361. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"Safety high is Activate");
  362. reservoirEntity.PostMsg(ReservoirMsg.Error);
  363. }
  364. //DIReplen
  365. _direplenHelper.MonitorPeriodTime();
  366. if (_currentOperation == ReservoirOperation.ManualDiReplen && _reservoirData.DiReplen)
  367. {
  368. bool result = _direplenHelper.MonitorManualDiReplenComplete(_manualReplenSecond, DIReplenOff);
  369. if (result)
  370. {
  371. _currentOperation = ReservoirOperation.None;
  372. }
  373. }
  374. else if (_currentOperation == ReservoirOperation.AutoDiReplen && _reservoirData.DiReplen)
  375. {
  376. bool result = _direplenHelper.AutoDiReplenMonitorTimeOut(DIReplenOff);
  377. if (result)
  378. {
  379. _currentOperation = ReservoirOperation.None;
  380. }
  381. else
  382. {
  383. //按液位补水
  384. result = _direplenHelper.AutoDiReplenMonitorComplete(_reservoirData.Level, _resRecipe.ReservoirCALevel, _resRecipe, DIReplenOff);
  385. if (result)
  386. {
  387. _currentOperation = ReservoirOperation.None;
  388. }
  389. }
  390. }
  391. if (reservoirEntity == null || !reservoirEntity.IsInitialized)
  392. {
  393. return true;
  394. }
  395. if (_persistentValue.OperatingMode == AUTO)
  396. {
  397. CAFlowRateCheck();
  398. TemperatureCheck();
  399. CMMPowerCheck();
  400. //CMM用电量记录
  401. if (_isExportCMMUsage && _persistentValue.CMMStartTime != DateTime.MinValue)
  402. {
  403. ReservoirItem reservoirItem = ReservoirItemManager.Instance.GetReservoirItem(Module);
  404. if (!string.IsNullOrEmpty(reservoirItem.CMMSupplyID) && _resRecipe != null && _resRecipe.CMMEnable)
  405. {
  406. CellPowerSupplier powerSupplier = DEVICE.GetDevice<CellPowerSupplier>(reservoirItem.CMMSupplyID);
  407. double cmmUsage = powerSupplier.PowerSupplierData.Current * DateTime.Now.Subtract(_persistentValue.CMMStartTime).TotalHours;
  408. ReservoirUsageManager.Instance.UpdateReservoirCMMUsage(Module, Math.Round(cmmUsage, 3));
  409. _persistentValue.CMMStartTime = DateTime.Now;
  410. ReservoirsPersistentManager.Instance.UpdatePersistentValue(Module);
  411. _isExportCMMUsage = false;
  412. }
  413. }
  414. }
  415. if (_phState == RState.Running)
  416. {
  417. _phState = _phRoutine.Monitor();
  418. if (_phState == RState.End)
  419. {
  420. _phRoutineEndTime = DateTime.Now;
  421. }
  422. }
  423. else if (_phState != RState.Init)
  424. {
  425. double phUpdatePeriod = SC.GetValue<double>("Reservoir.PHUpdatePeriod");
  426. if (DateTime.Now.Subtract(_phRoutineEndTime).TotalMilliseconds >= phUpdatePeriod * 1000)
  427. {
  428. StartDetectPHValve();
  429. }
  430. }
  431. if (_replenType != "" && _replenNum != 0)
  432. {
  433. //DosingSystem 状态监控
  434. _dosingCommonHelper.DoseStatusMonitor();
  435. //Dosing监控
  436. if (_dosingCommonHelper.IsDosingSystemInitialized)
  437. {
  438. if (_replenPersistentValue["Replen1"].OperatingMode == "Manual")
  439. {
  440. //ManualDosing
  441. _dosingCommonHelper.ManualDoseSystemMonitor();
  442. }
  443. if (_replenPersistentValue["Replen1"].OperatingMode == "Auto")
  444. {
  445. //AutoDosing
  446. _dosingCommonHelper.AutoDoseSystemMonitor();
  447. }
  448. else
  449. {
  450. _dosingCommonHelper.CheckDoseOperation();
  451. }
  452. }
  453. }
  454. return true;
  455. }
  456. /// <summary>
  457. /// 获取是否需要补水
  458. /// </summary>
  459. /// <returns></returns>
  460. private bool GetNeedAutoDireplen()
  461. {
  462. if (IsAuto&&_resRecipe!=null)
  463. {
  464. if (_resRecipe.DIReplenEnable && _resRecipe.DIReplenCurrentRate == 0 && _resRecipe.DIReplenTimeRate == 0)
  465. {
  466. double levelHysteresis = SC.GetValue<double>("Reservoir.LevelHysteresis");
  467. return ReservoirData.Level < _resRecipe.ReservoirCALevel - levelHysteresis;
  468. }
  469. return false;
  470. }
  471. else
  472. {
  473. return false;
  474. }
  475. }
  476. /// <summary>
  477. /// 初始化
  478. /// </summary>
  479. /// <returns></returns>
  480. public bool Initialize()
  481. {
  482. InitializeRoutine();
  483. InitializeParameter();
  484. SubscribeData();
  485. InitializeOperation();
  486. SubscribeValueAction();
  487. return true;
  488. }
  489. /// <summary>
  490. /// 初始化routine
  491. /// </summary>
  492. private void InitializeRoutine()
  493. {
  494. _phRoutine = new StandardHotPHRoutine(Module);
  495. }
  496. /// <summary>
  497. /// 初始化参数
  498. /// </summary>
  499. private void InitializeParameter()
  500. {
  501. _persistentValue = ReservoirsPersistentManager.Instance.GetReservoirsPersistentValue(Module.ToString());
  502. if (_persistentValue == null)
  503. {
  504. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module.ToString(), "Persistent Value Object is not exist");
  505. }
  506. else
  507. {
  508. if (!string.IsNullOrEmpty(_persistentValue.Recipe))
  509. {
  510. _resRecipe = RecipeFileManager.Instance.LoadGenericityRecipe<ResRecipe>(_persistentValue.Recipe);
  511. }
  512. _direplenHelper = new ReservoirDiReplenHelper(Module, _persistentValue);
  513. }
  514. ReservoirItem reservoirItem = ReservoirItemManager.Instance.GetReservoirItem(Module.ToString());
  515. if (reservoirItem != null)
  516. {
  517. foreach (var item in reservoirItem.MetalCells)
  518. {
  519. if (item.ModuleName != Module)
  520. {
  521. StandardHotMetalDevice metalDevice = DEVICE.GetDevice<StandardHotMetalDevice>(item.ModuleName);
  522. if (metalDevice != null)
  523. {
  524. _metalDevices.Add(metalDevice);
  525. }
  526. }
  527. }
  528. }
  529. _isCAFlowRateWARN = new List<bool>(new bool[_metalDevices.Count]);
  530. //DosingSystem数据初始化
  531. _replenType = reservoirItem.ChemReplenType;
  532. _replenNum = reservoirItem.ChemReplenPumps;
  533. if (_replenType != "" && _replenNum != 0)
  534. {
  535. _replenDatas = new ReplenData[_replenNum];
  536. _rdsRecipe = new RdsRecipe[_replenNum];
  537. _replenLevelLst = new List<bool>(new bool[_replenNum]);
  538. _currentDosingOperation = new List<DosingOperation>();
  539. for (int i = 0; i < _replenNum; i++)
  540. {
  541. string replenName = "Replen" + (i + 1).ToString();
  542. _replenDatas[i] = new ReplenData();
  543. _replenDatas[i].ReplenName = replenName;
  544. _replenDatas[i].RecipeName = "";
  545. _replenDatas[i].BottleLevel = DosingSystemHelper.BottleLevelState.Empty.ToString();
  546. _replenDatas[i].IsAutoDosingError = false;
  547. if(_dosingSystemHelperLst==null) _dosingSystemHelperLst = new List<DosingSystemHelper> ();
  548. _dosingSystemHelperLst.Add(new DosingSystemHelper(Module, _replenDatas[i].ReplenName));
  549. _currentDosingOperation.Add(DosingOperation.None);
  550. _replenPersistentValue[replenName] = ReplenPersistentManager.Instance.GetReplenPersistentValue(Module, replenName);
  551. }
  552. _dosingCommonHelper = new DosingCommonHelper(Module, _replenNum);
  553. }
  554. }
  555. /// <summary>
  556. /// 订阅数据
  557. /// </summary>
  558. private void SubscribeData()
  559. {
  560. DATA.Subscribe($"{Module}.DIValveMaxOnTime", () => SC.GetValue<double>($"Reservoir.{Module}.DIValveMaxOnTime")*60, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  561. DATA.Subscribe($"{Module}.IsManualReplen", () => { return _currentOperation == ReservoirOperation.ManualDiReplen; }, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  562. DATA.Subscribe($"{Module}.ReservoirData", () => _reservoirData, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  563. DATA.Subscribe($"{Module}.ReservoirAverageLevel", () => _avgLevel, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  564. DATA.Subscribe($"{Module}.{PERSISTENT_VALUE}", () => _persistentValue,SubscriptionAttribute.FLAG.IgnoreSaveDB);
  565. DATA.Subscribe($"{Module}.ReplenPersistentValue", () => _replenPersistentValue, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  566. DATA.Subscribe($"{Module}.PHValue", () => _avaragePH, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  567. DATA.Subscribe($"{Module}.CurrentRecipe", () => _resRecipe, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  568. DATA.Subscribe($"{Module}.ReplenType", () => _replenType, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  569. DATA.Subscribe($"{Module}.ReplenNum", () => _replenNum, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  570. DATA.Subscribe($"{Module}.ReplenDatas", () => _replenDatas, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  571. DATA.Subscribe($"{Module}.DosingSystemState", () => _dosingCommonHelper != null ? _dosingCommonHelper.DosingSystemState : null, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  572. DATA.Subscribe($"{Module}.RecipeName", () => (_resRecipe != null ? _resRecipe.Ppid : ""), SubscriptionAttribute.FLAG.IgnoreSaveDB);
  573. DATA.Subscribe($"{Module}.HedFlow", () => _reservoirData.HedFlow, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  574. DATA.Subscribe($"{Module}.PHEnable",()=>_reservoirData.PHFlowValve, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  575. }
  576. /// <summary>
  577. /// 初始化操作
  578. /// </summary>
  579. private void InitializeOperation()
  580. {
  581. OP.Subscribe($"{Module}.DisabledAction", DisabledOperation);
  582. OP.Subscribe($"{Module}.ManualAction", ManualOperation);
  583. OP.Subscribe($"{Module}.AutoAction", AutoOperation);
  584. OP.Subscribe($"{Module}.EngineeringModeAction", EngineeringModeOperation);
  585. OP.Subscribe($"{Module}.ProductionModeAction", ProductionModeOperation);
  586. OP.Subscribe($"{Module}.DiReplenOn", DIReplenOnOperation);
  587. OP.Subscribe($"{Module}.DiReplenOff", DIReplenOff);
  588. OP.Subscribe($"{Module}.ManualDiReplen", ManualDiReplen);
  589. OP.Subscribe($"{Module}.ResetTotalTime", ResetTotalTime);
  590. OP.Subscribe($"{Module}.LoadRecipe", LoadRecipeOperation);
  591. OP.Subscribe($"{Module}.LoadDosingRecipe", LoadDosingRecipeOperation);
  592. OP.Subscribe($"{Module}.ReplenPumpOn", ReplenPumpOnOperation);
  593. OP.Subscribe($"{Module}.ReplenPumpOff", ReplenPumpOffOperation);
  594. OP.Subscribe($"{Module}.SetPumpFactor", SetPumpFactor);
  595. OP.Subscribe($"{Module}.ManualDosing", ManualDosing);
  596. OP.Subscribe($"{Module}.StopManualDosing", StopManualDosing);
  597. OP.Subscribe($"{Module}.ResetBottleVolume", ResetBottleVolume);
  598. OP.Subscribe($"{Module}.DosingInitialize", DosingInitialize);
  599. }
  600. #region Operation
  601. /// <summary>
  602. /// 重置时长
  603. /// </summary>
  604. /// <param name="cmd"></param>
  605. /// <param name="objs"></param>
  606. /// <returns></returns>
  607. private bool ResetTotalTime(string cmd, object[] objs)
  608. {
  609. _persistentValue.TotalReplen = 0;
  610. _persistentValue.LastTotalReplen = 0;
  611. ReservoirsPersistentManager.Instance.UpdatePersistentValue(Module);
  612. return true;
  613. }
  614. /// <summary>
  615. /// DisabledAction
  616. /// </summary>
  617. /// <param name="cmd"></param>
  618. /// <param name="param"></param>
  619. /// <returns></returns>
  620. private bool DisabledOperation(string cmd, object[] args)
  621. {
  622. string currentOperation = "Disabled";
  623. if (args.Length >= 1 && (bool)args[0])
  624. {
  625. foreach(var replenData in ReplenDatas)
  626. {
  627. if (_replenPersistentValue != null && _replenPersistentValue[replenData.ReplenName] != null)
  628. {
  629. _replenPersistentValue[replenData.ReplenName].OperatingMode = currentOperation;
  630. ReplenPersistentManager.Instance.UpdatePersistentValue(Module, replenData.ReplenName);
  631. }
  632. }
  633. for (int i = 0; i < _replenNum; i++)
  634. {
  635. string replenName = "Replen" + (i + 1).ToString();
  636. if (_replenPersistentValue[replenName].IsDosingRunning)
  637. {
  638. _dosingSystemHelperLst[i].StopDosing();
  639. _currentDosingOperation[i] = DosingOperation.None;
  640. }
  641. }
  642. DosingEnterInit();
  643. }
  644. else
  645. {
  646. if (_persistentValue != null)
  647. {
  648. ReservoirEntity reservoirEntity = Singleton<RouteManager>.Instance.GetModule<ReservoirEntity>(Module);
  649. if (_persistentValue.OperatingMode == "Auto" && reservoirEntity.IsMetalBusy)
  650. {
  651. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"{Module} is Busy, can't change to disable mode");
  652. return false;
  653. }
  654. foreach (var metalDevice in _metalDevices)
  655. {
  656. metalDevice.DisabledOperation("", null);
  657. MetalEntity metalEntity = Singleton<RouteManager>.Instance.GetModule<MetalEntity>(metalDevice.Module);
  658. metalEntity.AbortRecipe(null);
  659. metalDevice.EnterDisabledOperation();
  660. }
  661. EnterDisabledOperation();
  662. if (_persistentValue.OperatingMode != "Disabled") reservoirEntity.EnterInit();
  663. _persistentValue.OperatingMode = currentOperation;
  664. }
  665. ReservoirsPersistentManager.Instance.UpdatePersistentValue(Module);
  666. _currentOperation = ReservoirOperation.None;
  667. }
  668. return true;
  669. }
  670. /// <summary>
  671. /// ManualAction
  672. /// </summary>
  673. /// <param name="cmd"></param>
  674. /// <param name="param"></param>
  675. /// <returns></returns>
  676. private bool ManualOperation(string cmd, object[] args)
  677. {
  678. string currentOperation = "Manual";
  679. if (args.Length >= 1 && (bool)args[0])
  680. {
  681. foreach (var replenData in ReplenDatas)
  682. {
  683. if (_replenPersistentValue != null && _replenPersistentValue[replenData.ReplenName] != null)
  684. {
  685. _replenPersistentValue[replenData.ReplenName].OperatingMode = currentOperation;
  686. ReplenPersistentManager.Instance.UpdatePersistentValue(Module, replenData.ReplenName);
  687. }
  688. }
  689. DosingEnterInit();
  690. }
  691. else
  692. {
  693. ReservoirEntity reservoirEntity = Singleton<RouteManager>.Instance.GetModule<ReservoirEntity>(Module);
  694. if (reservoirEntity == null) return false;
  695. if (_persistentValue != null)
  696. {
  697. if (_persistentValue.OperatingMode == "Auto" && reservoirEntity.IsMetalBusy)
  698. {
  699. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"{Module} is Busy, can't change to manual mode");
  700. return false;
  701. }
  702. foreach (var metalDevice in _metalDevices)
  703. {
  704. metalDevice.ManualOperation("", null);
  705. }
  706. if (_persistentValue.OperatingMode != "Manual" && reservoirEntity != null) reservoirEntity.EnterInit();
  707. _persistentValue.OperatingMode = currentOperation;
  708. }
  709. ReservoirsPersistentManager.Instance.UpdatePersistentValue(Module);
  710. _currentOperation = ReservoirOperation.None;
  711. }
  712. return true;
  713. }
  714. /// <summary>
  715. /// AutoAction
  716. /// </summary>
  717. /// <param name="cmd"></param>
  718. /// <param name="param"></param>
  719. /// <returns></returns>
  720. private bool AutoOperation(string cmd, object[] args)
  721. {
  722. if (!_reservoirData.LowLevel)
  723. {
  724. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"Lowlevel was activate");
  725. return false;
  726. }
  727. string currentOperation = "Auto";
  728. if (args.Length >= 1 && (bool)args[0])
  729. {
  730. foreach (var replenData in ReplenDatas)
  731. {
  732. if (_replenPersistentValue != null && _replenPersistentValue[replenData.ReplenName] != null)
  733. {
  734. _replenPersistentValue[replenData.ReplenName].OperatingMode = currentOperation;
  735. ReplenPersistentManager.Instance.UpdatePersistentValue(Module, replenData.ReplenName);
  736. }
  737. }
  738. DosingEnterInit();
  739. }
  740. else
  741. {
  742. if (_persistentValue != null)
  743. {
  744. ReservoirEntity reservoirEntity = Singleton<RouteManager>.Instance.GetModule<ReservoirEntity>(Module);
  745. if (_persistentValue.OperatingMode != "Auto" && reservoirEntity != null) reservoirEntity.EnterInit();
  746. _persistentValue.OperatingMode = currentOperation;
  747. }
  748. ReservoirsPersistentManager.Instance.UpdatePersistentValue(Module);
  749. }
  750. return true;
  751. }
  752. /// <summary>
  753. /// EngineeringModeAction
  754. /// </summary>
  755. /// <param name="cmd"></param>
  756. /// <param name="param"></param>
  757. /// <returns></returns>
  758. private bool EngineeringModeOperation(string cmd, object[] args)
  759. {
  760. string currentRecipeOperation = "Engineering";
  761. if (_persistentValue != null)
  762. {
  763. _persistentValue.RecipeOperatingMode = currentRecipeOperation;
  764. }
  765. ReservoirsPersistentManager.Instance.UpdatePersistentValue(Module);
  766. return true;
  767. }
  768. /// <summary>
  769. /// ProductionAction
  770. /// </summary>
  771. /// <param name="cmd"></param>
  772. /// <param name="param"></param>
  773. /// <returns></returns>
  774. private bool ProductionModeOperation(string cmd, object[] args)
  775. {
  776. string currentRecipeOperation = "Production";
  777. if (_persistentValue != null)
  778. {
  779. _persistentValue.RecipeOperatingMode = currentRecipeOperation;
  780. }
  781. ReservoirsPersistentManager.Instance.UpdatePersistentValue(Module);
  782. return true;
  783. }
  784. /// <summary>
  785. /// 加载Recipe
  786. /// </summary>
  787. /// <param name="cmd"></param>
  788. /// <param name="args"></param>
  789. /// <returns></returns>
  790. private bool LoadRecipeOperation(string cmd, object[] args)
  791. {
  792. _persistentValue.Recipe = args[0].ToString();
  793. string[] fileRoute = _persistentValue.Recipe.Split('\\');
  794. string recipeRoute = "";
  795. if (fileRoute.Length > 2)
  796. {
  797. recipeRoute = fileRoute[fileRoute.Length - 2];
  798. }
  799. try
  800. {
  801. _resRecipe = RecipeFileManager.Instance.LoadGenericityRecipe<ResRecipe>(_persistentValue.Recipe);
  802. ReservoirsPersistentManager.Instance.UpdatePersistentValue(Module.ToString());
  803. LOG.WriteLog(eEvent.INFO_RESERVOIR, Module, $"Load {recipeRoute} Recipe {_resRecipe.Ppid} Success");
  804. }
  805. catch
  806. {
  807. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"Load {recipeRoute} Recipe {_persistentValue.Recipe} failed");
  808. }
  809. return true;
  810. }
  811. /// <summary>
  812. /// DiReplen On
  813. /// </summary>
  814. /// <param name="cmd"></param>
  815. /// <param name="args"></param>
  816. /// <returns></returns>
  817. public bool DIReplenOnOperation(string cmd, object[] args)
  818. {
  819. return DIReplenOn(true);
  820. }
  821. /// <summary>
  822. /// 自动注水
  823. /// </summary>
  824. /// <returns></returns>
  825. public bool DIReplenOn(bool showError)
  826. {
  827. if (ReservoirData.WaterLevel > SC.GetValue<double>($"Reservoir.{Module}.HighLevel"))
  828. {
  829. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, "Highlevel is activate");
  830. return false;
  831. }
  832. if (!_reservoirData.LowLevel) //信号是相反的
  833. {
  834. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"WaterLevel low is Activate");
  835. return false;
  836. }
  837. bool preCondition = CheckPreDiReplenCondition(showError);
  838. if (!preCondition)
  839. {
  840. return false;
  841. }
  842. string ioName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{DI_REPLEN}");
  843. bool result = IOModuleManager.Instance.WriteIoValue(ioName, true);
  844. if (result)
  845. {
  846. _persistentValue.IsDiReplenOn = true;
  847. }
  848. return result;
  849. }
  850. /// <summary>
  851. /// 检验DiReplen前置条件
  852. /// </summary>
  853. /// <returns></returns>
  854. public bool CheckPreDiReplenCondition(bool showError)
  855. {
  856. if (!CheckFacilitiesDiReplenStatus()&&showError)
  857. {
  858. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, "Facilities DiReplen is Off");
  859. return false;
  860. }
  861. SafetyDevice safetyDevice = DEVICE.GetDevice<SafetyDevice>("Safety");
  862. if (safetyDevice != null && safetyDevice.SafetyData.ReservoirHighLevel)
  863. {
  864. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"Safety high is Activate");
  865. return false;
  866. }
  867. if (CheckOtherReservoirDiReplenStatus(showError))
  868. {
  869. return false;
  870. }
  871. return true;
  872. }
  873. /// <summary>
  874. /// 检验总Di有没有开
  875. /// </summary>
  876. /// <returns></returns>
  877. private bool CheckFacilitiesDiReplenStatus()
  878. {
  879. SystemFacilities systemFacilities = DEVICE.GetDevice<SystemFacilities>("System.Facilities");
  880. if(systemFacilities!=null)
  881. {
  882. return systemFacilities.DIReplenEnable;
  883. }
  884. return false;
  885. }
  886. /// <summary>
  887. /// 检验是否其他Reservoir Direplen已经
  888. /// </summary>
  889. /// <returns></returns>
  890. private bool CheckOtherReservoirDiReplenStatus(bool showError)
  891. {
  892. List<string> reservoirs = ReservoirItemManager.Instance.InstalledModules;
  893. foreach (string item in reservoirs)
  894. {
  895. if(item!=Module)
  896. {
  897. ReservoirItem reservoirItem=ReservoirItemManager.Instance.GetReservoirItem(item);
  898. if(reservoirItem.SubType==STRATUS)
  899. {
  900. StandardHotReservoirDevice tmpDevice = DEVICE.GetDevice<StandardHotReservoirDevice>(item);
  901. if(tmpDevice.ReservoirData.DiReplen && showError)
  902. {
  903. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"{item} direplen valve is on");
  904. return true;
  905. }
  906. }
  907. else
  908. {
  909. CompactMembranReservoirDevice tmpDevice = DEVICE.GetDevice<CompactMembranReservoirDevice>(item);
  910. if(tmpDevice.ReservoirData.ANDiReplen&&showError)
  911. {
  912. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"{item} ANDireplen valve is on");
  913. return true;
  914. }
  915. if(tmpDevice.ReservoirData.CADiReplen && showError)
  916. {
  917. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"{item} CADireplen valve is on");
  918. return true;
  919. }
  920. }
  921. }
  922. }
  923. return false;
  924. }
  925. /// <summary>
  926. /// DiReplen Off
  927. /// </summary>
  928. /// <param name="cmd"></param>
  929. /// <param name="args"></param>
  930. /// <returns></returns>
  931. private bool DIReplenOff(string cmd, object[] args)
  932. {
  933. string ioName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{DI_REPLEN}");
  934. bool result= IOModuleManager.Instance.WriteIoValue(ioName, false);
  935. if(result)
  936. {
  937. _persistentValue.IsDiReplenOn = false;
  938. if(_currentOperation==ReservoirOperation.ManualDiReplen||_currentOperation==ReservoirOperation.AutoDiReplen)
  939. {
  940. _currentOperation = ReservoirOperation.None;
  941. _persistentValue.LastTotalReplen = _persistentValue.TotalReplen;
  942. ReservoirsPersistentManager.Instance.UpdatePersistentValue(Module);
  943. }
  944. }
  945. return result;
  946. }
  947. /// <summary>
  948. /// 手动注水
  949. /// </summary>
  950. /// <param name="cmd"></param>
  951. /// <param name="args"></param>
  952. /// <returns></returns>
  953. private bool ManualDiReplen(string cmd, object[] args)
  954. {
  955. if(_currentOperation!=ReservoirOperation.None)
  956. {
  957. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"current operation is {_currentOperation},cannot execute ManualDireplen operation");
  958. return false;
  959. }
  960. bool result = DIReplenOnOperation("", null);
  961. if(result)
  962. {
  963. _currentOperation = ReservoirOperation.ManualDiReplen;
  964. _persistentValue.DiReplenTime = DateTime.Now;
  965. ReservoirsPersistentManager.Instance.UpdatePersistentValue(Module);
  966. int.TryParse(args[0].ToString(), out _manualReplenSecond);
  967. }
  968. return result;
  969. }
  970. /// <summary>
  971. /// 自动注水
  972. /// </summary>
  973. /// <returns></returns>
  974. public bool AutoDireplen()
  975. {
  976. if (!_reservoirData.LowLevel && !_isAutoDIReplenError)
  977. {
  978. _isAutoDIReplenError = true;
  979. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"LowLevel is activate,Can't AutoDireplen");
  980. return false;
  981. }
  982. else
  983. {
  984. _isAutoDIReplenError = false;
  985. }
  986. if (_currentOperation != ReservoirOperation.None)
  987. {
  988. return false;
  989. }
  990. if(_resRecipe==null)
  991. {
  992. return false;
  993. }
  994. bool result = DIReplenOn(false);
  995. if(result)
  996. {
  997. _currentOperation = ReservoirOperation.AutoDiReplen;
  998. _persistentValue.DiReplenTime = DateTime.Now;
  999. }
  1000. return result;
  1001. }
  1002. /// <summary>
  1003. /// 启动PH检测
  1004. /// </summary>
  1005. public bool StartDetectPHValve()
  1006. {
  1007. if(_persistentValue.OperatingMode==MANUAL)
  1008. {
  1009. return false;
  1010. }
  1011. _phState= _phRoutine.Start();
  1012. LOG.WriteLog(eEvent.INFO_RESERVOIR, Module, "Start Detect PH");
  1013. return true;
  1014. }
  1015. /// <summary>
  1016. /// 打开PH Valve
  1017. /// </summary>
  1018. /// <returns></returns>
  1019. public bool PHValveOn()
  1020. {
  1021. string ioName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{PH_FLOW_VALVE}");
  1022. return IOModuleManager.Instance.WriteIoValue(ioName, true);
  1023. }
  1024. /// <summary>
  1025. /// 关闭PH Valve
  1026. /// </summary>
  1027. /// <returns></returns>
  1028. public bool PHValveOff()
  1029. {
  1030. string ioName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{PH_FLOW_VALVE}");
  1031. return IOModuleManager.Instance.WriteIoValue(ioName, false);
  1032. }
  1033. /// <summary>
  1034. /// CAFlowRateCheck
  1035. /// </summary>
  1036. private void CAFlowRateCheck()
  1037. {
  1038. ReservoirEntity reservoirEntity = Singleton<RouteManager>.Instance.GetModule<ReservoirEntity>(Module);
  1039. if (_resRecipe == null) return;
  1040. for (int i = 0; i < _metalDevices.Count; i++)
  1041. {
  1042. StandardHotMetalDevice hotMetalDevice = _metalDevices[i];
  1043. if (hotMetalDevice != null && !hotMetalDevice.IsDisable && hotMetalDevice.IsAuto)
  1044. {
  1045. if (hotMetalDevice.MetalDeviceData == null || !hotMetalDevice.MetalDeviceData.Circulation) continue;
  1046. if (!hotMetalDevice.FlowValveStable) continue;
  1047. double cellFlow = hotMetalDevice.MetalDeviceData.CellFlow;
  1048. if (cellFlow < _resRecipe.CAFlowRateErrorLow)
  1049. {
  1050. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"cell {hotMetalDevice.Name} cellflow:{cellFlow} is less than recipe's CAFlowRateErrorLow parameter:{_resRecipe.CAFlowRateErrorLow}");
  1051. reservoirEntity.PostMsg(ReservoirMsg.Error);
  1052. }
  1053. else if (cellFlow < _resRecipe.CAFlowRateWarningLow)
  1054. {
  1055. if (!_isCAFlowRateWARN[i])
  1056. {
  1057. LOG.WriteLog(eEvent.WARN_RESERVOIR, Module, $"cell {hotMetalDevice.Name} cellflow:{cellFlow} is less than recipe's CAFlowRateWarningLow parameter:{_resRecipe.CAFlowRateWarningLow}");
  1058. _isCAFlowRateWARN[i] = true;
  1059. }
  1060. }
  1061. else
  1062. {
  1063. _isCAFlowRateWARN[i] = false;
  1064. }
  1065. }
  1066. }
  1067. }
  1068. /// <summary>
  1069. /// Temperature Check
  1070. /// </summary>
  1071. private void TemperatureCheck()
  1072. {
  1073. ReservoirEntity reservoirEntity = Singleton<RouteManager>.Instance.GetModule<ReservoirEntity>(Module);
  1074. ReservoirItem reservoirItem = ReservoirItemManager.Instance.GetReservoirItem(Module);
  1075. TemperatureController temperatureController = DEVICE.GetDevice<TemperatureController>(reservoirItem.TCID);
  1076. if (temperatureController == null || temperatureController.TemperatureData == null || _resRecipe == null
  1077. || temperatureController.TemperatureData.ControlOperationModel != ENABLE) return;
  1078. double tempValue = temperatureController.TemperatureData.ReserviorTemperature;
  1079. if (tempValue > _resRecipe.TemperatureErrorHigh && !reservoirEntity.IsError)
  1080. {
  1081. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"{temperatureController.Name} temperature:{tempValue} is over recipe's TemperatureErrorHigh parameter:{_resRecipe.TemperatureErrorHigh}");
  1082. reservoirEntity.PostMsg(ReservoirMsg.Error);
  1083. }
  1084. else if (tempValue < _resRecipe.TemperatureErrorLow && !reservoirEntity.IsError)
  1085. {
  1086. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"{temperatureController.Name} temperature:{tempValue} is less than recipe's TemperatureErrorLow parameter:{_resRecipe.TemperatureErrorLow}");
  1087. reservoirEntity.PostMsg(ReservoirMsg.Error);
  1088. }
  1089. else if (tempValue > _resRecipe.TemperatureWarningHigh)
  1090. {
  1091. if (!_isTCControlWARN)
  1092. {
  1093. LOG.WriteLog(eEvent.WARN_RESERVOIR, Module, $"{temperatureController.Name} temperature:{tempValue} is over recipe's TemperatureWarningHigh parameter:{_resRecipe.TemperatureWarningHigh}");
  1094. _isTCControlWARN = true;
  1095. }
  1096. }
  1097. else if (tempValue < _resRecipe.TemperatureWarningLow)
  1098. {
  1099. if (!_isTCControlWARN)
  1100. {
  1101. LOG.WriteLog(eEvent.WARN_RESERVOIR, Module, $"{temperatureController.Name} temperature:{tempValue} is less than recipe's TemperatureWarningLow parameter:{_resRecipe.TemperatureWarningLow}");
  1102. _isTCControlWARN = true;
  1103. }
  1104. }
  1105. else
  1106. {
  1107. _isTCControlWARN = false;
  1108. }
  1109. }
  1110. /// <summary>
  1111. /// CMMPowerCheck
  1112. /// </summary>
  1113. private void CMMPowerCheck()
  1114. {
  1115. ReservoirEntity reservoirEntity = Singleton<RouteManager>.Instance.GetModule<ReservoirEntity>(Module);
  1116. ReservoirItem _reservoirItem = ReservoirItemManager.Instance.GetReservoirItem(Module.ToString());
  1117. if (!string.IsNullOrEmpty(_reservoirItem.CMMSupplyID))
  1118. {
  1119. CellPowerSupplier _powerSupplier = DEVICE.GetDevice<CellPowerSupplier>(_reservoirItem.CMMSupplyID);
  1120. if (_powerSupplier == null || _powerSupplier.PowerSupplierData == null || _resRecipe == null || !_resRecipe.CMMEnable||!_powerSupplier.PowerSupplierData.Enabled || _powerSupplier.PowerSupplierData.Current == 0) return;
  1121. //CMM Current Check
  1122. double current = _powerSupplier.PowerSupplierData.Current;
  1123. if (current > _resRecipe.CMMCurrentSetPoint * (1 + (double)_resRecipe.CMMCurrentFaultPercent / 100))
  1124. {
  1125. 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} %");
  1126. reservoirEntity.PostMsg(ReservoirMsg.Error);
  1127. if (_powerSupplier.PowerSupplierData.Enabled)
  1128. {
  1129. _powerSupplier.DisableOperation("", null);
  1130. _persistentValue.CMMStartTime = DateTime.MinValue;
  1131. ReservoirsPersistentManager.Instance.UpdatePersistentValue(Module);
  1132. }
  1133. }
  1134. else if (current < _resRecipe.CMMCurrentSetPoint * (1 - (double)_resRecipe.CMMCurrentFaultPercent / 100))
  1135. {
  1136. 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}%");
  1137. reservoirEntity.PostMsg(ReservoirMsg.Error);
  1138. if (_powerSupplier.PowerSupplierData.Enabled)
  1139. {
  1140. _powerSupplier.DisableOperation("", null);
  1141. _persistentValue.CMMStartTime = DateTime.MinValue;
  1142. ReservoirsPersistentManager.Instance.UpdatePersistentValue(Module);
  1143. }
  1144. }
  1145. else if (current > _resRecipe.CMMCurrentSetPoint * (1 + (double)_resRecipe.CMMCurrentWarningPercent / 100))
  1146. {
  1147. if (!_isCMMPowerCurrentWARN)
  1148. {
  1149. 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}%");
  1150. _isCMMPowerCurrentWARN = true;
  1151. }
  1152. }
  1153. else if (current < _resRecipe.CMMCurrentSetPoint * (1 - (double)_resRecipe.CMMCurrentWarningPercent / 100))
  1154. {
  1155. if (!_isCMMPowerCurrentWARN)
  1156. {
  1157. 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}%");
  1158. _isCMMPowerCurrentWARN = true;
  1159. }
  1160. }
  1161. else
  1162. {
  1163. _isCMMPowerCurrentWARN = false;
  1164. }
  1165. //CMM Voltage Check
  1166. double voltage = _powerSupplier.PowerSupplierData.Voltage;
  1167. if (voltage < _resRecipe.CMMMinVoltage)
  1168. {
  1169. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"{_powerSupplier.Name} voltage:{voltage} is less than recipe's CMMMinVoltage parameter:{_resRecipe.CMMMinVoltage}");
  1170. reservoirEntity.PostMsg(ReservoirMsg.Error);
  1171. if (_powerSupplier.PowerSupplierData.Enabled) _powerSupplier.DisableOperation("", null);
  1172. }
  1173. //CMM Flow Check
  1174. double flow = ReservoirData.Flow;
  1175. double cmmFlowHighFault = SC.GetValue<double>($"Reservoir.CMM.CMMFlowHighFault");
  1176. double cmmFlowHighWarning = SC.GetValue<double>($"Reservoir.CMM.CMMFlowHighWarning");
  1177. double cmmFlowLowFault = SC.GetValue<double>($"Reservoir.CMM.CMMFlowLowFault");
  1178. double cmmFlowLowWarning = SC.GetValue<double>($"Reservoir.CMM.CMMFlowLowWarning");
  1179. if (flow < cmmFlowLowFault)
  1180. {
  1181. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"{Module} CMM flow:{flow} is less than config item CMMFlowLowFault:{cmmFlowLowFault}");
  1182. if (_powerSupplier.PowerSupplierData.Enabled) _powerSupplier.DisableOperation("", null);
  1183. reservoirEntity.PostMsg(ReservoirMsg.Error);
  1184. }
  1185. else if (flow < cmmFlowLowWarning)
  1186. {
  1187. if (!_isCMMPowerFlowWARN)
  1188. {
  1189. LOG.WriteLog(eEvent.WARN_RESERVOIR, Module, $"{Module} CMM flow:{flow} is less than config item CMMFlowLowWarning:{cmmFlowLowWarning}");
  1190. _isCMMPowerFlowWARN = true;
  1191. }
  1192. }
  1193. else if (flow > cmmFlowHighFault)
  1194. {
  1195. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"{Module} CMM flow:{flow} is over config item CMMFlowHighFault:{cmmFlowLowFault}");
  1196. if(_powerSupplier.PowerSupplierData.Enabled) _powerSupplier.DisableOperation("", null);
  1197. reservoirEntity.PostMsg(ReservoirMsg.Error);
  1198. }
  1199. else if (flow > cmmFlowHighWarning)
  1200. {
  1201. if (!_isCMMPowerFlowWARN)
  1202. {
  1203. LOG.WriteLog(eEvent.WARN_RESERVOIR, Module, $"{Module} CMM flow:{flow} is over config item CMMFlowHighWarning:{cmmFlowLowWarning}");
  1204. _isCMMPowerFlowWARN = true;
  1205. }
  1206. }
  1207. else
  1208. {
  1209. _isCMMPowerFlowWARN = false;
  1210. }
  1211. }
  1212. }
  1213. #region DosingSystem
  1214. /// <summary>
  1215. /// 加载Replen Recipe
  1216. /// </summary>
  1217. /// <param name="cmd"></param>
  1218. /// <param name="args"></param>
  1219. /// <returns></returns>
  1220. private bool LoadDosingRecipeOperation(string cmd, object[] args)
  1221. {
  1222. string replenName = args[1].ToString();
  1223. int replenID = int.Parse(args[1].ToString().Substring(6,1));
  1224. string replenRecipe = args[0].ToString();
  1225. _rdsRecipe[replenID-1] = RecipeFileManager.Instance.LoadGenericityRecipe<RdsRecipe>(replenRecipe);
  1226. _replenDatas[replenID-1].RecipeName = args[2].ToString();
  1227. LOG.WriteLog(eEvent.INFO_RESERVOIR, Module, $"Load Replen Recipe {_rdsRecipe[replenID-1].Ppid} Success");
  1228. return true;
  1229. }
  1230. #region Replen Pump
  1231. /// <summary>
  1232. /// Replen Pump On 操作(根据PumpFactor和InitialDosingSpeed调速)
  1233. /// </summary>
  1234. /// <param name="cmd"></param>
  1235. /// <param name="args"></param>
  1236. /// <returns></returns>
  1237. public bool ReplenPumpOnOperation(string cmd, object[] args)
  1238. {
  1239. string replenName = args[0].ToString();
  1240. int replenID = int.Parse(args[0].ToString().Substring(6, 1));
  1241. //加载InitialDosingSpeed
  1242. double InitialDosingSpeed = 0;
  1243. if (SC.ContainsItem($"Reservoir.{Module}.InitialDosingSpeed"))
  1244. {
  1245. InitialDosingSpeed = SC.GetValue<double>($"Reservoir.{Module}.InitialDosingSpeed");
  1246. if(InitialDosingSpeed == 0)
  1247. {
  1248. _replenDatas[replenID - 1].ReplenPumpEnable = false;
  1249. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, "InitialDosingSpeed is zero. Can't open replen pump");
  1250. return false;
  1251. }
  1252. }
  1253. else
  1254. {
  1255. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, "Configuration item of InitialDosingSpeed doesn't exist!");
  1256. return false;
  1257. }
  1258. //加载ReplenPumpFactor
  1259. double PumpFactor = 0;
  1260. PumpFactor = _replenPersistentValue[replenName].ReplenPumpFactor;
  1261. if(PumpFactor == 0)
  1262. {
  1263. _replenDatas[replenID - 1].ReplenPumpEnable = false;
  1264. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, "PumpFactor is zero. Can't open replen pump");
  1265. return false;
  1266. }
  1267. //计算PumpSpeed(mL/min)
  1268. double replenPumpSpeed = InitialDosingSpeed * PumpFactor;
  1269. SCConfigItem item = SC.GetConfigItem($"Reservoir.{Module}.InitialDosingSpeed");
  1270. double speedMax = double.Parse(item.Max);
  1271. if(replenPumpSpeed > speedMax) replenPumpSpeed = speedMax;
  1272. bool result = ReplenPump(replenPumpSpeed / PUMP_SPEED_CONVERT, replenID);
  1273. if (!result)
  1274. {
  1275. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"Opening replen{replenID} pump is failed");
  1276. _replenDatas[replenID - 1].ReplenPumpSpeed = 0;
  1277. _replenDatas[replenID - 1].ReplenPumpEnable = false;
  1278. return false;
  1279. }
  1280. _replenDatas[replenID - 1].ReplenPumpSpeed = replenPumpSpeed;
  1281. _replenDatas[replenID - 1].ReplenPumpEnable = true;
  1282. LOG.WriteLog(eEvent.INFO_RESERVOIR, Module, $"Replen{replenID} pump is opened");
  1283. return true;
  1284. }
  1285. /// <summary>
  1286. /// Replen Pump Off操作
  1287. /// </summary>
  1288. /// <param name="cmd"></param>
  1289. /// <param name="args"></param>
  1290. /// <returns></returns>
  1291. public bool ReplenPumpOffOperation(string cmd, object[] args)
  1292. {
  1293. string replenName = args[0].ToString();
  1294. int replenID = int.Parse(args[0].ToString().Substring(6, 1));
  1295. bool result = ReplenPump(0, replenID);
  1296. if (!result)
  1297. {
  1298. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"Closing replen{replenID} pump is failed");
  1299. return false;
  1300. }
  1301. _replenDatas[replenID - 1].ReplenPumpSpeed = 0;
  1302. _replenDatas[replenID - 1].ReplenPumpEnable = false;
  1303. LOG.WriteLog(eEvent.INFO_RESERVOIR, Module, $"Replen{replenID} pump is closed");
  1304. return true;
  1305. }
  1306. /// <summary>
  1307. /// Replen Pump WriteIOValue
  1308. /// </summary>
  1309. /// <param name="speed"></param>
  1310. /// <returns></returns>
  1311. private bool ReplenPump(double speed, int replenNum)
  1312. {
  1313. string ioName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.Replen{replenNum}PumpSpeed");
  1314. return IOModuleManager.Instance.WriteIoValue(ioName, speed);
  1315. }
  1316. #endregion
  1317. /// <summary>
  1318. /// 设置PumpFactor
  1319. /// </summary>
  1320. /// <param name="cmd"></param>
  1321. /// <param name="args"></param>
  1322. /// <returns></returns>
  1323. public bool SetPumpFactor(string cmd, object[] args)
  1324. {
  1325. int replenID = int.Parse(args[0].ToString().Substring(6, 1));
  1326. double targetPumpFactor = (double)args[1];
  1327. _dosingSystemHelperLst[replenID-1].SetPumpfactor(targetPumpFactor);
  1328. return true;
  1329. }
  1330. /// <summary>
  1331. /// 手动Dosing
  1332. /// </summary>
  1333. /// <param name="cmd"></param>
  1334. /// <param name="args"></param>
  1335. /// <returns></returns>
  1336. private bool ManualDosing(string cmd, object[] args)
  1337. {
  1338. ReservoirEntity reservoirEntity = Singleton<RouteManager>.Instance.GetModule<ReservoirEntity>(Module);
  1339. if (reservoirEntity == null || !_dosingCommonHelper.IsDosingSystemInitialized)
  1340. {
  1341. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, "Dosing System is not initialized!");
  1342. return true;
  1343. }
  1344. string replenName = args[0].ToString();
  1345. int replenID = int.Parse(args[0].ToString().Substring(6, 1));
  1346. double manualDosingVolume = (double)args[1];
  1347. if(manualDosingVolume == 0)
  1348. {
  1349. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, "Dosing Volume is zero, can't do manual dosing");
  1350. return false;
  1351. }
  1352. if (!CheckandUpdateBottleLevel(replenName, manualDosingVolume))
  1353. {
  1354. return false;
  1355. }
  1356. if (_replenPersistentValue[replenName].IsDosingRunning)
  1357. {
  1358. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, "Dosing is runnning, can't do manual dosing");
  1359. return false;
  1360. }
  1361. LOG.WriteLog(eEvent.INFO_RESERVOIR, Module, "ManualDosing starts now");
  1362. _currentDosingOperation[replenID - 1] = DosingOperation.ManualDosing;
  1363. bool result = _dosingSystemHelperLst[replenID-1].StartDosing(manualDosingVolume, false);
  1364. return result;
  1365. }
  1366. /// <summary>
  1367. /// 停止手动Dosing
  1368. /// </summary>
  1369. /// <param name="cmd"></param>
  1370. /// <param name="args"></param>
  1371. /// <returns></returns>
  1372. private bool StopManualDosing(string cmd, object[] args)
  1373. {
  1374. string replenName = args[0].ToString();
  1375. int replenID = int.Parse(args[0].ToString().Substring(6, 1));
  1376. if (!_replenPersistentValue[replenName].IsDosingRunning)
  1377. {
  1378. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, "ManualDosing is not running. Can't stop!");
  1379. }
  1380. _currentDosingOperation[replenID - 1] = DosingOperation.None;
  1381. bool result = _dosingSystemHelperLst[replenID - 1].StopDosing();
  1382. if (result)
  1383. {
  1384. LOG.WriteLog(eEvent.INFO_RESERVOIR, Module, "ManualDosing has stopped now");
  1385. }
  1386. return result;
  1387. }
  1388. /// <summary>
  1389. /// 检查并更新BottleLevel状态
  1390. /// </summary>
  1391. /// <param name="replenName"></param>
  1392. /// <param name="targetVolume"></param>
  1393. public bool CheckandUpdateBottleLevel(string replenName, double targetVolume = -1, bool isError = true)
  1394. {
  1395. int replenId = int.Parse(replenName.Substring(6, 1));
  1396. double remainVolume = _replenPersistentValue[replenName].RemainDosingVolume;
  1397. bool result = true;
  1398. if (ReservoirData.ReplenLevel[replenId - 1])
  1399. {
  1400. ReplenDatas[replenId - 1].BottleLevel = DosingSystemHelper.BottleLevelState.Full.ToString();
  1401. if (targetVolume > remainVolume)
  1402. {
  1403. ReplenDatas[replenId - 1].BottleLevel = DosingSystemHelper.BottleLevelState.Warning.ToString();
  1404. if (isError)
  1405. {
  1406. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"Current Bottle is in Warning Level!");
  1407. }
  1408. result = false;
  1409. }
  1410. }
  1411. else
  1412. {
  1413. ReplenDatas[replenId - 1].BottleLevel = DosingSystemHelper.BottleLevelState.Empty.ToString();
  1414. if (isError)
  1415. {
  1416. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"Current Bottle is in Empty Level!");
  1417. }
  1418. result = false;
  1419. }
  1420. return result;
  1421. }
  1422. /// <summary>
  1423. /// Reset BottleVolume
  1424. /// </summary>
  1425. /// <param name="cmd"></param>
  1426. /// <param name="args"></param>
  1427. /// <returns></returns>
  1428. private bool ResetBottleVolume(string cmd, object[] args)
  1429. {
  1430. string replenName = args[0].ToString();
  1431. int replenID = int.Parse(args[0].ToString().Substring(6, 1));
  1432. if (SC.ContainsItem($"Reservoir.{Module}.BottleReserveVolume{replenID}"))
  1433. {
  1434. _replenPersistentValue[replenName].RemainDosingVolume = SC.GetValue<double>($"Reservoir.{Module}.BottleReserveVolume{replenID}");
  1435. }
  1436. ReplenPersistentManager.Instance.UpdatePersistentValue(Module, replenName);
  1437. LOG.WriteLog(eEvent.INFO_RESERVOIR, Module, $"Bottle Reserve Volume of Replen{replenID} has been reset now");
  1438. return true;
  1439. }
  1440. /// <summary>
  1441. /// DosingSystem初始化
  1442. /// </summary>
  1443. /// <param name="cmd"></param>
  1444. /// <param name="args"></param>
  1445. /// <returns></returns>
  1446. private bool DosingInitialize(string cmd, object[] args)
  1447. {
  1448. ReservoirEntity reservoirEntity = Singleton<RouteManager>.Instance.GetModule<ReservoirEntity>(Module);
  1449. if (reservoirEntity == null || !reservoirEntity.IsInitialized)
  1450. {
  1451. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"{Module} is not initialized");
  1452. return false;
  1453. }
  1454. return _dosingCommonHelper.DosingInitialize(); ;
  1455. }
  1456. /// <summary>
  1457. /// Enetr Init State
  1458. /// </summary>
  1459. /// <param name="cmd"></param>
  1460. /// <param name="args"></param>
  1461. /// <returns></returns>
  1462. private bool DosingEnterInit()
  1463. {
  1464. return _dosingCommonHelper.DosingEnterInit();
  1465. }
  1466. #endregion
  1467. /// <summary>
  1468. /// Enter Disabled Operation
  1469. /// </summary>
  1470. private void EnterDisabledOperation()
  1471. {
  1472. ReservoirItem _reservoirItem = ReservoirItemManager.Instance.GetReservoirItem(Module.ToString());
  1473. //关CMMPower
  1474. if (!string.IsNullOrEmpty(_reservoirItem.CMMSupplyID))
  1475. {
  1476. CellPowerSupplier powerSupplier = DEVICE.GetDevice<CellPowerSupplier>(_reservoirItem.CMMSupplyID);
  1477. if(powerSupplier != null && powerSupplier.PowerSupplierData.Enabled) powerSupplier.DisableOperation("", null);
  1478. }
  1479. //关TC
  1480. if (!string.IsNullOrEmpty(_reservoirItem.TCID))
  1481. {
  1482. TemperatureController temperatureController = DEVICE.GetDevice<TemperatureController>(_reservoirItem.TCID);
  1483. if(temperatureController != null) temperatureController.DisableOperation("", null);
  1484. }
  1485. _phRoutine.Abort();
  1486. if (_reservoirData.PHFlowValve)
  1487. {
  1488. PHValveOff();
  1489. }
  1490. if (_reservoirData.DiReplen)
  1491. {
  1492. DIReplenOff("", null);
  1493. }
  1494. }
  1495. /// <summary>
  1496. /// Set Export CMMUsage
  1497. /// </summary>
  1498. public void SetExportCMMUsage()
  1499. {
  1500. _isExportCMMUsage = true;
  1501. }
  1502. #endregion
  1503. /// <summary>
  1504. /// 订阅变量数值发生变化
  1505. /// </summary>
  1506. private void SubscribeValueAction()
  1507. {
  1508. BeckhoffIoSubscribeUpdateVariable(FLOW);
  1509. BeckhoffIoSubscribeUpdateVariable(HED_FLOW);
  1510. BeckhoffIoSubscribeUpdateVariable(DI_REPLEN);
  1511. BeckhoffIoSubscribeUpdateVariable(PH_FLOW_VALVE);
  1512. BeckhoffIoSubscribeUpdateVariable(PH_VALUE);
  1513. BeckhoffIoSubscribeUpdateVariable(WATER_LEVEL);
  1514. BeckhoffIoSubscribeUpdateVariable(LOW_LEVEL);
  1515. BeckhoffIoSubscribeUpdateVariable(HIGH_LEVEL);
  1516. for(int i = 0;i < _replenNum;i++)
  1517. {
  1518. BeckhoffIoSubscribeUpdateVariable($"Replen{i+1}Level");
  1519. }
  1520. }
  1521. /// <summary>
  1522. /// 订阅IO变量
  1523. /// </summary>
  1524. /// <param name="variable"></param>
  1525. private void BeckhoffIoSubscribeUpdateVariable(string variable)
  1526. {
  1527. _variableInitializeDic[variable] = false;
  1528. IOModuleManager.Instance.SubscribeModuleVariable(Module, variable, UpdateVariableValue);
  1529. }
  1530. /// <summary>
  1531. /// 更新变量数值
  1532. /// </summary>
  1533. /// <param name="variable"></param>
  1534. /// <param name="value"></param>
  1535. private void UpdateVariableValue(string variable, object value)
  1536. {
  1537. if (!ReservoirData.IsDataInitialized)
  1538. {
  1539. ReservoirData.IsDataInitialized = true;
  1540. }
  1541. PropertyInfo property = ReservoirData.GetType().GetProperty(variable);
  1542. if (property != null)
  1543. {
  1544. property.SetValue(_reservoirData, value);
  1545. if(variable==WATER_LEVEL)
  1546. {
  1547. string levelCurve = SC.GetStringValue($"Reservoir.{Module}.LevelCurve");
  1548. ReservoirData.Level = LevelCurveManager.Instance.CalculateLevelByWaterLevel(ReservoirData.WaterLevel, levelCurve);
  1549. }
  1550. }
  1551. if (variable.Contains("Replen") && variable.Substring(0,6) == "Replen")
  1552. {
  1553. property = ReservoirData.GetType().GetProperty(REPLEN_LEVEL);
  1554. _replenLevelLst[int.Parse(variable.Substring(6, 1)) - 1] = (bool)value;
  1555. property.SetValue(_reservoirData, _replenLevelLst);
  1556. }
  1557. if (_variableInitializeDic.ContainsKey(variable) && !_variableInitializeDic[variable])
  1558. {
  1559. _variableInitializeDic[variable] = true;
  1560. }
  1561. }
  1562. /// <summary>
  1563. /// 是否所有IO变量初始化完成
  1564. /// </summary>
  1565. /// <returns></returns>
  1566. private bool AllIoVariableInitialized()
  1567. {
  1568. foreach (string item in _variableInitializeDic.Keys)
  1569. {
  1570. if (!_variableInitializeDic[item])
  1571. {
  1572. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"{item} is not initialized");
  1573. return false;
  1574. }
  1575. }
  1576. return true;
  1577. }
  1578. public void Monitor()
  1579. {
  1580. }
  1581. public void Reset()
  1582. {
  1583. }
  1584. public void Terminate()
  1585. {
  1586. }
  1587. }
  1588. }