From 000957de3d5a0b149e17ca65d7a6b63604ed6bed Mon Sep 17 00:00:00 2001 From: "GukSang.Jin" Date: Wed, 10 Jun 2026 12:36:26 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B01222?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DentistryHandpieces/MainWindowViewModel.cs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/DentistryHandpieces/MainWindowViewModel.cs b/DentistryHandpieces/MainWindowViewModel.cs index b416ff5..0e55dcb 100644 --- a/DentistryHandpieces/MainWindowViewModel.cs +++ b/DentistryHandpieces/MainWindowViewModel.cs @@ -1989,6 +1989,7 @@ public sealed class MainWindowViewModel : ObservableObject await WriteChangedFloatAsync(SpeedCoefficientRegister, "转速系数", current.SpeedCoefficient, updated.SpeedCoefficient); await WriteChangedFloatAsync(SpeedStopThresholdRegister, "低速停止", current.SpeedStopThreshold, updated.SpeedStopThreshold); await WriteChangedFloatAsync(PressureCoefficientRegister, "压力系数", current.PressureCoefficient, updated.PressureCoefficient); + await WriteChangedTenthsAsync(HoldTorqueRegister, "保持扭矩设置", current.HoldTorque, updated.HoldTorque); return changedItems; @@ -2012,6 +2013,26 @@ public sealed class MainWindowViewModel : ObservableObject Log.Information("PLC参数写入并回读确认成功,参数 {FieldName},D{RegisterAddress}={Value}", fieldName, registerAddress, confirmedValue); } + async Task WriteChangedTenthsAsync(ushort registerAddress, string fieldName, double oldValue, double newValue) + { + ushort oldRaw = ScaleTenthsToPlc(oldValue, fieldName); + ushort newRaw = ScaleTenthsToPlc(newValue, fieldName); + if (oldRaw == newRaw) + { + return; + } + + await _plcRegisterService.WriteUInt16Async(plcConfig, registerAddress, newRaw); + ushort confirmedRawValue = await _plcRegisterService.ReadUInt16Async(plcConfig, registerAddress); + if (confirmedRawValue != newRaw) + { + throw new InvalidOperationException($"{fieldName} D{registerAddress} 写入后回读不一致。"); + } + + changedItems.Add(fieldName); + Log.Information("PLC参数写入并回读确认成功,参数 {FieldName},D{RegisterAddress}={Value}", fieldName, registerAddress, ScaleTenthsFromPlc(confirmedRawValue)); + } + } private bool TryReadParameterPageConfig(out TestParameterConfig config, out string error)