StandardHotReservoirDevice.cs 113 KB

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