Selaa lähdekoodia

优化加载产品程序

zly 4 kuukautta sitten
vanhempi
sitoutus
7c154faba0

+ 26 - 0
TeamAAS-VM/Core/Management.cs

@@ -1400,7 +1400,23 @@ namespace TeamAAS_VP.Core
                 monitorNodeIds.Add(string.Format(addressConfig.In_MesCheck.Address, i));
                 monitorNodeIds.Add(string.Format(addressConfig.In_MesCheck.Address, i));
             }
             }
             //订阅PLC地址变化
             //订阅PLC地址变化
+            //plc.SubscribeNodes("AutoSensor", monitorNodeIds, PlcCommandTrigger, OpcUaSubscriptionMode.CustomPolling);
+            // 1. 初始订阅(使用原生模式)
             plc.SubscribeNodes("AutoSensor", monitorNodeIds, PlcCommandTrigger, OpcUaSubscriptionMode.CustomPolling);
             plc.SubscribeNodes("AutoSensor", monitorNodeIds, PlcCommandTrigger, OpcUaSubscriptionMode.CustomPolling);
+
+            // 2. 监听重连事件,重连成功后自动重新订阅
+            plc.ConnectChangedEvent -= Plc_ConnectChanged; // 防止重复注册
+            plc.ConnectChangedEvent += Plc_ConnectChanged;
+
+            // 定义重连处理方法(写在同一个类里即可)
+            void Plc_ConnectChanged(object sender, bool isConnected)
+            {
+                if (isConnected)
+                {
+                    // 重连成功后,重新订阅节点
+                    plc.SubscribeNodes("AutoSensor", monitorNodeIds, PlcCommandTrigger, OpcUaSubscriptionMode.CustomPolling);
+                }
+            }
         }
         }
 
 
         /// <summary>
         /// <summary>
@@ -1778,6 +1794,8 @@ namespace TeamAAS_VP.Core
                                         }
                                         }
                                         if (currentProduct.ID != productId || productWithMes.ProductKBSN != kb_sn)
                                         if (currentProduct.ID != productId || productWithMes.ProductKBSN != kb_sn)
                                         {
                                         {
+
+                                            _productService.Clear();
                                             //切换产品
                                             //切换产品
                                             _productService.LoadProduct(productId);
                                             _productService.LoadProduct(productId);
                                             _productService.SetCurrentProduct(productId);
                                             _productService.SetCurrentProduct(productId);
@@ -2459,6 +2477,8 @@ namespace TeamAAS_VP.Core
                     }
                     }
                 }
                 }
 
 
+                //翻转相机检测拍照
+
                 //切换成自动运行模式
                 //切换成自动运行模式
                 else if (addressConfig.AutoRunning.Address.Contains(tuple.nodeId))
                 else if (addressConfig.AutoRunning.Address.Contains(tuple.nodeId))
                 {
                 {
@@ -2968,6 +2988,11 @@ namespace TeamAAS_VP.Core
                                                 }
                                                 }
                                             }
                                             }
 
 
+                                        //测试使用,强制上传mes为pass
+                                        //if (sysConfig.IsMesResult)
+                                        //{
+                                        //    resultToMes.Clear();
+                                        //}
                                             bool recordResult = RecordStationResult(i, DFC, ProductMainSN, serverTimeResult.Now.Subtract(_LastMesCheckTime[i]).TotalSeconds, _LastMesCheckTime[i], stationConfig.SaveCsvPath);
                                             bool recordResult = RecordStationResult(i, DFC, ProductMainSN, serverTimeResult.Now.Subtract(_LastMesCheckTime[i]).TotalSeconds, _LastMesCheckTime[i], stationConfig.SaveCsvPath);
                                             // bool recordResult1 = WriteProductLog( ProductMainSN, serverTimeResult.Now.Subtract(_LastMesCheckTime[i]).TotalSeconds, _LastMesCheckTime[i], stationConfig.SaveCsvPath, DFC);
                                             // bool recordResult1 = WriteProductLog( ProductMainSN, serverTimeResult.Now.Subtract(_LastMesCheckTime[i]).TotalSeconds, _LastMesCheckTime[i], stationConfig.SaveCsvPath, DFC);
 
 
@@ -3905,6 +3930,7 @@ namespace TeamAAS_VP.Core
             }
             }
         }
         }
 
 
+
         #region 键盘相邻关系
         #region 键盘相邻关系
         /// <summary>
         /// <summary>
         /// 键盘相邻关系-US
         /// 键盘相邻关系-US

+ 2 - 0
TeamAAS-VM/Interfaces/IProductService.cs

@@ -11,6 +11,8 @@ namespace TeamAAS_VP.Interfaces
     /// </summary>
     /// </summary>
     public interface IProductService : IDisposable
     public interface IProductService : IDisposable
     {
     {
+
+        void Clear();
         /// <summary>
         /// <summary>
         /// ľąÇ°˛úơąŕşĹ
         /// ľąÇ°˛úơąŕşĹ
         /// </summary>
         /// </summary>

+ 10 - 0
TeamAAS-VM/Models/Product/ProductModel.cs

@@ -176,6 +176,16 @@ namespace TeamAAS_VP.Models
             set { SetProperty(ref _FixedDownCameraProcedureId, value); }
             set { SetProperty(ref _FixedDownCameraProcedureId, value); }
         }
         }
 
 
+        private Guid _FzCameraProcedureId;
+        /// <summary>
+        /// 翻转相机流程ID
+        /// </summary>
+        public Guid FzCameraProcedureId
+        {
+            get { return _FzCameraProcedureId; }
+            set { SetProperty(ref _FzCameraProcedureId, value); }
+        }
+
         private Guid _MoveDownCameraLockPhotoProcedureId;
         private Guid _MoveDownCameraLockPhotoProcedureId;
         /// <summary>
         /// <summary>
         /// 移动向下相机锁付拍照流程ID
         /// 移动向下相机锁付拍照流程ID

+ 23 - 2
TeamAAS-VM/Services/ProductService.cs

@@ -3,6 +3,7 @@ using Cognex.VisionPro.ToolBlock;
 using Newtonsoft.Json;
 using Newtonsoft.Json;
 using NPOI.SS.Formula.Functions;
 using NPOI.SS.Formula.Functions;
 using System;
 using System;
+using System.Collections.Concurrent;
 using System.Collections.Generic;
 using System.Collections.Generic;
 using System.IO;
 using System.IO;
 using System.Linq;
 using System.Linq;
@@ -29,6 +30,7 @@ namespace TeamAAS_VP.Services
         private Guid _currentProduct = Guid.Empty;
         private Guid _currentProduct = Guid.Empty;
         IConfigService _configService;
         IConfigService _configService;
         IFeederService _feederService;
         IFeederService _feederService;
+        private static readonly ConcurrentDictionary<string, CogToolBlock> _vppCache = new ConcurrentDictionary<string, CogToolBlock>();
 
 
         // 可配置的路径与文件名
         // 可配置的路径与文件名
         // 默认把产品放到公共应用数据目录下的 TeamAAS\Products
         // 默认把产品放到公共应用数据目录下的 TeamAAS\Products
@@ -70,6 +72,13 @@ namespace TeamAAS_VP.Services
             ProductsRootPath = DefaultProductsSubPath;
             ProductsRootPath = DefaultProductsSubPath;
         }
         }
 
 
+        public void Clear()
+        {
+            _currentProduct = Guid.Empty;
+
+            _vppCache.Clear();
+        }
+
         /// <summary>
         /// <summary>
         /// 初始化服务:清空内存产品并从磁盘枚举并加载产品清单(仅读取 JSON 配置,不加载所有视觉 ToolBlock)。
         /// 初始化服务:清空内存产品并从磁盘枚举并加载产品清单(仅读取 JSON 配置,不加载所有视觉 ToolBlock)。
         /// </summary>
         /// </summary>
@@ -517,15 +526,27 @@ namespace TeamAAS_VP.Services
             var dir = Path.GetDirectoryName(filePath);
             var dir = Path.GetDirectoryName(filePath);
             if (!Directory.Exists(dir)) Directory.CreateDirectory(dir);
             if (!Directory.Exists(dir)) Directory.CreateDirectory(dir);
 
 
+            //foreach (var camera in p.CameraProcedures)
+            //{
+            //    foreach (var prc in camera.ProcedureModels)
+            //    {
+            //        string prcPath = Path.Combine(dir, camera.Camera, prc.Name + ".vpp");
+            //        prc.ToolBlock = CogSerializer.LoadObjectFromFile(prcPath) as CogToolBlock;
+            //    }
+            //}
+
             foreach (var camera in p.CameraProcedures)
             foreach (var camera in p.CameraProcedures)
             {
             {
                 foreach (var prc in camera.ProcedureModels)
                 foreach (var prc in camera.ProcedureModels)
                 {
                 {
                     string prcPath = Path.Combine(dir, camera.Camera, prc.Name + ".vpp");
                     string prcPath = Path.Combine(dir, camera.Camera, prc.Name + ".vpp");
-                    prc.ToolBlock = CogSerializer.LoadObjectFromFile(prcPath) as CogToolBlock;
+
+                    prc.ToolBlock = _vppCache.GetOrAdd(prcPath, path =>
+                    {
+                        return CogSerializer.LoadObjectFromFile(path) as CogToolBlock;
+                    });
                 }
                 }
             }
             }
-
             return p;
             return p;
         }
         }
 
 

+ 21 - 0
TeamAAS-VM/ViewModels/Product/ProductParamsViewModel.cs

@@ -118,6 +118,23 @@ namespace TeamAAS_VP.ViewModels.Product
             }
             }
         }
         }
 
 
+        private ProcedureModel _FzCameraProcedure;
+        /// <summary>
+        /// 翻转相机流程ID
+        /// </summary>
+        public ProcedureModel FzCameraProcedure
+        {
+            get { return _FzCameraProcedure; }
+            set
+            {
+                SetProperty(ref _FzCameraProcedure, value);
+                if (value != null)
+                {
+                    SelectProduct.FzCameraProcedureId = value.Id;
+                }
+            }
+        }
+
         private ProcedureModel _MoveDownCameraLockPhotoProcedure;
         private ProcedureModel _MoveDownCameraLockPhotoProcedure;
         /// <summary>
         /// <summary>
         /// 移动向下相机锁付拍照流程ID
         /// 移动向下相机锁付拍照流程ID
@@ -308,6 +325,10 @@ namespace TeamAAS_VP.ViewModels.Product
                 {
                 {
                     FixedDownCameraProcedure = ProcedureModels.FirstOrDefault(p => p.Id == SelectProduct.FixedDownCameraProcedureId);
                     FixedDownCameraProcedure = ProcedureModels.FirstOrDefault(p => p.Id == SelectProduct.FixedDownCameraProcedureId);
                 }
                 }
+                if (SelectProduct.FzCameraProcedureId != Guid.Empty)
+                {
+                    FzCameraProcedure = ProcedureModels.FirstOrDefault(p => p.Id == SelectProduct.FzCameraProcedureId);
+                }
                 if (SelectProduct.MoveDownCameraLockPhotoProcedureId != Guid.Empty)
                 if (SelectProduct.MoveDownCameraLockPhotoProcedureId != Guid.Empty)
                 {
                 {
                     MoveDownCameraLockPhotoProcedure = ProcedureModels.FirstOrDefault(p => p.Id == SelectProduct.MoveDownCameraLockPhotoProcedureId);
                     MoveDownCameraLockPhotoProcedure = ProcedureModels.FirstOrDefault(p => p.Id == SelectProduct.MoveDownCameraLockPhotoProcedureId);

+ 7 - 6
TeamAAS-VM/Views/Product/ProductParams.xaml

@@ -122,6 +122,7 @@
                         <RowDefinition Height="auto" />
                         <RowDefinition Height="auto" />
                         <RowDefinition Height="auto" />
                         <RowDefinition Height="auto" />
                         <RowDefinition Height="auto" />
                         <RowDefinition Height="auto" />
+                        <RowDefinition Height="auto" />
                     </Grid.RowDefinitions>
                     </Grid.RowDefinitions>
                     <Grid.ColumnDefinitions>
                     <Grid.ColumnDefinitions>
                         <ColumnDefinition Width="auto" />
                         <ColumnDefinition Width="auto" />
@@ -358,14 +359,14 @@ materialDesign:HintAssist.Hint="{lex:Loc 选择需要配置的流程}"
                             </DataTemplate>
                             </DataTemplate>
                         </ComboBox.ItemTemplate>
                         </ComboBox.ItemTemplate>
                     </ComboBox>
                     </ComboBox>
-                    <!--固定向下相机取料流程--><!--
-                    <TextBlock Grid.Row="3"
+                    <!--翻转相机流程id-->
+                    <TextBlock Grid.Row="7"
                                Grid.Column="0"
                                Grid.Column="0"
-                               Text="固定向下相机取料流程ID: " />
-                    <ComboBox Grid.Row="3"
+                               Text="翻转相机流程ID: " />
+                    <ComboBox Grid.Row="7"
                               Grid.Column="1"
                               Grid.Column="1"
                               ItemsSource="{Binding ProcedureModels}"
                               ItemsSource="{Binding ProcedureModels}"
-                              SelectedItem="{Binding FixedDownCameraProcedure}"
+                              SelectedItem="{Binding FzCameraProcedure}"
                               materialDesign:TextFieldAssist.HasClearButton="True"
                               materialDesign:TextFieldAssist.HasClearButton="True"
                               materialDesign:HintAssist.Hint="{lex:Loc 选择需要配置的流程}">
                               materialDesign:HintAssist.Hint="{lex:Loc 选择需要配置的流程}">
                         <ComboBox.ItemTemplate>
                         <ComboBox.ItemTemplate>
@@ -381,7 +382,7 @@ materialDesign:HintAssist.Hint="{lex:Loc 选择需要配置的流程}"
                             </DataTemplate>
                             </DataTemplate>
                         </ComboBox.ItemTemplate>
                         </ComboBox.ItemTemplate>
                     </ComboBox>
                     </ComboBox>
-                    --><!--移动向下相机锁付拍照流程--><!--
+                    <!--移动向下相机锁付拍照流程--><!--
                     <TextBlock Grid.Row="4"
                     <TextBlock Grid.Row="4"
                                Grid.Column="0"
                                Grid.Column="0"
                                Text="移动向下相机锁付拍照流程ID: " />
                                Text="移动向下相机锁付拍照流程ID: " />