diff --git a/DentistryHandpieces/MainWindow.xaml b/DentistryHandpieces/MainWindow.xaml
index fdf9fd2..1850089 100644
--- a/DentistryHandpieces/MainWindow.xaml
+++ b/DentistryHandpieces/MainWindow.xaml
@@ -693,8 +693,8 @@
+
+
diff --git a/DentistryHandpieces/MainWindowViewModel.cs b/DentistryHandpieces/MainWindowViewModel.cs
index 3266e62..b256f42 100644
--- a/DentistryHandpieces/MainWindowViewModel.cs
+++ b/DentistryHandpieces/MainWindowViewModel.cs
@@ -297,9 +297,9 @@ public sealed class MainWindowViewModel : ObservableObject
ResetSpeedTorqueCommand = new AsyncRelayCommand(ResetSpeedTorqueAsync);
ToggleVentValveCommand = new AsyncRelayCommand(ToggleVentValveAsync);
ZeroAxialForceCommand = new AsyncRelayCommand(ZeroAxialForceAsync);
- ZeroSpeedTorquePressureCommand = new AsyncRelayCommand(
- ZeroSpeedTorquePressureAsync,
- CanZeroSpeedTorquePressure);
+ ZeroSpeedCommand = new AsyncRelayCommand(ZeroSpeedAsync, CanExecuteSpeedTorqueZeroing);
+ ZeroTorqueCommand = new AsyncRelayCommand(ZeroTorqueAsync, CanExecuteSpeedTorqueZeroing);
+ ZeroPressureCommand = new AsyncRelayCommand(ZeroPressureAsync, CanExecuteSpeedTorqueZeroing);
SaveNoLoadSpeedSettingCommand = new AsyncRelayCommand(SaveNoLoadSpeedSettingAsync);
RecordNoLoadSpeedCommand = new AsyncRelayCommand(RecordNoLoadSpeedAsync);
@@ -365,7 +365,11 @@ public sealed class MainWindowViewModel : ObservableObject
public IAsyncRelayCommand ZeroAxialForceCommand { get; }
- public IAsyncRelayCommand ZeroSpeedTorquePressureCommand { get; }
+ public IAsyncRelayCommand ZeroSpeedCommand { get; }
+
+ public IAsyncRelayCommand ZeroTorqueCommand { get; }
+
+ public IAsyncRelayCommand ZeroPressureCommand { get; }
public IAsyncRelayCommand SaveNoLoadSpeedSettingCommand { get; }
@@ -714,7 +718,7 @@ public sealed class MainWindowViewModel : ObservableObject
{
if (SetProperty(ref _speedTorqueTestButtonText, value))
{
- ZeroSpeedTorquePressureCommand?.NotifyCanExecuteChanged();
+ NotifySpeedTorqueZeroCommandsCanExecuteChanged();
}
}
}
@@ -2516,7 +2520,7 @@ public sealed class MainWindowViewModel : ObservableObject
{
if (_isSpeedTorqueZeroing)
{
- StatusText = "一键归零正在执行,已阻止启动测试。";
+ StatusText = "归零正在执行,已阻止启动测试。";
return;
}
@@ -2660,12 +2664,12 @@ public sealed class MainWindowViewModel : ObservableObject
{
if (_isSpeedTorqueZeroing)
{
- StatusText = "一键归零正在执行,已阻止复位。";
+ StatusText = "归零正在执行,已阻止复位。";
return;
}
_isSpeedTorqueResetting = true;
- ZeroSpeedTorquePressureCommand.NotifyCanExecuteChanged();
+ NotifySpeedTorqueZeroCommandsCanExecuteChanged();
SpeedTorqueResetButtonText = "复位中";
UpdateSpeedTorqueDisplay();
@@ -2709,7 +2713,7 @@ public sealed class MainWindowViewModel : ObservableObject
finally
{
_isSpeedTorqueResetting = false;
- ZeroSpeedTorquePressureCommand.NotifyCanExecuteChanged();
+ NotifySpeedTorqueZeroCommandsCanExecuteChanged();
SpeedTorqueResetButtonText = "复位";
}
}
@@ -2964,7 +2968,7 @@ public sealed class MainWindowViewModel : ObservableObject
StatusText = "轴向力归零完成。";
}
- private bool CanZeroSpeedTorquePressure()
+ private bool CanExecuteSpeedTorqueZeroing()
{
return !_isSpeedTorqueRunning
&& !_isSpeedTorqueResetting
@@ -2972,61 +2976,83 @@ public sealed class MainWindowViewModel : ObservableObject
&& SpeedTorqueTestButtonText == "测试";
}
- private async Task ZeroSpeedTorquePressureAsync()
+ private Task ZeroSpeedAsync()
{
- if (!CanZeroSpeedTorquePressure())
+ return ExecuteSpeedTorqueZeroingAsync(
+ "转速归零",
+ (SpeedZeroCoil, "转速归零"));
+ }
+
+ private Task ZeroTorqueAsync()
+ {
+ return ExecuteSpeedTorqueZeroingAsync(
+ "扭矩归零",
+ (TorqueZeroCoil, "扭矩归零第一路"),
+ (SecondaryTorqueZeroCoil, "扭矩归零第二路"));
+ }
+
+ private Task ZeroPressureAsync()
+ {
+ return ExecuteSpeedTorqueZeroingAsync(
+ "压力归零",
+ (PressureZeroCoil, "压力归零"));
+ }
+
+ private async Task ExecuteSpeedTorqueZeroingAsync(
+ string zeroingName,
+ params (ushort CoilAddress, string ActionName)[] actions)
+ {
+ if (!CanExecuteSpeedTorqueZeroing())
{
- StatusText = "转速/扭矩测试启动、运行或复位期间禁止一键归零。";
+ StatusText = $"转速/扭矩测试启动、运行或复位期间禁止{zeroingName}。";
Log.Warning(
- "一键归零已阻止:测试按钮状态 {ButtonState},运行中 {IsRunning},复位中 {IsResetting}",
+ "{ZeroingName}已阻止:测试按钮状态 {ButtonState},运行中 {IsRunning},复位中 {IsResetting},其他归零执行中 {IsZeroing}",
+ zeroingName,
SpeedTorqueTestButtonText,
_isSpeedTorqueRunning,
- _isSpeedTorqueResetting);
+ _isSpeedTorqueResetting,
+ _isSpeedTorqueZeroing);
return;
}
_isSpeedTorqueZeroing = true;
- ZeroSpeedTorquePressureCommand.NotifyCanExecuteChanged();
+ NotifySpeedTorqueZeroCommandsCanExecuteChanged();
try
{
- (ushort CoilAddress, string ActionName)[] actions =
- [
- (TorqueZeroCoil, "扭矩归零 M1101"),
- (SpeedZeroCoil, "转速归零 M1300"),
- (PressureZeroCoil, "压力归零 M1301"),
- (SecondaryTorqueZeroCoil, "第二路扭矩归零 M1302")
- ];
- var completedActions = new List();
foreach ((ushort coilAddress, string actionName) in actions)
{
if (!await PulsePlcAsync(coilAddress, actionName))
{
- StatusText = completedActions.Count == 0
- ? $"一键归零失败:{actionName}未完成。"
- : $"一键归零部分完成:已完成{string.Join("、", completedActions)};{actionName}失败,后续动作已停止。";
+ StatusText = $"{zeroingName}失败,请检查设备状态。";
Log.Error(
- "一键归零失败并停止后续动作:已完成 {CompletedActions},失败点位 M{CoilAddress},动作 {ActionName}",
- completedActions.Count == 0 ? "无" : string.Join(", ", completedActions),
+ "{ZeroingName}失败并停止后续动作,失败点位 M{CoilAddress},动作 {ActionName}",
+ zeroingName,
coilAddress,
actionName);
return;
}
-
- completedActions.Add(actionName);
}
- StatusText = "转速、扭矩、压力归零完成。";
+ StatusText = $"{zeroingName}完成。";
Log.Information(
- "一键归零完成,执行顺序 {ZeroingActions}",
+ "{ZeroingName}完成,执行顺序 {ZeroingActions}",
+ zeroingName,
string.Join(", ", actions.Select(static action => $"M{action.CoilAddress}")));
}
finally
{
_isSpeedTorqueZeroing = false;
- ZeroSpeedTorquePressureCommand.NotifyCanExecuteChanged();
+ NotifySpeedTorqueZeroCommandsCanExecuteChanged();
}
}
+ private void NotifySpeedTorqueZeroCommandsCanExecuteChanged()
+ {
+ ZeroSpeedCommand?.NotifyCanExecuteChanged();
+ ZeroTorqueCommand?.NotifyCanExecuteChanged();
+ ZeroPressureCommand?.NotifyCanExecuteChanged();
+ }
+
private async Task BeginAxialManualMotionAsync(ushort coilAddress, string actionName)
{
if (!await WriteManualMotionCoilAsync(coilAddress, true, $"{actionName}按下"))