This commit is contained in:
xyy
2026-04-02 18:06:10 +08:00
parent 85583d1ba2
commit 47cfa4c05b
4 changed files with 83 additions and 18 deletions

View File

@@ -78,6 +78,7 @@ namespace MembranePoreTester.ViewModels
set => SetProperty(ref _pressButtonText, value);
}
public bool EnableStatus
{
get => _enableStatus;
@@ -85,12 +86,17 @@ namespace MembranePoreTester.ViewModels
{
if (SetProperty(ref _enableStatus, value))
{
// 当 EnableStatus 变化时,通知依赖的属性也变化
// 当设备停止运行时,停止孔分布自动采集
if (!value)
{
PoreDistributionVM?.StopCollecting();
}
OnPropertyChanged(nameof(EnableStatusText));
OnPropertyChanged(nameof(EnableStatusColor));
}
}
}
// 使能状态显示文本
public string EnableStatusText => EnableStatus ? "运行中" : "未启动";
@@ -113,23 +119,25 @@ namespace MembranePoreTester.ViewModels
private double _pressureUpperLimit;
private double _pressureRate;
// 防止从PLC读取时触发校验弹窗
private bool _suppressPressureValidation = false;
public double PressureUpperLimit
{
get => _pressureUpperLimit;
set
{
if (SetProperty(ref _pressureUpperLimit, value))
// 如果不是从PLC读取即用户交互或程序主动设置先校验再设置
if (!_suppressPressureValidation && HighLowPressure.Contains("低压") && value > 200)
{
MessageBox.Show("低压模式,加压上限不能超过200!");
return;
}
bool changed = SetProperty(ref _pressureUpperLimit, value);
// 仅在非抑制模式下将改变写回PLC避免把PLC读回的值再次写入造成循环
if (changed && !_suppressPressureValidation)
{
if (HighLowPressure == "低压")
{
if (value > 200)
{
MessageBox.Show("低压模式,加压上限不能超过200!");
return;
}
}
// 值改变时写入PLC
_ = _plcService.WriteMultipleRegistersAsync(_plcConfig.PressureUpperLimit, (float)value);
}
}
@@ -161,8 +169,11 @@ namespace MembranePoreTester.ViewModels
Application.Current.Dispatcher.Invoke(() =>
{
// 在将PLC读取的值赋回到属性时抑制用户校验提示和避免回写PLC
_suppressPressureValidation = true;
PressureUpperLimit = upperLimit;
PressureRate = rate;
_suppressPressureValidation = false;
});
}
catch (Exception ex)

View File

@@ -407,17 +407,33 @@ namespace MembranePoreTester.ViewModels
// 修改 Calculate 方法:
private void Calculate()
{
var cleanedPoints = CleanDataPoints(Record.DataPoints);
if (Record.DataPoints.Count < 2) return;
// 先清洗数据并替换到绑定的集合中确保DataGrid和曲线显示清洗后的数据
var originalPoints = Record.DataPoints.ToList();
var cleanedPoints = CleanDataPoints(originalPoints);
if (cleanedPoints.Count < 2)
{
MessageBox.Show("有效数据点不足,至少需要 2 个数据点进行计算。");
return;
}
int invalidCount = originalPoints.Count - cleanedPoints.Count;
// 用清洗后的点替换 ObservableCollection 的内容触发UI更新
Record.DataPoints.Clear();
foreach (var p in cleanedPoints)
Record.DataPoints.Add(p);
// 刷新曲线以显示清洗后的数据
UpdatePlot();
// 使用清洗后的集合进行计算
AveragePoreSize = PoreDistributionAnalysis.CalculateAveragePore(
Record.DataPoints, Record.PressureUnit, Record.Liquid);
RangePercentage = PoreDistributionAnalysis.CalculatePoreRangePercentage(
Record.DataPoints, Record.PressureUnit, Record.Liquid, LowerPore, UpperPore);
// 可选:提示用户过滤了多少无效点
int invalidCount = Record.DataPoints.Count - cleanedPoints.Count;
if (invalidCount > 0)
{
MessageBox.Show($"已自动过滤 {invalidCount} 个无效数据点");