mirror of
https://gitee.com/ThingsGateway/ThingsGateway.git
synced 2025-10-20 10:50:48 +08:00
fix: opcua连接状态
This commit is contained in:
@@ -1,9 +1,9 @@
|
|||||||
<Project>
|
<Project>
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<PluginVersion>10.11.67</PluginVersion>
|
<PluginVersion>10.11.68</PluginVersion>
|
||||||
<ProPluginVersion>10.11.67</ProPluginVersion>
|
<ProPluginVersion>10.11.68</ProPluginVersion>
|
||||||
<DefaultVersion>10.11.67</DefaultVersion>
|
<DefaultVersion>10.11.68</DefaultVersion>
|
||||||
<AuthenticationVersion>10.11.6</AuthenticationVersion>
|
<AuthenticationVersion>10.11.6</AuthenticationVersion>
|
||||||
<SourceGeneratorVersion>10.11.6</SourceGeneratorVersion>
|
<SourceGeneratorVersion>10.11.6</SourceGeneratorVersion>
|
||||||
<NET8Version>8.0.20</NET8Version>
|
<NET8Version>8.0.20</NET8Version>
|
||||||
|
@@ -212,10 +212,13 @@ public class OpcUaMaster : IAsyncDisposable
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public ApplicationConfiguration AppConfig => m_configuration;
|
public ApplicationConfiguration AppConfig => m_configuration;
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 连接状态
|
/// 连接状态
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool Connected => m_session?.Connected == true;
|
public bool Connected => m_session?.Connected == true && connected;
|
||||||
|
|
||||||
|
private bool connected = false;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// OpcUaMaster
|
/// OpcUaMaster
|
||||||
@@ -403,11 +406,7 @@ public class OpcUaMaster : IAsyncDisposable
|
|||||||
public async Task DisconnectAsync()
|
public async Task DisconnectAsync()
|
||||||
{
|
{
|
||||||
await PrivateDisconnectAsync().ConfigureAwait(false);
|
await PrivateDisconnectAsync().ConfigureAwait(false);
|
||||||
// disconnect any existing session.
|
|
||||||
if (m_session != null)
|
|
||||||
{
|
|
||||||
m_session = null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async ValueTask DisposeAsync()
|
public async ValueTask DisposeAsync()
|
||||||
@@ -937,6 +936,7 @@ public class OpcUaMaster : IAsyncDisposable
|
|||||||
userIdentity,
|
userIdentity,
|
||||||
null, cancellationToken
|
null, cancellationToken
|
||||||
).ConfigureAwait(false);
|
).ConfigureAwait(false);
|
||||||
|
connected = true;
|
||||||
|
|
||||||
m_session.KeepAliveInterval = OpcUaProperty.KeepAliveInterval == 0 ? 60000 : OpcUaProperty.KeepAliveInterval;
|
m_session.KeepAliveInterval = OpcUaProperty.KeepAliveInterval == 0 ? 60000 : OpcUaProperty.KeepAliveInterval;
|
||||||
m_session.KeepAlive += Session_KeepAlive;
|
m_session.KeepAlive += Session_KeepAlive;
|
||||||
@@ -958,6 +958,7 @@ public class OpcUaMaster : IAsyncDisposable
|
|||||||
{
|
{
|
||||||
bool state = m_session?.Connected == true;
|
bool state = m_session?.Connected == true;
|
||||||
|
|
||||||
|
connected = false;
|
||||||
if (m_reConnectHandler != null)
|
if (m_reConnectHandler != null)
|
||||||
{
|
{
|
||||||
try { m_reConnectHandler.Dispose(); } catch { }
|
try { m_reConnectHandler.Dispose(); } catch { }
|
||||||
@@ -1353,6 +1354,8 @@ public class OpcUaMaster : IAsyncDisposable
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
Log(2, null, "Reconnected : success");
|
||||||
|
|
||||||
if (!Object.ReferenceEquals(sender, m_reConnectHandler))
|
if (!Object.ReferenceEquals(sender, m_reConnectHandler))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
@@ -1366,6 +1369,8 @@ public class OpcUaMaster : IAsyncDisposable
|
|||||||
{
|
{
|
||||||
var session = m_session;
|
var session = m_session;
|
||||||
m_session = m_reConnectHandler.Session;
|
m_session = m_reConnectHandler.Session;
|
||||||
|
connected = true;
|
||||||
|
|
||||||
Utils.SilentDispose(session);
|
Utils.SilentDispose(session);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1393,6 +1398,8 @@ public class OpcUaMaster : IAsyncDisposable
|
|||||||
|
|
||||||
if (ServiceResult.IsBad(e.Status))
|
if (ServiceResult.IsBad(e.Status))
|
||||||
{
|
{
|
||||||
|
connected = false;
|
||||||
|
|
||||||
if (m_reConnectHandler == null)
|
if (m_reConnectHandler == null)
|
||||||
{
|
{
|
||||||
Log(3, null, "Reconnecting : {0}", e.Status.ToString());
|
Log(3, null, "Reconnecting : {0}", e.Status.ToString());
|
||||||
|
Reference in New Issue
Block a user