|
|
@@ -5,7 +5,9 @@ using System;
|
|
|
using System.Collections.Concurrent;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Collections.ObjectModel;
|
|
|
+using System.Diagnostics;
|
|
|
using System.IO;
|
|
|
+using System.Linq;
|
|
|
using System.Threading.Tasks;
|
|
|
using System.Windows;
|
|
|
using System.Windows.Controls;
|
|
|
@@ -405,7 +407,37 @@ namespace YSAI.Tool.Core.opc.ua.client
|
|
|
//信息输出
|
|
|
MessageOut($"{reverseBack.Message},用时:{reverseBack.RunTime} ms");
|
|
|
}
|
|
|
+ List<NodeJsonStructuralBody> nodes;
|
|
|
+ private void ec(NodeJsonStructuralBody node)
|
|
|
+ {
|
|
|
+ if (nodes == null)
|
|
|
+ {
|
|
|
+ nodes = new List<NodeJsonStructuralBody>();
|
|
|
+ }
|
|
|
+ if (node.Nodes != null)
|
|
|
+ {
|
|
|
+ foreach (var item in node.Nodes)
|
|
|
+ {
|
|
|
+ if (item.Nodes != null)
|
|
|
+ {
|
|
|
+ foreach (var no in item.Nodes)
|
|
|
+ {
|
|
|
+ ec(no);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ nodes.Add(item);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ nodes.Add(node);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// 导出节点
|
|
|
/// </summary>
|
|
|
@@ -431,7 +463,25 @@ namespace YSAI.Tool.Core.opc.ua.client
|
|
|
//当有空数据时不做解析,且进行缩进处理
|
|
|
string Json = JsonConvert.SerializeObject(nodeStructuralBody, Newtonsoft.Json.Formatting.None, JsonSetting);
|
|
|
//写入文件
|
|
|
- FileTool.StringToFile(Path, Json);
|
|
|
+ FileTool.StringToFile(Path, Json.JsonFormatting());
|
|
|
+
|
|
|
+ ec(nodeStructuralBody);//, str + $"\\[{nodeStructuralBody.Name}]Node_Address {DateTime.Now.ToString("yyyyMMddHHmmssffff")}.json");
|
|
|
+
|
|
|
+ Address address = new Address();
|
|
|
+ address.AddressArray = new List<AddressDetails>();
|
|
|
+ foreach (var item in nodes)
|
|
|
+ {
|
|
|
+ address.AddressArray.Add(new AddressDetails
|
|
|
+ {
|
|
|
+ AddressName = item.Address,
|
|
|
+ AddressDescribe = item.Description,
|
|
|
+ AddressDataType = opcUaOperate.TypeConvert((BuiltInType)Enum.Parse(typeof(BuiltInType), item.DataType))
|
|
|
+ });
|
|
|
+ }
|
|
|
+ Path = str + $"\\[{nodeStructuralBody.Name}]Node_Address {DateTime.Now.ToString("yyyyMMddHHmmssffff")}.json";
|
|
|
+ //写入文件
|
|
|
+ FileTool.StringToFile(Path, address.ToJson().JsonFormatting());
|
|
|
+
|
|
|
MessageOut($"节点成功导出至:{Path}");
|
|
|
}
|
|
|
}
|
|
|
@@ -808,7 +858,7 @@ namespace YSAI.Tool.Core.opc.ua.client
|
|
|
/// </summary>
|
|
|
private Task GetAllNode()
|
|
|
{
|
|
|
- return Task.Run(() =>
|
|
|
+ return Task.Factory.StartNew(() =>
|
|
|
{
|
|
|
//获取所有节点
|
|
|
ReferenceDescriptionCollection references = opcUaOperate.GetAllNode(opcUaOperate.GetNodeID()).Result;
|
|
|
@@ -826,8 +876,10 @@ namespace YSAI.Tool.Core.opc.ua.client
|
|
|
int references1 = descriptions.Count;
|
|
|
|
|
|
DrawingImage drawingImage = null;
|
|
|
+
|
|
|
string imagename = opcUaOperate.GetNodeIconType(target, opcUaOperate.GetNodeID());
|
|
|
- System.Windows.Application.Current?.Dispatcher.Invoke(new Action(async () => drawingImage = (DrawingImage)System.Windows.Application.Current.FindResource(imagename)));
|
|
|
+ System.Windows.Application.Current?.Dispatcher.Invoke(new Action(() => drawingImage = (DrawingImage)System.Windows.Application.Current.FindResource(imagename)));
|
|
|
+
|
|
|
//赋值
|
|
|
NodeStructuralBody structuralBody = new NodeStructuralBody() { Name = target.ToString(), Icon = drawingImage, NodeID = target, Count = references1 > 0 ? $"( {references1} )" : string.Empty };
|
|
|
|
|
|
@@ -846,49 +898,48 @@ namespace YSAI.Tool.Core.opc.ua.client
|
|
|
/// <summary>
|
|
|
/// 获取分支
|
|
|
/// </summary>
|
|
|
- private async Task GetBranchNode(NodeId nodeId, NodeStructuralBody node)
|
|
|
+ private Task GetBranchNode(NodeId nodeId, NodeStructuralBody node)
|
|
|
{
|
|
|
- System.Windows.Application.Current?.Dispatcher.Invoke(new Action(() =>
|
|
|
+ return Task.Factory.StartNew(() =>
|
|
|
{
|
|
|
- //清空空白项
|
|
|
- node.Children.Clear();
|
|
|
- }));
|
|
|
- //获取分支下所有节点
|
|
|
- ReferenceDescriptionCollection references = await opcUaOperate.GetAllNode(nodeId);
|
|
|
+ System.Windows.Application.Current?.Dispatcher.Invoke(new Action(() =>
|
|
|
+ {
|
|
|
+ //清空空白项
|
|
|
+ node.Children.Clear();
|
|
|
+ }));
|
|
|
+ //获取分支下所有节点
|
|
|
+ ReferenceDescriptionCollection references = opcUaOperate.GetAllNode(nodeId).Result;
|
|
|
|
|
|
- //获取成功
|
|
|
- if (references != null && references.Count > 0)
|
|
|
- {
|
|
|
- for (int ii = 0; ii < references.Count; ii++)
|
|
|
+ //获取成功
|
|
|
+ if (references != null && references.Count > 0)
|
|
|
{
|
|
|
- //赋值
|
|
|
- ReferenceDescription target = references[ii];
|
|
|
- //得到这个节点下有多少个节点
|
|
|
- ReferenceDescriptionCollection descriptions = await opcUaOperate.GetAllNode((NodeId)target.NodeId);
|
|
|
- if (descriptions != null)
|
|
|
+ for (int ii = 0; ii < references.Count; ii++)
|
|
|
{
|
|
|
- int references1 = descriptions.Count;
|
|
|
+ //赋值
|
|
|
+ ReferenceDescription target = references[ii];
|
|
|
+ //得到这个节点下有多少个节点
|
|
|
+ ReferenceDescriptionCollection descriptions = opcUaOperate.GetAllNode((NodeId)target.NodeId).Result;
|
|
|
+ if (descriptions != null)
|
|
|
+ {
|
|
|
+ int references1 = descriptions.Count;
|
|
|
|
|
|
- DrawingImage drawingImage = null;
|
|
|
- string imagename = opcUaOperate.GetNodeIconType(target, opcUaOperate.GetNodeID());
|
|
|
- System.Windows.Application.Current?.Dispatcher.Invoke(new Action(async () => drawingImage = (DrawingImage)System.Windows.Application.Current.FindResource(imagename)));
|
|
|
+ DrawingImage drawingImage = null;
|
|
|
+ string imagename = opcUaOperate.GetNodeIconType(target, opcUaOperate.GetNodeID());
|
|
|
+ System.Windows.Application.Current?.Dispatcher.Invoke(new Action(async () => drawingImage = (DrawingImage)System.Windows.Application.Current.FindResource(imagename)));
|
|
|
|
|
|
- //赋值
|
|
|
- NodeStructuralBody structuralBody = new NodeStructuralBody() { Name = target.ToString(), Icon = drawingImage, NodeID = target, Count = references1 > 0 ? $"( {references1} )" : string.Empty };
|
|
|
+ NodeStructuralBody structuralBody = new NodeStructuralBody() { Name = target.BrowseName.Name, Icon = drawingImage, NodeID = target, Count = references1 > 0 ? $"( {references1} )" : string.Empty };
|
|
|
|
|
|
- //看此节点下是否存在节点
|
|
|
- if (references1 > 0)
|
|
|
- {
|
|
|
- GetBranchNode((NodeId)target.NodeId, structuralBody);
|
|
|
+ //看此节点下是否存在节点
|
|
|
+ if (references1 > 0)
|
|
|
+ {
|
|
|
+ //赋值
|
|
|
+ GetBranchNode((NodeId)target.NodeId, structuralBody);
|
|
|
+ }
|
|
|
+ System.Windows.Application.Current?.Dispatcher.Invoke(new Action(() => node.Children.Add(structuralBody)));
|
|
|
}
|
|
|
- System.Windows.Application.Current?.Dispatcher.Invoke(new Action(() => node.Children.Add(structuralBody)));
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- Console.WriteLine();
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
@@ -930,13 +981,13 @@ namespace YSAI.Tool.Core.opc.ua.client
|
|
|
for (int i = 0; i < nodeIds.Count; i++)
|
|
|
{
|
|
|
//名称
|
|
|
- string name = objects[i][3].ToString();
|
|
|
+ string name = nodeIds[i].ToString().Split('=')[nodeIds[i].ToString().Split('=').Length - 1];
|
|
|
//地址
|
|
|
string address = nodeIds[i].ToString();
|
|
|
//值
|
|
|
string value = objects[i][1].ToString();
|
|
|
//类型
|
|
|
- string type = (opcUaOperate.GetNodeValueType(nodeIds[i])).ToString();//objects[i][3].ToString();
|
|
|
+ string type = (opcUaOperate.GetNodeValueType(nodeIds[i])).ToString();
|
|
|
//描述
|
|
|
string des = objects[i][4].ToString();
|
|
|
//访问级别
|
|
|
@@ -989,7 +1040,6 @@ namespace YSAI.Tool.Core.opc.ua.client
|
|
|
nodeJson.DataType = (opcUaOperate.GetNodeValueType((NodeId)(node.NodeID as ReferenceDescription).NodeId)).ToString();
|
|
|
nodeJson.Name = dataValues[3].ToString();
|
|
|
nodeJson.Description = dataValues[4].ToString();
|
|
|
-
|
|
|
if (node.Children.Count > 0) //父级
|
|
|
{
|
|
|
if (nodeJson.Nodes == null)
|
|
|
@@ -1001,6 +1051,11 @@ namespace YSAI.Tool.Core.opc.ua.client
|
|
|
nodeJson.Nodes.Add(await ExpNodes(item, new NodeJsonStructuralBody()));
|
|
|
}
|
|
|
}
|
|
|
+ else
|
|
|
+ {
|
|
|
+ nodeJson.Address = (node.NodeID as ReferenceDescription).NodeId.ToString();
|
|
|
+ nodeJson.Name = nodeJson.Address.Split('=')[nodeJson.Address.Split('=').Length - 1];
|
|
|
+ }
|
|
|
return nodeJson;
|
|
|
}
|
|
|
|