Просмотр исходного кода

1. 修改OPCUA工具节点浏览的节点导出功能
2. 新增GE工具

Shun 2 лет назад
Родитель
Сommit
4499b548e5

+ 4 - 0
README.md

@@ -591,3 +591,7 @@ while(true)
 3. 所有库修改OFF实现与Dispose流程
 4. 依赖库更新
 
+#### 2024-1-9
+1. 修改OPCUA工具节点浏览的节点导出功能
+2. 新增GE工具
+

+ 1 - 0
src/YSAI.Tool.Wpf/YSAI.Tool.Wpf.csproj

@@ -26,6 +26,7 @@
 		<PackageReference Include="YSAI.AllenBradley" Version="24.8.31821" />
 		<PackageReference Include="YSAI.Beckhoff" Version="24.8.31821" />
 		<PackageReference Include="YSAI.DB" Version="24.8.31821" />
+		<PackageReference Include="YSAI.GE" Version="24.8.31821" />
 		<PackageReference Include="YSAI.Kafka" Version="24.8.31821" />
 		<PackageReference Include="YSAI.Mewtocol" Version="24.8.31821" />
 		<PackageReference Include="YSAI.Mitsubishi" Version="24.8.31821" />

+ 1 - 1
src/YSAI.Tool.Wpf/controllers/DaHttpController.cs

@@ -228,7 +228,7 @@ namespace YSAI.Tool.Wpf.controllers
         /// <summary>
         /// 通信
         /// </summary>
-        private OpcDaHttpOperate communication;
+        private OpcDaHttpOperate communication = new OpcDaHttpOperate();
 
         /// <summary>
         /// 节点浏览是否点击

+ 28 - 0
src/YSAI.Tool.Wpf/controllers/GEController.cs

@@ -0,0 +1,28 @@
+using System.Windows;
+using YSAI.GE;
+using YSAI.Tool.Wpf.template;
+using static YSAI.GE.GEData;
+
+namespace YSAI.Tool.Wpf.controllers
+{
+    internal class GEController : DaqController<Basics>
+    {
+        public GEController()
+        {
+            //初始化基础数据
+            BasicsData = new Basics();
+            //工具标题
+            ToolTitle = "GE通用电气PLC 工具";
+            //配置文件名
+            FileName = typeof(GEData).Name;
+            //Ascii是否显示
+            AsciiVisibility = Visibility.Collapsed;
+            //Hex是否显示
+            HexVisibility = Visibility.Collapsed;
+            //信息格式;  0 ASCII ; 1 HEX
+            InfoFormat = 0;
+            //设置采集对象
+            Daq = new GEOperate();
+        }
+    }
+}

+ 1 - 0
src/YSAI.Tool.Wpf/controllers/MainController.cs

@@ -43,6 +43,7 @@ namespace YSAI.Tool.Wpf.controllers
                             CreationControl("[ 三菱 ]", SymbolRegular.DesktopFlow24, typeof(YSAI.Tool.Wpf.views.Mitsubishi)),
                             CreationControl("[ 欧姆龙 ]", SymbolRegular.DesktopFlow24, typeof(YSAI.Tool.Wpf.views.Omron)),
                             CreationControl("[ 西门子 ]", SymbolRegular.DesktopFlow24, typeof(YSAI.Tool.Wpf.views.Siemens)),
+                            CreationControl("[ GE ]", SymbolRegular.DesktopFlow24, typeof(YSAI.Tool.Wpf.views.GE)),
                         }
                   },
                    new NavigationViewItem()

+ 56 - 32
src/YSAI.Tool.Wpf/controllers/UaClientController.cs

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

+ 20 - 0
src/YSAI.Tool.Wpf/views/GE.xaml

@@ -0,0 +1,20 @@
+<UserControl x:Class="YSAI.Tool.Wpf.views.GE"
+             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
+             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
+             xmlns:local="clr-namespace:YSAI.Tool.Wpf.views"
+             xmlns:c="clr-namespace:YSAI.Tool.Wpf.controllers"
+             Background="{DynamicResource ContentBackgroundPicture}">
+
+    <!--资源加载-->
+    <UserControl.Resources>
+        <ResourceDictionary Source="pack://application:,,,/YSAI.Tool.Wpf;component/template/DaqView.xaml" />
+    </UserControl.Resources>
+    <!--控制器绑定-->
+    <UserControl.DataContext>
+        <c:GEController />
+    </UserControl.DataContext>
+    <!--内容控件加载-->
+    <ContentControl Content="{Binding}" ContentTemplate="{DynamicResource DAQ}"/>
+</UserControl>

+ 28 - 0
src/YSAI.Tool.Wpf/views/GE.xaml.cs

@@ -0,0 +1,28 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Data;
+using System.Windows.Documents;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Imaging;
+using System.Windows.Navigation;
+using System.Windows.Shapes;
+
+namespace YSAI.Tool.Wpf.views
+{
+    /// <summary>
+    /// GE.xaml 的交互逻辑
+    /// </summary>
+    public partial class GE : UserControl
+    {
+        public GE()
+        {
+            InitializeComponent();
+        }
+    }
+}