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