123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656 |
- using Aitex.Core.RT.DataCenter;
- using Aitex.Core.RT.Log;
- using Aitex.Core.UI.MVVM;
- using CyberX8_Core;
- using CyberX8_MainPages.Model;
- using CyberX8_Themes.CustomControls;
- using ExcelLibrary.BinaryFileFormat;
- using MECF.Framework.Common.CommonData.Metal;
- using MECF.Framework.Common.CommonData.Reservoir;
- using MECF.Framework.Common.CommonData.TemperatureControl;
- using MECF.Framework.Common.DataCenter;
- using MECF.Framework.Common.OperationCenter;
- using MECF.Framework.Common.Persistent.Reservoirs;
- using MECF.Framework.Common.RecipeCenter;
- using MECF.Framework.Common.Utilities;
- using OpenSEMI.ClientBase.Command;
- using Prism.Mvvm;
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Input;
- using System.Windows.Threading;
- namespace CyberX8_MainPages.ViewModels
- {
- public class ReservoirsCatholyteViewModel : BindableBase
- {
- #region 常量
- private const string RESERVOIRS_DATA = "ReservoirsData";
- private const string RESERVOIRS = "reservoirs";
- private const string PERSISTENT_VALUE = "PersistentValue";
- #endregion
- #region 内部变量
- private string _module;
- private string _recipeContent;
- private string _operatingMode;
- private string _state;
- private string _recipeMode;
- private List<string> _rtDataKeys = new List<string>();
- DispatcherTimer _timer;
- private Dictionary<string, object> _rtDataValueDic = new Dictionary<string, object>();
- private ObservableCollection<RecipeNode> _recipeNodes;
- private string _currentRecipeFileName;
- private string _recipeType;
- private string _tcName;
- private double _caPumpSpeed;
- private bool _isDIReplenFault;
- private double _flowAdjustDelta;
- private double _maxFlowDelta;
- private bool _isFolwDeltaUnBlance = false;
- private bool _isHighLevel;
- private bool _isLowLevel;
- private bool _isLeakDetected;
- private bool _cdaOn;
- private bool _isError;
- private ResRecipe _currentRecipe;
- private double _avgCALevel;
-
- /// <summary>
- /// 是否配置Exhaust
- /// </summary>
- private bool _isEvaporatorConfig;
- /// <summary>
- /// 是否正在手动注水
- /// </summary>
- private bool _isManualReplen;
- /// <summary>
- /// 手动注水时长(秒)
- /// </summary>
- private int _manualFillSeconds;
- /// <summary>
- /// DIValveMaxOnTime
- /// </summary>
- private double _diValveMaxOnTime;
- /// <summary>
- /// TemperatureControl Module Name
- /// </summary>
- private TemperatureControllerData _temperatureControlData;
- /// <summary>
- /// Persistent
- /// </summary>
- private ReservoirsPersistentValue _reservoirsPersistent;
- /// <summary>
- /// Reservoir数据
- /// </summary>
- private CompactMembranReservoirData _reservoirData;
- /// <summary>
- /// CellModuleName集合
- /// </summary>
- private ObservableCollection<string> _cellModuleNameCollection = new ObservableCollection<string>();
- /// <summary>
- /// Cell A面Flow集合
- /// </summary>
- private ObservableCollection<double> _cellModuleNameFlowCollection = new ObservableCollection<double>();
- /// <summary>
- /// MetalData
- /// </summary>
- private ObservableCollection<CompactMembranMetalDeviceData> _metalDatas = new ObservableCollection<CompactMembranMetalDeviceData>();
- /// <summary>
- /// MetalData的CellFlow集合
- /// </summary>
- private ObservableCollection<double> _metalCellFlowDatas = new ObservableCollection<double>();
- /// <summary>
- /// 页面功能启用
- /// </summary>
- private bool _isEnabled;
- /// <summary>
- /// AutoMode页面功能启用
- /// </summary>
- private bool _isAutoEnabled;
- /// <summary>
- /// Meatl UI数据
- /// </summary>
- private ObservableCollection<ReservoirsUIData> _reservoirsUIDatas = new ObservableCollection<ReservoirsUIData>();
- /// <summary>
- /// TC Enable状态
- /// </summary>
- private string _tcEnableStatus;
- #endregion
- #region 属性
- public double AvgCALevel
- {
- get { return _avgCALevel; }
- set { SetProperty(ref _avgCALevel, value); }
- }
- public string CurrentRecipeFileName
- {
- get { return _currentRecipeFileName; }
- set { SetProperty(ref _currentRecipeFileName, value); }
- }
- public ObservableCollection<RecipeNode> RecipeNodes
- {
- get { return _recipeNodes; }
- set { SetProperty(ref _recipeNodes, value); }
- }
- public string Module { get { return _module; } set { SetProperty(ref _module, value); } }
- public string ReservoirRecipeContent
- {
- get { return _recipeContent; }
- set { SetProperty(ref _recipeContent, value); }
- }
- public string OperatingMode
- {
- get { return _operatingMode; }
- set { SetProperty(ref _operatingMode, value); }
- }
- public string State
- {
- get { return _state; }
- set { SetProperty(ref _state, value); }
- }
- public string RecipeMode
- {
- get { return _recipeMode; }
- set { SetProperty(ref _recipeMode, value); }
- }
- public string RecipeType
- {
- get { return _recipeType; }
- set { SetProperty(ref _recipeType, value); }
- }
- public double CAPumpSpeed
- {
- get { return _caPumpSpeed; }
- set
- {
- SetProperty(ref _caPumpSpeed, value);
- }
- }
- public ResRecipe CurrentRecipe
- {
- get { return _currentRecipe; }
- set { SetProperty(ref _currentRecipe, value); }
- }
- /// <summary>
- /// Threshold
- /// </summary>
- public ReservoirsPersistentValue ReservoirsPersistent
- {
- get { return _reservoirsPersistent; }
- set { SetProperty(ref _reservoirsPersistent, value); }
- }
- /// <summary>
- /// CellModuleName集合
- /// </summary>
- public ObservableCollection<string> CellModuleNameCollection
- {
- get { return _cellModuleNameCollection; }
- set { SetProperty(ref _cellModuleNameCollection, value); }
- }
- /// <summary>
- /// 模块Flow集合
- /// </summary>
- public ObservableCollection<double> CellModuleNameFlowCollection
- {
- get { return _cellModuleNameFlowCollection; }
- set { SetProperty(ref _cellModuleNameFlowCollection, value); }
- }
- /// <summary>
- /// Reservoir数据
- /// </summary>
- public CompactMembranReservoirData ReservoirData
- {
- get { return _reservoirData; }
- set { SetProperty(ref _reservoirData, value); }
- }
- /// <summary>
- /// MetalData
- /// </summary>
- public ObservableCollection<CompactMembranMetalDeviceData> MetalDatas
- {
- get { return _metalDatas; }
- set { SetProperty(ref _metalDatas, value); }
- }
- /// <summary>
- /// MetalDataCellFlow
- /// </summary>
- public ObservableCollection<double> MetalCellFlowDatas
- {
- get { return _metalCellFlowDatas; }
- set { SetProperty(ref _metalCellFlowDatas, value); }
- }
- /// <summary>
- /// 是否Error
- /// </summary>
- public bool IsError
- {
- get { return _isError; }
- set { SetProperty(ref _isError, value); }
- }
- /// <summary>
- /// 正在手动注水
- /// </summary>
- public bool IsManualReplen
- {
- get { return _isManualReplen; }
- set { SetProperty(ref _isManualReplen, value); }
- }
- /// <summary>
- /// 手动注水时长
- /// </summary>
- public int ManualFillSeconds
- {
- get { return _manualFillSeconds; }
- set { SetProperty(ref _manualFillSeconds, value); }
- }
- /// <summary>
- /// 单次注水最大时长
- /// </summary>
- public double DIValveMaxOnTime
- {
- get { return _diValveMaxOnTime; }
- set { SetProperty(ref _diValveMaxOnTime, value); }
- }
- /// <summary>
- /// 是否补水异常
- /// </summary>
- public bool IsDIReplenFault
- {
- get { return _isDIReplenFault; }
- set { SetProperty(ref _isDIReplenFault, value); }
- }
- /// <summary>
- /// metal cell 水位最大值和最小值之差
- /// </summary>
- public double FlowAdjustDelta
- {
- get { return _flowAdjustDelta; }
- set { SetProperty(ref _flowAdjustDelta, value); }
- }
- /// <summary>
- /// 流量误差是否超过0.5
- /// </summary>
- public bool IsFolwDeltaUnBlance
- {
- get { return _isFolwDeltaUnBlance; }
- set { SetProperty(ref _isFolwDeltaUnBlance, value); }
- }
- /// <summary>
- /// 是否触发高水位
- /// </summary>
- public bool IsHighLevel
- {
- get { return _isHighLevel; }
- set { SetProperty(ref _isHighLevel, value); }
- }
- /// <summary>
- /// 是否触发低水位
- /// </summary>
- public bool IsLowLevel
- {
- get { return _isLowLevel; }
- set { SetProperty(ref _isLowLevel, value); }
- }
- /// <summary>
- /// TemperatureControl Module Name
- /// </summary>
- public TemperatureControllerData TemperatureControlData
- {
- get { return _temperatureControlData; }
- set { SetProperty(ref _temperatureControlData, value); }
- }
- /// <summary>
- /// 页面功能启用
- /// </summary>
- public bool IsEnabled
- {
- get { return _isEnabled; }
- set { SetProperty(ref _isEnabled, value); }
- }
- /// <summary>
- /// AutoMode页面功能启用
- /// </summary>
- public bool IsAutoEnabled
- {
- get { return _isAutoEnabled; }
- set { SetProperty(ref _isAutoEnabled, value); }
- }
- /// <summary>
- /// metal ui数据
- /// </summary>
- public ObservableCollection<ReservoirsUIData> ReservoirsUIDatas
- {
- get { return _reservoirsUIDatas; }
- set { SetProperty(ref _reservoirsUIDatas, value); }
- }
- /// <summary>
- /// 是否配有排气模块
- /// </summary>
- public bool IsEvaporatorConfig
- {
- get { return _isEvaporatorConfig; }
- set { SetProperty(ref _isEvaporatorConfig, value); }
- }
- /// <summary>
- /// 排期模块是否检测到漏液
- /// </summary>
- public bool IsLeakDetected
- {
- get { return _isLeakDetected; }
- set { SetProperty(ref _isLeakDetected, value); }
- }
- /// <summary>
- /// 排气是否打开
- /// </summary>
- public bool CdaOn
- {
- get { return _cdaOn; }
- set { SetProperty(ref _cdaOn, value); }
- }
- /// <summary>
- /// TC Enable状态
- /// </summary>
- public string TCEnableStatus
- {
- get { return _tcEnableStatus; }
- set { SetProperty(ref _tcEnableStatus, value); }
- }
-
- #endregion
- #region 指令
- public ICommand ControlValveCommand { get; private set; }
- public ICommand ManualDireplenCommand { get; set; }
- public ICommand ResetTotalCommand { get; set; }
- public ICommand CAPumpSpeedCommand { get; private set; }
- public ICommand BackCommand { get; set; }
- public ICommand JumpToTCCommand { get; set; }
- #endregion
- public ReservoirsCatholyteViewModel()
- {
- ControlValveCommand = new DelegateCommand<object>(OnControlValve);
- ManualDireplenCommand = new DelegateCommand<object>(ManualDireplenAction);
- ResetTotalCommand = new DelegateCommand<object>(ResetTotalAction);
- CAPumpSpeedCommand = new DelegateCommand<object>(CAPumpSpeedAction);
- BackCommand = new DelegateCommand<object>(BackAction);
- JumpToTCCommand = new DelegateCommand<object>(JumpToTCAction);
- }
- #region 命令方法
- /// <summary>
- /// 回到Reservoir主页面
- /// </summary>
- /// <param name="param"></param>
- private void BackAction(object param)
- {
- GlobalEvents.OnSwitchFixedChildSubItem(Module, Module);
- }
- /// <summary>
- /// 跳转到对应的TC页面
- /// </summary>
- /// <param name="param"></param>
- private void JumpToTCAction(object param)
- {
- if (_tcName != null)
- {
- GlobalEvents.OnSwitchFixedTabItem("HardWare", "TemperatureController", $"{_tcName.Substring(0, 3)}");
- }
- else
- {
- GlobalEvents.OnSwitchFixedTabItem("HardWare", "TemperatureController", "");
- }
- }
- /// <summary>
- /// Control Valve
- /// </summary>
- /// <param name="obj"></param>
- private void OnControlValve(object obj)
- {
- CommonValveControl commonValveControl = (CommonValveControl)obj;
- if (commonValveControl.IsCanEdit == true)
- {
- string cmd = commonValveControl.OperationName;
- if (!commonValveControl.Status)
- {
- commonValveControl.Status = !commonValveControl.Status;
- InvokeClient.Instance.Service.DoOperation($"{cmd}On");
- }
- else
- {
- commonValveControl.Status = !commonValveControl.Status;
- InvokeClient.Instance.Service.DoOperation($"{cmd}Off");
- }
- }
- }
- /// <summary>
- /// CA Pump调速
- /// </summary>
- /// <param name="obj"></param>
- private void CAPumpSpeedAction(object obj)
- {
- object[] objects = (object[])obj;
- if (objects.Length >= 2)
- {
- InvokeClient.Instance.Service.DoOperation($"{Module}.CAPumpSpeed", objects[1]);
- }
- }
- /// <summary>
- /// 手动注水
- /// </summary>
- /// <param name="param"></param>
- private void ManualDireplenAction(object param)
- {
- InvokeClient.Instance.Service.DoOperation($"{Module}.ManualCADiReplen", ManualFillSeconds);
- }
- /// <summary>
- /// 重置TotalTime
- /// </summary>
- private void ResetTotalAction(object param)
- {
- InvokeClient.Instance.Service.DoOperation($"{Module}.ResetTotalTime");
- }
- #endregion
- public void LoadData(string systemName)
- {
- RecipeType = "res";
- Module = systemName;
- _rtDataKeys.Clear();
- _rtDataKeys.Add($"{Module}.Metals");
- Dictionary<string, object> tmpMetals = QueryDataClient.Instance.Service.PollData(_rtDataKeys);
- if (tmpMetals != null)
- {
- List<string> strMetals = CommonFunction.GetValue<List<string>>(tmpMetals, $"{Module}.Metals");
- int cellsCount = strMetals.Count;
- if (strMetals != null)
- {
- CellModuleNameCollection.Clear();
- CellModuleNameFlowCollection.Clear();
- MetalDatas.Clear();
- MetalCellFlowDatas.Clear();
- ReservoirsUIDatas.Clear();
- for (int i = 0; i < cellsCount; i++)
- {
- CellModuleNameCollection.Add(strMetals[i]);
- CellModuleNameFlowCollection.Add(0);
- MetalDatas.Add(null);
- MetalCellFlowDatas.Add(0);
- ReservoirsUIData reservoirsUIData = new ReservoirsUIData();
- reservoirsUIData.Name = strMetals[i];
- ReservoirsUIDatas.Add(reservoirsUIData);
- }
- }
- }
- _rtDataKeys.Clear();
- for (int i = 0; i < CellModuleNameCollection.Count; i++)
- {
- _rtDataKeys.Add($"{CellModuleNameCollection[i]}.CellFlow");
- _rtDataKeys.Add($"{CellModuleNameCollection[i]}.MetalData");
- }
- _rtDataKeys.Add($"{Module}.{PERSISTENT_VALUE}");
- _rtDataKeys.Add($"{Module}.ReservoirData");
- _rtDataKeys.Add($"{Module}.IsManualCAReplen");
- _rtDataKeys.Add($"{Module}.DIValveMaxOnTime");
- _rtDataKeys.Add($"{Module}.CAPumpSpeed");
- _rtDataKeys.Add($"{Module}.IsCAHighLevel");
- _rtDataKeys.Add($"{Module}.IsCALowLevel");
- _rtDataKeys.Add($"{Module}.IsDIReplenInFault");
- _rtDataKeys.Add($"{Module}.TemperatureControllerData");
- _rtDataKeys.Add($"{Module}.CurrentRecipe");
- _rtDataKeys.Add($"{Module}.FsmState");
- _rtDataKeys.Add($"{Module}.EvaporatorType");
- _rtDataKeys.Add($"{Module}.ReservoirAverageCALevel");
- _rtDataKeys.Add($"System.Facilities.CDAEnable");
- if (_timer == null)
- {
- _timer = new DispatcherTimer();
- _timer.Interval = TimeSpan.FromMilliseconds(200);
- _timer.Tick += Timer_Tick;
- }
- _timer.Start();
- }
- private void Timer_Tick(object sender, EventArgs e)
- {
- if (_rtDataKeys.Count != 0)
- {
- _rtDataValueDic = QueryDataClient.Instance.Service.PollData(_rtDataKeys);
- if (_rtDataValueDic != null)
- {
- State = CommonFunction.GetValue<string>(_rtDataValueDic, $"{Module}.FsmState");
- IsError = "Error".Equals(State) ? true : false;
- ReservoirsPersistent = CommonFunction.GetValue<ReservoirsPersistentValue>(_rtDataValueDic, $"{Module}.{PERSISTENT_VALUE}");
- ReservoirData = CommonFunction.GetValue<CompactMembranReservoirData>(_rtDataValueDic, $"{Module}.ReservoirData");
- AvgCALevel = CommonFunction.GetValue<double>(_rtDataValueDic, $"{Module}.ReservoirAverageCALevel");
- CurrentRecipe = CommonFunction.GetValue<ResRecipe>(_rtDataValueDic, $"{Module}.CurrentRecipe");
- IsManualReplen = CommonFunction.GetValue<bool>(_rtDataValueDic, $"{Module}.IsManualCAReplen");
- DIValveMaxOnTime = CommonFunction.GetValue<double>(_rtDataValueDic, $"{Module}.DIValveMaxOnTime");
- CAPumpSpeed = CommonFunction.GetValue<double>(_rtDataValueDic, $"{Module}.CAPumpSpeed");
- IsHighLevel = CommonFunction.GetValue<bool>(_rtDataValueDic, $"{Module}.IsCAHighLevel");
- IsLowLevel = CommonFunction.GetValue<bool>(_rtDataValueDic, $"{Module}.IsCALowLevel");
- IsDIReplenFault = CommonFunction.GetValue<bool>(_rtDataValueDic, $"{Module}.IsDIReplenInFault");
-
- CdaOn = CommonFunction.GetValue<bool>(_rtDataValueDic, $"System.Facilities.CDAEnable");
- TemperatureControlData = CommonFunction.GetValue<TemperatureControllerData>(_rtDataValueDic, $"{Module}.TemperatureControllerData");
- TCEnableStatus = TemperatureControlData.ControlOperationModel == 0 ? "Disable" : "Enable";
- _tcName = TemperatureControlData.Name;
- for (int i = 0; i < CellModuleNameCollection.Count; i++)
- {
- CellModuleNameFlowCollection[i] = CommonFunction.GetValue<double>(_rtDataValueDic, $"{CellModuleNameCollection[i]}.CellFlow");
- MetalDatas[i] = CommonFunction.GetValue<CompactMembranMetalDeviceData>(_rtDataValueDic, $"{CellModuleNameCollection[i]}.MetalData");
- MetalCellFlowDatas[i] = MetalDatas[i].CellFlow;
- ReservoirsUIDatas[i].MetalCellFlow = MetalCellFlowDatas[i];
- ReservoirsUIDatas[i].IsFlowing3 = MetalDatas[i].CellFlowValve;
- ReservoirsUIDatas[i].IsFlowing2 = MetalDatas[i].WHUnclamp;
- ReservoirsUIDatas[i].IsFlowing1 = MetalDatas[i].WHClamp;
- ReservoirsUIDatas[i].IsEnable = IsEnabled;
- ReservoirsUIDatas[i].IsAutoEnable = IsAutoEnabled;
- }
- //list记录参与循环的metal阴极的流量情况
- List<double> list = new List<double>();
- for (int i = 0; i < CellModuleNameCollection.Count; i++)
- {
- if (MetalDatas[i].CellFlowValve)
- {
- list.Add(MetalDatas[i].CellFlow);
- }
- }
- //如果参与循环的流量全是0或者没有参与循环的metal,直接跳过流量差相关逻辑
- if (list.Count==0 || list.All(num => num == 0))
- {
- for (int i = 0; i < CellModuleNameCollection.Count; i++)
- {
- ReservoirsUIDatas[i].IsMetalCellHigh = false;
- ReservoirsUIDatas[i].IsMetalCellLow = false;
- }
- }
- else
- {
- FlowAdjustDelta = list.Max() - list.Min();
- IsFolwDeltaUnBlance = FlowAdjustDelta > 0.5 ? true : false;
- if (IsFolwDeltaUnBlance)
- {
- for (int i = 0; i < CellModuleNameCollection.Count; i++)
- {
- if (list.Max() == MetalDatas[i].CellFlow && MetalDatas[i].CellFlowValve)
- {
- ReservoirsUIDatas[i].IsMetalCellHigh = true;
- }
- else
- {
- ReservoirsUIDatas[i].IsMetalCellHigh = false;
- }
- if (list.Min() == MetalDatas[i].CellFlow && MetalDatas[i].CellFlowValve)
- {
- ReservoirsUIDatas[i].IsMetalCellLow = true;
- }
- else
- {
- ReservoirsUIDatas[i].IsMetalCellLow = false;
- }
- }
- }
- else
- {
- for (int i = 0; i < CellModuleNameCollection.Count; i++)
- {
- ReservoirsUIDatas[i].IsMetalCellHigh = false;
- ReservoirsUIDatas[i].IsMetalCellLow = false;
- }
- }
- }
- list.Clear();
- if ("Manual".Equals(ReservoirsPersistent.OperatingMode))
- {
- IsEnabled = true;
- IsAutoEnabled = true;
- }
- else if ("Auto".Equals(ReservoirsPersistent.OperatingMode))
- {
- IsAutoEnabled = true;
- IsEnabled = false;
- }
- else
- {
- State = "Stopped";
- IsEnabled = false;
- IsAutoEnabled = false;
- }
- string evaporatorType = CommonFunction.GetValue<string>(_rtDataValueDic, $"{Module}.EvaporatorType");
- if ("STD".Equals(evaporatorType))
- {
- IsEvaporatorConfig = true;
- }
- else
- {
- IsEvaporatorConfig = false;
- }
- }
- }
- }
- /// <summary>
- /// 隐藏
- /// </summary>
- public void Hide()
- {
- if (_timer != null)
- {
- _timer.Stop();
- }
- }
- }
- }
|