Shun %!s(int64=2) %!d(string=hai) anos
pai
achega
69997208e5

+ 115 - 48
src/YSAI.DAQ/YSAI.Opc/ua/client/OpcUaClientOperate.cs

@@ -4,6 +4,7 @@ using Opc.Ua.Configuration;
 using System.Collections.Concurrent;
 using System.Security.Cryptography.X509Certificates;
 using YSAI.Core.data;
+using YSAI.Core.@enum;
 using YSAI.Core.@interface;
 using YSAI.Core.virtualAddress;
 using YSAI.Log;
@@ -93,7 +94,7 @@ namespace YSAI.Opc.ua.client
         /// <summary>
         /// 重连时间,多少秒与服务器进行重连一次
         /// </summary>
-        private int reconnectPeriod = 10;
+        private int reconnectPeriod = 2;
         /// <summary>
         /// 尝试重新连接到服务器
         /// </summary>
@@ -409,7 +410,83 @@ namespace YSAI.Opc.ua.client
                 return "null";
             }
         }
-
+        /// <summary>
+        /// OPCUA 数据类型转换成 Core 数据类型
+        /// </summary>
+        public DataType TypeConvert(BuiltInType builtInType)
+        {
+            try
+            {
+                switch (builtInType)
+                {
+                    case BuiltInType.Boolean:
+                        {
+                            return DataType.Bool;
+                        }
+                    case BuiltInType.Byte:
+                        {
+                            return DataType.Byte;
+                        }
+                    case BuiltInType.Double:
+                        {
+                            return DataType.Double;
+                        }
+                    case BuiltInType.Float:
+                        {
+                            return DataType.Float;
+                        }
+                    case BuiltInType.Int16:
+                        {
+                            return DataType.Short;
+                        }
+                    case BuiltInType.Int32:
+                        {
+                            return DataType.Int;
+                        }
+                    case BuiltInType.Int64:
+                        {
+                            return DataType.Long;
+                        }
+                    case BuiltInType.Integer:
+                        {
+                            return DataType.Int;
+                        }
+                    case BuiltInType.LocalizedText:
+                        {
+                            return DataType.String;
+                        }
+                    case BuiltInType.SByte:
+                        {
+                            return DataType.Sbyte;
+                        }
+                    case BuiltInType.String:
+                        {
+                            return DataType.String;
+                        }
+                    case BuiltInType.UInt16:
+                        {
+                            return DataType.Ushort;
+                        }
+                    case BuiltInType.UInt32:
+                        {
+                            return DataType.Uint;
+                        }
+                    case BuiltInType.UInt64:
+                        {
+                            return DataType.Ulong;
+                        }
+                    case BuiltInType.UInteger:
+                        {
+                            return DataType.Uint;
+                        }
+                    default: throw new Exception("Not supported data type");
+                }
+            }
+            catch
+            {
+                return DataType.String;
+            }
+        }
         /// <summary>
         /// 获取写入值的类型 并返回对应类型(字符串VALUE)
         /// </summary>
@@ -789,31 +866,26 @@ namespace YSAI.Opc.ua.client
 
                             if (Nodes.Count > 0)
                             {
-                                //添加监控项
-                                allSubscriptions[Tag].AddItems(monitoredItems);
                                 //添加订阅
-                                if (clientSession.AddSubscription(allSubscriptions[Tag]))
+                                if (!clientSession?.AddSubscription(allSubscriptions[Tag]) == true)
                                 {
-                                    //在服务器上创建订阅并添加所有监视项
-                                    if (allSubscriptions[Tag].CreateAsync().Wait(basics.Timeout))
-                                    {
-                                        // 将任何更改应用于订阅项
-                                        if (!allSubscriptions[Tag].ApplyChangesAsync().Wait(basics.Timeout))
-                                        {
-                                            allSubscriptions?.Remove(Tag, out _);
-                                            return Break("AddSubscribe", false, "将任何更改应用于订阅项超时");
-                                        }
-                                    }
-                                    else
-                                    {
-                                        allSubscriptions?.Remove(Tag, out _);
-                                        return Break("AddSubscribe", false, "在服务器上创建订阅并添加所有监视项超时");
-                                    }
+                                    return Break("AddSubscribe", false, "会话添加订阅失败");
                                 }
-                                else
+
+                                //在服务器上创建订阅并添加所有监视项
+                                if (!allSubscriptions[Tag].CreateAsync().Wait(basics.Timeout))
                                 {
-                                    return Break("AddSubscribe", false, "会话添加订阅失败");
+                                    return Break("AddSubscribe", false, "在服务器上创建订阅并添加所有监视项超时");
                                 }
+
+                                //添加监控项
+                                allSubscriptions[Tag].AddItems(monitoredItems);
+
+                                //把此订阅添加到集合,方便后续移除订阅(当存在此键则更新值,不存在则添加)
+                                allSubscriptions?.AddOrUpdate(Tag, allSubscriptions[Tag], (k, v) => allSubscriptions[Tag]);
+
+                                // 将任何更改应用于订阅项
+                                allSubscriptions[Tag].ApplyChangesAsync();
                             }
                         }
                         else
@@ -825,14 +897,28 @@ namespace YSAI.Opc.ua.client
                             subscription.PublishingEnabled = true;//是否启用发布
                             subscription.PublishingInterval = basics.PublishingInterval; //出版间隔
                             subscription.KeepAliveCount = uint.MaxValue;  //保活计数
-                            subscription.LifetimeCount = uint.MaxValue;  //寿命计数
+                            subscription.LifetimeCount =  uint.MaxValue;  //寿命计数
                             subscription.MaxNotificationsPerPublish = uint.MaxValue;  //每个发布请求的最大通知数
                             subscription.Priority = 1;  //分配给订阅的优先级
                             subscription.DisplayName = Tag;  //订阅的显示名称
                             subscription.TimestampsToReturn = TimestampsToReturn.Both;  //与通知消息一起返回的时间戳
                             subscription.StateChanged += delegate (Subscription subscription, SubscriptionStateChangedEventArgs e) { Subscription_StateChanged(subscription, e, Tag); };  //订阅状态
-                            //监控项集合                                                                                                                                                    //订阅节点集合
+
+                            //添加订阅
+                            if (!clientSession?.AddSubscription(subscription) == true)
+                            {
+                                return Break("AddSubscribe", false, "会话添加订阅失败");
+                            }
+
+                            //在服务器上创建订阅并添加所有监视项
+                            if (!subscription.CreateAsync().Wait(basics.Timeout))
+                            {
+                                return Break("AddSubscribe", false, "在服务器上创建订阅并添加所有监视项超时");
+                            }
+
+                            //监控项集合                                                                                                                                                    
                             List<MonitoredItem> monitoredItems = new List<MonitoredItem>();
+
                             //循环添加
                             foreach (var item in Nodes)
                             {
@@ -852,31 +938,13 @@ namespace YSAI.Opc.ua.client
                             }
                             //添加监控项
                             subscription.AddItems(monitoredItems);
+
                             //把此订阅添加到集合,方便后续移除订阅(当存在此键则更新值,不存在则添加)
                             allSubscriptions?.AddOrUpdate(Tag, subscription, (k, v) => subscription);
-                            //添加订阅
-                            if (clientSession.AddSubscription(allSubscriptions[Tag]))
-                            {
-                                //在服务器上创建订阅并添加所有监视项
-                                if (allSubscriptions[Tag].CreateAsync().Wait(basics.Timeout))
-                                {
-                                    // 将任何更改应用于订阅项
-                                    if (!allSubscriptions[Tag].ApplyChangesAsync().Wait(basics.Timeout))
-                                    {
-                                        allSubscriptions?.Remove(Tag, out _);
-                                        return Break("AddSubscribe", false, "将任何更改应用于订阅项超时");
-                                    }
-                                }
-                                else
-                                {
-                                    allSubscriptions?.Remove(Tag, out _);
-                                    return Break("AddSubscribe", false, "在服务器上创建订阅并添加所有监视项超时");
-                                }
-                            }
-                            else
-                            {
-                                return Break("AddSubscribe", false, "会话添加订阅失败");
-                            }
+
+                            // 将任何更改应用于订阅项
+                            subscription.ApplyChangesAsync();
+
                         }
                         return Break("AddSubscribe", true);
                     }
@@ -938,7 +1006,6 @@ namespace YSAI.Opc.ua.client
         {
             string Message = EnumParse(e.Status.ToString());
             string MessageJson = "{" + $"\"Uri\":\"{basics.ServerUrl}\",\"CustomName\":\"{basics.CustomName}\",\"StatusCode\":\"{e.Status}\",\"StatusMessage\":\"{Message}\"" + "}";
-            //LogHelper.Info(MessageJson.JsonFormatting(), ClassName + ".log");
             OnEventHandler(this, new EventResult(true, Message, MessageJson));
         }
 

+ 1 - 4
src/YSAI.DAQ/YSAI.Opc/ua/service/core/Node.cs

@@ -3179,7 +3179,7 @@ namespace YSAI.Opc.ua.service.core
         /// <param name="node"></param>
         public void CreateNode(NodeJsonStructuralBody node, FolderState folder)
         {
-            if (node.IsDynamic)  //创建动态
+            if (node.IsDynamic == true)  //创建动态
             {
                 //通过反射找到对应的属性并获取它的值
                 CreateDynamicVariable(folder, node.Name, node.DataType, (NodeId)typeof(DataTypeIds).GetField(node.DataType).GetValue(new object()), ValueRanks.Scalar).Description = node.Description;
@@ -3287,7 +3287,6 @@ namespace YSAI.Opc.ua.service.core
                     FileTool.StringToFile(m_configuration.NodeManagerSaveFile, Json);
                     #endregion
 
-
                     #region 读取并创建节点
                     Json = FileTool.FileToString(m_configuration.NodeManagerSaveFile);  //读取文件
                     NodeJsonStructuralBody body = JsonTool.StringToJsonEntity<NodeJsonStructuralBody>(Json);  //JSON反序列化
@@ -3296,8 +3295,6 @@ namespace YSAI.Opc.ua.service.core
                     m_simulationTimer = new Timer(DoSimulation, null, 1000, 1000);
                     references.Add(new NodeStateReference(ReferenceTypes.Organizes, false, root.NodeId));
                     #endregion
-
-
                 }
                 else   //如果存在,则从配置中拉取
                 {

+ 5 - 1
src/YSAI.DAQ/YSAI.Opc/ua/service/core/NodeJsonStructuralBody.cs

@@ -12,7 +12,7 @@
         /// <summary>
         /// 是动态
         /// </summary>
-        public bool IsDynamic { get; set; }
+        public bool? IsDynamic { get; set; }
         /// <summary>
         /// 数据类型
         /// </summary>
@@ -26,6 +26,10 @@
         /// </summary>
         public string Description { get; set; }
         /// <summary>
+        /// 导出使用
+        /// </summary>
+        public string Address { get; set; }
+        /// <summary>
         /// 节点
         /// </summary>
         public List<NodeJsonStructuralBody>? Nodes { get; set; }

+ 122 - 44
src/YSAI.DAQ/YSAI.Test.All/Program.cs

@@ -1,44 +1,122 @@
-using YSAI.Core.data;
+
+using YSAI.Core.data;
 using YSAI.Opc.ua.client;
 using YSAI.Unility;
 
 
-//点位地址
-Address address = new Address();
-address.SN = Guid.NewGuid().ToString();
-address.CreationTime = DateTime.Now.ToLocalTime();
-address.AddressArray = new List<AddressDetails> {
-    new AddressDetails()
-    {
-        AddressName = "ns=2;s=YT6022_VALUE_SJ2147_P_CUR_9",
-        AddressDataType = YSAI.Core.@enum.DataType.Float
-    },
-    new AddressDetails()
-    {
-         AddressName = "ns=2;s=YT6022_VALUE_SJ2147_W_P3",
-        AddressDataType = YSAI.Core.@enum.DataType.Float
-    }
-};
 
-for (int i = 0; i < 150; i++)
+Address address = JsonTool.StringToJsonEntity<Address>(FileTool.FileToString("C:\\Users\\Shun\\Desktop\\Address.json"));
+
+
+OpcUaClientOperate opcUaClientOperate = OpcUaClientOperate.Instance(new OpcUaClientData.Basics
 {
-    OpcUaClientOperate opcUaClientOperate = OpcUaClientOperate.Instance(new OpcUaClientData.Basics
+    ServerUrl = "opc.tcp://192.168.2.220:49320",
+    CustomName = "YSAI 性能测试",
+});
+Console.WriteLine(opcUaClientOperate.On().ToJson().JsonFormatting());
+opcUaClientOperate.OnEvent += OpcUaClientOperate_OnEvent;
+
+while (true)
+{
+    Console.ReadLine();
+    OperateResult operateResult = opcUaClientOperate.Subscribe(address);
+    Console.WriteLine(operateResult.ToJson().JsonFormatting());
+}
+
+void OpcUaClientOperate_OnEvent(object? sender, EventResult e)
+{
+    if (e.RData != null)
+    {
+        Console.ForegroundColor = ConsoleColor.Green;
+        Console.WriteLine(e.RData.ToJson());
+    }
+    else
     {
-        CustomName = Guid.NewGuid().ToString(),
-        Password = "ysai",
-        ServerUrl = "opc.tcp://127.0.0.1:8866/Opc.Ua.Service",
-        UserName = "ysai",
-        SN = Guid.NewGuid().ToString()
-    });
-    opcUaClientOperate.OnEvent += delegate (object? sender, EventResult e) { OpcUaClientOperate_OnEvent(sender, e, "a"); };
-    Console.WriteLine(opcUaClientOperate.OnAsync().Result.ToJson().JsonFormatting());
-    Console.WriteLine(opcUaClientOperate.AddSubscribe(new System.Collections.Concurrent.ConcurrentDictionary<string, Address>() { ["ysai"] = address }).ToJson().JsonFormatting());
+        Console.ForegroundColor = ConsoleColor.Red;
+        Console.WriteLine(e.ToJson().JsonFormatting());
+    }
 }
 
 
 
 
 
+//using Opc.Ua;
+//using YSAI.Core.data;
+//using YSAI.Core.@enum;
+//using YSAI.Opc.ua.client;
+//using YSAI.Unility;
+
+
+////点位地址
+//Address address = new Address();
+//address.SN = Guid.NewGuid().ToString();
+//address.CreationTime = DateTime.Now.ToLocalTime();
+//address.AddressArray = new List<AddressDetails>();
+
+//string path = "C:\\Users\\Shun\\Desktop\\标签导入-5k回潮加料.csv";
+
+//foreach (string s in ReadCsv(path, true))
+//{
+//    try
+//    {
+//        string[] str = s.Split(",");
+//        string Name = str[5];
+//        DataType Type = OpcUaClientOperate.Instance(new OpcUaClientData.Basics()).TypeConvert((BuiltInType)Enum.Parse(typeof(BuiltInType), str[6]));
+//        string Des = str[4];
+//        address.AddressArray.Add(new AddressDetails
+//        {
+//            AddressName = str[5],
+//            AddressDataType = Type,
+//            AddressDescribe = Des
+//        });
+//    }
+//    catch (Exception) { }
+
+//}
+
+//FileTool.StringToFile("C:\\Users\\Shun\\Desktop\\Address.json", address.ToJson().JsonFormatting());
+
+
+
+///// <summary>
+///// 读取Csv,返回行集合
+///// </summary>
+///// <param name="path"></param>
+///// <param name="hasTitle"></param>
+///// <returns></returns>
+//static List<string> ReadCsv(string path, bool hasTitle)
+//{
+//    if (!File.Exists(path))
+//        return new List<string>();
+
+//    var lines = File.ReadAllLines(path).ToList();
+//    if (hasTitle)
+//    {
+//        lines.RemoveAt(0);
+//    }
+//    return lines;
+//}
+
+//for (int i = 0; i < 150; i++)
+//{
+//    OpcUaClientOperate opcUaClientOperate = OpcUaClientOperate.Instance(new OpcUaClientData.Basics
+//    {
+//        CustomName = Guid.NewGuid().ToString(),
+//        Password = "ysai",
+//        ServerUrl = "opc.tcp://127.0.0.1:8866/Opc.Ua.Service",
+//        UserName = "ysai",
+//        SN = Guid.NewGuid().ToString()
+//    });
+//    opcUaClientOperate.OnEvent += delegate (object? sender, EventResult e) { OpcUaClientOperate_OnEvent(sender, e, "a"); };
+//    Console.WriteLine(opcUaClientOperate.OnAsync().Result.ToJson().JsonFormatting());
+//    Console.WriteLine(opcUaClientOperate.AddSubscribe(new System.Collections.Concurrent.ConcurrentDictionary<string, Address>() { ["ysai"] = address }).ToJson().JsonFormatting());
+//}
+
+
+
+
+
 //OpcUaClientOperate opcUaClientOperate_2 = OpcUaClientOperate.Instance(new OpcUaClientData.Basics
 //{
 //    CustomName = Guid.NewGuid().ToString(),
@@ -51,23 +129,23 @@ for (int i = 0; i < 150; i++)
 //Console.WriteLine(opcUaClientOperate_2.OnAsync().Result.ToJson().JsonFormatting());
 //Console.WriteLine(opcUaClientOperate_2.AddSubscribe(new System.Collections.Concurrent.ConcurrentDictionary<string, Address>() { ["ysai"] = address }).ToJson().JsonFormatting());
 
-void OpcUaClientOperate_OnEvent(object? sender, EventResult e, string name)
-{
-    if (name.Equals("a"))
-    {
-        Console.ForegroundColor = ConsoleColor.Green;
-    }
-    else
-    {
-        Console.ForegroundColor = ConsoleColor.Red;
-    }
-    Console.WriteLine(e.ToJson().JsonFormatting());
-}
+//void OpcUaClientOperate_OnEvent(object? sender, EventResult e, string name)
+//{
+//    if (name.Equals("a"))
+//    {
+//        Console.ForegroundColor = ConsoleColor.Green;
+//    }
+//    else
+//    {
+//        Console.ForegroundColor = ConsoleColor.Red;
+//    }
+//    Console.WriteLine(e.ToJson().JsonFormatting());
+//}
 
-while (true)
-{
-    Console.ReadKey();
-}
+//while (true)
+//{
+//    Console.ReadKey();
+//}
 
 //TcpClientOperate tcpClientOperate = TcpClientOperate.Instance(new TcpClientData.Basics
 //{

+ 5 - 5
src/YSAI.DAQ/YSAI.Tool.Core/opc/ua/client/OpcUaClientTool.xaml

@@ -430,12 +430,12 @@
                                             </i:EventTrigger>
                                         </i:Interaction.Triggers>
                                         <DataGrid.Columns>
-                                            <DataGridTextColumn Header="名称"  Width="*"  Binding="{Binding Name}" />
+                                            <DataGridTextColumn Header="名称"  Width="auto"  Binding="{Binding Name}" Visibility="Collapsed"/>
                                             <DataGridTextColumn Header="地址"  Width="*"  Binding="{Binding Address}" />
-                                            <DataGridTextColumn Header="值"  Width="*"  Binding="{Binding Value}" />
-                                            <DataGridTextColumn Header="类型" Width="*" Binding="{Binding Type}"/>
-                                            <DataGridTextColumn Header="访问级别"  Width="*"  Binding="{Binding AccessLevel}"/>
-                                            <DataGridTextColumn Header="描述"  Width="*"  Binding="{Binding Description}"/>
+                                            <DataGridTextColumn Header="值"  Width="150"  Binding="{Binding Value}" />
+                                            <DataGridTextColumn Header="类型" Width="120" Binding="{Binding Type}"/>
+                                            <DataGridTextColumn Header="访问级别"  Width="150"  Binding="{Binding AccessLevel}"/>
+                                            <DataGridTextColumn Header="描述"  Width="100"  Binding="{Binding Description}"/>
                                         </DataGrid.Columns>
                                     </DataGrid>
                                     

+ 93 - 38
src/YSAI.DAQ/YSAI.Tool.Core/opc/ua/client/OpcUaClientToolController.cs

@@ -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;
         }