RobotControlII.xaml.cs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. using Aitex.Core.UI.MVVM;
  2. using Aitex.Core.Util;
  3. using Aitex.Sorter.Common;
  4. using Aitex.Sorter.UI.Controls.Common;
  5. using MECF.Framework.Common.OperationCenter;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using System.Windows;
  12. using System.Windows.Controls;
  13. using System.Windows.Data;
  14. using System.Windows.Documents;
  15. using System.Windows.Input;
  16. using System.Windows.Media;
  17. using System.Windows.Media.Imaging;
  18. using System.Windows.Navigation;
  19. using System.Windows.Shapes;
  20. using MECF.Framework.Common.Equipment;
  21. using System.Globalization;
  22. namespace Aitex.Sorter.UI.Controls
  23. {
  24. /// <summary>
  25. /// RobotControl.xaml 的交互逻辑
  26. /// </summary>
  27. public partial class RobotControlII : ViewModelControl
  28. {
  29. public Dictionary<ModuleName, int> TargetII
  30. {
  31. get { return (Dictionary<ModuleName, int>)GetValue(TargetProperty); }
  32. set { SetValue(TargetProperty, value); }
  33. }
  34. // Using a DependencyProperty as the backing store for Target. This enables animation, styling, binding, etc...
  35. public static readonly DependencyProperty TargetProperty =
  36. DependencyProperty.Register("TargetII", typeof(Dictionary<ModuleName, int>), typeof(RobotControlII), new PropertyMetadata(null));
  37. public bool EnableHighSpeed
  38. {
  39. get { return (bool)GetValue(EnableHighSpeedProperty); }
  40. set { SetValue(EnableHighSpeedProperty, value); }
  41. }
  42. // Using a DependencyProperty as the backing store for Target. This enables animation, styling, binding, etc...
  43. public static readonly DependencyProperty EnableHighSpeedProperty =
  44. DependencyProperty.Register("EnableHighSpeed", typeof(bool), typeof(RobotControl), new PropertyMetadata(null));
  45. public RobotControlII()
  46. {
  47. InitializeComponent();
  48. OperationCommand = new DelegateCommand<DependencyObject>(Operation, x => !IsMaintenanceMode && !IsAutoMode);
  49. Command = new DelegateCommand<DependencyObject>(DoCommand, x => !IsMaintenanceMode && !IsAutoMode);
  50. SetSpeedCommand = new DelegateCommand<DependencyObject>(Operation, CanSetSpeed);
  51. var hands = new List<Hand>();
  52. hands.Add(Hand.Blade1);
  53. hands.Add(Hand.Blade2);
  54. Hands = hands.ToArray();
  55. EnableHighSpeed = true;
  56. root.DataContext = this;
  57. }
  58. private bool CanSetSpeed(DependencyObject sender)
  59. {
  60. var command = CommandHelper.GetCommandItem(sender);
  61. var lstParameter = new List<object>(command.Parameters);
  62. if (lstParameter[0].ToString() == RobotSpeed)
  63. return false;
  64. return true;
  65. }
  66. [Subscription(ParamName.RTStatus, "System")]
  67. public int RoutManagerState
  68. {
  69. get;
  70. set;
  71. }
  72. public bool IsMaintenanceMode
  73. {
  74. get => RoutManagerState == (int)RtState.Maintenance;
  75. }
  76. [Subscription(ParamName.IsAutoMode, "System")]
  77. public bool IsAutoMode { get; set; }
  78. public ICommand OperationCommand
  79. {
  80. get;
  81. private set;
  82. }
  83. public ICommand Command
  84. {
  85. get;
  86. private set;
  87. }
  88. public ICommand SetSpeedCommand
  89. {
  90. get;
  91. private set;
  92. }
  93. void Operation(DependencyObject sender)
  94. {
  95. var command = CommandHelper.GetCommandItem(sender);
  96. InvokeClient.Instance.Service.DoOperation(command.CommandName, command.Parameters);
  97. }
  98. private void DoCommand(DependencyObject sender)
  99. {
  100. var command = CommandHelper.GetCommandItem(sender);
  101. var lstParameter = new List<object>(command.Parameters);
  102. lstParameter.Insert(0, command.Target);
  103. lstParameter.Insert(1, command.CommandName);
  104. InvokeClient.Instance.Service.DoOperation(OperationName.DeviceOperation, lstParameter.ToArray());
  105. }
  106. [Subscription(ParamName.RobotState, DeviceName.Robot)]
  107. public string Status
  108. {
  109. get;
  110. set;
  111. }
  112. [Subscription(ParamName.RobotPosRotationAxis, DeviceName.Robot)]
  113. public string RobotPosRotationAxis
  114. {
  115. get;
  116. set;
  117. }
  118. [Subscription(ParamName.RobotPosExtensionAxis, DeviceName.Robot)]
  119. public string RobotPosExtensionAxis
  120. {
  121. get; set;
  122. }
  123. [Subscription(ParamName.RobotPosWrist1Axis, DeviceName.Robot)]
  124. public string RobotPosWrist1Axis
  125. {
  126. get;
  127. set;
  128. }
  129. [Subscription(ParamName.RobotPosWrist2Axis, DeviceName.Robot)]
  130. public string RobotPosWrist2Axis
  131. {
  132. get;
  133. set;
  134. }
  135. [Subscription(ParamName.RobotPosEvevationAxis, DeviceName.Robot)]
  136. public string RobotPosEvevationAxis
  137. {
  138. get;
  139. set;
  140. }
  141. [Subscription(ParamName.RobotBlade1Traget, DeviceName.Robot)]
  142. public string RobotBlade1Traget
  143. {
  144. get;
  145. set;
  146. }
  147. [Subscription(ParamName.RobotBlade2Traget, DeviceName.Robot)]
  148. public string RobotBlade2Traget
  149. {
  150. get;
  151. set;
  152. }
  153. private string robotSpeed;
  154. [Subscription(ParamName.RobotSpeed, DeviceName.Robot)]
  155. public string RobotSpeed
  156. {
  157. get
  158. { return robotSpeed; }
  159. set
  160. {
  161. ChickSpeedSetBtn(value);
  162. robotSpeed = value;
  163. }
  164. }
  165. private void ChickSpeedSetBtn(string speedStr)
  166. {
  167. switch (speedStr)
  168. {
  169. case "Fast":
  170. IsLowEnabled = true;
  171. IsMediumEnabled = true;
  172. IsHighEnabled = false;
  173. break;
  174. case "Medium":
  175. IsLowEnabled = true;
  176. IsMediumEnabled = false;
  177. IsHighEnabled = true;
  178. break;
  179. case "Slow":
  180. IsLowEnabled = false;
  181. IsMediumEnabled = true;
  182. IsHighEnabled = true;
  183. break;
  184. default:
  185. break;
  186. }
  187. }
  188. public bool IsLowEnabled { get; set; }
  189. public bool IsMediumEnabled { get; set; }
  190. public bool IsHighEnabled { get; set; }
  191. [Subscription(ParamName.RobotError, DeviceName.Robot)]
  192. public string ErrorCode
  193. {
  194. get;
  195. set;
  196. }
  197. public Hand[] Hands
  198. {
  199. get;
  200. set;
  201. }
  202. }
  203. }