StandardHotReservoirDevice.cs 103 KB

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