更新实时显示
This commit is contained in:
@@ -1047,13 +1047,16 @@ namespace COFTester.Services
|
||||
|
||||
// 循环读取传感器数据(不再发送 Start 命令)
|
||||
double intervalMs = 1000.0 / parameters.SamplingRate;
|
||||
int totalPoints = (int)(parameters.TestDuration * parameters.SamplingRate);
|
||||
int maxPoints = (int)(parameters.TestDuration * parameters.SamplingRate);
|
||||
int consecutiveZeroCount = 0; // 连续零值计数
|
||||
const int zeroThreshold = 3; // 连续3次全零才停止(避免误判)
|
||||
|
||||
System.Diagnostics.Debug.WriteLine($"[ModbusTCP] 数据采集配置: {totalPoints} 点, 间隔 {intervalMs:F1}ms");
|
||||
System.Diagnostics.Debug.WriteLine($"[ModbusTCP] 监控 M31 状态:1=测试中,0=停止");
|
||||
System.Diagnostics.Debug.WriteLine($"[ModbusTCP] 数据采集配置: 最大 {maxPoints} 点, 间隔 {intervalMs:F1}ms");
|
||||
System.Diagnostics.Debug.WriteLine($"[ModbusTCP] 停止条件:D1314力值、D360位移、D12升降位置、D16水平位置全为零");
|
||||
|
||||
// 循环读取传感器数据(包含力值、位移和位置)
|
||||
for (int i = 0; i < totalPoints && !token.IsCancellationRequested; i++)
|
||||
int i = 0;
|
||||
while (i < maxPoints && !token.IsCancellationRequested)
|
||||
{
|
||||
// 每隔一定次数检查 M31 状态(避免频繁读取)
|
||||
if (i % 10 == 0) // 每 10 个数据点检查一次
|
||||
@@ -1094,9 +1097,34 @@ namespace COFTester.Services
|
||||
dataPoint.HorizontalPosition = 0;
|
||||
}
|
||||
|
||||
// 检查是否所有数据都为零(使用小阈值判断浮点数为零)
|
||||
const double epsilon = 0.001; // 小于0.001视为零
|
||||
bool allZero = Math.Abs(dataPoint.Force) < epsilon &&
|
||||
Math.Abs(dataPoint.Displacement) < epsilon &&
|
||||
Math.Abs(dataPoint.VerticalPosition) < epsilon &&
|
||||
Math.Abs(dataPoint.HorizontalPosition) < epsilon;
|
||||
|
||||
if (allZero)
|
||||
{
|
||||
consecutiveZeroCount++;
|
||||
System.Diagnostics.Debug.WriteLine($"[ModbusTCP] 检测到全零数据 ({consecutiveZeroCount}/{zeroThreshold})");
|
||||
|
||||
if (consecutiveZeroCount >= zeroThreshold)
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine("[ModbusTCP] 连续检测到全零数据,停止采集");
|
||||
break; // 退出采集循环
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
consecutiveZeroCount = 0; // 重置计数器
|
||||
}
|
||||
|
||||
OnDataReceived(dataPoint);
|
||||
}
|
||||
|
||||
await Task.Delay((int)intervalMs, token);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
@@ -1533,13 +1561,16 @@ namespace COFTester.Services
|
||||
|
||||
// 循环读取传感器数据(不再发送 Start 命令)
|
||||
double intervalMs = 1000.0 / parameters.SamplingRate;
|
||||
int totalPoints = (int)(parameters.TestDuration * parameters.SamplingRate);
|
||||
int maxPoints = (int)(parameters.TestDuration * parameters.SamplingRate);
|
||||
int consecutiveZeroCount = 0; // 连续零值计数
|
||||
const int zeroThreshold = 3; // 连续3次全零才停止(避免误判)
|
||||
|
||||
System.Diagnostics.Debug.WriteLine($"[ModbusRTU] 数据采集配置: {totalPoints} 点, 间隔 {intervalMs:F1}ms");
|
||||
System.Diagnostics.Debug.WriteLine($"[ModbusRTU] 监控 M31 状态:1=测试中,0=停止");
|
||||
System.Diagnostics.Debug.WriteLine($"[ModbusRTU] 数据采集配置: 最大 {maxPoints} 点, 间隔 {intervalMs:F1}ms");
|
||||
System.Diagnostics.Debug.WriteLine($"[ModbusRTU] 停止条件:D1314力值、D360位移、D12升降位置、D16水平位置全为零");
|
||||
|
||||
// 循环读取传感器数据(包含力值、位移和位置)
|
||||
for (int i = 0; i < totalPoints && !token.IsCancellationRequested; i++)
|
||||
int i = 0;
|
||||
while (i < maxPoints && !token.IsCancellationRequested)
|
||||
{
|
||||
// 每隔一定次数检查 M31 状态(避免频繁读取)
|
||||
if (i % 10 == 0) // 每 10 个数据点检查一次
|
||||
@@ -1580,9 +1611,34 @@ namespace COFTester.Services
|
||||
dataPoint.HorizontalPosition = 0;
|
||||
}
|
||||
|
||||
// 检查是否所有数据都为零(使用小阈值判断浮点数为零)
|
||||
const double epsilon = 0.001; // 小于0.001视为零
|
||||
bool allZero = Math.Abs(dataPoint.Force) < epsilon &&
|
||||
Math.Abs(dataPoint.Displacement) < epsilon &&
|
||||
Math.Abs(dataPoint.VerticalPosition) < epsilon &&
|
||||
Math.Abs(dataPoint.HorizontalPosition) < epsilon;
|
||||
|
||||
if (allZero)
|
||||
{
|
||||
consecutiveZeroCount++;
|
||||
System.Diagnostics.Debug.WriteLine($"[ModbusRTU] 检测到全零数据 ({consecutiveZeroCount}/{zeroThreshold})");
|
||||
|
||||
if (consecutiveZeroCount >= zeroThreshold)
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine("[ModbusRTU] 连续检测到全零数据,停止采集");
|
||||
break; // 退出采集循环
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
consecutiveZeroCount = 0; // 重置计数器
|
||||
}
|
||||
|
||||
OnDataReceived(dataPoint);
|
||||
}
|
||||
|
||||
await Task.Delay((int)intervalMs, token);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
@@ -2002,13 +2058,16 @@ namespace COFTester.Services
|
||||
|
||||
// 循环读取传感器数据(不再发送 Start 命令)
|
||||
double intervalMs = 1000.0 / parameters.SamplingRate;
|
||||
int totalPoints = (int)(parameters.TestDuration * parameters.SamplingRate);
|
||||
int maxPoints = (int)(parameters.TestDuration * parameters.SamplingRate);
|
||||
int consecutiveZeroCount = 0; // 连续零值计数
|
||||
const int zeroThreshold = 3; // 连续3次全零才停止(避免误判)
|
||||
|
||||
System.Diagnostics.Debug.WriteLine($"[ModbusASCII] 数据采集配置: {totalPoints} 点, 间隔 {intervalMs:F1}ms");
|
||||
System.Diagnostics.Debug.WriteLine($"[ModbusASCII] 监控 M31 状态:1=测试中,0=停止");
|
||||
System.Diagnostics.Debug.WriteLine($"[ModbusASCII] 数据采集配置: 最大 {maxPoints} 点, 间隔 {intervalMs:F1}ms");
|
||||
System.Diagnostics.Debug.WriteLine($"[ModbusASCII] 停止条件:D1314力值、D360位移、D12升降位置、D16水平位置全为零");
|
||||
|
||||
// 循环读取传感器数据(包含力值、位移和位置)
|
||||
for (int i = 0; i < totalPoints && !token.IsCancellationRequested; i++)
|
||||
int i = 0;
|
||||
while (i < maxPoints && !token.IsCancellationRequested)
|
||||
{
|
||||
// 每隔一定次数检查 M31 状态(避免频繁读取)
|
||||
if (i % 10 == 0) // 每 10 个数据点检查一次
|
||||
@@ -2049,9 +2108,34 @@ namespace COFTester.Services
|
||||
dataPoint.HorizontalPosition = 0;
|
||||
}
|
||||
|
||||
// 检查是否所有数据都为零(使用小阈值判断浮点数为零)
|
||||
const double epsilon = 0.001; // 小于0.001视为零
|
||||
bool allZero = Math.Abs(dataPoint.Force) < epsilon &&
|
||||
Math.Abs(dataPoint.Displacement) < epsilon &&
|
||||
Math.Abs(dataPoint.VerticalPosition) < epsilon &&
|
||||
Math.Abs(dataPoint.HorizontalPosition) < epsilon;
|
||||
|
||||
if (allZero)
|
||||
{
|
||||
consecutiveZeroCount++;
|
||||
System.Diagnostics.Debug.WriteLine($"[ModbusASCII] 检测到全零数据 ({consecutiveZeroCount}/{zeroThreshold})");
|
||||
|
||||
if (consecutiveZeroCount >= zeroThreshold)
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine("[ModbusASCII] 连续检测到全零数据,停止采集");
|
||||
break; // 退出采集循环
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
consecutiveZeroCount = 0; // 重置计数器
|
||||
}
|
||||
|
||||
OnDataReceived(dataPoint);
|
||||
}
|
||||
|
||||
await Task.Delay((int)intervalMs, token);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
|
||||
Reference in New Issue
Block a user