更新20260616
This commit is contained in:
@@ -693,8 +693,8 @@
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Text="实时转速" Style="{StaticResource MetricTitle}" HorizontalAlignment="Left" />
|
||||
<Button Grid.Column="1"
|
||||
Content="一键归零"
|
||||
Command="{Binding ZeroSpeedTorquePressureCommand}"
|
||||
Content="转速归零"
|
||||
Command="{Binding ZeroSpeedCommand}"
|
||||
FontSize="13"
|
||||
Padding="12,3"
|
||||
MinHeight="28"
|
||||
@@ -719,6 +719,14 @@
|
||||
<ColumnDefinition Width="Auto" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Text="实时扭矩" Style="{StaticResource MetricTitle}" HorizontalAlignment="Left" />
|
||||
<Button Grid.Column="1"
|
||||
Content="扭矩归零"
|
||||
Command="{Binding ZeroTorqueCommand}"
|
||||
FontSize="13"
|
||||
Padding="12,3"
|
||||
MinHeight="28"
|
||||
Background="#64748B"
|
||||
BorderBrush="#475569" />
|
||||
<TextBlock Grid.Row="1"
|
||||
Grid.ColumnSpan="2"
|
||||
x:Name="RealtimeTorqueText"
|
||||
@@ -740,6 +748,14 @@
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"
|
||||
Foreground="#52616F" />
|
||||
<Button Grid.Column="1"
|
||||
Content="压力归零"
|
||||
Command="{Binding ZeroPressureCommand}"
|
||||
FontSize="13"
|
||||
Padding="12,3"
|
||||
MinHeight="28"
|
||||
Background="#64748B"
|
||||
BorderBrush="#475569" />
|
||||
</Grid>
|
||||
</Border>
|
||||
</Grid>
|
||||
|
||||
@@ -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<string>();
|
||||
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<bool> BeginAxialManualMotionAsync(ushort coilAddress, string actionName)
|
||||
{
|
||||
if (!await WriteManualMotionCoilAsync(coilAddress, true, $"{actionName}按下"))
|
||||
|
||||
Reference in New Issue
Block a user