12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030 |
- 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;
- 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;
- private bool _reservoirPowerOn = 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", () => _reservoirPowerOn, 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);
- }
- #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);
- 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()
- {
- }
- }
- }
|