StandardHotReservoirDevice.cs 112 KB

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