123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189 |
- using Avalonia.Controls;
- using CommunityToolkit.Mvvm.Input;
- using Shaker.Model;
- using Shaker.Model.Tools;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Input;
- namespace ShakerApp.ViewModels
- {
- public sealed class ShakerStatusViewModel:ViewModelBase<Shaker.Model.ShakerStatusModel>
- {
- private float givenDisplacement;
- private float measuredDisplacement;
- private float acceleration;
- private float valveDrive;
- private float outSignal;
- public float GivenDisplacement { get => givenDisplacement; set => SetProperty(ref givenDisplacement, value); }
- public float MeasuredDisplacement { get => measuredDisplacement; set => SetProperty(ref measuredDisplacement, value); }
- public float Acceleration { get => acceleration; set => SetProperty(ref acceleration, value); }
- public float ValveDrive { get => valveDrive; set => SetProperty(ref valveDrive, value); }
- public float OutSignal { get => outSignal; set => SetProperty(ref outSignal, value); }
- private float workPosition = 0;
- public RTStatus RTStatus { get => Model.RTStatus; set => SetProperty(ref Model.RTStatus, value); }
- public bool Start { get => Model.Start; set => SetProperty(ref Model.Start, value); }
- public bool IsTableRised { get => Model.IsTableRised; set => SetProperty(ref Model.IsTableRised, value); }
- public bool IsTableDroped { get => Model.IsTableDroped; set => SetProperty(ref Model.IsTableDroped, value); }
- public bool IsFaultRelease { get => Model.IsFaultRelease; set => SetProperty(ref Model.IsFaultRelease, value); }
- public uint RiseCount { get => Model.RiseCount; set => SetProperty(ref Model.RiseCount, value); }
- public uint SignalGenStopCount { get => Model.SignalGenStopCount; set => SetProperty(ref Model.SignalGenStopCount, value); }
- public uint EmergencyStopCount { get => Model.EmergencyStopCount; set => SetProperty(ref Model.EmergencyStopCount, value); }
- public bool IsSignalGenStoped { get => Model.IsSignalGenStoped; set => SetProperty(ref Model.IsSignalGenStoped, value); }
- public uint ZeroChangedCount { get => Model.ZeroChangedCount; set => SetProperty(ref Model.ZeroChangedCount, value); }
- public ushort WarnCode { get => Model.WarnCode; set => SetProperty(ref Model.WarnCode, value); }
- public float CurrentFrequency { get => Model.CurrentFrequency; set => SetProperty(ref Model.CurrentFrequency, value); }
- public bool ClosedValve { get => Model.ClosedValve; set => SetProperty(ref Model.ClosedValve, value); }
- public uint DropCount { get => Model.DropCount; set => SetProperty(ref Model.DropCount, value); }
- public ushort ErrorCode { get => Model.ErrorCode; set => SetProperty(ref Model.ErrorCode, value); }
- public float WorkPosition { get => workPosition; set =>SetProperty(ref workPosition , value); }
- private ShakerStatusViewModel()
- {
- Content = typeof(Views.ShakerStatusControlView);
- ButtonVisibily = false;
- InitDisplacementModel();
- InitServoValveModel();
- GetEvent(ShakerSettingViewModel.LANGUAGECHANGEDEVENT).Subscrip((_, _) =>
- {
- DisplacementModel.Axes[0].Title = App.Current?.FindResource("Time") + "";
- DisplacementModel.Axes[1].Title = App.Current?.FindResource("Ampt") + "";
- DisplacementModel.Title = App.Current?.FindResource("Displacement") + "";
- ServoValveModel.Axes[0].Title = App.Current?.FindResource("Time") + "";
- ServoValveModel.Axes[1].Title = App.Current?.FindResource("Ampt") + "";
- ServoValveModel.Title = App.Current?.FindResource("ValveDriveSignal") + "";
- });
- GetEvent<AllConfig>().Subscrip((sender, args) =>
- {
- UpDateModel(args.Data.ShakerStatus);
- if(CommunicationViewModel.Intance.ServiceIsStart)
- {
- CommunicationViewModel.Intance.ServiceCommunication.GetEvent<ShakerStatusModel>().Publish(this, args.Data.ShakerStatus);
- }
- CommunicationViewModel.Intance.LocalCommunication?.GetEvent<Shaker.Model.ShakerStatusModel>()?.Subscrip((sender, args) =>
- {
- UpDateModel(args.Data);
- CommunicationViewModel.Intance.ServiceCommunication?.GetEvent<Shaker.Model.ShakerStatusModel>()?.Publish(this, args.Data);
- });
- });
- }
- private void InitDisplacementModel()
- {
- DisplacementModel.Axes.Add(new OxyPlot.Axes.TimeSpanAxis()
- {
- MaximumPadding = 0,
- MinimumPadding = 0,
- Title = App.Current?.FindResource("Time") + "",
- Unit="s",
- MajorGridlineStyle = OxyPlot.LineStyle.Solid,
- Position = OxyPlot.Axes.AxisPosition.Bottom
- });
- DisplacementModel.Axes.Add(new OxyPlot.Axes.LinearAxis()
- {
- Title = App.Current?.FindResource("Ampt") + "",
- Unit = "mm",
- Position = OxyPlot.Axes.AxisPosition.Left,
- MajorGridlineStyle = OxyPlot.LineStyle.Solid,
- });
- DisplacementModel.Title = App.Current?.FindResource("Displacement") + "";
- }
- private void InitServoValveModel()
- {
- ServoValveModel.Axes.Add(new OxyPlot.Axes.TimeSpanAxis()
- {
- MaximumPadding = 0,
- MinimumPadding = 0,
- Title = App.Current?.FindResource("Time") + "",
- Unit = "s",
- MajorGridlineStyle = OxyPlot.LineStyle.Solid,
- Position= OxyPlot.Axes.AxisPosition.Bottom
- });
- ServoValveModel.Axes.Add(new OxyPlot.Axes.LinearAxis()
- {
- Title = App.Current?.FindResource("Ampt") + "",
- Unit = "V",
- MajorGridlineStyle = OxyPlot.LineStyle.Solid,
- Position = OxyPlot.Axes.AxisPosition.Left,
- });
- ServoValveModel.Title = App.Current?.FindResource("ValveDriveSignal") + "";
- }
- public override bool CanCancel => false;
- static ShakerStatusViewModel()
- {
- }
- public ICommand RiseTableCommand => new RelayCommand(RiseTableCommandExecute);
- private void RiseTableCommandExecute()
- {
- }
- public ICommand DropTableCommand => new RelayCommand(DropTableCommandExecute);
- private void DropTableCommandExecute()
- {
- }
- public ICommand EmergencyStopCommand => new RelayCommand(EmergencyStopCommandExecute);
- private void EmergencyStopCommandExecute()
- {
- }
- public ICommand StartCommand=> new RelayCommand(StartCommandExecute);
- private void StartCommandExecute()
- {
- if (MainPageViewModel.Instance.MainPage is SineMainPageViewModel sine)
- {
- SinePlotTest();
- }
- }
- private async void SinePlotTest()
- {
- float invtert=0.01f;
- float start = SweepConfigViewModel.Instance.SweepDirection == SweepDirection.Up ? SweepConfigViewModel.Instance.StartFrequency : SweepConfigViewModel.Instance.EndFrequency;
- float end = SweepConfigViewModel.Instance.SweepDirection != SweepDirection.Up ? SweepConfigViewModel.Instance.StartFrequency : SweepConfigViewModel.Instance.EndFrequency;
- while (true)
- {
- var val = SweepConfigViewModel.Instance.Model.CalcAmpt(start);
- SineDataModel data = new SineDataModel()
- {
- SweepDirection = SweepConfigViewModel.Instance.SweepDirection,
- CurrentAcceleration =val,
- CurrentFrequency = start,
- TotalTime = SweepConfigViewModel.Instance.TotalSweepTime,
- RunTime =0f,
- };
- SineMainPageViewModel.Instance.UpdateData(data);
- start += invtert;
- await Task.Delay(100);
- if (start > end) break;
- }
- }
- public ICommand StopCommand => new RelayCommand(StopCommandExecute);
- private void StopCommandExecute()
- {
- }
- public ICommand ResetCommand => new RelayCommand(ResetCommandExecute);
- private void ResetCommandExecute()
- {
- }
- public static ShakerStatusViewModel Instance { get; } = new ShakerStatusViewModel();
- public OxyPlot.PlotModel DisplacementModel { get; } = new OxyPlot.PlotModel();
- public OxyPlot.PlotModel ServoValveModel { get; } = new OxyPlot.PlotModel();
- }
- }
|