mirror of
https://gitee.com/ThingsGateway/ThingsGateway.git
synced 2025-10-22 19:43:07 +08:00
Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
10eecac19b | ||
![]() |
59241b8faa | ||
![]() |
52b3097f04 |
@@ -1,8 +1,8 @@
|
||||
<Project>
|
||||
|
||||
<PropertyGroup>
|
||||
<PluginVersion>10.8.6</PluginVersion>
|
||||
<ProPluginVersion>10.8.6</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>
|
||||
|
@@ -549,7 +549,7 @@ public abstract class DeviceBase : DisposableObject, IDevice
|
||||
Channel.ChannelReceivedWaitDict.TryAdd(sign, ChannelReceived);
|
||||
var sendOperResult = await SendAsync(command, clientChannel, endPoint, cancellationToken).ConfigureAwait(false);
|
||||
if (!sendOperResult.IsSuccess)
|
||||
throw sendOperResult.Exception ?? new(sendOperResult.ErrorMessage);
|
||||
throw sendOperResult.Exception ?? new(sendOperResult.ErrorMessage ?? "unknown error");
|
||||
|
||||
await waitData.WaitAsync(timeout).ConfigureAwait(false);
|
||||
|
||||
|
@@ -0,0 +1,7 @@
|
||||
namespace ThingsGateway.Gateway.Application
|
||||
{
|
||||
public interface IScheduledIntIntervalTask
|
||||
{
|
||||
int IntervalMS { get; }
|
||||
}
|
||||
}
|
@@ -5,10 +5,10 @@ using TouchSocket.Core;
|
||||
|
||||
namespace ThingsGateway.Gateway.Application;
|
||||
|
||||
public class ScheduledAsyncTask : DisposeBase, IScheduledTask
|
||||
public class ScheduledAsyncTask : DisposeBase, IScheduledTask, IScheduledIntIntervalTask
|
||||
{
|
||||
private int _interval10MS = 10;
|
||||
private int _intervalMS;
|
||||
public int IntervalMS { get; }
|
||||
private readonly Func<object?, CancellationToken, Task> _taskFunc;
|
||||
private readonly CancellationToken _token;
|
||||
private TimerX? _timer;
|
||||
@@ -19,7 +19,7 @@ public class ScheduledAsyncTask : DisposeBase, IScheduledTask
|
||||
|
||||
public ScheduledAsyncTask(int interval, Func<object?, CancellationToken, Task> taskFunc, object? state, ILog log, CancellationToken token)
|
||||
{
|
||||
_intervalMS = interval;
|
||||
IntervalMS = interval;
|
||||
LogMessage = log;
|
||||
_state = state;
|
||||
_taskFunc = taskFunc;
|
||||
@@ -30,7 +30,7 @@ public class ScheduledAsyncTask : DisposeBase, IScheduledTask
|
||||
{
|
||||
_timer?.Dispose();
|
||||
if (!_token.IsCancellationRequested)
|
||||
_timer = new TimerX(DoAsync, _state, _intervalMS, _intervalMS, nameof(IScheduledTask)) { Async = true };
|
||||
_timer = new TimerX(DoAsync, _state, IntervalMS, IntervalMS, nameof(IScheduledTask)) { Async = true };
|
||||
}
|
||||
|
||||
private async Task DoAsync(object? state)
|
||||
@@ -78,6 +78,7 @@ public class ScheduledAsyncTask : DisposeBase, IScheduledTask
|
||||
_timer?.SetNext(_interval10MS);
|
||||
}
|
||||
|
||||
|
||||
public void Stop()
|
||||
{
|
||||
_timer?.Dispose();
|
||||
|
@@ -5,10 +5,10 @@ using TouchSocket.Core;
|
||||
|
||||
namespace ThingsGateway.Gateway.Application;
|
||||
|
||||
public class ScheduledSyncTask : DisposeBase, IScheduledTask
|
||||
public class ScheduledSyncTask : DisposeBase, IScheduledTask, IScheduledIntIntervalTask
|
||||
{
|
||||
private int _interval10MS = 10;
|
||||
private int _intervalMS;
|
||||
public int IntervalMS { get; }
|
||||
private readonly Action<object?, CancellationToken> _taskAction;
|
||||
private readonly CancellationToken _token;
|
||||
private TimerX? _timer;
|
||||
@@ -19,7 +19,7 @@ public class ScheduledSyncTask : DisposeBase, IScheduledTask
|
||||
|
||||
public ScheduledSyncTask(int interval, Action<object?, CancellationToken> taskFunc, object? state, ILog log, CancellationToken token)
|
||||
{
|
||||
_intervalMS = interval;
|
||||
IntervalMS = interval;
|
||||
LogMessage = log;
|
||||
_state = state;
|
||||
_taskAction = taskFunc;
|
||||
@@ -30,7 +30,7 @@ public class ScheduledSyncTask : DisposeBase, IScheduledTask
|
||||
{
|
||||
_timer?.Dispose();
|
||||
if (!_token.IsCancellationRequested)
|
||||
_timer = new TimerX(TimerCallback, _state, _intervalMS, _intervalMS, nameof(IScheduledTask)) { Async = true };
|
||||
_timer = new TimerX(TimerCallback, _state, IntervalMS, IntervalMS, nameof(IScheduledTask)) { Async = true };
|
||||
}
|
||||
|
||||
private void TimerCallback(object? state)
|
||||
@@ -82,13 +82,6 @@ public class ScheduledSyncTask : DisposeBase, IScheduledTask
|
||||
_timer?.SetNext(_interval10MS);
|
||||
}
|
||||
|
||||
public void Change(int dueTime, int period)
|
||||
{
|
||||
_intervalMS = period;
|
||||
if (!_token.IsCancellationRequested)
|
||||
_timer?.Change(dueTime, period);
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
{
|
||||
_timer?.Dispose();
|
||||
|
@@ -12,6 +12,7 @@ public class TaskSchedulerLoop
|
||||
{
|
||||
return Tasks.Count;
|
||||
}
|
||||
|
||||
public void Start()
|
||||
{
|
||||
foreach (var task in Tasks)
|
||||
|
@@ -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);
|
||||
}
|
||||
|
@@ -40,12 +40,6 @@ public abstract class CollectPropertyBase : DriverPropertyBase
|
||||
/// </summary>
|
||||
public abstract class CollectPropertyRetryBase : CollectPropertyBase
|
||||
{
|
||||
/// <summary>
|
||||
/// 离线后恢复运行的间隔时间
|
||||
/// </summary>
|
||||
[DynamicProperty]
|
||||
public override int ReIntervalTime { get; set; } = 0;
|
||||
|
||||
/// <summary>
|
||||
/// 失败重试次数,默认3
|
||||
/// </summary>
|
||||
|
@@ -282,7 +282,7 @@ public abstract class DriverBase : DisposableObject, IDriver
|
||||
}
|
||||
|
||||
// 设置设备状态为当前时间
|
||||
CurrentDevice.SetDeviceStatus(TimerX.Now);
|
||||
CurrentDevice.SetDeviceStatus(TimerX.Now, false);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
@@ -298,11 +298,9 @@
|
||||
},
|
||||
"ThingsGateway.Gateway.Application.CollectPropertyBase": {
|
||||
"ConcurrentCount": "ConcurrentCount",
|
||||
"ReIntervalTime": "ReIntervalTime",
|
||||
"RetryCount": "RetryCount"
|
||||
},
|
||||
"ThingsGateway.Gateway.Application.CollectPropertyRetryBase": {
|
||||
"ReIntervalTime": "ReIntervalTime",
|
||||
"RetryCount": "RetryCount"
|
||||
},
|
||||
"ThingsGateway.Gateway.Application.ControlController": {
|
||||
|
@@ -297,11 +297,9 @@
|
||||
},
|
||||
"ThingsGateway.Gateway.Application.CollectPropertyBase": {
|
||||
"ConcurrentCount": "最大并发数量",
|
||||
"ReIntervalTime": "离线恢复时间",
|
||||
"RetryCount": "失败重试次数"
|
||||
},
|
||||
"ThingsGateway.Gateway.Application.CollectPropertyRetryBase": {
|
||||
"ReIntervalTime": "离线恢复时间",
|
||||
"RetryCount": "失败重试次数"
|
||||
},
|
||||
"ThingsGateway.Gateway.Application.ControlController": {
|
||||
|
@@ -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;
|
||||
|
||||
|
@@ -108,17 +108,23 @@ public class OpcUaMaster : CollectBase
|
||||
|
||||
var check = ScheduledTaskHelper.GetTask("3000", CheckAsync, null, LogMessage, cancellationToken);
|
||||
list.Add(check);
|
||||
var checkConnec = ScheduledTaskHelper.GetTask("3000", CheckConnectAsync, null, LogMessage, cancellationToken);
|
||||
var checkConnec = ScheduledTaskHelper.GetTask("10000", CheckConnectAsync, null, LogMessage, cancellationToken);
|
||||
list.Add(checkConnec);
|
||||
return list;
|
||||
}
|
||||
|
||||
protected override async Task ProtectedStartAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
await CheckConnectAsync(null, cancellationToken).ConfigureAwait(false);
|
||||
await base.ProtectedStartAsync(cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
private async Task CheckConnectAsync(object? state, CancellationToken cancellationToken)
|
||||
{
|
||||
if (_plc.Session == null)
|
||||
{
|
||||
try
|
||||
{
|
||||
await Task.Delay(100, cancellationToken).ConfigureAwait(false);
|
||||
if (_plc.Session == null)
|
||||
await _plc.ConnectAsync(cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
@@ -129,13 +135,12 @@ public class OpcUaMaster : CollectBase
|
||||
|
||||
connectFirstFailLoged = true;
|
||||
CurrentDevice.SetDeviceStatus(TimerX.Now, true, ex.Message);
|
||||
await Task.Delay(10000, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
private async Task CheckAsync(object? state, CancellationToken cancellationToken)
|
||||
{
|
||||
if (_plc.Session == null)
|
||||
if (_plc.Session != null)
|
||||
{
|
||||
if (_driverProperties.ActiveSubscribe)
|
||||
{
|
||||
|
@@ -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.6</Version>
|
||||
<Version>10.8.9</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
Reference in New Issue
Block a user