123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230 |
- using LiveCharts;
- using MECF.Framework.Common.DataCenter;
- using MECF.Framework.Common.OperationCenter;
- using Microsoft.Win32;
- using Prism.Commands;
- using Prism.Mvvm;
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Threading;
- using Venus_Core;
- using Venus_MainPages.Unity;
- using Venus_Unity;
- namespace Venus_MainPages.ViewModels
- {
- internal class PartialPressureViewModel : BindableBase
- {
- #region 私有字段
- private List<string> m_RtConfigKeys=new List<string>();
- private Dictionary<string, object> m_RtConfigValues=new Dictionary<string, object> ();
- private Dictionary<int, object> m_GasFlows = new Dictionary<int, object>();
- private object[] m_GasPressures = new object[10];
- private string m_ModuleName = "PMA";
- private int m_GasIndex;
- ChartValues<double> m_CurrentLineSeries= new ChartValues<double>();
- ChartValues<double> m_ReferenceLineSeries = new ChartValues<double>();
- DispatcherTimer timer = new DispatcherTimer();
- private int m_GasTime;
- private PartialPressureResult m_partialPressureResult;
- string value;
- int maxScale;
- ObservableCollection<string> m_ReferenceFlow = new ObservableCollection<string>();
- #endregion
- #region 属性
- public ObservableCollection<string> ReferenceFlow
- {
- get { return m_ReferenceFlow; }
- set { SetProperty(ref m_ReferenceFlow, value); }
- }
- public Dictionary<string, object> RtConfigValues
- {
- get { return m_RtConfigValues; }
- set { SetProperty(ref m_RtConfigValues, value); }
- }
- public string ModuleName
- {
- get { return m_ModuleName; }
- set { SetProperty(ref m_ModuleName, value); }
- }
- public Dictionary<int, object> GasFlows
- {
- get { return m_GasFlows; }
- set { SetProperty(ref m_GasFlows, value); }
- }
- public ChartValues<double> CurrentLineSeries
- {
- get { return m_CurrentLineSeries; }
- set { SetProperty(ref m_CurrentLineSeries, value); }
- }
- public ChartValues<double> ReferenceLineSeries
- {
- get { return m_ReferenceLineSeries; }
- set { SetProperty(ref m_ReferenceLineSeries, value); }
- }
- public int GasTime
- {
- get { return m_GasTime; }
- set { SetProperty(ref m_GasTime, value); }
- }
- #endregion
- #region 命令
- private DelegateCommand<object> _SelectGasCommand;
- public DelegateCommand<object> SelectGasCommand =>
- _SelectGasCommand ?? (_SelectGasCommand = new DelegateCommand<object>(OnSelectGas));
- private DelegateCommand _StartCommand;
- public DelegateCommand StartCommand =>
- _StartCommand ?? (_StartCommand = new DelegateCommand(OnStart));
- private DelegateCommand _SaveCommand;
- public DelegateCommand SaveCommand =>
- _SaveCommand ?? (_SaveCommand = new DelegateCommand(OnSave));
- private DelegateCommand _LoadReferenceCommand;
- public DelegateCommand LoadReferenceCommand =>
- _LoadReferenceCommand ?? (_LoadReferenceCommand = new DelegateCommand(OnLoadReference));
- private DelegateCommand _AbortCommand;
- public DelegateCommand AbortCommand =>
- _AbortCommand ?? (_AbortCommand = new DelegateCommand(OnAbort));
- #endregion
- #region 构造函数
- public PartialPressureViewModel()
- {
- ModuleName = "PMA";
- addConfigKeys();
- GasTime = 60;
-
- foreach (var item in QueryDataClient.Instance.Service.PollConfig(m_RtConfigKeys))
- {
- var newkey = item.Key.Substring(4, item.Key.Length-4);
- RtConfigValues.Add(newkey, item.Value);
- }
- timer.Interval = TimeSpan.FromSeconds(1);
- timer.Tick += Timer_Tick;
- OnSelectGas(1);
- }
-
- #endregion
- #region 命令方法
- private void OnSelectGas(object obj)
- {
- Dictionary<int, object> CurrentGasFlows = new Dictionary<int, object>();
- value = $"MfcGas{obj.ToString()}";
- maxScale = Convert.ToInt32(RtConfigValues[$"{value}.MfcN2Scale"]);
- var xishu = Convert.ToDouble(QueryDataClient.Instance.Service.GetConfig($"{ModuleName}.{value}.MfcScaleFactor"));
- for (int i = 1; i < 11; i++)
- {
- CurrentGasFlows.Add(i, (int)(maxScale *xishu / 10 * i));
- }
- GasFlows = CurrentGasFlows;
- m_GasIndex = Convert.ToInt32(obj);
- }
- private void OnStart()
- {
- m_partialPressureResult = new PartialPressureResult();
- m_partialPressureResult.StartTime = DateTime.Now.ToString();
- m_partialPressureResult.FlowTime = GasTime;
- m_partialPressureResult.GasName = value;
- CurrentLineSeries = new ChartValues<double>();
- timer.Start();
- InvokeClient.Instance.Service.DoOperation($"{ModuleName}.PartialPressureTest", m_GasIndex,1000* GasTime);
- }
- private void OnSave()
- {
- SerializeHelper.Instance.WriteToJsonFile<PartialPressureResult>(m_partialPressureResult, $"PartialPressureResult/{m_partialPressureResult.GasName}/{DateTime.Now.ToString("yyyyMMddHHmm")}.json");
- }
- private void OnLoadReference()
- {
- OpenFileDialog dialog = new OpenFileDialog();
- dialog.Filter = ".json|*.json";
- dialog.InitialDirectory = Path.Combine(Directory.GetCurrentDirectory(), "PartialPressureResult") ;
- if (dialog.ShowDialog() == true)
- {
- string SelectedPath = dialog.FileName;
- var value = SerializeHelper.Instance.ReadFromJsonFile<PartialPressureResult>(SelectedPath);
- ReferenceLineSeries.Clear();
- ReferenceFlow.Clear();
- value.ValuePairs.ForEach(x =>
- {
- ReferenceFlow.Add(x.Flow);
- ReferenceLineSeries.Add(x.Pressure);
- });
- }
- else
- {
- ReferenceLineSeries.Clear();
- //ReferenceLineSeries.Insert(20, 0);
- ReferenceLineSeries.Add(0);
- ReferenceFlow.Clear();
- }
-
- }
- private void OnAbort()
- {
- timer.Stop();
- InvokeClient.Instance.Service.DoOperation($"{ModuleName}.Abort");
- CurrentLineSeries = new ChartValues<double>();
- }
- #endregion
- #region 私有方法
- private void Timer_Tick(object sender, EventArgs e)
- {
- var counter= (int)QueryDataClient.Instance.Service.GetData($"{ModuleName}.PartialPressureCounter");
- if (counter >=2 && counter<=11 && counter>CurrentLineSeries.Count+1)
- {
- var pressureValue = Convert.ToDouble(QueryDataClient.Instance.Service.GetData($"{ModuleName}.ProcessPressureLow.Value"));
- CurrentLineSeries.Add(pressureValue);
- //m_partialPressureResult.ValuePairs.Add($"{(counter-1) * 10}%", pressureValue);
- m_partialPressureResult.ValuePairs.Add(new Value() { Flow = GasFlows[counter - 1].ToString(), Pressure = Math.Round(pressureValue,3) });
- }
- if (counter == 11)
- {
- m_partialPressureResult.EndTime = DateTime.Now.ToString();
- //m_partialPressureResult.Result = "Success";
- timer.Stop();
- }
- }
- private void addConfigKeys()
- {
- m_RtConfigKeys.Add($"{ModuleName}.MfcGas1.GasName");
- m_RtConfigKeys.Add($"{ModuleName}.MfcGas1.MfcN2Scale");
- m_RtConfigKeys.Add($"{ModuleName}.MfcGas2.GasName");
- m_RtConfigKeys.Add($"{ModuleName}.MfcGas2.MfcN2Scale");
- m_RtConfigKeys.Add($"{ModuleName}.MfcGas3.GasName");
- m_RtConfigKeys.Add($"{ModuleName}.MfcGas3.MfcN2Scale");
- m_RtConfigKeys.Add($"{ModuleName}.MfcGas4.GasName");
- m_RtConfigKeys.Add($"{ModuleName}.MfcGas4.MfcN2Scale");
- m_RtConfigKeys.Add($"{ModuleName}.MfcGas5.GasName");
- m_RtConfigKeys.Add($"{ModuleName}.MfcGas5.MfcN2Scale");
- m_RtConfigKeys.Add($"{ModuleName}.MfcGas6.GasName");
- m_RtConfigKeys.Add($"{ModuleName}.MfcGas6.MfcN2Scale");
- m_RtConfigKeys.Add($"{ModuleName}.MfcGas7.GasName");
- m_RtConfigKeys.Add($"{ModuleName}.MfcGas7.MfcN2Scale");
- m_RtConfigKeys.Add($"{ModuleName}.MfcGas8.GasName");
- m_RtConfigKeys.Add($"{ModuleName}.MfcGas8.MfcN2Scale");
- }
- #endregion
- }
- }
|