From 6db335cf877d08021b14d03f7b7b5e1435f81bed Mon Sep 17 00:00:00 2001 From: Kimdiego2098 <2248356998@qq.com> Date: Thu, 23 Nov 2023 20:51:08 +0800 Subject: [PATCH] =?UTF-8?q?OPCUA=E6=8F=92=E4=BB=B6afterStop=E6=96=B9?= =?UTF-8?q?=E6=B3=95=E9=87=8D=E5=86=99=E6=97=B6=E9=9C=80=E6=89=A7=E8=A1=8C?= =?UTF-8?q?=E7=88=B6=E7=B1=BB=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Plugin/CollectBase.cs | 4 +++- .../Workers/CollectDeviceWorker.cs | 7 ++++++- .../Workers/DeviceWorker.cs | 2 +- .../ThingsGateway.Gateway.Blazor.csproj | 1 - .../ThingsGateway.Plugin.DLT645.csproj | 2 +- .../ThingsGateway.Plugin.Modbus.csproj | 2 +- .../ThingsGateway.Plugin.OPCDA.csproj | 2 +- .../ThingsGateway.Plugin.OPCUA/OPCUAClient/OPCUAClient.cs | 2 +- .../ThingsGateway.Plugin.OPCUA.csproj | 2 +- .../ThingsGateway.Plugin.Siemens.csproj | 2 +- 10 files changed, 16 insertions(+), 10 deletions(-) diff --git a/framework/gateway/ThingsGateway.Gateway.Application/Plugin/CollectBase.cs b/framework/gateway/ThingsGateway.Gateway.Application/Plugin/CollectBase.cs index d808b9150..cfad7cd73 100644 --- a/framework/gateway/ThingsGateway.Gateway.Application/Plugin/CollectBase.cs +++ b/framework/gateway/ThingsGateway.Gateway.Application/Plugin/CollectBase.cs @@ -43,14 +43,16 @@ public abstract class CollectBase : DriverBase public override async Task AfterStopAsync() { - await base.AfterStopAsync(); //去除全局设备变量 lock (_globalDeviceData.CollectDevices) { _globalDeviceData.CollectDevices.RemoveWhere(it => it.Id == DeviceId); } + await base.AfterStopAsync(); } + + public override void Init(DeviceRunTime device) { base.Init(device); diff --git a/framework/gateway/ThingsGateway.Gateway.Application/Workers/CollectDeviceWorker.cs b/framework/gateway/ThingsGateway.Gateway.Application/Workers/CollectDeviceWorker.cs index 2d5613323..e9c9ac331 100644 --- a/framework/gateway/ThingsGateway.Gateway.Application/Workers/CollectDeviceWorker.cs +++ b/framework/gateway/ThingsGateway.Gateway.Application/Workers/CollectDeviceWorker.cs @@ -23,7 +23,7 @@ namespace ThingsGateway.Gateway.Application; /// public class CollectDeviceWorker : DeviceWorker { - + private GlobalDeviceData _globalDeviceData; public CollectDeviceWorker(IServiceScopeFactory serviceScopeFactory, IHostApplicationLifetime appLifetime) : base(serviceScopeFactory, appLifetime) { _logger = _serviceScope.ServiceProvider.GetService().CreateLogger("南向设备服务"); @@ -49,6 +49,10 @@ public class CollectDeviceWorker : DeviceWorker await StopOtherHostService(); //停止全部采集线程 await RemoveAllDeviceThreadAsync(); + + //清空内存列表 + _globalDeviceData.CollectDevices.Clear(); + //创建全部采集线程 await CreatAllDeviceThreadsAsync(); //开始其他后台服务 @@ -197,6 +201,7 @@ public class CollectDeviceWorker : DeviceWorker { await _easyLock?.WaitAsync(); _driverPluginService = _serviceScope.ServiceProvider.GetService(); + _globalDeviceData = _serviceScope.ServiceProvider.GetService(); //重启采集线程,会启动其他后台服务 await RestartDeviceThreadAsync(); await WhileExecuteAsync(stoppingToken); diff --git a/framework/gateway/ThingsGateway.Gateway.Application/Workers/DeviceWorker.cs b/framework/gateway/ThingsGateway.Gateway.Application/Workers/DeviceWorker.cs index 6aff6767f..0819c272d 100644 --- a/framework/gateway/ThingsGateway.Gateway.Application/Workers/DeviceWorker.cs +++ b/framework/gateway/ThingsGateway.Gateway.Application/Workers/DeviceWorker.cs @@ -49,7 +49,7 @@ public abstract class DeviceWorker : BackgroundService /// public List DriverBases => _deviceThreads .Where(a => a.DriverBases.Any(b => b.CurrentDevice != null)) - .SelectMany(a => a.DriverBases).ToList(); + .SelectMany(a => a.DriverBases).OrderByDescending(a => a.CurrentDevice.DeviceStatus).ToList(); /// /// 设备子线程列表 diff --git a/framework/gateway/ThingsGateway.Gateway.Blazor/ThingsGateway.Gateway.Blazor.csproj b/framework/gateway/ThingsGateway.Gateway.Blazor/ThingsGateway.Gateway.Blazor.csproj index 56424733b..59063e5b8 100644 --- a/framework/gateway/ThingsGateway.Gateway.Blazor/ThingsGateway.Gateway.Blazor.csproj +++ b/framework/gateway/ThingsGateway.Gateway.Blazor/ThingsGateway.Gateway.Blazor.csproj @@ -2,7 +2,6 @@ - diff --git a/framework/plugin/ThingsGateway.Plugin.DLT645/ThingsGateway.Plugin.DLT645.csproj b/framework/plugin/ThingsGateway.Plugin.DLT645/ThingsGateway.Plugin.DLT645.csproj index 0d9c3047d..340cc2586 100644 --- a/framework/plugin/ThingsGateway.Plugin.DLT645/ThingsGateway.Plugin.DLT645.csproj +++ b/framework/plugin/ThingsGateway.Plugin.DLT645/ThingsGateway.Plugin.DLT645.csproj @@ -30,7 +30,7 @@ - + false false runtime diff --git a/framework/plugin/ThingsGateway.Plugin.Modbus/ThingsGateway.Plugin.Modbus.csproj b/framework/plugin/ThingsGateway.Plugin.Modbus/ThingsGateway.Plugin.Modbus.csproj index 66999b6cd..bfe5515b4 100644 --- a/framework/plugin/ThingsGateway.Plugin.Modbus/ThingsGateway.Plugin.Modbus.csproj +++ b/framework/plugin/ThingsGateway.Plugin.Modbus/ThingsGateway.Plugin.Modbus.csproj @@ -51,7 +51,7 @@ - + false false runtime diff --git a/framework/plugin/ThingsGateway.Plugin.OPCDA/ThingsGateway.Plugin.OPCDA.csproj b/framework/plugin/ThingsGateway.Plugin.OPCDA/ThingsGateway.Plugin.OPCDA.csproj index 745c6d07c..cb2dd351a 100644 --- a/framework/plugin/ThingsGateway.Plugin.OPCDA/ThingsGateway.Plugin.OPCDA.csproj +++ b/framework/plugin/ThingsGateway.Plugin.OPCDA/ThingsGateway.Plugin.OPCDA.csproj @@ -45,7 +45,7 @@ - + false false runtime diff --git a/framework/plugin/ThingsGateway.Plugin.OPCUA/OPCUAClient/OPCUAClient.cs b/framework/plugin/ThingsGateway.Plugin.OPCUA/OPCUAClient/OPCUAClient.cs index 44ca25770..f996b1e99 100644 --- a/framework/plugin/ThingsGateway.Plugin.OPCUA/OPCUAClient/OPCUAClient.cs +++ b/framework/plugin/ThingsGateway.Plugin.OPCUA/OPCUAClient/OPCUAClient.cs @@ -48,7 +48,7 @@ public class OPCUAClient : CollectBase public override Task AfterStopAsync() { _plc?.Disconnect(); - return Task.CompletedTask; + return base.AfterStopAsync(); } protected override string GetAddressDescription() { diff --git a/framework/plugin/ThingsGateway.Plugin.OPCUA/ThingsGateway.Plugin.OPCUA.csproj b/framework/plugin/ThingsGateway.Plugin.OPCUA/ThingsGateway.Plugin.OPCUA.csproj index bef09b497..c4724a308 100644 --- a/framework/plugin/ThingsGateway.Plugin.OPCUA/ThingsGateway.Plugin.OPCUA.csproj +++ b/framework/plugin/ThingsGateway.Plugin.OPCUA/ThingsGateway.Plugin.OPCUA.csproj @@ -54,7 +54,7 @@ - + false false runtime diff --git a/framework/plugin/ThingsGateway.Plugin.Siemens/ThingsGateway.Plugin.Siemens.csproj b/framework/plugin/ThingsGateway.Plugin.Siemens/ThingsGateway.Plugin.Siemens.csproj index 7738eb498..e55934b06 100644 --- a/framework/plugin/ThingsGateway.Plugin.Siemens/ThingsGateway.Plugin.Siemens.csproj +++ b/framework/plugin/ThingsGateway.Plugin.Siemens/ThingsGateway.Plugin.Siemens.csproj @@ -36,7 +36,7 @@ - + false false runtime