Browse Source

新增光源控制器手动调试界面及初始化支持

本次提交主要内容:
- 新增 LightManual.xaml 及其 ViewModel,实现光源控制器手动调试界面,并在调试树中集成导航入口。
- 系统初始化流程增加光源控制器注册与连接步骤,完善 Management 相关方法和依赖注入。
- 增强权限控制,操作员不可编辑,支持用户登录动态切换权限。
- 多语言资源文件补充光源控制器相关词条,支持中/英/日/繁多语种。
- 项目文件增加新界面及 ViewModel 的编译配置。
- 其他细节优化:调试主界面数据绑定、进度条步骤调整等。
孝锋 徐 8 months ago
parent
commit
87d8cbb990

+ 1 - 0
TeamAAS-VM/App.xaml.cs

@@ -74,6 +74,7 @@ namespace TeamAAS_VP
             containerRegistry.RegisterForNavigation<ScriptHome>();
             containerRegistry.RegisterForNavigation<FeederClear>();
             containerRegistry.RegisterForNavigation<AfagFeederManual>();
+            containerRegistry.RegisterForNavigation<LightManual>();
 
             //产品
             containerRegistry.RegisterForNavigation<ProductHome>();

+ 49 - 1
TeamAAS-VM/Core/Management.cs

@@ -64,6 +64,7 @@ namespace TeamAAS_VP.Core
         ICameraService _cameraService;
         IFeederService _feederService;
         IPlcService _plcService;
+        ILightManagerService _lightManagerService;
         IProductService _productService;
         ICalibrationService _calibrationService;
         IRemoteCommandService _remoteCommandService;
@@ -168,7 +169,7 @@ namespace TeamAAS_VP.Core
 
         public Management(IRegionManager regionManager, IEventAggregator ea, IContainerProvider container, IConfigService configService,
             IRobotService robotService, ICameraService cameraService, IFeederService feederService, IPlcService plcService, IProductService productService,
-            ICalibrationService calibrationService, IRemoteCommandService remoteCommandService, ISystemDatabaseService systemDatabaseService)
+            ICalibrationService calibrationService, IRemoteCommandService remoteCommandService, ISystemDatabaseService systemDatabaseService, ILightManagerService lightManagerService)
         {
             _regionManager = regionManager;
             _eventAggregator = ea;
@@ -185,6 +186,7 @@ namespace TeamAAS_VP.Core
             _productService = productService;
             _remoteCommandService = remoteCommandService;
             _systemDatabaseService = systemDatabaseService;
+            _lightManagerService = lightManagerService;
         }
 
         #region 初始化硬件模块
@@ -354,6 +356,52 @@ namespace TeamAAS_VP.Core
             }
         }
 
+        /// <summary>
+        /// 初始化光源控制器
+        /// </summary>
+        /// <returns></returns>
+        public async Task<(bool IsSucceed, string Msg)> InitLightControllers()
+        {
+            var lightcontrollers = _configService.GetAllLightControllers();
+            StringBuilder sb = new StringBuilder();
+            foreach (var item in lightcontrollers)
+            {
+                try
+                {
+                    var lishtCtr= await _lightManagerService.RegisterControllerAsync(item.Id, item);
+                    //var lightcontroller = _cameraService.GetLightController(item.Id);
+                    //await lightcontroller.ConnectAsync();     //连接光源控制器
+                    //SendTaskMessage($"{item.LightControllerName}{Lang.已连接}!", MessageLevel.Debug);
+                }
+                catch (Exception ex)
+                {
+                    //sb.AppendLine($"{item.LightControllerName}:{Lang.断开连接}![{ex.Message}]");
+                    //SendTaskMessage($"{item.LightControllerName}{Lang.断开连接}!", MessageLevel.Alarm);
+                }
+            }
+            if (lightcontrollers.Count>0)
+            {
+                var result=await _lightManagerService.ConnectAllAsync();
+                if (result)
+                {
+                    return (true, "");
+                }
+                else
+                {
+                    return (false, "Light Controller Connect Failed!");
+                }
+            }
+            return (true, "");
+            //if (sb.Length == 0)
+            //{
+            //    return (true, "");
+            //}
+            //else
+            //{
+            //    return (false, sb.ToString());
+            //}
+        }
+
         /// <summary>
         /// 初始化后台TCP服务器通讯
         /// </summary>

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

@@ -3795,6 +3795,15 @@ namespace TeamAAS_VP.Resources.Languages {
             }
         }
         
+        /// <summary>
+        ///   查找类似 正在初始化光源控制器 的本地化字符串。
+        /// </summary>
+        public static string 正在初始化光源控制器 {
+            get {
+                return ResourceManager.GetString("正在初始化光源控制器", resourceCulture);
+            }
+        }
+        
         /// <summary>
         ///   查找类似 正在初始化机器人 的本地化字符串。
         /// </summary>

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

@@ -1971,4 +1971,31 @@
   <data name="节点头" xml:space="preserve">
     <value>Node Header</value>
   </data>
+  <data name="增加光源控制器" xml:space="preserve">
+    <value>Add a light source controller</value>
+  </data>
+  <data name="移除光源控制器" xml:space="preserve">
+    <value>Remove the Light Controller</value>
+  </data>
+  <data name="光源控制器列表" xml:space="preserve">
+    <value>Light Source Controller List</value>
+  </data>
+  <data name="通道数" xml:space="preserve">
+    <value>Number of Channels</value>
+  </data>
+  <data name="光源控制器" xml:space="preserve">
+    <value>Light Source Controller</value>
+  </data>
+  <data name="通道配置" xml:space="preserve">
+    <value>Channel Configuration</value>
+  </data>
+  <data name="串口配置" xml:space="preserve">
+    <value>Serial Port Configuration</value>
+  </data>
+  <data name="TCP配置" xml:space="preserve">
+    <value>TCP Configuration</value>
+  </data>
+  <data name="正在初始化光源控制器" xml:space="preserve">
+    <value>Initializing Light Controller</value>
+  </data>
 </root>

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

@@ -1971,4 +1971,31 @@
   <data name="节点头" xml:space="preserve">
     <value>ノードヘッダー</value>
   </data>
+  <data name="增加光源控制器" xml:space="preserve">
+    <value>光源コントローラーを追加してください</value>
+  </data>
+  <data name="移除光源控制器" xml:space="preserve">
+    <value>ライトコントローラーを取り外します</value>
+  </data>
+  <data name="光源控制器列表" xml:space="preserve">
+    <value>光源コントローラリスト</value>
+  </data>
+  <data name="通道数" xml:space="preserve">
+    <value>チャネル数</value>
+  </data>
+  <data name="光源控制器" xml:space="preserve">
+    <value>光源コントローラー</value>
+  </data>
+  <data name="通道配置" xml:space="preserve">
+    <value>チャンネル設定</value>
+  </data>
+  <data name="串口配置" xml:space="preserve">
+    <value>シリアルポートの設定</value>
+  </data>
+  <data name="TCP配置" xml:space="preserve">
+    <value>TCP設定</value>
+  </data>
+  <data name="正在初始化光源控制器" xml:space="preserve">
+    <value>ライトコントローラーを初期化しています</value>
+  </data>
 </root>

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

@@ -2087,4 +2087,7 @@
   <data name="TCP配置" xml:space="preserve">
     <value>TCP 配置</value>
   </data>
+  <data name="正在初始化光源控制器" xml:space="preserve">
+    <value>正在初始化光源控制器</value>
+  </data>
 </root>

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

@@ -1971,4 +1971,31 @@
   <data name="节点头" xml:space="preserve">
     <value>節點頭</value>
   </data>
+  <data name="增加光源控制器" xml:space="preserve">
+    <value>增加光源控制器</value>
+  </data>
+  <data name="移除光源控制器" xml:space="preserve">
+    <value>移除光源控制器</value>
+  </data>
+  <data name="光源控制器列表" xml:space="preserve">
+    <value>光源控制器列表</value>
+  </data>
+  <data name="通道数" xml:space="preserve">
+    <value>通道數</value>
+  </data>
+  <data name="光源控制器" xml:space="preserve">
+    <value>光源控制器</value>
+  </data>
+  <data name="通道配置" xml:space="preserve">
+    <value>通道配置</value>
+  </data>
+  <data name="串口配置" xml:space="preserve">
+    <value>串口配置</value>
+  </data>
+  <data name="TCP配置" xml:space="preserve">
+    <value>配置</value>
+  </data>
+  <data name="正在初始化光源控制器" xml:space="preserve">
+    <value>正在初始化光源控制器</value>
+  </data>
 </root>

+ 8 - 0
TeamAAS-VM/TeamAAS-VP.csproj

@@ -748,6 +748,7 @@
     <Compile Include="ValueConverter\RobotConverter.cs" />
     <Compile Include="ValueConverter\RobotIdToVisibiltyConverter.cs" />
     <Compile Include="ValueConverter\StringFormatConverter.cs" />
+    <Compile Include="ViewModels\DebugMod\LightManualViewModel.cs" />
     <Compile Include="ViewModels\Setting\AddLightControllerViewModel.cs" />
     <Compile Include="ViewModels\Setting\AddPlcViewModel.cs" />
     <Compile Include="ViewModels\Product\AfagFeederParamsViewModel.cs" />
@@ -857,6 +858,9 @@
     <Compile Include="Views\DebugMod\InchingControl.xaml.cs">
       <DependentUpon>InchingControl.xaml</DependentUpon>
     </Compile>
+    <Compile Include="Views\DebugMod\LightManual.xaml.cs">
+      <DependentUpon>LightManual.xaml</DependentUpon>
+    </Compile>
     <Compile Include="Views\DebugMod\RobotManualStep.xaml.cs">
       <DependentUpon>RobotManualStep.xaml</DependentUpon>
     </Compile>
@@ -1129,6 +1133,10 @@
       <SubType>Designer</SubType>
       <Generator>MSBuild:Compile</Generator>
     </Page>
+    <Page Include="Views\DebugMod\LightManual.xaml">
+      <SubType>Designer</SubType>
+      <Generator>MSBuild:Compile</Generator>
+    </Page>
     <Page Include="Views\DebugMod\RobotManualStep.xaml">
       <SubType>Designer</SubType>
       <Generator>MSBuild:Compile</Generator>

+ 8 - 1
TeamAAS-VM/ViewModels/DebugMod/FeederManualViewModel.cs

@@ -62,7 +62,14 @@ namespace TeamAAS_VP.ViewModels.DebugMod
         #region 方法
         void ExecuteLoadedCommand()
         {
-            
+            if (_systemDatabaseService.GetCurrentUser().userPart == Enums.UserPart.Operator)
+            {
+                IsAllowEdit = false;
+            }
+            else
+            {
+                IsAllowEdit = true;
+            }
         }
 
         #endregion

+ 127 - 0
TeamAAS-VM/ViewModels/DebugMod/LightManualViewModel.cs

@@ -0,0 +1,127 @@
+using Prism.Commands;
+using Prism.Events;
+using Prism.Ioc;
+using Prism.Mvvm;
+using Prism.Regions;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using TeamAAS_VP.Core;
+using TeamAAS_VP.Data;
+using TeamAAS_VP.Events;
+using TeamAAS_VP.Interfaces;
+using TeamAAS_VP.Resources.Languages;
+
+namespace TeamAAS_VP.ViewModels.DebugMod
+{
+    public class LightManualViewModel : BindableBase
+    {
+        IContainerProvider _container;
+        IEventAggregator _eventAggregator;
+        ILightManagerService _lightManagerService;
+        IConfigService _configService;
+        ISystemDatabaseService _systemDatabaseService;
+
+        #region 属性
+
+        #endregion
+
+        #region 命令
+        private DelegateCommand _LoadedCommand;
+        public DelegateCommand LoadedCommand =>
+            _LoadedCommand ?? (_LoadedCommand = new DelegateCommand(ExecuteLoadedCommand));
+
+        
+        #endregion
+
+        #region 事件
+
+        #endregion
+
+        public LightManualViewModel(IContainerProvider container, IEventAggregator ea, ILightManagerService lightManagerService, IConfigService configService, ISystemDatabaseService systemDatabaseService)
+        {
+            _container = container;
+            _eventAggregator = ea;
+            _lightManagerService = lightManagerService;
+            _configService = configService;
+            _systemDatabaseService = systemDatabaseService;
+            //订阅权限登录事件
+            _eventAggregator.GetEvent<UserLoginNotification>().Subscribe(LoginChange);
+        }
+
+        #region 方法
+        void ExecuteLoadedCommand()
+        {
+            if (_systemDatabaseService.GetCurrentUser().userPart == Enums.UserPart.Operator)
+            {
+                IsAllowEdit = false;
+            }
+            else
+            {
+                IsAllowEdit = true;
+            }
+        }
+        #endregion
+
+        #region 继承
+        /// <summary>
+        /// 确认导航请求时调用。此方法允许您在导航之前执行一些操作。
+        /// </summary>
+        /// <param name="navigationContext"></param>
+        /// <param name="continuationCallback"></param>
+        public void ConfirmNavigationRequest(NavigationContext navigationContext, Action<bool> continuationCallback)
+        {
+            continuationCallback(true);
+        }
+
+        /// <summary>
+        /// 接收导航请求时调用。传入导航参数,包含有关导航目标的信息。
+        /// </summary>
+        /// <param name="navigationContext"></param>
+        /// <exception cref="NotImplementedException"></exception>
+        public async void OnNavigatedTo(NavigationContext navigationContext)
+        {
+            
+        }
+
+        /// <summary>
+        /// 是否允许导航到此视图模型。
+        /// </summary>
+        /// <param name="navigationContext"></param>
+        /// <returns></returns>
+        public bool IsNavigationTarget(NavigationContext navigationContext)
+        {
+            return true;
+        }
+
+        /// <summary>
+        /// 导航离开此视图模型时调用。您可以在此处执行清理操作或保存状态。
+        /// </summary>
+        /// <param name="navigationContext"></param>
+        public void OnNavigatedFrom(NavigationContext navigationContext)
+        {
+            
+        }
+        #endregion
+
+        private bool _IsAllowEdit = false;
+
+        public bool IsAllowEdit
+        {
+            get { return _IsAllowEdit; }
+            set { SetProperty(ref _IsAllowEdit, value); }
+        }
+
+        private void LoginChange(Models.User user)
+        {
+            if (user.userPart == Enums.UserPart.Operator)
+            {
+                IsAllowEdit = false;
+            }
+            else
+            {
+                IsAllowEdit = true;
+            }
+        }
+    }
+}

+ 10 - 1
TeamAAS-VM/ViewModels/DebugMod/RobotManualStepViewModel.cs

@@ -139,12 +139,21 @@ namespace TeamAAS_VP.ViewModels.DebugMod
             _robotService = robotService;
             _systemDatabaseService = systemDatabaseService;
             _configService = configService;
+            //订阅权限登录事件
+            _eventAggregator.GetEvent<UserLoginNotification>().Subscribe(LoginChange);
         }
 
         #region 方法
         void ExecuteLoadedCommand()
         {
-            
+            if (_systemDatabaseService.GetCurrentUser().userPart == Enums.UserPart.Operator)
+            {
+                IsAllowEdit = false;
+            }
+            else
+            {
+                IsAllowEdit = true;
+            }
         }
 
         /// <summary>

+ 20 - 0
TeamAAS-VM/ViewModels/DebugViewModel.cs

@@ -15,6 +15,7 @@ using TeamAAS_VP.Core;
 using TeamAAS_VP.Events;
 using TeamAAS_VP.Interfaces;
 using TeamAAS_VP.Models;
+using TeamAAS_VP.Models.Lights;
 using static System.Windows.Forms.VisualStyles.VisualStyleElement.StartPanel;
 using static System.Windows.Forms.VisualStyles.VisualStyleElement.Window;
 
@@ -73,6 +74,16 @@ namespace TeamAAS_VP.ViewModels
             get { return _FeederList; }
             set { SetProperty(ref _FeederList, value); }
         }
+
+        //光源控制器的通道集合
+        private ObservableCollection<ChannelConfig> _LightChannelController;
+        public ObservableCollection<ChannelConfig> LightChannelController
+        {
+            get { return _LightChannelController; }
+            set { SetProperty(ref _LightChannelController, value); }
+        }
+
+
         #endregion
 
         #region 命令
@@ -150,6 +161,10 @@ namespace TeamAAS_VP.ViewModels
                 {
                     _regionManager.RequestNavigate("DebugRegionContext", "ScriptHome");
                 }
+                else if (e.NewValue is TreeViewItem && ((TreeViewItem)(e.NewValue)).Name == "LightController")
+                {
+                    _regionManager.RequestNavigate("DebugRegionContext", "LightManual");
+                }
                 else if (e.NewValue is TreeViewItem && ((TreeViewItem)(e.NewValue)).Name == "FeederClear")
                 {
                     _regionManager.RequestNavigate("DebugRegionContext", "FeederClear");
@@ -192,6 +207,11 @@ namespace TeamAAS_VP.ViewModels
                 var feeders = _configService.GetAllFeeders();
                 FeederList = new ObservableCollection<FeederInfo>(feeders);
             }
+            if (LightChannelController == null)
+            {
+                var lights = _configService.GetAllLightChannels();
+                LightChannelController=new ObservableCollection<ChannelConfig>(lights);
+            }
         }
 
         /// <summary>

+ 13 - 5
TeamAAS-VM/ViewModels/MainWindowViewModel.cs

@@ -261,7 +261,7 @@ namespace TeamAAS_VP.ViewModels
             SendTaskMessage(Lang.软件启动, MessageLevel.Info);
             StartTime = DateTime.Now;
             _regionManager.RequestNavigate("MainRegionContext", "HomeView");
-            double max = 11;
+            double max = 13;
             double curvalue = 0;
             currentUser = Guid.NewGuid();
             Status.Add(new StatusInfo(currentUser, $"{Lang.当前用户}:{_systemDatabaseService.GetCurrentUser().UserName}[{_systemDatabaseService.GetCurrentUser().userPart.ToString()}]", new SolidColorBrush(Colors.White)));
@@ -312,7 +312,15 @@ namespace TeamAAS_VP.ViewModels
             }));
             await management.InitCameras();
 
-            //-------------------SETP 6: 加载所有产品-----------------------------------------------------------------------
+            //-------------------SETP 6: 初始化光源控制器-----------------------------------------------------------------------
+            curvalue += 1;
+            _ = App.Current.Dispatcher.BeginInvoke(new Action(() =>
+            {
+                _eventAggregator.GetEvent<ProgressNotification>().Publish(new UProgressBar.ProgressParameter { Maximum = max, Minimum = 0, SubTitle = $"{Lang.初始化中}...", Message = $"{Lang.正在初始化光源控制器}...", Value = curvalue });
+            }));
+            await management.InitLightControllers();
+
+            //-------------------SETP 7: 加载所有产品-----------------------------------------------------------------------
             curvalue += 1;
             _ = App.Current.Dispatcher.BeginInvoke(new Action(() =>
             {
@@ -320,7 +328,7 @@ namespace TeamAAS_VP.ViewModels
             }));
              await _productService.InitializeAsync();
 
-            //-------------------SETP 7: 开启服务器监听-----------------------------------------------------------------------
+            //-------------------SETP 8: 开启服务器监听-----------------------------------------------------------------------
             curvalue += 1;
             _ = App.Current.Dispatcher.BeginInvoke(new Action(() =>
             {
@@ -328,7 +336,7 @@ namespace TeamAAS_VP.ViewModels
             }));
             management.InitBgTcp();
 
-            //-------------------SETP 8: 开启Modbus Tcp-----------------------------------------------------------------------
+            //-------------------SETP 9: 开启Modbus Tcp-----------------------------------------------------------------------
             curvalue += 1;
             _ = App.Current.Dispatcher.BeginInvoke(new Action(() =>
             {
@@ -336,7 +344,7 @@ namespace TeamAAS_VP.ViewModels
             }));
             management.InitModbusTcp();
 
-            //-------------------SETP 9: 开启后台脚本-----------------------------------------------------------------------
+            //-------------------SETP 10: 开启后台脚本-----------------------------------------------------------------------
             curvalue += 1;
             _ = App.Current.Dispatcher.BeginInvoke(new Action(() =>
             {

+ 32 - 0
TeamAAS-VM/Views/DebugMod/LightManual.xaml

@@ -0,0 +1,32 @@
+<UserControl x:Class="TeamAAS_VP.Views.DebugMod.LightManual"
+             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+             xmlns:prism="http://prismlibrary.com/"
+             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
+             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
+             xmlns:vm="clr-namespace:TeamAAS_VP.ViewModels.DebugMod"
+             xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
+             xmlns:mah="http://metro.mahapps.com/winfx/xaml/controls"
+             xmlns:b="http://schemas.microsoft.com/xaml/behaviors"
+             xmlns:sys="clr-namespace:System;assembly=mscorlib"
+             xmlns:uControl="clr-namespace:TeamAAS_VP.Controls"
+             xmlns:convert="clr-namespace:TeamAAS_VP.ValueConverter"
+             xmlns:lex="http://wpflocalizeextension.codeplex.com"
+             lex:LocalizeDictionary.DesignCulture="zh-CN"
+             lex:ResxLocalizationProvider.DefaultAssembly="TeamAAS-VP"
+             lex:ResxLocalizationProvider.DefaultDictionary="Lang"
+             prism:ViewModelLocator.AutoWireViewModel="True"
+             mc:Ignorable="d"
+             d:Background="White"
+             d:DataContext="{d:DesignInstance Type=vm:LightManualViewModel}"
+             FontFamily="{DynamicResource DefaultFont}">
+    <b:Interaction.Triggers>
+        <b:EventTrigger EventName="Loaded">
+            <b:InvokeCommandAction Command="{Binding LoadedCommand}" />
+        </b:EventTrigger>
+    </b:Interaction.Triggers>
+    <Grid VerticalAlignment="Center"
+          IsEnabled="{Binding IsAllowEdit}">
+            
+    </Grid>
+</UserControl>

+ 15 - 0
TeamAAS-VM/Views/DebugMod/LightManual.xaml.cs

@@ -0,0 +1,15 @@
+using System.Windows.Controls;
+
+namespace TeamAAS_VP.Views.DebugMod
+{
+    /// <summary>
+    /// Interaction logic for LightManual
+    /// </summary>
+    public partial class LightManual : UserControl
+    {
+        public LightManual()
+        {
+            InitializeComponent();
+        }
+    }
+}

+ 16 - 0
TeamAAS-VM/Views/DebugView.xaml

@@ -172,6 +172,22 @@
                 </TreeViewItem.ItemTemplate>
             </TreeViewItem>
 
+            <!--光源控制器-->
+            <TreeViewItem FontWeight="Bold"
+                          IsExpanded="False"
+                          Name="LightController">
+                <TreeViewItem.Header>
+                    <StackPanel Orientation="
+                          Horizontal">
+                        <materialDesign:PackIcon Kind="
+                          TelevisionAmbientLight" />
+                        <TextBlock Text="{lex:Loc 光源控制器}"
+                                   FontSize="{DynamicResource Font.Size.Body2}"
+                                   Margin="8,0,0,0" />
+                    </StackPanel>
+                </TreeViewItem.Header>
+            </TreeViewItem>
+
             <!--Feeder清料-->
             <TreeViewItem FontWeight="Bold"
                           IsExpanded="False"