From 873dbe61bb2128d95f5539082751c5f31bc5d0bb Mon Sep 17 00:00:00 2001
From: xyy <544939200@qq.com>
Date: Fri, 15 May 2026 10:59:24 +0800
Subject: [PATCH]
---
ASTM D7896-19瞬态热线法.csproj | 1 +
ViewModels/D7896ViewModel.cs | 146 +++++++++++++++++++++---
Views/D7896View.xaml | 203 ++++++++++++++++-----------------
3 files changed, 232 insertions(+), 118 deletions(-)
diff --git a/ASTM D7896-19瞬态热线法.csproj b/ASTM D7896-19瞬态热线法.csproj
index b746fc5..6d8cff7 100644
--- a/ASTM D7896-19瞬态热线法.csproj
+++ b/ASTM D7896-19瞬态热线法.csproj
@@ -11,6 +11,7 @@
+
diff --git a/ViewModels/D7896ViewModel.cs b/ViewModels/D7896ViewModel.cs
index 860303f..c3e22e4 100644
--- a/ViewModels/D7896ViewModel.cs
+++ b/ViewModels/D7896ViewModel.cs
@@ -1,14 +1,17 @@
-using System;
-using System.Collections.ObjectModel;
-using System.Threading.Tasks;
-using System.Windows;
-using CommunityToolkit.Mvvm.ComponentModel;
-using CommunityToolkit.Mvvm.Input;
+using ASTM_D7896_Tester.Helpers;
using ASTM_D7896_Tester.Models;
using ASTM_D7896_Tester.Services;
-using ASTM_D7896_Tester.Helpers;
-using System.Linq;
+using CommunityToolkit.Mvvm.ComponentModel;
+using CommunityToolkit.Mvvm.Input;
+using OxyPlot;
+using OxyPlot.Axes;
+using OxyPlot.Series;
+using System;
+using System.Collections.ObjectModel;
using System.IO;
+using System.Linq;
+using System.Threading.Tasks;
+using System.Windows;
namespace ASTM_D7896_Tester.ViewModels;
@@ -89,6 +92,31 @@ public partial class D7896ViewModel : ObservableObject
[ObservableProperty]
private double _calibrationErrorPercent = 0.0;
+
+
+ // 新增核心参数(实时显示)
+ [ObservableProperty]
+ private double _platinumVoltage; // 铂丝电压 U_pt (V)
+
+ [ObservableProperty]
+ private double _standardResistorVoltage; // 标准电阻电压 U_std (V)
+
+ [ObservableProperty]
+ private double _platinumResistance; // 铂丝电阻 R_pt (Ω)
+
+ [ObservableProperty]
+ private double _chamberPressure; // 样品池压力 (kPa)
+
+
+
+ // 当前曲线标题
+ [ObservableProperty]
+ private string _curveTitle = "温升曲线";
+
+ // 在 ViewModel 中
+ [ObservableProperty]
+ private PlotModel _temperatureCurveModel;
+
public D7896ViewModel()
{
_config = JsonConfigHelper.LoadConfig();
@@ -101,6 +129,10 @@ public partial class D7896ViewModel : ObservableObject
PressureValue = _config.TestParameters.DefaultPressure;
SelectedReferenceLiquid = _config.TestParameters.ReferenceLiquid;
ReferenceConductivity = _config.TestParameters.ReferenceConductivity;
+ IsCleanConfirmed = true;
+ BubbleRemoved = true;
+ PlatinumCompatible = true;
+ AmbientCalibrated = true;
}
// ========== 原有命令 ==========
@@ -177,7 +209,7 @@ public partial class D7896ViewModel : ObservableObject
float temperature = await _plcService.ReadFloatAsync(_config.PlcRegisterAddresses.TestTemperature);
if (i == 1) TestTemperature = temperature;
-
+ GenerateTemperatureCurve(lambda, alpha); // 更新曲线图
var result = new MeasurementResult
{
Index = i,
@@ -199,6 +231,7 @@ public partial class D7896ViewModel : ObservableObject
}
}
+
CalculateAverages();
StatusMessage = "测试完成。";
}
@@ -214,6 +247,85 @@ public partial class D7896ViewModel : ObservableObject
}
}
+
+ // 模拟获取实时核心参数(实际应从PLC读取)
+ private async Task UpdateRealTimeParametersAsync()
+ {
+ if (await _plcService.IsConnectedAsync())
+ {
+ // 示例:从PLC读取这些值(地址需在配置文件中定义)
+ PlatinumVoltage = await _plcService.ReadFloatAsync(40010); // 假设地址
+ StandardResistorVoltage = await _plcService.ReadFloatAsync(40012);
+ PlatinumResistance = await _plcService.ReadFloatAsync(40014);
+ ChamberPressure = await _plcService.ReadFloatAsync(40016);
+ }
+ }
+ private void GenerateTemperatureCurve(float lambda, float alpha)
+ {
+ // 第一次调用时初始化 PlotModel(只创建一次)
+ if (TemperatureCurveModel == null)
+ {
+ TemperatureCurveModel = new PlotModel
+ {
+ Title = "温升曲线对比 (10次测量)",
+ Background = OxyColors.White
+ };
+ // 添加坐标轴(只添加一次)
+ TemperatureCurveModel.Axes.Add(new LinearAxis
+ {
+ Position = AxisPosition.Bottom,
+ Title = "时间 (s)",
+ Minimum = 0,
+ Maximum = 2
+ });
+ TemperatureCurveModel.Axes.Add(new LinearAxis
+ {
+ Position = AxisPosition.Left,
+ Title = "温升 (℃)",
+ Minimum = 0
+ });
+ }
+
+ // 创建本次测量的曲线系列(用不同颜色区分)
+ var series = new LineSeries
+ {
+ Title = $"第{CurrentMeasurementIndex}次测量",
+ Color = GetColorForIndex(CurrentMeasurementIndex),
+ StrokeThickness = 1.5,
+ MarkerType = MarkerType.None
+ };
+
+ // 添加数据点(这里仍用模拟数据,实际应替换为真实采集数据)
+ // 理论公式:ΔT = (Q/(4πλL)) * ln(t/t0) + C
+ // 其中 Q 是加热功率,L 是铂丝长度,C 是常数
+ double Q = 0.01; // 假设 10mW,实际应从电流和电阻计算
+ double L = 0.04; // 40mm
+ double constant = 0.2;
+ for (int i = 0; i <= 200; i++)
+ {
+ double t = i * 0.01;
+ double deltaT = (Q / (4 * Math.PI * lambda * L)) * Math.Log(t + 0.1) + constant;
+ series.Points.Add(new DataPoint(t, deltaT));
+ }
+
+ // 将本次曲线添加到同一个 Model 中(叠加)
+ TemperatureCurveModel.Series.Add(series);
+ TemperatureCurveModel.InvalidatePlot(true);
+ CurveTitle = $"已完成 {CurrentMeasurementIndex} 次测量";
+ }
+
+ // 辅助方法:根据测量序号返回不同的颜色
+ private OxyColor GetColorForIndex(int index)
+ {
+ var colors = new[]
+ {
+ OxyColors.Red, OxyColors.Blue, OxyColors.Green, OxyColors.Orange,
+ OxyColors.Purple, OxyColors.Brown, OxyColors.Pink, OxyColors.Cyan,
+ OxyColors.Magenta, OxyColors.Olive
+ };
+ return colors[(index - 1) % colors.Length];
+ }
+
private void CalculateAverages()
{
if (Measurements.Count == 0) return;
@@ -232,12 +344,9 @@ public partial class D7896ViewModel : ObservableObject
CurrentMeasurementIndex = 0;
StatusMessage = "已重置";
TestDateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
-
+ TemperatureCurveModel = null; // 下次测量会重新初始化
// 重置确认标志(可根据需要决定是否重置)
- // IsCleanConfirmed = false;
- // BubbleRemoved = false;
- // PlatinumCompatible = false;
- // AmbientCalibrated = false;
+
}
[RelayCommand]
@@ -377,5 +486,14 @@ public partial class D7896ViewModel : ObservableObject
{
IsCalibrating = false;
}
+
+
+
+
}
+
+
+
+
+
}
\ No newline at end of file
diff --git a/Views/D7896View.xaml b/Views/D7896View.xaml
index d077b50..e3e1d56 100644
--- a/Views/D7896View.xaml
+++ b/Views/D7896View.xaml
@@ -1,6 +1,7 @@
-->
+
-
+
@@ -113,145 +115,138 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
-
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
-
-
+
+
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ RowHeight="28" MinHeight="150">
-
-
-
-
+
+
+
+
-
-
+
+
-
-
+
-
+
-
+
-
+
+
+
+
+
+
-
-
+
+
-
-
+
+
-
-
-
-
+
+
+
+
-
-
+
-
-
-
-
-
-
-
\ No newline at end of file