BrooksMag7RobotTesterView.xaml.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. using Aitex.Core.UI.MVVM;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Collections.ObjectModel;
  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. using MECF.Framework.Simulator.Core.Driver;
  18. namespace MECF.Framework.Simulator.Core.Robots
  19. {
  20. /// <summary>
  21. /// BrooksMag7View.xaml 的交互逻辑
  22. /// </summary>
  23. public partial class BrooksMag7RobotTesterView : UserControl
  24. {
  25. public BrooksMag7RobotTesterView()
  26. {
  27. InitializeComponent();
  28. this.DataContext = new BrooksMag7ViewModel();
  29. this.Loaded += SxFxView_Loaded;
  30. }
  31. private void SxFxView_Loaded(object sender, RoutedEventArgs e)
  32. {
  33. (DataContext as BrooksMag7ViewModel).Start();
  34. }
  35. }
  36. class BrooksMag7ViewModel : TimerViewModelBase
  37. {
  38. public ICommand ClearLogCommand { get; set; }
  39. public ICommand EnableCommand { get; set; }
  40. public ICommand DisableCommand { get; set; }
  41. public ICommand HomeCommand { get; set; }
  42. public ICommand PickCommand { get; set; }
  43. public ICommand PlaceCommand { get; set; }
  44. public bool IsEnableEnable
  45. {
  46. get { return !_robot.IsEnabled; }
  47. }
  48. public bool IsEnableDisable
  49. {
  50. get { return _robot.IsEnabled; }
  51. }
  52. public ObservableCollection< TransactionLogItem> TransactionLogItems { get; set; }
  53. private BrooksMag7RobotSimulator _robot;
  54. public BrooksMag7ViewModel() : base("BrooksMag7ViewModel")
  55. {
  56. ClearLogCommand = new DelegateCommand<string>(ClearLog);
  57. //EnableCommand = new DelegateCommand<string>(Enable);
  58. //DisableCommand = new DelegateCommand<string>(Disable);
  59. TransactionLogItems = new ObservableCollection<TransactionLogItem>();
  60. _robot = new BrooksMag7RobotSimulator();
  61. //HomeCommand = new DelegateCommand<string>(HomeAll);
  62. //PickCommand = new DelegateCommand<string>(Pick);
  63. //PlaceCommand = new DelegateCommand<string>(Place);
  64. _robot.MessageOut += _robot_MessageOut;
  65. _robot.MessageIn += _robot_MessageIn;
  66. }
  67. //private void HomeAll(string obj)
  68. //{
  69. // _robot.HomeAll();
  70. //}
  71. //private void Pick(string obj)
  72. //{
  73. // _robot.Pick();
  74. //}
  75. //private void Place(string obj)
  76. //{
  77. // _robot.Place();
  78. //}
  79. //private void Disable(string obj)
  80. //{
  81. // _robot.Disable();
  82. //}
  83. //private void Enable(string obj)
  84. //{
  85. // _robot.Enable();
  86. //}
  87. private void ClearLog(string obj)
  88. {
  89. TransactionLogItems.Clear();
  90. }
  91. private void _robot_MessageIn(string obj)
  92. {
  93. Application.Current.Dispatcher.Invoke(new Action(() =>
  94. {
  95. TransactionLogItems.Add(new TransactionLogItem() { Incoming = obj, OccurTime = DateTime.Now.ToString("HH:mm:ss.fff") });
  96. }));
  97. }
  98. private void _robot_MessageOut(string obj)
  99. {
  100. Application.Current.Dispatcher.Invoke(new Action(() =>
  101. {
  102. TransactionLogItems.Add(new TransactionLogItem() { Outgoing = obj, OccurTime = DateTime.Now.ToString("HH:mm:ss.fff") });
  103. }));
  104. }
  105. protected override void Poll()
  106. {
  107. Application.Current.Dispatcher.Invoke(new Action(() =>
  108. {
  109. InvokeAllPropertyChanged();
  110. }));
  111. }
  112. }
  113. }