From 0be672788fb025bd3a9de062eae9ca1a67f9ed63 Mon Sep 17 00:00:00 2001
From: "2248356998 qq.com" <2248356998@qq.com>
Date: Mon, 27 Mar 2023 08:49:10 +0800
Subject: [PATCH] update code collation
---
.../TouchSocketEx/TGWaitingClient.cs | 3 ++-
.../HostServices/CollectDeviceCore.cs | 5 +++--
.../HostServices/CollectDeviceHostService.cs | 1 +
3 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/src/ThingsGateway.Foundation/TouchSocketEx/TGWaitingClient.cs b/src/ThingsGateway.Foundation/TouchSocketEx/TGWaitingClient.cs
index 3557738fb..c54d2ad0f 100644
--- a/src/ThingsGateway.Foundation/TouchSocketEx/TGWaitingClient.cs
+++ b/src/ThingsGateway.Foundation/TouchSocketEx/TGWaitingClient.cs
@@ -165,7 +165,7 @@ namespace ThingsGateway.Foundation
return SendThenResponse(byteBlock.Buffer, 0, byteBlock.Len, timeout, token);
}
///
- /// 异步发送
+ /// 异步发送,,非线程安全
///
/// 数据缓存区
/// 偏移
@@ -178,6 +178,7 @@ namespace ThingsGateway.Foundation
/// 返回的数据
public async Task SendThenResponseAsync(byte[] buffer, int offset, int length, int timeout = 1000 * 5, CancellationToken token = default)
{
+
try
{
breaked = false;
diff --git a/src/ThingsGateway.Web.Foundation/HostServices/CollectDeviceCore.cs b/src/ThingsGateway.Web.Foundation/HostServices/CollectDeviceCore.cs
index 1150c2a15..a1f0de7f8 100644
--- a/src/ThingsGateway.Web.Foundation/HostServices/CollectDeviceCore.cs
+++ b/src/ThingsGateway.Web.Foundation/HostServices/CollectDeviceCore.cs
@@ -202,17 +202,18 @@ public class CollectDeviceCore : DisposableObject
break;
//连读变量
+ var readTime = DateTime.Now;
if (deviceVariableSourceRead.CheckIfRequestAndUpdateTime(DateTime.Now))
{
var read = await _driver.ReadSourceAsync(deviceVariableSourceRead, StoppingToken.Token);
if (read != null && read.IsSuccess)
{
- _logger?.LogTrace(_device.Name + "采集[" + deviceVariableSourceRead.Address + " -" + deviceVariableSourceRead.Length + "] 数据成功" + read.Content?.ToHexString(" "));
+ _logger?.LogTrace(_device.Name +" - "+ readTime+" - 采集[" + deviceVariableSourceRead.Address + " - " + deviceVariableSourceRead.Length + "] 数据成功" + read.Content?.ToHexString(" "));
deviceSourceVariableSuccessNum += 1;
}
else if (read != null && read.IsSuccess == false)
{
- _logger?.LogWarning(_device.Name + "采集[" + deviceVariableSourceRead.Address + " -" + deviceVariableSourceRead.Length + "] 数据失败 - " + read?.Message);
+ _logger?.LogWarning(_device.Name +" - "+ readTime+ " - 采集[" + deviceVariableSourceRead.Address + " -" + deviceVariableSourceRead.Length + "] 数据失败 - " + read?.Message);
deviceSourceVariableFailedNum += 1;
}
}
diff --git a/src/ThingsGateway.Web.Foundation/HostServices/CollectDeviceHostService.cs b/src/ThingsGateway.Web.Foundation/HostServices/CollectDeviceHostService.cs
index 76b51de65..a2058dc64 100644
--- a/src/ThingsGateway.Web.Foundation/HostServices/CollectDeviceHostService.cs
+++ b/src/ThingsGateway.Web.Foundation/HostServices/CollectDeviceHostService.cs
@@ -270,6 +270,7 @@ public class CollectDeviceHostService : BackgroundService
_logger?.LogError(ex, device.Name);
}
}
+ await Task.Delay(2000);
await base.StopAsync(cancellationToken);
}
private CancellationToken _stoppingToken;