更新20260613

This commit is contained in:
GukSang.Jin
2026-06-13 10:34:12 +08:00
parent ca18602bca
commit d97616fc92
2 changed files with 80 additions and 47 deletions

View File

@@ -703,10 +703,10 @@
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<TextBlock Text="实时转速" Style="{StaticResource MetricTitle}" HorizontalAlignment="Left" /> <TextBlock Text="实时转速" Style="{StaticResource MetricTitle}" HorizontalAlignment="Left" />
<Button Grid.Column="1" <Button Grid.Column="1"
Content="转速归零" Content="一键归零"
Command="{Binding ZeroSpeedCommand}" Command="{Binding ZeroSpeedTorquePressureCommand}"
FontSize="13" FontSize="13"
Padding="8,3" Padding="12,3"
MinHeight="28" MinHeight="28"
Background="#64748B" Background="#64748B"
BorderBrush="#475569" /> BorderBrush="#475569" />
@@ -729,14 +729,6 @@
<ColumnDefinition Width="Auto" /> <ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<TextBlock Text="实时扭矩" Style="{StaticResource MetricTitle}" HorizontalAlignment="Left" /> <TextBlock Text="实时扭矩" Style="{StaticResource MetricTitle}" HorizontalAlignment="Left" />
<Button Grid.Column="1"
Content="扭矩归零"
Command="{Binding ZeroTorqueCommand}"
FontSize="13"
Padding="8,3"
MinHeight="28"
Background="#64748B"
BorderBrush="#475569" />
<TextBlock Grid.Row="1" <TextBlock Grid.Row="1"
Grid.ColumnSpan="2" Grid.ColumnSpan="2"
x:Name="RealtimeTorqueText" x:Name="RealtimeTorqueText"
@@ -758,15 +750,6 @@
HorizontalAlignment="Center" HorizontalAlignment="Center"
VerticalAlignment="Center" VerticalAlignment="Center"
Foreground="#52616F" /> Foreground="#52616F" />
<Button Grid.Column="1"
Content="压力归零"
Command="{Binding ZeroPressureCommand}"
FontSize="13"
Padding="8,3"
MinHeight="28"
Background="#64748B"
BorderBrush="#475569"
Margin="8,0,0,0" />
</Grid> </Grid>
</Border> </Border>
</Grid> </Grid>

View File

@@ -228,6 +228,7 @@ public sealed class MainWindowViewModel : ObservableObject
private bool _isApplyingParameterConfigToInputs; private bool _isApplyingParameterConfigToInputs;
private bool _isDisplacementResetting; private bool _isDisplacementResetting;
private bool _isSpeedTorqueResetting; private bool _isSpeedTorqueResetting;
private bool _isSpeedTorqueZeroing;
private bool _hasShownSpeedTorqueEndWarnings; private bool _hasShownSpeedTorqueEndWarnings;
private DateTime _lastParameterReadFailureLogAt = DateTime.MinValue; private DateTime _lastParameterReadFailureLogAt = DateTime.MinValue;
private string _dialIndicatorText = "0.000 mm"; private string _dialIndicatorText = "0.000 mm";
@@ -296,9 +297,9 @@ public sealed class MainWindowViewModel : ObservableObject
ResetSpeedTorqueCommand = new AsyncRelayCommand(ResetSpeedTorqueAsync); ResetSpeedTorqueCommand = new AsyncRelayCommand(ResetSpeedTorqueAsync);
ToggleVentValveCommand = new AsyncRelayCommand(ToggleVentValveAsync); ToggleVentValveCommand = new AsyncRelayCommand(ToggleVentValveAsync);
ZeroAxialForceCommand = new AsyncRelayCommand(ZeroAxialForceAsync); ZeroAxialForceCommand = new AsyncRelayCommand(ZeroAxialForceAsync);
ZeroTorqueCommand = new AsyncRelayCommand(ZeroTorqueAsync); ZeroSpeedTorquePressureCommand = new AsyncRelayCommand(
ZeroSpeedCommand = new AsyncRelayCommand(ZeroSpeedAsync); ZeroSpeedTorquePressureAsync,
ZeroPressureCommand = new AsyncRelayCommand(ZeroPressureAsync); CanZeroSpeedTorquePressure);
SaveNoLoadSpeedSettingCommand = new AsyncRelayCommand(SaveNoLoadSpeedSettingAsync); SaveNoLoadSpeedSettingCommand = new AsyncRelayCommand(SaveNoLoadSpeedSettingAsync);
RecordNoLoadSpeedCommand = new AsyncRelayCommand(RecordNoLoadSpeedAsync); RecordNoLoadSpeedCommand = new AsyncRelayCommand(RecordNoLoadSpeedAsync);
@@ -364,11 +365,7 @@ public sealed class MainWindowViewModel : ObservableObject
public IAsyncRelayCommand ZeroAxialForceCommand { get; } public IAsyncRelayCommand ZeroAxialForceCommand { get; }
public IAsyncRelayCommand ZeroTorqueCommand { get; } public IAsyncRelayCommand ZeroSpeedTorquePressureCommand { get; }
public IAsyncRelayCommand ZeroSpeedCommand { get; }
public IAsyncRelayCommand ZeroPressureCommand { get; }
public IAsyncRelayCommand SaveNoLoadSpeedSettingCommand { get; } public IAsyncRelayCommand SaveNoLoadSpeedSettingCommand { get; }
@@ -713,7 +710,13 @@ public sealed class MainWindowViewModel : ObservableObject
public string SpeedTorqueTestButtonText public string SpeedTorqueTestButtonText
{ {
get => _speedTorqueTestButtonText; get => _speedTorqueTestButtonText;
private set => SetProperty(ref _speedTorqueTestButtonText, value); private set
{
if (SetProperty(ref _speedTorqueTestButtonText, value))
{
ZeroSpeedTorquePressureCommand?.NotifyCanExecuteChanged();
}
}
} }
public string NoLoadSpeedTestButtonText public string NoLoadSpeedTestButtonText
@@ -2511,6 +2514,12 @@ public sealed class MainWindowViewModel : ObservableObject
private async Task StartSpeedTorqueAsync() private async Task StartSpeedTorqueAsync()
{ {
if (_isSpeedTorqueZeroing)
{
StatusText = "一键归零正在执行,已阻止启动测试。";
return;
}
if (_isSpeedTorqueRunning) if (_isSpeedTorqueRunning)
{ {
UpdateSpeedTorqueDisplay(); UpdateSpeedTorqueDisplay();
@@ -2649,7 +2658,14 @@ public sealed class MainWindowViewModel : ObservableObject
private async Task ResetSpeedTorqueAsync() private async Task ResetSpeedTorqueAsync()
{ {
if (_isSpeedTorqueZeroing)
{
StatusText = "一键归零正在执行,已阻止复位。";
return;
}
_isSpeedTorqueResetting = true; _isSpeedTorqueResetting = true;
ZeroSpeedTorquePressureCommand.NotifyCanExecuteChanged();
SpeedTorqueResetButtonText = "复位中"; SpeedTorqueResetButtonText = "复位中";
UpdateSpeedTorqueDisplay(); UpdateSpeedTorqueDisplay();
@@ -2693,6 +2709,7 @@ public sealed class MainWindowViewModel : ObservableObject
finally finally
{ {
_isSpeedTorqueResetting = false; _isSpeedTorqueResetting = false;
ZeroSpeedTorquePressureCommand.NotifyCanExecuteChanged();
SpeedTorqueResetButtonText = "复位"; SpeedTorqueResetButtonText = "复位";
} }
} }
@@ -2947,34 +2964,67 @@ public sealed class MainWindowViewModel : ObservableObject
StatusText = "轴向力归零完成。"; StatusText = "轴向力归零完成。";
} }
private async Task ZeroTorqueAsync() private bool CanZeroSpeedTorquePressure()
{ {
if (!await PulsePlcAsync(TorqueZeroCoil, "扭矩归零 M1101")) return !_isSpeedTorqueRunning
{ && !_isSpeedTorqueResetting
return; && !_isSpeedTorqueZeroing
} && SpeedTorqueTestButtonText == "测试";
StatusText = "扭矩归零完成。";
} }
private async Task ZeroSpeedAsync() private async Task ZeroSpeedTorquePressureAsync()
{ {
if (!await PulsePlcAsync(SpeedZeroCoil, "转速归零 M1300")) if (!CanZeroSpeedTorquePressure())
{ {
StatusText = "转速/扭矩测试启动、运行或复位期间禁止一键归零。";
Log.Warning(
"一键归零已阻止:测试按钮状态 {ButtonState},运行中 {IsRunning},复位中 {IsResetting}",
SpeedTorqueTestButtonText,
_isSpeedTorqueRunning,
_isSpeedTorqueResetting);
return; return;
} }
StatusText = "转速归零完成。"; _isSpeedTorqueZeroing = true;
} ZeroSpeedTorquePressureCommand.NotifyCanExecuteChanged();
try
private async Task ZeroPressureAsync()
{
if (!await PulsePlcAsync(PressureZeroCoil, "压力归零 M1301"))
{ {
return; (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}失败,后续动作已停止。";
Log.Error(
"一键归零失败并停止后续动作:已完成 {CompletedActions},失败点位 M{CoilAddress},动作 {ActionName}",
completedActions.Count == 0 ? "无" : string.Join(", ", completedActions),
coilAddress,
actionName);
return;
}
StatusText = "压力归零完成。"; completedActions.Add(actionName);
}
StatusText = "转速、扭矩、压力归零完成。";
Log.Information(
"一键归零完成,执行顺序 {ZeroingActions}",
string.Join(", ", actions.Select(static action => $"M{action.CoilAddress}")));
}
finally
{
_isSpeedTorqueZeroing = false;
ZeroSpeedTorquePressureCommand.NotifyCanExecuteChanged();
}
} }
private async Task<bool> BeginAxialManualMotionAsync(ushort coilAddress, string actionName) private async Task<bool> BeginAxialManualMotionAsync(ushort coilAddress, string actionName)