更新OPCUAClient类库
This commit is contained in:
@@ -116,16 +116,16 @@
|
|||||||
|
|
||||||
|
|
||||||
<ItemGroup >
|
<ItemGroup >
|
||||||
<PackageReference Include="ThingsGateway.Foundation.Adapter.DLT645" Version="*" />
|
<!--<PackageReference Include="ThingsGateway.Foundation.Adapter.DLT645" Version="*" />
|
||||||
<PackageReference Include="ThingsGateway.Foundation.Adapter.Modbus" Version="*" />
|
<PackageReference Include="ThingsGateway.Foundation.Adapter.Modbus" Version="*" />
|
||||||
<PackageReference Include="ThingsGateway.Foundation.Adapter.OPCDA" Version="*" />
|
<PackageReference Include="ThingsGateway.Foundation.Adapter.OPCDA" Version="*" />
|
||||||
<PackageReference Include="ThingsGateway.Foundation.Adapter.OPCUA" Version="*" />
|
<PackageReference Include="ThingsGateway.Foundation.Adapter.OPCUA" Version="*" />
|
||||||
<PackageReference Include="ThingsGateway.Foundation.Adapter.Siemens" Version="*" />
|
<PackageReference Include="ThingsGateway.Foundation.Adapter.Siemens" Version="*" />-->
|
||||||
<!--<ProjectReference Include="..\..\Foundation\ThingsGateway.Foundation.Adapter.DLT645\ThingsGateway.Foundation.Adapter.DLT645.csproj" />
|
<ProjectReference Include="..\..\Foundation\ThingsGateway.Foundation.Adapter.DLT645\ThingsGateway.Foundation.Adapter.DLT645.csproj" />
|
||||||
<ProjectReference Include="..\..\Foundation\ThingsGateway.Foundation.Adapter.Modbus\ThingsGateway.Foundation.Adapter.Modbus.csproj" />
|
<ProjectReference Include="..\..\Foundation\ThingsGateway.Foundation.Adapter.Modbus\ThingsGateway.Foundation.Adapter.Modbus.csproj" />
|
||||||
<ProjectReference Include="..\..\Foundation\ThingsGateway.Foundation.Adapter.OPCDA\ThingsGateway.Foundation.Adapter.OPCDA.csproj" />
|
<ProjectReference Include="..\..\Foundation\ThingsGateway.Foundation.Adapter.OPCDA\ThingsGateway.Foundation.Adapter.OPCDA.csproj" />
|
||||||
<ProjectReference Include="..\..\Foundation\ThingsGateway.Foundation.Adapter.OPCUA\ThingsGateway.Foundation.Adapter.OPCUA.csproj" />
|
<ProjectReference Include="..\..\Foundation\ThingsGateway.Foundation.Adapter.OPCUA\ThingsGateway.Foundation.Adapter.OPCUA.csproj" />
|
||||||
<ProjectReference Include="..\..\Foundation\ThingsGateway.Foundation.Adapter.Siemens\ThingsGateway.Foundation.Adapter.Siemens.csproj" />-->
|
<ProjectReference Include="..\..\Foundation\ThingsGateway.Foundation.Adapter.Siemens\ThingsGateway.Foundation.Adapter.Siemens.csproj" />
|
||||||
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup >
|
<ItemGroup >
|
||||||
|
|||||||
@@ -280,7 +280,7 @@ public class OPCUAClient : IDisposable
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
UpdateStatus(true, DateTime.Now, $"初始化{items[i]}变量订阅失败");
|
UpdateStatus(true, DateTime.Now, $"初始化{items[i]}变量订阅失败,错误原因:{ex}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
m_subscription.AddItems(monitoredItems);
|
m_subscription.AddItems(monitoredItems);
|
||||||
@@ -380,7 +380,7 @@ public class OPCUAClient : IDisposable
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
UpdateStatus(true, DateTime.Now, $"{monitoreditem.StartNodeId}订阅处理错误");
|
UpdateStatus(true, DateTime.Now, $"{monitoreditem.StartNodeId}订阅处理错误,错误原因:" + ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -25,12 +25,10 @@ public class OpcUaStatusEventArgs
|
|||||||
/// 是否异常
|
/// 是否异常
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool Error { get; set; }
|
public bool Error { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 时间
|
/// 时间
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public DateTime Time { get; set; }
|
public DateTime Time { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 文本
|
/// 文本
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -42,7 +40,7 @@ public class OpcUaStatusEventArgs
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
return Error ? "[异常]" : "[正常]" + Time.ToString(" yyyy-MM-dd HH:mm:ss ") + Text;
|
return $"{(Error ? "[异常]" : "[正常]")}{Time.ToString("yyyy-MM-dd HH:mm:ss zz")}{Text}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -177,6 +177,8 @@ public class OPCUAClient : CollectBase
|
|||||||
if (_plc != null)
|
if (_plc != null)
|
||||||
{
|
{
|
||||||
_plc.DataChangedHandler -= DataChangedHandler;
|
_plc.DataChangedHandler -= DataChangedHandler;
|
||||||
|
_plc.OpcStatusChange -= _plc_OpcStatusChange;
|
||||||
|
|
||||||
_plc.Disconnect();
|
_plc.Disconnect();
|
||||||
_plc.SafeDispose();
|
_plc.SafeDispose();
|
||||||
_plc = null;
|
_plc = null;
|
||||||
@@ -204,13 +206,19 @@ public class OPCUAClient : CollectBase
|
|||||||
};
|
};
|
||||||
if (_plc == null)
|
if (_plc == null)
|
||||||
{
|
{
|
||||||
_plc = new((arg1, arg2, arg3, arg4) => Log_Out((LogLevel)arg1, arg2, arg3, arg4));
|
_plc = new();
|
||||||
|
_plc.OpcStatusChange += _plc_OpcStatusChange;
|
||||||
_plc.DataChangedHandler += DataChangedHandler;
|
_plc.DataChangedHandler += DataChangedHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
_plc.OPCNode = opcNode;
|
_plc.OPCNode = opcNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void _plc_OpcStatusChange(object sender, OpcUaStatusEventArgs e)
|
||||||
|
{
|
||||||
|
Log_Out(e.Error ? LogLevel.Warning : LogLevel.Info, null, e.Text, null);
|
||||||
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
protected override Task<OperResult<byte[]>> ReadAsync(string address, int length, CancellationToken cancellationToken)
|
protected override Task<OperResult<byte[]>> ReadAsync(string address, int length, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -36,16 +36,23 @@ public partial class OPCUAClientPage
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
|
OPC.OpcStatusChange -= OPC_OpcStatusChange;
|
||||||
OPC.SafeDispose();
|
OPC.SafeDispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
protected override void OnInitialized()
|
protected override void OnInitialized()
|
||||||
{
|
{
|
||||||
OPC = new ThingsGateway.Foundation.Adapter.OPCUA.OPCUAClient(LogOut);
|
OPC = new ThingsGateway.Foundation.Adapter.OPCUA.OPCUAClient();
|
||||||
|
OPC.OpcStatusChange += OPC_OpcStatusChange;
|
||||||
base.OnInitialized();
|
base.OnInitialized();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OPC_OpcStatusChange(object sender, OpcUaStatusEventArgs e)
|
||||||
|
{
|
||||||
|
LogAction?.Invoke(e.Error ? LogLevel.Warning : LogLevel.Info, null, e.Text, null);
|
||||||
|
}
|
||||||
|
|
||||||
private async Task ConnectAsync()
|
private async Task ConnectAsync()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@@ -75,6 +82,4 @@ public partial class OPCUAClientPage
|
|||||||
return OPC;
|
return OPC;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void LogOut(byte logLevel, object source, string message, Exception exception) => LogAction?.Invoke((LogLevel)logLevel, source, message, exception);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user