diff --git a/Services/PlcSimulator.cs b/Services/PlcSimulator.cs index 7d4360c..f7afd87 100644 --- a/Services/PlcSimulator.cs +++ b/Services/PlcSimulator.cs @@ -19,6 +19,7 @@ namespace TabletTester2025.Services { 72 => 40 + (float)_rand.NextDouble() * 20, // 硬度最大采集力 100 => 40 + (float)_rand.NextDouble() * 20, // 硬度 40~60N + 1314 => 40 + (float)_rand.NextDouble() * 20, // 硬度实时力显示 82 => _rand.Next(0, 101), // 脆碎实时圈数 410 => 100f, // 脆碎圈数 412 => 5.0f + (float)_rand.NextDouble() * 2, // 脆碎度前重 diff --git a/ViewModels/StationViewModel.cs b/ViewModels/StationViewModel.cs index ef25fc5..a2e7e11 100644 --- a/ViewModels/StationViewModel.cs +++ b/ViewModels/StationViewModel.cs @@ -1529,7 +1529,7 @@ namespace TabletTester2025.ViewModels _hardnessGlobalTimer = new DispatcherTimer { Interval = TimeSpan.FromMilliseconds(500) }; _hardnessGlobalTimer.Tick += async (_, _) => { - if (_isReadingHardnessLiveForce || _isHardnessRunning) + if (_isReadingHardnessLiveForce) return; try @@ -1621,9 +1621,9 @@ namespace TabletTester2025.ViewModels if (completeWasActiveBeforeStart) await WaitForCoilStateAsync(completeCoil, false, TimeSpan.FromSeconds(10), "硬度完成信号未复位"); - double value = await WaitForHardnessSamplePeakAsync(completeCoil); + await WaitForHardnessSampleCompleteAsync(completeCoil); + double value = await ReadHardnessMaxCaptureAsync(); AddHardnessSample(value); - await ReadHardnessMaxCaptureAsync(); ApplyHardnessStatistics(count); await TryWaitForCoilStateAsync(completeCoil, false, TimeSpan.FromSeconds(2)); } @@ -1631,7 +1631,6 @@ namespace TabletTester2025.ViewModels if (_hardnessResults.Count < count) throw new InvalidOperationException("硬度测试已停止,未保存结果"); - await ReadHardnessMaxCaptureAsync(); ApplyHardnessStatistics(count); AddHardnessGroupSummaryRow(); resultReady = true; @@ -1712,28 +1711,14 @@ namespace TabletTester2025.ViewModels HardnessSudu = value; } - private async Task WaitForHardnessSamplePeakAsync(ushort completeCoil) + private async Task WaitForHardnessSampleCompleteAsync(ushort completeCoil) { - double peak = 0; DateTime deadline = DateTime.Now.AddSeconds(120); while (_isHardnessRunning && DateTime.Now <= deadline) { - double liveForce = await ReadHardnessLiveForceAsync(); - if (liveForce > peak) - peak = liveForce; - if (await _plc.ReadCoilAsync(completeCoil)) - { - double finalForce = await ReadHardnessLiveForceAsync(); - if (finalForce > peak) - peak = finalForce; - - if (peak <= 0) - throw new InvalidOperationException("硬度实时力数据异常"); - - return peak; - } + return; await Task.Delay(100); } @@ -1812,6 +1797,8 @@ namespace TabletTester2025.ViewModels HardnessAvg = stats.Average; HardnessAverageDeviation = stats.AverageDeviation; HardnessRSD = stats.RsdPercent; + HardnessMax = stats.Maximum; + HardnessMin = stats.Minimum; HardnessCurrentCount = stats.Count; HardnessPass = stats.IsPass; diff --git a/Views/MainWindow.xaml b/Views/MainWindow.xaml index ae26524..cc27315 100644 --- a/Views/MainWindow.xaml +++ b/Views/MainWindow.xaml @@ -571,10 +571,6 @@ - - - -