123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817 |
- using HandyControl.Interactivity;
- using HandyControl.Interactivity.Commands;
- using OxyPlot;
- using Shaker.Model;
- using Shaker.ViewModel;
- using ShakerManger.Data;
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.ComponentModel.DataAnnotations;
- using System.Diagnostics.CodeAnalysis;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Input;
- using System.Windows.Media;
- namespace ShakerManger.ViewModel
- {
- internal class ShakerControlViewModel:Shaker.ViewModel.DisplayViewModel<Shaker.Model.ShakerControlModel>
- {
- private object locker = new object();
- public string ClientID { get => Model.ClientID; set => UpdateProperty(ref Model.ClientID, value); }
- public int MaxItemCount => 1000;
- private ObservableCollection<DataMangerItemViewModel> Items { get; } = new ObservableCollection<DataMangerItemViewModel>();
- public OxyPlot.PlotModel MinPlotModel { get; } = new PlotModel();
- private List<OxyPlot.Series.LineSeries> _MinLineSeries = new List<OxyPlot.Series.LineSeries>();
- private List<OxyPlot.Series.LineSeries> _LineSeries = new List<OxyPlot.Series.LineSeries>();
- public string[] PropertiyNames { get; }= new string[]
- {
- nameof(DataMangerItemViewModel.OperatingStatus),
- nameof(DataMangerItemViewModel.OutputCurrent),
- nameof(DataMangerItemViewModel.OutputVoltage),
- nameof(DataMangerItemViewModel.ExcitationCurrent),
- nameof(DataMangerItemViewModel.ExcitationVoltage),
- nameof(DataMangerItemViewModel.ThreePhaseVoltage),
- nameof(DataMangerItemViewModel.AbutmentTemperature0),
- nameof(DataMangerItemViewModel.AbutmentTemperature1),
- nameof(DataMangerItemViewModel.DCVoltage1),
- nameof(DataMangerItemViewModel.DCVoltage2),
- nameof(DataMangerItemViewModel.DCVoltage3),
- nameof(DataMangerItemViewModel.DCVoltage4),
- nameof(DataMangerItemViewModel.ExternalCirculatingWaterPressure),
- nameof(DataMangerItemViewModel.ExternalCirculatingWaterFlow),
- nameof(DataMangerItemViewModel.ExternalCirculatingWaterTemperature),
- nameof(DataMangerItemViewModel.MovingCoilWaterSupplyPressure),
- nameof(DataMangerItemViewModel.MovingCoilWaterSupplyFlow),
- nameof(DataMangerItemViewModel.MovingCoilWaterSupplyTemperature),
- nameof(DataMangerItemViewModel.ExcitationWaterSupplyPressure),
- nameof(DataMangerItemViewModel.ExcitationWaterSupplyFlow),
- nameof(DataMangerItemViewModel.ExcitationWaterSupplyTemperature),
- nameof(DataMangerItemViewModel.CoolingWaterStatus),
- nameof(DataMangerItemViewModel.Gain),
- };
- public ICommand MenuShowCommand => new DelegateCommand<ExCommandParameter>(MenuShow);
- private void MenuShow(ExCommandParameter parameter)
- {
- if(parameter.EventArgs is MouseButtonEventArgs args)
- {
- if (args.ChangedButton == MouseButton.Right)
- {
- MenuIsOpen = true;
- }
- }
- }
- public ICommand DisConnectCommand=> new DelegateCommand(DisConnect);
- private void DisConnect()
- {
- PromptViewModel.Default.Init();
- PromptViewModel.Default.IconType = IconType.Ask;
- PromptViewModel.Default.Message = "是否断开功放连接?";
- PromptViewModel.Default.YesAction = async ()=>
- {
- var result = await BusManger.Defaut.Bus.RPC.RequestAsync<Shaker.Model.SysControl, Shaker.Model.Result>(new SysControl()
- {
- Cmd = SysCmd.DisConnect,
- }, Properties);
- if (result == null ||!result.Success)
- {
- PromptViewModel.Default.Init();
- PromptViewModel.Default.IconType = IconType.Error;
- PromptViewModel.Default.Message = result == null? "通信超时" : result.Message;
- PromptViewModel.Default.NoVisibility = Visibility.Collapsed;
- PromptViewModel.Default.IsOpen = true;
- }
- };
- PromptViewModel.Default.IsOpen = true;
- }
- public ICommand ConnectCommand => new DelegateCommand(Connect);
- private async void Connect()
- {
- var result = await BusManger.Defaut.Bus.RPC.RequestAsync<Shaker.Model.SysControl, Shaker.Model.Result>(new SysControl()
- {
- Cmd = SysCmd.Connect,
- },Properties);
- if(result == null || !result.Success)
- {
- PromptViewModel.Default.Init();
- PromptViewModel.Default.IconType = IconType.Error;
- PromptViewModel.Default.Message = result == null?"通信超时": result.Message;
- PromptViewModel.Default.NoVisibility = Visibility.Collapsed;
- PromptViewModel.Default.IsOpen= true;
- }
- }
- public bool IsOnline { get => isOnline; set =>UpdateProperty(ref isOnline, value); }
- public DataMangerItemViewModel CurrentData { get => currentData; set =>UpdateProperty(ref currentData, value); }
- public Boolean SetPlotConfigIsOpen
- {
- get => setPlotConfigIsOpen;
- set
- {
- UpdateProperty(ref setPlotConfigIsOpen, value);
- if(value)
- {
- foreach(var item in PlotConfig)
- {
- item.Init();
- }
- }
- }
- }
- public bool MenuIsOpen { get => menuIsOpen; set =>UpdateProperty(ref menuIsOpen , value); }
- private Data.ShakerViewType lastviewType = ShakerViewType.ShakerControl;
- public Data.ShakerViewType ShakerView
- {
- get => shakerView;
- set
- {
- if (shakerView == value) return;
- MenuIsOpen = false;
- UpdateProperty(ref shakerView, value);
- }
- }
- public bool IsDeviceControl { get => isDeviceControl; set =>UpdateProperty(ref isDeviceControl , value); }
- public bool IsConnected
- {
- get => isConnected;
- set
- {
- if (isConnected == value) return;
- UpdateProperty(ref isConnected, value);
- if (value)
- {
- ShakerView = lastviewType;
- }
- else
- {
- lastviewType = ShakerView;
- ShakerView = ShakerViewType.None;
- }
- }
- }
- private bool isVisible = false;
- public bool IsVisible { get => isVisible; set => UpdateProperty(ref isVisible, value); }
- public string[] AnalogNames { get; } = new string[Shaker.Model.DataMangerItemModel.ANALOG_DATA_LENGTH];
- public string[] Units { get; } = new string[Shaker.Model.DataMangerItemModel.ANALOG_DATA_LENGTH];
- private Dictionary<string, string> Properties { get; init; } = new Dictionary<string, string>();
- public ObservableCollection<PlotConfigViewModel> PlotConfig { get; } = new ObservableCollection<PlotConfigViewModel>();
- public ShakerControlViewModel(Shaker.Model.ShakerControlModel model)
- {
- Model = model;
- Values.Add(new PLCAnlogViewModel(model.ExcitationVoltage));
- Values.Add(new PLCAnlogViewModel(model.ExcitationCurrent));
- Values.Add(new PLCAnlogViewModel(model.ThreePhaseVoltage));
- Values.Add(new PLCAnlogViewModel(model.AbutmentTemperature0));
- Values.Add(new PLCAnlogViewModel(model.AbutmentTemperature1));
- Values.Add(new PLCAnlogViewModel(model.DCVoltage1));
- Values.Add(new PLCAnlogViewModel(model.DCVoltage2));
- Values.Add(new PLCAnlogViewModel(model.DCVoltage3));
- Values.Add(new PLCAnlogViewModel(model.DCVoltage4));
- CoolingWaterValues.Add(new PLCAnlogViewModel(model.ExternalCirculatingWaterPressure));
- CoolingWaterValues.Add(new PLCAnlogViewModel(model.ExternalCirculatingWaterFlow));
- CoolingWaterValues.Add(new PLCAnlogViewModel(model.ExternalCirculatingWaterTemperature));
- CoolingWaterValues.Add(new PLCAnlogViewModel(model.MovingCoilWaterSupplyPressure));
- CoolingWaterValues.Add(new PLCAnlogViewModel(model.MovingCoilWaterSupplyFlow));
- CoolingWaterValues.Add(new PLCAnlogViewModel(model.MovingCoilWaterSupplyTemperature));
- CoolingWaterValues.Add(new PLCAnlogViewModel(model.ExcitationWaterSupplyPressure));
- CoolingWaterValues.Add(new PLCAnlogViewModel(model.ExcitationWaterSupplyFlow));
- CoolingWaterValues.Add(new PLCAnlogViewModel(model.ExcitationWaterSupplyTemperature));
- CurrentData = new DataMangerItemViewModel(new DataMangerItemModel());
- CurrentData.PropertyChanged += (sender, args) =>
- {
- if(args.PropertyName == nameof(DataMangerItemViewModel.OperatingStatus))
- {
- OnPropertyChanged(nameof(GainEnabled));
- OnPropertyChanged(nameof(GainSwitchEnabled));
- OnPropertyChanged(nameof(StartEnabled));
- OnPropertyChanged(nameof(StopEnabled));
- OnPropertyChanged(nameof(ResetEnabled));
- }
- };
- Properties[Shaker.Model.GlobalVariable.ShakerIDKey] = model.Id;
- AnalogNames[0] = Model.OperatingStatus.Name;
- AnalogNames[1] = Model.OutputCurrent.Name;
- AnalogNames[2] = Model.OutputVoltage.Name;
- AnalogNames[3] = Model.ExcitationCurrent.Name;
- AnalogNames[4] = Model.ExcitationVoltage.Name;
- AnalogNames[5] = Model.ThreePhaseVoltage.Name;
- Units[0] = Model.OperatingStatus.Unit;
- Units[1] = Model.OutputCurrent.Unit;
- Units[2] = Model.OutputVoltage.Unit;
- Units[3] = Model.ExcitationCurrent.Unit;
- Units[4] = Model.ExcitationVoltage.Unit;
- Units[5] = Model.ThreePhaseVoltage.Unit;
- if (!string.IsNullOrEmpty(model.AbutmentTemperature0.Name))
- {
- AnalogNames[6] = Model.AbutmentTemperature0.Name;
- Units[6] = Model.AbutmentTemperature0.Unit;
- }
- if (!string.IsNullOrEmpty(model.AbutmentTemperature1.Name))
- {
- AnalogNames[7] = Model.AbutmentTemperature1.Name;
- Units[7] = Model.AbutmentTemperature1.Unit;
- }
- if (!string.IsNullOrEmpty(model.DCVoltage1.Name))
- {
- AnalogNames[8] = Model.DCVoltage1.Name;
- Units[8] = Model.DCVoltage1.Unit;
- }
- if (!string.IsNullOrEmpty(model.DCVoltage2.Name))
- {
- AnalogNames[9] = Model.DCVoltage2.Name;
- Units[9] = Model.DCVoltage2.Unit;
- }
- if (!string.IsNullOrEmpty(model.DCVoltage3.Name))
- {
- AnalogNames[10] = Model.DCVoltage3.Name;
- Units[10] = Model.DCVoltage3.Unit;
- }
- if (!string.IsNullOrEmpty(model.DCVoltage4.Name))
- {
- AnalogNames[11] = Model.DCVoltage4.Name;
- Units[11] = Model.DCVoltage4.Unit;
- }
- AnalogNames[12] = Model.ExternalCirculatingWaterPressure.Name;
- Units[12] = Model.ExternalCirculatingWaterPressure.Unit;
- AnalogNames[13] = Model.ExternalCirculatingWaterFlow.Name;
- Units[13] = Model.ExternalCirculatingWaterFlow.Unit;
- AnalogNames[14] = Model.ExternalCirculatingWaterTemperature.Name;
- Units[14] = Model.ExternalCirculatingWaterTemperature.Unit;
- AnalogNames[15] = Model.MovingCoilWaterSupplyPressure.Name;
- Units[15] = Model.MovingCoilWaterSupplyPressure.Unit;
- AnalogNames[16] = Model.MovingCoilWaterSupplyFlow.Name;
- Units[16] = Model.MovingCoilWaterSupplyFlow.Unit;
- AnalogNames[17] = Model.MovingCoilWaterSupplyTemperature.Name;
- Units[17] = Model.MovingCoilWaterSupplyTemperature.Unit;
- AnalogNames[18] = Model.ExcitationWaterSupplyPressure.Name;
- Units[18] = Model.ExcitationWaterSupplyPressure.Unit;
- AnalogNames[19] = Model.ExcitationWaterSupplyFlow.Name;
- Units[19] = Model.ExcitationWaterSupplyFlow.Unit;
- AnalogNames[20] = Model.ExcitationWaterSupplyTemperature.Name;
- Units[20] = Model.ExcitationWaterSupplyTemperature.Unit;
- AnalogNames[21] = Model.CoolingWaterOperatingStatus.Name;
- Units[21] = Model.CoolingWaterOperatingStatus.Unit;
- PlotModel.TextColor = OxyColors.White;
- PlotModel.TitleColor = OxyColors.White;
- PlotModel.PlotAreaBorderColor = OxyColors.White;
- PlotModel.Axes.Add(new OxyPlot.Axes.DateTimeAxis()
- {
- Title = "时间",
- Position = OxyPlot.Axes.AxisPosition.Bottom,
- Key = "X",
- MaximumPadding = 0,
- MajorGridlineColor = OxyPlot.OxyColors.Gray,
- MajorGridlineStyle = LineStyle.Dot,
- MajorGridlineThickness = 1,
- MinimumPadding = 0,
- ExtraGridlineColor = OxyPlot.OxyColors.White,
- TextColor = OxyColors.White,
- TitleColor = OxyColors.White,
- AxislineColor = OxyColors.White,
- TicklineColor = OxyColors.White,
- });
- PlotModel.Axes.Add(new OxyPlot.Axes.LinearAxis()
- {
- Title = "值",
- Position = OxyPlot.Axes.AxisPosition.Left,
- Key = "Y",
- MajorGridlineStyle = LineStyle.Dot,
- MajorGridlineColor = OxyPlot.OxyColors.Gray,
- MajorGridlineThickness = 1,
- ExtraGridlineColor = OxyPlot.OxyColors.White,
- TextColor = OxyColors.White,
- TitleColor = OxyColors.White,
- AxislineColor = OxyColors.White,
- TicklineColor = OxyColors.White,
- });
- for (int i = 0; i < AnalogNames.Length-1; i++)
- {
- if (string.IsNullOrEmpty(AnalogNames[i]) || i == 0) continue;
- OxyPlot.Series.LineSeries lineSeries = new OxyPlot.Series.LineSeries();
- lineSeries.Title = AnalogNames[i];
- lineSeries.StrokeThickness = 1;
- lineSeries.XAxisKey = "X";
- lineSeries.YAxisKey = "Y";
- lineSeries.TrackerFormatString = "{1}:{2}\n{0}:{4}" + Units[i];
- lineSeries.CanTrackerInterpolatePoints = false;
- lineSeries.DataFieldX = nameof(DataMangerItemModel.Time);
- lineSeries.DataFieldY = PropertiyNames[i];
- lineSeries.IsVisible = PropertiyNames[i] == nameof(DataMangerItemModel.OutputCurrent) || PropertiyNames[i] == nameof(DataMangerItemModel.OutputVoltage);
- _LineSeries.Add(lineSeries);
- PlotModel.Series.Add(lineSeries);
- PlotConfig.Add(new PlotConfigViewModel(lineSeries));
- PlotConfig[^1].PropertyChanged += (_, _) =>
- {
- PlotModel.InvalidatePlot(false);
- PlotModel.InvalidatePlot(true);
- };
- }
- {
- OxyPlot.Series.LineSeries lineSeries = new OxyPlot.Series.LineSeries();
- lineSeries.Title = "增益";
- lineSeries.XAxisKey = "X";
- lineSeries.YAxisKey = "Y";
- lineSeries.IsVisible = false;
- lineSeries.StrokeThickness = 1;
- lineSeries.TrackerFormatString = "{1}:{2}\n{0}:{4}%";
- lineSeries.CanTrackerInterpolatePoints = false;
- lineSeries.DataFieldX = nameof(DataMangerItemModel.Time);
- lineSeries.DataFieldY = PropertiyNames[^1];
- _LineSeries.Add(lineSeries);
- PlotModel.Series.Add(lineSeries);
- PlotConfig.Add(new PlotConfigViewModel(lineSeries));
- PlotConfig[^1].PropertyChanged += (_, _) =>
- {
- PlotModel.InvalidatePlot(false);
- PlotModel.InvalidatePlot(true);
- };
- }
- PlotModel.Legends.Add(new OxyPlot.Legends.Legend()
- {
- IsLegendVisible = true,
- ShowInvisibleSeries = false,
- });
-
- BusManger.Defaut.Bus.PubSub.Subscribe<Shaker.Model.ShakerConnectState>((data, _) =>
- {
- Tools.DispatherInovke.Inovke(() =>
- {
- IsConnected = data.IsConnected;
- });
- }, $"{Shaker.Model.GlobalVariable.ShakerIDKey}='{Model.Id}'");
- BusManger.Defaut.Bus.PubSub.Subscribe<Shaker.Model.ShakerStatusModel>((data, _) =>
- {
- Tools.DispatherInovke.Inovke(() =>
- {
- GainSwitch = data.GainSwich;
- });
- }, $"{Shaker.Model.GlobalVariable.ShakerIDKey}='{Model.Id}'");
- BusManger.Defaut.Bus.PubSub.Subscribe<Shaker.Model.ClientExitModel>((data, _) =>
- {
- Tools.DispatherInovke.Inovke(() =>
- {
- IsOnline = data.Online;
- });
- }, $"{Shaker.Model.GlobalVariable.ShakerIDKey}='{Model.Id}'");
- BusManger.Defaut.Bus.PubSub.Subscribe<DataMangerItemModel>((model, property) =>
- {
- if(MainWindowViewModel.Default.IsSaveData) Sql.Default.Insert(model, Model.Id);
- Tools.DispatherInovke.Inovke(() =>
- {
- if (CurrentData == null)
- {
- CurrentData = new DataMangerItemViewModel(model);
- }
- else
- {
- CurrentData.UpDateModel(model);
- }
- lock (locker)
- {
- gain = model.Gain;
- OnPropertyChanged(nameof(Gain));
- }
- Items.Add(new DataMangerItemViewModel(model));
- if (Items.Count > MaxItemCount) Items.RemoveAt(0);
- PlotModel.InvalidatePlot(false);
- _LineSeries.ForEach(x => x.ItemsSource = Items);
- PlotModel.InvalidatePlot(true);
- MinPlotModel.InvalidatePlot(false);
- _MinLineSeries.ForEach(x => x.ItemsSource = Items);
- MinPlotModel.InvalidatePlot(true);
- });
- }, $"{Shaker.Model.GlobalVariable.ShakerIDKey}='{Model.Id}'");
- BusManger.Defaut.Bus.PubSub.Subscribe<Shaker.Model.AllowRemoteControl>((model, property) =>
- {
- Tools.DispatherInovke.Inovke(() =>
- {
- IsRemoteControl = model == AllowRemoteControl.Remote;
- });
- }, $"{Shaker.Model.GlobalVariable.ShakerIDKey}='{Model.Id}'");
- MinPlotModel.Axes.Add(new OxyPlot.Axes.DateTimeAxis()
- {
- Title = "时间",
- Position = OxyPlot.Axes.AxisPosition.Bottom,
- Key = "X",
- MaximumPadding = 0,
- MajorGridlineColor = OxyPlot.OxyColors.Gray,
- MajorGridlineStyle = LineStyle.Dot,
- MajorGridlineThickness = 1,
- MinimumPadding = 0,
- ExtraGridlineColor = OxyPlot.OxyColors.White,
- TextColor = OxyColors.White,
- TitleColor = OxyColors.White,
- AxislineColor = OxyColors.White,
- TicklineColor = OxyColors.White,
- });
- MinPlotModel.Axes.Add(new OxyPlot.Axes.LinearAxis()
- {
- Title = "电流",
- Position = OxyPlot.Axes.AxisPosition.Left,
- Key = "Y",
- Unit = "A",
- MajorGridlineStyle = LineStyle.Dot,
- MajorGridlineColor = OxyPlot.OxyColors.Gray,
- MajorGridlineThickness = 1,
- ExtraGridlineColor = OxyPlot.OxyColors.White,
- TextColor = OxyColors.White,
- TitleColor = OxyColors.White,
- AxislineColor = OxyColors.White,
- TicklineColor = OxyColors.White,
- });
- {
- OxyPlot.Series.LineSeries lineSeries = new OxyPlot.Series.LineSeries();
- lineSeries.Title = AnalogNames[1];
- lineSeries.StrokeThickness = 1;
- lineSeries.XAxisKey = "X";
- lineSeries.YAxisKey = "Y";
- lineSeries.TrackerFormatString = "{1}:{2}\n{0}:{4}" + Units[1];
- lineSeries.CanTrackerInterpolatePoints = false;
- lineSeries.DataFieldX = nameof(DataMangerItemModel.Time);
- lineSeries.DataFieldY = PropertiyNames[1];
- _MinLineSeries.Add(lineSeries);
- MinPlotModel.Series.Add(lineSeries);
- }
- PlotController.BindMouseDown(OxyMouseButton.Right, new DelegatePlotCommand<OxyMouseDownEventArgs>((v, c, h) =>
- {
- h.Handled = true;
- MenuIsOpen = true;
- }));
- }
- public OxyPlot.IPlotController PlotController { get; } = new OxyPlot.PlotController();
- public View.ShakerView Content { get; } = new View.ShakerView();
- public bool GainSwitch
- {
- get => gainSwitch;
- set
- {
- if (value == gainSwitch) return;
- UpdateProperty(ref gainSwitch, value);
- OnPropertyChanged(nameof(GainEnabled));
- }
- }
- public bool AllowCoolingWater => Model.AllowCoolingWater;
- [AllowNull]
- public PowerAmplifierViewModel PowerAmplifier { get; init; }
- public ObservableCollection<PLCAnlogViewModel> CoolingWaterValues { get; } = new ObservableCollection<PLCAnlogViewModel>();
- public ObservableCollection<PLCAnlogViewModel> Values { get; } = new ObservableCollection<PLCAnlogViewModel>();
- public override Type View { get; } = typeof(View.ShakerView);
- public ICommand OpenCommand => new DelegateCommand(Open);
- public ICommand CloseCommand => new DelegateCommand(Close);
- public ICommand StartCommand => new DelegateCommand(Start);
- public ICommand StopCommand => new DelegateCommand(Stop);
- public ICommand ResetCommand => new DelegateCommand(Reset);
- public ICommand CoolingWaterStartCommand => new DelegateCommand(CoolingWaterStart);
- public ICommand CoolingWaterStopCommand => new DelegateCommand(CoolingWaterStop);
- public ICommand CoolingWaterResetCommand => new DelegateCommand(CoolingWaterReset);
- public async void CoolingWaterStartNoResult()
- {
- await BusManger.Defaut.Bus.PubSub.PublishAsync<SysControl>(new SysControl()
- {
- Cmd = SysCmd.CoolingWaterStart,
- }, Properties);
- }
- public async void CoolingWaterStopNoResult()
- {
- await BusManger.Defaut.Bus.PubSub.PublishAsync<SysControl>(new SysControl()
- {
- Cmd = SysCmd.CoolingWaterStop,
- }, Properties);
- }
- public async void CoolingWaterResetNoResult()
- {
- await BusManger.Defaut.Bus.PubSub.PublishAsync<SysControl>(new SysControl()
- {
- Cmd = SysCmd.CoolingWaterReset,
- }, Properties);
- }
- public async void StartNoResult()
- {
- await BusManger.Defaut.Bus.PubSub.PublishAsync<SysControl>(new SysControl()
- {
- Cmd = SysCmd.Start,
- }, Properties);
- }
- public async void StopNoResult()
- {
- await BusManger.Defaut.Bus.PubSub.PublishAsync<SysControl>(new SysControl()
- {
- Cmd = SysCmd.Stop,
- }, Properties);
- }
- public async void ResetNoResult()
- {
- await BusManger.Defaut.Bus.PubSub.PublishAsync<SysControl>(new SysControl()
- {
- Cmd = SysCmd.Reset,
- }, Properties);
- }
- public async void GainSwitchControlNoResult(bool switchon)
- {
- await BusManger.Defaut.Bus.PubSub.PublishAsync<Shaker.Model.SysControl>(new Shaker.Model.SysControl()
- {
- Cmd = switchon ? SysCmd.OpenGain: Shaker.Model.SysCmd.CloseGain,
- }, Properties);
- }
- private bool isOpen = false;
- public OxyPlot.PlotModel PlotModel { get; } = new OxyPlot.PlotModel();
- public bool IsOpen { get => isOpen; set => UpdateProperty(ref isOpen, value); }
- private async void Close()
- {
- GetEvent<Shaker.Model.LogModel>().Publish(this, new Shaker.Model.LogModel($"振动台{Name}关闭功放"));
- var result = await BusManger.Defaut.Bus.RPC.RequestAsync<Shaker.Model.SysControl,Shaker.Model.Result>(new Shaker.Model.SysControl()
- {
- Cmd = Shaker.Model.SysCmd.CloseGain,
- }, Properties);
- if(result == null || !result.Success)
- {
- PromptViewModel.Default.Init();
- PromptViewModel.Default.IconType = IconType.Error;
- PromptViewModel.Default.Message = result == null ? "通信超时" : result.Message;
- PromptViewModel.Default.NoVisibility = Visibility.Collapsed;
- PromptViewModel.Default.IsOpen = true;
- }
- }
- public void SetGainNoResult(short gain)
- {
- lock (locker)
- {
- BusManger.Defaut.Bus.PubSub.PublishAsync(new SetGain()
- {
- Gain = gain
- }, Properties).Wait();
- this.gain = gain;
- OnPropertyChanged(nameof(Gain));
- }
- }
- public ICommand GainSwitchCommand => new DelegateCommand<ExCommandParameter>(GainSwitchControl);
- public void GainSwitchControl(ExCommandParameter parameter)
- {
- if (parameter.Parameter is bool switchon)
- {
- if (switchon) Open();
- else Close();
- }
- }
- private void SetGain(short gain)
- {
- GetEvent<Shaker.Model.LogModel>().Publish(this, new Shaker.Model.LogModel($"振动台{Name}设置功放增益为{Gain}%"));
- var result = BusManger.Defaut.Bus.RPC.RequestAsync<Shaker.Model.SetGain, Shaker.Model.Result>(new Shaker.Model.SetGain()
- {
- Gain = gain,
- }, Properties).Result;
- if (result == null || !result.Success)
- {
- PromptViewModel.Default.Init();
- PromptViewModel.Default.IconType = IconType.Error;
- PromptViewModel.Default.Message = result == null ? "通信超时" : result.Message;
- PromptViewModel.Default.NoVisibility = Visibility.Collapsed;
- PromptViewModel.Default.IsOpen = true;
- }
- }
- public bool GainSwitchEnabled => CurrentData?.OperatingStatus == OperatingStatus.Run;
- public bool GainEnabled => CurrentData != null && (CurrentData.OperatingStatus == OperatingStatus.Run && GainSwitch);
- public bool StartEnabled => CurrentData?.OperatingStatus == OperatingStatus.Wait;
- public bool StopEnabled => CurrentData?.OperatingStatus == OperatingStatus.Run;
- public bool ResetEnabled => CurrentData?.OperatingStatus != OperatingStatus.Run;
- public bool CoolingWaterStartEnabled => CurrentData?.CoolingWaterStatus == CoolingWaterOperatingStatus.Wait && AllowCoolingWater;
- public bool CoolingWaterStopEnabled => CurrentData?.CoolingWaterStatus == CoolingWaterOperatingStatus.Run && AllowCoolingWater;
- public bool CoolingWaterResetEnabled => CurrentData?.CoolingWaterStatus != CoolingWaterOperatingStatus.Run && AllowCoolingWater;
- private async void CoolingWaterStart()
- {
- GetEvent<Shaker.Model.LogModel>().Publish(this, new Shaker.Model.LogModel($"振动台{Name}冷却开始"));
- var result = await BusManger.Defaut.Bus.RPC.RequestAsync<Shaker.Model.SysControl, Shaker.Model.Result>(new Shaker.Model.SysControl()
- {
- Cmd = Shaker.Model.SysCmd.CoolingWaterStart,
- }, Properties);
- if (result == null || !result.Success)
- {
- PromptViewModel.Default.Init();
- PromptViewModel.Default.IconType = IconType.Error;
- PromptViewModel.Default.Message = result == null ? "通信超时" : result.Message;
- PromptViewModel.Default.NoVisibility = Visibility.Collapsed;
- PromptViewModel.Default.IsOpen = true;
- }
- }
- private async void CoolingWaterStop()
- {
- GetEvent<Shaker.Model.LogModel>().Publish(this, new Shaker.Model.LogModel($"振动台{Name}停止冷却"));
- var result = await BusManger.Defaut.Bus.RPC.RequestAsync<Shaker.Model.SysControl, Shaker.Model.Result>(new Shaker.Model.SysControl()
- {
- Cmd = Shaker.Model.SysCmd.CoolingWaterStop,
- }, Properties);
- }
- private async void CoolingWaterReset()
- {
- GetEvent<Shaker.Model.LogModel>().Publish(this, new Shaker.Model.LogModel($"振动台{Name}冷却复位"));
- var result = await BusManger.Defaut.Bus.RPC.RequestAsync<Shaker.Model.SysControl, Shaker.Model.Result>(new Shaker.Model.SysControl()
- {
- Cmd = Shaker.Model.SysCmd.CoolingWaterReset,
- }, Properties);
- if (result == null || !result.Success)
- {
- PromptViewModel.Default.Init();
- PromptViewModel.Default.IconType = IconType.Error;
- PromptViewModel.Default.Message = result == null ? "通信超时" : result.Message;
- PromptViewModel.Default.NoVisibility = Visibility.Collapsed;
- PromptViewModel.Default.IsOpen = true;
- }
- }
- private async void Start()
- {
- GetEvent<Shaker.Model.LogModel>().Publish(this, new Shaker.Model.LogModel($"振动台{Name}功放开始"));
- var result = await BusManger.Defaut.Bus.RPC.RequestAsync<Shaker.Model.SysControl,Shaker.Model.Result>(new Shaker.Model.SysControl()
- {
- Cmd = Shaker.Model.SysCmd.Start,
- }, Properties);
- if (result == null || !result.Success)
- {
- PromptViewModel.Default.Init();
- PromptViewModel.Default.IconType = IconType.Error;
- PromptViewModel.Default.Message = result == null ? "通信超时" : result.Message;
- PromptViewModel.Default.NoVisibility = Visibility.Collapsed;
- PromptViewModel.Default.IsOpen = true;
- }
- }
- private async void Stop()
- {
- GetEvent<Shaker.Model.LogModel>().Publish(this, new Shaker.Model.LogModel($"振动台{Name}停止功放"));
- var result = await BusManger.Defaut.Bus.RPC.RequestAsync<Shaker.Model.SysControl,Shaker.Model.Result>(new Shaker.Model.SysControl()
- {
- Cmd = Shaker.Model.SysCmd.Stop,
- }, Properties);
- }
- private async void Reset()
- {
- GetEvent<Shaker.Model.LogModel>().Publish(this, new Shaker.Model.LogModel($"振动台{Name}功放复位"));
- var result= await BusManger.Defaut.Bus.RPC.RequestAsync<Shaker.Model.SysControl,Shaker.Model.Result>(new Shaker.Model.SysControl()
- {
- Cmd = Shaker.Model.SysCmd.Reset,
- }, Properties);
- if (result == null || !result.Success)
- {
- PromptViewModel.Default.Init();
- PromptViewModel.Default.IconType = IconType.Error;
- PromptViewModel.Default.Message = result == null ? "通信超时" : result.Message;
- PromptViewModel.Default.NoVisibility = Visibility.Collapsed;
- PromptViewModel.Default.IsOpen = true;
- }
- }
- private async void Open()
- {
- GetEvent<Shaker.Model.LogModel>().Publish(this, new Shaker.Model.LogModel($"振动台{Name}打开功放"));
- var result = await BusManger.Defaut.Bus.RPC.RequestAsync<Shaker.Model.SysControl,Shaker.Model.Result>(new Shaker.Model.SysControl()
- {
- Cmd = Shaker.Model.SysCmd.OpenGain,
- }, Properties);
- if (result == null || !result.Success)
- {
- PromptViewModel.Default.Init();
- PromptViewModel.Default.IconType = IconType.Error;
- PromptViewModel.Default.Message = result == null ? "通信超时" : result.Message;
- PromptViewModel.Default.NoVisibility = Visibility.Collapsed;
- PromptViewModel.Default.IsOpen = true;
- }
- }
- private short gain;
- private bool setPlotConfigIsOpen = false;
- [AllowNull]
- private DataMangerItemViewModel currentData;
- private bool isConnected = false;
- private bool isRemoteControl = false;
- private bool isOnline = false;
- private bool gainSwitch = false;
- private bool isDeviceControl = false;
- private ShakerViewType shakerView = Data.ShakerViewType.None;
- private bool menuIsOpen = false;
- public string Title => string.IsNullOrEmpty(Description) ? Name : Description;
- public string Name
- {
- get => Model.Name;
- set
- {
- UpdateProperty(ref Model.Name, value);
- OnPropertyChanged(nameof(Title));
- }
- }
- public string Description
- {
- get => Model.Description;
- set
- {
- if (value == Model.Description) return;
- GetEvent<Shaker.Model.LogModel>().Publish(this, new Shaker.Model.LogModel($"振动台{Name}别名修改为{value}"));
- UpdateProperty(ref Model.Description, value);
- Sql.Default.UpDate<Shaker.Model.ShakerControlModel, string, string>(p => p.Id, Model.Id, p => p.Description, Model.Description);
- OnPropertyChanged(nameof(Title));
- }
- }
- public byte SlaveID { get=>Model.SlaveID; set=>UpdateProperty(ref Model.SlaveID, value); }
- public string IPAddress
- {
- get => Model.IPAddress;
- set
- {
- if (Model.Id == value) return;
- GetEvent<Shaker.Model.LogModel>().Publish(this, new Shaker.Model.LogModel($"振动台{Name}功放IP地址修改为{value}"));
- UpdateProperty(ref Model.IPAddress, value);
- Sql.Default.UpDate<Shaker.Model.ShakerControlModel, string, string>(p => p.Id, Model.Id, p => p.IPAddress, Model.IPAddress);
- }
- }
- public int Port
- {
- get => Model.Port;
- set
- {
- if (value != Model.Port)
- {
- GetEvent<Shaker.Model.LogModel>().Publish(this, new Shaker.Model.LogModel($"振动台{Name}功放端口号修改为{value}"));
- UpdateProperty(ref Model.Port, value);
- Sql.Default.UpDate<Shaker.Model.ShakerControlModel, string, int>(p => p.Id, Model.Id, p => p.Port, Model.Port);
- }
- }
- }
- public ICommand RequestPermissionsCommand => new DelegateCommand(RequestPermissions);
- private async void RequestPermissions()
- {
- if (IsRemoteControl) return;
- GetEvent<Shaker.Model.LogModel>().Publish(this, new Shaker.Model.LogModel($"申请振动台{Name}功放控制权限"));
- var result = await BusManger.Defaut.Bus.RPC.RequestAsync<Shaker.Model.SysControl, Shaker.Model.Result>(new Shaker.Model.SysControl()
- {
- Cmd = Shaker.Model.SysCmd.ApplicationControl,
- }, Properties,CancellationToken.None,MainWindowViewModel.Default.SystemConfig.SystemPage.RequestPermissionsTimeout);
- if (result == null || !result.Success)
- {
- PromptViewModel.Default.Init();
- PromptViewModel.Default.IconType = IconType.Error;
- PromptViewModel.Default.Message = result == null ? "通信超时" : result.Message;
- PromptViewModel.Default.NoVisibility = Visibility.Collapsed;
- PromptViewModel.Default.IsOpen = true;
- }
- }
- public short Gain
- {
- get => gain;
- set
- {
- if (gain == value) return;
- lock (locker)
- {
- UpdateProperty(ref gain, value);
- }
- SetGain(value);
- }
- }
- public bool IsRemoteControl { get => isRemoteControl; set =>UpdateProperty(ref isRemoteControl, value); }
- public ICommand SaveCommand => new DelegateCommand(() => Save());
- public ICommand CancelCommand => new DelegateCommand(() => Cancel());
- private void Save()
- {
- GetEvent<Shaker.Model.LogModel>().Publish(this, new Shaker.Model.LogModel($"修改了振动台{Name}配置参数"));
- Sql.Default.Replace(p => p.Id, Model.Id, Model);
- }
- private void Cancel()
- {
- Model = Sql.Default.FindFirst<Shaker.Model.ShakerControlModel>(p => p.Id == Model.Id)!;
- RefreshUI();
- }
- public bool IsMax { get; set; }
- public bool IsSelected { get; set; }
- }
- }
|