StandardHotReservoirDevice.cs 107 KB

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