diff --git a/Seyounth.Hyosung.Core/Plc/HyosungPlcService.cs b/Seyounth.Hyosung.Core/Plc/HyosungPlcService.cs index 11d0064..37f0c36 100644 --- a/Seyounth.Hyosung.Core/Plc/HyosungPlcService.cs +++ b/Seyounth.Hyosung.Core/Plc/HyosungPlcService.cs @@ -132,15 +132,23 @@ public class HyosungPlcService(ILogger logger) : IHyosungPlcS { while (!token.IsCancellationRequested) { - await QueryScanProductRequest(); - await QueryScanFixtureRequest(); - if (!isLeaving) - await QueryLeavingProductionLine(); - await QueryNeedTrayCode(); - await QueryPutOnceCompleted(); - await QueryPackLineOption(); - await QueryPrintLabel(); - await Task.Delay(100, token); + try + { + await QueryScanProductRequest(); + await QueryScanFixtureRequest(); + if (!isLeaving) + await QueryLeavingProductionLine(); + await QueryNeedTrayCode(); + await QueryPutOnceCompleted(); + await QueryPackLineOption(); + await QueryPrintLabel(); + await Task.Delay(100, token); + } + catch(Exception e) + { + + } + } } @@ -234,8 +242,9 @@ public class HyosungPlcService(ILogger logger) : IHyosungPlcS private async Task QueryPutOnceCompleted() { var status = await _reader.ReadShortsAsync(4691, 2); - if (status[0] == 1) + if (status[0] >0 ) { + await _writer.WriteShortsAsync(4690, 0, 0, 0); var trayCode = await _reader.ReadStringAsync(4620); var yarn1 = await _reader.ReadStringAsync(4630); var yarn2 = await _reader.ReadStringAsync(4640); @@ -258,7 +267,7 @@ public class HyosungPlcService(ILogger logger) : IHyosungPlcS return; } - await _writer.WriteShortsAsync(4690, 0, 0, 0); + await _writer.WriteShortsAsync(4620, new short[40]); OnPlcPutCompleted?.Invoke(info); } diff --git a/Seyounth.Hyosung.Data/Entities/TrayEntity.cs b/Seyounth.Hyosung.Data/Entities/TrayEntity.cs index a2f8a63..5f69179 100644 --- a/Seyounth.Hyosung.Data/Entities/TrayEntity.cs +++ b/Seyounth.Hyosung.Data/Entities/TrayEntity.cs @@ -14,7 +14,7 @@ public class TrayEntity [SugarColumn(ColumnDescription = "所属的品类信息")] public int VarietyId { get; set; } - [SugarColumn(ColumnDescription = "垛高")] + [SugarColumn(ColumnDescription = "垛高",IsNullable =true)] public int? StackHeight { get; set; } [SugarColumn(ColumnDescription = "是否为双号")] diff --git a/Seyounth.Hyosung.Data/Entities/VarietyEntity.cs b/Seyounth.Hyosung.Data/Entities/VarietyEntity.cs index de232f9..0b747c8 100644 --- a/Seyounth.Hyosung.Data/Entities/VarietyEntity.cs +++ b/Seyounth.Hyosung.Data/Entities/VarietyEntity.cs @@ -57,7 +57,7 @@ public class VarietyEntity [SugarColumn(ColumnDescription = "垛头数量")] public int? StackHeadCount { get; set; } - [SugarColumn(ColumnDescription = "纸托Id")] + [SugarColumn(ColumnDescription = "纸托Id",IsNullable =true)] public int? PaperTrayId { get; set; } [SugarColumn(ColumnDescription = "是否需要纸箱")] diff --git a/Seyounth.Hyosung.Data/Models/NeedType.cs b/Seyounth.Hyosung.Data/Models/NeedType.cs index 0693061..41be46c 100644 --- a/Seyounth.Hyosung.Data/Models/NeedType.cs +++ b/Seyounth.Hyosung.Data/Models/NeedType.cs @@ -4,10 +4,10 @@ namespace Seyounth.Hyosung.Data.Models; public enum NeedType { - [Description("需要")] Need, - [Description("不需要")] NotNeed, - [Description("单号需要")] OddNeed, - [Description("双号需要")] EvenNeed + [Description("需要")] Need=1, + [Description("不需要")] NotNeed=2, + [Description("单号需要")] OddNeed=3, + [Description("双号需要")] EvenNeed=4 } public class NeedTypeEnumItem diff --git a/Seyounth.Hyosung.Data/Models/Variety.cs b/Seyounth.Hyosung.Data/Models/Variety.cs index 49f7e6b..e4aa400 100644 --- a/Seyounth.Hyosung.Data/Models/Variety.cs +++ b/Seyounth.Hyosung.Data/Models/Variety.cs @@ -164,13 +164,13 @@ public class Variety ls.Add((short)PaperTray.Height); } - ls.Add((short)TopAndBottomPallet.HoleCount); - ls.Add((short)(TopAndBottomPallet.IsBigHole.Value ? 1 : 2)); + ls.Add((short)(TopAndBottomPallet.HoleCount is null?0: TopAndBottomPallet.HoleCount)); + ls.Add((short)(TopAndBottomPallet.IsBigHole is null?2:(TopAndBottomPallet.IsBigHole.Value?1:2))); ls.Add((short)TopAndBottomPallet.Length); ls.Add((short)TopAndBottomPallet.Width); ls.Add((short)TopAndBottomPallet.Height); - ls.Add((short)MiddlePallet.HoleCount); - ls.Add((short)(MiddlePallet.IsBigHole.Value ? 1 : 2)); + ls.Add((short)(MiddlePallet.HoleCount is null ? 0 : MiddlePallet.HoleCount)); + ls.Add((short)(MiddlePallet.IsBigHole is null ? 2 : (MiddlePallet.IsBigHole.Value ? 1 : 2))); ls.Add((short)MiddlePallet.Length); ls.Add((short)MiddlePallet.Width); ls.Add((short)MiddlePallet.Height); diff --git a/Seyounth.Hyosung.Data/ServiceExtensions.cs b/Seyounth.Hyosung.Data/ServiceExtensions.cs index 218b491..526888e 100644 --- a/Seyounth.Hyosung.Data/ServiceExtensions.cs +++ b/Seyounth.Hyosung.Data/ServiceExtensions.cs @@ -16,24 +16,24 @@ public static class ServiceExtensions var connectionString = configuration.GetConnectionString("DefaultConnection"); services.AddSingleton(s => { -//#if RELEASE - // SqlSugarScope sqlSugar = new SqlSugarScope(new ConnectionConfig() - // { - // DbType = DbType.SqlServer, - // ConnectionString = connectionString, - // IsAutoCloseConnection = true, - // } - // ); -//#elif DEBUG + //#if RELEASE SqlSugarScope sqlSugar = new SqlSugarScope(new ConnectionConfig() - { - DbType = DbType.Sqlite, - ConnectionString = "Data Source=hyosung.db", - IsAutoCloseConnection = true, - InitKeyType = InitKeyType.Attribute - } + { + DbType = DbType.SqlServer, + ConnectionString = connectionString, + IsAutoCloseConnection = true, + } ); -//#endif + //#elif DEBUG + //SqlSugarScope sqlSugar = new SqlSugarScope(new ConnectionConfig() + // { + // DbType = DbType.Sqlite, + // ConnectionString = "Data Source=hyosung.db", + // IsAutoCloseConnection = true, + // InitKeyType = InitKeyType.Attribute + // } + //); + //#endif return sqlSugar; }); services.AddScoped(typeof(IRepository<>), typeof(Repository<>)); @@ -49,13 +49,13 @@ public static class ServiceExtensions public static void UseHyosungData(this IServiceProvider provider) { - var db = provider.GetRequiredService(); - db.DbMaintenance.CreateDatabase(); - db.CodeFirst.InitTables(typeof(VarietyEntity), - typeof(PalletEntity), - typeof(ScannedYarnEntity), - typeof(TrayEntity), - typeof(AgvBinEntity), - typeof(DictEntity)); + //var db = provider.GetRequiredService(); + //db.DbMaintenance.CreateDatabase(); + //db.CodeFirst.InitTables(typeof(VarietyEntity), + // typeof(PalletEntity), + // typeof(ScannedYarnEntity), + // typeof(TrayEntity), + // typeof(AgvBinEntity), + // typeof(DictEntity)); } } \ No newline at end of file diff --git a/Seyounth.Hyosung.Data/Services/TrayService.cs b/Seyounth.Hyosung.Data/Services/TrayService.cs index d605857..e9989aa 100644 --- a/Seyounth.Hyosung.Data/Services/TrayService.cs +++ b/Seyounth.Hyosung.Data/Services/TrayService.cs @@ -1,5 +1,6 @@ using System.Collections.Concurrent; using Microsoft.Extensions.DependencyInjection; +using Seyounth.Core.Extensions; using Seyounth.Hyosung.Data.Entities; using Seyounth.Hyosung.Data.Models; using Seyounth.Hyosung.Data.Repositories; @@ -29,7 +30,7 @@ public class TrayService : ITrayService { var tray = new Tray() { - TrayCode = DateTime.Now.ToString("yyMMddHHmmss"), + TrayCode =DateTime.Now.ToTimestamp().ToString(), VarietyId = varietyId, CreateTime = DateTime.Now }; @@ -43,7 +44,16 @@ public class TrayService : ITrayService public async Task GetIdByCode(string code) { - return _cache[code].Id; + try + { + return _cache[code].Id; + + } + catch + { + return (await _repository.GetFirstAsync(d => d.TrayCode == code)).Id; + } + } public async Task GetByCode(string code) diff --git a/Seyounth.Hyosung.Data/Services/YarnService.cs b/Seyounth.Hyosung.Data/Services/YarnService.cs index 66f04a5..138993b 100644 --- a/Seyounth.Hyosung.Data/Services/YarnService.cs +++ b/Seyounth.Hyosung.Data/Services/YarnService.cs @@ -39,7 +39,15 @@ public class YarnService : IYarnService public async Task GetYarnByCodeAsync(string code) { - return NoFinished[code]; + try + { + return NoFinished[code]; + } + catch + { + return Yarn.FromEntity(await _yarnRepository.GetFirstAsync(d => d.ScanCode == code)) ; + } + } public async Task FinishYarnAsync(string yarnCode) diff --git a/Seyounth.Hyosung.Runtime/HyosungRuntime.cs b/Seyounth.Hyosung.Runtime/HyosungRuntime.cs index c26a477..76237d0 100644 --- a/Seyounth.Hyosung.Runtime/HyosungRuntime.cs +++ b/Seyounth.Hyosung.Runtime/HyosungRuntime.cs @@ -102,6 +102,13 @@ public class HyosungRuntime( return; } + var variety = await varietyService.GetById(varietyId); + if (yarn.Lot != variety.Lot) + { + await hyosungPlcService.WriteScanYarnResultAsync(false); + logger.LogInformation($"scan yarn fail,lot not equal"); + return; + } await yarnService.AddYarnAsync(yarn); await hyosungPlcService.WriteScanYarnResultAsync(true, (short)varietyId, yarn.ScanCode); logger.LogInformation($"scan yarn {yarn.ScanCode} success: qrcode[{yarn.QrCode}]"); @@ -180,6 +187,7 @@ public class HyosungRuntime( foreach (var yarnCode in arg.YarnCode) { await yarnService.BindTrayAsync(yarnCode, await trayService.GetIdByCode(arg.TrayCode)); + logger.LogInformation($" stack yarn{yarnCode} succeed"); } await hyosungPlcService.WriteReceivedYarnCountAsync(arg.YarnCode.Count);