更新最新
This commit is contained in:
@@ -127,20 +127,65 @@ namespace Footwear_Test_methodsfor_wholeshoe_Slipresistanceperformance.Services
|
|||||||
|
|
||||||
public Task PulseResetAsync() => PulseCoilAsync(ResetCoil);
|
public Task PulseResetAsync() => PulseCoilAsync(ResetCoil);
|
||||||
|
|
||||||
public Task ToggleMoveLeftAsync() => ToggleCoilAsync(MoveLeftCoil);
|
public async Task StartLiftAsync()
|
||||||
|
|
||||||
public Task ToggleMoveRightAsync() => ToggleCoilAsync(MoveRightCoil);
|
|
||||||
|
|
||||||
public async Task LiftAsync()
|
|
||||||
{
|
{
|
||||||
await WriteCoilAsync(LowerCoil, false);
|
await WriteCoilAsync(LowerCoil, false);
|
||||||
await WriteCoilAsync(LiftCoil, true);
|
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(LiftCoil, false);
|
||||||
await WriteCoilAsync(LowerCoil, true);
|
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);
|
public Task WriteManualSpeedAsync(double value) => WriteFloatRegisterAsync(ManualSpeedRegister, value);
|
||||||
|
|||||||
@@ -301,17 +301,23 @@ namespace Footwear_Test_methodsfor_wholeshoe_Slipresistanceperformance.ViewModel
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[RelayCommand]
|
public Task StartLiftMotionAsync() => RunDeviceCommand(deviceService.StartLiftAsync(), "垂直架提升中,松开停止");
|
||||||
private async Task Lift() => await RunDeviceCommand(deviceService.LiftAsync(), "垂直架提升指令已发送 M5");
|
|
||||||
|
|
||||||
[RelayCommand]
|
public Task StopLiftMotionAsync() => RunDeviceCommand(deviceService.StopLiftAsync(), "垂直架提升已停止");
|
||||||
private async Task Lower() => await RunDeviceCommand(deviceService.LowerAsync(), "垂直架下降指令已发送 M4");
|
|
||||||
|
|
||||||
[RelayCommand]
|
public Task StartLowerMotionAsync() => RunDeviceCommand(deviceService.StartLowerAsync(), "垂直架下降中,松开停止");
|
||||||
private async Task MoveLeft() => await RunDeviceCommand(deviceService.ToggleMoveLeftAsync(), "水平板左移状态已切换 M1");
|
|
||||||
|
|
||||||
[RelayCommand]
|
public Task StopLowerMotionAsync() => RunDeviceCommand(deviceService.StopLowerAsync(), "垂直架下降已停止");
|
||||||
private async Task MoveRight() => await RunDeviceCommand(deviceService.ToggleMoveRightAsync(), "水平板右移状态已切换 M2");
|
|
||||||
|
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]
|
[RelayCommand]
|
||||||
private void DeleteSelectedSample()
|
private void DeleteSelectedSample()
|
||||||
@@ -425,6 +431,15 @@ namespace Footwear_Test_methodsfor_wholeshoe_Slipresistanceperformance.ViewModel
|
|||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
refreshTimer.Stop();
|
refreshTimer.Stop();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
deviceService.StopAllMotionAsync().Wait(500);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Log.Warning(ex, "关闭窗口时停止全部运动失败");
|
||||||
|
}
|
||||||
|
|
||||||
deviceService.Dispose();
|
deviceService.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -334,16 +334,38 @@
|
|||||||
<StackPanel Grid.Row="2" Spacing="8">
|
<StackPanel Grid.Row="2" Spacing="8">
|
||||||
<TextBlock Text="垂直架" FontWeight="SemiBold"/>
|
<TextBlock Text="垂直架" FontWeight="SemiBold"/>
|
||||||
<Grid ColumnDefinitions="*,*" ColumnSpacing="8">
|
<Grid ColumnDefinitions="*,*" ColumnSpacing="8">
|
||||||
<Button Content="提升" Classes="motion compact" Command="{Binding LiftCommand}"/>
|
<Button Content="提升"
|
||||||
<Button Grid.Column="1" Content="下降" Classes="motion compact" Command="{Binding LowerCommand}"/>
|
Classes="motion compact"
|
||||||
|
Tag="Lift"
|
||||||
|
PointerPressed="MotionButton_PointerPressed"
|
||||||
|
PointerReleased="MotionButton_PointerReleased"
|
||||||
|
PointerCaptureLost="MotionButton_PointerCaptureLost"/>
|
||||||
|
<Button Grid.Column="1"
|
||||||
|
Content="下降"
|
||||||
|
Classes="motion compact"
|
||||||
|
Tag="Lower"
|
||||||
|
PointerPressed="MotionButton_PointerPressed"
|
||||||
|
PointerReleased="MotionButton_PointerReleased"
|
||||||
|
PointerCaptureLost="MotionButton_PointerCaptureLost"/>
|
||||||
</Grid>
|
</Grid>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
|
|
||||||
<StackPanel Grid.Row="3" Spacing="8">
|
<StackPanel Grid.Row="3" Spacing="8">
|
||||||
<TextBlock Text="水平板" FontWeight="SemiBold"/>
|
<TextBlock Text="水平板" FontWeight="SemiBold"/>
|
||||||
<Grid ColumnDefinitions="*,*" ColumnSpacing="8">
|
<Grid ColumnDefinitions="*,*" ColumnSpacing="8">
|
||||||
<Button Content="左移" Classes="motion compact" Command="{Binding MoveLeftCommand}"/>
|
<Button Content="左移"
|
||||||
<Button Grid.Column="1" Content="右移" Classes="motion compact" Command="{Binding MoveRightCommand}"/>
|
Classes="motion compact"
|
||||||
|
Tag="MoveLeft"
|
||||||
|
PointerPressed="MotionButton_PointerPressed"
|
||||||
|
PointerReleased="MotionButton_PointerReleased"
|
||||||
|
PointerCaptureLost="MotionButton_PointerCaptureLost"/>
|
||||||
|
<Button Grid.Column="1"
|
||||||
|
Content="右移"
|
||||||
|
Classes="motion compact"
|
||||||
|
Tag="MoveRight"
|
||||||
|
PointerPressed="MotionButton_PointerPressed"
|
||||||
|
PointerReleased="MotionButton_PointerReleased"
|
||||||
|
PointerCaptureLost="MotionButton_PointerCaptureLost"/>
|
||||||
</Grid>
|
</Grid>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
|
|
||||||
|
|||||||
@@ -1,23 +1,111 @@
|
|||||||
|
using Avalonia.Controls;
|
||||||
|
using Avalonia.Input;
|
||||||
|
using Footwear_Test_methodsfor_wholeshoe_Slipresistanceperformance.ViewModels;
|
||||||
using SukiUI.Controls;
|
using SukiUI.Controls;
|
||||||
using System;
|
using System;
|
||||||
using Footwear_Test_methodsfor_wholeshoe_Slipresistanceperformance.ViewModels;
|
using System.Collections.Generic;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace Footwear_Test_methodsfor_wholeshoe_Slipresistanceperformance.Views
|
namespace Footwear_Test_methodsfor_wholeshoe_Slipresistanceperformance.Views
|
||||||
{
|
{
|
||||||
public partial class MainWindow : SukiWindow
|
public partial class MainWindow : SukiWindow
|
||||||
{
|
{
|
||||||
|
private readonly HashSet<string> activeMotionTags = [];
|
||||||
|
|
||||||
public MainWindow()
|
public MainWindow()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
Closed += OnClosed;
|
Closed += OnClosed;
|
||||||
|
Deactivated += OnDeactivated;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnClosed(object? sender, EventArgs e)
|
private async void MotionButton_PointerPressed(object? sender, PointerPressedEventArgs e)
|
||||||
{
|
{
|
||||||
|
if (sender is not Button button || button.Tag is not string tag || DataContext is not MainWindowViewModel viewModel)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!activeMotionTags.Add(tag))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
e.Pointer.Capture(button);
|
||||||
|
e.Handled = true;
|
||||||
|
await StartMotionAsync(viewModel, tag);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async void MotionButton_PointerReleased(object? sender, PointerReleasedEventArgs e)
|
||||||
|
{
|
||||||
|
if (sender is not Button button || button.Tag is not string tag || DataContext is not MainWindowViewModel viewModel)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
e.Pointer.Capture(null);
|
||||||
|
e.Handled = true;
|
||||||
|
await StopMotionAsync(viewModel, tag);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async void MotionButton_PointerCaptureLost(object? sender, PointerCaptureLostEventArgs e)
|
||||||
|
{
|
||||||
|
if (sender is not Button button || button.Tag is not string tag || DataContext is not MainWindowViewModel viewModel)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await StopMotionAsync(viewModel, tag);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async void OnDeactivated(object? sender, EventArgs e)
|
||||||
|
{
|
||||||
|
await StopAllMotionAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
private async void OnClosed(object? sender, EventArgs e)
|
||||||
|
{
|
||||||
|
await StopAllMotionAsync();
|
||||||
if (DataContext is MainWindowViewModel viewModel)
|
if (DataContext is MainWindowViewModel viewModel)
|
||||||
{
|
{
|
||||||
viewModel.Dispose();
|
viewModel.Dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static Task StartMotionAsync(MainWindowViewModel viewModel, string tag) =>
|
||||||
|
tag switch
|
||||||
|
{
|
||||||
|
"Lift" => viewModel.StartLiftMotionAsync(),
|
||||||
|
"Lower" => viewModel.StartLowerMotionAsync(),
|
||||||
|
"MoveLeft" => viewModel.StartMoveLeftMotionAsync(),
|
||||||
|
"MoveRight" => viewModel.StartMoveRightMotionAsync(),
|
||||||
|
_ => Task.CompletedTask
|
||||||
|
};
|
||||||
|
|
||||||
|
private async Task StopMotionAsync(MainWindowViewModel viewModel, string tag)
|
||||||
|
{
|
||||||
|
if (!activeMotionTags.Remove(tag))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await (tag switch
|
||||||
|
{
|
||||||
|
"Lift" => viewModel.StopLiftMotionAsync(),
|
||||||
|
"Lower" => viewModel.StopLowerMotionAsync(),
|
||||||
|
"MoveLeft" => viewModel.StopMoveLeftMotionAsync(),
|
||||||
|
"MoveRight" => viewModel.StopMoveRightMotionAsync(),
|
||||||
|
_ => Task.CompletedTask
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task StopAllMotionAsync()
|
||||||
|
{
|
||||||
|
activeMotionTags.Clear();
|
||||||
|
if (DataContext is MainWindowViewModel viewModel)
|
||||||
|
{
|
||||||
|
await viewModel.StopAllMotionAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user