提交BUG

This commit is contained in:
zhangzhuo 2025-03-21 10:19:10 +08:00
parent 61407f6436
commit a84cfd5e71
12 changed files with 94 additions and 36 deletions

View File

@ -155,8 +155,8 @@ public class HyosungPlcService(ILogger<HyosungPlcService> logger) : IHyosungPlcS
public event Func<string, Task>? OnPlcRequestPackLineOption;
public event Func<int, string, int, Task>? OnRequestPrintLabel;
public event Func<int, int, Task>? OnRequestPrintLabel;
public event Func<string, Task> OnRequestGetPrintLableOption;
private async Task ReadLoop(CancellationToken token)
{
@ -173,6 +173,7 @@ public class HyosungPlcService(ILogger<HyosungPlcService> logger) : IHyosungPlcS
await QueryPackLineOption();
await QueryPrintLabel();
await Task.Delay(100, token);
await QueryGetPrintLabel();
}
catch (Exception e)
{
@ -315,23 +316,32 @@ public class HyosungPlcService(ILogger<HyosungPlcService> 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]);
}
}
}

View File

@ -93,5 +93,7 @@ public interface IHyosungPlcService
/// <summary>
/// 贴标站请求贴标
/// </summary>
event Func<int, string, int, Task> OnRequestPrintLabel;
event Func<int, int, Task> OnRequestPrintLabel;
event Func<string, Task> OnRequestGetPrintLableOption;
}

View File

@ -13,6 +13,9 @@ public class HyosungScannerService : IHyosungScannerService
private readonly ConcurrentDictionary<int, HikScanner> _fixtureScanners = new();
private List<string> lastCodes = new List<string>();
public HyosungScannerService(ILogger<HyosungScannerService> 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<string> 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;
}
}

View File

@ -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<IVarietyService, VarietyService>();
services.AddSingleton<IYarnService, YarnService>();
services.AddSingleton<ITrayService, TrayService>();

View File

@ -12,8 +12,9 @@ public class AgvBinService : IAgvBinService
public AgvBinService(IServiceProvider provider)
{
_repository = provider.CreateScope().ServiceProvider.GetRequiredService<IRepository<AgvBinEntity>>();
_cache = _repository.GetList();
_repository = provider.CreateScope().ServiceProvider.GetRequiredService<IRepository<AgvBinEntity>>();
//_repository = provider.GetService<IRepository<AgvBinEntity>>();
_cache = _repository.GetList();
}
public async Task<AgvBinEntity> GetAvailableBin(int height)

View File

@ -13,9 +13,10 @@ public class DictService : IDictService
public DictService(IServiceProvider provider)
{
_repository = provider.CreateScope()
.ServiceProvider.GetRequiredService<IRepository<DictEntity>>();
_cache = _repository.GetList();
_repository = provider.CreateScope()
.ServiceProvider.GetRequiredService<IRepository<DictEntity>>();
//_repository = provider.GetService<IRepository<DictEntity>>();
_cache = _repository.GetList();
}

View File

@ -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
/// <param name="controlNo"></param>
/// <param name="itemInfo"></param>
/// <returns></returns>
Task<Tray> PrintTrayAsync(string trayCode, int stackHeight, int controlNo, MST_ITEM_2240_V itemInfo);
Task<Tray> PrintTrayAsync(string trayCode, int controlNo, MST_ITEM_2240_V itemInfo);
Task UpdateHeightAsync(string trayCode, int height);
}

View File

@ -13,7 +13,8 @@ public class PalletService : IPalletService
public PalletService(IServiceProvider serviceProvider)
{
_palletRepository = serviceProvider.CreateScope().ServiceProvider
.GetRequiredService<IRepository<PalletEntity>>();
.GetRequiredService<IRepository<PalletEntity>>();
// _palletRepository = serviceProvider.GetService<IRepository<PalletEntity>>();
_pallets = _palletRepository.GetList().Select(Pallet.FromEntity).ToList();
}

View File

@ -17,7 +17,8 @@ public class TrayService : ITrayService
public TrayService(IServiceProvider provider, IHyosungWmsService hyosungWmsService)
{
_repository = provider.CreateScope().ServiceProvider.GetRequiredService<IRepository<TrayEntity>>();
_repository = provider.CreateScope().ServiceProvider.GetRequiredService<IRepository<TrayEntity>>();
//_repository = provider.GetService<IRepository<TrayEntity>>();
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<Tray> PrintTrayAsync(string trayCode, int stackHeight, int controlNo, MST_ITEM_2240_V itemInfo)
public async Task<Tray> 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();
}
}

View File

@ -19,8 +19,10 @@ public class VarietyService : IVarietyService
{
_varietyRepository =
provider.CreateScope().ServiceProvider.GetRequiredService<IRepository<VarietyEntity>>();
_palletRepository = provider.CreateScope().ServiceProvider.GetRequiredService<IRepository<PalletEntity>>();
_varietiesCache = new List<VarietyEntity>(_varietyRepository.GetList());
_palletRepository = provider.CreateScope().ServiceProvider.GetRequiredService<IRepository<PalletEntity>>();
//_varietyRepository = provider.GetService<IRepository<VarietyEntity>>();
// _palletRepository = provider.GetService<IRepository<PalletEntity>>();
_varietiesCache = new List<VarietyEntity>(_varietyRepository.GetList());
_palletsCache = new List<PalletEntity>(_palletRepository.GetList());
}
catch (Exception e)

View File

@ -13,6 +13,7 @@ public class YarnService : IYarnService
public YarnService(IServiceProvider provider)
{
_yarnRepository = provider.CreateScope().ServiceProvider.GetRequiredService<IRepository<ScannedYarnEntity>>();
// _yarnRepository = provider.GetService<IRepository<ScannedYarnEntity>>();
NoFinished = new ConcurrentDictionary<string, Yarn>();
var yarns = _yarnRepository.GetList(y => !y.IsFinished);
foreach (var yarn in yarns)

View File

@ -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);
}
}
/// <summary>
/// 处理贴标站请求贴标事件
/// </summary>
@ -287,32 +309,25 @@ public class HyosungRuntime(
/// <param name="arg2"></param>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
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));
}