StandardHotReservoirDevice.cs 112 KB

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