123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436 |
- using Aitex.Core.UI.MVVM;
- 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.Device.Safety;
- using MECF.Framework.Common.OperationCenter;
- using MECF.Framework.Common.Persistent.Reservoirs;
- using MECF.Framework.Common.RecipeCenter;
- using MECF.Framework.Common.Utilities;
- using Prism.Mvvm;
- using PunkHPX8_MainPages.Model;
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Input;
- using System.Windows.Threading;
- namespace PunkHPX8_MainPages.ViewModels
- {
- public class DMReservoirViewModel : BindableBase
- {
- #region 常量
- private const string RESERVOIRS_DATA = "ReservoirsData";
- private const string RESERVOIRS = "reservoirs";
- private const string PERSISTENT_VALUE = "PersistentValue";
- #endregion
- #region 内部变量
- private List<string> _rtDataKeys = new List<string>();
- private Dictionary<string, object> _rtDataValueDic = new Dictionary<string, object>();
- DispatcherTimer _timer;
- private bool _isEnabled;
- private bool _isError;
- private bool _isAutoEnabled;
- private SafetyData _commonSafetyData;
- private string _module;
- private string _state;
- private ResRecipe _currentRecipe;
- private ReservoirsPersistentValue _reservoirsPersistent;
- private string _recipeType;
- private int _inputCAPumpSpeed;
- private int _inputANPumpSpeed;
- private int _inputReturnFlowOpenPercent;
- private TemperatureControllerData _temperatureControlData;
- private string _tcEnableStatus;
- private string _tcName;
- private ReservoirData _reservoirData;
- private bool _isCAHighLevel;
- private bool _isCALowLevel;
- private double _avgCaLevel;
- private ObservableCollection<RecipeNode> _recipeNodes;
- private string _currentRecipeFileName;
- /// <summary>
- /// 是否配置Exhaust
- /// </summary>
- private bool _isEvaporatorConfig;
- /// <summary>
- /// 是否正在手动注水
- /// </summary>
- private bool _isManualReplen;
- /// <summary>
- /// 手动注水时长(秒)
- /// </summary>
- private int _manualFillSeconds;
- /// <summary>
- /// DIValveMaxOnTime
- /// </summary>
- private double _diValveMaxOnTime;
- /// <summary>
- /// 是否补水异常
- /// </summary>
- private bool _isDIReplenFault;
- /// <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>
- /// Meatl UI数据
- /// </summary>
- private ObservableCollection<ReservoirsUIData> _reservoirsUIDatas = new ObservableCollection<ReservoirsUIData>();
- #endregion
- #region 属性
- public string Module
- {
- get { return _module; }
- set { SetProperty(ref _module, value); }
- }
- public bool IsEnabled
- {
- get { return _isEnabled; }
- set { SetProperty(ref _isEnabled, value); }
- }
- public bool IsError
- {
- get { return _isError; }
- set { SetProperty(ref _isError, value); }
- }
- public bool IsAutoEnabled
- {
- get { return _isAutoEnabled; }
- set { SetProperty(ref _isAutoEnabled, value); }
- }
- public SafetyData CommonSafetyData
- {
- get { return _commonSafetyData; }
- set { SetProperty(ref _commonSafetyData, value); }
- }
- public string State
- {
- get { return _state; }
- set { SetProperty(ref _state, value); }
- }
- public ResRecipe CurrentRecipe
- {
- get { return _currentRecipe; }
- set { SetProperty(ref _currentRecipe, value); }
- }
- public ReservoirsPersistentValue ReservoirsPersistent
- {
- get { return _reservoirsPersistent; }
- set { SetProperty(ref _reservoirsPersistent, value); }
- }
- public string RecipeType
- {
- get { return _recipeType; }
- set { SetProperty(ref _recipeType, value); }
- }
- public int InputCAPumpSpeed
- {
- get { return _inputCAPumpSpeed; }
- set
- {
- SetProperty(ref _inputCAPumpSpeed, value);
- }
- }
- public int InputANPumpSpeed
- {
- get { return _inputANPumpSpeed; }
- set
- {
- SetProperty(ref _inputANPumpSpeed, value);
- }
- }
- public int InputRetrunFlowOpenPercent
- {
- get { return _inputReturnFlowOpenPercent; }
- set
- {
- SetProperty(ref _inputReturnFlowOpenPercent, value);
- }
- }
-
- public TemperatureControllerData TemperatureControlData
- {
- get { return _temperatureControlData; }
- set { SetProperty(ref _temperatureControlData, value); }
- }
- public string TCEnableStatus
- {
- get { return _tcEnableStatus; }
- set { SetProperty(ref _tcEnableStatus, value); }
- }
-
-
- public ReservoirData ReservoirData
- {
- get { return _reservoirData; }
- set { SetProperty(ref _reservoirData, value); }
- }
- public bool IsCAHighLevel
- {
- get { return _isCAHighLevel; }
- set { SetProperty(ref _isCAHighLevel, value); }
- }
- public bool IsCALowLevel
- {
- get { return _isCALowLevel; }
- set { SetProperty(ref _isCALowLevel, value); }
- }
- /// <summary>
- /// Ca Level采样周期内平均值
- /// </summary>
- public double AvgCALevel
- {
- get { return _avgCaLevel; }
- set { SetProperty(ref _avgCaLevel, value); }
- }
- /// <summary>
- /// 单次注水最大时长
- /// </summary>
- public double DIValveMaxOnTime
- {
- get { return _diValveMaxOnTime; }
- set { SetProperty(ref _diValveMaxOnTime, value); }
- }
- /// <summary>
- /// 手动注水时长
- /// </summary>
- public int ManualFillSeconds
- {
- get { return _manualFillSeconds; }
- set { SetProperty(ref _manualFillSeconds, value); }
- }
- /// <summary>
- /// 正在手动注水
- /// </summary>
- public bool IsManualReplen
- {
- get { return _isManualReplen; }
- set { SetProperty(ref _isManualReplen, value); }
- }
- /// <summary>
- /// 是否补水异常
- /// </summary>
- public bool IsDIReplenFault
- {
- get { return _isDIReplenFault; }
- set { SetProperty(ref _isDIReplenFault, value); }
- }
- #endregion
- #region 指令
- public ICommand InitializeCommand { get; set; }
- public ICommand CAPumpSpeedSetCommand { get; set; }
- public ICommand ANPumpSpeedSetCommand { get; set; }
- public ICommand ReturnFlowOpenPercentSetCommand { get; set; }
- public ICommand ResetTotalCommand { get; set; }
- public ICommand ManualDireplenCommand { get; set; }
- #endregion
- public DMReservoirViewModel()
- {
- InitializeCommand = new DelegateCommand<object>(InitializeAction);
- CAPumpSpeedSetCommand = new DelegateCommand<object>(CAPumpSpeedSetAction);
- ANPumpSpeedSetCommand = new DelegateCommand<object>(ANPumpSpeedSetAction);
- ReturnFlowOpenPercentSetCommand = new DelegateCommand<object>(ReturnFlowOpenPercentSetAction);
- ResetTotalCommand = new DelegateCommand<object>(ResetTotalAction);
- ManualDireplenCommand = new DelegateCommand<object>(ManualDireplenAction);
- }
- #region 命令方法
- /// <summary>
- /// 初始化
- /// </summary>
- /// <param name="param"></param>
- private void InitializeAction(object param)
- {
- InvokeClient.Instance.Service.DoOperation($"{Module}.InitializeAll");
- }
- /// <summary>
- /// 设置CA pump泵速
- /// </summary>
- /// <param name="param"></param>
- private void CAPumpSpeedSetAction(object param)
- {
- if (InputCAPumpSpeed>100 || InputCAPumpSpeed < 0)
- {
- MessageBox.Show($"Input CAPumpSpeed value in 0~100", "Error",
- MessageBoxButton.OK, MessageBoxImage.Error);
- return;
- }
- InvokeClient.Instance.Service.DoOperation($"{Module}.CAPumpSpeed",InputCAPumpSpeed);
- }
- /// <summary>
- /// 设置AN pump泵速
- /// </summary>
- /// <param name="param"></param>
- private void ANPumpSpeedSetAction(object param)
- {
- if (InputANPumpSpeed > 100 || InputANPumpSpeed < 0)
- {
- MessageBox.Show($"Input ANPumpSpeed value in 0~100", "Error",
- MessageBoxButton.OK, MessageBoxImage.Error);
- return;
- }
- InvokeClient.Instance.Service.DoOperation($"{Module}.ANPumpSpeed", InputANPumpSpeed);
- }
- /// <summary>
- /// 设置return flow valve开闭的程度
- /// </summary>
- /// <param name="param"></param>
- private void ReturnFlowOpenPercentSetAction(object param)
- {
- if (InputRetrunFlowOpenPercent > 100 || InputRetrunFlowOpenPercent < 0)
- {
- MessageBox.Show($"Input RetrunFlowOpenPercent value in 0~100", "Error",
- MessageBoxButton.OK, MessageBoxImage.Error);
- return;
- }
- InvokeClient.Instance.Service.DoOperation($"{Module}.ReturnValvePercent", InputRetrunFlowOpenPercent);
- }
- /// <summary>
- /// 重置TotalTime
- /// </summary>
- private void ResetTotalAction(object param)
- {
- InvokeClient.Instance.Service.DoOperation($"{Module}.ResetTotalTime");
- }
- /// <summary>
- /// 手动注水
- /// </summary>
- /// <param name="param"></param>
- private void ManualDireplenAction(object param)
- {
- InvokeClient.Instance.Service.DoOperation($"{Module}.ManualCADiReplen", ManualFillSeconds);
- }
- #endregion
- public void LoadData(string systemName)
- {
- RecipeType = "res";
- Module = systemName;
- _rtDataKeys.Clear();
- _rtDataKeys.Add($"{Module}.{PERSISTENT_VALUE}");
- _rtDataKeys.Add($"{Module}.CurrentRecipe");
- _rtDataKeys.Add($"{Module}.FsmState");
- _rtDataKeys.Add($"Safety.SafetyData");
- _rtDataKeys.Add($"{Module}.ReservoirData");
- _rtDataKeys.Add($"{Module}.IsCAHighLevel");
- _rtDataKeys.Add($"{Module}.IsCALowLevel");
- _rtDataKeys.Add($"{Module}.TemperatureControllerData");
- _rtDataKeys.Add($"{Module}.DIValveMaxOnTime");
- _rtDataKeys.Add($"{Module}.IsManualCAReplen");
- _rtDataKeys.Add($"{Module}.IsDIReplenPerfillTimeOut");
- _rtDataKeys.Add($"{Module}.IsDIReplenMaxTimeOut");
- _rtDataKeys.Add($"{Module}.AvgCALevel");
- 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");
- ReservoirData = CommonFunction.GetValue<ReservoirData>(_rtDataValueDic, $"{Module}.ReservoirData");
- CommonSafetyData = CommonFunction.GetValue<SafetyData>(_rtDataValueDic, $"Safety.SafetyData");
- ReservoirsPersistent = CommonFunction.GetValue<ReservoirsPersistentValue>(_rtDataValueDic, $"{Module}.{PERSISTENT_VALUE}");
- if (ReservoirsPersistent!= null && "Manual".Equals(ReservoirsPersistent.OperatingMode))
- {
- IsEnabled = true;
- IsAutoEnabled = true;
- }
- else if (ReservoirsPersistent != null && "Auto".Equals(ReservoirsPersistent.OperatingMode))
- {
- IsAutoEnabled = true;
- IsEnabled = false;
- }
- else
- {
- State = "Stopped";
- IsEnabled = false;
- IsAutoEnabled = false;
- }
- CurrentRecipe = CommonFunction.GetValue<ResRecipe>(_rtDataValueDic, $"{Module}.CurrentRecipe");
- TemperatureControlData = CommonFunction.GetValue<TemperatureControllerData>(_rtDataValueDic, $"{Module}.TemperatureControllerData");
- TCEnableStatus = TemperatureControlData.ControlOperationModel == 0 ? "Disable" : "Enable";
- _tcName = TemperatureControlData.Name;
- IsCAHighLevel = CommonFunction.GetValue<bool>(_rtDataValueDic, $"{Module}.IsCAHighLevel");
- IsCALowLevel = CommonFunction.GetValue<bool>(_rtDataValueDic, $"{Module}.IsCALowLevel");
- AvgCALevel = CommonFunction.GetValue<double>(_rtDataValueDic, $"{Module}.AvgCALevel");
- DIValveMaxOnTime = CommonFunction.GetValue<double>(_rtDataValueDic, $"{Module}.DIValveMaxOnTime");
- IsManualReplen = CommonFunction.GetValue<bool>(_rtDataValueDic, $"{Module}.IsManualCAReplen");
- IsDIReplenFault = CommonFunction.GetValue<bool>(_rtDataValueDic, $"{Module}.IsDIReplenPerfillTimeOut")
- || CommonFunction.GetValue<bool>(_rtDataValueDic, $"{Module}.IsDIReplenMaxTimeOut");
- }
- }
- }
- /// <summary>
- /// 隐藏
- /// </summary>
- public void Hide()
- {
- if (_timer != null)
- {
- _timer.Stop();
- }
- }
- }
- }
|