修改OPCUAClient的心跳频率配置项

This commit is contained in:
Kimdiego2098
2023-07-18 08:48:18 +08:00
parent f9b566984b
commit a4c91bb268
7 changed files with 11 additions and 19 deletions

View File

@@ -18,7 +18,7 @@ public class OPCNode
public bool ActiveSubscribe { get; set; } = true;
public int GroupSize { get; set; } = 500;
public double DeadBand { get; set; } = 0;
public int ReconnectPeriod { get; set; } = 5000;
public int KeepAliveInterval { get; set; } = 60000;
public bool IsUseSecurity { get; set; } = true;
public override string ToString()

View File

@@ -479,7 +479,6 @@ public class OPCUAClient : DisposableObject
/// </summary>
public void Disconnect()
{
UpdateStatus(false, DateTime.UtcNow, "断开连接");
// stop any reconnect operation.
if (m_reConnectHandler != null)
@@ -491,6 +490,7 @@ public class OPCUAClient : DisposableObject
// disconnect any existing session.
if (m_session != null)
{
UpdateStatus(false, DateTime.UtcNow, "断开连接");
m_session.Close(10000);
m_session = null;
}
@@ -910,7 +910,9 @@ public class OPCUAClient : DisposableObject
UserIdentity,
new string[] { });
UpdateStatus(false, DateTime.UtcNow, "连接成功");
m_session.KeepAliveInterval = OPCNode.KeepAliveInterval == 0 ? 60000 : OPCNode.KeepAliveInterval;
m_session.KeepAlive += new KeepAliveEventHandler(Session_KeepAlive);
m_IsConnected = true;
@@ -1041,19 +1043,15 @@ public class OPCUAClient : DisposableObject
if (ServiceResult.IsBad(e.Status))
{
if (OPCNode?.ReconnectPeriod <= 0)
{
OPCNode.ReconnectPeriod = 5000;
}
UpdateStatus(true, e.CurrentTime, "心跳检测错误:{0},重新连接中", e.Status.ToString());
// 上次重连未完成前不会再重试
if (m_reConnectHandler == null)
{
m_ReconnectStarting?.Invoke(this, e);
m_reConnectHandler = new SessionReconnectHandler();
m_reConnectHandler.BeginReconnect(m_session, (OPCNode?.ReconnectPeriod ?? 5000), Server_ReconnectComplete);
m_reConnectHandler.BeginReconnect(m_session, m_session.KeepAliveInterval, Server_ReconnectComplete);
}
return;

View File

@@ -49,7 +49,7 @@ namespace ThingsGateway.OPCUA
data.DevicePropertys.Add(new() { PropertyName = nameof(OPCUAClientProperty.DeadBand), Value = PLC.OPCNode.DeadBand.ToString(), Description = typeof(OPCUAClientProperty).GetProperty(nameof(OPCUAClientProperty.DeadBand)).GetCustomAttribute<DevicePropertyAttribute>().Description });
data.DevicePropertys.Add(new() { PropertyName = nameof(OPCUAClientProperty.GroupSize), Value = PLC.OPCNode.GroupSize.ToString(), Description = typeof(OPCUAClientProperty).GetProperty(nameof(OPCUAClientProperty.GroupSize)).GetCustomAttribute<DevicePropertyAttribute>().Description });
data.DevicePropertys.Add(new() { PropertyName = nameof(OPCUAClientProperty.UpdateRate), Value = PLC.OPCNode.UpdateRate.ToString(), Description = typeof(OPCUAClientProperty).GetProperty(nameof(OPCUAClientProperty.UpdateRate)).GetCustomAttribute<DevicePropertyAttribute>().Description });
data.DevicePropertys.Add(new() { PropertyName = nameof(OPCUAClientProperty.ReconnectPeriod), Value = PLC.OPCNode.ReconnectPeriod.ToString(), Description = typeof(OPCUAClientProperty).GetProperty(nameof(OPCUAClientProperty.ReconnectPeriod)).GetCustomAttribute<DevicePropertyAttribute>().Description });
data.DevicePropertys.Add(new() { PropertyName = nameof(OPCUAClientProperty.KeepAliveInterval), Value = PLC.OPCNode.KeepAliveInterval.ToString(), Description = typeof(OPCUAClientProperty).GetProperty(nameof(OPCUAClientProperty.KeepAliveInterval)).GetCustomAttribute<DevicePropertyAttribute>().Description });
return data;
}

View File

@@ -183,7 +183,7 @@ public class OPCUAClient : CollectBase
oPCNode.UpdateRate = driverPropertys.UpdateRate;
oPCNode.DeadBand = driverPropertys.DeadBand;
oPCNode.GroupSize = driverPropertys.GroupSize;
oPCNode.ReconnectPeriod = driverPropertys.ReconnectPeriod;
oPCNode.KeepAliveInterval = driverPropertys.KeepAliveInterval;
oPCNode.IsUseSecurity = driverPropertys.IsUseSecurity;
oPCNode.ActiveSubscribe = driverPropertys.ActiveSubscribe;

View File

@@ -13,7 +13,6 @@
using Newtonsoft.Json.Linq;
using Opc.Ua;
using Opc.Ua.Client;
using ThingsGateway.Core;
@@ -140,11 +139,6 @@ namespace ThingsGateway.OPCUA
}
}
private void callback(string arg1, MonitoredItem arg2, MonitoredItemNotificationEventArgs arg3)
{
}
private async Task DownDeviceExport()
{
var data = await importVariable?.GetImportVariableList();

View File

@@ -31,7 +31,7 @@
<MTextField Class="mx-1 my-1" Label=@node.Description(a=>a.UpdateRate) Dense Outlined HideDetails="@("auto")" @bind-Value=@node.UpdateRate />
<MTextField Class="mx-1 my-1" Label=@node.Description(a=>a.DeadBand) Dense Outlined HideDetails="@("auto")" @bind-Value=@node.DeadBand />
<MTextField Class="mx-1 my-1" Label=@node.Description(a=>a.ReconnectPeriod) Dense Outlined HideDetails="@("auto")" @bind-Value=@node.ReconnectPeriod />
<MTextField Class="mx-1 my-1" Label=@node.Description(a=>a.KeepAliveInterval) Dense Outlined HideDetails="@("auto")" @bind-Value=@node.KeepAliveInterval />
</MRow>
<MRow Justify="JustifyTypes.SpaceBetween" Align="AlignTypes.Center">
<MCheckbox Class="mx-1 my-1" Label=@node.Description(a=>a.IsUseSecurity) Dense HideDetails="@("auto")" @bind-Value=@node.IsUseSecurity />

View File

@@ -63,9 +63,9 @@ public class OPCUAClientProperty : CollectDriverPropertyBase
/// <summary>
/// 重连频率
/// 心跳频率
/// </summary>
[DeviceProperty("重连频率", "")] public int ReconnectPeriod { get; set; } = 5000;
[DeviceProperty("心跳频率", "")] public int KeepAliveInterval { get; set; } = 60000;
public override bool IsShareChannel { get; set; } = false;
public override ShareChannelEnum ShareChannel => ShareChannelEnum.None;