This commit is contained in:
GukSang.Jin
2025-12-31 14:15:34 +08:00
parent 5075aa0533
commit 1c0d725886

View File

@@ -372,16 +372,21 @@ namespace WindowsFormsApp6
}
/// <summary>
/// 定时器事件 - 模拟从寄存器读取吸水时间数据
/// 定时器事件 - 模拟从寄存器读取数据
/// </summary>
private void DataTimer_Tick(object sender, EventArgs e)
{
// 读取吸水时间(s) - 从寄存器读取
// 第1行读取吸水时间(s) - 从寄存器读取每个试样读取3次
DataRow timeRow = sampleDataTable.Rows[0];
for (int i = 1; i <= currentSampleCount; i++)
{
double registerValue = ReadRegisterData(i - 1);
timeRow[$"试样{i}_1"] = registerValue;
double time1 = ReadRegisterData((i - 1) * 3); // 第1次测试
double time2 = ReadRegisterData((i - 1) * 3 + 1); // 第2次测试
double time3 = ReadRegisterData((i - 1) * 3 + 2); // 第3次测试
timeRow[$"试样{i}_1"] = time1;
timeRow[$"试样{i}_2"] = time2;
timeRow[$"试样{i}_3"] = time3;
}
UpdateDisplay();
@@ -392,6 +397,7 @@ namespace WindowsFormsApp6
/// </summary>
private double ReadRegisterData(int registerAddress)
{
// 吸水时间寄存器30-34秒
return 30 + random.NextDouble() * 4;
}
@@ -411,14 +417,19 @@ namespace WindowsFormsApp6
}
}
// 第1行吸水时间s- 试样次数1系统读数)
// 每个试样只在第1次测试时记录吸水时间
// 第1行吸水时间s- 系统读数每个试样3次
DataRow timeRow = sampleDataTable.Rows[0];
for (int i = 1; i <= currentSampleCount; i++)
{
double timeValue = Math.Round(30 + random.NextDouble() * 4, 2); // 30-34秒
timeRow[$"试样{i}_1"] = timeValue;
// 试样次数2和3不使用保持为0
// 生成3次测试的吸水时间数据30-34秒略有差异
double baseTime = 31 + random.NextDouble() * 2; // 基准时间 31-33秒
double time1 = Math.Round(baseTime + (random.NextDouble() - 0.5) * 2, 2); // ±1秒
double time2 = Math.Round(baseTime + (random.NextDouble() - 0.5) * 2, 2);
double time3 = Math.Round(baseTime + (random.NextDouble() - 0.5) * 2, 2);
timeRow[$"试样{i}_1"] = time1;
timeRow[$"试样{i}_2"] = time2;
timeRow[$"试样{i}_3"] = time3;
}
// 第2行吸芯高度mm- 手动输入,不自动生成
@@ -431,63 +442,12 @@ namespace WindowsFormsApp6
RefreshDataGridView();
ShowMessage($"已生成 {currentSampleCount} 个试样的吸水时间数据\n" +
$"- 吸水时间30-34秒系统读数\n" +
$"- 吸水时间30-34秒系统读数每个试样3次\n" +
$"- 吸芯高度请手动输入每个试样3次测试\n" +
$"- 芯吸速率:输入吸芯高度后自动计算",
"模拟数据生成");
}
/// <summary>
/// 生成完整的测试数据(包含吸芯高度)- 用于快速测试
/// </summary>
public void GenerateFullMockData()
{
// 清空所有行的数据(保持表结构)
foreach (DataRow row in sampleDataTable.Rows)
{
for (int i = 1; i <= currentSampleCount; i++)
{
row[$"试样{i}_1"] = 0.0;
row[$"试样{i}_2"] = 0.0;
row[$"试样{i}_3"] = 0.0;
}
}
// 第1行吸水时间s
DataRow timeRow = sampleDataTable.Rows[0];
for (int i = 1; i <= currentSampleCount; i++)
{
double timeValue = Math.Round(30 + random.NextDouble() * 4, 2);
timeRow[$"试样{i}_1"] = timeValue;
}
// 第2行吸芯高度mm- 生成测试数据
DataRow heightRow = sampleDataTable.Rows[1];
for (int i = 1; i <= currentSampleCount; i++)
{
double baseHeight = 55 + random.NextDouble() * 10;
double height1 = Math.Round(baseHeight + (random.NextDouble() - 0.5) * 4, 2);
double height2 = Math.Round(baseHeight + (random.NextDouble() - 0.5) * 4, 2);
double height3 = Math.Round(baseHeight + (random.NextDouble() - 0.5) * 4, 2);
heightRow[$"试样{i}_1"] = height1;
heightRow[$"试样{i}_2"] = height2;
heightRow[$"试样{i}_3"] = height3;
}
// 计算所有行
CalculateAllRows();
// 更新显示
RefreshDataGridView();
ShowMessage($"已生成完整测试数据(包含吸芯高度)\n" +
$"- 吸水时间30-34秒\n" +
$"- 吸芯高度50-70mm自动生成\n" +
$"- 芯吸速率:已自动计算",
"完整测试数据");
}
/// <summary>
/// 更新界面显示
/// </summary>
@@ -535,37 +495,25 @@ namespace WindowsFormsApp6
for (int i = 1; i <= currentSampleCount; i++)
{
// 获取吸水时间试样次数1系统读数
double time = ConvertToDouble(timeRow[$"试样{i}_1"]);
// 获取3次吸水时间测试数据
double time1 = ConvertToDouble(timeRow[$"试样{i}_1"]);
double time2 = ConvertToDouble(timeRow[$"试样{i}_2"]);
double time3 = ConvertToDouble(timeRow[$"试样{i}_3"]);
// 获取吸芯高度(优先使用对应列的数据
// 试样次数1 → 使用吸芯高度_1
// 试样次数2 → 使用吸芯高度_2
// 试样次数3 → 使用吸芯高度_3
// 获取3次吸芯高度测试数据
double height1 = ConvertToDouble(heightRow[$"试样{i}_1"]);
double height2 = ConvertToDouble(heightRow[$"试样{i}_2"]);
double height3 = ConvertToDouble(heightRow[$"试样{i}_3"]);
// 计算芯吸速率(使用对应的吸芯高度)
double rate = 0;
if (time > 0)
{
// 使用平均吸芯高度或选择非零值
double avgHeight = 0;
int count = 0;
if (height1 > 0) { avgHeight += height1; count++; }
if (height2 > 0) { avgHeight += height2; count++; }
if (height3 > 0) { avgHeight += height3; count++; }
if (count > 0)
{
avgHeight /= count;
rate = avgHeight / (time / 60.0);
}
}
// 计算3次芯吸速率(每次测试独立计算,使用对应的时间和高度)
double rate1 = (time1 > 0 && height1 > 0) ? height1 / (time1 / 60.0) : 0;
double rate2 = (time2 > 0 && height2 > 0) ? height2 / (time2 / 60.0) : 0;
double rate3 = (time3 > 0 && height3 > 0) ? height3 / (time3 / 60.0) : 0;
// 存储到试样次数3系统计算
rateRow[$"试样{i}_3"] = Math.Round(rate, 2);
// 存储到对应的列
rateRow[$"试样{i}_1"] = Math.Round(rate1, 2);
rateRow[$"试样{i}_2"] = Math.Round(rate2, 2);
rateRow[$"试样{i}_3"] = Math.Round(rate3, 2);
}
}