PrewetMotionPanel.xaml.cs 8.6 KB

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