添加查找当前节点下的所有变量功能
This commit is contained in:
@@ -12,6 +12,7 @@ using Opc.Ua;
|
|||||||
using Opc.Ua.Client;
|
using Opc.Ua.Client;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
|
using static Dm.net.buffer.ByteArrayBuffer;
|
||||||
|
|
||||||
namespace DMS.WPF.ViewModels.Dialogs;
|
namespace DMS.WPF.ViewModels.Dialogs;
|
||||||
|
|
||||||
@@ -40,6 +41,9 @@ public partial class ImportOpcUaDialogViewModel : DialogViewModelBase<List<Varia
|
|||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
private bool _isConnectButtonEnabled = true;
|
private bool _isConnectButtonEnabled = true;
|
||||||
|
|
||||||
|
[ObservableProperty]
|
||||||
|
private OpcUaNodeItemViewModel _currentOpcUaNodeItem;
|
||||||
|
|
||||||
private Session _session;
|
private Session _session;
|
||||||
|
|
||||||
private readonly IOpcUaService _opcUaService;
|
private readonly IOpcUaService _opcUaService;
|
||||||
@@ -137,7 +141,17 @@ public partial class ImportOpcUaDialogViewModel : DialogViewModelBase<List<Varia
|
|||||||
// 加载节点的子项
|
// 加载节点的子项
|
||||||
node.IsExpanded = true;
|
node.IsExpanded = true;
|
||||||
node.IsSelected = true;
|
node.IsSelected = true;
|
||||||
|
CurrentOpcUaNodeItem = node;
|
||||||
|
await Browse(node);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
NotificationHelper.ShowError($"加载 OPC UA 节点变量失败: {node.NodeId} - {ex.Message}", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task Browse(OpcUaNodeItemViewModel node, bool isScan = false)
|
||||||
|
{
|
||||||
var childrens = await _opcUaService.BrowseNode(_mapper.Map<OpcUaNode>(node));
|
var childrens = await _opcUaService.BrowseNode(_mapper.Map<OpcUaNode>(node));
|
||||||
foreach (var children in childrens)
|
foreach (var children in childrens)
|
||||||
{
|
{
|
||||||
@@ -154,17 +168,42 @@ public partial class ImportOpcUaDialogViewModel : DialogViewModelBase<List<Varia
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
if (node.Children.FirstOrDefault(n => n.NodeId == opcNodeItem.NodeId) == null)
|
||||||
{
|
{
|
||||||
node.Children.Add(opcNodeItem);
|
node.Children.Add(opcNodeItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isScan)
|
||||||
|
{
|
||||||
|
Browse(opcNodeItem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[RelayCommand]
|
||||||
|
private async Task FindCurrentNodeVariables()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (CurrentOpcUaNodeItem == null)
|
||||||
|
{
|
||||||
|
NotificationHelper.ShowError($"请先选择左边的节点,然后再查找变量。");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
OpcUaNodeVariables.Clear();
|
||||||
|
|
||||||
|
// 加载节点的子项
|
||||||
|
CurrentOpcUaNodeItem.IsExpanded = true;
|
||||||
|
CurrentOpcUaNodeItem.IsSelected = true;
|
||||||
|
|
||||||
|
await Browse(CurrentOpcUaNodeItem, true);
|
||||||
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
NlogHelper.Error($"加载 OPC UA 节点变量失败: {node.NodeId} - {ex.Message}", ex);
|
NotificationHelper.ShowError($"加载 OPC UA 节点变量失败: {CurrentOpcUaNodeItem.NodeId} - {ex.Message}", ex);
|
||||||
NotificationHelper.ShowError($"加载 OPC UA 节点变量失败: {node.NodeId} - {ex.Message}", ex);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -47,6 +47,22 @@
|
|||||||
Content="{Binding ConnectButtonText}"
|
Content="{Binding ConnectButtonText}"
|
||||||
IsEnabled="{Binding IsConnectButtonEnabled}"
|
IsEnabled="{Binding IsConnectButtonEnabled}"
|
||||||
Style="{StaticResource AccentButtonStyle}" />
|
Style="{StaticResource AccentButtonStyle}" />
|
||||||
|
<Button
|
||||||
|
x:Name="FindVariablesButton"
|
||||||
|
Margin="10,0,0,0"
|
||||||
|
Command="{Binding FindCurrentNodeVariablesCommand}"
|
||||||
|
Content="查找当前节点下的所有变量">
|
||||||
|
<Button.Style>
|
||||||
|
<Style BasedOn="{StaticResource {x:Type Button}}" TargetType="Button">
|
||||||
|
<Setter Property="Visibility" Value="Collapsed" />
|
||||||
|
<Style.Triggers>
|
||||||
|
<DataTrigger Binding="{Binding IsConnected}" Value="True">
|
||||||
|
<Setter Property="Visibility" Value="Visible" />
|
||||||
|
</DataTrigger>
|
||||||
|
</Style.Triggers>
|
||||||
|
</Style>
|
||||||
|
</Button.Style>
|
||||||
|
</Button>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
|
|
||||||
<!-- 节点树 -->
|
<!-- 节点树 -->
|
||||||
|
|||||||
Reference in New Issue
Block a user