Commit f88e593c authored by 潘栩锋's avatar 潘栩锋 🚴

修复 ModbusMapper_Client 实际采样周期统计,第1次读取时时间太短。

parent 582acd98
......@@ -104,6 +104,7 @@ namespace FLY.Modbus.WithThread
void OnPoll_update()
{
Stopwatch stopwatch = new Stopwatch();
Stopwatch stopwatch_act = new Stopwatch();
bool isTimeForRead = true;
_connect:
while (true)
......@@ -152,10 +153,17 @@ namespace FLY.Modbus.WithThread
if (isTimeForRead)
{
isTimeForRead = false;
TimeSpan elapsed = stopwatch.Elapsed;
ActUpdateInterval = elapsed;
stopwatch.Restart();
if (!stopwatch_act.IsRunning)
{
stopwatch_act.Restart();
}
else {
ActUpdateInterval = stopwatch_act.Elapsed;
stopwatch_act.Restart();
}
if (!UpdateReadData())
{
if (cts.IsCancellationRequested)//可能是外部强制关闭
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment