更新20260610
This commit is contained in:
@@ -22,12 +22,10 @@ public sealed class SpeedCoefficientSettingRow : ObservableObject
|
||||
|
||||
public sealed class HiddenSpeedSettingsViewModel : ObservableObject
|
||||
{
|
||||
private const ushort LoadSpeedSettingRegister = 414;
|
||||
private const ushort FirstSpeedCoefficientRegister = 1200;
|
||||
private const int SpeedCoefficientCount = 30;
|
||||
private readonly IPlcRegisterService _plcRegisterService;
|
||||
private readonly PlcConnectionConfig _plcConfig;
|
||||
private string _loadSpeedSettingInput = string.Empty;
|
||||
private string _statusText = "打开后将从 PLC 读取参数。";
|
||||
private bool _isBusy;
|
||||
|
||||
@@ -36,7 +34,6 @@ public sealed class HiddenSpeedSettingsViewModel : ObservableObject
|
||||
_plcRegisterService = plcRegisterService;
|
||||
_plcConfig = plcConfig;
|
||||
ReadCommand = new AsyncRelayCommand(ReadAsync);
|
||||
SaveLoadSpeedSettingCommand = new AsyncRelayCommand(SaveLoadSpeedSettingAsync);
|
||||
SaveSpeedCoefficientCommand = new AsyncRelayCommand<SpeedCoefficientSettingRow>(SaveSpeedCoefficientAsync);
|
||||
|
||||
for (int index = 0; index < SpeedCoefficientCount; index++)
|
||||
@@ -55,16 +52,8 @@ public sealed class HiddenSpeedSettingsViewModel : ObservableObject
|
||||
|
||||
public IAsyncRelayCommand ReadCommand { get; }
|
||||
|
||||
public IAsyncRelayCommand SaveLoadSpeedSettingCommand { get; }
|
||||
|
||||
public IAsyncRelayCommand<SpeedCoefficientSettingRow> SaveSpeedCoefficientCommand { get; }
|
||||
|
||||
public string LoadSpeedSettingInput
|
||||
{
|
||||
get => _loadSpeedSettingInput;
|
||||
set => SetProperty(ref _loadSpeedSettingInput, value);
|
||||
}
|
||||
|
||||
public string StatusText
|
||||
{
|
||||
get => _statusText;
|
||||
@@ -95,45 +84,6 @@ public sealed class HiddenSpeedSettingsViewModel : ObservableObject
|
||||
}
|
||||
}
|
||||
|
||||
private async Task SaveLoadSpeedSettingAsync()
|
||||
{
|
||||
if (_isBusy)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!TryParseFloat(LoadSpeedSettingInput, out float loadSpeedSetting))
|
||||
{
|
||||
StatusText = "负载转速设置必须是有效数字。";
|
||||
return;
|
||||
}
|
||||
|
||||
_isBusy = true;
|
||||
StatusText = "正在保存负载转速设置...";
|
||||
try
|
||||
{
|
||||
await _plcRegisterService.WriteFloatAsync(_plcConfig, LoadSpeedSettingRegister, loadSpeedSetting);
|
||||
float confirmedValue = await _plcRegisterService.ReadFloatAsync(_plcConfig, LoadSpeedSettingRegister);
|
||||
if (float.IsNaN(confirmedValue)
|
||||
|| float.IsInfinity(confirmedValue)
|
||||
|| !AreEquivalentFloatRegisterValues(loadSpeedSetting, confirmedValue))
|
||||
{
|
||||
throw new InvalidOperationException("PLC 写入后回读不一致。");
|
||||
}
|
||||
|
||||
LoadSpeedSettingInput = FormatNumber(confirmedValue);
|
||||
StatusText = "负载转速设置已保存并回读确认。";
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
StatusText = $"负载转速设置保存失败:{OperatorMessageFormatter.FromException(ex)}";
|
||||
}
|
||||
finally
|
||||
{
|
||||
_isBusy = false;
|
||||
}
|
||||
}
|
||||
|
||||
private async Task SaveSpeedCoefficientAsync(SpeedCoefficientSettingRow? row)
|
||||
{
|
||||
if (_isBusy || row is null)
|
||||
@@ -175,16 +125,9 @@ public sealed class HiddenSpeedSettingsViewModel : ObservableObject
|
||||
|
||||
private async Task ReadValuesAsync()
|
||||
{
|
||||
float loadSpeedSetting = await _plcRegisterService.ReadFloatAsync(_plcConfig, LoadSpeedSettingRegister);
|
||||
if (float.IsNaN(loadSpeedSetting) || float.IsInfinity(loadSpeedSetting))
|
||||
{
|
||||
throw new InvalidOperationException("负载转速设置读取无效。");
|
||||
}
|
||||
|
||||
ushort[] addresses = SpeedCoefficientSettings.Select(static row => row.Address).ToArray();
|
||||
IReadOnlyDictionary<ushort, float> values = await _plcRegisterService.ReadFloatValuesAsync(_plcConfig, addresses);
|
||||
|
||||
LoadSpeedSettingInput = FormatNumber(loadSpeedSetting);
|
||||
foreach (SpeedCoefficientSettingRow row in SpeedCoefficientSettings)
|
||||
{
|
||||
if (!values.TryGetValue(row.Address, out float value)
|
||||
|
||||
@@ -38,40 +38,11 @@
|
||||
|
||||
<Grid Margin="18">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="*" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<Border Background="White"
|
||||
BorderBrush="#C9D4DD"
|
||||
BorderThickness="1"
|
||||
CornerRadius="6"
|
||||
Padding="16">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="240" />
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="120" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Text="负载转速设置"
|
||||
FontSize="19"
|
||||
FontWeight="Bold"
|
||||
VerticalAlignment="Center"
|
||||
Foreground="#22313F" />
|
||||
<TextBox Grid.Column="1"
|
||||
Text="{Binding LoadSpeedSettingInput, UpdateSourceTrigger=PropertyChanged}"
|
||||
Style="{StaticResource HiddenDecimalInputTextBox}"
|
||||
local:NumericKeypad.Title="负载转速设置"
|
||||
Margin="12,0" />
|
||||
<Button Grid.Column="2"
|
||||
Content="保存"
|
||||
Command="{Binding SaveLoadSpeedSettingCommand}"
|
||||
Margin="0" />
|
||||
</Grid>
|
||||
</Border>
|
||||
|
||||
<DataGrid Grid.Row="1"
|
||||
<DataGrid
|
||||
ItemsSource="{Binding SpeedCoefficientSettings}"
|
||||
Margin="0,14"
|
||||
AutoGenerateColumns="False"
|
||||
@@ -112,7 +83,7 @@
|
||||
</DataGrid.Columns>
|
||||
</DataGrid>
|
||||
|
||||
<Border Grid.Row="2"
|
||||
<Border Grid.Row="1"
|
||||
Background="White"
|
||||
BorderBrush="#C9D4DD"
|
||||
BorderThickness="1"
|
||||
|
||||
@@ -777,6 +777,7 @@
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
@@ -820,6 +821,27 @@
|
||||
VerticalAlignment="Center"
|
||||
Margin="8,0,0,0" />
|
||||
</Grid>
|
||||
<Grid Grid.Row="2" Margin="0,12,0,0">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="80" />
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="58" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Text="负载转速"
|
||||
Style="{StaticResource FormLabel}"
|
||||
VerticalAlignment="Center"
|
||||
Margin="0,0,12,0" />
|
||||
<TextBox Grid.Column="1"
|
||||
x:Name="LoadSpeedSettingInput"
|
||||
Text="{Binding LoadSpeedSettingInput, UpdateSourceTrigger=PropertyChanged, Delay=600}"
|
||||
Style="{StaticResource DecimalInputTextBox}"
|
||||
local:NumericKeypad.Title="负载转速设置" />
|
||||
<TextBlock Grid.Column="2"
|
||||
Text="r/min"
|
||||
Style="{StaticResource MutedText}"
|
||||
VerticalAlignment="Center"
|
||||
Margin="8,0,0,0" />
|
||||
</Grid>
|
||||
</Grid>
|
||||
|
||||
</Grid>
|
||||
|
||||
@@ -30,6 +30,7 @@ internal enum TestPageInputParameter
|
||||
AxialForceHoldTime,
|
||||
HoldTorque,
|
||||
TorqueHoldTime,
|
||||
LoadSpeedSetting,
|
||||
NoLoadSpeedSetting
|
||||
}
|
||||
|
||||
@@ -84,6 +85,7 @@ public sealed class MainWindowViewModel : ObservableObject
|
||||
private const ushort AxialForceHoldTimeRegister = 406;
|
||||
private const ushort HoldTorqueRegister = 410;
|
||||
private const ushort TorqueHoldTimeRegister = 412;
|
||||
private const ushort LoadSpeedSettingRegister = 414;
|
||||
private const ushort NoLoadSpeedSettingRegister = 420;
|
||||
private const ushort AxialForceDisplayRegister = 1130;
|
||||
private const ushort AxialForceCoefficientRegister = 1128;
|
||||
@@ -140,6 +142,7 @@ public sealed class MainWindowViewModel : ObservableObject
|
||||
SpeedCoefficientRegister,
|
||||
SpeedStopThresholdRegister,
|
||||
PressureCoefficientRegister,
|
||||
LoadSpeedSettingRegister,
|
||||
NoLoadSpeedSettingRegister
|
||||
];
|
||||
|
||||
@@ -232,6 +235,7 @@ public sealed class MainWindowViewModel : ObservableObject
|
||||
private string _realtimePressureText = "0.000 MPa";
|
||||
private string _noLoadSpeedRecordText = "0 r/min";
|
||||
private string _noLoadSpeedErrorRateText = "0.00 %";
|
||||
private string _loadSpeedSettingInput = "0";
|
||||
private string _noLoadSpeedSettingInput = "0";
|
||||
private string _finalSpeedTorqueText = "最终:-- / --";
|
||||
private string _speedTorqueAxisPositionText = "0.000 mm";
|
||||
@@ -486,6 +490,20 @@ public sealed class MainWindowViewModel : ObservableObject
|
||||
|
||||
public string PressureCoefficientInput { get; set; } = "1";
|
||||
|
||||
public string LoadSpeedSettingInput
|
||||
{
|
||||
get => _loadSpeedSettingInput;
|
||||
set
|
||||
{
|
||||
if (!SetProperty(ref _loadSpeedSettingInput, value) || _isApplyingParameterConfigToInputs)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
QueueFloatTestPageInputWrite(TestPageInputParameter.LoadSpeedSetting, LoadSpeedSettingRegister, "负载转速设置", value);
|
||||
}
|
||||
}
|
||||
|
||||
public string NoLoadSpeedSettingInput
|
||||
{
|
||||
get => _noLoadSpeedSettingInput;
|
||||
@@ -842,6 +860,7 @@ public sealed class MainWindowViewModel : ObservableObject
|
||||
double speedCoefficient = ReadFloatValue(values, SpeedCoefficientRegister, "转速系数");
|
||||
double speedStopThreshold = ReadFloatValue(values, SpeedStopThresholdRegister, "低速停止设置");
|
||||
double pressureCoefficient = ReadFloatValue(values, PressureCoefficientRegister, "压力系数");
|
||||
double loadSpeedSetting = ReadFloatValue(values, LoadSpeedSettingRegister, "负载转速设置");
|
||||
double noLoadSpeedSetting = ReadFloatValue(values, NoLoadSpeedSettingRegister, "空载转速设置");
|
||||
|
||||
_parameterConfig = new TestParameterConfig
|
||||
@@ -867,6 +886,7 @@ public sealed class MainWindowViewModel : ObservableObject
|
||||
SpeedCoefficient = speedCoefficient,
|
||||
SpeedStopThreshold = speedStopThreshold,
|
||||
PressureCoefficient = pressureCoefficient,
|
||||
LoadSpeedSetting = loadSpeedSetting,
|
||||
NoLoadSpeedSetting = noLoadSpeedSetting,
|
||||
PlcIpAddress = _parameterConfig.PlcIpAddress,
|
||||
PlcPort = _parameterConfig.PlcPort,
|
||||
@@ -988,6 +1008,7 @@ public sealed class MainWindowViewModel : ObservableObject
|
||||
SpeedCoefficient = _parameterConfig.SpeedCoefficient,
|
||||
SpeedStopThreshold = _parameterConfig.SpeedStopThreshold,
|
||||
PressureCoefficient = _parameterConfig.PressureCoefficient,
|
||||
LoadSpeedSetting = _parameterConfig.LoadSpeedSetting,
|
||||
NoLoadSpeedSetting = _parameterConfig.NoLoadSpeedSetting,
|
||||
PlcIpAddress = _parameterConfig.PlcIpAddress,
|
||||
PlcPort = _parameterConfig.PlcPort,
|
||||
@@ -1024,6 +1045,7 @@ public sealed class MainWindowViewModel : ObservableObject
|
||||
SpeedCoefficient = config.SpeedCoefficient,
|
||||
SpeedStopThreshold = config.SpeedStopThreshold,
|
||||
PressureCoefficient = config.PressureCoefficient,
|
||||
LoadSpeedSetting = parameter == TestPageInputParameter.LoadSpeedSetting ? value : config.LoadSpeedSetting,
|
||||
NoLoadSpeedSetting = parameter == TestPageInputParameter.NoLoadSpeedSetting ? value : config.NoLoadSpeedSetting,
|
||||
PlcIpAddress = config.PlcIpAddress,
|
||||
PlcPort = config.PlcPort,
|
||||
@@ -1059,6 +1081,7 @@ public sealed class MainWindowViewModel : ObservableObject
|
||||
SpeedCoefficientInput = FormatConfigNumber(_parameterConfig.SpeedCoefficient);
|
||||
SpeedStopThresholdInput = FormatConfigNumber(_parameterConfig.SpeedStopThreshold);
|
||||
PressureCoefficientInput = FormatConfigNumber(_parameterConfig.PressureCoefficient);
|
||||
LoadSpeedSettingInput = FormatConfigNumber(_parameterConfig.LoadSpeedSetting);
|
||||
NoLoadSpeedSettingInput = FormatConfigNumber(_parameterConfig.NoLoadSpeedSetting);
|
||||
PlcIpAddressInput = string.IsNullOrWhiteSpace(_parameterConfig.PlcIpAddress) ? "192.168.1.10" : _parameterConfig.PlcIpAddress;
|
||||
PlcPortInput = _parameterConfig.PlcPort > 0 ? _parameterConfig.PlcPort.ToString(CultureInfo.InvariantCulture) : "502";
|
||||
@@ -1096,6 +1119,7 @@ public sealed class MainWindowViewModel : ObservableObject
|
||||
OnPropertyChanged(nameof(SpeedCoefficientInput));
|
||||
OnPropertyChanged(nameof(SpeedStopThresholdInput));
|
||||
OnPropertyChanged(nameof(PressureCoefficientInput));
|
||||
OnPropertyChanged(nameof(LoadSpeedSettingInput));
|
||||
OnPropertyChanged(nameof(PlcIpAddressInput));
|
||||
OnPropertyChanged(nameof(PlcPortInput));
|
||||
OnPropertyChanged(nameof(PlcUnitIdInput));
|
||||
@@ -1142,7 +1166,7 @@ public sealed class MainWindowViewModel : ObservableObject
|
||||
AxialConfigSummaryText =
|
||||
$"2号轴:位移极限 {FormatDisplacement(_parameterConfig.AxialDisplacementLimit)} mm;速度 {FormatSpeedSetting(_parameterConfig.AxialSpeed)} mm/min;手动位移 {FormatDisplacement(_parameterConfig.AxialManualDisplacement)} mm;{GetActiveAxialForceSetpointName()} {FormatForce(GetActiveAxialForceSetpoint())} N";
|
||||
SpeedTorqueConfigSummaryText =
|
||||
$"1号轴:位移极限 {FormatDisplacement(_parameterConfig.SpeedTorqueDisplacementLimit)} mm;速度 {FormatSpeedSetting(_parameterConfig.SpeedTorqueSpeed)} mm/min;手动位移 {FormatDisplacement(_parameterConfig.SpeedTorqueManualDisplacement)} mm;低速停止 {FormatSpeed(_parameterConfig.SpeedStopThreshold)} r/min";
|
||||
$"1号轴:位移极限 {FormatDisplacement(_parameterConfig.SpeedTorqueDisplacementLimit)} mm;速度 {FormatSpeedSetting(_parameterConfig.SpeedTorqueSpeed)} mm/min;手动位移 {FormatDisplacement(_parameterConfig.SpeedTorqueManualDisplacement)} mm;低速停止 {FormatSpeed(_parameterConfig.SpeedStopThreshold)} r/min;负载转速 {FormatSpeedSetting(_parameterConfig.LoadSpeedSetting)} r/min";
|
||||
}
|
||||
|
||||
private void Export()
|
||||
@@ -1591,6 +1615,7 @@ public sealed class MainWindowViewModel : ObservableObject
|
||||
("转速/扭矩", "转速系数", p.SpeedCoefficient, string.Empty),
|
||||
("转速/扭矩", "低速停止", p.SpeedStopThreshold, "r/min"),
|
||||
("转速/扭矩", "压力系数", p.PressureCoefficient, string.Empty),
|
||||
("转速/扭矩", "负载转速设置", p.LoadSpeedSetting, "r/min"),
|
||||
("空载转速", "空载转速设置", p.NoLoadSpeedSetting, "r/min"),
|
||||
("通信", "PLC IP", p.PlcIpAddress, string.Empty),
|
||||
("通信", "PLC端口", p.PlcPort, string.Empty),
|
||||
@@ -2037,6 +2062,7 @@ public sealed class MainWindowViewModel : ObservableObject
|
||||
SpeedCoefficient = speedCoefficient,
|
||||
SpeedStopThreshold = speedStopThreshold,
|
||||
PressureCoefficient = pressureCoefficient,
|
||||
LoadSpeedSetting = _parameterConfig.LoadSpeedSetting,
|
||||
NoLoadSpeedSetting = _parameterConfig.NoLoadSpeedSetting,
|
||||
PlcIpAddress = plcIpAddress,
|
||||
PlcPort = plcPort,
|
||||
@@ -2287,6 +2313,7 @@ public sealed class MainWindowViewModel : ObservableObject
|
||||
TestPageInputParameter.AxialForceHoldTime => AxialForceHoldTimeInput,
|
||||
TestPageInputParameter.HoldTorque => HoldTorqueInput,
|
||||
TestPageInputParameter.TorqueHoldTime => TorqueHoldTimeInput,
|
||||
TestPageInputParameter.LoadSpeedSetting => LoadSpeedSettingInput,
|
||||
TestPageInputParameter.NoLoadSpeedSetting => NoLoadSpeedSettingInput,
|
||||
_ => null
|
||||
};
|
||||
@@ -2317,6 +2344,9 @@ public sealed class MainWindowViewModel : ObservableObject
|
||||
case TestPageInputParameter.TorqueHoldTime:
|
||||
TorqueHoldTimeInput = confirmedText;
|
||||
break;
|
||||
case TestPageInputParameter.LoadSpeedSetting:
|
||||
LoadSpeedSettingInput = confirmedText;
|
||||
break;
|
||||
case TestPageInputParameter.NoLoadSpeedSetting:
|
||||
NoLoadSpeedSettingInput = confirmedText;
|
||||
break;
|
||||
@@ -3595,6 +3625,7 @@ public sealed class MainWindowViewModel : ObservableObject
|
||||
SpeedCoefficient = config.SpeedCoefficient,
|
||||
SpeedStopThreshold = config.SpeedStopThreshold,
|
||||
PressureCoefficient = config.PressureCoefficient,
|
||||
LoadSpeedSetting = config.LoadSpeedSetting,
|
||||
NoLoadSpeedSetting = config.NoLoadSpeedSetting,
|
||||
PlcIpAddress = config.PlcIpAddress,
|
||||
PlcPort = config.PlcPort,
|
||||
|
||||
@@ -345,6 +345,8 @@ public sealed class TestParameterConfig
|
||||
|
||||
public double PressureCoefficient { get; init; }
|
||||
|
||||
public double LoadSpeedSetting { get; init; }
|
||||
|
||||
public double NoLoadSpeedSetting { get; init; }
|
||||
|
||||
public string PlcIpAddress { get; init; } = "192.168.1.10";
|
||||
@@ -397,6 +399,7 @@ public sealed class TestParameterConfig
|
||||
SpeedCoefficient = 1,
|
||||
SpeedStopThreshold = 0,
|
||||
PressureCoefficient = 1,
|
||||
LoadSpeedSetting = 0,
|
||||
NoLoadSpeedSetting = 0,
|
||||
PlcIpAddress = "192.168.1.10",
|
||||
PlcPort = 502,
|
||||
|
||||
Reference in New Issue
Block a user