123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233 |
- using MECF.Framework.Common.OperationCenter;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Linq;
- 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;
- namespace CyberX8_Themes.UserControls
- {
- /// <summary>
- /// LinMotControl.xaml 的交互逻辑
- /// </summary>
- public partial class LinMotControl : UserControl, INotifyPropertyChanged
- {
- #region 属性
- public static readonly DependencyProperty ModuleNameProperty = DependencyProperty.Register("ModuleName", typeof(string), typeof(LinMotControl),
- new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.AffectsRender));
- /// <summary>
- /// 模块名称
- /// </summary>
- public string ModuleName
- {
- get
- {
- return (string)this.GetValue(ModuleNameProperty);
- }
- set
- {
- this.SetValue(ModuleNameProperty, value);
- }
- }
- public static readonly DependencyProperty ModuleTitleProperty = DependencyProperty.Register("ModuleTitle", typeof(string), typeof(LinMotControl),
- new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.AffectsRender));
- /// <summary>
- /// 标题
- /// </summary>
- public string ModuleTitle
- {
- get
- {
- return (string)this.GetValue(ModuleTitleProperty);
- }
- set
- {
- this.SetValue(ModuleTitleProperty, value);
- }
- }
- public static readonly DependencyProperty ParentModuleProperty = DependencyProperty.Register("ParentModule", typeof(string), typeof(LinMotControl),
- new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.AffectsRender));
- public event PropertyChangedEventHandler PropertyChanged;
- /// <summary>
- /// ParentModule
- /// </summary>
- public string ParentModule
- {
- get
- {
- return (string)this.GetValue(ParentModuleProperty);
- }
- set
- {
- this.SetValue(ParentModuleProperty, value);
- }
- }
- public static readonly DependencyProperty CurrentSpeedProperty = DependencyProperty.Register("CurrentSpeed", typeof(string), typeof(LinMotControl),
- new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.AffectsRender));
- /// <summary>
- /// 模块名称
- /// </summary>
- public string CurrentSpeed
- {
- get
- {
- return (string)this.GetValue(CurrentSpeedProperty);
- }
- set
- {
- this.SetValue(CurrentSpeedProperty, value);
- }
- }
- /// <summary>
- /// Speed
- /// </summary>
- public int Speed
- {
- get
- {
- return _speed;
- }
- set
- {
- _speed = value;
- InvokePropertyChanged(nameof(Speed));
- }
- }
- private int _speed=100;
- public static readonly DependencyProperty PositionProperty = DependencyProperty.Register("Position", typeof(double), typeof(LinMotControl));
- public double Position
- {
- get { return (double)this.GetValue(PositionProperty); }
- set { SetValue(PositionProperty, value); }
- }
- public static readonly DependencyProperty IsConnectedProperty = DependencyProperty.Register("IsConnected", typeof(bool), typeof(LinMotControl),
- new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
- /// <summary>
- /// 连接状态
- /// </summary>
- public bool IsConnected
- {
- get
- {
- return (bool)this.GetValue(IsConnectedProperty);
- }
- set
- {
- this.SetValue(IsConnectedProperty, value);
- }
- }
- public static readonly DependencyProperty StatusWordProperty = DependencyProperty.Register("StatusWord", typeof(short), typeof(LinMotControl),
- new FrameworkPropertyMetadata((short)0,new PropertyChangedCallback(StatusWordPropertyChangedCallBack)));
- /// <summary>
- /// 状态字
- /// </summary>
- public short StatusWord
- {
- get { return (short)this.GetValue(StatusWordProperty); }
- set
- {
- this.SetValue(StatusWordProperty, value);
- }
- }
- private static void StatusWordPropertyChangedCallBack(DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- short statusWord = (short)e.NewValue;
- d.SetValue(ReadyProperty, (statusWord & 0x01) == 1);
- d.SetValue(DisableProperty, (statusWord & 0b0100) >> 2 == 0);
- d.SetValue(ErrorProperty, ((statusWord & 0b01000) >> 3 == 1)||((statusWord & 0b01000000000000) >> 12 == 1));
- d.SetValue(InitProperty, (statusWord & 0b0100000000000) >> 11 == 1);
- d.SetValue(RunProperty, (statusWord & 0b010000000000000) >> 13 == 1);
- }
- public static readonly DependencyProperty ReadyProperty = DependencyProperty.Register("Ready", typeof(bool), typeof(LinMotControl),
- new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
- public bool Ready
- {
- get { return (bool)this.GetValue(ReadyProperty); }
- set { SetValue(ReadyProperty, value); }
- }
- public static readonly DependencyProperty DisableProperty = DependencyProperty.Register("Disable", typeof(bool), typeof(LinMotControl),
- new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
- public bool Disable
- {
- get { return (bool)this.GetValue(DisableProperty); }
- set { SetValue(DisableProperty, value); }
- }
- public static readonly DependencyProperty RunProperty = DependencyProperty.Register("Run", typeof(bool), typeof(LinMotControl),
- new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
- public bool Run
- {
- get { return (bool)this.GetValue(RunProperty); }
- set { SetValue(RunProperty, value); }
- }
- public static readonly DependencyProperty ErrorProperty = DependencyProperty.Register("Error", typeof(bool), typeof(LinMotControl),
- new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
- public bool Error
- {
- get { return (bool)this.GetValue(ErrorProperty); }
- set { SetValue(ErrorProperty, value); }
- }
- public static readonly DependencyProperty InitProperty = DependencyProperty.Register("Init", typeof(bool), typeof(LinMotControl),
- new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
- public bool Init
- {
- get { return (bool)this.GetValue(InitProperty); }
- set { SetValue(InitProperty, value); }
- }
- private void InvokePropertyChanged(string propertyName)
- {
- if (PropertyChanged != null)
- {
- PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
- }
- }
- #endregion
- /// <summary>
- /// 构造函数
- /// </summary>
- public LinMotControl()
- {
- InitializeComponent();
- }
- /// <summary>
- /// 启动
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void Start_Click(object sender, RoutedEventArgs e)
- {
- InvokeClient.Instance.Service.DoOperation($"{ModuleName}.StartCurve","Speed",new object[] {_speed});
- }
- private void Stop_Click(object sender, RoutedEventArgs e)
- {
- InvokeClient.Instance.Service.DoOperation($"{ModuleName}.Stop");
- }
- private void Abort_Click(object sender, RoutedEventArgs e)
- {
- InvokeClient.Instance.Service.DoOperation($"{ModuleName}.Abort");
- }
- private void Reset_Click(object sender, RoutedEventArgs e)
- {
- InvokeClient.Instance.Service.DoOperation($"{ModuleName}.Reset");
- }
- }
- }
|