StandardHotReservoirDevice.cs 107 KB

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