更新2026

This commit is contained in:
GukSang.Jin
2026-06-08 18:49:29 +08:00
parent 9ccf012cec
commit 2fc1dd89a2
2 changed files with 64 additions and 4 deletions

View File

@@ -42,6 +42,7 @@ namespace Footwear_Test_methodsfor_wholeshoe_Slipresistanceperformance.ViewModel
private const string LegacyPlcPortName = "COM7"; private const string LegacyPlcPortName = "COM7";
private const string LegacyAdcPortName = "COM8"; private const string LegacyAdcPortName = "COM8";
private static readonly TimeSpan ResetButtonPendingTimeout = TimeSpan.FromMilliseconds(800); 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 static readonly TimeSpan RealtimeCurveTraceInterval = TimeSpan.FromSeconds(1);
private readonly SlipResistanceDeviceService deviceService = new(); private readonly SlipResistanceDeviceService deviceService = new();
@@ -56,6 +57,8 @@ namespace Footwear_Test_methodsfor_wholeshoe_Slipresistanceperformance.ViewModel
private bool isLoadingDeviceSettings; private bool isLoadingDeviceSettings;
private bool wasRunning; private bool wasRunning;
private bool isTestStartPending;
private DateTime testStartPendingStartedAt = DateTime.MinValue;
private bool isResetButtonPending; private bool isResetButtonPending;
private bool hasObservedResetDeviceBusy; private bool hasObservedResetDeviceBusy;
private DateTime resetButtonPendingStartedAt = DateTime.MinValue; private DateTime resetButtonPendingStartedAt = DateTime.MinValue;
@@ -165,6 +168,9 @@ namespace Footwear_Test_methodsfor_wholeshoe_Slipresistanceperformance.ViewModel
[ObservableProperty] [ObservableProperty]
private string testButtonText = "测试"; private string testButtonText = "测试";
[ObservableProperty]
private bool isTestButtonEnabled = true;
[ObservableProperty] [ObservableProperty]
private string resetButtonText = "复位"; private string resetButtonText = "复位";
@@ -319,11 +325,15 @@ namespace Footwear_Test_methodsfor_wholeshoe_Slipresistanceperformance.ViewModel
[RelayCommand] [RelayCommand]
private async Task StartTest() private async Task StartTest()
{ {
if (!IsTestButtonEnabled)
{
return;
}
ApplyConnectionSettings(); ApplyConnectionSettings();
var device = deviceService.CurrentSnapshot; var device = deviceService.CurrentSnapshot;
if (device.IsTestRunning) if (device.IsTestRunning)
{ {
await RunDeviceCommand(deviceService.PulseStopTestAsync(), "已按老代码逻辑发送停止指令 M83");
return; return;
} }
@@ -332,7 +342,19 @@ namespace Footwear_Test_methodsfor_wholeshoe_Slipresistanceperformance.ViewModel
return; 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] [RelayCommand]
@@ -608,7 +630,6 @@ namespace Footwear_Test_methodsfor_wholeshoe_Slipresistanceperformance.ViewModel
if (device.IsConnected) if (device.IsConnected)
{ {
DeviceStatus = device.IsTestRunning ? "联机 / 测试中" : device.IsResetting ? "联机 / 复位中" : "联机 / 待机"; DeviceStatus = device.IsTestRunning ? "联机 / 测试中" : device.IsResetting ? "联机 / 复位中" : "联机 / 待机";
TestButtonText = device.IsTestRunning ? "停止" : "测试";
UpdateResetButtonText(device); UpdateResetButtonText(device);
VerticalPressure = device.VerticalLoadN.ToString("F1", CultureInfo.InvariantCulture); VerticalPressure = device.VerticalLoadN.ToString("F1", CultureInfo.InvariantCulture);
HorizontalForce = device.HorizontalFrictionN.ToString("F1", CultureInfo.InvariantCulture); HorizontalForce = device.HorizontalFrictionN.ToString("F1", CultureInfo.InvariantCulture);
@@ -619,7 +640,6 @@ namespace Footwear_Test_methodsfor_wholeshoe_Slipresistanceperformance.ViewModel
else else
{ {
DeviceStatus = IsAdcCalibrationError(device.LastError) ? "数据无效" : "离线"; DeviceStatus = IsAdcCalibrationError(device.LastError) ? "数据无效" : "离线";
TestButtonText = device.IsTestRunning ? "停止" : "测试";
UpdateResetButtonText(device); UpdateResetButtonText(device);
VerticalPressure = "--"; VerticalPressure = "--";
HorizontalForce = "--"; HorizontalForce = "--";
@@ -628,6 +648,8 @@ namespace Footwear_Test_methodsfor_wholeshoe_Slipresistanceperformance.ViewModel
ActualLoadText = "-- N"; ActualLoadText = "-- N";
} }
UpdateTestButtonState(device);
if (!device.IsConnected && !string.IsNullOrWhiteSpace(device.LastError)) if (!device.IsConnected && !string.IsNullOrWhiteSpace(device.LastError))
{ {
CurrentStatus = IsAdcCalibrationError(device.LastError) CurrentStatus = IsAdcCalibrationError(device.LastError)
@@ -661,6 +683,43 @@ namespace Footwear_Test_methodsfor_wholeshoe_Slipresistanceperformance.ViewModel
wasRunning = isRecording; 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() private void BeginResetButtonFeedback()
{ {
isResetButtonPending = true; isResetButtonPending = true;

View File

@@ -357,6 +357,7 @@
Command="{Binding ClearCommand}"/> Command="{Binding ClearCommand}"/>
<Button Content="{Binding TestButtonText}" <Button Content="{Binding TestButtonText}"
Classes="success side-action" Classes="success side-action"
IsEnabled="{Binding IsTestButtonEnabled}"
Command="{Binding StartTestCommand}"/> Command="{Binding StartTestCommand}"/>
<Button Content="停止" <Button Content="停止"
Classes="danger side-action" Classes="danger side-action"