|
|
@@ -219,7 +219,7 @@ namespace YSAI.Tool.Wpf.controllers
|
|
|
/// <summary>
|
|
|
/// 通信
|
|
|
/// </summary>
|
|
|
- private OpcUaClientOperate communication;
|
|
|
+ private OpcUaClientOperate communication = new OpcUaClientOperate();
|
|
|
|
|
|
/// <summary>
|
|
|
/// 加载节点的生命周期
|
|
|
@@ -480,6 +480,7 @@ namespace YSAI.Tool.Wpf.controllers
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
Output($"数据格式不正确:{ex.Message}");
|
|
|
+ _write = false;
|
|
|
return;
|
|
|
}
|
|
|
//写入
|
|
|
@@ -800,6 +801,10 @@ namespace YSAI.Tool.Wpf.controllers
|
|
|
/// <param name="body"></param>
|
|
|
private async Task<NodeJsonStructuralBody> ExpNodes(NodeStructuralBody node, NodeJsonStructuralBody nodeJson = null)
|
|
|
{
|
|
|
+ if (node.NodeID == null)
|
|
|
+ {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
if (nodeJson == null)
|
|
|
{
|
|
|
nodeJson = new NodeJsonStructuralBody();
|
|
|
@@ -820,7 +825,16 @@ namespace YSAI.Tool.Wpf.controllers
|
|
|
}
|
|
|
foreach (var item in node.Children)
|
|
|
{
|
|
|
- nodeJson.Nodes.Add(await ExpNodes(item, new NodeJsonStructuralBody()));
|
|
|
+ if (item == null)
|
|
|
+ {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ NodeJsonStructuralBody nodeJsonStructuralBody = await ExpNodes(item, new NodeJsonStructuralBody());
|
|
|
+ if (nodeJsonStructuralBody == null)
|
|
|
+ {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ nodeJson.Nodes.Add(nodeJsonStructuralBody);
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
@@ -970,16 +984,19 @@ namespace YSAI.Tool.Wpf.controllers
|
|
|
{
|
|
|
foreach (var item in node.Nodes)
|
|
|
{
|
|
|
- if (item.Nodes != null)
|
|
|
+ if (item != null)
|
|
|
{
|
|
|
- foreach (var no in item.Nodes)
|
|
|
+ if (item.Nodes != null)
|
|
|
{
|
|
|
- ec(no);
|
|
|
+ foreach (var no in item.Nodes)
|
|
|
+ {
|
|
|
+ ec(no);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ nodes.Add(item);
|
|
|
}
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- nodes.Add(item);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -1008,32 +1025,39 @@ namespace YSAI.Tool.Wpf.controllers
|
|
|
else
|
|
|
{
|
|
|
NodeJsonStructuralBody nodeStructuralBody = await ExpNodes(NodeSelectedItem);
|
|
|
- string Path = str + $"\\[{nodeStructuralBody.Name}]Node {DateTime.Now.ToString("yyyyMMddHHmmssffff")}.json";
|
|
|
- //设置json序列化反序列化格式
|
|
|
- JsonSerializerSettings JsonSetting = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore };
|
|
|
- //当有空数据时不做解析,且进行缩进处理
|
|
|
- string Json = JsonConvert.SerializeObject(nodeStructuralBody, Newtonsoft.Json.Formatting.None, JsonSetting);
|
|
|
- //写入文件
|
|
|
- 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)
|
|
|
+ if (nodeStructuralBody == null)
|
|
|
{
|
|
|
- address.AddressArray.Add(new AddressDetails
|
|
|
- {
|
|
|
- AddressName = item.Address,
|
|
|
- AddressDescribe = item.Description,
|
|
|
- AddressDataType = communication.TypeConvert((BuiltInType)Enum.Parse(typeof(BuiltInType), item.DataType))
|
|
|
- });
|
|
|
+ Output("请把所有子节点都展开在进行导出操作");
|
|
|
}
|
|
|
- Path = str + $"\\[{nodeStructuralBody.Name}]Node_Address {DateTime.Now.ToString("yyyyMMddHHmmssffff")}.json";
|
|
|
- //写入文件
|
|
|
- FileTool.StringToFile(Path, address.ToJson().JsonFormatting());
|
|
|
+ else
|
|
|
+ {
|
|
|
+ string Path = str + $"\\[{nodeStructuralBody.Name}]Node {DateTime.Now.ToString("yyyyMMddHHmmssffff")}.json";
|
|
|
+ //设置json序列化反序列化格式
|
|
|
+ JsonSerializerSettings JsonSetting = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore };
|
|
|
+ //当有空数据时不做解析,且进行缩进处理
|
|
|
+ string Json = JsonConvert.SerializeObject(nodeStructuralBody, Newtonsoft.Json.Formatting.None, JsonSetting);
|
|
|
+ //写入文件
|
|
|
+ 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 = communication.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());
|
|
|
|
|
|
- Output($"节点成功导出至:{Path}");
|
|
|
+ Output($"节点成功导出至:{Path}");
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
#endregion
|