LinMotControl.xaml.cs 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. using MECF.Framework.Common.OperationCenter;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using System.Windows;
  9. using System.Windows.Controls;
  10. using System.Windows.Data;
  11. using System.Windows.Documents;
  12. using System.Windows.Input;
  13. using System.Windows.Media;
  14. using System.Windows.Media.Imaging;
  15. using System.Windows.Navigation;
  16. using System.Windows.Shapes;
  17. namespace CyberX8_Themes.UserControls
  18. {
  19. /// <summary>
  20. /// LinMotControl.xaml 的交互逻辑
  21. /// </summary>
  22. public partial class LinMotControl : UserControl, INotifyPropertyChanged
  23. {
  24. #region 属性
  25. public static readonly DependencyProperty ModuleNameProperty = DependencyProperty.Register("ModuleName", typeof(string), typeof(LinMotControl),
  26. new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.AffectsRender));
  27. /// <summary>
  28. /// 模块名称
  29. /// </summary>
  30. public string ModuleName
  31. {
  32. get
  33. {
  34. return (string)this.GetValue(ModuleNameProperty);
  35. }
  36. set
  37. {
  38. this.SetValue(ModuleNameProperty, value);
  39. }
  40. }
  41. public static readonly DependencyProperty ModuleTitleProperty = DependencyProperty.Register("ModuleTitle", typeof(string), typeof(LinMotControl),
  42. new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.AffectsRender));
  43. /// <summary>
  44. /// 标题
  45. /// </summary>
  46. public string ModuleTitle
  47. {
  48. get
  49. {
  50. return (string)this.GetValue(ModuleTitleProperty);
  51. }
  52. set
  53. {
  54. this.SetValue(ModuleTitleProperty, value);
  55. }
  56. }
  57. public static readonly DependencyProperty ParentModuleProperty = DependencyProperty.Register("ParentModule", typeof(string), typeof(LinMotControl),
  58. new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.AffectsRender));
  59. public event PropertyChangedEventHandler PropertyChanged;
  60. /// <summary>
  61. /// ParentModule
  62. /// </summary>
  63. public string ParentModule
  64. {
  65. get
  66. {
  67. return (string)this.GetValue(ParentModuleProperty);
  68. }
  69. set
  70. {
  71. this.SetValue(ParentModuleProperty, value);
  72. }
  73. }
  74. public static readonly DependencyProperty CurrentSpeedProperty = DependencyProperty.Register("CurrentSpeed", typeof(string), typeof(LinMotControl),
  75. new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.AffectsRender));
  76. /// <summary>
  77. /// 模块名称
  78. /// </summary>
  79. public string CurrentSpeed
  80. {
  81. get
  82. {
  83. return (string)this.GetValue(CurrentSpeedProperty);
  84. }
  85. set
  86. {
  87. this.SetValue(CurrentSpeedProperty, value);
  88. }
  89. }
  90. /// <summary>
  91. /// Speed
  92. /// </summary>
  93. public int Speed
  94. {
  95. get
  96. {
  97. return _speed;
  98. }
  99. set
  100. {
  101. _speed = value;
  102. InvokePropertyChanged(nameof(Speed));
  103. }
  104. }
  105. private int _speed=100;
  106. public static readonly DependencyProperty PositionProperty = DependencyProperty.Register("Position", typeof(double), typeof(LinMotControl));
  107. public double Position
  108. {
  109. get { return (double)this.GetValue(PositionProperty); }
  110. set { SetValue(PositionProperty, value); }
  111. }
  112. public static readonly DependencyProperty IsConnectedProperty = DependencyProperty.Register("IsConnected", typeof(bool), typeof(LinMotControl),
  113. new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
  114. /// <summary>
  115. /// 连接状态
  116. /// </summary>
  117. public bool IsConnected
  118. {
  119. get
  120. {
  121. return (bool)this.GetValue(IsConnectedProperty);
  122. }
  123. set
  124. {
  125. this.SetValue(IsConnectedProperty, value);
  126. }
  127. }
  128. public static readonly DependencyProperty StatusWordProperty = DependencyProperty.Register("StatusWord", typeof(short), typeof(LinMotControl),
  129. new FrameworkPropertyMetadata((short)0,new PropertyChangedCallback(StatusWordPropertyChangedCallBack)));
  130. /// <summary>
  131. /// 状态字
  132. /// </summary>
  133. public short StatusWord
  134. {
  135. get { return (short)this.GetValue(StatusWordProperty); }
  136. set
  137. {
  138. this.SetValue(StatusWordProperty, value);
  139. }
  140. }
  141. private static void StatusWordPropertyChangedCallBack(DependencyObject d, DependencyPropertyChangedEventArgs e)
  142. {
  143. short statusWord = (short)e.NewValue;
  144. d.SetValue(ReadyProperty, (statusWord & 0x01) == 1);
  145. d.SetValue(DisableProperty, (statusWord & 0b0100) >> 2 == 0);
  146. d.SetValue(ErrorProperty, ((statusWord & 0b01000) >> 3 == 1)||((statusWord & 0b01000000000000) >> 12 == 1));
  147. d.SetValue(InitProperty, (statusWord & 0b0100000000000) >> 11 == 1);
  148. d.SetValue(RunProperty, (statusWord & 0b010000000000000) >> 13 == 1);
  149. }
  150. public static readonly DependencyProperty ReadyProperty = DependencyProperty.Register("Ready", typeof(bool), typeof(LinMotControl),
  151. new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
  152. public bool Ready
  153. {
  154. get { return (bool)this.GetValue(ReadyProperty); }
  155. set { SetValue(ReadyProperty, value); }
  156. }
  157. public static readonly DependencyProperty DisableProperty = DependencyProperty.Register("Disable", typeof(bool), typeof(LinMotControl),
  158. new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
  159. public bool Disable
  160. {
  161. get { return (bool)this.GetValue(DisableProperty); }
  162. set { SetValue(DisableProperty, value); }
  163. }
  164. public static readonly DependencyProperty RunProperty = DependencyProperty.Register("Run", typeof(bool), typeof(LinMotControl),
  165. new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
  166. public bool Run
  167. {
  168. get { return (bool)this.GetValue(RunProperty); }
  169. set { SetValue(RunProperty, value); }
  170. }
  171. public static readonly DependencyProperty ErrorProperty = DependencyProperty.Register("Error", typeof(bool), typeof(LinMotControl),
  172. new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
  173. public bool Error
  174. {
  175. get { return (bool)this.GetValue(ErrorProperty); }
  176. set { SetValue(ErrorProperty, value); }
  177. }
  178. public static readonly DependencyProperty InitProperty = DependencyProperty.Register("Init", typeof(bool), typeof(LinMotControl),
  179. new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
  180. public bool Init
  181. {
  182. get { return (bool)this.GetValue(InitProperty); }
  183. set { SetValue(InitProperty, value); }
  184. }
  185. private void InvokePropertyChanged(string propertyName)
  186. {
  187. if (PropertyChanged != null)
  188. {
  189. PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
  190. }
  191. }
  192. #endregion
  193. /// <summary>
  194. /// 构造函数
  195. /// </summary>
  196. public LinMotControl()
  197. {
  198. InitializeComponent();
  199. }
  200. /// <summary>
  201. /// 启动
  202. /// </summary>
  203. /// <param name="sender"></param>
  204. /// <param name="e"></param>
  205. private void Start_Click(object sender, RoutedEventArgs e)
  206. {
  207. InvokeClient.Instance.Service.DoOperation($"{ModuleName}.StartCurve","Speed",new object[] {_speed});
  208. }
  209. private void Stop_Click(object sender, RoutedEventArgs e)
  210. {
  211. InvokeClient.Instance.Service.DoOperation($"{ModuleName}.Stop");
  212. }
  213. private void Abort_Click(object sender, RoutedEventArgs e)
  214. {
  215. InvokeClient.Instance.Service.DoOperation($"{ModuleName}.Abort");
  216. }
  217. private void Reset_Click(object sender, RoutedEventArgs e)
  218. {
  219. InvokeClient.Instance.Service.DoOperation($"{ModuleName}.Reset");
  220. }
  221. }
  222. }