using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Diagnostics; using System.Linq; using System.Reflection; using System.Text; using System.Threading.Tasks; using System.Windows.Controls; using Aitex.Core.Common.DeviceData; using Aitex.Core.RT.IOCore; using Aitex.Core.RT.Log; using Aitex.Core.UI.DeviceControl; using Aitex.Core.Util; using Caliburn.Micro.Core; using FurnaceUI.Models; using FurnaceUI.Views.Recipes; using MECF.Framework.Common.CommonData.DeviceData; using MECF.Framework.Common.DataCenter; using MECF.Framework.Common.Device; using MECF.Framework.Common.OperationCenter; using OpenSEMI.ClientBase; namespace FurnaceUI.Views.Maintenances { public class FFUConfigViewModel : FurnaceUIViewModelBase { public bool SetField(ref T field, T value, string propertyName) { if (EqualityComparer.Default.Equals(field, value)) return false; field = value; NotifyOfPropertyChange(propertyName); return true; } [Subscription("System.FFUKeyDict")] public List FFUKeyDict { get; set; } private ObservableCollection _ffuDatas = new ObservableCollection(); public ObservableCollection FFUDataList { get => _ffuDatas; set { _ffuDatas = value; NotifyOfPropertyChange(nameof(FFUDataList)); } } private bool _powerOffVisibility = false; public bool PowerOffVisibility { get => _powerOffVisibility; set => SetField(ref _powerOffVisibility, value, nameof(PowerOffVisibility)); } private bool _powerOnVisibility = true; public bool PowerOnVisibility { get => _powerOnVisibility; set => SetField(ref _powerOnVisibility, value, nameof(PowerOnVisibility)); } Dictionary ffuDictionary = new Dictionary(); protected override void OnActivate() { base.OnActivate(); FFUKeyDict = QueryDataClient.Instance.Service.GetData("System.FFUKeyDict") as List; FFUDataList.Clear(); foreach (var item in FFUKeyDict) { var deviceName = item.Split('.').ToList()[1]; FFUDataList.Add(new FFUData() { DisplayName = deviceName, }); } ffuDictionary = FFUDataList.ToDictionary(a => a.DisplayName); } protected override void InvokeAfterUpdateProperty(Dictionary data) { base.InvokeAfterUpdateProperty(data); var values = QueryDataClient.Instance.Service.PollData(FFUKeyDict).Values.Select(a => (a as AITFFUData)).ToList(); if (ffuDictionary != null) { foreach (var item in values) { if (item==null || !ffuDictionary.TryGetValue(item.DisplayName, out var ffu)) continue; ffu.MaxValue = item.Max.ToString(); ffu.MinValue = item.Min.ToString(); ffu.ActualValue = item.Feedback; ffu.IsSwitch = item.IsSwitchOn; ffu.Value = item.SetPoint.ToString(); ffu.LastSetValue = item.SetPoint; } } } async void DelayData(string type, object sender, object item) { await WaitForResultsAsync(); if (!string.IsNullOrEmpty(type) && item != null && sender != null) { var dataItem = item as FFUData; string value = ((TextBox)sender).Text; var setValue = double.Parse(value); var max = double.Parse(dataItem.MaxValue); var min = double.Parse(dataItem.MinValue); if (setValue != dataItem.LastSetValue) { //if (setValue < min || setValue > max) //{ // DialogBox.ShowWarning($"{dataItem.DisplayName} setValue={setValue}, limit is ({min}, {max})"); // return; //} InvokeClient.Instance.Service.DoOperation($"PM1.{dataItem.DisplayName}.SetCurrectSpeed", value); } } } private async Task WaitForResultsAsync() { // Simulate waiting for results using a delay // In a real-world scenario, you might wait for an event or a specific condition await Task.Delay(10); // Here you can add logic to check if the results are ready // For example, polling or using a completion source } public void AllFFUPower(string value) { var setValue = bool.Parse(value); if (setValue) { PowerOnVisibility = false; PowerOffVisibility = true; } else { PowerOnVisibility = true; PowerOffVisibility = false; } InvokeClient.Instance.Service.DoOperation($"PM1.SetAllFFUPower", setValue); } public void SetValueTextChanged(string type, object sender, object item) { try { DelayData(type,sender,item); } catch (Exception ex) { LOG.Write(ex); } } } public class FFUData : PropertyChangedBase { private int _no; public int No { get => _no; set { _no = value; NotifyOfPropertyChange(nameof(No)); } } private string _displayName; public string DisplayName { get => _displayName; set { _displayName = value; NotifyOfPropertyChange(nameof(DisplayName)); } } private double _lastSetValue; public double LastSetValue { get => _lastSetValue; set { _lastSetValue = value; NotifyOfPropertyChange(nameof(LastSetValue)); } } private double _actualValue; public double ActualValue { get => _actualValue; set { _actualValue = value; NotifyOfPropertyChange(nameof(ActualValue)); } } private string _value; public string Value { get => _value; set { _value = value; NotifyOfPropertyChange(nameof(Value)); } } private bool _isSwitch; public bool IsSwitch { get => _isSwitch; set { _isSwitch = value; NotifyOfPropertyChange(nameof(IsSwitch)); } } private string _maxValue; public string MaxValue { get => _maxValue; set { _maxValue = value; NotifyOfPropertyChange(nameof(MaxValue)); } } private string _minValue; public string MinValue { get => _minValue; set { _minValue = value; NotifyOfPropertyChange(nameof(MinValue)); } } private bool _isSetChanged = true; public bool IsSetChanged { get => _isSetChanged; set { _isSetChanged = value; NotifyOfPropertyChange(nameof(IsSetChanged)); } } } }