StandardHotReservoirDevice.cs 110 KB

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