123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112 |
- using Aitex.Core.RT.DataCenter;
- using Aitex.Core.RT.Device;
- using Aitex.Core.RT.Log;
- using Aitex.Core.RT.OperationCenter;
- using Aitex.Core.RT.RecipeCenter;
- using Aitex.Core.RT.SCCore;
- using Aitex.Core.Util;
- using MECF.Framework.Common.Beckhoff.ModuleIO;
- using MECF.Framework.Common.CommonData.Reservoir;
- using MECF.Framework.Common.Persistent.Reservoirs;
- using MECF.Framework.Common.RecipeCenter;
- using MECF.Framework.Common.ToolLayout;
- using MECF.Framework.Common.TwinCat;
- using CyberX8_Core;
- using CyberX8_RT.Devices.Facilities;
- using CyberX8_RT.Devices.Metal;
- using CyberX8_RT.Modules.Reservoir;
- using System;
- using System.Collections.Generic;
- using System.Reflection;
- using CyberX8_RT.Modules;
- using System.Collections.ObjectModel;
- using CyberX8_RT.Devices.Dose;
- using CyberX8_RT.Modules.Metal;
- using CyberX8_RT.Devices.Temperature;
- using CyberX8_RT.Devices.PowerSupplier;
- using System.Linq;
- using CyberX8_RT.Devices.Safety;
- using MECF.Framework.Common.ProcessCell;
- using MECF.Framework.Common.Alarm;
- using MECF.Framework.Common.IOCore;
- using Aitex.Core.RT.Routine;
- namespace CyberX8_RT.Devices.Reservoir
- {
- public class StandardHotReservoirDevice : BaseDevice, IDevice
- {
- private enum ReservoirOperation
- {
- None,
- ManualDiReplen,
- AutoDiReplen
- }
- private enum DosingOperation
- {
- None,
- ManualDosing,
- AutoDosing,
- }
- #region 常量
- private const string AUTO = "Auto";
- private const string MANUAL = "Manual";
- private const string DISABLE = "Disable";
- private const string STRATUS = "Stratus";
- private const string PERSISTENT_VALUE = "PersistentValue";
- private const string FLOW = "Flow";
- private const string HED_FLOW = "HedFlow";
- private const string PH_FLOW_VALVE = "PHFlowValve";
- private const string PH_VALUE = "PHValue";
- private const string WATER_LEVEL = "WaterLevel";
- private const string LOW_LEVEL = "LowLevel";
- private const string HIGH_LEVEL = "HighLevel";
- private const string SAFETY_HIGH_LEVEL = "SafetyHighLevel";
- private const string DI_REPLEN = "DiReplen";
- private const string RESERVOIRDEVICEDATA = "ReservoirDeviceData";
- private const string REPLEN_LEVEL = "ReplenLevel";
- private const string RESPOWERON = "ResPowerOn";
- private const string HEDPOWERON = "HedPowerOn";
- private const double PUMP_SPEED_CONVERT = 0.0672;
- private const int ENABLE = 5;
- #endregion
- #region 内部变量
- /// <summary>
- /// Level取样平均值
- /// </summary>
- private double _avgLevel;
- /// <summary>
- /// AN Level取样队列
- /// </summary>
- private Queue<double> _LevelSamples;
- /// <summary>
- /// Level计算平均值取样数
- /// </summary>
- private int levelSampleCount;
- /// <summary>
- /// Prewet 持久性数值对象
- /// </summary>
- private ReservoirsPersistentValue _persistentValue;
- /// <summary>
- /// 定时器Job
- /// </summary>
- PeriodicJob _periodicJob = null;
- /// <summary>
- /// 变量是否初始化字典
- /// </summary>
- private Dictionary<string, bool> _variableInitializeDic = new Dictionary<string, bool>();
- /// <summary>
- /// Reservoir数据
- /// </summary>
- private StandardHotReservoirData _reservoirData = new StandardHotReservoirData();
- /// <summary>
- /// 当前操作
- /// </summary>
- private ReservoirOperation _currentOperation = ReservoirOperation.None;
- /// <summary>
- /// 手动注水时间(秒)
- /// </summary>
- private int _manualReplenSecond = 0;
- /// <summary>
- /// 注水是否出错
- /// </summary>
- private bool _isDiReplenInFault = false;
- /// <summary>
- /// Recipe
- /// </summary>
- private ResRecipe _resRecipe;
- /// <summary>
- /// 平均PH值
- /// </summary>
- private double _avaragePH;
- /// <summary>
- /// PH Routine
- /// </summary>
- private StandardHotPHRoutine _phRoutine;
- /// <summary>
- /// PH Routine状态
- /// </summary>
- private RState _phState = RState.Init;
- /// <summary>
- /// PH结束时间
- /// </summary>
- private DateTime _phRoutineEndTime = DateTime.Now;
- /// <summary>
- /// Direplen 逻辑对象
- /// </summary>
- private ReservoirDiReplenHelper _direplenHelper;
- /// <summary>
- /// Replen数量
- /// </summary>
- private int _replenNum = 0;
- /// <summary>
- /// Dose Replen数据
- /// </summary>
- private ReplenData[] _replenDatas;
- /// <summary>
- /// ReplenType
- /// </summary>
- private string _replenType;
- /// <summary>
- /// Replen Recipe集合
- /// </summary>
- private RdsRecipe[] _rdsRecipe;
- /// <summary>
- /// DosingSystemHelper对象列表
- /// </summary>
- private List<DosingSystemHelper> _dosingSystemHelperLst;
- /// <summary>
- /// ReplenLevel 列表
- /// </summary>
- private List<bool> _replenLevelLst;
- /// <summary>
- /// 当前操作
- /// </summary>
- private List<DosingOperation> _currentDosingOperation;
- /// <summary>
- /// 配置的metal device集合
- /// </summary>
- private ObservableCollection<StandardHotMetalDevice> _metalDevices = new ObservableCollection<StandardHotMetalDevice>();
- /// <summary>
- /// Replen Persistent Value
- /// </summary>
- private Dictionary<string, ReplenPersistentValue> _replenPersistentValue = new Dictionary<string, ReplenPersistentValue>();
- /// <summary>
- /// DosingCommonHelper
- /// </summary>
- private DosingCommonHelper _dosingCommonHelper;
- /// <summary>
- /// WarningFlag
- /// </summary>
- private List<bool> _isCAFlowRateWARN;
- /// <summary>
- /// CMM Flow High Error
- /// </summary>
- private double _reservoirCMMFlowHighError;
- /// <summary>
- /// CMM Flow Low Error
- /// </summary>
- private double _reservoirCMMFlowLowError;
- /// <summary>
- /// ErrorMessage
- /// </summary>
- private bool _isTCControlWARN = false;
- private bool _isCMMPowerCurrentWARN = false;
- private bool _isCMMPowerFlowWARN = false;
- private bool _isExportCMMUsage = false;
- private bool _isAutoDIReplenError = false;
- private bool _isSafetyHigh = false;
- private bool _isSystemAutoMode = false;
- /// <summary>
- /// 用于控制打印错误log
- /// </summary>
- private HashSet<string> errorLogSet = new HashSet<string>();
- #endregion
- #region 属性
- /// <summary>
- /// 数据
- /// </summary>
- public StandardHotReservoirData ReservoirData { get { return _reservoirData; } }
- /// <summary>
- /// Replen数据
- /// </summary>
- public ReplenData[] ReplenDatas { get { return _replenDatas; } }
- /// <summary>
- /// DosingSystemHelper对象列表
- /// </summary>
- public List<DosingSystemHelper> DosingSystemHelpers { get { return _dosingSystemHelperLst; } }
- /// <summary>
- /// Replen数量
- /// </summary>
- public int ReplenNum { get { return _replenNum; } }
- /// <summary>
- /// 操作模式
- /// </summary>
- public string OperationMode { get { return _persistentValue.OperatingMode; } }
- /// <summary>
- /// 工程模式
- /// </summary>
- public string EngineerMode { get { return _persistentValue.RecipeOperatingMode; } }
- /// <summary>
- /// 是否自动
- /// </summary>
- public bool IsAuto { get { return _persistentValue.OperatingMode == AUTO; } }
- /// <summary>
- /// 是否需要补水
- /// </summary>
- public bool NeedAutoDireplen { get { return GetNeedAutoDireplen(); } }
- /// <summary>
- /// 正在补水
- /// </summary>
- public bool IsDireplenOn { get { return _reservoirData.DiReplen; } }
- /// <summary>
- /// 平均PH数值
- /// </summary>
- public double AveragePH { get { return _avaragePH; } set { _avaragePH = value; } }
- /// <summary>
- /// 当前Recipe
- /// </summary>
- public ResRecipe Recipe { get { return _resRecipe; } }
- /// <summary>
- /// 当前Rds Recipe
- /// </summary>
- public RdsRecipe[] RdsRecipe { get { return _rdsRecipe; } }
- #endregion
- /// <summary>
- /// 初始化成功清除对应的错误log
- /// </summary>
- /// <param name="module"></param>
- public void ClearErrorLogSet(string module)
- {
- // 使用构造函数复制 HashSet
- HashSet<string> newHashSet = new HashSet<string>(errorLogSet);
- foreach (var item in newHashSet)
- {
- if (item.Contains(module))
- {
- errorLogSet.Remove(item);
- }
- }
- }
- /// <summary>
- /// 构造函数
- /// </summary>
- /// <param name="moduleName"></param>
- /// <param name="name"></param>
- public StandardHotReservoirDevice(string moduleName) : base(moduleName, moduleName, moduleName, moduleName)
- {
- levelSampleCount = SC.GetValue<int>("Reservoir.LevelAvgSamples");
- levelSampleCount = levelSampleCount == 0 ? 20 : levelSampleCount;
- _LevelSamples = new Queue<double>(levelSampleCount);
- _periodicJob = new PeriodicJob(100, OnTimer, $"{Module}.OnTimer", true);
- ResPowerOn();//保持继电器常开
- }
- /// <summary>
- /// 定时器
- /// </summary>
- /// <returns></returns>
- private bool OnTimer()
- {
- //计算AN/CA level的平均值
- if (ReservoirData != null)
- {
- //AN
- if (_LevelSamples.Count >= levelSampleCount)
- {
- _LevelSamples.Dequeue();
- _LevelSamples.Enqueue(ReservoirData.Level);
- }
- else
- {
- _LevelSamples.Enqueue(ReservoirData.Level);
- }
- _avgLevel = _LevelSamples.Count > 0 ? _LevelSamples.Average() : 0;
- }
- foreach (StandardHotMetalDevice device in _metalDevices)
- {
- device.OnTimer(_periodicJob.Interval);
- }
- ReservoirEntity reservoirEntity = Singleton<RouteManager>.Instance.GetModule<ReservoirEntity>(Module);
- //报错停DosingSystem
- //if (_replenType != "" && _replenNum != 0 && reservoirEntity != null && reservoirEntity.IsError)
- //{
- // for (int i = 0; i < _replenNum; i++)
- // {
- // string replenName = "Replen" + (i + 1).ToString();
- // if (_replenPersistentValue[replenName].IsDosingRunning)
- // {
- // _dosingSystemHelperLst[i].StopDosing();
- // _currentDosingOperation[i] = DosingOperation.None;
- // }
- // }
- //}
- /// <summary>
- /// WaterLevelMonitor
- /// </summary>
- WaterLevelMonitor();
- //触发Safetyhigh将reservoir切成error
- SafetyDevice safetyDevice = DEVICE.GetDevice<SafetyDevice>("Safety");
- if (safetyDevice != null && safetyDevice.SafetyData.ReservoirHighLevel && !_isSafetyHigh)
- {
- _isSafetyHigh = true;
- LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"Safety high is Activate");
- reservoirEntity.PostMsg(ReservoirMsg.Error);
- }
- else
- {
- _isSafetyHigh = false;
- }
- //DIReplen
- if (_direplenHelper != null)
- {
- _direplenHelper.MonitorPeriodTime();
- if (_currentOperation == ReservoirOperation.ManualDiReplen && _reservoirData.DiReplen)
- {
- bool result = _direplenHelper.MonitorManualDiReplenComplete(_manualReplenSecond, DIReplenOff);
- if (result)
- {
- _currentOperation = ReservoirOperation.None;
- }
- }
- else if (_currentOperation == ReservoirOperation.AutoDiReplen && _reservoirData.DiReplen)
- {
- bool result = _direplenHelper.AutoDiReplenMonitorTimeOut(DIReplenOff);
- if (result)
- {
- _currentOperation = ReservoirOperation.None;
- //触发注水异常信号
- _isDiReplenInFault = true;
- }
- else
- {
- //按液位补水
- result = _direplenHelper.AutoDiReplenMonitorComplete(_reservoirData.Level, _resRecipe.ReservoirCALevel, _resRecipe.DIReplenEnable,
- _resRecipe.DIReplenTimeRate, _resRecipe.DIReplenCurrentRate, DIReplenOff);
- if (result)
- {
- _currentOperation = ReservoirOperation.None;
- }
- }
- }
- }
- if (reservoirEntity == null || !reservoirEntity.IsInitialized)
- {
- return true;
- }
- if (_persistentValue.OperatingMode == AUTO)
- {
- CAFlowRateCheck();
- TemperatureCheck();
- CMMPowerCheck();
- //CMM用电量记录
- if (_isExportCMMUsage && _persistentValue.CMMStartTime != DateTime.MinValue)
- {
- ReservoirItem reservoirItem = ReservoirItemManager.Instance.GetReservoirItem(Module);
- if (!string.IsNullOrEmpty(reservoirItem.CMMSupplyID) && _resRecipe != null && _resRecipe.CMMEnable)
- {
- CellPowerSupplier powerSupplier = DEVICE.GetDevice<CellPowerSupplier>(reservoirItem.CMMSupplyID);
- double cmmUsage = powerSupplier.PowerSupplierData.Current * DateTime.Now.Subtract(_persistentValue.CMMStartTime).TotalHours;
- ReservoirUsageManager.Instance.UpdateReservoirCMMUsage(Module, Math.Round(cmmUsage, 3));
- _persistentValue.CMMStartTime = DateTime.Now;
- ReservoirsPersistentManager.Instance.UpdatePersistentValue(Module);
- _isExportCMMUsage = false;
- }
- }
- }
- if (_phState == RState.Running)
- {
- _phState = _phRoutine.Monitor();
- if (_phState == RState.End)
- {
- _phRoutineEndTime = DateTime.Now;
- }
- }
- else if (_phState != RState.Init)
- {
- double phUpdatePeriod = SC.GetValue<double>("Reservoir.PHUpdatePeriod");
- if (DateTime.Now.Subtract(_phRoutineEndTime).TotalMilliseconds >= phUpdatePeriod * 1000)
- {
- StartDetectPHValve();
- }
- }
- //if (_replenType != "" && _replenNum != 0)
- //{
- // //DosingSystem 状态监控
- // _dosingCommonHelper.DoseStatusMonitor();
- // //Dosing监控
- // if (_dosingCommonHelper.IsDosingSystemInitialized)
- // {
- // if (_replenPersistentValue["Replen1"].OperatingMode == "Manual")
- // {
- // //ManualDosing
- // _dosingCommonHelper.ManualDoseSystemMonitor();
- // }
- // if (_replenPersistentValue["Replen1"].OperatingMode == "Auto")
- // {
- // //AutoDosing
- // _dosingCommonHelper.AutoDoseSystemMonitor();
- // }
- // else
- // {
- // _dosingCommonHelper.CheckDoseOperation();
- // }
- // }
- //}
- return true;
- }
- /// <summary>
- /// Low Level 触发操作
- /// </summary>
- private void LowLevelOperation()
- {
- if (!_reservoirData.LowLevel) //true是正常的
- {
- ReservoirItem reservoirItem = ReservoirItemManager.Instance.GetReservoirItem(Module);
- foreach (var metalDevice in _metalDevices)
- {
- if (metalDevice.MetalDeviceData.Circulation)
- {
- metalDevice.SwitchToBypass($"{metalDevice.Name}.SwitchToBypass", null);
- }
- if (metalDevice.MetalDeviceData.CellFlow > 0)
- {
- metalDevice.ClosePump("", null);
- }
- //水位过低时将起对应的metal也要切成error
- MetalEntity metalEntity = Singleton<RouteManager>.Instance.GetModule<MetalEntity>(metalDevice.DeviceID);
- if (metalEntity != null && !metalEntity.IsError)
- {
- metalEntity.PostMsg(MetalMsg.Error);
- }
- }
- //禁用TC
- if (!String.IsNullOrEmpty(reservoirItem.TCID))
- {
- TemperatureController temperatureController = DEVICE.GetDevice<TemperatureController>(reservoirItem.TCID);
- if (temperatureController != null && temperatureController.TemperatureData.ControlOperationModel == 5)
- {
- LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"Lowlevel was activate");
- temperatureController.DisableOperation("", null);
- }
- }
- }
- }
- /// <summary>
- /// High Level 触发操作
- /// </summary>
- private void HighLevelOperation()
- {
- SystemFacilities systemFacilities = DEVICE.GetDevice<SystemFacilities>("System.Facilities");
- if (systemFacilities != null)
- {
- if (systemFacilities.DIFillEnable) systemFacilities.DiFillDisableOperation("DIFillDisableOpeartion", null);
- if (systemFacilities.DIReplenEnable) systemFacilities.DiReplenDisableOperation("DiReplenDisableOperation", null);
- if (ReservoirData.DiReplen)
- {
- _currentOperation = ReservoirOperation.None;
- DIReplenOff("", null);
- }
- }
- }
- /// <summary>
- /// WaterLevelMonitor
- /// </summary>
- private void WaterLevelMonitor()
- {
- ReservoirEntity reservoirEntity = Singleton<RouteManager>.Instance.GetModule<ReservoirEntity>(Module);
- _isSystemAutoMode = reservoirEntity.IsAuto;
- //触发水位过高或者过低将reservoir切成error
- if (!_reservoirData.LowLevel)
- {
- if (!errorLogSet.Contains($"{Module}.WaterLevel"))
- {
- errorLogSet.Add($"{Module}.WaterLevel");
- LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"WaterLevel low is Activate");
- }
- LowLevelOperation();
- if (!reservoirEntity.IsError)
- {
- reservoirEntity.PostMsg(ReservoirMsg.Error);
- }
- if (_isSystemAutoMode && !AlarmListManager.Instance.IsContainDataError(Module, "WaterLevel"))
- {
- AlarmListManager.Instance.AddDataError(Module,
- $"WaterLevel", $"WaterLevel low is Activate");
- }
- }
- else if (ReservoirData.WaterLevel > SC.GetValue<double>($"Reservoir.{Module}.HighLevel"))
- {
- if (!errorLogSet.Contains($"{Module}.WaterLevel"))
- {
- errorLogSet.Add($"{Module}.WaterLevel");
- LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"WaterLevel:{ReservoirData.WaterLevel} is larger than HighLevel Config:{SC.GetValue<double>($"Reservoir.{Module}.HighLevel")}");
- }
- HighLevelOperation();
- if (!reservoirEntity.IsError)
- {
- reservoirEntity.PostMsg(ReservoirMsg.Error);
- }
- if (_isSystemAutoMode && !AlarmListManager.Instance.IsContainDataError(Module, "WaterLevel"))
- {
- AlarmListManager.Instance.AddDataError(Module,
- $"WaterLevel", $"WaterLevel:{ReservoirData.WaterLevel} is larger than HighLevel Config:{SC.GetValue<double>($"Reservoir.{Module}.HighLevel")}");
- }
- }
- //水位触发reservoir里面的high/low将对应的reservoir切成error
- if (_resRecipe == null) return;
- if (ReservoirData.Level < _resRecipe.CALevelErrorLow)
- {
- if (!errorLogSet.Contains($"{Module}.Level"))
- {
- errorLogSet.Add($"{Module}.Level");
- LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"Current level:{ReservoirData.Level} is lower than recipe's CA Errorlow paramater:{_resRecipe.CALevelErrorLow}");
- }
- if (!reservoirEntity.IsError)
- {
- reservoirEntity.PostMsg(ReservoirMsg.Error);
- }
- if (_isSystemAutoMode && !AlarmListManager.Instance.IsContainDataError(Module, "Level"))
- {
- AlarmListManager.Instance.AddDataError(Module,
- $"Level", $"Current level:{ReservoirData.Level} is lower than recipe's CA Errorlow paramater:{_resRecipe.CALevelErrorLow}");
- }
- }
- else if (ReservoirData.Level > _resRecipe.CALevelErrorHigh)
- {
- if (!errorLogSet.Contains($"{Module}.Level"))
- {
- errorLogSet.Add($"{Module}.Level");
- LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"Current level:{ReservoirData.Level} is larger than recipe's CA ErrorHigh paramater:{_resRecipe.CALevelErrorHigh}");
- }
- if (!reservoirEntity.IsError)
- {
- reservoirEntity.PostMsg(ReservoirMsg.Error);
- }
- if (_isSystemAutoMode && !AlarmListManager.Instance.IsContainDataError(Module, "Level"))
- {
- AlarmListManager.Instance.AddDataError(Module,
- $"Level", $"Current level:{ReservoirData.Level} is larger than recipe CA ErrorHigh paramater:{_resRecipe.CALevelErrorHigh}");
- }
- }
- }
- /// <summary>
- /// 获取是否需要补水
- /// </summary>
- /// <returns></returns>
- private bool GetNeedAutoDireplen()
- {
- if (IsAuto && _resRecipe != null)
- {
- if (_resRecipe.DIReplenEnable && _resRecipe.DIReplenCurrentRate == 0 && _resRecipe.DIReplenTimeRate == 0)
- {
- double levelHysteresis = SC.GetValue<double>("Reservoir.LevelHysteresis");
- return ReservoirData.Level < _resRecipe.ReservoirCALevel - levelHysteresis;
- }
- return false;
- }
- else
- {
- return false;
- }
- }
- /// <summary>
- /// 初始化
- /// </summary>
- /// <returns></returns>
- public bool Initialize()
- {
- InitializeRoutine();
- InitializeParameter();
- SubscribeData();
- InitializeOperation();
- SubscribeValueAction();
- return true;
- }
- /// <summary>
- /// 初始化routine
- /// </summary>
- private void InitializeRoutine()
- {
- _phRoutine = new StandardHotPHRoutine(Module);
- }
- /// <summary>
- /// 初始化参数
- /// </summary>
- private void InitializeParameter()
- {
- _persistentValue = ReservoirsPersistentManager.Instance.GetReservoirsPersistentValue(Module.ToString());
- if (_persistentValue == null)
- {
- LOG.WriteLog(eEvent.ERR_RESERVOIR, Module.ToString(), "Persistent Value Object is not exist");
- }
- else
- {
- if (!string.IsNullOrEmpty(_persistentValue.Recipe))
- {
- _resRecipe = RecipeFileManager.Instance.LoadGenericityRecipe<ResRecipe>(_persistentValue.Recipe);
- }
- _direplenHelper = new ReservoirDiReplenHelper(Module, _persistentValue);
- }
- ReservoirItem reservoirItem = ReservoirItemManager.Instance.GetReservoirItem(Module.ToString());
- if (reservoirItem != null)
- {
- foreach (var item in reservoirItem.MetalCells)
- {
- if (item.ModuleName != Module)
- {
- StandardHotMetalDevice metalDevice = DEVICE.GetDevice<StandardHotMetalDevice>(item.ModuleName);
- if (metalDevice != null)
- {
- _metalDevices.Add(metalDevice);
- }
- }
- }
- }
- _isCAFlowRateWARN = new List<bool>(new bool[_metalDevices.Count]);
- //DosingSystem数据初始化
- _replenType = reservoirItem.ChemReplenType;
- _replenNum = reservoirItem.ChemReplenPumps;
- if (_replenType != "" && _replenNum != 0)
- {
- _replenDatas = new ReplenData[_replenNum];
- _rdsRecipe = new RdsRecipe[_replenNum];
- _replenLevelLst = new List<bool>(new bool[_replenNum]);
- _currentDosingOperation = new List<DosingOperation>();
- for (int i = 0; i < _replenNum; i++)
- {
- string replenName = "Replen" + (i + 1).ToString();
- _replenDatas[i] = new ReplenData();
- _replenDatas[i].ReplenName = replenName;
- _replenDatas[i].RecipeName = "";
- _replenDatas[i].BottleLevel = DosingSystemHelper.BottleLevelState.Empty.ToString();
- _replenDatas[i].IsAutoDosingError = false;
- if (_dosingSystemHelperLst == null) _dosingSystemHelperLst = new List<DosingSystemHelper>();
- _dosingSystemHelperLst.Add(new DosingSystemHelper(Module, _replenDatas[i].ReplenName));
- _currentDosingOperation.Add(DosingOperation.None);
- _replenPersistentValue[replenName] = ReplenPersistentManager.Instance.GetReplenPersistentValue(Module, replenName);
- }
- _dosingCommonHelper = new DosingCommonHelper(Module, _replenNum);
- }
- }
- /// <summary>
- /// 订阅数据
- /// </summary>
- private void SubscribeData()
- {
- DATA.Subscribe($"{Module}.DIValveMaxOnTime", () => SC.GetValue<double>($"Reservoir.{Module}.DIValveMaxOnTime") * 60, SubscriptionAttribute.FLAG.IgnoreSaveDB);
- DATA.Subscribe($"{Module}.IsManualReplen", () => { return _currentOperation == ReservoirOperation.ManualDiReplen; }, SubscriptionAttribute.FLAG.IgnoreSaveDB);
- DATA.Subscribe($"{Module}.ReservoirData", () => _reservoirData, SubscriptionAttribute.FLAG.IgnoreSaveDB);
- DATA.Subscribe($"{Module}.ReservoirAverageLevel", () => _avgLevel, SubscriptionAttribute.FLAG.IgnoreSaveDB);
- DATA.Subscribe($"{Module}.{PERSISTENT_VALUE}", () => _persistentValue, SubscriptionAttribute.FLAG.IgnoreSaveDB);
- DATA.Subscribe($"{Module}.ReplenPersistentValue", () => _replenPersistentValue, SubscriptionAttribute.FLAG.IgnoreSaveDB);
- DATA.Subscribe($"{Module}.PHValue", () => _avaragePH, SubscriptionAttribute.FLAG.IgnoreSaveDB);
- DATA.Subscribe($"{Module}.CurrentRecipe", () => _resRecipe, SubscriptionAttribute.FLAG.IgnoreSaveDB);
- DATA.Subscribe($"{Module}.ReplenType", () => _replenType, SubscriptionAttribute.FLAG.IgnoreSaveDB);
- DATA.Subscribe($"{Module}.ReplenNum", () => _replenNum, SubscriptionAttribute.FLAG.IgnoreSaveDB);
- DATA.Subscribe($"{Module}.ReplenDatas", () => _replenDatas, SubscriptionAttribute.FLAG.IgnoreSaveDB);
- DATA.Subscribe($"{Module}.DosingSystemState", () => _dosingCommonHelper != null ? _dosingCommonHelper.DosingSystemState : null, SubscriptionAttribute.FLAG.IgnoreSaveDB);
- DATA.Subscribe($"{Module}.RecipeName", () => (_resRecipe != null ? _resRecipe.Ppid : ""), SubscriptionAttribute.FLAG.IgnoreSaveDB);
- DATA.Subscribe($"{Module}.HedFlow", () => _reservoirData.HedFlow, SubscriptionAttribute.FLAG.IgnoreSaveDB);
- DATA.Subscribe($"{Module}.PHEnable", () => _reservoirData.PHFlowValve, SubscriptionAttribute.FLAG.IgnoreSaveDB);
- DATA.Subscribe($"{Module}.IsDIReplenInFault", () => _isDiReplenInFault, SubscriptionAttribute.FLAG.IgnoreSaveDB);
- DATA.Subscribe($"{Module}.ReservoirPowerOn", () => _reservoirData.ResPowerOn, SubscriptionAttribute.FLAG.IgnoreSaveDB);
- DATA.Subscribe($"{Module}.HedPowerOn", () => _reservoirData.HedPowerOn, SubscriptionAttribute.FLAG.IgnoreSaveDB);
- }
- /// <summary>
- /// 初始化操作
- /// </summary>
- private void InitializeOperation()
- {
- OP.Subscribe($"{Module}.DisabledAction", DisabledOperation);
- OP.Subscribe($"{Module}.ManualAction", ManualOperation);
- OP.Subscribe($"{Module}.AutoAction", AutoOperation);
- OP.Subscribe($"{Module}.EngineeringModeAction", EngineeringModeOperation);
- OP.Subscribe($"{Module}.ProductionModeAction", ProductionModeOperation);
- OP.Subscribe($"{Module}.DiReplenOn", DIReplenOnOperation);
- OP.Subscribe($"{Module}.DiReplenOff", DIReplenOff);
- OP.Subscribe($"{Module}.ManualDiReplen", ManualDiReplen);
- OP.Subscribe($"{Module}.ResetTotalTime", ResetTotalTime);
- OP.Subscribe($"{Module}.LoadRecipe", LoadRecipeOperation);
- OP.Subscribe($"{Module}.LoadDosingRecipe", LoadDosingRecipeOperation);
- OP.Subscribe($"{Module}.ReplenPumpOn", ReplenPumpOnOperation);
- OP.Subscribe($"{Module}.ReplenPumpOff", ReplenPumpOffOperation);
- OP.Subscribe($"{Module}.SetPumpFactor", SetPumpFactor);
- OP.Subscribe($"{Module}.ManualDosing", ManualDosing);
- OP.Subscribe($"{Module}.StopManualDosing", StopManualDosing);
- OP.Subscribe($"{Module}.ResetBottleVolume", ResetBottleVolume);
- OP.Subscribe($"{Module}.DosingInitialize", DosingInitialize);
-
- OP.Subscribe($"{Module}.HedPowerOn", HedPowerOnAction);
- OP.Subscribe($"{Module}.HedPowerOff", HedPowerOffAction);
- OP.Subscribe($"{Module}.ResPowerOn", ResPowerOnAction);
- OP.Subscribe($"{Module}.ResPowerOff", ResPowerOffAction);
- }
- private bool HedPowerOnAction(string cmd, object[] args)
- {
- string ioName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{HEDPOWERON}");
- if (!string.IsNullOrEmpty(ioName))
- {
- bool result = IOModuleManager.Instance.WriteIoValue(ioName, true);
- if (!result)
- {
- LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"Open HED Power Relay failed");
- return false;
- }
- return true;
- }
- else
- {
- return true;
- }
- }
- private bool HedPowerOffAction(string cmd, object[] args)
- {
- string ioName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{HEDPOWERON}");
- if (!string.IsNullOrEmpty(ioName))
- {
- bool result = IOModuleManager.Instance.WriteIoValue(ioName, false);
- if (!result)
- {
- LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"Close HED Power Relay failed");
- return false;
- }
- return true;
- }
- else
- {
- return true;
- }
- }
- private bool ResPowerOnAction(string cmd, object[] args)
- {
- string ioName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{RESPOWERON}");
- if (!string.IsNullOrEmpty(ioName))
- {
- bool result = IOModuleManager.Instance.WriteIoValue(ioName, true);
- if (!result)
- {
- LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"Open Res Power Relay failed");
- return false;
- }
- return true;
- }
- else
- {
- return true;
- }
- }
- private bool ResPowerOffAction(string cmd, object[] args)
- {
- string ioName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{RESPOWERON}");
- if (!string.IsNullOrEmpty(ioName))
- {
- bool result = IOModuleManager.Instance.WriteIoValue(ioName, false);
- if (!result)
- {
- LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"Close Res Power Relay failed");
- return false;
- }
- return true;
- }
- else
- {
- return true;
- }
- }
- #region Operation
- /// <summary>
- /// 重置时长
- /// </summary>
- /// <param name="cmd"></param>
- /// <param name="objs"></param>
- /// <returns></returns>
- private bool ResetTotalTime(string cmd, object[] objs)
- {
- _persistentValue.TotalReplen = 0;
- _persistentValue.LastTotalReplen = 0;
- ReservoirsPersistentManager.Instance.UpdatePersistentValue(Module);
- return true;
- }
- /// <summary>
- /// DisabledAction
- /// </summary>
- /// <param name="cmd"></param>
- /// <param name="param"></param>
- /// <returns></returns>
- private bool DisabledOperation(string cmd, object[] args)
- {
- string currentOperation = "Disabled";
- if (args.Length >= 1 && (bool)args[0])
- {
- foreach (var replenData in ReplenDatas)
- {
- if (_replenPersistentValue != null && _replenPersistentValue[replenData.ReplenName] != null)
- {
- _replenPersistentValue[replenData.ReplenName].OperatingMode = currentOperation;
- ReplenPersistentManager.Instance.UpdatePersistentValue(Module, replenData.ReplenName);
- }
- }
- for (int i = 0; i < _replenNum; i++)
- {
- string replenName = "Replen" + (i + 1).ToString();
- if (_replenPersistentValue[replenName].IsDosingRunning)
- {
- _dosingSystemHelperLst[i].StopDosing();
- _currentDosingOperation[i] = DosingOperation.None;
- }
- }
- DosingEnterInit();
- }
- else
- {
- ReservoirEntity reservoirEntity = Singleton<RouteManager>.Instance.GetModule<ReservoirEntity>(Module);
- if (_persistentValue != null && reservoirEntity != null && _persistentValue.OperatingMode != currentOperation)
- {
- string preOperation = _persistentValue.OperatingMode;
- if (reservoirEntity.IsBusy)
- {
- LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"{Module} is Busy, can't switch to Disabled mode");
- return false;
- }
- if (_persistentValue.OperatingMode == "Auto" && reservoirEntity.IsMetalBusy)
- {
- string busymodule = "";
- if (_metalDevices != null)
- {
- foreach (var item in _metalDevices)
- {
- MetalEntity metalEntity = Singleton<RouteManager>.Instance.GetModule<MetalEntity>(item.Module.ToString());
- if (metalEntity != null && metalEntity.IsBusy)
- {
- busymodule += metalEntity.Module.ToString() + "/";
- }
- }
- }
- LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"{busymodule} is Busy, can't switch to Disabled mode");
- return false;
- }
- foreach (var metalDevice in _metalDevices)
- {
- metalDevice.DisabledOperation("", null);
- MetalEntity metalEntity = Singleton<RouteManager>.Instance.GetModule<MetalEntity>(metalDevice.Module);
- metalEntity.AbortRecipe(null);
- metalDevice.EnterDisabledOperation();
- }
- EnterDisabledOperation();
- reservoirEntity.EnterInit();
- _persistentValue.OperatingMode = currentOperation;
- LOG.WriteLog(eEvent.INFO_RESERVOIR, Module, $"Operating mode is switched from {preOperation} to {currentOperation}");
- }
- ReservoirsPersistentManager.Instance.UpdatePersistentValue(Module);
- _currentOperation = ReservoirOperation.None;
- }
- return true;
- }
- /// <summary>
- /// ManualAction
- /// </summary>
- /// <param name="cmd"></param>
- /// <param name="param"></param>
- /// <returns></returns>
- private bool ManualOperation(string cmd, object[] args)
- {
- string currentOperation = "Manual";
- if (args.Length >= 1 && (bool)args[0])
- {
- foreach (var replenData in ReplenDatas)
- {
- if (_replenPersistentValue != null && _replenPersistentValue[replenData.ReplenName] != null)
- {
- _replenPersistentValue[replenData.ReplenName].OperatingMode = currentOperation;
- ReplenPersistentManager.Instance.UpdatePersistentValue(Module, replenData.ReplenName);
- }
- }
- DosingEnterInit();
- }
- else
- {
- ReservoirEntity reservoirEntity = Singleton<RouteManager>.Instance.GetModule<ReservoirEntity>(Module);
- if (_persistentValue != null && reservoirEntity != null && _persistentValue.OperatingMode != currentOperation)
- {
- string preOperation = _persistentValue.OperatingMode;
- if (reservoirEntity.IsBusy)
- {
- LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"{Module} is Busy, can't switch to Manual mode");
- return false;
- }
- if (_persistentValue.OperatingMode == "Auto" && reservoirEntity.IsMetalBusy)
- {
- string busymodule = "";
- if (_metalDevices != null)
- {
- foreach (var item in _metalDevices)
- {
- MetalEntity metalEntity = Singleton<RouteManager>.Instance.GetModule<MetalEntity>(item.Module.ToString());
- if (metalEntity != null && metalEntity.IsBusy)
- {
- busymodule += metalEntity.Module.ToString() + "/";
- }
- }
- }
- LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"{busymodule} is Busy, can't switch to Manual mode");
- return false;
- }
- foreach (var metalDevice in _metalDevices)
- {
- metalDevice.ManualOperation("", null);
- }
- reservoirEntity.EnterInit();
- if (_reservoirData.DiReplen) DIReplenOff("", null);
- _persistentValue.OperatingMode = currentOperation;
- LOG.WriteLog(eEvent.INFO_RESERVOIR, Module, $"Operating mode is switched from {preOperation} to {currentOperation}");
- }
- ReservoirsPersistentManager.Instance.UpdatePersistentValue(Module);
- _currentOperation = ReservoirOperation.None;
- }
- return true;
- }
- /// <summary>
- /// AutoAction
- /// </summary>
- /// <param name="cmd"></param>
- /// <param name="param"></param>
- /// <returns></returns>
- private bool AutoOperation(string cmd, object[] args)
- {
- if (!_reservoirData.LowLevel)
- {
- LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"Lowlevel was activated, can't switch to Auto mode");
- return false;
- }
- string currentOperation = "Auto";
- if (args.Length >= 1 && (bool)args[0])
- {
- foreach (var replenData in ReplenDatas)
- {
- if (_replenPersistentValue != null && _replenPersistentValue[replenData.ReplenName] != null)
- {
- _replenPersistentValue[replenData.ReplenName].OperatingMode = currentOperation;
- ReplenPersistentManager.Instance.UpdatePersistentValue(Module, replenData.ReplenName);
- }
- }
- DosingEnterInit();
- }
- else
- {
- ReservoirEntity reservoirEntity = Singleton<RouteManager>.Instance.GetModule<ReservoirEntity>(Module);
- if (_persistentValue != null && reservoirEntity != null && _persistentValue.OperatingMode != currentOperation)
- {
- string preOperation = _persistentValue.OperatingMode;
- if (reservoirEntity.IsBusy)
- {
- LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"{Module} is Busy, can't switch to Auto mode");
- return false;
- }
- reservoirEntity.EnterInit();
- _persistentValue.OperatingMode = currentOperation;
- if (_reservoirData.DiReplen) DIReplenOff("", null);
- _isDiReplenInFault = false;
- LOG.WriteLog(eEvent.INFO_RESERVOIR, Module, $"Operating mode is switched from {preOperation} to {currentOperation}");
- }
- ReservoirsPersistentManager.Instance.UpdatePersistentValue(Module);
- }
- return true;
- }
- /// <summary>
- /// EngineeringModeAction
- /// </summary>
- /// <param name="cmd"></param>
- /// <param name="param"></param>
- /// <returns></returns>
- private bool EngineeringModeOperation(string cmd, object[] args)
- {
- string currentRecipeOperation = "Engineering";
- if (_persistentValue != null)
- {
- _persistentValue.RecipeOperatingMode = currentRecipeOperation;
- }
- ReservoirsPersistentManager.Instance.UpdatePersistentValue(Module);
- return true;
- }
- /// <summary>
- /// ProductionAction
- /// </summary>
- /// <param name="cmd"></param>
- /// <param name="param"></param>
- /// <returns></returns>
- private bool ProductionModeOperation(string cmd, object[] args)
- {
- string currentRecipeOperation = "Production";
- if (_persistentValue != null)
- {
- _persistentValue.RecipeOperatingMode = currentRecipeOperation;
- }
- ReservoirsPersistentManager.Instance.UpdatePersistentValue(Module);
- return true;
- }
- /// <summary>
- /// 加载Recipe
- /// </summary>
- /// <param name="cmd"></param>
- /// <param name="args"></param>
- /// <returns></returns>
- private bool LoadRecipeOperation(string cmd, object[] args)
- {
- _persistentValue.Recipe = args[0].ToString();
- string[] fileRoute = _persistentValue.Recipe.Split('\\');
- string recipeRoute = "";
- if (fileRoute.Length > 2)
- {
- recipeRoute = fileRoute[fileRoute.Length - 2];
- }
- try
- {
- _resRecipe = RecipeFileManager.Instance.LoadGenericityRecipe<ResRecipe>(_persistentValue.Recipe);
- ReservoirsPersistentManager.Instance.UpdatePersistentValue(Module.ToString());
- LOG.WriteLog(eEvent.INFO_RESERVOIR, Module, $"Load {recipeRoute} Recipe {_resRecipe.Ppid} Success");
- }
- catch
- {
- LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"Load {recipeRoute} Recipe {_persistentValue.Recipe} failed");
- }
- return true;
- }
- /// <summary>
- /// DiReplen On
- /// </summary>
- /// <param name="cmd"></param>
- /// <param name="args"></param>
- /// <returns></returns>
- public bool DIReplenOnOperation(string cmd, object[] args)
- {
- return DIReplenOn(true);
- }
- /// <summary>
- /// 自动注水
- /// </summary>
- /// <returns></returns>
- public bool DIReplenOn(bool showError)
- {
- if (ReservoirData.WaterLevel > SC.GetValue<double>($"Reservoir.{Module}.HighLevel"))
- {
- LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, "Highlevel is activate");
- return false;
- }
- if (!_reservoirData.LowLevel) //信号是相反的
- {
- LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"WaterLevel low is Activate");
- return false;
- }
- bool preCondition = CheckPreDiReplenCondition(showError);
- if (!preCondition)
- {
- return false;
- }
- string ioName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{DI_REPLEN}");
- bool result = IOModuleManager.Instance.WriteIoValue(ioName, true);
- if (result)
- {
- _persistentValue.IsDiReplenOn = true;
- }
- return result;
- }
- /// <summary>
- /// 打开继电器
- /// </summary>
- /// <returns></returns>
- public void ResPowerOn()
- {
- bool result = false;
- string ioName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{RESPOWERON}");
- if (!string.IsNullOrEmpty(ioName))
- {
- result = IOModuleManager.Instance.WriteIoValue(ioName, true);
- if (!result)
- {
- LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"Open {Module} Power Relay failed");
- }
- }
- ioName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{HEDPOWERON}");
- if (!string.IsNullOrEmpty(ioName))
- {
- result = IOModuleManager.Instance.WriteIoValue(ioName, true);
- if (!result)
- {
- LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"Open {Module} Hed Power Relay failed");
- }
- }
- }
- /// <summary>
- /// 检验DiReplen前置条件
- /// </summary>
- /// <returns></returns>
- public bool CheckPreDiReplenCondition(bool showError)
- {
- if (!CheckFacilitiesDiReplenStatus() && showError)
- {
- LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, "Facilities DiReplen is Off");
- return false;
- }
- SafetyDevice safetyDevice = DEVICE.GetDevice<SafetyDevice>("Safety");
- if (safetyDevice != null && safetyDevice.SafetyData.ReservoirHighLevel)
- {
- LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"Safety high is Activate");
- return false;
- }
- if (CheckOtherReservoirDiReplenStatus(showError))
- {
- return false;
- }
- return true;
- }
- /// <summary>
- /// 检验总Di有没有开
- /// </summary>
- /// <returns></returns>
- private bool CheckFacilitiesDiReplenStatus()
- {
- SystemFacilities systemFacilities = DEVICE.GetDevice<SystemFacilities>("System.Facilities");
- if (systemFacilities != null)
- {
- return systemFacilities.DIReplenEnable;
- }
- return false;
- }
- /// <summary>
- /// 检验是否其他Reservoir Direplen已经
- /// </summary>
- /// <returns></returns>
- private bool CheckOtherReservoirDiReplenStatus(bool showError)
- {
- List<string> reservoirs = ReservoirItemManager.Instance.InstalledModules;
- foreach (string item in reservoirs)
- {
- if (item != Module)
- {
- ReservoirItem reservoirItem = ReservoirItemManager.Instance.GetReservoirItem(item);
- if (reservoirItem.SubType == STRATUS)
- {
- StandardHotReservoirDevice tmpDevice = DEVICE.GetDevice<StandardHotReservoirDevice>(item);
- if (tmpDevice.ReservoirData.DiReplen && showError)
- {
- LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"{item} direplen valve is on");
- return true;
- }
- }
- else
- {
- CompactMembranReservoirDevice tmpDevice = DEVICE.GetDevice<CompactMembranReservoirDevice>(item);
- if (tmpDevice.ReservoirData.ANDiReplen && showError)
- {
- LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"{item} ANDireplen valve is on");
- return true;
- }
- if (tmpDevice.ReservoirData.CADiReplen && showError)
- {
- LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"{item} CADireplen valve is on");
- return true;
- }
- }
- }
- }
- return false;
- }
- /// <summary>
- /// DiReplen Off
- /// </summary>
- /// <param name="cmd"></param>
- /// <param name="args"></param>
- /// <returns></returns>
- private bool DIReplenOff(string cmd, object[] args)
- {
- string ioName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{DI_REPLEN}");
- bool result = IOModuleManager.Instance.WriteIoValue(ioName, false);
- if (result)
- {
- _persistentValue.IsDiReplenOn = false;
- if (_currentOperation == ReservoirOperation.ManualDiReplen || _currentOperation == ReservoirOperation.AutoDiReplen)
- {
- _currentOperation = ReservoirOperation.None;
- _persistentValue.LastTotalReplen = _persistentValue.TotalReplen;
- ReservoirsPersistentManager.Instance.UpdatePersistentValue(Module);
- }
- }
- return result;
- }
- /// <summary>
- /// 手动注水
- /// </summary>
- /// <param name="cmd"></param>
- /// <param name="args"></param>
- /// <returns></returns>
- private bool ManualDiReplen(string cmd, object[] args)
- {
- if (_currentOperation != ReservoirOperation.None)
- {
- LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"current operation is {_currentOperation},cannot execute ManualDireplen operation");
- return false;
- }
- bool result = DIReplenOnOperation("", null);
- if (result)
- {
- _currentOperation = ReservoirOperation.ManualDiReplen;
- _persistentValue.DiReplenTime = DateTime.Now;
- ReservoirsPersistentManager.Instance.UpdatePersistentValue(Module);
- int.TryParse(args[0].ToString(), out _manualReplenSecond);
- }
- return result;
- }
- /// <summary>
- /// 自动注水
- /// </summary>
- /// <returns></returns>
- public bool AutoDireplen()
- {
- if (!_reservoirData.LowLevel && !_isAutoDIReplenError)
- {
- _isAutoDIReplenError = true;
- LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"LowLevel is activate,Can't AutoDireplen");
- return false;
- }
- else
- {
- _isAutoDIReplenError = false;
- }
- if (_currentOperation != ReservoirOperation.None)
- {
- return false;
- }
- if (_resRecipe == null)
- {
- return false;
- }
- bool result = DIReplenOn(false);
- if (result)
- {
- _currentOperation = ReservoirOperation.AutoDiReplen;
- _persistentValue.DiReplenTime = DateTime.Now;
- }
- return result;
- }
- /// <summary>
- /// 启动PH检测
- /// </summary>
- public bool StartDetectPHValve()
- {
- if (_persistentValue.OperatingMode == MANUAL)
- {
- return false;
- }
- _phState = _phRoutine.Start();
- LOG.WriteLog(eEvent.INFO_RESERVOIR, Module, "Start Detect PH");
- return true;
- }
- /// <summary>
- /// 打开PH Valve
- /// </summary>
- /// <returns></returns>
- public bool PHValveOn()
- {
- string ioName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{PH_FLOW_VALVE}");
- return IOModuleManager.Instance.WriteIoValue(ioName, true);
- }
- /// <summary>
- /// 关闭PH Valve
- /// </summary>
- /// <returns></returns>
- public bool PHValveOff()
- {
- string ioName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{PH_FLOW_VALVE}");
- return IOModuleManager.Instance.WriteIoValue(ioName, false);
- }
- /// <summary>
- /// CAFlowRateCheck
- /// </summary>
- private void CAFlowRateCheck()
- {
- if (_resRecipe == null) return;
- for (int i = 0; i < _metalDevices.Count; i++)
- {
- StandardHotMetalDevice hotMetalDevice = _metalDevices[i];
- if (hotMetalDevice != null && !hotMetalDevice.IsDisable && hotMetalDevice.IsAuto)
- {
- if (hotMetalDevice.MetalDeviceData == null || !hotMetalDevice.MetalDeviceData.Circulation) continue;
- if (!hotMetalDevice.FlowValveStable) continue;
- MetalEntity metalEntity = Singleton<RouteManager>.Instance.GetModule<MetalEntity>(hotMetalDevice.Name);
- double cellFlow = hotMetalDevice.MetalDeviceData.CellFlow;
- if (cellFlow < _resRecipe.CAFlowRateErrorLow)
- {
- if (!metalEntity.IsError)
- {
- LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"cell {hotMetalDevice.Name} cellflow:{cellFlow} is less than recipe's CAFlowRateErrorLow parameter:{_resRecipe.CAFlowRateErrorLow}");
- metalEntity.PostMsg(MetalMsg.Error);
- }
- }
- else if (cellFlow < _resRecipe.CAFlowRateWarningLow)
- {
- if (!_isCAFlowRateWARN[i])
- {
- LOG.WriteLog(eEvent.WARN_RESERVOIR, Module, $"cell {hotMetalDevice.Name} cellflow:{cellFlow} is less than recipe's CAFlowRateWarningLow parameter:{_resRecipe.CAFlowRateWarningLow}");
- _isCAFlowRateWARN[i] = true;
- }
- }
- else
- {
- _isCAFlowRateWARN[i] = false;
- }
- }
- }
- }
- /// <summary>
- /// Temperature Check
- /// </summary>
- private void TemperatureCheck()
- {
- ReservoirEntity reservoirEntity = Singleton<RouteManager>.Instance.GetModule<ReservoirEntity>(Module);
- ReservoirItem reservoirItem = ReservoirItemManager.Instance.GetReservoirItem(Module);
- TemperatureController temperatureController = DEVICE.GetDevice<TemperatureController>(reservoirItem.TCID);
- if (temperatureController == null || temperatureController.TemperatureData == null || _resRecipe == null
- || temperatureController.TemperatureData.ControlOperationModel != ENABLE) return;
- double tempValue = temperatureController.TemperatureData.ReserviorTemperature;
- if (tempValue > _resRecipe.TemperatureErrorHigh && !reservoirEntity.IsError)
- {
- LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"{temperatureController.Name} temperature:{tempValue} is over recipe's TemperatureErrorHigh parameter:{_resRecipe.TemperatureErrorHigh}");
- reservoirEntity.PostMsg(ReservoirMsg.Error);
- }
- else if (tempValue < _resRecipe.TemperatureErrorLow && !reservoirEntity.IsError)
- {
- LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"{temperatureController.Name} temperature:{tempValue} is less than recipe's TemperatureErrorLow parameter:{_resRecipe.TemperatureErrorLow}");
- reservoirEntity.PostMsg(ReservoirMsg.Error);
- }
- else if (tempValue > _resRecipe.TemperatureWarningHigh)
- {
- if (!_isTCControlWARN)
- {
- LOG.WriteLog(eEvent.WARN_RESERVOIR, Module, $"{temperatureController.Name} temperature:{tempValue} is over recipe's TemperatureWarningHigh parameter:{_resRecipe.TemperatureWarningHigh}");
- _isTCControlWARN = true;
- }
- }
- else if (tempValue < _resRecipe.TemperatureWarningLow)
- {
- if (!_isTCControlWARN)
- {
- LOG.WriteLog(eEvent.WARN_RESERVOIR, Module, $"{temperatureController.Name} temperature:{tempValue} is less than recipe's TemperatureWarningLow parameter:{_resRecipe.TemperatureWarningLow}");
- _isTCControlWARN = true;
- }
- }
- else
- {
- _isTCControlWARN = false;
- }
- }
- /// <summary>
- /// CMMPowerCheck
- /// </summary>
- private void CMMPowerCheck()
- {
- ReservoirEntity reservoirEntity = Singleton<RouteManager>.Instance.GetModule<ReservoirEntity>(Module);
- ReservoirItem _reservoirItem = ReservoirItemManager.Instance.GetReservoirItem(Module.ToString());
- if (!string.IsNullOrEmpty(_reservoirItem.CMMSupplyID))
- {
- CellPowerSupplier _powerSupplier = DEVICE.GetDevice<CellPowerSupplier>(_reservoirItem.CMMSupplyID);
- if (_powerSupplier == null || _powerSupplier.PowerSupplierData == null || _resRecipe == null || !_resRecipe.CMMEnable || !_powerSupplier.PowerSupplierData.Enabled || _powerSupplier.PowerSupplierData.Current == 0) return;
- //CMM Current Check
- double current = _powerSupplier.PowerSupplierData.Current;
- if (current > _resRecipe.CMMCurrentSetPoint * (1 + (double)_resRecipe.CMMCurrentFaultPercent / 100))
- {
- 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} %");
- reservoirEntity.PostMsg(ReservoirMsg.Error);
- if (_powerSupplier.PowerSupplierData.Enabled)
- {
- _powerSupplier.DisableOperation("", null);
- _persistentValue.CMMStartTime = DateTime.MinValue;
- ReservoirsPersistentManager.Instance.UpdatePersistentValue(Module);
- }
- }
- else if (current < _resRecipe.CMMCurrentSetPoint * (1 - (double)_resRecipe.CMMCurrentFaultPercent / 100))
- {
- 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}%");
- reservoirEntity.PostMsg(ReservoirMsg.Error);
- if (_powerSupplier.PowerSupplierData.Enabled)
- {
- _powerSupplier.DisableOperation("", null);
- _persistentValue.CMMStartTime = DateTime.MinValue;
- ReservoirsPersistentManager.Instance.UpdatePersistentValue(Module);
- }
- }
- else if (current > _resRecipe.CMMCurrentSetPoint * (1 + (double)_resRecipe.CMMCurrentWarningPercent / 100))
- {
- if (!_isCMMPowerCurrentWARN)
- {
- 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}%");
- _isCMMPowerCurrentWARN = true;
- }
- }
- else if (current < _resRecipe.CMMCurrentSetPoint * (1 - (double)_resRecipe.CMMCurrentWarningPercent / 100))
- {
- if (!_isCMMPowerCurrentWARN)
- {
- 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}%");
- _isCMMPowerCurrentWARN = true;
- }
- }
- else
- {
- _isCMMPowerCurrentWARN = false;
- }
- //CMM Voltage Check
- double voltage = _powerSupplier.PowerSupplierData.Voltage;
- if (voltage < _resRecipe.CMMMinVoltage)
- {
- LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"{_powerSupplier.Name} voltage:{voltage} is less than recipe's CMMMinVoltage parameter:{_resRecipe.CMMMinVoltage}");
- reservoirEntity.PostMsg(ReservoirMsg.Error);
- if (_powerSupplier.PowerSupplierData.Enabled) _powerSupplier.DisableOperation("", null);
- }
- //CMM Flow Check
- double flow = ReservoirData.Flow;
- double cmmFlowHighFault = SC.GetValue<double>($"Reservoir.{Module}.CMMFlowHighFault");
- double cmmFlowHighWarning = SC.GetValue<double>($"Reservoir.{Module}.CMMFlowHighWarning");
- double cmmFlowLowFault = SC.GetValue<double>($"Reservoir.{Module}.CMMFlowLowFault");
- double cmmFlowLowWarning = SC.GetValue<double>($"Reservoir.{Module}.CMMFlowLowWarning");
- if (flow < cmmFlowLowFault)
- {
- LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"{Module} CMM flow:{flow} is less than config item CMMFlowLowFault:{cmmFlowLowFault}");
- if (_powerSupplier.PowerSupplierData.Enabled) _powerSupplier.DisableOperation("", null);
- reservoirEntity.PostMsg(ReservoirMsg.Error);
- }
- else if (flow < cmmFlowLowWarning)
- {
- if (!_isCMMPowerFlowWARN)
- {
- LOG.WriteLog(eEvent.WARN_RESERVOIR, Module, $"{Module} CMM flow:{flow} is less than config item CMMFlowLowWarning:{cmmFlowLowWarning}");
- _isCMMPowerFlowWARN = true;
- }
- }
- else if (flow > cmmFlowHighFault)
- {
- LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"{Module} CMM flow:{flow} is over config item CMMFlowHighFault:{cmmFlowLowFault}");
- if (_powerSupplier.PowerSupplierData.Enabled) _powerSupplier.DisableOperation("", null);
- reservoirEntity.PostMsg(ReservoirMsg.Error);
- }
- else if (flow > cmmFlowHighWarning)
- {
- if (!_isCMMPowerFlowWARN)
- {
- LOG.WriteLog(eEvent.WARN_RESERVOIR, Module, $"{Module} CMM flow:{flow} is over config item CMMFlowHighWarning:{cmmFlowLowWarning}");
- _isCMMPowerFlowWARN = true;
- }
- }
- else
- {
- _isCMMPowerFlowWARN = false;
- }
- }
- }
- #region DosingSystem
- /// <summary>
- /// 加载Replen Recipe
- /// </summary>
- /// <param name="cmd"></param>
- /// <param name="args"></param>
- /// <returns></returns>
- private bool LoadDosingRecipeOperation(string cmd, object[] args)
- {
- string replenName = args[1].ToString();
- int replenID = int.Parse(args[1].ToString().Substring(6, 1));
- string replenRecipe = args[0].ToString();
- _rdsRecipe[replenID - 1] = RecipeFileManager.Instance.LoadGenericityRecipe<RdsRecipe>(replenRecipe);
- _replenDatas[replenID - 1].RecipeName = args[2].ToString();
- LOG.WriteLog(eEvent.INFO_RESERVOIR, Module, $"Load Replen Recipe {_rdsRecipe[replenID - 1].Ppid} Success");
- return true;
- }
- #region Replen Pump
- /// <summary>
- /// Replen Pump On 操作(根据PumpFactor和InitialDosingSpeed调速)
- /// </summary>
- /// <param name="cmd"></param>
- /// <param name="args"></param>
- /// <returns></returns>
- public bool ReplenPumpOnOperation(string cmd, object[] args)
- {
- string replenName = args[0].ToString();
- int replenID = int.Parse(args[0].ToString().Substring(6, 1));
- //加载InitialDosingSpeed
- double InitialDosingSpeed = 0;
- if (SC.ContainsItem($"Reservoir.{Module}.InitialDosingSpeed"))
- {
- InitialDosingSpeed = SC.GetValue<double>($"Reservoir.{Module}.InitialDosingSpeed");
- if (InitialDosingSpeed == 0)
- {
- _replenDatas[replenID - 1].ReplenPumpEnable = false;
- LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, "InitialDosingSpeed is zero. Can't open replen pump");
- return false;
- }
- }
- else
- {
- LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, "Configuration item of InitialDosingSpeed doesn't exist!");
- return false;
- }
- //加载ReplenPumpFactor
- double PumpFactor = 0;
- PumpFactor = _replenPersistentValue[replenName].ReplenPumpFactor;
- if (PumpFactor == 0)
- {
- _replenDatas[replenID - 1].ReplenPumpEnable = false;
- LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, "PumpFactor is zero. Can't open replen pump");
- return false;
- }
- //计算PumpSpeed(mL/min)
- double replenPumpSpeed = InitialDosingSpeed * PumpFactor;
- SCConfigItem item = SC.GetConfigItem($"Reservoir.{Module}.InitialDosingSpeed");
- double speedMax = double.Parse(item.Max);
- if (replenPumpSpeed > speedMax) replenPumpSpeed = speedMax;
- bool result = ReplenPump(replenPumpSpeed / PUMP_SPEED_CONVERT, replenID);
- if (!result)
- {
- LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"Opening replen{replenID} pump is failed");
- _replenDatas[replenID - 1].ReplenPumpSpeed = 0;
- _replenDatas[replenID - 1].ReplenPumpEnable = false;
- return false;
- }
- _replenDatas[replenID - 1].ReplenPumpSpeed = replenPumpSpeed;
- _replenDatas[replenID - 1].ReplenPumpEnable = true;
- LOG.WriteLog(eEvent.INFO_RESERVOIR, Module, $"Replen{replenID} pump is opened");
- return true;
- }
- /// <summary>
- /// Replen Pump Off操作
- /// </summary>
- /// <param name="cmd"></param>
- /// <param name="args"></param>
- /// <returns></returns>
- public bool ReplenPumpOffOperation(string cmd, object[] args)
- {
- string replenName = args[0].ToString();
- int replenID = int.Parse(args[0].ToString().Substring(6, 1));
- bool result = ReplenPump(0, replenID);
- if (!result)
- {
- LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"Closing replen{replenID} pump is failed");
- return false;
- }
- _replenDatas[replenID - 1].ReplenPumpSpeed = 0;
- _replenDatas[replenID - 1].ReplenPumpEnable = false;
- LOG.WriteLog(eEvent.INFO_RESERVOIR, Module, $"Replen{replenID} pump is closed");
- return true;
- }
- /// <summary>
- /// Replen Pump WriteIOValue
- /// </summary>
- /// <param name="speed"></param>
- /// <returns></returns>
- private bool ReplenPump(double speed, int replenNum)
- {
- string ioName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.Replen{replenNum}PumpSpeed");
- return IOModuleManager.Instance.WriteIoValue(ioName, speed);
- }
- #endregion
- /// <summary>
- /// 设置PumpFactor
- /// </summary>
- /// <param name="cmd"></param>
- /// <param name="args"></param>
- /// <returns></returns>
- public bool SetPumpFactor(string cmd, object[] args)
- {
- int replenID = int.Parse(args[0].ToString().Substring(6, 1));
- double targetPumpFactor = (double)args[1];
- _dosingSystemHelperLst[replenID - 1].SetPumpfactor(targetPumpFactor);
- return true;
- }
- /// <summary>
- /// 手动Dosing
- /// </summary>
- /// <param name="cmd"></param>
- /// <param name="args"></param>
- /// <returns></returns>
- private bool ManualDosing(string cmd, object[] args)
- {
- ReservoirEntity reservoirEntity = Singleton<RouteManager>.Instance.GetModule<ReservoirEntity>(Module);
- if (reservoirEntity == null || !_dosingCommonHelper.IsDosingSystemInitialized)
- {
- LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, "Dosing System is not initialized!");
- return true;
- }
- string replenName = args[0].ToString();
- int replenID = int.Parse(args[0].ToString().Substring(6, 1));
- double manualDosingVolume = (double)args[1];
- if (manualDosingVolume == 0)
- {
- LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, "Dosing Volume is zero, can't do manual dosing");
- return false;
- }
- if (!CheckandUpdateBottleLevel(replenName, manualDosingVolume))
- {
- return false;
- }
- if (_replenPersistentValue[replenName].IsDosingRunning)
- {
- LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, "Dosing is runnning, can't do manual dosing");
- return false;
- }
- LOG.WriteLog(eEvent.INFO_RESERVOIR, Module, "ManualDosing starts now");
- _currentDosingOperation[replenID - 1] = DosingOperation.ManualDosing;
- bool result = _dosingSystemHelperLst[replenID - 1].StartDosing(manualDosingVolume, false);
- return result;
- }
- /// <summary>
- /// 停止手动Dosing
- /// </summary>
- /// <param name="cmd"></param>
- /// <param name="args"></param>
- /// <returns></returns>
- private bool StopManualDosing(string cmd, object[] args)
- {
- string replenName = args[0].ToString();
- int replenID = int.Parse(args[0].ToString().Substring(6, 1));
- if (!_replenPersistentValue[replenName].IsDosingRunning)
- {
- LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, "ManualDosing is not running. Can't stop!");
- }
- _currentDosingOperation[replenID - 1] = DosingOperation.None;
- bool result = _dosingSystemHelperLst[replenID - 1].StopDosing();
- if (result)
- {
- LOG.WriteLog(eEvent.INFO_RESERVOIR, Module, "ManualDosing has stopped now");
- }
- return result;
- }
- /// <summary>
- /// 检查并更新BottleLevel状态
- /// </summary>
- /// <param name="replenName"></param>
- /// <param name="targetVolume"></param>
- public bool CheckandUpdateBottleLevel(string replenName, double targetVolume = -1, bool isError = true)
- {
- int replenId = int.Parse(replenName.Substring(6, 1));
- double remainVolume = _replenPersistentValue[replenName].RemainDosingVolume;
- bool result = true;
- if (ReservoirData.ReplenLevel[replenId - 1])
- {
- ReplenDatas[replenId - 1].BottleLevel = DosingSystemHelper.BottleLevelState.Full.ToString();
- if (targetVolume > remainVolume)
- {
- ReplenDatas[replenId - 1].BottleLevel = DosingSystemHelper.BottleLevelState.Warning.ToString();
- if (isError)
- {
- LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"Current Bottle is in Warning Level!");
- }
- result = false;
- }
- }
- else
- {
- ReplenDatas[replenId - 1].BottleLevel = DosingSystemHelper.BottleLevelState.Empty.ToString();
- if (isError)
- {
- LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"Current Bottle is in Empty Level!");
- }
- result = false;
- }
- return result;
- }
- /// <summary>
- /// Reset BottleVolume
- /// </summary>
- /// <param name="cmd"></param>
- /// <param name="args"></param>
- /// <returns></returns>
- private bool ResetBottleVolume(string cmd, object[] args)
- {
- string replenName = args[0].ToString();
- int replenID = int.Parse(args[0].ToString().Substring(6, 1));
- if (SC.ContainsItem($"Reservoir.{Module}.BottleReserveVolume{replenID}"))
- {
- _replenPersistentValue[replenName].RemainDosingVolume = SC.GetValue<double>($"Reservoir.{Module}.BottleReserveVolume{replenID}");
- }
- ReplenPersistentManager.Instance.UpdatePersistentValue(Module, replenName);
- LOG.WriteLog(eEvent.INFO_RESERVOIR, Module, $"Bottle Reserve Volume of Replen{replenID} has been reset now");
- return true;
- }
- /// <summary>
- /// DosingSystem初始化
- /// </summary>
- /// <param name="cmd"></param>
- /// <param name="args"></param>
- /// <returns></returns>
- private bool DosingInitialize(string cmd, object[] args)
- {
- ReservoirEntity reservoirEntity = Singleton<RouteManager>.Instance.GetModule<ReservoirEntity>(Module);
- if (reservoirEntity == null || !reservoirEntity.IsInitialized)
- {
- LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"{Module} is not initialized");
- return false;
- }
- return _dosingCommonHelper.DosingInitialize(); ;
- }
- /// <summary>
- /// Enetr Init State
- /// </summary>
- /// <param name="cmd"></param>
- /// <param name="args"></param>
- /// <returns></returns>
- private bool DosingEnterInit()
- {
- return _dosingCommonHelper.DosingEnterInit();
- }
- #endregion
- /// <summary>
- /// Enter Disabled Operation
- /// </summary>
- private void EnterDisabledOperation()
- {
- ReservoirItem _reservoirItem = ReservoirItemManager.Instance.GetReservoirItem(Module.ToString());
- //关CMMPower
- if (!string.IsNullOrEmpty(_reservoirItem.CMMSupplyID))
- {
- CellPowerSupplier powerSupplier = DEVICE.GetDevice<CellPowerSupplier>(_reservoirItem.CMMSupplyID);
- if (powerSupplier != null && powerSupplier.PowerSupplierData.Enabled) powerSupplier.DisableOperation("", null);
- }
- //关TC
- if (!string.IsNullOrEmpty(_reservoirItem.TCID))
- {
- TemperatureController temperatureController = DEVICE.GetDevice<TemperatureController>(_reservoirItem.TCID);
- if (temperatureController != null) temperatureController.DisableOperation("", null);
- }
- _phRoutine.Abort();
- if (_reservoirData.PHFlowValve)
- {
- PHValveOff();
- }
- if (_reservoirData.DiReplen)
- {
- DIReplenOff("", null);
- }
- }
- /// <summary>
- /// Set Export CMMUsage
- /// </summary>
- public void SetExportCMMUsage()
- {
- _isExportCMMUsage = true;
- }
- /// <summary>
- /// ReservoirUsage监控
- /// </summary>
- public void ReservoirUsageMonitor()
- {
- ReservoirUsage reservoirUsage = ReservoirUsageManager.Instance.GetReservoirUsage(Module);
- ReservoirEntity reservoirEntity = Singleton<RouteManager>.Instance.GetModule<ReservoirEntity>(Module);
- if (reservoirUsage == null || reservoirEntity == null) return;
- //reservoirTotalAmpHours Check
- double reservoirTotalAmpHoursWarningLimit = 0;
- if (SC.ContainsItem($"Reservoir.{Module}.ReservoirTotalAmpHoursWarningLimit"))
- {
- reservoirTotalAmpHoursWarningLimit = (double)SC.GetValue<double>($"Reservoir.{Module}.ReservoirTotalAmpHoursWarningLimit");
- }
- double reservoirTotalAmpHoursFaultLimit = 0;
- if (SC.ContainsItem($"Reservoir.{Module}.ReservoirTotalAmpHoursFaultLimit"))
- {
- reservoirTotalAmpHoursFaultLimit = (double)SC.GetValue<double>($"Reservoir.{Module}.ReservoirTotalAmpHoursFaultLimit");
- }
- if (reservoirUsage.TotalUsage > reservoirTotalAmpHoursFaultLimit && reservoirTotalAmpHoursFaultLimit != 0)
- {
- LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"{Module} Total Usage(AHr):{reservoirUsage.TotalUsage} is over config item ReservoirTotalAmpHoursFaultLimit:{reservoirTotalAmpHoursFaultLimit}");
- reservoirEntity.PostMsg(ReservoirMsg.Error);
- AlarmListManager.Instance.AddDataError(Module,
- $"TotalUsage", $"{Module} usage:{reservoirUsage.TotalUsage} is over ReservoirTotalAmpHoursFaultLimit:{reservoirTotalAmpHoursFaultLimit}");
- }
- else if (reservoirUsage.TotalUsage > reservoirTotalAmpHoursWarningLimit && reservoirTotalAmpHoursWarningLimit != 0)
- {
- LOG.WriteLog(eEvent.WARN_RESERVOIR, Module, $"{Module} Total Usage(AHr):{reservoirUsage.TotalUsage} is over config item ReservoirTotalAmpHoursWarningLimit:{reservoirTotalAmpHoursWarningLimit}");
- AlarmListManager.Instance.AddWarn(Module,
- $"TotalUsage", $"{Module} usage:{reservoirUsage.TotalUsage} is over ReservoirTotalAmpHoursWarningLimit:{reservoirTotalAmpHoursWarningLimit}");
- }
- //MembraneTotalAmpHoursCheck
- double membraneTotalAmpHoursWarningLimit = 0;
- if (SC.ContainsItem($"Reservoir.{Module}.MembraneTotalAmpHoursWarningLimit"))
- {
- membraneTotalAmpHoursWarningLimit = (double)SC.GetValue<double>($"Reservoir.{Module}.MembraneTotalAmpHoursWarningLimit");
- }
- double membraneTotalAmpHoursFaultLimit = 0;
- if (SC.ContainsItem($"Reservoir.{Module}.MembraneTotalAmpHoursFaultLimit"))
- {
- membraneTotalAmpHoursFaultLimit = (double)SC.GetValue<double>($"Reservoir.{Module}.MembraneTotalAmpHoursFaultLimit");
- }
- if (reservoirUsage.MembranceUsage > membraneTotalAmpHoursFaultLimit && membraneTotalAmpHoursFaultLimit != 0)
- {
- LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"{Module} Membrane Usage(AHr):{reservoirUsage.MembranceUsage} is over config item MembraneTotalAmpHoursFaultLimit:{membraneTotalAmpHoursFaultLimit}");
- reservoirEntity.PostMsg(ReservoirMsg.Error);
- AlarmListManager.Instance.AddDataError(Module,
- $"MembraneUsage", $"{Module} usage:{reservoirUsage.MembranceUsage} is over MembraneTotalAmpHoursFaultLimit:{membraneTotalAmpHoursFaultLimit}");
- }
- else if (reservoirUsage.MembranceUsage > membraneTotalAmpHoursWarningLimit && membraneTotalAmpHoursWarningLimit != 0)
- {
- LOG.WriteLog(eEvent.WARN_RESERVOIR, Module, $"{Module} Membrane Usage(AHr):{reservoirUsage.MembranceUsage} is over config item MembraneTotalAmpHoursWarningLimit:{membraneTotalAmpHoursWarningLimit}");
- AlarmListManager.Instance.AddWarn(Module,
- $"MembraneUsage", $"{Module} usage:{reservoirUsage.MembranceUsage} is over MembraneTotalAmpHoursWarningLimit:{membraneTotalAmpHoursWarningLimit}");
- }
- //ANBathTotalAmpHoursCheck
- //double anBathTotalAmpHoursWarningLimit = 0;
- //if (SC.ContainsItem($"Reservoir.{Module}.ANBathTotalAmpHoursWarningLimit"))
- //{
- // anBathTotalAmpHoursWarningLimit = (double)SC.GetValue<double>($"Reservoir.{Module}.ANBathTotalAmpHoursWarningLimit");
- //}
- //double anBathTotalAmpHoursFaultLimit = 0;
- //if (SC.ContainsItem($"Reservoir.{Module}.ANBathTotalAmpHoursFaultLimit"))
- //{
- // anBathTotalAmpHoursFaultLimit = (double)SC.GetValue<double>($"Reservoir.{Module}.ANBathTotalAmpHoursFaultLimit");
- //}
- //if (reservoirUsage.AnodeUsage > anBathTotalAmpHoursFaultLimit && anBathTotalAmpHoursFaultLimit != 0)
- //{
- // LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"{Module} Anolyte Bath Usage(AHr):{reservoirUsage.AnodeUsage} is over config item ANBathTotalAmpHoursFaultLimit:{anBathTotalAmpHoursFaultLimit}");
- // reservoirEntity.PostMsg(ReservoirMsg.Error);
- // AlarmListManager.Instance.AddDataError(Module,
- // $"AnodeUsage", $"{Module} usage:{reservoirUsage.AnodeUsage} is over ANBathTotalAmpHoursFaultLimit:{anBathTotalAmpHoursFaultLimit}");
- //}
- //else if (reservoirUsage.AnodeUsage > anBathTotalAmpHoursWarningLimit && anBathTotalAmpHoursWarningLimit != 0)
- //{
- // LOG.WriteLog(eEvent.WARN_RESERVOIR, Module, $"{Module} Anolyte Bath Usage(AHr):{reservoirUsage.AnodeUsage} is over config item ANBathTotalAmpHoursWarningLimit:{anBathTotalAmpHoursWarningLimit}");
- // AlarmListManager.Instance.AddWarn(Module,
- // $"AnodeUsage", $"{Module} usage:{reservoirUsage.AnodeUsage} is over ANBathTotalAmpHoursWarningLimit:{anBathTotalAmpHoursWarningLimit}");
- //}
- //BathTotalAmpHoursCheck
- double bathTotalAmpHoursWarningLimit = 0;
- if (SC.ContainsItem($"Reservoir.{Module}.BathTotalAmpHoursWarningLimit"))
- {
- bathTotalAmpHoursWarningLimit = (double)SC.GetValue<double>($"Reservoir.{Module}.BathTotalAmpHoursWarningLimit");
- }
- double bathTotalAmpHoursFaultLimit = 0;
- if (SC.ContainsItem($"Reservoir.{Module}.BathTotalAmpHoursFaultLimit"))
- {
- bathTotalAmpHoursFaultLimit = (double)SC.GetValue<double>($"Reservoir.{Module}.BathTotalAmpHoursFaultLimit");
- }
- if (reservoirUsage.BathUsage > bathTotalAmpHoursFaultLimit && bathTotalAmpHoursFaultLimit != 0)
- {
- LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"{Module} Bath Usage(AHr):{reservoirUsage.BathUsage} is over config item BathTotalAmpHoursFaultLimit:{bathTotalAmpHoursFaultLimit}");
- reservoirEntity.PostMsg(ReservoirMsg.Error);
- AlarmListManager.Instance.AddDataError(Module,
- $"BathUsage", $"{Module} usage:{reservoirUsage.BathUsage} is over BathTotalAmpHoursFaultLimit:{bathTotalAmpHoursFaultLimit}");
- }
- else if (reservoirUsage.BathUsage > bathTotalAmpHoursWarningLimit && bathTotalAmpHoursWarningLimit != 0)
- {
- LOG.WriteLog(eEvent.WARN_RESERVOIR, Module, $"{Module} Bath Usage(AHr):{reservoirUsage.BathUsage} is over config item BathTotalAmpHoursWarningLimit:{bathTotalAmpHoursWarningLimit}");
- AlarmListManager.Instance.AddWarn(Module,
- $"BathUsage", $"{Module} usage:{reservoirUsage.BathUsage} is over BathTotalAmpHoursWarningLimit:{bathTotalAmpHoursWarningLimit}");
- }
- //BathTotalDaysCheck
- int bathTotalDaysWarningLimit = 0;
- if (SC.ContainsItem($"Reservoir.{Module}.BathTotalDaysWarningLimit"))
- {
- bathTotalDaysWarningLimit = SC.GetValue<int>($"Reservoir.{Module}.BathTotalDaysWarningLimit");
- }
- int bathTotalDaysFaultLimit = 0;
- if (SC.ContainsItem($"Reservoir.{Module}.BathTotalDaysFaultLimit"))
- {
- bathTotalDaysFaultLimit = SC.GetValue<int>($"Reservoir.{Module}.BathTotalDaysFaultLimit");
- }
- if (reservoirUsage.BathUsageDays > bathTotalDaysFaultLimit && bathTotalDaysFaultLimit != 0)
- {
- LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"{Module} Bath Usage(Days):{reservoirUsage.BathUsageDays} is over config item BathTotalDaysFaultLimit:{bathTotalDaysFaultLimit}");
- reservoirEntity.PostMsg(ReservoirMsg.Error);
- AlarmListManager.Instance.AddDataError(Module,
- $"BathUsageDays", $"{Module} usage:{reservoirUsage.BathUsageDays} is over BathTotalDaysFaultLimit:{bathTotalDaysFaultLimit}");
- }
- else if (reservoirUsage.BathUsageDays > bathTotalDaysWarningLimit && bathTotalDaysWarningLimit != 0)
- {
- LOG.WriteLog(eEvent.WARN_RESERVOIR, Module, $"{Module} Bath Usage(Days):{reservoirUsage.BathUsage} is over config item BathTotalDaysWarningLimit:{bathTotalDaysWarningLimit}");
- AlarmListManager.Instance.AddWarn(Module,
- $"BathUsageDays", $"{Module} usage:{reservoirUsage.BathUsageDays} is over BathTotalDaysWarningLimit:{bathTotalDaysWarningLimit}");
- }
- //ReservoirTotalWafersCheck
- int reservoirTotalWafersWarningLimit = 0;
- if (SC.ContainsItem($"Reservoir.{Module}.ReservoirTotalWafersWarningLimit"))
- {
- reservoirTotalWafersWarningLimit = SC.GetValue<int>($"Reservoir.{Module}.ReservoirTotalWafersWarningLimit");
- }
- int reservoirTotalWafersFaultLimit = 0;
- if (SC.ContainsItem($"Reservoir.{Module}.ReservoirTotalWafersFaultLimit"))
- {
- reservoirTotalWafersFaultLimit = SC.GetValue<int>($"Reservoir.{Module}.ReservoirTotalWafersFaultLimit");
- }
- if (reservoirUsage.TotalWafers > reservoirTotalWafersFaultLimit && reservoirTotalWafersFaultLimit != 0)
- {
- LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"{Module} Total Wafers:{reservoirUsage.TotalWafers} is over config item ReservoirTotalWafersFaultLimit:{reservoirTotalWafersFaultLimit}");
- reservoirEntity.PostMsg(ReservoirMsg.Error);
- AlarmListManager.Instance.AddDataError(Module,
- $"TotalWafers", $"{Module} usage:{reservoirUsage.TotalWafers} is over ReservoirTotalWafersFaultLimit:{reservoirTotalWafersFaultLimit}");
- }
- else if (reservoirUsage.TotalWafers > reservoirTotalWafersWarningLimit && reservoirTotalWafersWarningLimit != 0)
- {
- LOG.WriteLog(eEvent.WARN_RESERVOIR, Module, $"{Module} Total Wafers:{reservoirUsage.TotalWafers} is over config item ReservoirTotalWafersWarningLimit:{reservoirTotalWafersWarningLimit}");
- AlarmListManager.Instance.AddWarn(Module,
- $"TotalWafers", $"{Module} usage:{reservoirUsage.TotalWafers} is over ReservoirTotalWafersWarningLimit:{reservoirTotalWafersWarningLimit}");
- }
- //CMMAnodeTotalAmpHoursCheck
- double cmmAnodeTotalAmpHoursWarningLimit = 0;
- if (SC.ContainsItem($"Reservoir.{Module}.CMMAnodeTotalAmpHoursWarningLimit"))
- {
- cmmAnodeTotalAmpHoursWarningLimit = (double)SC.GetValue<double>($"Reservoir.{Module}.CMMAnodeTotalAmpHoursWarningLimit");
- }
- double cmmAnodeTotalAmpHoursFaultLimit = 0;
- if (SC.ContainsItem($"Reservoir.{Module}.CMMAnodeTotalAmpHoursFaultLimit"))
- {
- cmmAnodeTotalAmpHoursFaultLimit = (double)SC.GetValue<double>($"Reservoir.{Module}.CMMAnodeTotalAmpHoursFaultLimit");
- }
- if (reservoirUsage.CMMAnodeUsage > cmmAnodeTotalAmpHoursFaultLimit && cmmAnodeTotalAmpHoursFaultLimit != 0)
- {
- LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"{Module} CMM Anode Usage(AHr):{reservoirUsage.CMMAnodeUsage} is over config item CMMAnodeTotalAmpHoursFaultLimit:{cmmAnodeTotalAmpHoursFaultLimit}");
- reservoirEntity.PostMsg(ReservoirMsg.Error);
- AlarmListManager.Instance.AddDataError(Module,
- $"CMMAnodeUsage", $"{Module} CMM Anode Usage(AHr):{reservoirUsage.CMMAnodeUsage} is over CMMAnodeTotalAmpHoursFaultLimit:{cmmAnodeTotalAmpHoursFaultLimit}");
- }
- else if (reservoirUsage.CMMAnodeUsage > cmmAnodeTotalAmpHoursWarningLimit && cmmAnodeTotalAmpHoursWarningLimit != 0)
- {
- LOG.WriteLog(eEvent.WARN_RESERVOIR, Module, $"{Module} CMM Anode Usage(AHr):{reservoirUsage.CMMAnodeUsage} is over config item CMMAnodeTotalAmpHoursWarningLimit:{cmmAnodeTotalAmpHoursWarningLimit}");
- AlarmListManager.Instance.AddWarn(Module,
- $"CMMAnodeUsage", $"{Module} CMM Anode Usage(AHr):{reservoirUsage.CMMAnodeUsage} is over CMMAnodeTotalAmpHoursWarningLimit:{cmmAnodeTotalAmpHoursWarningLimit}");
- }
- //CMMCathodeTotalAmpHoursCheck
- double cmmCathodeTotalAmpHoursWarningLimit = 0;
- if (SC.ContainsItem($"Reservoir.{Module}.CMMCathodeTotalAmpHoursWarningLimit"))
- {
- cmmCathodeTotalAmpHoursWarningLimit = (double)SC.GetValue<double>($"Reservoir.{Module}.CMMCathodeTotalAmpHoursWarningLimit");
- }
- double cmmCathodeTotalAmpHoursFaultLimit = 0;
- if (SC.ContainsItem($"Reservoir.{Module}.CMMCathodeTotalAmpHoursFaultLimit"))
- {
- cmmCathodeTotalAmpHoursFaultLimit = (double)SC.GetValue<double>($"Reservoir.{Module}.CMMCathodeTotalAmpHoursFaultLimit");
- }
- if (reservoirUsage.CMMMembranceUsage > cmmCathodeTotalAmpHoursFaultLimit && cmmCathodeTotalAmpHoursFaultLimit != 0)
- {
- LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"{Module} CMM Cathode Usage(AHr):{reservoirUsage.CMMMembranceUsage} is over config item CMMCathodeTotalAmpHoursFaultLimit:{cmmCathodeTotalAmpHoursFaultLimit}");
- reservoirEntity.PostMsg(ReservoirMsg.Error);
- AlarmListManager.Instance.AddDataError(Module,
- $"CMMCathodeUsage", $"{Module} CMM Cathode Usage(AHr):{reservoirUsage.CMMMembranceUsage} is over CMMCathodeTotalAmpHoursFaultLimit:{cmmCathodeTotalAmpHoursFaultLimit}");
- }
- else if (reservoirUsage.CMMMembranceUsage > cmmCathodeTotalAmpHoursWarningLimit && cmmCathodeTotalAmpHoursWarningLimit != 0)
- {
- LOG.WriteLog(eEvent.WARN_RESERVOIR, Module, $"{Module} CMM Cathode Usage(AHr):{reservoirUsage.CMMMembranceUsage} is over config item CMMCathodeTotalAmpHoursWarningLimit:{cmmCathodeTotalAmpHoursWarningLimit}");
- AlarmListManager.Instance.AddWarn(Module,
- $"CMMCathodeUsage", $"{Module} CMM Cathode Usage(AHr):{reservoirUsage.CMMMembranceUsage} is over CMMCathodeTotalAmpHoursWarningLimit:{cmmCathodeTotalAmpHoursWarningLimit}");
- }
- }
- #endregion
- /// <summary>
- /// 订阅变量数值发生变化
- /// </summary>
- private void SubscribeValueAction()
- {
- BeckhoffIoSubscribeUpdateVariable(FLOW);
- BeckhoffIoSubscribeUpdateVariable(HED_FLOW);
- BeckhoffIoSubscribeUpdateVariable(DI_REPLEN);
- BeckhoffIoSubscribeUpdateVariable(PH_FLOW_VALVE);
- BeckhoffIoSubscribeUpdateVariable(PH_VALUE);
- BeckhoffIoSubscribeUpdateVariable(WATER_LEVEL);
- BeckhoffIoSubscribeUpdateVariable(LOW_LEVEL);
- BeckhoffIoSubscribeUpdateVariable(HIGH_LEVEL);
- BeckhoffIoSubscribeUpdateVariable(SAFETY_HIGH_LEVEL);
- BeckhoffIoSubscribeUpdateVariable(RESPOWERON);
- BeckhoffIoSubscribeUpdateVariable(HEDPOWERON);
- for (int i = 0; i < _replenNum; i++)
- {
- BeckhoffIoSubscribeUpdateVariable($"Replen{i + 1}Level");
- }
- }
- /// <summary>
- /// 订阅IO变量
- /// </summary>
- /// <param name="variable"></param>
- private void BeckhoffIoSubscribeUpdateVariable(string variable)
- {
- _variableInitializeDic[variable] = false;
- IOModuleManager.Instance.SubscribeModuleVariable(Module, variable, UpdateVariableValue);
- }
- /// <summary>
- /// 更新变量数值
- /// </summary>
- /// <param name="variable"></param>
- /// <param name="value"></param>
- private void UpdateVariableValue(string variable, object value)
- {
- if (!ReservoirData.IsDataInitialized)
- {
- ReservoirData.IsDataInitialized = true;
- }
- PropertyInfo property = ReservoirData.GetType().GetProperty(variable);
- if (property != null)
- {
- property.SetValue(_reservoirData, value);
- if (variable == WATER_LEVEL)
- {
- string levelCurve = SC.GetStringValue($"Reservoir.{Module}.LevelCurve");
- ReservoirData.Level = LevelCurveManager.Instance.CalculateLevelByWaterLevel(ReservoirData.WaterLevel, levelCurve);
- }
- }
- if (variable.Contains("Replen") && variable.Substring(0, 6) == "Replen")
- {
- property = ReservoirData.GetType().GetProperty(REPLEN_LEVEL);
- _replenLevelLst[int.Parse(variable.Substring(6, 1)) - 1] = (bool)value;
- property.SetValue(_reservoirData, _replenLevelLst);
- }
- if (_variableInitializeDic.ContainsKey(variable) && !_variableInitializeDic[variable])
- {
- _variableInitializeDic[variable] = true;
- }
- }
- /// <summary>
- /// 是否所有IO变量初始化完成
- /// </summary>
- /// <returns></returns>
- private bool AllIoVariableInitialized()
- {
- foreach (string item in _variableInitializeDic.Keys)
- {
- if (!_variableInitializeDic[item])
- {
- LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"{item} is not initialized");
- return false;
- }
- }
- return true;
- }
- public void Monitor()
- {
- }
- public void Reset()
- {
- }
- public void Terminate()
- {
- }
- }
- }
|