From 2347c07d105c6615aeb61b395bc46cbf5e36825c Mon Sep 17 00:00:00 2001 From: anerx <512464164@qq.com> Date: Mon, 14 Apr 2025 16:09:10 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=AC=AC=E4=B8=89=E5=8F=B0?= =?UTF-8?q?=E6=89=93=E5=8D=B0=E6=9C=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Views/VarietyManagerPage.axaml | 2 + .../Plc/HyosungPlcService.cs | 24 +++++-- .../Plc/IHyosungPlcService.cs | 10 +-- .../Printer/HyosungPrinter.cs | 62 ++++++++++--------- .../Printer/IHyosungPrinter.cs | 11 ++-- .../Entities/VarietyEntity.cs | 3 + Seyounth.Hyosung.Data/Models/Variety.cs | 8 ++- Seyounth.Hyosung.Runtime/HyosungRuntime.cs | 16 +++-- Seyounth.Hyosung/Views/MainWindow.xaml.cs | 6 +- 9 files changed, 81 insertions(+), 61 deletions(-) diff --git a/Seyounth.Hyosung.Ava/Views/VarietyManagerPage.axaml b/Seyounth.Hyosung.Ava/Views/VarietyManagerPage.axaml index 119c5ee..50c25a2 100644 --- a/Seyounth.Hyosung.Ava/Views/VarietyManagerPage.axaml +++ b/Seyounth.Hyosung.Ava/Views/VarietyManagerPage.axaml @@ -219,6 +219,8 @@ Binding="{Binding NetWeight}" /> + diff --git a/Seyounth.Hyosung.Core/Plc/HyosungPlcService.cs b/Seyounth.Hyosung.Core/Plc/HyosungPlcService.cs index 7099d49..5e8beb9 100644 --- a/Seyounth.Hyosung.Core/Plc/HyosungPlcService.cs +++ b/Seyounth.Hyosung.Core/Plc/HyosungPlcService.cs @@ -106,10 +106,10 @@ public class HyosungPlcService(ILogger logger) : IHyosungPlcS await _writer.WriteShortsAsync(12120, ls.ToArray()); } - public async Task WritePrintLableOptionsAsync(int side, int slave) + public async Task WritePrintLabelOptionsAsync(int master, int slave, int color) { short masterCount = 0; - switch (side) + switch (master) { case 0: masterCount = 1; @@ -148,12 +148,19 @@ public class HyosungPlcService(ILogger logger) : IHyosungPlcS break; } - await _writer.WriteShortsAsync(13050, [1, 1, 1, 2]); + if (color == 1) + await _writer.WriteShortsAsync(13050, [1, 1, 1, 2]); + else + { + await _writer.WriteShortsAsync(13056, 2); + //todo:此处是写副标签的,后续测试无问题则需要修改此处 + await _writer.WriteShortsAsync(13052, 1); + } } public async Task WritePrintLabelResultAsync(int index, bool result) { - var address = index == 1 ? 13060 : 13061; + var address = 13059 + index; await _writer.WriteShortsAsync(address, (short)(result ? 1 : 2)); } @@ -375,7 +382,7 @@ public class HyosungPlcService(ILogger logger) : IHyosungPlcS private async Task QueryPrintLabel() { - var requestPrintLabel = await _reader.ReadShortsAsync(13010, 3); + var requestPrintLabel = await _reader.ReadShortsAsync(13010, 4); if (requestPrintLabel[0] == 1) { await _writer.WriteShortsAsync(13010, 0); @@ -389,5 +396,12 @@ public class HyosungPlcService(ILogger logger) : IHyosungPlcS await _writer.WriteShortsAsync(13012, 0); OnRequestPrintLabel?.Invoke(2, requestPrintLabel[2]); } + + if (requestPrintLabel[3] == 1) + { + await _writer.WriteShortsAsync(13013, 0); + await _writer.WriteShortsAsync(13012, 0); + OnRequestPrintLabel?.Invoke(3, requestPrintLabel[2]); + } } } \ No newline at end of file diff --git a/Seyounth.Hyosung.Core/Plc/IHyosungPlcService.cs b/Seyounth.Hyosung.Core/Plc/IHyosungPlcService.cs index b15f47b..f1cfeaa 100644 --- a/Seyounth.Hyosung.Core/Plc/IHyosungPlcService.cs +++ b/Seyounth.Hyosung.Core/Plc/IHyosungPlcService.cs @@ -58,11 +58,11 @@ public interface IHyosungPlcService Task WritePackLineOptionAsync(PackLineOption option); - Task WritePrintLableOptionsAsync(int side,int slaveCount); + Task WritePrintLabelOptionsAsync(int masterCount, int slaveCount, int color); + + Task WritePrintLabelResultAsync(int index, bool result); + - Task WritePrintLabelResultAsync(int index, bool result); - - Task WriteScanEntryResultAsync(int index, bool result); /// @@ -101,6 +101,6 @@ public interface IHyosungPlcService event Func OnRequestPrintLabel; event Func OnRequestGetPrintLableOption; - + event Func OnRequestScanEntry; } \ No newline at end of file diff --git a/Seyounth.Hyosung.Core/Printer/HyosungPrinter.cs b/Seyounth.Hyosung.Core/Printer/HyosungPrinter.cs index 77b3773..25dac7e 100644 --- a/Seyounth.Hyosung.Core/Printer/HyosungPrinter.cs +++ b/Seyounth.Hyosung.Core/Printer/HyosungPrinter.cs @@ -15,55 +15,58 @@ public class HyosungPrinter( IHyosungWmsService hyosungWmsService, IOptions options) : IHyosungPrinter { - private readonly AveryPrinter _masterPrinter = new("192.168.3.61", 9100); - private readonly AveryPrinter _slavePrinter = new("192.168.3.60", 9100); + private readonly Dictionary _printers = new Dictionary() + { + { 1001, new AveryPrinter("192.168.3.61", 9100) }, + { 2, new AveryPrinter("192.168.3.62", 9100) }, + { 1, new AveryPrinter("192.168.3.60", 9100) } + }; + public async Task StartAsync(CancellationToken token) { List ls = new List(); - ls.Add(_masterPrinter.ConnectAsync(token)); - ls.Add(_slavePrinter.ConnectAsync(token)); + foreach (var (_, printer) in _printers) + { + ls.Add(printer.ConnectAsync(token)); + } + await Task.WhenAll(ls); logger.LogInformation("printer connected"); } public async Task StopAsync(CancellationToken token) { - await _masterPrinter.CloseAsync(token); - await _slavePrinter.CloseAsync(token); + foreach (var (_, printer) in _printers) + { + printer.CloseAsync(token); + } + logger.LogInformation("printer disconnected"); } - public async Task PrintAsync(int index, string trayCode) + public async Task PrintMasterLabelAsync(int color, string trayCode) { var tray = await trayService.GetByCode(trayCode); - if (index == 1) - { - await PrintLabel1Async(tray); - } - else - { - await PrintLabel2Async(tray); - } + var content = await GetMasterLabelContent(tray); + await _printers[color].CleanContextAsync(); + await _printers[color].SendContentAsync(content); + await _printers[color].PrintAsync(); } - private async Task PrintLabel1Async(Tray tray) + public async Task PrintSubLabelAsync(string trayCode) { - await _masterPrinter.CleanContextAsync(); - var content = await GetPrint1Content(tray); - await _masterPrinter.SendContentAsync(content); - await _masterPrinter.PrintAsync(); + var tray = await trayService.GetByCode(trayCode); + var content = await GetSubLabelContentAsync(tray); + await _printers[1001].CleanContextAsync(); + await _printers[1001].SendContentAsync(content); + await _printers[1001].PrintAsync(); } - private async Task PrintLabel2Async(Tray tray) - { - await _slavePrinter.CleanContextAsync(); - var content = await GetPrint2Content(tray); - await _slavePrinter.SendContentAsync(content); - await _slavePrinter.PrintAsync(); - } - private async Task GetPrint1Content(Tray tray) + + + private async Task GetSubLabelContentAsync(Tray tray) { var variety = await varietyService.GetById(tray.VarietyId); var yarns = await yarnService.GetYarnsByTrayIdAsync(tray.Id); @@ -100,7 +103,7 @@ public class HyosungPrinter( return temp; } - private async Task GetPrint2Content(Tray tray) + private async Task GetMasterLabelContent(Tray tray) { var variety = await varietyService.GetById(tray.VarietyId); @@ -128,6 +131,7 @@ public class HyosungPrinter( { content = content.Replace(key, value); } + logger.LogInformation($"print content: {content}"); return content; } diff --git a/Seyounth.Hyosung.Core/Printer/IHyosungPrinter.cs b/Seyounth.Hyosung.Core/Printer/IHyosungPrinter.cs index 4a2cbac..a0f9642 100644 --- a/Seyounth.Hyosung.Core/Printer/IHyosungPrinter.cs +++ b/Seyounth.Hyosung.Core/Printer/IHyosungPrinter.cs @@ -6,10 +6,9 @@ public interface IHyosungPrinter Task StopAsync(CancellationToken token); - /// - /// 打印指定垛的标签 - /// - /// - /// - Task PrintAsync(int index,string trayCode); + + + Task PrintMasterLabelAsync(int color, string trayCode); + + Task PrintSubLabelAsync(string trayCode); } \ No newline at end of file diff --git a/Seyounth.Hyosung.Data/Entities/VarietyEntity.cs b/Seyounth.Hyosung.Data/Entities/VarietyEntity.cs index d968df5..5d327f6 100644 --- a/Seyounth.Hyosung.Data/Entities/VarietyEntity.cs +++ b/Seyounth.Hyosung.Data/Entities/VarietyEntity.cs @@ -84,6 +84,9 @@ public class VarietyEntity [SugarColumn(ColumnDescription = "副标签数量")] public int SubLabelCount { get; set; } + [SugarColumn(ColumnDescription = "标签颜色 1=红色 2=黑色")] + public int LabelColor { get; set; } + [SugarColumn(IsNullable = true)] public int? LastNo { get; set; } [SugarColumn(IsNullable = true)] public double? NetWeight { get; set; } diff --git a/Seyounth.Hyosung.Data/Models/Variety.cs b/Seyounth.Hyosung.Data/Models/Variety.cs index b4fd677..09874ae 100644 --- a/Seyounth.Hyosung.Data/Models/Variety.cs +++ b/Seyounth.Hyosung.Data/Models/Variety.cs @@ -70,6 +70,8 @@ public class Variety public double? GrossWeight { get; set; } + public int LabelColor { get; set; } + public static Variety Create(VarietyEntity entity, List pallets) { var variety = new Variety() @@ -101,7 +103,8 @@ public class Variety HasBox = entity.HasBox, LastNo = entity.LastNo, NetWeight = entity.NetWeight, - GrossWeight = entity.GrossWeight + GrossWeight = entity.GrossWeight, + LabelColor = entity.LabelColor, }; if (entity.PaperTrayId != null && entity.PaperTrayId != 0) variety.PaperTray = Pallet.FromEntity(pallets.First(x => x.Id == entity.PaperTrayId)); @@ -141,7 +144,8 @@ public class Variety HasBox = HasBox, LastNo = LastNo, NetWeight = NetWeight, - GrossWeight = GrossWeight + GrossWeight = GrossWeight, + LabelColor = LabelColor, }; return entity; } diff --git a/Seyounth.Hyosung.Runtime/HyosungRuntime.cs b/Seyounth.Hyosung.Runtime/HyosungRuntime.cs index 339df81..c53227b 100644 --- a/Seyounth.Hyosung.Runtime/HyosungRuntime.cs +++ b/Seyounth.Hyosung.Runtime/HyosungRuntime.cs @@ -375,7 +375,8 @@ public class HyosungRuntime( var mod = await hyosungWmsService.GetItemInfoByItemCode(variety.Code); _ = await trayService.PrintTrayAsync(arg, mod, variety); await dictService.SetValue("System", "CurrentPackingTrayCode", arg); - await hyosungPlcService.WritePrintLableOptionsAsync(variety.MasterLabelCount, variety.SubLabelCount); + await hyosungPlcService.WritePrintLabelOptionsAsync(variety.MasterLabelCount, variety.SubLabelCount, + variety.LabelColor); logger.LogInformation("request print option succeed"); } catch (Exception e) @@ -403,19 +404,16 @@ public class HyosungRuntime( { if (arg1 == 1) { - await printer.PrintAsync(1, tray.TrayCode); - await hyosungPlcService.WritePrintLabelResultAsync(arg1, true); + await printer.PrintSubLabelAsync(tray.TrayCode); } else { - await printer.PrintAsync(2, tray.TrayCode); - await hyosungPlcService.WritePrintLabelResultAsync(arg1, true); - //var version = await hyosungWmsService.GetItemInfoByItemCode(variety.Code); - // await varietyService.SetLastNo(variety.Id, tray.ControlNo.Value); - //await hyosungWmsService.UpdateControlNo(variety, tray.ControlNo.Value); - // await hyosungWmsService.AddLabelResult(new LabelResult(tray, variety)); + await printer.PrintMasterLabelAsync(arg1 - 1, tray.TrayCode); + // await hyosungWmsService.AddLabelResult(new LabelResult(tray, variety)); } + await hyosungPlcService.WritePrintLabelResultAsync(arg1, true); + logger.LogInformation($"plc request print label success"); } catch (Exception e) diff --git a/Seyounth.Hyosung/Views/MainWindow.xaml.cs b/Seyounth.Hyosung/Views/MainWindow.xaml.cs index 92b1aa9..bc5a5a3 100644 --- a/Seyounth.Hyosung/Views/MainWindow.xaml.cs +++ b/Seyounth.Hyosung/Views/MainWindow.xaml.cs @@ -1,8 +1,4 @@ -using System.Windows; -using Seyounth.Hyosung.Data.Models; -using Seyounth.Hyosung.Data.Services; -using Seyounth.Hyosung.Runtime; -using Seyounth.Hyosung.ViewModels; +using Seyounth.Hyosung.ViewModels; using Seyounth.Hyosung.Views.Pages; namespace Seyounth.Hyosung.Views;