Explorar o código

增加3d aoi旁边人工站的区分

KWD hai 3 meses
pai
achega
7d44cd9120

+ 34 - 4
TeamAAS-VM/Core/Management.cs

@@ -1675,6 +1675,7 @@ namespace TeamAAS_VP.Core
                             catch { }
                             var sysConfig = _configService.GetSystemConfiguration();
 
+                            #region 扫码枪扫码
                             if (sysConfig.ScannerUse == true && cameraIndex == 1 && sysConfig.CodeUse2 == true)
                             {
                                 ScanValue = "";
@@ -1950,6 +1951,7 @@ namespace TeamAAS_VP.Core
                                 }
                                 return;
                             }
+                            #endregion
 
                             if (procIds.Count == 0 && cameraIndex != currentProduct.PhotoCountStop)
                             {
@@ -2010,7 +2012,7 @@ namespace TeamAAS_VP.Core
                                 }));
                             }
 
-
+                            #region 相机扫码
                             if (sysConfig.CodeUse == true && cameraIndex == 1)
                             {
                                 var cts = new CancellationTokenSource();
@@ -2100,6 +2102,7 @@ namespace TeamAAS_VP.Core
                                                 {
                                                     ProductMainSN = snItem.Replace("sn=", "").Trim();
                                                     _productService.CurrentProductCode = ProductMainSN;
+                                                    await plc.WriteNodeAsync<string>(string.Format(addressConfig.In_Code.Address, 0), ProductMainSN);
                                                     SendTaskMessage($"产品主sn:{ProductMainSN}", MessageLevel.Info);
                                                 }
                                                 string woItem = item.FirstOrDefault(f => f.Contains("wo="));
@@ -2172,7 +2175,15 @@ namespace TeamAAS_VP.Core
                                         {
                                             LogHelper.WriteLogMes($"第二次询问mes失败");
                                             SendTaskMessage($"第二次询问mes失败:{response2}", MessageLevel.Error);
-
+                                            string[] item = response2.Split('\n');
+                                            string snItem = item.FirstOrDefault(f => f.Contains("sn="));
+                                            if (snItem != null)
+                                            {
+                                                ProductMainSN = snItem.Replace("sn=", "").Trim();
+                                                _productService.CurrentProductCode = ProductMainSN;
+                                                await plc.WriteNodeAsync<string>(string.Format(addressConfig.In_Code.Address, 0), ProductMainSN);
+                                                SendTaskMessage($"产品主sn:{ProductMainSN}", MessageLevel.Info);
+                                            }
                                             await plc.WriteNodeAsync(addressConfig.Out_FixedCameraPickStatus.Address, (Int16)3);
                                         }
                                     }
@@ -2259,6 +2270,7 @@ namespace TeamAAS_VP.Core
                                             {
                                                 ProductMainSN = snItem.Replace("sn=", "").Trim();
                                                 _productService.CurrentProductCode = ProductMainSN;
+                                                await plc.WriteNodeAsync<string>(string.Format(addressConfig.In_Code.Address, 0), ProductMainSN);
                                                 SendTaskMessage($"产品主sn:{ProductMainSN}", MessageLevel.Info);
                                             }
                                             string woItem = items.FirstOrDefault(f => f.Contains("wo="));
@@ -2333,7 +2345,16 @@ namespace TeamAAS_VP.Core
                                         //产品发生改变并且供料器发生了变化时,需要通知PLC进行取料更改
 
                                         await plc.WriteNodeAsync(addressConfig.Out_FixedCameraPickStatus.Address, (Int16)3);
+                                        string[] items = response.Split('\n');
 
+                                        string snItem = items.FirstOrDefault(f => f.Contains("sn="));
+                                        if (snItem != null)
+                                        {
+                                            ProductMainSN = snItem.Replace("sn=", "").Trim();
+                                            _productService.CurrentProductCode = ProductMainSN;
+                                            await plc.WriteNodeAsync<string>(string.Format(addressConfig.In_Code.Address, 0), ProductMainSN);
+                                            SendTaskMessage($"产品主sn:{ProductMainSN}", MessageLevel.Info);
+                                        }
                                         LogHelper.WriteLogMes($"询问mes失败");
                                         SendTaskMessage($"询问mes失败:{response}", MessageLevel.Error);
                                     }
@@ -2345,6 +2366,8 @@ namespace TeamAAS_VP.Core
                                 }
                                 return;
                             }
+                            #endregion
+
 
                             //不能使用全局变量,不然并发的时候会被清除掉,所以局部变量
                             var _ImageTaskList = new List<Task<(bool IsSucceed, ICogImage[] Images, string Message, int cameraIndex, Guid procedureId)>>();
@@ -2685,6 +2708,11 @@ namespace TeamAAS_VP.Core
                                 {
                                     code = plc.ReadNode<string>(string.Format(addressConfig.In_Code.Address, i));
                                 }
+                                if (sysConfig.IsManual && i == 1)
+                                {
+                                    return;
+                                }
+
                                 //var homeview = _container.Resolve<HomeViewModel>();
                                 if (i == 0)
                                 {
@@ -2823,7 +2851,7 @@ namespace TeamAAS_VP.Core
                                                         }
                                                     }
                                                     catch (Exception ex)
-                                                    { SendTaskMessage($"切换产品异常"+ex.Message, MessageLevel.Error); }
+                                                    { SendTaskMessage($"切换产品异常" + ex.Message, MessageLevel.Error); }
                                                 }
                                             }
                                             await plc.WriteNodeAsync(string.Format(addressConfig.Out_MesStatus.Address, i), (Int16)1);
@@ -2910,7 +2938,9 @@ namespace TeamAAS_VP.Core
                                         //{
                                         //    submitData.Append($"{item.PhotoName}={item.ResultData}");
                                         //}
-                                        string data = $"{item.PhotoName}={item.ResultData}&";
+                                        string PhotoName = item.PhotoName.Replace("?", "%3F").Replace("#", "%23").Replace("+", "%2B").Replace("/", "%2F").Replace("%", "%25");
+                                        string data = $"{PhotoName}={item.ResultData}&";
+                                        //string data = $"{item.PhotoName}={item.ResultData}&";
 
                                         // 按顺序填满,不超过 3500 就加进去
                                         if (submitData.Length + data.Length <= 3500)

+ 18 - 0
TeamAAS-VM/Models/SystemConfiguration.cs

@@ -532,6 +532,24 @@ namespace TeamAAS_VP.Models
             set => SetProperty(ref _iouThreshold, value);
         }
 
+        private bool _IsManual;
+        /// <summary>
+        /// 是否有人工站
+        /// </summary>
+        public bool IsManual
+        {
+            get => _IsManual;
+            set => SetProperty(ref _IsManual, value);
+        }
 
+        private double _PermissionIdleTimeout = 0;
+        /// <summary>
+        ///  工程师和管理员权限的无操作超时时长
+        /// </summary>
+        public double PermissionIdleTimeout
+        {
+            get => _PermissionIdleTimeout;
+            set => SetProperty(ref _PermissionIdleTimeout, value);
+        }
     }
 }

+ 6 - 1
TeamAAS-VM/ViewModels/MainWindowViewModel.cs

@@ -69,7 +69,7 @@ namespace TeamAAS_VP.ViewModels
         /// 工程师和管理员权限的无操作超时时长。
         /// 超过该时长后自动切回操作员权限。
         /// </summary>
-        private readonly TimeSpan PermissionIdleTimeout = TimeSpan.FromMinutes(0.5);
+        private TimeSpan PermissionIdleTimeout = TimeSpan.FromMinutes(0.5);
 
         /// <summary>
         /// 权限空闲检测计时器。
@@ -265,6 +265,11 @@ namespace TeamAAS_VP.ViewModels
         {
             // 1. 读取配置参数
             _configService.LoadAll();
+
+            //if (_regionManager != null && _configService.GetSystemConfiguration().PermissionIdleTimeout > 0)
+            //{
+            //    PermissionIdleTimeout = TimeSpan.FromMinutes(_configService.GetSystemConfiguration().PermissionIdleTimeout);
+            //}
             // 2. 加载校准
             _calibrationService.LoadAll();
 

+ 72 - 1
TeamAAS-VM/ViewModels/Product/AdvancedProcedureViewModel.cs

@@ -1,4 +1,6 @@
-using Cognex.VisionPro.ToolBlock;
+using Cognex.VisionPro;
+using Cognex.VisionPro.ToolBlock;
+using MaterialDesignThemes.Wpf;
 using OpenCvSharp;
 using Prism.Commands;
 using Prism.Events;
@@ -19,6 +21,7 @@ using System.Windows.Media.Media3D;
 using Team.FFFeederService;
 using Team.FFFeederService.Interfaces;
 using TeamAAS_VP;
+using TeamAAS_VP.Controls;
 using TeamAAS_VP.Core;
 using TeamAAS_VP.Core.Lights;
 using TeamAAS_VP.Enums;
@@ -94,6 +97,16 @@ namespace TeamAAS_VP.ViewModels.Product
             get { return _Message; }
             set { SetProperty(ref _Message, value); }
         }
+
+        /// <summary>
+        /// 模板 ToolBlock 的默认路径,用于在产品不存在视觉工具文件时进行初始化。
+        /// </summary>
+        public const string TemplateToolBlock = "..//Vision Template//TemplateToolBlock.vpp";
+
+        /// <summary>
+        /// 默认产品路径的相对子目录(相对于应用运行目录或配置指定的根)。
+        /// </summary>
+        public const string DefaultProductsSubPath = "..//Products";
         #endregion
 
         #region 命令
@@ -113,6 +126,11 @@ namespace TeamAAS_VP.ViewModels.Product
         public DelegateCommand RunVisionProcessCommand =>
             _RunVisionProcessCommand ?? (_RunVisionProcessCommand = new DelegateCommand(async () => await ExecuteRunVisionProcessCommand()));
 
+        private DelegateCommand _SaveRunVisionVPPCommand;
+        public DelegateCommand SaveRunVisionVPPCommand =>
+            _SaveRunVisionVPPCommand ?? (_SaveRunVisionVPPCommand = new DelegateCommand(async () => await ExecuteSaveRunVisionVPPCommand()));
+
+
         private DelegateCommand _VisionStaticAccuracyAnalyzerCommand;
         public DelegateCommand VisionStaticAccuracyAnalyzerCommand =>
             _VisionStaticAccuracyAnalyzerCommand ?? (_VisionStaticAccuracyAnalyzerCommand = new DelegateCommand(ExecuteVisionStaticAccuracyAnalyzerCommand));
@@ -210,6 +228,59 @@ namespace TeamAAS_VP.ViewModels.Product
             }
         }
 
+
+        /// <summary>
+        /// 保存Vpp
+        /// </summary>
+        /// <returns></returns>
+        async Task ExecuteSaveRunVisionVPPCommand()
+        {
+            try
+            {
+
+                if (MessageBox.Show(Lang.是否保存产品.Replace("[{0}]", ""), Lang.保存产品, MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
+                {
+                    var waiting = new WaitingControl();
+
+                    var task = DialogHost.Show(waiting, "RootDialog", null, null, null);
+                    string prcPath = DefaultProductsSubPath + "//" + SelectProduct.Name + "//" + SelectProcedure.CameraName + "//" + SelectProcedure.Name + ".vpp";
+                    var prcDir = Path.GetDirectoryName(prcPath);
+                    if (!Directory.Exists(prcDir))
+                    {
+                        Directory.CreateDirectory(prcDir);
+                    }
+
+                    // 【关键修复】如果目标 vpp 已存在(例如 CopyProduct 刚复制过来),则不再用模板/ToolBlock 覆盖它
+                    if (File.Exists(prcPath))
+                    {
+                        if (SelectProcedure.ToolBlock == null)
+                        {
+                            SelectProcedure.ToolBlock = CogSerializer.LoadObjectFromFile(prcPath) as CogToolBlock;
+                        }
+                    }
+                    if (SelectProcedure.ToolBlock != null)
+                    {
+                        CogSerializer.SaveObjectToFile(SelectProcedure.ToolBlock, prcPath);
+                    }
+                    else if (File.Exists(TemplateToolBlock))
+                    {
+                        SelectProcedure.ToolBlock = CogSerializer.LoadObjectFromFile(TemplateToolBlock) as CogToolBlock;
+                        CogSerializer.SaveObjectToFile(SelectProcedure.ToolBlock, prcPath);
+                    }
+                    if (DialogHost.IsDialogOpen("RootDialog"))
+                    {
+                        DialogHost.Close("RootDialog");
+                    }
+                    await task;
+                    MessageBox.Show($"保存{SelectProcedure.Name}VPP成功");
+                }
+            }
+            catch (Exception ex)
+            {
+                MessageBox.Show($"保存VPP异常{ex.Message}");
+            }
+        }
+
         async Task ExecuteRunVisionProcessCommand()
         {
             try

+ 12 - 0
TeamAAS-VM/Views/Product/AdvancedProcedure.xaml

@@ -131,6 +131,18 @@
                                    VerticalAlignment="Center"
                                    Foreground="Gray" />
                     </StackPanel>
+
+                    <!--<StackPanel Grid.Row="1" 
+                                Margin="5,3"
+                                HorizontalAlignment="Center"
+                                VerticalAlignment="Center"
+                                Orientation="Horizontal">
+                        <Button Content="保存VPP"
+                                Width="100"
+                                Command="{Binding SaveRunVisionVPPCommand}" />
+                    </StackPanel>-->
+
+
                     <Button Grid.Row="1"
     Margin="5,3"
     HorizontalAlignment="Right"