This commit is contained in:
xyy
2026-03-11 19:11:16 +08:00
parent fb82101706
commit 01b2f8f901

View File

@@ -265,49 +265,49 @@ namespace PLCDataMonitor
{
int i = 0;
while (i < 100)
{
// 添加随机测试数据
Random random = new Random();
//int i = 0;
//while (i < 100)
//{
// // 添加随机测试数据
// Random random = new Random();
// 生成随机摩擦力值(包含负值)
double friction1 = random.Next(-200, 200);
double friction2 = random.Next(-200, 200);
// // 生成随机摩擦力值(包含负值)
// double friction1 = random.Next(-200, 200);
// double friction2 = random.Next(-200, 200);
// 创建数据点(时间戳相同,确保数据一致性)
var dataPoint = new Tuple<DateTime, double, double>(
DateTime.Now,
friction1,
friction2
);
// // 创建数据点(时间戳相同,确保数据一致性)
// var dataPoint = new Tuple<DateTime, double, double>(
// DateTime.Now,
// friction1,
// friction2
// );
// 关键修改:同时添加到两个地方
// 1. 添加到共享曲线数据队列(曲线页面和报表页面共享)
_sharedCurveDataQueue.Enqueue(dataPoint);
// // 关键修改:同时添加到两个地方
// // 1. 添加到共享曲线数据队列(曲线页面和报表页面共享)
// _sharedCurveDataQueue.Enqueue(dataPoint);
// 2. 添加到报表数据
_reportPage.AddReportRecord(new ReportData
{
D = random.Next(1, 100),
Friction1 = friction1.ToString("F1"), // 使用相同的摩擦力值
Friction2 = friction2.ToString("F1"), // 使用相同的摩擦力值
Id = (i + 11).ToString(),
Pressure1 = random.Next(1, 10).ToString(),
Pressure2 = random.Next(2, 12).ToString(),
t1 = random.Next(20, 40),
t2 = random.Next(25, 45),
Time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") // 使用相同的时间格式
});
// // 2. 添加到报表数据
// _reportPage.AddReportRecord(new ReportData
// {
// D = random.Next(1, 100),
// Friction1 = friction1.ToString("F1"), // 使用相同的摩擦力值
// Friction2 = friction2.ToString("F1"), // 使用相同的摩擦力值
// Id = (i + 11).ToString(),
// Pressure1 = random.Next(1, 10).ToString(),
// Pressure2 = random.Next(2, 12).ToString(),
// t1 = random.Next(20, 40),
// t2 = random.Next(25, 45),
// Time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") // 使用相同的时间格式
// });
// 3. 通知曲线页面更新(这个调用只是触发重绘,数据已经在队列中)
_curvePage.AddFrictionData(friction1, friction2);
// // 3. 通知曲线页面更新(这个调用只是触发重绘,数据已经在队列中)
// _curvePage.AddFrictionData(friction1, friction2);
// 为了让曲线更平滑,可以少量数据生成
Thread.Sleep(100); // 每100ms一个数据点
// // 为了让曲线更平滑,可以少量数据生成
// Thread.Sleep(100); // 每100ms一个数据点
i++;
}
// i++;
//}