From d1631df129ac17bc0e73ccdb89ee2b813e1a30db Mon Sep 17 00:00:00 2001 From: anerx <512464164@qq.com> Date: Mon, 17 Mar 2025 02:37:39 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0ControlNo=E5=B1=95=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Seyounth.Hyosung.Data/Models/Variety.cs | 1 + Seyounth.Hyosung.Runtime/HyosungRuntime.cs | 42 ++++++++++++++++++- Seyounth.Hyosung.Runtime/IHyosungRuntime.cs | 4 ++ .../Models/StackStationModel.cs | 4 +- Seyounth.Hyosung/Seyounth.Hyosung.csproj | 4 ++ Seyounth.Hyosung/ViewModels/HomeViewModel.cs | 18 ++++---- .../Views/Pages/HomeViewPage.xaml | 2 + .../Views/Pages/HomeViewPage.xaml.cs | 31 ++++++++++---- 8 files changed, 88 insertions(+), 18 deletions(-) rename Seyounth.Hyosung/Models/StackModel.cs => Seyounth.Hyosung.Runtime/Models/StackStationModel.cs (83%) diff --git a/Seyounth.Hyosung.Data/Models/Variety.cs b/Seyounth.Hyosung.Data/Models/Variety.cs index 523e24f..49f7e6b 100644 --- a/Seyounth.Hyosung.Data/Models/Variety.cs +++ b/Seyounth.Hyosung.Data/Models/Variety.cs @@ -4,6 +4,7 @@ namespace Seyounth.Hyosung.Data.Models; public class Variety { + public int ControlNo { get; set; } public string Name => $"{Id} - {Code} - {StackingLayers}"; public int Id { get; set; } diff --git a/Seyounth.Hyosung.Runtime/HyosungRuntime.cs b/Seyounth.Hyosung.Runtime/HyosungRuntime.cs index fb5dd6c..c9d2c49 100644 --- a/Seyounth.Hyosung.Runtime/HyosungRuntime.cs +++ b/Seyounth.Hyosung.Runtime/HyosungRuntime.cs @@ -1,4 +1,5 @@ using System.Collections.Concurrent; +using System.Collections.ObjectModel; using Microsoft.Extensions.Logging; using Seyounth.Hyosung.Core.Agv; using Seyounth.Hyosung.Core.Plc; @@ -8,6 +9,7 @@ using Seyounth.Hyosung.Data.Models; using Seyounth.Hyosung.Data.Models.Plc; using Seyounth.Hyosung.Data.Services; using Seyounth.Hyosung.Data.Services.Hyosung; +using Seyounth.Hyosung.Runtime.Models; namespace Seyounth.Hyosung.Runtime; @@ -22,11 +24,13 @@ public class HyosungRuntime( IHyosungAgvService hyosungAgvService, IHyosungWmsService hyosungWmsService) : IHyosungRuntime { + public StackStationModel Stack1 { get; private set; } = new(); + public StackStationModel Stack2 { get; private set; } = new(); + public async Task StartAsync(CancellationToken token) { //启动扫码服务 await hyosungScannerService.StartAsync(token); - await printer.StartAsync(token); //最后启动PLC服务 hyosungPlcService.OnPlcRequestScanProduct += OnPlcRequestScanProduct; hyosungPlcService.OnPlcRequestScanFixture += OnPlcRequestScanFixture; @@ -41,7 +45,7 @@ public class HyosungRuntime( public async Task StopAsync(CancellationToken token) { //先停止扫码服务 - // await hyosungScannerService.StopAsync(token); + // await hyosungScannerService.StopAsync(token); await printer.StopAsync(token); //先停止PLC服务 //解绑相关事件 @@ -126,6 +130,23 @@ public class HyosungRuntime( private async Task OnPlcNeedNewTrayCode(int index, int varietyId) { var tray = await trayService.GeneraNewTray(varietyId); + var variety = await varietyService.GetById(varietyId); + var stackModel = new StackStationModel(); + stackModel.TrayCode = tray.TrayCode; + stackModel.VarietyCode = variety.Code; + stackModel.Layers = variety.StackingLayers; + stackModel.TotalCount = variety.TotalCount; + stackModel.CurrentCount = 0; + stackModel.Yarns = new ObservableCollection(); + if (index == 1) + { + Stack1 = stackModel; + } + else + { + Stack2 = stackModel; + } + await hyosungPlcService.WriteTrayCodeAsync(index, tray.TrayCode); } @@ -137,6 +158,23 @@ public class HyosungRuntime( /// private async Task OnPlcPutCompleted(PlcStackingInfo arg) { + if (arg.TrayCode == Stack1.TrayCode) + { + Stack1.CurrentCount += arg.YarnCode.Count; + foreach (var yarnCode in arg.YarnCode) + { + Stack1.Yarns.Add(await yarnService.GetYarnByCodeAsync(yarnCode)); + } + } + else if (arg.TrayCode == Stack2.TrayCode) + { + Stack2.CurrentCount += arg.YarnCode.Count; + foreach (var yarnCode in arg.YarnCode) + { + Stack2.Yarns.Add(await yarnService.GetYarnByCodeAsync(yarnCode)); + } + } + foreach (var yarnCode in arg.YarnCode) { await yarnService.BindTrayAsync(yarnCode, await trayService.GetIdByCode(arg.TrayCode)); diff --git a/Seyounth.Hyosung.Runtime/IHyosungRuntime.cs b/Seyounth.Hyosung.Runtime/IHyosungRuntime.cs index 3dfb334..70f65be 100644 --- a/Seyounth.Hyosung.Runtime/IHyosungRuntime.cs +++ b/Seyounth.Hyosung.Runtime/IHyosungRuntime.cs @@ -1,10 +1,14 @@ using System.Collections.Concurrent; using Seyounth.Hyosung.Data.Models; +using Seyounth.Hyosung.Runtime.Models; namespace Seyounth.Hyosung.Runtime; public interface IHyosungRuntime { + StackStationModel Stack1 { get; } + + StackStationModel Stack2 { get; } /// /// 启动运行 diff --git a/Seyounth.Hyosung/Models/StackModel.cs b/Seyounth.Hyosung.Runtime/Models/StackStationModel.cs similarity index 83% rename from Seyounth.Hyosung/Models/StackModel.cs rename to Seyounth.Hyosung.Runtime/Models/StackStationModel.cs index e70e7f6..5e5b23e 100644 --- a/Seyounth.Hyosung/Models/StackModel.cs +++ b/Seyounth.Hyosung.Runtime/Models/StackStationModel.cs @@ -1,9 +1,9 @@ using System.Collections.ObjectModel; using Seyounth.Hyosung.Data.Models; -namespace Seyounth.Hyosung.Models; +namespace Seyounth.Hyosung.Runtime.Models; -public class StackModel +public class StackStationModel { public string TrayCode { get; set; } = "NoData"; diff --git a/Seyounth.Hyosung/Seyounth.Hyosung.csproj b/Seyounth.Hyosung/Seyounth.Hyosung.csproj index eedaf4b..5e3e7b1 100644 --- a/Seyounth.Hyosung/Seyounth.Hyosung.csproj +++ b/Seyounth.Hyosung/Seyounth.Hyosung.csproj @@ -32,4 +32,8 @@ + + + + diff --git a/Seyounth.Hyosung/ViewModels/HomeViewModel.cs b/Seyounth.Hyosung/ViewModels/HomeViewModel.cs index 5dc903b..5cd6c3e 100644 --- a/Seyounth.Hyosung/ViewModels/HomeViewModel.cs +++ b/Seyounth.Hyosung/ViewModels/HomeViewModel.cs @@ -2,26 +2,30 @@ using System.Collections.ObjectModel; using CommunityToolkit.Mvvm.ComponentModel; using Seyounth.Hyosung.Data.Models; using Seyounth.Hyosung.Data.Services; -using Seyounth.Hyosung.Models; +using Seyounth.Hyosung.Runtime; +using Seyounth.Hyosung.Runtime.Models; namespace Seyounth.Hyosung.ViewModels; public partial class HomeViewModel : ObservableObject { - [ObservableProperty] private StackModel _stack1; + [ObservableProperty] private StackStationModel _stack1; - [ObservableProperty] private StackModel _stack2; + [ObservableProperty] private StackStationModel _stack2; [ObservableProperty] private ObservableCollection _varieties; [ObservableProperty] private List _yarnCarTypes; - + [ObservableProperty] private Variety _selectedVariety; - public HomeViewModel(IVarietyService varietyService) + private readonly IHyosungRuntime _runtime; + + public HomeViewModel(IVarietyService varietyService, IHyosungRuntime runtime) { - _stack1 = new StackModel(); - _stack2 = new StackModel(); + _runtime = runtime; + _stack1 = _runtime.Stack1; + _stack2 = _runtime.Stack2; _yarnCarTypes = new List(); _yarnCarTypes.Add("A"); _yarnCarTypes.Add("B"); diff --git a/Seyounth.Hyosung/Views/Pages/HomeViewPage.xaml b/Seyounth.Hyosung/Views/Pages/HomeViewPage.xaml index 98c4ae2..b80be84 100644 --- a/Seyounth.Hyosung/Views/Pages/HomeViewPage.xaml +++ b/Seyounth.Hyosung/Views/Pages/HomeViewPage.xaml @@ -163,6 +163,7 @@ Foreground="White" Grid.Row="0" Text="品类:" /> @@ -181,6 +182,7 @@ +