Переглянути джерело

机器人与PLC配置增强,界面及多语言优化

本次提交主要内容:
- Axis类新增带参构造函数,便于轴初始化
- XYZU_Robot类增加PLC连接事件通知,优化停止逻辑
- 多语言资源新增“节点头”字段,完善本地化
- AddRobotViewModel引入IConfigService,支持PLC列表绑定及轴列表自动初始化
- AddPlc、AddRobot、SettingView界面增加“节点头”输入,数据双向绑定
- 代码细节优化,提升可读性和健壮性
孝锋 徐 8 місяців тому
батько
коміт
76a61473e8

+ 6 - 0
TeamAAS-VM/Core/Robots/Axis.cs

@@ -184,6 +184,12 @@ namespace TeamAAS_VP.Core.Robots
             State = new AxisState();
         }
 
+        public Axis(string name, int index) : this()
+        {
+            Name = name;
+            Index = index;
+        }
+
         /// <summary>
         /// Logical name of the axis, e.g. "X","Y","Z","U" or "A1".
         /// </summary>

+ 23 - 10
TeamAAS-VM/Core/Robots/XYZU_Robot.cs

@@ -92,6 +92,10 @@ namespace TeamAAS_VP.Core.Robots
         private void Plc_ConnectChangedEvent(object arg1, bool arg2)
         {
             CanExecute = arg2;
+            if (arg2)
+                ConnectedEvent?.Invoke(Id, this, null);
+            else
+                DisconnectedEvent?.Invoke(Id, this, null);
         }
 
         #region ÊôÐÔ
@@ -164,11 +168,18 @@ namespace TeamAAS_VP.Core.Robots
         #region Á¬½Ó
         public void Connect()
         {
-
+            if (Plc.IsConnected)
+            {
+                ConnectedEvent?.Invoke(Id, this, null);
+            }
         }
 
         public Task ConnectAsync()
         {
+            if (Plc.IsConnected)
+            {
+                ConnectedEvent?.Invoke(Id, this, null);
+            }
             return Task.CompletedTask;
         }
 
@@ -304,7 +315,8 @@ namespace TeamAAS_VP.Core.Robots
             return Task.Run(() => GetRobotPos());
         }
 
-        public bool Go(RPoint position) { 
+        public bool Go(RPoint position)
+        {
             return WaitMoveFinished(position);
         }
 
@@ -382,7 +394,7 @@ namespace TeamAAS_VP.Core.Robots
         public Task<bool> CalibOutIOAsync(bool state) => Task.FromResult(false);
         public bool CalibParame(PickInfo Pick, int Speed, int Accel, bool Power, int WaitSuction, int WaitBlow)
         {
-                        return false;
+            return false;
 
         }
         public Task<bool> CalibParameAsync(PickInfo Pick, int Speed, int Accel, bool Power, int WaitSuction, int WaitBlow) => Task.FromResult(false);
@@ -514,15 +526,16 @@ namespace TeamAAS_VP.Core.Robots
             //Task.Run(async () =>
             //{
             //    await Task.Delay(100);
-                Dictionary<string, object> resetValues = new Dictionary<string, object>();
-                foreach (var axis in Axes)
+            Thread.Sleep(50);
+            Dictionary<string, object> resetValues = new Dictionary<string, object>();
+            foreach (var axis in Axes)
+            {
+                if (!string.IsNullOrWhiteSpace(axis.Command.StopNode))
                 {
-                    if (!string.IsNullOrWhiteSpace(axis.Command.StopNode))
-                    {
-                        resetValues.Add(axis.Command.StopNode, false);
-                    }
+                    resetValues.Add(axis.Command.StopNode, false);
                 }
-                Plc.WriteNodes(resetValues);
+            }
+            Plc.WriteNodes(resetValues);
             //});
             return result;
         }

+ 9 - 0
TeamAAS-VM/Resources/Languages/Lang.Designer.cs

@@ -4650,6 +4650,15 @@ namespace TeamAAS_VP.Resources.Languages {
             }
         }
         
+        /// <summary>
+        ///   查找类似 节点头 的本地化字符串。
+        /// </summary>
+        public static string 节点头 {
+            get {
+                return ResourceManager.GetString("节点头", resourceCulture);
+            }
+        }
+        
         /// <summary>
         ///   查找类似 获取视觉输出结果失败 的本地化字符串。
         /// </summary>

+ 3 - 0
TeamAAS-VM/Resources/Languages/Lang.en.resx

@@ -1968,4 +1968,7 @@
   <data name="编辑所选任务" xml:space="preserve">
     <value>Edit the selected task</value>
   </data>
+  <data name="节点头" xml:space="preserve">
+    <value>Node Header</value>
+  </data>
 </root>

+ 3 - 0
TeamAAS-VM/Resources/Languages/Lang.ja-JP.resx

@@ -1968,4 +1968,7 @@
   <data name="编辑所选任务" xml:space="preserve">
     <value>選択したタスクを編集します</value>
   </data>
+  <data name="节点头" xml:space="preserve">
+    <value>ノードヘッダー</value>
+  </data>
 </root>

+ 3 - 0
TeamAAS-VM/Resources/Languages/Lang.resx

@@ -2060,4 +2060,7 @@
   <data name="编辑所选任务" xml:space="preserve">
     <value>编辑所选任务</value>
   </data>
+  <data name="节点头" xml:space="preserve">
+    <value>节点头</value>
+  </data>
 </root>

+ 3 - 0
TeamAAS-VM/Resources/Languages/Lang.zh-TW.resx

@@ -1968,4 +1968,7 @@
   <data name="编辑所选任务" xml:space="preserve">
     <value>編輯所選任務</value>
   </data>
+  <data name="节点头" xml:space="preserve">
+    <value>節點頭</value>
+  </data>
 </root>

+ 75 - 6
TeamAAS-VM/ViewModels/Setting/AddRobotViewModel.cs

@@ -4,10 +4,13 @@ using Prism.Mvvm;
 using Prism.Services.Dialogs;
 using System;
 using System.Collections.Generic;
+using System.Collections.ObjectModel;
 using System.Linq;
 using System.Windows;
 using TeamAAS_VP.Core;
+using TeamAAS_VP.Interfaces;
 using TeamAAS_VP.Models;
+using TeamAAS_VP.Models.PLC;
 using TeamAAS_VP.Resources.Languages;
 using TouchSocket.Core;
 
@@ -15,6 +18,7 @@ namespace TeamAAS_VP.ViewModels.Setting
 {
     public class AddRobotViewModel : BindableBase, IDialogAware
     {
+        private readonly IConfigService _configService;
         private RobotInfo _Robot;
         /// <summary>
         /// 机器人
@@ -22,7 +26,17 @@ namespace TeamAAS_VP.ViewModels.Setting
         public RobotInfo Robot
         {
             get { return _Robot; }
-            set { SetProperty(ref _Robot, value); }
+            set
+            {
+                SetProperty(ref _Robot, value);
+            }
+        }
+
+        private ObservableCollection<PlcInfo> _AllPlc;
+        public ObservableCollection<PlcInfo> AllPlc
+        {
+            get { return _AllPlc; }
+            set { SetProperty(ref _AllPlc, value); }
         }
 
         private PlcInfo _SelectedPlc;
@@ -35,25 +49,47 @@ namespace TeamAAS_VP.ViewModels.Setting
                 if (value != null)
                 {
                     Robot.PLC = value.Id;
+                    if (Robot.PlcRobotParameter == null)
+                    {
+                        Robot.PlcRobotParameter = new PlcRobotParameter();
+                    }
+                    if (Robot.PlcRobotParameter.AxixList == null)
+                    {
+                        Robot.PlcRobotParameter.AxixList = new List<Core.Robots.Axis>();
+                        if (Robot.RobotBrand == Enums.RobotBrand.XYZ_Platform)
+                        {
+                            Robot.PlcRobotParameter.AxixList.Add(new Core.Robots.Axis("X", 1));
+                            Robot.PlcRobotParameter.AxixList.Add(new Core.Robots.Axis("Y", 2));
+                            Robot.PlcRobotParameter.AxixList.Add(new Core.Robots.Axis("Z", 3));
+                        }
+                        else
+                        {
+                            Robot.PlcRobotParameter.AxixList.Add(new Core.Robots.Axis("X", 1));
+                            Robot.PlcRobotParameter.AxixList.Add(new Core.Robots.Axis("Y", 2));
+                            Robot.PlcRobotParameter.AxixList.Add(new Core.Robots.Axis("Z", 3));
+                            Robot.PlcRobotParameter.AxixList.Add(new Core.Robots.Axis("U", 4));
+                        }
+                    }
                 }
                 else
                 {
                     Robot.PLC = Guid.Empty;
+                    Robot.PlcRobotParameter = null;
                 }
             }
         }
 
         private DelegateCommand _ConfirmCommand;
         public DelegateCommand ConfirmCommand =>
-            _ConfirmCommand ?? (_ConfirmCommand = new DelegateCommand(ExecuteConfirmCommand, CanExecuteConfirmCommand).ObservesProperty(()=> Robot.RobotName));
+            _ConfirmCommand ?? (_ConfirmCommand = new DelegateCommand(ExecuteConfirmCommand, CanExecuteConfirmCommand).ObservesProperty(() => Robot.RobotName));
 
         private DelegateCommand _CancelCommand;
         public DelegateCommand CancelCommand =>
             _CancelCommand ?? (_CancelCommand = new DelegateCommand(ExecuteCancelCommand));
 
-        public AddRobotViewModel()
+        public AddRobotViewModel(IConfigService configService)
         {
-
+            _configService = configService;
         }
 
         /// <summary>
@@ -62,7 +98,7 @@ namespace TeamAAS_VP.ViewModels.Setting
         /// <returns></returns>
         bool CanExecuteConfirmCommand()
         {
-            return Robot!=null && Robot.RobotName!=null && !string.IsNullOrEmpty(Robot.RobotName.Trim());
+            return Robot != null && Robot.RobotName != null && !string.IsNullOrEmpty(Robot.RobotName.Trim());
         }
 
         void ExecuteConfirmCommand()
@@ -76,6 +112,38 @@ namespace TeamAAS_VP.ViewModels.Setting
                 MessageBox.Show(Lang.AddCameraVM_message1, "AAS", MessageBoxButton.OK, MessageBoxImage.Error);
                 return;
             }
+            if (Robot.RobotBrand == Enums.RobotBrand.XYZ_Platform)
+            {
+                if (Robot.PlcRobotParameter == null)
+                {
+                    Robot.PlcRobotParameter = new PlcRobotParameter();
+                }
+                if (Robot.PlcRobotParameter.AxixList == null)
+                {
+                    Robot.PlcRobotParameter.AxixList = new List<Core.Robots.Axis>();
+                    Robot.PlcRobotParameter.AxixList.Add(new Core.Robots.Axis("X", 1));
+                    Robot.PlcRobotParameter.AxixList.Add(new Core.Robots.Axis("Y", 2));
+                    Robot.PlcRobotParameter.AxixList.Add(new Core.Robots.Axis("Z", 3));
+                }
+            }
+            else if (Robot.RobotBrand == Enums.RobotBrand.XYZU_Platform)
+            {
+                if (Robot.PlcRobotParameter == null)
+                {
+                    Robot.PlcRobotParameter = new PlcRobotParameter();
+                }
+                if (Robot.PlcRobotParameter.AxixList == null)
+                {
+                    Robot.PlcRobotParameter.AxixList.Add(new Core.Robots.Axis("X", 1));
+                    Robot.PlcRobotParameter.AxixList.Add(new Core.Robots.Axis("Y", 2));
+                    Robot.PlcRobotParameter.AxixList.Add(new Core.Robots.Axis("Z", 3));
+                    Robot.PlcRobotParameter.AxixList.Add(new Core.Robots.Axis("U", 4));
+                }
+            }
+            else
+            {
+                Robot.PlcRobotParameter = null;
+            }
 
             IDialogParameters parameters = new DialogParameters();
             parameters.Add("Robot", Robot);
@@ -111,7 +179,8 @@ namespace TeamAAS_VP.ViewModels.Setting
         public void OnDialogOpened(IDialogParameters parameters)
         {
             Title = Lang.增加机器人;
-            Robot = new RobotInfo() { Id = Guid.NewGuid(),RobotBrand= Enums.RobotBrand.Default,ConnectType= Enums.TCPConnectType.Client, Terminator= Enums.Terminator.CRLF, DataEncoding= Enums.DataEncoding.Default };
+            Robot = new RobotInfo() { Id = Guid.NewGuid(), RobotBrand = Enums.RobotBrand.Default, ConnectType = Enums.TCPConnectType.Client, Terminator = Enums.Terminator.CRLF, DataEncoding = Enums.DataEncoding.Default };
+            AllPlc = new ObservableCollection<PlcInfo>(_configService.GetAllPlcs());
         }
     }
 }

+ 19 - 0
TeamAAS-VM/Views/Setting/AddPlc.xaml

@@ -61,6 +61,7 @@
                 <RowDefinition MinHeight="50"/>
                 <RowDefinition MinHeight="50"/>
                 <RowDefinition MinHeight="50" />
+                <RowDefinition MinHeight="50" />
             </Grid.RowDefinitions>
             <Grid.ColumnDefinitions>
                 <ColumnDefinition Width="50*" />
@@ -138,6 +139,24 @@
                      HorizontalAlignment="Left"
                      VerticalAlignment="Center"
                      Text="{Binding SelectedPlc.EndpointUrl}" />
+            <!--节点头-->
+            <TextBlock Text="{lex:Loc 节点头, Converter={StaticResource StringFormatConverter},ConverterParameter='{}{0}: '}"
+                       Grid.Row="4"
+                       Grid.Column="0"
+                       Style="{StaticResource MaterialDesignSubtitle1TextBlock}"
+                       FontSize="{DynamicResource Font.Size.Body3}"
+                       HorizontalAlignment="Right"
+                       VerticalAlignment="Center" />
+            <TextBox Grid.Row="4"
+                     Grid.Column="1"
+                     FontSize="{DynamicResource Font.Size.Body3}"
+                     Margin="10,0"
+                     MinWidth="80"
+                     TextAlignment="Center"
+                     HorizontalAlignment="Left"
+                     VerticalAlignment="Center"
+                     Width="{Binding ElementName=txt_Id,Path=ActualWidth}"
+                     Text="{Binding SelectedPlc.NodeHeader,Mode=TwoWay}" />
         </Grid>
         <StackPanel Grid.Row="1"
                     Orientation="Horizontal"

+ 3 - 3
TeamAAS-VM/Views/Setting/AddRobot.xaml

@@ -244,7 +244,7 @@
                       VerticalAlignment="Center"
                       Visibility="{Binding Robot.RobotBrand,Converter={StaticResource RobotBrandToVisibiltyConverter}}" />
             <!--PLC-->
-            <!--<TextBlock Grid.Row="3"
+            <TextBlock Grid.Row="3"
                        Grid.Column="0"
                        Text="PLC: "
                        HorizontalAlignment="Right"
@@ -255,7 +255,7 @@
                       Grid.Row="3"
                       Grid.Column="1"
                       Margin="10,5"
-                      ItemsSource="{Binding management.DeviceConfig.Plcs}"
+                      ItemsSource="{Binding AllPlc}"
                       Width="{Binding ElementName=txt_Id,Path=ActualWidth}"
                       MinWidth="80"
                       HorizontalContentAlignment="Center"
@@ -268,7 +268,7 @@
                         <TextBlock Text="{Binding Name}" />
                     </DataTemplate>
                 </ComboBox.ItemTemplate>
-            </ComboBox>-->
+            </ComboBox>
         </Grid>
         <StackPanel Grid.Row="1"
                     Orientation="Horizontal"

+ 20 - 0
TeamAAS-VM/Views/SettingView.xaml

@@ -1099,6 +1099,7 @@
                                 <RowDefinition />
                                 <RowDefinition />
                                 <RowDefinition />
+                                <RowDefinition />
                             </Grid.RowDefinitions>
                             <Grid.ColumnDefinitions>
                                 <ColumnDefinition Width="auto" />
@@ -1183,6 +1184,25 @@
                                      HorizontalAlignment="Left"
                                      VerticalAlignment="Center"
                                      Text="{Binding SelectPlc.EndpointUrl}" />
+                            <!--节点头-->
+                            <TextBlock Text="{lex:Loc 节点头, Converter={StaticResource StringFormatConverter},ConverterParameter='{}{0}: '}"
+                                       Grid.Row="4"
+                                       Grid.Column="0"
+                                       Style="{StaticResource MaterialDesignSubtitle1TextBlock}"
+                                       FontSize="{DynamicResource Font.Size.Body3}"
+                                       HorizontalAlignment="Right"
+                                       VerticalAlignment="Center" />
+                            <TextBox Grid.Row="4"
+                                       Grid.Column="1"
+                                       FontSize="{DynamicResource Font.Size.Body3}"
+                                       Margin="10,0"
+                                       MinWidth="80"
+                                       TextAlignment="Center"
+                                       HorizontalAlignment="Left"
+                                       VerticalAlignment="Center"
+                                       Width="{Binding ElementName=txt_plc_Id,Path=ActualWidth}"
+                                       Text="{Binding SelectPlc.NodeHeader,Mode=TwoWay}" />
+
                         </Grid>
                     </ScrollViewer>
                 </Grid>