mirror of
https://gitee.com/ThingsGateway/ThingsGateway.git
synced 2025-11-05 10:03:58 +08:00
调整非主从协议的状态判断策略;OPCUA去除主动连接
This commit is contained in:
@@ -433,11 +433,11 @@ public class CollectDeviceCore
|
||||
if (_driver.IsConnected())
|
||||
{
|
||||
//更新设备活动时间
|
||||
Device.SetDeviceStatus(SysDateTimeExtensions.CurrentDateTime, 0);
|
||||
Device.SetDeviceStatus(SysDateTimeExtensions.CurrentDateTime, errorCount: 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
Device.SetDeviceStatus(SysDateTimeExtensions.CurrentDateTime, 999);
|
||||
Device.SetDeviceStatus(errorCount: 999);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -69,7 +69,10 @@ public class OPCUAClient : DisposableObject
|
||||
private readonly ApplicationInstance m_application = new();
|
||||
|
||||
private readonly ApplicationConfiguration m_configuration;
|
||||
|
||||
/// <summary>
|
||||
/// SessionReconnectHandler
|
||||
/// </summary>
|
||||
public SessionReconnectHandler ReConnectHandler => m_reConnectHandler;
|
||||
private SessionReconnectHandler m_reConnectHandler;
|
||||
private ISession m_session;
|
||||
/// <summary>
|
||||
|
||||
@@ -286,6 +286,11 @@
|
||||
当前的订阅组,组名称/组
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:ThingsGateway.Foundation.Adapter.OPCUA.OPCUAClient.ReConnectHandler">
|
||||
<summary>
|
||||
SessionReconnectHandler
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:ThingsGateway.Foundation.Adapter.OPCUA.OPCUAClient.#ctor(TouchSocket.Core.ILog)">
|
||||
<summary>
|
||||
默认的构造函数,实例化一个新的OPC UA类
|
||||
|
||||
@@ -72,7 +72,12 @@ public class OPCDAClient : CollectBase
|
||||
{
|
||||
}
|
||||
/// <inheritdoc/>
|
||||
public override bool IsConnected() => _plc?.IsConnected == true;
|
||||
public override bool IsConnected()
|
||||
{
|
||||
Device.SetDeviceStatus(SysDateTimeExtensions.CurrentDateTime);
|
||||
return _plc?.IsConnected == true;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override List<DeviceVariableSourceRead> LoadSourceRead(List<DeviceVariableRunTime> deviceVariables)
|
||||
{
|
||||
|
||||
@@ -22,6 +22,7 @@ using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using ThingsGateway.Admin.Core;
|
||||
using ThingsGateway.Application;
|
||||
using ThingsGateway.Foundation;
|
||||
using ThingsGateway.Foundation.Adapter.OPCUA;
|
||||
@@ -38,18 +39,10 @@ public class OPCUAClient : CollectBase
|
||||
{
|
||||
internal Foundation.Adapter.OPCUA.OPCUAClient _plc = null;
|
||||
internal CollectDeviceRunTime Device;
|
||||
readonly PeriodicTimer _periodicTimer = new(TimeSpan.FromSeconds(60));
|
||||
private readonly OPCUAClientProperty driverPropertys = new();
|
||||
|
||||
private List<DeviceVariableRunTime> _deviceVariables = new();
|
||||
|
||||
/// <summary>
|
||||
/// OPCUA客户端
|
||||
/// </summary>
|
||||
public OPCUAClient()
|
||||
{
|
||||
_ = RunTimerAsync();
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override Type DriverDebugUIType => typeof(OPCUAClientDebugDriverPage);
|
||||
@@ -87,8 +80,11 @@ public class OPCUAClient : CollectBase
|
||||
/// <inheritdoc/>
|
||||
public override bool IsConnected()
|
||||
{
|
||||
|
||||
return _plc.Connected;
|
||||
if (_plc.Session != null)
|
||||
{
|
||||
Device.SetDeviceStatus(SysDateTimeExtensions.CurrentDateTime);
|
||||
}
|
||||
return _plc?.Connected == true;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
@@ -184,7 +180,6 @@ public class OPCUAClient : CollectBase
|
||||
/// <inheritdoc/>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
_periodicTimer?.Dispose();
|
||||
if (_plc != null)
|
||||
{
|
||||
_plc.DataChangedHandler -= DataChangedHandler;
|
||||
@@ -291,22 +286,4 @@ public class OPCUAClient : CollectBase
|
||||
}
|
||||
}
|
||||
|
||||
private async Task RunTimerAsync()
|
||||
{
|
||||
while (await _periodicTimer.WaitForNextTickAsync())
|
||||
{
|
||||
if (_plc != null && _plc.Session == null)
|
||||
{
|
||||
try
|
||||
{
|
||||
await _plc.ConnectAsync();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogMessage.Exception(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,11 +33,6 @@
|
||||
OPCUA客户端
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:ThingsGateway.OPCUA.OPCUAClient.#ctor">
|
||||
<summary>
|
||||
OPCUA客户端
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:ThingsGateway.OPCUA.OPCUAClient.DriverDebugUIType">
|
||||
<inheritdoc/>
|
||||
</member>
|
||||
|
||||
Reference in New Issue
Block a user