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.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 _rtDataKeys = new List(); private Dictionary _rtDataValueDic = new Dictionary(); 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 ObservableCollection _recipeNodes; private string _currentRecipeFileName; private double _returnValveOpenPerccent; private bool _isCADIReplenFault; private bool _isANDIReplenFault; private double _flowAdjustDelta; private double _maxFlowDelta; private bool _isFolwDeltaUnBlance = false; private bool _isHighLevel; private bool _isLowLevel; private bool _isLeakDetected; private bool _cdaOn; /// /// 是否配置Exhaust /// private bool _isEvaporatorConfig; /// /// 是否正在手动注水 /// private bool _isManualReplen; /// /// 手动注水时长(秒) /// private int _manualFillSeconds; /// /// DIValveMaxOnTime /// private double _diValveMaxOnTime; /// /// CellModuleName集合 /// private ObservableCollection _cellModuleNameCollection = new ObservableCollection(); /// /// Cell A面Flow集合 /// private ObservableCollection _cellModuleNameFlowCollection = new ObservableCollection(); /// /// MetalData /// private ObservableCollection _metalDatas = new ObservableCollection(); /// /// MetalData的CellFlow集合 /// private ObservableCollection _metalCellFlowDatas = new ObservableCollection(); /// /// Meatl UI数据 /// private ObservableCollection _reservoirsUIDatas = new ObservableCollection(); #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); } } #endregion #region 指令 public ICommand InitializeCommand { get; set; } public ICommand CAPumpSpeedSetCommand { get; set; } public ICommand ANPumpSpeedSetCommand { get; set; } public ICommand ReturnFlowOpenPercentSetCommand { get; set; } #endregion public DMReservoirViewModel() { InitializeCommand = new DelegateCommand(InitializeAction); CAPumpSpeedSetCommand = new DelegateCommand(CAPumpSpeedSetAction); ANPumpSpeedSetCommand = new DelegateCommand(ANPumpSpeedSetAction); ReturnFlowOpenPercentSetCommand = new DelegateCommand(ReturnFlowOpenPercentSetAction); } #region 命令方法 /// /// 初始化 /// /// private void InitializeAction(object param) { InvokeClient.Instance.Service.DoOperation($"{Module}.InitializeAll"); } /// /// 设置CA pump泵速 /// /// private void CAPumpSpeedSetAction(object param) { InvokeClient.Instance.Service.DoOperation($"{Module}.CAPumpSpeed",InputCAPumpSpeed); } /// /// 设置AN pump泵速 /// /// private void ANPumpSpeedSetAction(object param) { InvokeClient.Instance.Service.DoOperation($"{Module}.ANPumpSpeed", InputANPumpSpeed); } /// /// 设置return flow valve开闭的程度 /// /// private void ReturnFlowOpenPercentSetAction(object param) { InvokeClient.Instance.Service.DoOperation($"{Module}.InitializeAll"); } #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}.TemperatureControllerData"); 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(_rtDataValueDic, $"{Module}.FsmState"); ReservoirData = CommonFunction.GetValue(_rtDataValueDic, $"{Module}.ReservoirData"); CommonSafetyData = CommonFunction.GetValue(_rtDataValueDic, $"Safety.SafetyData"); ReservoirsPersistent = CommonFunction.GetValue(_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(_rtDataValueDic, $"{Module}.CurrentRecipe"); //TemperatureControlData = CommonFunction.GetValue(_rtDataValueDic, $"{Module}.TemperatureControllerData"); //TCEnableStatus = TemperatureControlData.ControlOperationModel == 0 ? "Disable" : "Enable"; //_tcName = TemperatureControlData.Name; } } } /// /// 隐藏 /// public void Hide() { if (_timer != null) { _timer.Stop(); } } } }