mirror of
https://gitee.com/ThingsGateway/ThingsGateway.git
synced 2025-10-20 10:50:48 +08:00
feat: 优化设备状态逻辑
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
<Project>
|
||||
|
||||
<PropertyGroup>
|
||||
<PluginVersion>10.8.8</PluginVersion>
|
||||
<ProPluginVersion>10.8.8</ProPluginVersion>
|
||||
<PluginVersion>10.8.9</PluginVersion>
|
||||
<ProPluginVersion>10.8.9</ProPluginVersion>
|
||||
<AuthenticationVersion>2.8.0</AuthenticationVersion>
|
||||
<SourceGeneratorVersion>10.8.2</SourceGeneratorVersion>
|
||||
<NET8Version>8.0.17</NET8Version>
|
||||
|
@@ -213,7 +213,19 @@ public abstract class CollectBase : DriverBase, IRpcDriver
|
||||
{
|
||||
if (IsConnected())
|
||||
{
|
||||
CurrentDevice.SetDeviceStatus(TimerX.Now);
|
||||
if (CurrentDevice.DeviceStatus == DeviceStatusEnum.OffLine)
|
||||
{
|
||||
if (IdVariableRuntimes.Any(a => a.Value.IsOnline))
|
||||
CurrentDevice.SetDeviceStatus(TimerX.Now, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
CurrentDevice.SetDeviceStatus(TimerX.Now);
|
||||
}
|
||||
}
|
||||
else if (IsStarted)
|
||||
{
|
||||
CurrentDevice.SetDeviceStatus(TimerX.Now, true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -258,7 +270,7 @@ public abstract class CollectBase : DriverBase, IRpcDriver
|
||||
// 方法调用成功时记录日志并增加成功计数器
|
||||
if (LogMessage?.LogLevel <= TouchSocket.Core.LogLevel.Trace)
|
||||
LogMessage?.Trace(string.Format("{0} - Execute method [{1}] - Succeeded {2}", DeviceName, readVariableMethods.MethodInfo.Name, readResult.Content?.ToSystemTextJsonString()));
|
||||
CurrentDevice.SetDeviceStatus(TimerX.Now, false);
|
||||
CurrentDevice.SetDeviceStatus(TimerX.Now, null);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -281,7 +293,7 @@ public abstract class CollectBase : DriverBase, IRpcDriver
|
||||
}
|
||||
|
||||
readVariableMethods.LastErrorMessage = readResult.ErrorMessage;
|
||||
CurrentDevice.SetDeviceStatus(TimerX.Now, false);
|
||||
CurrentDevice.SetDeviceStatus(TimerX.Now, null);
|
||||
}
|
||||
|
||||
return;
|
||||
@@ -329,7 +341,7 @@ public abstract class CollectBase : DriverBase, IRpcDriver
|
||||
// 读取成功时记录日志并增加成功计数器
|
||||
if (LogMessage?.LogLevel <= TouchSocket.Core.LogLevel.Trace)
|
||||
LogMessage?.Trace(string.Format("{0} - Collection [{1} - {2}] data succeeded {3}", DeviceName, variableSourceRead?.RegisterAddress, variableSourceRead?.Length, readResult.Content?.ToHexString(' ')));
|
||||
CurrentDevice.SetDeviceStatus(TimerX.Now, false);
|
||||
CurrentDevice.SetDeviceStatus(TimerX.Now, null);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -352,7 +364,7 @@ public abstract class CollectBase : DriverBase, IRpcDriver
|
||||
}
|
||||
|
||||
variableSourceRead.LastErrorMessage = readResult.ErrorMessage;
|
||||
CurrentDevice.SetDeviceStatus(TimerX.Now, true, readResult.ErrorMessage);
|
||||
CurrentDevice.SetDeviceStatus(TimerX.Now, null, readResult.ErrorMessage);
|
||||
var time = DateTime.Now;
|
||||
variableSourceRead.VariableRuntimes.ForEach(a => a.SetValue(null, time, isOnline: false));
|
||||
}
|
||||
|
@@ -100,7 +100,7 @@ public abstract class CollectFoundationBase : CollectBase
|
||||
LogMessage?.LogWarning(exception, string.Format(AppResource.CollectFail, DeviceName, item?.RegisterAddress, item?.Length, exception.Message));
|
||||
}
|
||||
item.LastErrorMessage = exception.Message;
|
||||
CurrentDevice.SetDeviceStatus(TimerX.Now, true, exception.Message);
|
||||
CurrentDevice.SetDeviceStatus(TimerX.Now, null, exception.Message);
|
||||
var time = DateTime.Now;
|
||||
item.VariableRuntimes.ForEach(a => a.SetValue(null, time, isOnline: false));
|
||||
}
|
||||
@@ -112,7 +112,7 @@ public abstract class CollectFoundationBase : CollectBase
|
||||
LogMessage?.LogWarning(exception, string.Format(AppResource.MethodFail, DeviceName, item.MethodInfo.Name, exception.Message));
|
||||
}
|
||||
item.LastErrorMessage = exception.Message;
|
||||
CurrentDevice.SetDeviceStatus(TimerX.Now, true, exception.Message);
|
||||
CurrentDevice.SetDeviceStatus(TimerX.Now, null, exception.Message);
|
||||
var time = DateTime.Now;
|
||||
item.Variable.SetValue(null, time, isOnline: false);
|
||||
}
|
||||
|
@@ -282,7 +282,7 @@ public abstract class DriverBase : DisposableObject, IDriver
|
||||
}
|
||||
|
||||
// 设置设备状态为当前时间
|
||||
CurrentDevice.SetDeviceStatus(TimerX.Now);
|
||||
CurrentDevice.SetDeviceStatus(TimerX.Now, false);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
@@ -153,14 +153,8 @@ public class ModbusSlave : BusinessBase
|
||||
protected override async Task ProtectedExecuteAsync(object? state, CancellationToken cancellationToken)
|
||||
{
|
||||
//获取设备连接状态
|
||||
if (IsConnected())
|
||||
if (!IsConnected())
|
||||
{
|
||||
//更新设备活动时间
|
||||
CurrentDevice.SetDeviceStatus(TimerX.Now, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
CurrentDevice.SetDeviceStatus(TimerX.Now, true);
|
||||
try
|
||||
{
|
||||
if (cancellationToken.IsCancellationRequested)
|
||||
|
@@ -287,17 +287,6 @@ public partial class MqttCollect : CollectBase
|
||||
await Task.Delay(10000, cancellationToken).ConfigureAwait(false);
|
||||
//return;
|
||||
}
|
||||
//获取设备连接状态
|
||||
if (IsConnected())
|
||||
{
|
||||
//更新设备活动时间
|
||||
CurrentDevice.SetDeviceStatus(TimerX.Now, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
CurrentDevice.SetDeviceStatus(TimerX.Now, true);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@@ -14,6 +14,7 @@ using ThingsGateway.Foundation.OpcDa;
|
||||
using ThingsGateway.Foundation.OpcDa.Da;
|
||||
using ThingsGateway.Gateway.Application;
|
||||
using ThingsGateway.NewLife.Json.Extension;
|
||||
using ThingsGateway.NewLife.Threading;
|
||||
|
||||
using TouchSocket.Core;
|
||||
|
||||
|
@@ -157,14 +157,8 @@ public partial class OpcUaServer : BusinessBase
|
||||
{
|
||||
try
|
||||
{
|
||||
if (IsConnected())
|
||||
if (!IsConnected())
|
||||
{
|
||||
//更新设备活动时间
|
||||
CurrentDevice.SetDeviceStatus(TimerX.Now, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
CurrentDevice.SetDeviceStatus(TimerX.Now, true);
|
||||
try
|
||||
{
|
||||
await Task.Delay(3000, cancellationToken).ConfigureAwait(false);
|
||||
|
@@ -261,9 +261,9 @@ public partial class OpcUaImportVariable
|
||||
await ToastService.Warning(OpcUaPropertyLocalizer["NoVariablesAvailable"], OpcUaPropertyLocalizer["NoVariablesAvailable"]);
|
||||
return;
|
||||
}
|
||||
await App.RootServices.GetRequiredService<IChannelRuntimeService>().SaveChannelAsync(data.Item1, ItemChangedType.Add, false);
|
||||
await App.RootServices.GetRequiredService<IDeviceRuntimeService>().SaveDeviceAsync(data.Item2, ItemChangedType.Add, false);
|
||||
await App.RootServices.GetRequiredService<IVariableRuntimeService>().BatchSaveVariableAsync(data.Item3.ToList(), ItemChangedType.Add, false, default);
|
||||
await App.RootServices.GetRequiredService<IChannelRuntimeService>().SaveChannelAsync(data.Item1, ItemChangedType.Add, true);
|
||||
await App.RootServices.GetRequiredService<IDeviceRuntimeService>().SaveDeviceAsync(data.Item2, ItemChangedType.Add, true);
|
||||
await App.RootServices.GetRequiredService<IVariableRuntimeService>().BatchSaveVariableAsync(data.Item3.ToList(), ItemChangedType.Add, true, default);
|
||||
await ToastService.Default();
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
@@ -1,6 +1,6 @@
|
||||
<Project>
|
||||
<PropertyGroup>
|
||||
<Version>10.8.8</Version>
|
||||
<Version>10.8.9</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
Reference in New Issue
Block a user