This commit is contained in:
@@ -158,16 +158,26 @@ namespace MembranePoreTester.ViewModels
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
private async Task ReadPlcAsync()
|
||||
{
|
||||
if (IsDisposed) return;
|
||||
|
||||
Record.BubblePointPressure = Record.BubbleCurrentPressure;
|
||||
|
||||
OnPropertyChanged(nameof(Record.BubblePointPressure));
|
||||
try
|
||||
{
|
||||
double rawPressure = await _plcService.ReadPressureAsync(StationId);
|
||||
rawPressure = Math.Round((double)rawPressure, 2);
|
||||
double pressure = rawPressure * _plcConfig.PressureFactor;
|
||||
|
||||
// 更新当前压力显示
|
||||
Record.BubbleCurrentPressure = pressure;
|
||||
// 同时将泡点压力设为该值(符合涨破测试逻辑)
|
||||
Record.BubblePointPressure = pressure;
|
||||
|
||||
OnPropertyChanged(nameof(Record.BubblePointPressure));
|
||||
OnPropertyChanged(nameof(Record.BubbleCurrentPressure));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show($"读取PLC失败: {ex.Message}", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -207,12 +217,12 @@ namespace MembranePoreTester.ViewModels
|
||||
{
|
||||
StationId = StationId,
|
||||
TestDate = Record.TestDate,
|
||||
Tester = Record.Tester,
|
||||
SampleType = Record.SampleType,
|
||||
SampleSpec = Record.SampleSpec,
|
||||
Tester = Record.Tester ?? "系统操作员",
|
||||
SampleType = Record.SampleType ?? "缺省值",
|
||||
SampleSpec = Record.SampleSpec ?? "缺省值",
|
||||
RoomTemperature = Record.RoomTemperature,
|
||||
SoakingTime = Record.SoakingTime,
|
||||
LiquidName = Record.Liquid?.Name,
|
||||
LiquidName = Record.Liquid?.Name ?? "缺省值",
|
||||
LiquidSurfaceTension = Record.Liquid?.SurfaceTension ?? 0,
|
||||
LiquidManufacturer = Record.LiquidManufacturer,
|
||||
BubblePointPressure = Record.BubblePointPressure,
|
||||
@@ -232,12 +242,12 @@ namespace MembranePoreTester.ViewModels
|
||||
|
||||
Record.SampleType = entity.SampleType;
|
||||
Record.SampleSpec = entity.SampleSpec;
|
||||
Record.RoomTemperature = entity.RoomTemperature;
|
||||
Record.SoakingTime = entity.SoakingTime;
|
||||
Record.RoomTemperature = entity.RoomTemperature ?? 0;
|
||||
Record.SoakingTime = entity.SoakingTime ?? 0;
|
||||
Record.Liquid = TestLiquid.Predefined.FirstOrDefault(l => l.Name == entity.LiquidName)
|
||||
?? new TestLiquid { Name = entity.LiquidName, SurfaceTension = entity.LiquidSurfaceTension };
|
||||
?? new TestLiquid { Name = entity.LiquidName, SurfaceTension = entity.LiquidSurfaceTension ?? 0 };
|
||||
Record.LiquidManufacturer = entity.LiquidManufacturer;
|
||||
Record.BubblePointPressure = entity.BubblePointPressure;
|
||||
Record.BubblePointPressure = entity.BubblePointPressure ?? 0;
|
||||
Record.PressureUnit = entity.PressureUnit;
|
||||
Record.TestDate = entity.TestDate;
|
||||
Record.Tester = entity.Tester;
|
||||
@@ -316,8 +326,23 @@ namespace MembranePoreTester.ViewModels
|
||||
};
|
||||
if (saveFileDialog.ShowDialog() == true)
|
||||
{
|
||||
// 转换为Entity后导出
|
||||
var entity = new BubblePointEntity { /* 从Record复制 */ };
|
||||
// 将 Record 转换为 Entity
|
||||
var entity = new BubblePointEntity
|
||||
{
|
||||
StationId = this.StationId,
|
||||
TestDate = Record.TestDate,
|
||||
Tester = Record.Tester,
|
||||
SampleType = Record.SampleType,
|
||||
SampleSpec = Record.SampleSpec,
|
||||
RoomTemperature = Record.RoomTemperature,
|
||||
SoakingTime = Record.SoakingTime,
|
||||
LiquidName = Record.Liquid?.Name,
|
||||
LiquidSurfaceTension = Record.Liquid?.SurfaceTension,
|
||||
LiquidManufacturer = Record.LiquidManufacturer,
|
||||
BubblePointPressure = Record.BubblePointPressure,
|
||||
PressureUnit = Record.PressureUnit,
|
||||
MaxPoreSize = Record.MaxPoreSize
|
||||
};
|
||||
ExportHelper.ExportBubblePoint(entity, saveFileDialog.FileName);
|
||||
MessageBox.Show("导出成功");
|
||||
}
|
||||
|
||||
@@ -91,59 +91,44 @@ namespace MembranePoreTester.ViewModels
|
||||
|
||||
private async void AutoCollectTimer_Tick(object sender, EventArgs e)
|
||||
{
|
||||
if (!IsActive) return; // 不在当前标签页,跳过采集
|
||||
await SafeExecuteAsync($"AutoCollect_Station{StationId}", async () =>
|
||||
if (!IsActive) return;
|
||||
|
||||
try
|
||||
{
|
||||
try
|
||||
// 1. 读取当前压力
|
||||
float rawPressure = await _plcService.ReadPressureAsync(StationId);
|
||||
double pressure = Math.Round(rawPressure * _plcConfig.PressureFactor, 2);
|
||||
|
||||
// 2. 读取当前模式对应的流量
|
||||
double flow = 0;
|
||||
if (TestMode.Contains("湿膜"))
|
||||
{
|
||||
// 1. 读取当前压力
|
||||
float rawPressure = await _plcService.ReadPressureAsync(StationId);
|
||||
double pressure = Math.Round(rawPressure, 2);
|
||||
|
||||
double flow = 0;
|
||||
if (TestMode == "湿膜")
|
||||
{
|
||||
float rawFlow = await _plcService.ReadWetFlowAsync();
|
||||
flow = rawFlow;
|
||||
}
|
||||
else
|
||||
{
|
||||
float rawFlow = await _plcService.ReadDryFlowAsync();
|
||||
flow = rawFlow;
|
||||
}
|
||||
|
||||
flow = Math.Round(flow, 2);
|
||||
// 3. 在 DataPoints 中查找是否存在相同压力的行(允许微小误差)
|
||||
var existing = Record.DataPoints.FirstOrDefault(p => Math.Abs(p.Pressure - pressure) < 0.001);
|
||||
if (existing != null)
|
||||
{
|
||||
// 更新对应列
|
||||
if (TestMode == "湿膜")
|
||||
existing.WetFlow = flow;
|
||||
else
|
||||
existing.DryFlow = flow;
|
||||
}
|
||||
else
|
||||
{
|
||||
// 新增一行
|
||||
var newPoint = new Models.DataPoint { Pressure = pressure };
|
||||
if (TestMode == "湿膜")
|
||||
newPoint.WetFlow = flow;
|
||||
else
|
||||
newPoint.DryFlow = flow;
|
||||
Record.DataPoints.Add(newPoint);
|
||||
}
|
||||
|
||||
// 4. 刷新曲线
|
||||
UpdatePlot();
|
||||
float rawFlow = await _plcService.ReadWetFlowAsync();
|
||||
flow = Math.Round(rawFlow, 2);
|
||||
}
|
||||
catch (Exception ex)
|
||||
else
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine($"自动采集失败: {ex.Message}");
|
||||
float rawFlow = await _plcService.ReadDryFlowAsync();
|
||||
flow = Math.Round(rawFlow, 2);
|
||||
}
|
||||
});
|
||||
|
||||
// 3. 直接新增一行(不查找相同压力)
|
||||
var newPoint = new Models.DataPoint
|
||||
{
|
||||
Pressure = pressure,
|
||||
WetFlow = TestMode.Contains("湿膜") ? flow : 0,
|
||||
DryFlow = TestMode.Contains("干膜") ? flow : 0
|
||||
};
|
||||
Record.DataPoints.Add(newPoint);
|
||||
|
||||
// 4. 刷新曲线
|
||||
UpdatePlot();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine($"自动采集失败: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 清空所有数据点,重置表格和曲线
|
||||
/// </summary>
|
||||
@@ -285,7 +270,10 @@ namespace MembranePoreTester.ViewModels
|
||||
|
||||
Record.DataPoints.CollectionChanged += (s, e) => UpdatePlot();
|
||||
|
||||
// 加到构造函数最后即可
|
||||
ClearAllCommand = new RelayCommand(ClearAllData);
|
||||
|
||||
RemoveDataPointCommand = new RelayCommand(RemoveSelectedDataPoint, () => SelectedDataPoint != null);
|
||||
|
||||
// 延迟2秒后读取,确保连接稳定
|
||||
Task.Delay(2000).ContinueWith(async _ =>
|
||||
@@ -295,6 +283,11 @@ namespace MembranePoreTester.ViewModels
|
||||
|
||||
}
|
||||
|
||||
private void ClearAllData()
|
||||
{
|
||||
ClearData();
|
||||
}
|
||||
|
||||
private async Task ReadPressureModeAsync()
|
||||
{
|
||||
await SafeExecuteAsync($"ReadPressureModeAsync{StationId}", async () =>
|
||||
@@ -338,7 +331,7 @@ namespace MembranePoreTester.ViewModels
|
||||
|
||||
// 始终读取压力
|
||||
float rawPressure = await _plcService.ReadPressureAsync(StationId);
|
||||
double pressure = rawPressure;
|
||||
double pressure = Math.Round(rawPressure * _plcConfig.PressureFactor, 2);
|
||||
|
||||
if (SelectedDataPoint != null)
|
||||
{
|
||||
@@ -495,14 +488,14 @@ namespace MembranePoreTester.ViewModels
|
||||
{
|
||||
StationId = this.StationId,
|
||||
TestDate = Record.TestDate,
|
||||
Tester = Record.Tester,
|
||||
Tester = Record.Tester ?? "系统操作员",
|
||||
SampleType = Record.SampleType,
|
||||
SampleSpec = Record.SampleSpec,
|
||||
SampleSpec = Record.SampleSpec ?? "缺省值",
|
||||
RoomTemperature = Record.RoomTemperature,
|
||||
SoakingTime = Record.SoakingTime,
|
||||
LiquidName = Record.Liquid?.Name,
|
||||
LiquidSurfaceTension = Record.Liquid?.SurfaceTension ?? 0,
|
||||
LiquidManufacturer = Record.LiquidManufacturer,
|
||||
LiquidManufacturer = Record.LiquidManufacturer ?? "缺省值",
|
||||
PressureUnit = Record.PressureUnit,
|
||||
BubblePointPressure = Record.BubblePointPressure,
|
||||
AveragePoreSize = AveragePoreSize, // 使用计算后的属性
|
||||
@@ -685,10 +678,22 @@ namespace MembranePoreTester.ViewModels
|
||||
}
|
||||
|
||||
|
||||
public ICommand ClearAllCommand { get; }
|
||||
|
||||
|
||||
// 修改命令初始化(构造函数中)
|
||||
|
||||
|
||||
// 实现删除方法
|
||||
private void RemoveSelectedDataPoint()
|
||||
{
|
||||
if (SelectedDataPoint != null)
|
||||
{
|
||||
Record.DataPoints.Remove(SelectedDataPoint);
|
||||
SelectedDataPoint = null; // 清除选中状态
|
||||
UpdatePlot(); // 刷新曲线
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user