| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698 |
- using Prism.Commands;
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.ComponentModel;
- using System.Linq;
- using System.Runtime.CompilerServices;
- using System.Security.Cryptography;
- 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.Enums;
- using Team.FFFeederService.Interfaces;
- using Team.FFFeederService.Models;
- using TeamAAS_VP;
- using TeamAAS_VP.Resources.Languages;
- using TouchSocket.Core;
- namespace TeamAAS_VP.Controls
- {
- /// <summary>
- /// FeederSequence.xaml 的交互逻辑
- /// </summary>
- public partial class FeederSequence : UserControl, INotifyPropertyChanged
- {
- private bool _manualStop = false;
- public FeederSequence()
- {
- InitializeComponent();
- this.DataContext = this;
- SequenceCollection.Clear();
- for (int i = 1; i <= 26; i++)
- {
- SequenceCollection.Add(i);
- char chn = (char)('A' + i);
- }
- }
- #region 属性
- public IVoiceCoilMotorFeeder Feeder { get; set; }
- private ObservableCollection<int> _SequenceCollection = new ObservableCollection<int>();
- /// <summary>
- /// 序列集
- /// </summary>
- public ObservableCollection<int> SequenceCollection
- {
- get { return _SequenceCollection; }
- set { SetProperty(ref _SequenceCollection, value); }
- }
- private int _SelectedSequence = -1;
- /// <summary>
- /// 当前选中的序列
- /// </summary>
- public int SelectedSequence
- {
- get { return _SelectedSequence; }
- set { SetProperty(ref _SelectedSequence, value); }
- }
- private int _CurrentSequencePartCntMax;
- /// <summary>
- /// 极限值
- /// </summary>
- public int CurrentSequencePartCntMax
- {
- get { return _CurrentSequencePartCntMax; }
- set { SetProperty(ref _CurrentSequencePartCntMax, value); }
- }
- private int _CycleRunningTimes;
- /// <summary>
- /// 循环次数
- /// </summary>
- public int CycleRunningTimes
- {
- get { return _CycleRunningTimes; }
- set { SetProperty(ref _CycleRunningTimes, value); }
- }
- private SingleSequenceActionGroup _CurrentSequenceActionGroup;
- /// <summary>
- /// 序列集
- /// </summary>
- public SingleSequenceActionGroup CurrentSequenceActionGroup
- {
- get { return _CurrentSequenceActionGroup; }
- set { SetProperty(ref _CurrentSequenceActionGroup, value); }
- }
- private SingleSequenceAction _SingleSequenceAction1;
- /// <summary>
- /// 1
- /// </summary>
- public SingleSequenceAction SingleSequenceAction1
- {
- get { return _SingleSequenceAction1; }
- set { SetProperty(ref _SingleSequenceAction1, value); }
- }
- private SingleSequenceAction _SingleSequenceAction2;
- /// <summary>
- /// 2
- /// </summary>
- public SingleSequenceAction SingleSequenceAction2
- {
- get { return _SingleSequenceAction2; }
- set { SetProperty(ref _SingleSequenceAction2, value); }
- }
- private SingleSequenceAction _SingleSequenceAction3;
- /// <summary>
- /// 3
- /// </summary>
- public SingleSequenceAction SingleSequenceAction3
- {
- get { return _SingleSequenceAction3; }
- set { SetProperty(ref _SingleSequenceAction3, value); }
- }
- private SingleSequenceAction _SingleSequenceAction4;
- /// <summary>
- /// 4
- /// </summary>
- public SingleSequenceAction SingleSequenceAction4
- {
- get { return _SingleSequenceAction4; }
- set { SetProperty(ref _SingleSequenceAction4, value); }
- }
- private SingleSequenceAction _SingleSequenceAction5;
- /// <summary>
- /// 5
- /// </summary>
- public SingleSequenceAction SingleSequenceAction5
- {
- get { return _SingleSequenceAction5; }
- set { SetProperty(ref _SingleSequenceAction5, value); }
- }
- private SingleSequenceAction _SingleSequenceAction6;
- /// <summary>
- /// 6
- /// </summary>
- public SingleSequenceAction SingleSequenceAction6
- {
- get { return _SingleSequenceAction6; }
- set { SetProperty(ref _SingleSequenceAction6, value); }
- }
- private SingleSequenceAction _SingleSequenceAction7;
- /// <summary>
- /// 7
- /// </summary>
- public SingleSequenceAction SingleSequenceAction7
- {
- get { return _SingleSequenceAction7; }
- set { SetProperty(ref _SingleSequenceAction7, value); }
- }
- #region 属性视图显示
- private Visibility _IsVisibility1 = Visibility.Collapsed;
- public Visibility IsVisibility1
- {
- get { return _IsVisibility1; }
- set { SetProperty(ref _IsVisibility1, value); }
- }
- private Visibility _IsVisibility1_2 = Visibility.Collapsed;
- public Visibility IsVisibility1_2
- {
- get { return _IsVisibility1_2; }
- set { SetProperty(ref _IsVisibility1_2, value); }
- }
- private Visibility _IsVisibility2 = Visibility.Collapsed;
- public Visibility IsVisibility2
- {
- get { return _IsVisibility2; }
- set { SetProperty(ref _IsVisibility2, value); }
- }
- private Visibility _IsVisibility2_2 = Visibility.Collapsed;
- public Visibility IsVisibility2_2
- {
- get { return _IsVisibility2_2; }
- set { SetProperty(ref _IsVisibility2_2, value); }
- }
- private Visibility _IsVisibility3 = Visibility.Collapsed;
- public Visibility IsVisibility3
- {
- get { return _IsVisibility3; }
- set { SetProperty(ref _IsVisibility3, value); }
- }
- private Visibility _IsVisibility3_2 = Visibility.Collapsed;
- public Visibility IsVisibility3_2
- {
- get { return _IsVisibility3_2; }
- set { SetProperty(ref _IsVisibility3_2, value); }
- }
- private Visibility _IsVisibility4 = Visibility.Collapsed;
- public Visibility IsVisibility4
- {
- get { return _IsVisibility4; }
- set { SetProperty(ref _IsVisibility4, value); }
- }
- private Visibility _IsVisibility4_2 = Visibility.Collapsed;
- public Visibility IsVisibility4_2
- {
- get { return _IsVisibility4_2; }
- set { SetProperty(ref _IsVisibility4_2, value); }
- }
- private Visibility _IsVisibility5 = Visibility.Collapsed;
- public Visibility IsVisibility5
- {
- get { return _IsVisibility5; }
- set { SetProperty(ref _IsVisibility5, value); }
- }
- private Visibility _IsVisibility5_2 = Visibility.Collapsed;
- public Visibility IsVisibility5_2
- {
- get { return _IsVisibility5_2; }
- set { SetProperty(ref _IsVisibility5_2, value); }
- }
- private Visibility _IsVisibility6 = Visibility.Collapsed;
- public Visibility IsVisibility6
- {
- get { return _IsVisibility6; }
- set { SetProperty(ref _IsVisibility6, value); }
- }
- private Visibility _IsVisibility6_2 = Visibility.Collapsed;
- public Visibility IsVisibility6_2
- {
- get { return _IsVisibility6_2; }
- set { SetProperty(ref _IsVisibility6_2, value); }
- }
- private Visibility _IsVisibility7 = Visibility.Collapsed;
- public Visibility IsVisibility7
- {
- get { return _IsVisibility7; }
- set { SetProperty(ref _IsVisibility7, value); }
- }
- private Visibility _IsVisibility7_2 = Visibility.Collapsed;
- public Visibility IsVisibility7_2
- {
- get { return _IsVisibility7_2; }
- set { SetProperty(ref _IsVisibility7_2, value); }
- }
- #endregion
- #endregion
- #region 命令
- private DelegateCommand _SelectSequenceCommand;
- public DelegateCommand SelectSequenceCommand =>
- _SelectSequenceCommand ?? (_SelectSequenceCommand = new DelegateCommand(ExecuteSelectSequenceCommand));
- private DelegateCommand _StartCommand;
- public DelegateCommand StartCommand =>
- _StartCommand ?? (_StartCommand = new DelegateCommand(ExecuteStartCommand));
- private DelegateCommand _StopCommand;
- public DelegateCommand StopCommand =>
- _StopCommand ?? (_StopCommand = new DelegateCommand(ExecuteStopCommand));
- private DelegateCommand _WriteParamCommand;
- public DelegateCommand WriteParamCommand =>
- _WriteParamCommand ?? (_WriteParamCommand = new DelegateCommand(ExecuteWriteParamCommand));
- private DelegateCommand<int?> _SelectActionCommand1;
- public DelegateCommand<int?> SelectActionCommand1 =>
- _SelectActionCommand1 ?? (_SelectActionCommand1 = new DelegateCommand<int?>(ExecuteSelectActionCommand1));
- private DelegateCommand<int?> _SelectActionCommand2;
- public DelegateCommand<int?> SelectActionCommand2 =>
- _SelectActionCommand2 ?? (_SelectActionCommand2 = new DelegateCommand<int?>(ExecuteSelectActionCommand2));
- private DelegateCommand<int?> _SelectActionCommand3;
- public DelegateCommand<int?> SelectActionCommand3 =>
- _SelectActionCommand3 ?? (_SelectActionCommand3 = new DelegateCommand<int?>(ExecuteSelectActionCommand3));
- private DelegateCommand<int?> _SelectActionCommand4;
- public DelegateCommand<int?> SelectActionCommand4 =>
- _SelectActionCommand4 ?? (_SelectActionCommand4 = new DelegateCommand<int?>(ExecuteSelectActionCommand4));
- private DelegateCommand<int?> _SelectActionCommand5;
- public DelegateCommand<int?> SelectActionCommand5 =>
- _SelectActionCommand5 ?? (_SelectActionCommand5 = new DelegateCommand<int?>(ExecuteSelectActionCommand5));
- private DelegateCommand<int?> _SelectActionCommand6;
- public DelegateCommand<int?> SelectActionCommand6 =>
- _SelectActionCommand6 ?? (_SelectActionCommand6 = new DelegateCommand<int?>(ExecuteSelectActionCommand6));
- private DelegateCommand<int?> _SelectActionCommand7;
- public DelegateCommand<int?> SelectActionCommand7 =>
- _SelectActionCommand7 ?? (_SelectActionCommand7 = new DelegateCommand<int?>(ExecuteSelectActionCommand7));
- #endregion
- #region 方法
- /// <summary>
- /// 选中序列时
- /// </summary>
- async void ExecuteSelectSequenceCommand()
- {
- if (SelectedSequence == -1)
- {
- return;
- }
- if (Feeder == null || !Feeder.IsConnected)
- {
- return;
- }
- try
- {
- var id = SelectedSequence;
- CurrentSequenceActionGroup = await Feeder.GetSequenceGroupAsync(id);
- CurrentSequencePartCntMax = CurrentSequenceActionGroup.PartCntMax;
- SingleSequenceAction1 = CurrentSequenceActionGroup.SingleSequenceActions[0];
- SingleSequenceAction2 = CurrentSequenceActionGroup.SingleSequenceActions[1];
- SingleSequenceAction3 = CurrentSequenceActionGroup.SingleSequenceActions[2];
- SingleSequenceAction4 = CurrentSequenceActionGroup.SingleSequenceActions[3];
- SingleSequenceAction5 = CurrentSequenceActionGroup.SingleSequenceActions[4];
- SingleSequenceAction6 = CurrentSequenceActionGroup.SingleSequenceActions[5];
- SingleSequenceAction7 = CurrentSequenceActionGroup.SingleSequenceActions[6];
- }
- catch (Exception ex)
- {
- LogHelper.WriteLogError(Lang.选中Feeder序列时出错, ex);
- }
- }
- /// <summary>
- /// 开始执行序列
- /// </summary>
- async void ExecuteStartCommand()
- {
- if (Feeder == null)
- {
- return;
- }
- if (SelectedSequence == -1)
- {
- return;
- }
- try
- {
- var needToExecute = CycleRunningTimes;
- while (true)
- {
- var value = await Feeder.StartOneSequenceAsync(SelectedSequence + 1);
- await Task.Delay(value);
- needToExecute--;
- if (needToExecute != 0 && !_manualStop) continue;
- _manualStop = !_manualStop;
- break;
- }
- }
- catch (Exception ex)
- {
- LogHelper.WriteLogError(Lang.执行Feeder序列时出错, ex);
- }
- }
- /// <summary>
- /// 停止执行序列
- /// </summary>
- async void ExecuteStopCommand()
- {
- try
- {
- if (Feeder == null)
- {
- return;
- }
- await Feeder.StopOneSequenceAsync();
- _manualStop = true;
- }
- catch (Exception ex)
- {
- LogHelper.WriteLogError(Lang.停止Feeder序列时出错, ex);
- }
- }
- /// <summary>
- /// 下载
- /// </summary>
- async void ExecuteWriteParamCommand()
- {
- try
- {
- var singleSequenceActions = new[]
- {
- SingleSequenceAction1,SingleSequenceAction2,SingleSequenceAction3,
- SingleSequenceAction4,SingleSequenceAction5,SingleSequenceAction6,
- SingleSequenceAction7
- };
- for (var i = 0; i < singleSequenceActions.Length; i++)
- {
- await Feeder.SetSequenceAsync(SelectedSequence, i, singleSequenceActions[i]);
- }
- await Feeder.SaveSequenceAsync();
- }
- catch (Exception ex)
- {
- LogHelper.WriteLogError(Lang.保存Feeder序列时出错, ex);
- }
- }
- /// <summary>
- /// 选择动作1时触发
- /// </summary>
- void ExecuteSelectActionCommand1(int? index)
- {
- switch (index)
- {
- case null:
- return;
- case 1:
- IsVisibility1 = Visibility.Visible;
- IsVisibility1_2 = Visibility.Visible;
- break;
- case 2:
- IsVisibility1 = Visibility.Visible;
- IsVisibility1_2 = Visibility.Visible;
- break;
- case 3:
- IsVisibility1 = Visibility.Collapsed;
- IsVisibility1_2 = Visibility.Visible;
- break;
- default:
- IsVisibility1 = Visibility.Collapsed;
- IsVisibility1_2 = Visibility.Collapsed;
- break;
- }
- }
- /// <summary>
- /// 选择动作2时触发
- /// </summary>
- void ExecuteSelectActionCommand2(int? index)
- {
- switch (index)
- {
- case null:
- return;
- case 1:
- IsVisibility2 = Visibility.Visible;
- IsVisibility2_2 = Visibility.Visible;
- break;
- case 2:
- IsVisibility2 = Visibility.Visible;
- IsVisibility2_2 = Visibility.Visible;
- break;
- case 3:
- IsVisibility2 = Visibility.Collapsed;
- IsVisibility2_2 = Visibility.Visible;
- break;
- default:
- IsVisibility2 = Visibility.Collapsed;
- IsVisibility2_2 = Visibility.Collapsed;
- break;
- }
- }
- /// <summary>
- /// 选择动作3时触发
- /// </summary>
- void ExecuteSelectActionCommand3(int? index)
- {
- switch (index)
- {
- case null:
- return;
- case 1:
- IsVisibility3 = Visibility.Visible;
- IsVisibility3_2 = Visibility.Visible;
- break;
- case 2:
- IsVisibility3 = Visibility.Visible;
- IsVisibility3_2 = Visibility.Visible;
- break;
- case 3:
- IsVisibility3 = Visibility.Collapsed;
- IsVisibility3_2 = Visibility.Visible;
- break;
- default:
- IsVisibility3 = Visibility.Collapsed;
- IsVisibility3_2 = Visibility.Collapsed;
- break;
- }
- }
- /// <summary>
- /// 选择动作4时触发
- /// </summary>
- void ExecuteSelectActionCommand4(int? index)
- {
- switch (index)
- {
- case null:
- return;
- case 1:
- IsVisibility4 = Visibility.Visible;
- IsVisibility4_2 = Visibility.Visible;
- break;
- case 2:
- IsVisibility4 = Visibility.Visible;
- IsVisibility4_2 = Visibility.Visible;
- break;
- case 3:
- IsVisibility4 = Visibility.Collapsed;
- IsVisibility4_2 = Visibility.Visible;
- break;
- default:
- IsVisibility4 = Visibility.Collapsed;
- IsVisibility4_2 = Visibility.Collapsed;
- break;
- }
- }
- /// <summary>
- /// 选择动作5时触发
- /// </summary>
- void ExecuteSelectActionCommand5(int? index)
- {
- switch (index)
- {
- case null:
- return;
- case 1:
- IsVisibility5 = Visibility.Visible;
- IsVisibility5_2 = Visibility.Visible;
- break;
- case 2:
- IsVisibility5 = Visibility.Visible;
- IsVisibility5_2 = Visibility.Visible;
- break;
- case 3:
- IsVisibility5 = Visibility.Collapsed;
- IsVisibility5_2 = Visibility.Visible;
- break;
- default:
- IsVisibility5 = Visibility.Collapsed;
- IsVisibility5_2 = Visibility.Collapsed;
- break;
- }
- }
- /// <summary>
- /// 选择动作6时触发
- /// </summary>
- void ExecuteSelectActionCommand6(int? index)
- {
- switch (index)
- {
- case null:
- return;
- case 1:
- IsVisibility6 = Visibility.Visible;
- IsVisibility6_2 = Visibility.Visible;
- break;
- case 2:
- IsVisibility6 = Visibility.Visible;
- IsVisibility6_2 = Visibility.Visible;
- break;
- case 3:
- IsVisibility6 = Visibility.Collapsed;
- IsVisibility6_2 = Visibility.Visible;
- break;
- default:
- IsVisibility6 = Visibility.Collapsed;
- IsVisibility6_2 = Visibility.Collapsed;
- break;
- }
- }
- /// <summary>
- /// 选择动作7时触发
- /// </summary>
- void ExecuteSelectActionCommand7(int? index)
- {
- switch (index)
- {
- case null:
- return;
- case 1:
- IsVisibility7 = Visibility.Visible;
- IsVisibility7_2 = Visibility.Visible;
- break;
- case 2:
- IsVisibility7 = Visibility.Visible;
- IsVisibility7_2 = Visibility.Visible;
- break;
- case 3:
- IsVisibility7 = Visibility.Collapsed;
- IsVisibility7_2 = Visibility.Visible;
- break;
- default:
- IsVisibility7 = Visibility.Collapsed;
- IsVisibility7_2 = Visibility.Collapsed;
- break;
- }
- }
- #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
- }
- }
|