From 74c921634775c5dc36441e7fdce02ba4c12f88ce Mon Sep 17 00:00:00 2001 From: liuwf Date: Thu, 25 Apr 2024 13:57:37 +0800 Subject: [PATCH] =?UTF-8?q?change-=E9=92=A3=E9=87=91=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ViewModels/IndexPageViewModel.cs | 31 ++++++++++-- .../Views/SplitPlanView.xaml | 2 +- .../Views/SplitPlanView.xaml.cs | 13 ++++- Aucma.Core.SheetMetal/appsettings.json | 2 +- .../AucamSheetMetalTaskService.cs | 49 +++++++++++++++++-- Aucma.Core.SheetMetalTasks/Models/Bin.cs | 4 ++ 6 files changed, 91 insertions(+), 10 deletions(-) diff --git a/Aucma.Core.SheetMetal/ViewModels/IndexPageViewModel.cs b/Aucma.Core.SheetMetal/ViewModels/IndexPageViewModel.cs index 32b6c51..0e0f761 100644 --- a/Aucma.Core.SheetMetal/ViewModels/IndexPageViewModel.cs +++ b/Aucma.Core.SheetMetal/ViewModels/IndexPageViewModel.cs @@ -475,12 +475,35 @@ namespace Aucma.Core.SheetMetal.ViewModels int id = Convert.ToInt32(Id); ExecutePlanInfo executionPlanInfo = _taskExecutionPlanInfoServices.FirstAsync(s => s.ObjId == id).Result; - if (executionPlanInfo.PlanAmount == executionPlanInfo.CompleteAmount) + + if (executionPlanInfo.ExecuteStatus != 2) { - MessageBox.Show("执行计划已经完成,不可以删除!", "系统信息"); - return; - } + // 未下发任务直接删除,已经下发的任务隐式删除 + bool result1 = false; + if (executionPlanInfo.CompleteAmount==0) + { + result1 = await _taskExecutionPlanInfoServices.DeleteAsync(executionPlanInfo); + } + else + { + executionPlanInfo.IsFlag = 1; + result1 = await _taskExecutionPlanInfoServices.UpdateAsync(executionPlanInfo); + } + + if (result1) + { + PlanInfoDataGrid.Clear(); + await LoadData(); + MessageBox.Show("执行计划删除成功", "系统信息"); + return; + } + else + { + MessageBox.Show("执行计划删除失败", "系统信息"); + return; + } + } if (executionPlanInfo.PlanType == 1) { var obj_sidePanel = PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("SidePanelPlc")); diff --git a/Aucma.Core.SheetMetal/Views/SplitPlanView.xaml b/Aucma.Core.SheetMetal/Views/SplitPlanView.xaml index 81f678b..57ff542 100644 --- a/Aucma.Core.SheetMetal/Views/SplitPlanView.xaml +++ b/Aucma.Core.SheetMetal/Views/SplitPlanView.xaml @@ -219,7 +219,7 @@ - + diff --git a/Aucma.Core.SheetMetal/Views/SplitPlanView.xaml.cs b/Aucma.Core.SheetMetal/Views/SplitPlanView.xaml.cs index 26e80e8..0cfcda3 100644 --- a/Aucma.Core.SheetMetal/Views/SplitPlanView.xaml.cs +++ b/Aucma.Core.SheetMetal/Views/SplitPlanView.xaml.cs @@ -27,7 +27,18 @@ namespace Aucma.Core.SheetMetal.Views private void dgvMH_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { - planInfoEditViewModel.MouseClick(sender); + // 检查是否有单选框被选中 + if (!status1.IsChecked.HasValue || !status2.IsChecked.HasValue || !status3.IsChecked.HasValue || + !(status1.IsChecked.Value || status2.IsChecked.Value || status3.IsChecked.Value)) + { + // 如果没有单选框被选中,则触发提醒弹框 + MessageBox.Show("请至少选择一个执行类型!", "提醒", MessageBoxButton.OK, MessageBoxImage.Warning); + } + else + { + // 至少有一个单选框被选中,执行正常逻辑 + planInfoEditViewModel.MouseClick(sender); + } } private void queryParam_PreviewMouseDoubleClick(object sender, MouseButtonEventArgs e) diff --git a/Aucma.Core.SheetMetal/appsettings.json b/Aucma.Core.SheetMetal/appsettings.json index 00e9590..10a913a 100644 --- a/Aucma.Core.SheetMetal/appsettings.json +++ b/Aucma.Core.SheetMetal/appsettings.json @@ -142,7 +142,7 @@ "EquipName": "BackPanelPLC", "PlcType": "Melsec", "Enabled": true, - // "IP": "127.0.0.1", + // "IP": "127.0.0.1", "IP": "10.10.91.6", "Port": 5553 } diff --git a/Aucma.Core.SheetMetalTasks/AucamSheetMetalTaskService.cs b/Aucma.Core.SheetMetalTasks/AucamSheetMetalTaskService.cs index af5574d..75c7c4a 100644 --- a/Aucma.Core.SheetMetalTasks/AucamSheetMetalTaskService.cs +++ b/Aucma.Core.SheetMetalTasks/AucamSheetMetalTaskService.cs @@ -7,6 +7,7 @@ using Aucma.Core.HwPLc; using log4net; using Aucma.Core.SheetMetalTasks.Models; using StackExchange.Profiling.Internal; +using NetTaste; namespace Aucma.Core.SheetMetalTasks { @@ -191,6 +192,13 @@ namespace Aucma.Core.SheetMetalTasks Console.WriteLine($"【{DateTime.Now.ToString("HH:m:s")}】===>未获取到需要下发的前板任务"); return; } + // 如果前板有正在执行的计划,不再下发新计划,直接开始读取plc数量 + //if (planInfoList.FirstOrDefault().ExecuteStatus == 2) + //{ + // //读取设备进度,完成后再次下发新任务 + // ReadDeviceComplate_SidePanel(obj_sidePanel); + //} + planInfoList = planInfoList.Where(d => d.PlanAmount > d.SidePanelAmount && (d.ExecuteStatus == 1 || d.ExecuteStatus == 2)).ToList(); if (planInfoList == null || planInfoList.Count == 0) return; //planInfoList = planInfoList.Where(d => d.ExecuteStatus == 1 || d.ExecuteStatus == 2).ToList(); @@ -298,8 +306,23 @@ namespace Aucma.Core.SheetMetalTasks obj_sidePanel.plc.WriteInt16("D6022", SmProductId.ToString());//产品号 string processNumber = GetProcessNumberBy(planInfo.MaterialCode); obj_sidePanel.plc.WriteString("D6010", planInfo.MaterialSpecificatons); - //int surplus = planInfo.PlanAmount-planInfo.CompleteAmount; + + // 如果没有计划执行或者是切换新计划,需要将剩余数量写入PLC + // 如果是当前计划继续执行,写入计划数量 int surplus = planInfo.PlanAmount; + byte[] info = obj_sidePanel.plc.Read("D6030", 40); + string planCode = Encoding.ASCII.GetString(info.Skip(0).Take(20).ToArray()).Replace("\0", "").Trim(); + if(planCode==planInfo.TaskCode) + { + surplus = planInfo.PlanAmount; + } + else + { + surplus = planInfo.PlanAmount - planInfo.CompleteAmount; + + } + + obj_sidePanel.plc.WriteInt16("D6020", surplus.ToString()); Thread.Sleep(500); @@ -607,8 +630,23 @@ namespace Aucma.Core.SheetMetalTasks obj_backPanel.plc.WriteInt16("D4022", productId.ToString()); string processNumber = GetProcessNumberBy(planInfo.MaterialCode); obj_backPanel.plc.WriteString("D4010", planInfo.MaterialSpecificatons); + // 如果没有计划执行或者是切换新计划,需要将剩余数量写入PLC + // 如果是当前计划继续执行,写入计划数量 + int surplus = planInfo.PlanAmount; + byte[] info = obj_backPanel.plc.Read("D4030", 40); + string planCode = Encoding.ASCII.GetString(info.Skip(0).Take(20).ToArray()).Replace("\0", "").Trim(); + if (planCode == planInfo.TaskCode) + { + surplus = planInfo.PlanAmount; + } + else + { + surplus = planInfo.PlanAmount - planInfo.CompleteAmount; + + } + //int surplus = planInfo.PlanAmount - planInfo.CompleteAmount;//剩余计划数量 - int surplus = planInfo.PlanAmount;//剩余计划数量 + obj_backPanel.plc.WriteInt16("D4020", surplus.ToString()); Thread.Sleep(500); @@ -1131,7 +1169,7 @@ namespace Aucma.Core.SheetMetalTasks //D6030 //计划编号:D6030-D6039,物料编号:D6040-D6049,计划完成数:D6050,计划下线数:D6051,设备状态:D6052-D6056,生产节拍:D6057-D6058 byte[] info = obj.plc.Read("D6030", 59); - + if (info == null) { Thread.Sleep(1000); @@ -1960,6 +1998,7 @@ namespace Aucma.Core.SheetMetalTasks { string productId = obj_SidePanel.plc.ReadInt16("D1402").ToString(); Bin bin = new Bin(); + bin.Id = 1; bin.ProductId = productId; bin.Status = startb0; list.Add(bin); @@ -1969,6 +2008,7 @@ namespace Aucma.Core.SheetMetalTasks { string productId = obj_SidePanel.plc.ReadInt16("D1426").ToString(); Bin bin = new Bin(); + bin.Id = 2; bin.ProductId = productId; bin.Status = startb0; list.Add(bin); @@ -1976,8 +2016,10 @@ namespace Aucma.Core.SheetMetalTasks var startb4 = obj_SidePanel.plc.ReadBool("M142"); if (startb4) { + string productId = obj_SidePanel.plc.ReadInt16("D1450").ToString(); Bin bin = new Bin(); + bin.Id = 3; bin.ProductId = productId; bin.Status = startb4; list.Add(bin); @@ -1987,6 +2029,7 @@ namespace Aucma.Core.SheetMetalTasks { string productId = obj_SidePanel.plc.ReadInt16("D1474").ToString(); Bin bin = new Bin(); + bin.Id = 4; bin.ProductId = productId; bin.Status = startb6; list.Add(bin); diff --git a/Aucma.Core.SheetMetalTasks/Models/Bin.cs b/Aucma.Core.SheetMetalTasks/Models/Bin.cs index 8306fc6..85aead6 100644 --- a/Aucma.Core.SheetMetalTasks/Models/Bin.cs +++ b/Aucma.Core.SheetMetalTasks/Models/Bin.cs @@ -11,6 +11,10 @@ namespace Aucma.Core.SheetMetalTasks.Models /// public class Bin { + /// + /// 机头ID + /// + public int Id { get; set; } /// /// 料仓Id ///