This commit is contained in:
GukSang.Jin
2026-05-20 14:51:00 +08:00
parent 263fffbcf5
commit 0cba5198f2
7 changed files with 66 additions and 5 deletions

View File

@@ -149,6 +149,7 @@ namespace TabletTester2025.ViewModels
[ObservableProperty] private bool _friabilityClockwise = true;
[ObservableProperty] private bool _friabilityCounterClockwise;
[ObservableProperty] private double _friabilityCurrentRpm;
[ObservableProperty] private int _friabilityRealtimeRounds;
[ObservableProperty] private int _friabilityRemainingRounds = 100;
public IAsyncRelayCommand StopHardnessCommand { get; }
public IAsyncRelayCommand StopFriabilityCommand { get; }
@@ -1888,6 +1889,7 @@ namespace TabletTester2025.ViewModels
int totalRounds = Math.Max(1, FriabilityTargetRounds);
FriabilityRemainingRounds = totalRounds;
FriabilityCurrentRpm = rpm;
await RefreshFriabilityRealtimeRoundsAsync();
await PulseCoilAsync(startCoil);
int durationMs = (int)Math.Ceiling(testTimeMin * 60 * 1000); // 总运行时间(毫秒)
@@ -1904,6 +1906,8 @@ namespace TabletTester2025.ViewModels
// 更新界面绑定的剩余圈数
FriabilityRemainingRounds = remainingRounds;
if (i % 500 == 0)
await RefreshFriabilityRealtimeRoundsAsync();
// 等待100ms再更新下一次
await Task.Delay(100);
@@ -1914,6 +1918,7 @@ namespace TabletTester2025.ViewModels
double weightAfter = await ReadFriabilityWeightAsync(ResolveFriabilityWeightAfterRegister(), "脆碎后重量");
SetFriabilityWeightFromPlc(weightAfter: weightAfter);
FriabilityCurrentRpm = rpm;
await RefreshFriabilityRealtimeRoundsAsync();
bool localLossReady = TryCalculateFriabilityLossFromWeights(out double localLossPercent);
if (localLossReady)
@@ -1962,6 +1967,31 @@ namespace TabletTester2025.ViewModels
return value;
}
private ushort ResolveFriabilityRealtimeRoundsRegister()
{
return _plcConfig.FriabilityRealtimeRounds != 0
? _plcConfig.FriabilityRealtimeRounds
: (ushort)82;
}
private async Task RefreshFriabilityRealtimeRoundsAsync()
{
ushort registerAddress = ResolveFriabilityRealtimeRoundsRegister();
if (registerAddress == 0)
return;
try
{
int value = await _plc.ReadIntAsync(registerAddress);
if (value >= 0)
FriabilityRealtimeRounds = value;
}
catch
{
// Keep the last displayed realtime count if the PLC read fails once.
}
}
private async Task RunDisintegrationAsync()
{
if (_isDisintegrationRunning) return;