diff --git a/XplorePlane/ViewModels/Main/MainViewModel.cs b/XplorePlane/ViewModels/Main/MainViewModel.cs index a9ae943..26e6403 100644 --- a/XplorePlane/ViewModels/Main/MainViewModel.cs +++ b/XplorePlane/ViewModels/Main/MainViewModel.cs @@ -21,6 +21,7 @@ using XP.Common.Logging.Interfaces; using XP.Common.GeneralForm.Views; using XP.Common.PdfViewer.Interfaces; using XP.Hardware.MotionControl.Abstractions; +using XP.Hardware.MotionControl.Services; namespace XplorePlane.ViewModels { @@ -90,6 +91,8 @@ namespace XplorePlane.ViewModels // 硬件命令 public DelegateCommand AxisResetCommand { get; } + public DelegateCommand OpenDoorCommand { get; } + public DelegateCommand CloseDoorCommand { get; } public DelegateCommand OpenDetectorConfigCommand { get; } public DelegateCommand OpenMotionDebugCommand { get; } public DelegateCommand OpenPlcAddrConfigCommand { get; } @@ -295,6 +298,8 @@ namespace XplorePlane.ViewModels _eventAggregator.GetEvent().Publish()); AxisResetCommand = new DelegateCommand(ExecuteAxisReset); + OpenDoorCommand = new DelegateCommand(ExecuteOpenDoor); + CloseDoorCommand = new DelegateCommand(ExecuteCloseDoor); OpenDetectorConfigCommand = new DelegateCommand(ExecuteOpenDetectorConfig); OpenMotionDebugCommand = new DelegateCommand(ExecuteOpenMotionDebug); OpenPlcAddrConfigCommand = new DelegateCommand(ExecuteOpenPlcAddrConfig); @@ -589,6 +594,46 @@ namespace XplorePlane.ViewModels } } + private void ExecuteOpenDoor() + { + try + { + var motionService = _containerProvider.Resolve(); + var result = motionService.OpenDoor(); + if (!result.Success) + { + MessageBox.Show($"Open door failed: {result.ErrorMessage}", "Error", + MessageBoxButton.OK, MessageBoxImage.Warning); + } + } + catch (Exception ex) + { + _logger.Error(ex, "Open door failed."); + MessageBox.Show($"Open door error: {ex.Message}", "Error", + MessageBoxButton.OK, MessageBoxImage.Error); + } + } + + private void ExecuteCloseDoor() + { + try + { + var motionService = _containerProvider.Resolve(); + var result = motionService.CloseDoor(); + if (!result.Success) + { + MessageBox.Show($"Close door failed: {result.ErrorMessage}", "Error", + MessageBoxButton.OK, MessageBoxImage.Warning); + } + } + catch (Exception ex) + { + _logger.Error(ex, "Close door failed."); + MessageBox.Show($"Close door error: {ex.Message}", "Error", + MessageBoxButton.OK, MessageBoxImage.Error); + } + } + private void ExecuteOpenDetectorConfig() { try diff --git a/XplorePlane/Views/Main/MainWindow.xaml b/XplorePlane/Views/Main/MainWindow.xaml index ea42682..46b1ab1 100644 --- a/XplorePlane/Views/Main/MainWindow.xaml +++ b/XplorePlane/Views/Main/MainWindow.xaml @@ -138,12 +138,14 @@