StandardHotReservoirDevice.cs 104 KB

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