| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319 |
- using Prism.Commands;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Linq;
- using System.Runtime.CompilerServices;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Navigation;
- using System.Windows.Shapes;
- using Team.FFFeederService.Interfaces;
- using TeamAAS_VP;
- using TeamAAS_VP.Resources.Languages;
- using static NPOI.HSSF.Util.HSSFColor;
- namespace TeamAAS_VP.Controls
- {
- /// <summary>
- /// FeederSystemParam.xaml 的交互逻辑
- /// </summary>
- public partial class FeederSystemParam : UserControl, INotifyPropertyChanged
- {
- private bool IsLoading = false;
- public FeederSystemParam()
- {
- InitializeComponent();
- this.DataContext = this;
- this.Loaded += FeederSystemParam_Loaded;
- }
- #region 属性
- public IVoiceCoilMotorFeeder Feeder { get; set; }
- private ushort _LightTimeOutValue;
- /// <summary>
- /// 背光超时时长
- /// </summary>
- public ushort LightTimeOutValue
- {
- get { return _LightTimeOutValue; }
- set { SetProperty(ref _LightTimeOutValue,value); }
- }
- private ushort _LightValue;
- /// <summary>
- /// 背光亮度
- /// </summary>
- public ushort LightValue
- {
- get { return _LightValue; }
- set { SetProperty(ref _LightValue, value); }
- }
- private int _BackLightFlashTime;
- /// <summary>
- /// 背光闪烁时间
- /// </summary>
- public int BackLightFlashTime
- {
- get { return _BackLightFlashTime; }
- set { SetProperty(ref _BackLightFlashTime, value); }
- }
- private int _PlatShakeTimeout;
- /// <summary>
- /// 平台振动超时
- /// </summary>
- public int PlatShakeTimeout
- {
- get { return _PlatShakeTimeout; }
- set { SetProperty(ref _PlatShakeTimeout, value); }
- }
- private int _UpperFeederShakeTimeout;
- /// <summary>
- /// 料斗振动超时
- /// </summary>
- public int UpperFeederShakeTimeout
- {
- get { return _UpperFeederShakeTimeout; }
- set { SetProperty(ref _UpperFeederShakeTimeout, value); }
- }
- #endregion
- #region 命令
- private DelegateCommand<double?> _LightTimeOutValueChangedCommand;
- public DelegateCommand<double?> LightTimeOutValueChangedCommand =>
- _LightTimeOutValueChangedCommand ?? (_LightTimeOutValueChangedCommand = new DelegateCommand<double?>(ExecuteLightTimeOutValueChangedCommand));
- private DelegateCommand<double?> _LightValueChangedCommand;
- public DelegateCommand<double?> LightValueChangedCommand =>
- _LightValueChangedCommand ?? (_LightValueChangedCommand = new DelegateCommand<double?>(ExecuteLightValueChangedCommand));
- private DelegateCommand<double?> _LightFlashTimeChangedCommand;
- public DelegateCommand<double?> LightFlashTimeChangedCommand =>
- _LightFlashTimeChangedCommand ?? (_LightFlashTimeChangedCommand = new DelegateCommand<double?>(ExecuteLightFlashTimeChangedCommand));
- private DelegateCommand<double?> _PlatShakeTimeoutChangedCommand;
- public DelegateCommand<double?> PlatShakeTimeoutChangedCommand =>
- _PlatShakeTimeoutChangedCommand ?? (_PlatShakeTimeoutChangedCommand = new DelegateCommand<double?>(ExecutePlatShakeTimeoutChangedCommand));
- private DelegateCommand<double?> _UpperFeederShakeTimeoutChangedCommand;
- public DelegateCommand<double?> UpperFeederShakeTimeoutChangedCommand =>
- _UpperFeederShakeTimeoutChangedCommand ?? (_UpperFeederShakeTimeoutChangedCommand = new DelegateCommand<double?>(ExecuteUpperFeederShakeTimeoutChangedCommand));
- private DelegateCommand _WriteCommand;
- public DelegateCommand WriteCommand =>
- _WriteCommand ?? (_WriteCommand = new DelegateCommand(ExecuteWriteCommand));
- #endregion
- #region 方法
- private async void FeederSystemParam_Loaded(object sender, RoutedEventArgs e)
- {
- if (Feeder == null || !Feeder.IsConnected) return;
- IsLoading = true;
- try
- {
- LightTimeOutValue = await Feeder.GetLightTimeoutAsync();
- LightValue = await Feeder.GetLightBrightnessAsync();
- BackLightFlashTime = await Feeder.GetBackLightFlashTimeAsync();
- UpperFeederShakeTimeout = await Feeder.GetUpperFeederShakeTimeoutAsync();
- PlatShakeTimeout = await Feeder.GetPlatShakeTimeoutAsync();
- }
- catch (Exception ex)
- {
- LogHelper.WriteLogError(Lang.Feeder系统参数加载时出错, ex);
- }
- IsLoading = false;
- }
- /// <summary>
- /// 背光超时时长修改时
- /// </summary>
- async void ExecuteLightTimeOutValueChangedCommand(double? lightvalue)
- {
- if (Feeder == null || !Feeder.IsConnected || IsLoading) return;
- if (lightvalue == null) return;
- try
- {
- await Feeder.SetLightTimeOutAsync((ushort)lightvalue);
- }
- catch (Exception ex)
- {
- LogHelper.WriteLogError(Lang.Feeder背光超时时长修改时出错, ex);
- }
- }
- /// <summary>
- /// 背光亮度改变时
- /// </summary>
- async void ExecuteLightValueChangedCommand(double? lightvalue)
- {
- if (Feeder == null || !Feeder.IsConnected || IsLoading) return;
- if (lightvalue==null) return;
- try
- {
- await Feeder.SetLightValueToBufferAsync((ushort)lightvalue);
- }
- catch (Exception ex)
- {
- LogHelper.WriteLogError(Lang.Feeder背光亮度改变时出错, ex);
- }
- }
- /// <summary>
- /// 背光闪烁时间改变时
- /// </summary>
- /// <param name="lightvalue"></param>
- async void ExecuteLightFlashTimeChangedCommand(double? lightvalue)
- {
- if (Feeder == null || !Feeder.IsConnected || IsLoading) return;
- if (lightvalue == null) return;
- try
- {
- await Feeder.SetBackLightFlashTimeAsync((ushort)lightvalue);
- }
- catch (Exception ex)
- {
- LogHelper.WriteLogError(Lang.Feeder背光闪烁时间改变时出错, ex);
- }
- }
- /// <summary>
- /// 平台振动超时改变时
- /// </summary>
- async void ExecutePlatShakeTimeoutChangedCommand(double? time)
- {
- if (Feeder == null || !Feeder.IsConnected || IsLoading) return;
- if (time == null) return;
- try
- {
- await Feeder.SetPlatShakeTimeoutAsync((ushort)time);
- }
- catch (Exception ex)
- {
- LogHelper.WriteLogError(Lang.Feeder平台振动超时改变时出错, ex);
- }
- }
- /// <summary>
- /// 料斗振动超时改变时
- /// </summary>
- /// <param name="time"></param>
- async void ExecuteUpperFeederShakeTimeoutChangedCommand(double? time)
- {
- if (Feeder == null || !Feeder.IsConnected || IsLoading) return;
- if (time == null) return;
- try
- {
- await Feeder.SetUpperFeederShakeTimeoutAsync((ushort)time);
- }
- catch (Exception ex)
- {
- LogHelper.WriteLogError(Lang.Feeder料斗振动超时时出错, ex);
- }
- }
- /// <summary>
- /// 保存
- /// </summary>
- async void ExecuteWriteCommand()
- {
- if (Feeder == null || !Feeder.IsConnected || IsLoading) return;
- try
- {
- await Feeder.SaveGlobalSetAsync();
- }
- catch (Exception ex)
- {
- LogHelper.WriteLogError(Lang.Feeder保存系统参数时出错, ex);
- }
- }
- #endregion
- #region 属性更改通知
- /// <summary>
- /// Occurs when a property value changes.
- /// </summary>
- public event PropertyChangedEventHandler PropertyChanged;
- /// <summary>
- /// Checks if a property already matches a desired value. Sets the property and
- /// notifies listeners only when necessary.
- /// </summary>
- /// <typeparam name="T">Type of the property.</typeparam>
- /// <param name="storage">Reference to a property with both getter and setter.</param>
- /// <param name="value">Desired value for the property.</param>
- /// <param name="propertyName">Name of the property used to notify listeners. This
- /// value is optional and can be provided automatically when invoked from compilers that
- /// support CallerMemberName.</param>
- /// <returns>True if the value was changed, false if the existing value matched the
- /// desired value.</returns>
- protected virtual bool SetProperty<T>(ref T storage, T value, [CallerMemberName] string propertyName = null)
- {
- if (EqualityComparer<T>.Default.Equals(storage, value)) return false;
- storage = value;
- RaisePropertyChanged(propertyName);
- return true;
- }
- /// <summary>
- /// Checks if a property already matches a desired value. Sets the property and
- /// notifies listeners only when necessary.
- /// </summary>
- /// <typeparam name="T">Type of the property.</typeparam>
- /// <param name="storage">Reference to a property with both getter and setter.</param>
- /// <param name="value">Desired value for the property.</param>
- /// <param name="propertyName">Name of the property used to notify listeners. This
- /// value is optional and can be provided automatically when invoked from compilers that
- /// support CallerMemberName.</param>
- /// <param name="onChanged">Action that is called after the property value has been changed.</param>
- /// <returns>True if the value was changed, false if the existing value matched the
- /// desired value.</returns>
- protected virtual bool SetProperty<T>(ref T storage, T value, Action onChanged, [CallerMemberName] string propertyName = null)
- {
- if (EqualityComparer<T>.Default.Equals(storage, value)) return false;
- storage = value;
- onChanged?.Invoke();
- RaisePropertyChanged(propertyName);
- return true;
- }
- /// <summary>
- /// Raises this object's PropertyChanged event.
- /// </summary>
- /// <param name="propertyName">Name of the property used to notify listeners. This
- /// value is optional and can be provided automatically when invoked from compilers
- /// that support <see cref="CallerMemberNameAttribute"/>.</param>
- protected void RaisePropertyChanged([CallerMemberName] string propertyName = null)
- {
- OnPropertyChanged(new PropertyChangedEventArgs(propertyName));
- }
- /// <summary>
- /// Raises this object's PropertyChanged event.
- /// </summary>
- /// <param name="args">The PropertyChangedEventArgs</param>
- protected virtual void OnPropertyChanged(PropertyChangedEventArgs args)
- {
- PropertyChanged?.Invoke(this, args);
- }
- #endregion
- }
- }
|