SRDMotionControl.xaml.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. using Aitex.Core.UI.MVVM;
  2. using Aitex.Core.Utilities;
  3. using MECF.Framework.Common.CommonData.PUF;
  4. using MECF.Framework.Common.OperationCenter;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows;
  11. using System.Windows.Controls;
  12. using System.Windows.Data;
  13. using System.Windows.Documents;
  14. using System.Windows.Input;
  15. using System.Windows.Media;
  16. using System.Windows.Media.Imaging;
  17. using System.Windows.Navigation;
  18. using System.Windows.Shapes;
  19. namespace CyberX8_Themes.UserControls
  20. {
  21. /// <summary>
  22. /// SRDMotionControl.xaml 的交互逻辑
  23. /// </summary>
  24. public partial class SRDMotionControl : UserControl
  25. {
  26. #region 属性
  27. public static readonly DependencyProperty ModuleNameProperty = DependencyProperty.Register(
  28. "ModuleName", typeof(string), typeof(SRDMotionControl), new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.AffectsRender));
  29. /// <summary>
  30. /// 模块名称
  31. /// </summary>
  32. public string ModuleName
  33. {
  34. get
  35. {
  36. return (string)this.GetValue(ModuleNameProperty);
  37. }
  38. set
  39. {
  40. this.SetValue(ModuleNameProperty, value);
  41. }
  42. }
  43. public static readonly DependencyProperty ModuleTitleProperty = DependencyProperty.Register(
  44. "ModuleTitle", typeof(string), typeof(SRDMotionControl), new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.AffectsRender));
  45. /// <summary>
  46. /// 标题
  47. /// </summary>
  48. public string ModuleTitle
  49. {
  50. get
  51. {
  52. return (string)this.GetValue(ModuleTitleProperty);
  53. }
  54. set
  55. {
  56. this.SetValue(ModuleTitleProperty, value);
  57. }
  58. }
  59. public static readonly DependencyProperty ModuleUnitProperty = DependencyProperty.Register(
  60. "ModuleUnit", typeof(string), typeof(SRDMotionControl), new FrameworkPropertyMetadata("deg", FrameworkPropertyMetadataOptions.AffectsRender));
  61. /// <summary>
  62. /// 标题
  63. /// </summary>
  64. public string ModuleUnit
  65. {
  66. get
  67. {
  68. return (string)this.GetValue(ModuleUnitProperty);
  69. }
  70. set
  71. {
  72. this.SetValue(ModuleUnitProperty, value);
  73. }
  74. }
  75. public static readonly DependencyProperty InputSpeedProperty = DependencyProperty.Register(
  76. "InputSpeed", typeof(double), typeof(SRDMotionControl), new FrameworkPropertyMetadata(0.00, FrameworkPropertyMetadataOptions.AffectsRender));
  77. /// <summary>
  78. /// InSpeed
  79. /// </summary>
  80. public double InputSpeed
  81. {
  82. get
  83. {
  84. return (double)this.GetValue(InputSpeedProperty);
  85. }
  86. set
  87. {
  88. this.SetValue(InputSpeedProperty, value);
  89. }
  90. }
  91. public static readonly DependencyProperty InputAccelerationProperty = DependencyProperty.Register(
  92. "InputAcceleration", typeof(double), typeof(SRDMotionControl), new FrameworkPropertyMetadata(0.00, FrameworkPropertyMetadataOptions.AffectsRender));
  93. /// <summary>
  94. /// InSpeed
  95. /// </summary>
  96. public double InputAcceleration
  97. {
  98. get
  99. {
  100. return (double)this.GetValue(InputAccelerationProperty);
  101. }
  102. set
  103. {
  104. this.SetValue(InputAccelerationProperty, value);
  105. }
  106. }
  107. public static readonly DependencyProperty InputDecelerationProperty = DependencyProperty.Register(
  108. "InputDeceleration", typeof(double), typeof(SRDMotionControl), new FrameworkPropertyMetadata(0.00, FrameworkPropertyMetadataOptions.AffectsRender));
  109. /// <summary>
  110. /// InputDeceleration
  111. /// </summary>
  112. public double InputDeceleration
  113. {
  114. get
  115. {
  116. return (double)this.GetValue(InputDecelerationProperty);
  117. }
  118. set
  119. {
  120. this.SetValue(InputDecelerationProperty, value);
  121. }
  122. }
  123. public static readonly DependencyProperty InputHomeSpeedSwitchProperty = DependencyProperty.Register(
  124. "InputHomeSpeedSwitch", typeof(double), typeof(SRDMotionControl), new FrameworkPropertyMetadata(0.00, FrameworkPropertyMetadataOptions.AffectsRender));
  125. /// <summary>
  126. /// InputHomeSpeedSwitch
  127. /// </summary>
  128. public double InputHomeSpeedSwitch
  129. {
  130. get
  131. {
  132. return (double)this.GetValue(InputHomeSpeedSwitchProperty);
  133. }
  134. set
  135. {
  136. this.SetValue(InputHomeSpeedSwitchProperty, value);
  137. }
  138. }
  139. public static readonly DependencyProperty InputHomeSpeedIndexProperty = DependencyProperty.Register(
  140. "InputHomeSpeedIndex", typeof(double), typeof(SRDMotionControl), new FrameworkPropertyMetadata(0.00, FrameworkPropertyMetadataOptions.AffectsRender));
  141. /// <summary>
  142. /// InputHomeSpeedIndex
  143. /// </summary>
  144. public double InputHomeSpeedIndex
  145. {
  146. get
  147. {
  148. return (double)this.GetValue(InputHomeSpeedIndexProperty);
  149. }
  150. set
  151. {
  152. this.SetValue(InputHomeSpeedIndexProperty, value);
  153. }
  154. }
  155. public static readonly DependencyProperty JogValueIndexProperty = DependencyProperty.Register(
  156. "JogValue", typeof(double), typeof(SRDMotionControl), new FrameworkPropertyMetadata(0.00, FrameworkPropertyMetadataOptions.AffectsRender));
  157. /// <summary>
  158. /// JogValue
  159. /// </summary>
  160. public double JogValue
  161. {
  162. get
  163. {
  164. return (double)this.GetValue(JogValueIndexProperty);
  165. }
  166. set
  167. {
  168. this.SetValue(JogValueIndexProperty, value);
  169. }
  170. }
  171. public static readonly DependencyProperty InputHomeAccelDecelProperty = DependencyProperty.Register(
  172. "InputHomeAccelDecel", typeof(double), typeof(SRDMotionControl), new FrameworkPropertyMetadata(0.00, FrameworkPropertyMetadataOptions.AffectsRender));
  173. /// <summary>
  174. /// InputHomeAccelDecel
  175. /// </summary>
  176. public double InputHomeAccelDecel
  177. {
  178. get
  179. {
  180. return (double)this.GetValue(InputHomeAccelDecelProperty);
  181. }
  182. set
  183. {
  184. this.SetValue(InputHomeAccelDecelProperty, value);
  185. }
  186. }
  187. public static readonly DependencyProperty MotionDataProperty = DependencyProperty.Register(
  188. "MotionData", typeof(CommandMotionData), typeof(SRDMotionControl), new FrameworkPropertyMetadata(null, new PropertyChangedCallback(OnItemsSourceChanged)));
  189. /// <summary>
  190. /// MotionData
  191. /// </summary>
  192. public CommandMotionData MotionData
  193. {
  194. get
  195. {
  196. return (CommandMotionData)this.GetValue(MotionDataProperty);
  197. }
  198. set
  199. {
  200. this.SetValue(MotionDataProperty, value);
  201. }
  202. }
  203. private static void OnItemsSourceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
  204. {
  205. if (e.NewValue != null)
  206. {
  207. CommandMotionData data = (CommandMotionData)e.NewValue;
  208. d.SetValue(InputSpeedProperty, data.FileProfileVelocity);
  209. d.SetValue(InputAccelerationProperty, data.FileAcceleration);
  210. d.SetValue(InputDecelerationProperty, data.FileDeceleration);
  211. d.SetValue(InputHomeSpeedSwitchProperty, data.FileHomingVelocity);
  212. d.SetValue(InputHomeSpeedIndexProperty, data.FileHomingVelocitySlow);
  213. d.SetValue(InputHomeAccelDecelProperty, data.FileHomingAccel);
  214. }
  215. }
  216. public static readonly DependencyProperty IncrementValueProperty = DependencyProperty.Register("IncrementValue", typeof(double), typeof(SRDMotionControl));
  217. /// <summary>
  218. /// 当前位置
  219. /// </summary>
  220. public double IncrementValue
  221. {
  222. get
  223. {
  224. return (double)this.GetValue(IncrementValueProperty);
  225. }
  226. set
  227. {
  228. this.SetValue(IncrementValueProperty, Math.Round(value, 2));
  229. }
  230. }
  231. [IgnorePropertyChange]
  232. public ICommand KeyDownCommand
  233. {
  234. get;
  235. private set;
  236. }
  237. #endregion
  238. /// <summary>
  239. /// 构造函数
  240. /// </summary>
  241. public SRDMotionControl()
  242. {
  243. KeyDownCommand = new DelegateCommand<object[]>(KeyDownAction);
  244. InitializeComponent();
  245. }
  246. private void KeyDownAction(object[] param)
  247. {
  248. if (param.Length >= 2)
  249. {
  250. if (double.TryParse(param[1].ToString(), out double paramValue))
  251. {
  252. InvokeClient.Instance.Service.DoOperation($"{ModuleName}.KeyDown", param[0].ToString(), paramValue);
  253. }
  254. }
  255. }
  256. private void JogDown_Click(object sender, RoutedEventArgs e)
  257. {
  258. InvokeClient.Instance.Service.DoOperation($"{ModuleName}.JogDown", "TargetPosition", JogValue, MotionData.MotorPosition);
  259. }
  260. private void JogUp_Click(object sender, RoutedEventArgs e)
  261. {
  262. InvokeClient.Instance.Service.DoOperation($"{ModuleName}.JogUp", "TargetPosition", JogValue, MotionData.MotorPosition);
  263. }
  264. private void JogStop_Click(object sender, RoutedEventArgs e)
  265. {
  266. InvokeClient.Instance.Service.DoOperation($"{ModuleName}.Stop");
  267. }
  268. private void SwitchOn_Click(object sender, RoutedEventArgs e)
  269. {
  270. InvokeClient.Instance.Service.DoOperation($"{ModuleName}.SwitchOn");
  271. }
  272. private void SwitchOff_Click(object sender, RoutedEventArgs e)
  273. {
  274. InvokeClient.Instance.Service.DoOperation($"{ModuleName}.SwitchOff");
  275. }
  276. private void Home_Click(object sender, RoutedEventArgs e)
  277. {
  278. InvokeClient.Instance.Service.DoOperation($"{ModuleName}.Home");
  279. }
  280. }
  281. }