StandardHotReservoirDevice.cs 105 KB

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