diff --git a/Footwear Test methodsfor wholeshoe Slipresistanceperformance/Services/SlipResistanceDeviceService.cs b/Footwear Test methodsfor wholeshoe Slipresistanceperformance/Services/SlipResistanceDeviceService.cs index 5bc891f..8237277 100644 --- a/Footwear Test methodsfor wholeshoe Slipresistanceperformance/Services/SlipResistanceDeviceService.cs +++ b/Footwear Test methodsfor wholeshoe Slipresistanceperformance/Services/SlipResistanceDeviceService.cs @@ -127,20 +127,65 @@ namespace Footwear_Test_methodsfor_wholeshoe_Slipresistanceperformance.Services public Task PulseResetAsync() => PulseCoilAsync(ResetCoil); - public Task ToggleMoveLeftAsync() => ToggleCoilAsync(MoveLeftCoil); - - public Task ToggleMoveRightAsync() => ToggleCoilAsync(MoveRightCoil); - - public async Task LiftAsync() + public async Task StartLiftAsync() { await WriteCoilAsync(LowerCoil, false); await WriteCoilAsync(LiftCoil, true); + Log.Information("提升按下运行:M{LiftCoil}=1, M{LowerCoil}=0", LiftCoil, LowerCoil); } - public async Task LowerAsync() + public async Task StopLiftAsync() + { + await WriteCoilAsync(LiftCoil, false); + Log.Information("提升松开停止:M{LiftCoil}=0", LiftCoil); + } + + public async Task StartLowerAsync() { await WriteCoilAsync(LiftCoil, false); await WriteCoilAsync(LowerCoil, true); + Log.Information("下降按下运行:M{LowerCoil}=1, M{LiftCoil}=0", LowerCoil, LiftCoil); + } + + public async Task StopLowerAsync() + { + await WriteCoilAsync(LowerCoil, false); + Log.Information("下降松开停止:M{LowerCoil}=0", LowerCoil); + } + + public async Task StartMoveLeftAsync() + { + await WriteCoilAsync(MoveRightCoil, false); + await WriteCoilAsync(MoveLeftCoil, true); + Log.Information("左移按下运行:M{MoveLeftCoil}=1, M{MoveRightCoil}=0", MoveLeftCoil, MoveRightCoil); + } + + public async Task StopMoveLeftAsync() + { + await WriteCoilAsync(MoveLeftCoil, false); + Log.Information("左移松开停止:M{MoveLeftCoil}=0", MoveLeftCoil); + } + + public async Task StartMoveRightAsync() + { + await WriteCoilAsync(MoveLeftCoil, false); + await WriteCoilAsync(MoveRightCoil, true); + Log.Information("右移按下运行:M{MoveRightCoil}=1, M{MoveLeftCoil}=0", MoveRightCoil, MoveLeftCoil); + } + + public async Task StopMoveRightAsync() + { + await WriteCoilAsync(MoveRightCoil, false); + Log.Information("右移松开停止:M{MoveRightCoil}=0", MoveRightCoil); + } + + public async Task StopAllMotionAsync() + { + await WriteCoilAsync(LiftCoil, false); + await WriteCoilAsync(LowerCoil, false); + await WriteCoilAsync(MoveLeftCoil, false); + await WriteCoilAsync(MoveRightCoil, false); + Log.Information("全部运动停止:M{LiftCoil}=0, M{LowerCoil}=0, M{MoveLeftCoil}=0, M{MoveRightCoil}=0", LiftCoil, LowerCoil, MoveLeftCoil, MoveRightCoil); } public Task WriteManualSpeedAsync(double value) => WriteFloatRegisterAsync(ManualSpeedRegister, value); diff --git a/Footwear Test methodsfor wholeshoe Slipresistanceperformance/ViewModels/MainWindowViewModel.cs b/Footwear Test methodsfor wholeshoe Slipresistanceperformance/ViewModels/MainWindowViewModel.cs index aeb3188..4e4a402 100644 --- a/Footwear Test methodsfor wholeshoe Slipresistanceperformance/ViewModels/MainWindowViewModel.cs +++ b/Footwear Test methodsfor wholeshoe Slipresistanceperformance/ViewModels/MainWindowViewModel.cs @@ -301,17 +301,23 @@ namespace Footwear_Test_methodsfor_wholeshoe_Slipresistanceperformance.ViewModel } } - [RelayCommand] - private async Task Lift() => await RunDeviceCommand(deviceService.LiftAsync(), "垂直架提升指令已发送 M5"); + public Task StartLiftMotionAsync() => RunDeviceCommand(deviceService.StartLiftAsync(), "垂直架提升中,松开停止"); - [RelayCommand] - private async Task Lower() => await RunDeviceCommand(deviceService.LowerAsync(), "垂直架下降指令已发送 M4"); + public Task StopLiftMotionAsync() => RunDeviceCommand(deviceService.StopLiftAsync(), "垂直架提升已停止"); - [RelayCommand] - private async Task MoveLeft() => await RunDeviceCommand(deviceService.ToggleMoveLeftAsync(), "水平板左移状态已切换 M1"); + public Task StartLowerMotionAsync() => RunDeviceCommand(deviceService.StartLowerAsync(), "垂直架下降中,松开停止"); - [RelayCommand] - private async Task MoveRight() => await RunDeviceCommand(deviceService.ToggleMoveRightAsync(), "水平板右移状态已切换 M2"); + public Task StopLowerMotionAsync() => RunDeviceCommand(deviceService.StopLowerAsync(), "垂直架下降已停止"); + + public Task StartMoveLeftMotionAsync() => RunDeviceCommand(deviceService.StartMoveLeftAsync(), "水平板左移中,松开停止"); + + public Task StopMoveLeftMotionAsync() => RunDeviceCommand(deviceService.StopMoveLeftAsync(), "水平板左移已停止"); + + public Task StartMoveRightMotionAsync() => RunDeviceCommand(deviceService.StartMoveRightAsync(), "水平板右移中,松开停止"); + + public Task StopMoveRightMotionAsync() => RunDeviceCommand(deviceService.StopMoveRightAsync(), "水平板右移已停止"); + + public Task StopAllMotionAsync() => RunDeviceCommand(deviceService.StopAllMotionAsync(), "全部运动已停止"); [RelayCommand] private void DeleteSelectedSample() @@ -425,6 +431,15 @@ namespace Footwear_Test_methodsfor_wholeshoe_Slipresistanceperformance.ViewModel public void Dispose() { refreshTimer.Stop(); + try + { + deviceService.StopAllMotionAsync().Wait(500); + } + catch (Exception ex) + { + Log.Warning(ex, "关闭窗口时停止全部运动失败"); + } + deviceService.Dispose(); } diff --git a/Footwear Test methodsfor wholeshoe Slipresistanceperformance/Views/MainWindow.axaml b/Footwear Test methodsfor wholeshoe Slipresistanceperformance/Views/MainWindow.axaml index 56203c1..6189f40 100644 --- a/Footwear Test methodsfor wholeshoe Slipresistanceperformance/Views/MainWindow.axaml +++ b/Footwear Test methodsfor wholeshoe Slipresistanceperformance/Views/MainWindow.axaml @@ -334,16 +334,38 @@ -