MotionControl.xaml.cs 11 KB

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