From a84cfd5e71ae4d3d95ccd88b2018d440f4e92dfc Mon Sep 17 00:00:00 2001 From: zhangzhuo <512464164@qq.com> Date: Fri, 21 Mar 2025 10:19:10 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4BUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Plc/HyosungPlcService.cs | 22 ++++++--- .../Plc/IHyosungPlcService.cs | 4 +- .../Scanner/HyosungScannerService.cs | 15 ++++++ Seyounth.Hyosung.Data/ServiceExtensions.cs | 2 +- .../Services/AgvBinService.cs | 5 +- Seyounth.Hyosung.Data/Services/DictService.cs | 7 +-- .../Services/ITrayService.cs | 5 +- .../Services/PalletService.cs | 3 +- Seyounth.Hyosung.Data/Services/TrayService.cs | 13 +++-- .../Services/VarietyService.cs | 6 ++- Seyounth.Hyosung.Data/Services/YarnService.cs | 1 + Seyounth.Hyosung.Runtime/HyosungRuntime.cs | 47 ++++++++++++------- 12 files changed, 94 insertions(+), 36 deletions(-) diff --git a/Seyounth.Hyosung.Core/Plc/HyosungPlcService.cs b/Seyounth.Hyosung.Core/Plc/HyosungPlcService.cs index 7e64f4e..5779c2f 100644 --- a/Seyounth.Hyosung.Core/Plc/HyosungPlcService.cs +++ b/Seyounth.Hyosung.Core/Plc/HyosungPlcService.cs @@ -155,8 +155,8 @@ public class HyosungPlcService(ILogger logger) : IHyosungPlcS public event Func? OnPlcRequestPackLineOption; - public event Func? OnRequestPrintLabel; - + public event Func? OnRequestPrintLabel; + public event Func OnRequestGetPrintLableOption; private async Task ReadLoop(CancellationToken token) { @@ -173,6 +173,7 @@ public class HyosungPlcService(ILogger logger) : IHyosungPlcS await QueryPackLineOption(); await QueryPrintLabel(); await Task.Delay(100, token); + await QueryGetPrintLabel(); } catch (Exception e) { @@ -315,23 +316,32 @@ public class HyosungPlcService(ILogger logger) : IHyosungPlcS } } + private async Task QueryGetPrintLabel() + { + var trayCode = await _reader.ReadStringAsync(13000); + if (!string.IsNullOrEmpty(trayCode)||!trayCode.StartsWith("0000")) + { + await _reader.WriteStringAsync(13000, "00000000000000000000"); + OnRequestGetPrintLableOption?.Invoke(trayCode); + } + } private async Task QueryPrintLabel() { var requestPrintLabel = await _reader.ReadShortsAsync(13010, 3); if (requestPrintLabel[0] == 1) { - var trayCode = await _reader.ReadStringAsync(13000); + await _writer.WriteShortsAsync(13010, 0); await _writer.WriteShortsAsync(13012, 0); - OnRequestPrintLabel?.Invoke(1, trayCode, requestPrintLabel[2]); + OnRequestPrintLabel?.Invoke(1, requestPrintLabel[2]); } if (requestPrintLabel[1] == 1) { - var trayCode = await _reader.ReadStringAsync(13000); + await _writer.WriteShortsAsync(13011, 0); await _writer.WriteShortsAsync(13012, 0); - OnRequestPrintLabel?.Invoke(2, trayCode, requestPrintLabel[2]); + OnRequestPrintLabel?.Invoke(2, 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 3cc2f4f..a0f2600 100644 --- a/Seyounth.Hyosung.Core/Plc/IHyosungPlcService.cs +++ b/Seyounth.Hyosung.Core/Plc/IHyosungPlcService.cs @@ -93,5 +93,7 @@ public interface IHyosungPlcService /// /// 贴标站请求贴标 /// - event Func OnRequestPrintLabel; + event Func OnRequestPrintLabel; + + event Func OnRequestGetPrintLableOption; } \ No newline at end of file diff --git a/Seyounth.Hyosung.Core/Scanner/HyosungScannerService.cs b/Seyounth.Hyosung.Core/Scanner/HyosungScannerService.cs index cee0d26..92270eb 100644 --- a/Seyounth.Hyosung.Core/Scanner/HyosungScannerService.cs +++ b/Seyounth.Hyosung.Core/Scanner/HyosungScannerService.cs @@ -13,6 +13,9 @@ public class HyosungScannerService : IHyosungScannerService private readonly ConcurrentDictionary _fixtureScanners = new(); + private List lastCodes = new List(); + + public HyosungScannerService(ILogger logger) { _yarnScanners.Add(new HikScanner("192.168.3.35", 2001)); @@ -25,6 +28,10 @@ public class HyosungScannerService : IHyosungScannerService _fixtureScanners.TryAdd(3, new HikScanner("192.168.3.33", 2001)); _fixtureScanners.TryAdd(4, new HikScanner("192.168.3.30", 2001)); _logger = logger; + lastCodes.Add(""); + lastCodes.Add(""); + lastCodes.Add(""); + lastCodes.Add(""); } public async Task StartAsync(CancellationToken token) @@ -131,5 +138,13 @@ public class HyosungScannerService : IHyosungScannerService public async Task ScanFixtureAsync(int fixtureId) { return await _fixtureScanners[fixtureId].ScanAsync(); + //string code = ""; + //do + //{ + // code= await _fixtureScanners[fixtureId].ScanAsync(); + // await Task.Delay(100); + //} while (code != lastCodes[fixtureId - 1]); + //lastCodes[fixtureId - 1] = code; + //return code; } } \ No newline at end of file diff --git a/Seyounth.Hyosung.Data/ServiceExtensions.cs b/Seyounth.Hyosung.Data/ServiceExtensions.cs index 526888e..b4285d2 100644 --- a/Seyounth.Hyosung.Data/ServiceExtensions.cs +++ b/Seyounth.Hyosung.Data/ServiceExtensions.cs @@ -36,7 +36,7 @@ public static class ServiceExtensions //#endif return sqlSugar; }); - services.AddScoped(typeof(IRepository<>), typeof(Repository<>)); + services.AddSingleton(typeof(IRepository<>), typeof(Repository<>)); services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); diff --git a/Seyounth.Hyosung.Data/Services/AgvBinService.cs b/Seyounth.Hyosung.Data/Services/AgvBinService.cs index be932ca..166d3ca 100644 --- a/Seyounth.Hyosung.Data/Services/AgvBinService.cs +++ b/Seyounth.Hyosung.Data/Services/AgvBinService.cs @@ -12,8 +12,9 @@ public class AgvBinService : IAgvBinService public AgvBinService(IServiceProvider provider) { - _repository = provider.CreateScope().ServiceProvider.GetRequiredService>(); - _cache = _repository.GetList(); + _repository = provider.CreateScope().ServiceProvider.GetRequiredService>(); + //_repository = provider.GetService>(); + _cache = _repository.GetList(); } public async Task GetAvailableBin(int height) diff --git a/Seyounth.Hyosung.Data/Services/DictService.cs b/Seyounth.Hyosung.Data/Services/DictService.cs index 8b6c40e..3d74446 100644 --- a/Seyounth.Hyosung.Data/Services/DictService.cs +++ b/Seyounth.Hyosung.Data/Services/DictService.cs @@ -13,9 +13,10 @@ public class DictService : IDictService public DictService(IServiceProvider provider) { - _repository = provider.CreateScope() - .ServiceProvider.GetRequiredService>(); - _cache = _repository.GetList(); + _repository = provider.CreateScope() + .ServiceProvider.GetRequiredService>(); + //_repository = provider.GetService>(); + _cache = _repository.GetList(); } diff --git a/Seyounth.Hyosung.Data/Services/ITrayService.cs b/Seyounth.Hyosung.Data/Services/ITrayService.cs index 9db78da..2523bf6 100644 --- a/Seyounth.Hyosung.Data/Services/ITrayService.cs +++ b/Seyounth.Hyosung.Data/Services/ITrayService.cs @@ -1,3 +1,4 @@ +using System.Globalization; using Seyounth.Hyosung.Data.Models; using Seyounth.Hyosung.Data.Services.Hyosung.Entities; @@ -41,5 +42,7 @@ public interface ITrayService /// /// /// - Task PrintTrayAsync(string trayCode, int stackHeight, int controlNo, MST_ITEM_2240_V itemInfo); + Task PrintTrayAsync(string trayCode, int controlNo, MST_ITEM_2240_V itemInfo); + + Task UpdateHeightAsync(string trayCode, int height); } \ No newline at end of file diff --git a/Seyounth.Hyosung.Data/Services/PalletService.cs b/Seyounth.Hyosung.Data/Services/PalletService.cs index 4247f88..3e5bfad 100644 --- a/Seyounth.Hyosung.Data/Services/PalletService.cs +++ b/Seyounth.Hyosung.Data/Services/PalletService.cs @@ -13,7 +13,8 @@ public class PalletService : IPalletService public PalletService(IServiceProvider serviceProvider) { _palletRepository = serviceProvider.CreateScope().ServiceProvider - .GetRequiredService>(); + .GetRequiredService>(); + // _palletRepository = serviceProvider.GetService>(); _pallets = _palletRepository.GetList().Select(Pallet.FromEntity).ToList(); } diff --git a/Seyounth.Hyosung.Data/Services/TrayService.cs b/Seyounth.Hyosung.Data/Services/TrayService.cs index 04ef3b5..8355635 100644 --- a/Seyounth.Hyosung.Data/Services/TrayService.cs +++ b/Seyounth.Hyosung.Data/Services/TrayService.cs @@ -17,7 +17,8 @@ public class TrayService : ITrayService public TrayService(IServiceProvider provider, IHyosungWmsService hyosungWmsService) { - _repository = provider.CreateScope().ServiceProvider.GetRequiredService>(); + _repository = provider.CreateScope().ServiceProvider.GetRequiredService>(); + //_repository = provider.GetService>(); var trays = _repository.GetList(t => t.ControlNo == null); _hyosungWmsService = hyosungWmsService; foreach (var tray in trays) @@ -64,7 +65,7 @@ public class TrayService : ITrayService throw new NotImplementedException(); } - public async Task PrintTrayAsync(string trayCode, int stackHeight, int controlNo, MST_ITEM_2240_V itemInfo) + public async Task PrintTrayAsync(string trayCode, int controlNo, MST_ITEM_2240_V itemInfo) { Tray tray; try @@ -77,7 +78,6 @@ public class TrayService : ITrayService } tray.ControlNo = controlNo; - tray.StackHeight = stackHeight; tray.Grade = itemInfo.GRADE; tray.Type = itemInfo.TYPE; tray.DenFila = itemInfo.DEN_FILA; @@ -99,4 +99,11 @@ public class TrayService : ITrayService await _repository.UpdateAsync(tray); _cache.TryRemove(tray.TrayCode, out _); } + + public async Task UpdateHeightAsync(string trayCode, int height) + { + await _repository.AsUpdateable() + .Where(x => x.TrayCode == trayCode) + .SetColumns(x => x.StackHeight, height).ExecuteCommandAsync(); + } } \ No newline at end of file diff --git a/Seyounth.Hyosung.Data/Services/VarietyService.cs b/Seyounth.Hyosung.Data/Services/VarietyService.cs index e2fd47d..5f0b9d5 100644 --- a/Seyounth.Hyosung.Data/Services/VarietyService.cs +++ b/Seyounth.Hyosung.Data/Services/VarietyService.cs @@ -19,8 +19,10 @@ public class VarietyService : IVarietyService { _varietyRepository = provider.CreateScope().ServiceProvider.GetRequiredService>(); - _palletRepository = provider.CreateScope().ServiceProvider.GetRequiredService>(); - _varietiesCache = new List(_varietyRepository.GetList()); + _palletRepository = provider.CreateScope().ServiceProvider.GetRequiredService>(); + //_varietyRepository = provider.GetService>(); + // _palletRepository = provider.GetService>(); + _varietiesCache = new List(_varietyRepository.GetList()); _palletsCache = new List(_palletRepository.GetList()); } catch (Exception e) diff --git a/Seyounth.Hyosung.Data/Services/YarnService.cs b/Seyounth.Hyosung.Data/Services/YarnService.cs index 138993b..2497a44 100644 --- a/Seyounth.Hyosung.Data/Services/YarnService.cs +++ b/Seyounth.Hyosung.Data/Services/YarnService.cs @@ -13,6 +13,7 @@ public class YarnService : IYarnService public YarnService(IServiceProvider provider) { _yarnRepository = provider.CreateScope().ServiceProvider.GetRequiredService>(); + // _yarnRepository = provider.GetService>(); NoFinished = new ConcurrentDictionary(); var yarns = _yarnRepository.GetList(y => !y.IsFinished); foreach (var yarn in yarns) diff --git a/Seyounth.Hyosung.Runtime/HyosungRuntime.cs b/Seyounth.Hyosung.Runtime/HyosungRuntime.cs index 94a320a..f435ca0 100644 --- a/Seyounth.Hyosung.Runtime/HyosungRuntime.cs +++ b/Seyounth.Hyosung.Runtime/HyosungRuntime.cs @@ -12,6 +12,7 @@ using Seyounth.Hyosung.Data.Services; using Seyounth.Hyosung.Data.Services.Hyosung; using Seyounth.Hyosung.Data.Services.Hyosung.Entities; using Seyounth.Hyosung.Runtime.Models; +using static System.Runtime.CompilerServices.RuntimeHelpers; namespace Seyounth.Hyosung.Runtime; @@ -30,6 +31,8 @@ public class HyosungRuntime( public StackStationModel Stack1 { get; private set; } = new(); public StackStationModel Stack2 { get; private set; } = new(); + private string currentPrintTrayCode = ""; + public async Task StartAsync(CancellationToken token) { //启动扫码服务 @@ -43,9 +46,12 @@ public class HyosungRuntime( hyosungPlcService.OnPlcPutCompleted += OnPlcPutCompleted; hyosungPlcService.OnPlcRequestPackLineOption += OnPlcRequestPackLineOption; hyosungPlcService.OnRequestPrintLabel += OnPlcRequestPrintLabel; + hyosungPlcService.OnRequestGetPrintLableOption += OnRequestGetPrintLabel; await hyosungPlcService.StartAsync(token); } + + public async Task StopAsync(CancellationToken token) { //先停止扫码服务 @@ -280,6 +286,22 @@ public class HyosungRuntime( } } + private async Task OnRequestGetPrintLabel(string arg) + { + currentPrintTrayCode = arg; + var tray = await trayService.GetByCode(arg); + var variety = await varietyService.GetById(tray.VarietyId); + var mod = await hyosungWmsService.GetItemInfoByItemCode(variety.Code); + var grade = "1"; + if (mod.GRADE != "AA") grade = mod.GRADE; + int controlNo = 0; + if (tray.ControlNo is null || tray.ControlNo == 0) + { + controlNo = await hyosungWmsService.GetControlNo(variety, grade); + tray = await trayService.PrintTrayAsync(arg, controlNo, mod); + } + } + /// /// 处理贴标站请求贴标事件 /// @@ -287,32 +309,25 @@ public class HyosungRuntime( /// /// /// - private async Task OnPlcRequestPrintLabel(int arg1, string trayCode, int height) + private async Task OnPlcRequestPrintLabel(int arg1, int height) { - logger.LogInformation($"plc request print label:{arg1} {trayCode} {height}"); + logger.LogInformation($"plc request print label:{arg1} {currentPrintTrayCode} {height}"); + var tray = await trayService.GetByCode(currentPrintTrayCode); + var variety = await varietyService.GetById(tray.VarietyId); + await trayService.UpdateHeightAsync(currentPrintTrayCode, height); try { - var tray = await trayService.GetByCode(trayCode); - var variety = await varietyService.GetById(tray.VarietyId); - var mod = await hyosungWmsService.GetItemInfoByItemCode(variety.Code); - var grade = "1"; - if (mod.GRADE != "AA") grade = mod.GRADE; - int controlNo = 0; - if(tray.ControlNo is null || tray.ControlNo == 0) - { - controlNo = await hyosungWmsService.GetControlNo(variety, grade); - tray = await trayService.PrintTrayAsync(trayCode, height, controlNo, mod); - } + if (arg1 == 1) { - await printer.PrintAsync(1, trayCode); + await printer.PrintAsync(1, currentPrintTrayCode); await hyosungPlcService.WritePrintLabelResultAsync(arg1, variety.SubLabelCount, true); } else { - await printer.PrintAsync(2, trayCode); + await printer.PrintAsync(2, currentPrintTrayCode); await hyosungPlcService.WritePrintLabelResultAsync(arg1, variety.MasterLabelCount, true); - await hyosungWmsService.UpdateControlNo(variety, controlNo); + await hyosungWmsService.UpdateControlNo(variety, tray.ControlNo.Value); await hyosungWmsService.AddLabelResult(new LabelResult(tray, variety)); }