Prechádzať zdrojové kódy

增加读取PLC生产CT,修改图片保存路径,修改显示界面

KWD 2 mesiacov pred
rodič
commit
458d6cece7

+ 45 - 35
TeamAAS-VM/Core/Management.cs

@@ -156,6 +156,17 @@ namespace TeamAAS_VP.Core
             get { return _CTtime; }
             set { SetProperty(ref _CTtime, value); }
         }
+
+        private double _CTtime2;
+        /// <summary>
+        /// ct2
+        /// </summary>
+        public double CTtime2
+        {
+            get { return _CTtime2; }
+            set { SetProperty(ref _CTtime2, value); }
+        }
+
         /// <summary>
         /// 显示界面
         /// </summary>
@@ -220,25 +231,6 @@ namespace TeamAAS_VP.Core
             get { return _CurrentUPH; }
             set { SetProperty(ref _CurrentUPH, value); }
         }
-
-        private Int64 _NgNumber;
-        /// <summary>
-        /// 当前的NG数量
-        /// </summary>
-        public Int64 NgNumber
-        {
-            get { return _NgNumber; }
-            set { SetProperty(ref _NgNumber, value); }
-        }
-        private double _Yield;
-        /// <summary>
-        /// 当前的NG数量
-        /// </summary>
-        public double Yield
-        {
-            get { return _Yield; }
-            set { SetProperty(ref _Yield, value); }
-        }
         private XYD_ScrewDriver _ScrewDriver;
         public XYD_ScrewDriver ScrewDriver
         {
@@ -1376,6 +1368,7 @@ namespace TeamAAS_VP.Core
                 addressConfig.AutoRunning.Address,
                 addressConfig.ManualMode.Address,
                 addressConfig.ClearMode.Address,
+                addressConfig.WorkCt.Address,
             };
             for (int i = 0; i < 10; i++)
             {
@@ -1487,6 +1480,7 @@ namespace TeamAAS_VP.Core
         public bool _LastManualMode = false;
         bool _LastFzCameracheckExe = false;
         bool _LastClearMode = false;
+        bool _Lastworkct = false;
         Int16 _LastWorkStart = 0;
         Int16 _LastWorkDone = 0;
         Int16 _LastRequestPosition = 0;
@@ -2679,6 +2673,28 @@ namespace TeamAAS_VP.Core
                         }
                     }
                 }
+                //读取PLC生产CT
+                else if (addressConfig.WorkCt.Address.Contains(tuple.nodeId))
+                {
+                    if (tuple.value is bool state)
+                    {
+                        if (_Lastworkct != state)
+                        {
+                            _Lastworkct = state;
+                        }
+                        else
+                        {
+                            return;
+                        }
+                        if (state)
+                        {
+                            Int32 cttime = plc.ReadNode<Int32>(addressConfig.In_CycleTimeBefor.Address);
+                            SendTaskMessage($"读取PLC记录CT:{cttime}", MessageLevel.Info);
+                            CTtime2 = Convert.ToDouble(cttime);
+                        }
+                    }
+                }
+
                 // 过站检查
                 else
                 {
@@ -3175,9 +3191,9 @@ namespace TeamAAS_VP.Core
                                                     ERROR_MESSAGE = item.PhotoPassed == "OK" ? "" : $"{item.PhotoName} OOS",
                                                     PD_ATTR_01 = ProductMainSN,//
                                                     PD_ATTR_02 = item.MidLimit,
-                                                    PD_ATTR_03 = "",
+                                                    PD_ATTR_03 = CTtime.ToString(),
                                                     PD_ATTR_04 = code,
-                                                    PD_ATTR_05 = CTtime.ToString(),
+                                                    PD_ATTR_05 = CTtime2.ToString(),
                                                 });
                                             }
                                             if (stationConfig.SaveCsvkeyData)
@@ -3209,9 +3225,9 @@ namespace TeamAAS_VP.Core
                                                         ERROR_MESSAGE = ok ? "" : $"{diffvalue}",
                                                         PD_ATTR_01 = ProductMainSN,//
                                                         PD_ATTR_02 = "",
-                                                        PD_ATTR_03 = "",
+                                                        PD_ATTR_03 = CTtime.ToString(),
                                                         PD_ATTR_04 = code,
-                                                        PD_ATTR_05 = CTtime.ToString(),
+                                                        PD_ATTR_05 = CTtime2.ToString(),
                                                     });
                                                 }
                                                 foreach (var items in keyData1)
@@ -3240,9 +3256,9 @@ namespace TeamAAS_VP.Core
                                                         ERROR_MESSAGE = ok ? "" : $"{diffvalue1}",
                                                         PD_ATTR_01 = ProductMainSN,//
                                                         PD_ATTR_02 = "0.15",
-                                                        PD_ATTR_03 = "",
+                                                        PD_ATTR_03 = CTtime.ToString(),
                                                         PD_ATTR_04 = code,
-                                                        PD_ATTR_05 = CTtime.ToString(),
+                                                        PD_ATTR_05 = CTtime2.ToString(),
                                                     });
                                                 }
                                             }
@@ -5232,29 +5248,22 @@ namespace TeamAAS_VP.Core
             try
             {
                 //获取当前产品
-                CurrentProduct = _productService.GetCurrentProduct();
                 var currentproduct = _productService.GetCurrentProduct();
                 if (currentproduct == null) return;
                 TotalQuantity = await _systemDatabaseService.GetOverallProductionAsync(currentproduct.Name);
-                //TotalQuantityToday = await _systemDatabaseService.GetTodayProductionAsync(currentproduct.Name);
-                //CurrentUPH = await _systemDatabaseService.GetLastHourProductionAsync(currentproduct.Name);
-                ////
-                //NgNumber = await _systemDatabaseService.GetNGProductionAsync(currentproduct.Name);
-                //Yield = ((double)TotalQuantityToday - (double)NgNumber) / (double)TotalQuantityToday * 100;
 
                 TotalQuantityToday = 0;
                 CurrentUPH = 0;
-                NgNumber = 0;
-                Yield = 0;
+                //NgNumber = 0;
+                //Yield = 0;
                 ObservableCollection<ProductModel> ProductList = new ObservableCollection<ProductModel>(_productService.GetAllProducts());
                 foreach (var product in ProductList)
                 {
                     //TotalQuantity += await _systemDatabaseService.GetOverallProductionAsync(product.Name);
                     TotalQuantityToday += await _systemDatabaseService.GetTodayProductionAsync(product.Name);
                     CurrentUPH += await _systemDatabaseService.GetLastHourProductionAsync(product.Name);
-                    NgNumber += await _systemDatabaseService.GetNGProductionAsync(product.Name);
+                    //NgNumber += await _systemDatabaseService.GetNGProductionAsync(product.Name);
                 }
-                Yield += ((double)TotalQuantityToday - (double)NgNumber) / (double)TotalQuantityToday * 100;
             }
             catch (Exception)
             {
@@ -5262,6 +5271,7 @@ namespace TeamAAS_VP.Core
             }
         }
 
+
         #region vm启动检测
 
         /// <summary>

+ 31 - 0
TeamAAS-VM/Models/PLC/PlcAddressConfig.cs

@@ -556,6 +556,26 @@ namespace TeamAAS_VP.Models.PLC
             set { SetProperty(ref _In_FzCameraPixExe, value); }
         }
 
+        private PlcAddress _WorkCt;
+        /// <summary>
+        /// 触发读取PLC记录CT
+        /// </summary>
+        public PlcAddress WorkCt
+        {
+            get { return _WorkCt; }
+            set { SetProperty(ref _WorkCt, value); }
+        }
+
+
+        private PlcAddress _In_CycleTimeBefor = new PlcAddress();
+        /// <summary>
+        /// PLC记录CT时长
+        /// </summary>
+        public PlcAddress In_CycleTimeBefor
+        {
+            get { return _In_CycleTimeBefor; }
+            set { SetProperty(ref _In_CycleTimeBefor, value); }
+        }
         #endregion
 
         public PlcAddressConfig()
@@ -871,6 +891,17 @@ namespace TeamAAS_VP.Models.PLC
             In_FzCameraPixExe.DataType = "bool";
             In_FzCameraPixExe.Description = "翻转相机检测拍照触发";
 
+            WorkCt = Ensure(WorkCt);
+            WorkCt.Address = "ns=4;s=DB_Communication|ToPC.WorkCt";
+            WorkCt.DataType = "Bool";
+            WorkCt.Description = "触发读取PLC记录CT";
+
+            In_CycleTimeBefor = Ensure(In_CycleTimeBefor);
+            In_CycleTimeBefor.Address = "ns=4;s=DB_Communication|ToPC.CycleTimeBefor";
+            In_CycleTimeBefor.DataType = "int32";
+            In_CycleTimeBefor.Description = "PLC记录CT时长";
+
+
             // 说明:若项目中 PlcAddress 的实际属性名或类型与此不同(例如使用枚举、不同字段名),
             // 请根据实际类型调整赋值。本方法主要提供合理的默认字符串地址、数据类型及描述,便于后续从配置覆盖。
         }

+ 45 - 1
TeamAAS-VM/ViewModels/Statistics/ProductionStatementViewModel.cs

@@ -7,6 +7,7 @@ using Prism.Ioc;
 using Prism.Mvvm;
 using System;
 using System.Collections.Generic;
+using System.Collections.ObjectModel;
 using System.Linq;
 using System.Windows.Documents;
 using TeamAAS_VP.Core;
@@ -14,6 +15,7 @@ using TeamAAS_VP.Data;
 using TeamAAS_VP.Interfaces;
 using TeamAAS_VP.Models;
 using TeamAAS_VP.Resources.Languages;
+using TeamAAS_VP.Services;
 using static MaterialDesignThemes.Wpf.Theme.ToolBar;
 
 namespace TeamAAS_VP.ViewModels.Statistics
@@ -21,6 +23,7 @@ namespace TeamAAS_VP.ViewModels.Statistics
     public class ProductionStatementViewModel : BindableBase
     {
         IContainerProvider _container;
+        IProductService _productService;
         ISystemDatabaseService _systemDatabaseService;
 
         Management management;
@@ -105,6 +108,37 @@ namespace TeamAAS_VP.ViewModels.Statistics
             get { return _DayChartModel; }
             set { SetProperty(ref _DayChartModel, value); }
         }
+
+        private Int64 _ThrowNumber;
+        /// <summary>
+        /// 抛料数
+        /// </summary>
+        public Int64 ThrowNumber
+        {
+            get { return _ThrowNumber; }
+            set { SetProperty(ref _ThrowNumber, value); }
+        }
+
+        private Int64 _NgNumber;
+        /// <summary>
+        /// ng数量
+        /// </summary>
+        public Int64 NgNumber
+        {
+            get { return _NgNumber; }
+            set { SetProperty(ref _NgNumber, value); }
+        }
+
+        private double _Yield;
+        /// <summary>
+        /// 良率
+        /// </summary>
+        public double Yield
+        {
+            get { return _Yield; }
+            set { SetProperty(ref _Yield, value); }
+        }
+
         #endregion
 
         #region 命令
@@ -140,7 +174,17 @@ namespace TeamAAS_VP.ViewModels.Statistics
                MonthChartModel = CreateMonth(await _systemDatabaseService.GetMonthlyProductionByDayAndCategoryAsync(management.CurrentProduct.Name));
                 WeekChartModel = CreateWeek(await _systemDatabaseService.GetWeeklyProductionByDayAndCategoryAsync(management.CurrentProduct.Name));
                 DayChartModel = CreateDay(await _systemDatabaseService.GetDailyProductionByHourAndCategoryAsync(management.CurrentProduct.Name));
-            }));
+
+               double TotalQuantityToday2 = 0;
+               ObservableCollection<ProductModel> ProductList = new ObservableCollection<ProductModel>(_productService.GetAllProducts());
+               foreach (var product in ProductList)
+               {
+                   TotalQuantityToday2 += await _systemDatabaseService.GetTodayProductionAsync(product.Name);
+               }
+               ThrowNumber = 0;
+               NgNumber = await _systemDatabaseService.GetNGProductionAsync(management.CurrentProduct.Name);
+               Yield = (TotalQuantityToday2 - (double)NgNumber) / TotalQuantityToday2 * 100;
+           }));
 
         }
 

+ 12 - 12
TeamAAS-VM/Views/Home/ShowVisionRender.xaml.cs

@@ -659,25 +659,25 @@ namespace TeamAAS_VP.Views.Home
 
                     if (saveImageModel == ProcedureSaveImageModel.Original)
                     {
-                        string Originalpath = $"{path}\\{now:yyyy-MM}\\{now:MM-dd}\\{imgName}.bmp";
+                        string Originalpath = $"{path}\\Original\\{now:yyyy-MM}\\{now:MM-dd}\\{imgName}.bmp";
 
                         if (saveImagePathModel == ProcedureSaveImagePathModel.Month_Day_OkNG_Time)
                         {
                             Originalpath = result
-                                ? $"{path}\\{now:yyyy-MM}\\{now:MM-dd}\\OK\\{imgName}.bmp"
-                                : $"{path}\\{now:yyyy-MM}\\{now:MM-dd}\\NG\\{imgName}.bmp";
+                                ? $"{path}\\Original\\{now:yyyy-MM}\\{now:MM-dd}\\OK\\{imgName}.bmp"
+                                : $"{path}\\Original\\{now:yyyy-MM}\\{now:MM-dd}\\NG\\{imgName}.bmp";
                         }
                         else if (saveImagePathModel == ProcedureSaveImagePathModel.Month_Day_Ok_Time)
                         {
                             if (result)
-                                Originalpath = $"{path}\\{now:yyyy-MM}\\{now:MM-dd}\\OK\\{imgName}.bmp";
+                                Originalpath = $"{path}\\Original\\{now:yyyy-MM}\\{now:MM-dd}\\OK\\{imgName}.bmp";
                             else
                                 return;
                         }
                         else if (saveImagePathModel == ProcedureSaveImagePathModel.Month_Day_Ng_Time)
                         {
                             if (!result)
-                                Originalpath = $"{path}\\{now:yyyy-MM}\\{now:MM-dd}\\NG\\{imgName}.bmp";
+                                Originalpath = $"{path}\\Original\\{now:yyyy-MM}\\{now:MM-dd}\\NG\\{imgName}.bmp";
                             else
                                 return;
                         }
@@ -694,7 +694,7 @@ namespace TeamAAS_VP.Views.Home
                                 productSN = productSN.Replace(c, '_');
 
                             string resultStr = result ? "OK" : "NG";
-                            Originalpath = $"{path}\\{now:yyyy-MM}\\{now:MM-dd}\\{formulaName}\\{productSN}\\{resultStr}\\{imgName}.bmp";
+                            Originalpath = $"{path}\\Original\\{now:yyyy-MM}\\{now:MM-dd}\\{formulaName}\\{productSN}\\{resultStr}\\{imgName}.bmp";
                         }
 
                         if (!Directory.Exists(Path.GetDirectoryName(Originalpath)))
@@ -709,25 +709,25 @@ namespace TeamAAS_VP.Views.Home
                     }
                     else if (saveImageModel == ProcedureSaveImageModel.Recorded)
                     {
-                        string Recordedpath = $"{path}\\{now:yyyy-MM}\\{now:MM-dd}\\{imgName}.bmp";
+                        string Recordedpath = $"{path}\\Recored\\{now:yyyy-MM}\\{now:MM-dd}\\{imgName}.bmp";
 
                         if (saveImagePathModel == ProcedureSaveImagePathModel.Month_Day_OkNG_Time)
                         {
                             Recordedpath = result
-                                ? $"{path}\\{now:yyyy-MM}\\{now:MM-dd}\\OK\\{imgName}.bmp"
-                                : $"{path}\\{now:yyyy-MM}\\{now:MM-dd}\\NG\\{imgName}.bmp";
+                                ? $"{path}\\Recored\\{now:yyyy-MM}\\{now:MM-dd}\\OK\\{imgName}.bmp"
+                                : $"{path}\\Recored\\{now:yyyy-MM}\\{now:MM-dd}\\NG\\{imgName}.bmp";
                         }
                         else if (saveImagePathModel == ProcedureSaveImagePathModel.Month_Day_Ok_Time)
                         {
                             if (result)
-                                Recordedpath = $"{path}\\{now:yyyy-MM}\\{now:MM-dd}\\OK\\{imgName}.bmp";
+                                Recordedpath = $"{path}\\Recored\\{now:yyyy-MM}\\{now:MM-dd}\\OK\\{imgName}.bmp";
                             else
                                 return;
                         }
                         else if (saveImagePathModel == ProcedureSaveImagePathModel.Month_Day_Ng_Time)
                         {
                             if (!result)
-                                Recordedpath = $"{path}\\{now:yyyy-MM}\\{now:MM-dd}\\NG\\{imgName}.bmp";
+                                Recordedpath = $"{path}\\Recored\\{now:yyyy-MM}\\{now:MM-dd}\\NG\\{imgName}.bmp";
                             else
                                 return;
                         }
@@ -742,7 +742,7 @@ namespace TeamAAS_VP.Views.Home
                                 productSN = productSN.Replace(c, '_');
 
                             string resultStr = result ? "OK" : "NG";
-                            Recordedpath = $"{path}\\{now:yyyy-MM}\\{now:MM-dd}\\{formulaName}\\{productSN}\\{resultStr}\\{imgName}.bmp";
+                            Recordedpath = $"{path}\\Recored\\{now:yyyy-MM}\\{now:MM-dd}\\{formulaName}\\{productSN}\\{resultStr}\\{imgName}.bmp";
                         }
 
                         if (!Directory.Exists(Path.GetDirectoryName(Recordedpath)))

+ 13 - 5
TeamAAS-VM/Views/HomeView.xaml

@@ -180,7 +180,6 @@
                     <Grid.ColumnDefinitions>
                         <ColumnDefinition Width="*" />
                         <ColumnDefinition Width="*" />
-                        <ColumnDefinition Width="*" />
                     </Grid.ColumnDefinitions>
                     <!--加载产品-->
                     <materialDesign:Card Grid.Row="0"
@@ -329,7 +328,7 @@
                         </Grid>
                     </materialDesign:Card>
 
-                    <!--OK/NG-->
+                    <!--OK/NG--><!--
                     <materialDesign:Card Grid.Row="0"
                      Grid.Column="2"
                      UniformCornerRadius="10"
@@ -365,7 +364,7 @@
                         Value="CharacterEllipsis" />
                                 </Style>
                             </Grid.Resources>
-                            <TextBlock Text="{lex:Loc 抛料数,Converter={StaticResource StringFormatConverter},ConverterParameter='{}{0}: '}"
+                            --><!--<TextBlock Text="{lex:Loc 抛料数,Converter={StaticResource StringFormatConverter},ConverterParameter='{}{0}: '}"
                    HorizontalAlignment="Right"
                    TextAlignment="Right" />
                             <Border Grid.Row="0"
@@ -401,9 +400,9 @@
                 BorderThickness="1" />
                             <TextBlock Grid.Row="2"
                    Grid.Column="1"
-                   Text="{Binding management.Yield,StringFormat={}{0:F2}%}" />
+                   Text="{Binding management.Yield,StringFormat={}{0:F2}%}" />--><!--
                         </Grid>
-                    </materialDesign:Card>
+                    </materialDesign:Card>-->
                 </Grid>
 
 
@@ -416,6 +415,15 @@
                                FontSize="{DynamicResource Font.Size.Body2}"
                                VerticalAlignment="Center" />
                     <TextBlock Text="{Binding management.CTtime,StringFormat={}{0:F2} s}"
+                               FontSize="{DynamicResource Font.Size.Body3}"
+                               VerticalAlignment="Center"
+                               Margin="10,0,50,0" />
+
+                    <TextBlock Text="CT2: "
+                               FontWeight="Bold"
+                               FontSize="{DynamicResource Font.Size.Body2}"
+                               VerticalAlignment="Center" />
+                    <TextBlock Text="{Binding management.CTtime2,StringFormat={}{0:F2} s}"
                                FontSize="{DynamicResource Font.Size.Body3}"
                                VerticalAlignment="Center"
                                Margin="10,0" />

+ 39 - 0
TeamAAS-VM/Views/Statistics/ProductionStatement.xaml

@@ -47,6 +47,9 @@
                     <RowDefinition Height="auto" />
                     <RowDefinition Height="auto" />
                     <RowDefinition Height="auto" />
+                    <RowDefinition Height="auto" />
+                    <RowDefinition Height="auto" />
+                    <RowDefinition Height="auto" />
                 </Grid.RowDefinitions>
                 <oxy:PlotView Grid.Row="0"
                               Grid.Column="0"
@@ -103,6 +106,42 @@
                          TextAlignment="Center"
                          BorderThickness="1"
                          Margin="5" />
+                <TextBlock Grid.Row="5"
+                           Text="{lex:Loc 抛料数,Converter={StaticResource StringFormatConverter},ConverterParameter='{}{0}: '}"
+                           VerticalAlignment="Center"
+                           Margin="5" />
+                <TextBox Grid.Row="5"
+                         Grid.Column="1"
+                         Text="{Binding ThrowNumber}"
+                         IsReadOnly="True"
+                         BorderBrush="Gray"
+                         TextAlignment="Center"
+                         BorderThickness="1"
+                         Margin="5" />
+                <TextBlock Grid.Row="6"
+                           Text="{lex:Loc NG数量,Converter={StaticResource StringFormatConverter},ConverterParameter='{}{0}: '}"
+                           VerticalAlignment="Center"
+                           Margin="5" />
+                <TextBox Grid.Row="6"
+                         Grid.Column="1"
+                         Text="{Binding NgNumber}"
+                         IsReadOnly="True"
+                         BorderBrush="Gray"
+                         TextAlignment="Center"
+                         BorderThickness="1"
+                         Margin="5" />
+                <TextBlock Grid.Row="7"
+                           Text="{lex:Loc 良率,Converter={StaticResource StringFormatConverter},ConverterParameter='{}{0}: '}"
+                           VerticalAlignment="Center"
+                           Margin="5" />
+                <TextBox Grid.Row="7"
+                         Grid.Column="1"
+                         Text="{Binding Yield,StringFormat={}{0:F2}%}"
+                         IsReadOnly="True"
+                         BorderBrush="Gray"
+                         TextAlignment="Center"
+                         BorderThickness="1"
+                         Margin="5" />
             </Grid>
             <Button Content="{lex:Loc 生成报表}"
                     Margin="10"