diff --git a/Footwear Test methodsfor wholeshoe Slipresistanceperformance/ViewModels/MainWindowViewModel.cs b/Footwear Test methodsfor wholeshoe Slipresistanceperformance/ViewModels/MainWindowViewModel.cs
index 46633e7..fe7d395 100644
--- a/Footwear Test methodsfor wholeshoe Slipresistanceperformance/ViewModels/MainWindowViewModel.cs
+++ b/Footwear Test methodsfor wholeshoe Slipresistanceperformance/ViewModels/MainWindowViewModel.cs
@@ -42,6 +42,7 @@ namespace Footwear_Test_methodsfor_wholeshoe_Slipresistanceperformance.ViewModel
private const string LegacyPlcPortName = "COM7";
private const string LegacyAdcPortName = "COM8";
private static readonly TimeSpan ResetButtonPendingTimeout = TimeSpan.FromMilliseconds(800);
+ private static readonly TimeSpan TestButtonPendingTimeout = TimeSpan.FromSeconds(5);
private static readonly TimeSpan RealtimeCurveTraceInterval = TimeSpan.FromSeconds(1);
private readonly SlipResistanceDeviceService deviceService = new();
@@ -56,6 +57,8 @@ namespace Footwear_Test_methodsfor_wholeshoe_Slipresistanceperformance.ViewModel
private bool isLoadingDeviceSettings;
private bool wasRunning;
+ private bool isTestStartPending;
+ private DateTime testStartPendingStartedAt = DateTime.MinValue;
private bool isResetButtonPending;
private bool hasObservedResetDeviceBusy;
private DateTime resetButtonPendingStartedAt = DateTime.MinValue;
@@ -165,6 +168,9 @@ namespace Footwear_Test_methodsfor_wholeshoe_Slipresistanceperformance.ViewModel
[ObservableProperty]
private string testButtonText = "测试";
+ [ObservableProperty]
+ private bool isTestButtonEnabled = true;
+
[ObservableProperty]
private string resetButtonText = "复位";
@@ -319,11 +325,15 @@ namespace Footwear_Test_methodsfor_wholeshoe_Slipresistanceperformance.ViewModel
[RelayCommand]
private async Task StartTest()
{
+ if (!IsTestButtonEnabled)
+ {
+ return;
+ }
+
ApplyConnectionSettings();
var device = deviceService.CurrentSnapshot;
if (device.IsTestRunning)
{
- await RunDeviceCommand(deviceService.PulseStopTestAsync(), "已按老代码逻辑发送停止指令 M83");
return;
}
@@ -332,7 +342,19 @@ namespace Footwear_Test_methodsfor_wholeshoe_Slipresistanceperformance.ViewModel
return;
}
- await RunDeviceCommand(deviceService.PulseStartTestAsync(), "已按老代码逻辑发送测试启动指令 M80,等待 M81 运行状态");
+ BeginTestButtonFeedback();
+ try
+ {
+ await deviceService.PulseStartTestAsync();
+ CurrentStatus = "已按老代码逻辑发送测试启动指令 M80,等待 M81 运行状态";
+ }
+ catch (Exception ex)
+ {
+ Log.Error(ex, "设备指令失败:已按老代码逻辑发送测试启动指令 M80");
+ CurrentStatus = $"设备指令失败:{ex.Message}";
+ ClearTestButtonFeedback();
+ UpdateTestButtonState(deviceService.CurrentSnapshot);
+ }
}
[RelayCommand]
@@ -608,7 +630,6 @@ namespace Footwear_Test_methodsfor_wholeshoe_Slipresistanceperformance.ViewModel
if (device.IsConnected)
{
DeviceStatus = device.IsTestRunning ? "联机 / 测试中" : device.IsResetting ? "联机 / 复位中" : "联机 / 待机";
- TestButtonText = device.IsTestRunning ? "停止" : "测试";
UpdateResetButtonText(device);
VerticalPressure = device.VerticalLoadN.ToString("F1", CultureInfo.InvariantCulture);
HorizontalForce = device.HorizontalFrictionN.ToString("F1", CultureInfo.InvariantCulture);
@@ -619,7 +640,6 @@ namespace Footwear_Test_methodsfor_wholeshoe_Slipresistanceperformance.ViewModel
else
{
DeviceStatus = IsAdcCalibrationError(device.LastError) ? "数据无效" : "离线";
- TestButtonText = device.IsTestRunning ? "停止" : "测试";
UpdateResetButtonText(device);
VerticalPressure = "--";
HorizontalForce = "--";
@@ -628,6 +648,8 @@ namespace Footwear_Test_methodsfor_wholeshoe_Slipresistanceperformance.ViewModel
ActualLoadText = "-- N";
}
+ UpdateTestButtonState(device);
+
if (!device.IsConnected && !string.IsNullOrWhiteSpace(device.LastError))
{
CurrentStatus = IsAdcCalibrationError(device.LastError)
@@ -661,6 +683,43 @@ namespace Footwear_Test_methodsfor_wholeshoe_Slipresistanceperformance.ViewModel
wasRunning = isRecording;
}
+ private void BeginTestButtonFeedback()
+ {
+ isTestStartPending = true;
+ testStartPendingStartedAt = DateTime.UtcNow;
+ TestButtonText = "测试中";
+ IsTestButtonEnabled = false;
+ }
+
+ private void ClearTestButtonFeedback()
+ {
+ isTestStartPending = false;
+ testStartPendingStartedAt = DateTime.MinValue;
+ }
+
+ private void UpdateTestButtonState(SlipDeviceSnapshot device)
+ {
+ if (device.IsTestRunning)
+ {
+ ClearTestButtonFeedback();
+ TestButtonText = "测试中";
+ IsTestButtonEnabled = false;
+ return;
+ }
+
+ if (isTestStartPending
+ && DateTime.UtcNow - testStartPendingStartedAt < TestButtonPendingTimeout)
+ {
+ TestButtonText = "测试中";
+ IsTestButtonEnabled = false;
+ return;
+ }
+
+ ClearTestButtonFeedback();
+ TestButtonText = "测试";
+ IsTestButtonEnabled = true;
+ }
+
private void BeginResetButtonFeedback()
{
isResetButtonPending = true;
diff --git a/Footwear Test methodsfor wholeshoe Slipresistanceperformance/Views/MainWindow.axaml b/Footwear Test methodsfor wholeshoe Slipresistanceperformance/Views/MainWindow.axaml
index 57d4257..ec45bed 100644
--- a/Footwear Test methodsfor wholeshoe Slipresistanceperformance/Views/MainWindow.axaml
+++ b/Footwear Test methodsfor wholeshoe Slipresistanceperformance/Views/MainWindow.axaml
@@ -357,6 +357,7 @@
Command="{Binding ClearCommand}"/>