diff --git a/Seyounth.Core/Extensions/DateTimeExtensions.cs b/Seyounth.Core/Extensions/DateTimeExtensions.cs index 326190b..3b6736f 100644 --- a/Seyounth.Core/Extensions/DateTimeExtensions.cs +++ b/Seyounth.Core/Extensions/DateTimeExtensions.cs @@ -2,8 +2,8 @@ namespace Seyounth.Core.Extensions; public static class DateTimeExtensions { - public static int ToTimestamp(this DateTime dateTime) + public static long ToTimestamp(this DateTime dateTime) { - return (int)new DateTimeOffset(dateTime).ToUnixTimeSeconds(); + return new DateTimeOffset(dateTime).ToUnixTimeMilliseconds(); } } \ No newline at end of file diff --git a/Seyounth.Hyosung.Core/Agv/HyosungAgvService.cs b/Seyounth.Hyosung.Core/Agv/HyosungAgvService.cs index d215582..5d804af 100644 --- a/Seyounth.Hyosung.Core/Agv/HyosungAgvService.cs +++ b/Seyounth.Hyosung.Core/Agv/HyosungAgvService.cs @@ -13,7 +13,7 @@ public class HyosungAgvService( private readonly HikAgv _agv = new(loggerFactory.CreateLogger()); - public async Task StorageAsync(string trayCode) + public async Task StorageAsync(long trayCode) { AgvStatusInfo? status; do diff --git a/Seyounth.Hyosung.Core/Agv/IHyosungAgvService.cs b/Seyounth.Hyosung.Core/Agv/IHyosungAgvService.cs index a94d7a0..46e57ca 100644 --- a/Seyounth.Hyosung.Core/Agv/IHyosungAgvService.cs +++ b/Seyounth.Hyosung.Core/Agv/IHyosungAgvService.cs @@ -7,5 +7,5 @@ public interface IHyosungAgvService /// /// /// - Task StorageAsync(string trayCode); + Task StorageAsync(long trayCode); } \ No newline at end of file diff --git a/Seyounth.Hyosung.Core/Plc/HyosungPlcService.cs b/Seyounth.Hyosung.Core/Plc/HyosungPlcService.cs index e1f03f2..9a5da67 100644 --- a/Seyounth.Hyosung.Core/Plc/HyosungPlcService.cs +++ b/Seyounth.Hyosung.Core/Plc/HyosungPlcService.cs @@ -46,12 +46,12 @@ public class HyosungPlcService(ILogger logger) : IHyosungPlcS logger.LogInformation($"write [{variety.Id}] to plc address[4230]"); } - public async Task WriteScanYarnResultAsync(bool result, short? varietyId = null, string? yarnCode = null) + public async Task WriteScanYarnResultAsync(bool result, short? varietyId = null, long yarnCode = 0) { if (result && yarnCode != null && varietyId != null) { await _writer.WriteShortsAsync(4009, varietyId.Value); - await _writer.WriteStringAsync(4010, yarnCode); + await _writer.WriteLongAsync(4010, yarnCode); logger.LogInformation($"write [{yarnCode}] to plc address[4010]"); } @@ -81,10 +81,10 @@ public class HyosungPlcService(ILogger logger) : IHyosungPlcS isLeaving = false; } - public async Task WriteTrayCodeAsync(int index, string trayCode) + public async Task WriteTrayCodeAsync(int index, long trayCode) { var address = index == 1 ? 4100 : 4110; - await _writer.WriteStringAsync(address, trayCode); + await _writer.WriteLongAsync(address, trayCode); } public async Task WriteReceivedYarnCountAsync(int count) @@ -124,9 +124,9 @@ public class HyosungPlcService(ILogger logger) : IHyosungPlcS public event Func? OnPlcPutCompleted; - public event Func? OnPlcRequestPackLineOption; + public event Func? OnPlcRequestPackLineOption; - public event Func? OnRequestPrintLabel; + public event Func? OnRequestPrintLabel; private async Task ReadLoop(CancellationToken token) @@ -205,8 +205,8 @@ public class HyosungPlcService(ILogger logger) : IHyosungPlcS if (leavingProductionLine[0] == 1) { await _writer.WriteShortsAsync(4020, 0); - var trayCode = await _reader.ReadStringAsync(12600); - if (!string.IsNullOrEmpty(trayCode)) + var trayCode = await _reader.ReadLongAsync(12600); + if (trayCode != 0) { PlcStackInfo info = new PlcStackInfo() { @@ -244,21 +244,21 @@ public class HyosungPlcService(ILogger logger) : IHyosungPlcS 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); - var yarn3 = await _reader.ReadStringAsync(4650); + var trayCode = await _reader.ReadLongAsync(4620); + var yarn1 = await _reader.ReadLongAsync(4630); + var yarn2 = await _reader.ReadLongAsync(4640); + var yarn3 = await _reader.ReadLongAsync(4650); var info = new PlcStackingInfo() { TrayCode = trayCode, YarnCount = status[0], TotalYarnCount = status[1] }; - if (!string.IsNullOrEmpty(yarn1)) + if (yarn1!=0) info.YarnCode.Add(yarn1); - if (!string.IsNullOrEmpty(yarn2)) + if (yarn2!=0) info.YarnCode.Add(yarn2); - if (!string.IsNullOrEmpty(yarn3)) + if (yarn3!=0) info.YarnCode.Add(yarn3); if (info.YarnCode.Count != info.YarnCount) { @@ -280,7 +280,7 @@ public class HyosungPlcService(ILogger logger) : IHyosungPlcS var requestPackLineOption = await _reader.ReadShortsAsync(4022, 1); if (requestPackLineOption[0] == 1) { - var trayCode = await _reader.ReadStringAsync(12100); + var trayCode = await _reader.ReadLongAsync(12100); await _writer.WriteShortsAsync(4022, 0); OnPlcRequestPackLineOption?.Invoke(trayCode); } @@ -291,7 +291,7 @@ public class HyosungPlcService(ILogger logger) : IHyosungPlcS var requestPrintLabel = await _reader.ReadShortsAsync(13010, 3); if (requestPrintLabel[0] == 1) { - var trayCode = await _reader.ReadStringAsync(13000); + var trayCode = await _reader.ReadLongAsync(13000); await _writer.WriteShortsAsync(13010, 0); await _writer.WriteShortsAsync(13012, 0); OnRequestPrintLabel?.Invoke(1, trayCode, requestPrintLabel[2]); @@ -299,7 +299,7 @@ public class HyosungPlcService(ILogger logger) : IHyosungPlcS if (requestPrintLabel[1] == 1) { - var trayCode = await _reader.ReadStringAsync(13000); + var trayCode = await _reader.ReadLongAsync(13000); await _writer.WriteShortsAsync(13011, 0); await _writer.WriteShortsAsync(13012, 0); OnRequestPrintLabel?.Invoke(2, trayCode, requestPrintLabel[2]); diff --git a/Seyounth.Hyosung.Core/Plc/IHyosungPlcService.cs b/Seyounth.Hyosung.Core/Plc/IHyosungPlcService.cs index ed87387..c92c092 100644 --- a/Seyounth.Hyosung.Core/Plc/IHyosungPlcService.cs +++ b/Seyounth.Hyosung.Core/Plc/IHyosungPlcService.cs @@ -24,7 +24,7 @@ public interface IHyosungPlcService /// 品类ID /// 纱码 /// - Task WriteScanYarnResultAsync(bool result, short? varietyId = null, string? yarnCode = null); + Task WriteScanYarnResultAsync(bool result, short? varietyId = null, long yarnCode = 0); /// /// 写入治具扫码结果 @@ -47,7 +47,7 @@ public interface IHyosungPlcService /// /// /// - Task WriteTrayCodeAsync(int index, string trayCode); + Task WriteTrayCodeAsync(int index, long trayCode); /// /// 写入收到的纱数量 @@ -88,10 +88,10 @@ public interface IHyosungPlcService /// /// Plc请求打包线选项 /// - event Func OnPlcRequestPackLineOption; + event Func OnPlcRequestPackLineOption; /// /// 贴标站请求贴标 /// - event Func OnRequestPrintLabel; + event Func OnRequestPrintLabel; } \ No newline at end of file diff --git a/Seyounth.Hyosung.Core/Plc/McPlc.cs b/Seyounth.Hyosung.Core/Plc/McPlc.cs index b86f602..268319b 100644 --- a/Seyounth.Hyosung.Core/Plc/McPlc.cs +++ b/Seyounth.Hyosung.Core/Plc/McPlc.cs @@ -51,6 +51,27 @@ public class McPlc(string host, int port, Mitsubishi.McFrame type) return shorts; } + public async Task ReadLongAsync(int address) + { + // 一个 long 类型是 8 字节,所以需要读取 8 个字节的数据 + var bytes = await ReadBytesAsync(address, 8); + // 确保读取到了足够的字节 + if (bytes.Length < 8) + { + throw new Exception("读取 long 类型数据时字节数不足"); + } + // 将字节数组转换为 long 类型 + return BitConverter.ToInt64(bytes, 0); + } + + public async Task WriteLongAsync(int address, long value) + { + byte[] bytes = BitConverter.GetBytes(value); + + // Write the byte array to the PLC + await WriteBytesAsync(address, bytes); + } + public async Task WriteShortsAsync(int address, params short[] values) { var code = await _mc.WriteDeviceBlock(Mitsubishi.PlcDeviceType.D, address, values.Length, diff --git a/Seyounth.Hyosung.Core/Printer/HyosungPrinter.cs b/Seyounth.Hyosung.Core/Printer/HyosungPrinter.cs index e7b98c9..31abdbf 100644 --- a/Seyounth.Hyosung.Core/Printer/HyosungPrinter.cs +++ b/Seyounth.Hyosung.Core/Printer/HyosungPrinter.cs @@ -34,7 +34,7 @@ public class HyosungPrinter( logger.LogInformation("printer disconnected"); } - public async Task PrintAsync(int index, string trayCode) + public async Task PrintAsync(int index, long trayCode) { var tray = await trayService.GetByCode(trayCode); if (index == 1) diff --git a/Seyounth.Hyosung.Core/Printer/IHyosungPrinter.cs b/Seyounth.Hyosung.Core/Printer/IHyosungPrinter.cs index 4a2cbac..1a41047 100644 --- a/Seyounth.Hyosung.Core/Printer/IHyosungPrinter.cs +++ b/Seyounth.Hyosung.Core/Printer/IHyosungPrinter.cs @@ -11,5 +11,5 @@ public interface IHyosungPrinter /// /// /// - Task PrintAsync(int index,string trayCode); + Task PrintAsync(int index,long trayCode); } \ No newline at end of file diff --git a/Seyounth.Hyosung.Data/Entities/ScannedYarnEntity.cs b/Seyounth.Hyosung.Data/Entities/ScannedYarnEntity.cs index cc731c2..3ee217d 100644 --- a/Seyounth.Hyosung.Data/Entities/ScannedYarnEntity.cs +++ b/Seyounth.Hyosung.Data/Entities/ScannedYarnEntity.cs @@ -12,7 +12,7 @@ public class ScannedYarnEntity public string QrCode { get; set; } [SugarColumn(ColumnDescription = "纱线代码", Length = 20)] - public string ScanCode { get; set; } + public long ScanCode { get; set; } [SugarColumn(ColumnDescription = "Lot")] public int Lot { get; set; } diff --git a/Seyounth.Hyosung.Data/Entities/TrayEntity.cs b/Seyounth.Hyosung.Data/Entities/TrayEntity.cs index 5f69179..0b3c324 100644 --- a/Seyounth.Hyosung.Data/Entities/TrayEntity.cs +++ b/Seyounth.Hyosung.Data/Entities/TrayEntity.cs @@ -9,12 +9,12 @@ public class TrayEntity public int Id { get; set; } [SugarColumn(ColumnDescription = "托盘唯一号")] - public string TrayCode { get; set; } + public long TrayCode { get; set; } [SugarColumn(ColumnDescription = "所属的品类信息")] public int VarietyId { get; set; } - [SugarColumn(ColumnDescription = "垛高",IsNullable =true)] + [SugarColumn(ColumnDescription = "垛高", IsNullable = true)] public int? StackHeight { get; set; } [SugarColumn(ColumnDescription = "是否为双号")] diff --git a/Seyounth.Hyosung.Data/Models/Plc/PackLineOption.cs b/Seyounth.Hyosung.Data/Models/Plc/PackLineOption.cs index 13d0e74..0eb7fe4 100644 --- a/Seyounth.Hyosung.Data/Models/Plc/PackLineOption.cs +++ b/Seyounth.Hyosung.Data/Models/Plc/PackLineOption.cs @@ -16,5 +16,5 @@ public partial class PackLineOption : ObservableObject [ObservableProperty] private bool isLam; - [ObservableProperty] private string trayCode; + [ObservableProperty] private long trayCode; } \ No newline at end of file diff --git a/Seyounth.Hyosung.Data/Models/Plc/PlcStackInfo.cs b/Seyounth.Hyosung.Data/Models/Plc/PlcStackInfo.cs index 4899f27..88282ff 100644 --- a/Seyounth.Hyosung.Data/Models/Plc/PlcStackInfo.cs +++ b/Seyounth.Hyosung.Data/Models/Plc/PlcStackInfo.cs @@ -5,6 +5,6 @@ namespace Seyounth.Hyosung.Data.Models.Plc; /// public class PlcStackInfo { - public string TrayCode { get; set; } + public long TrayCode { get; set; } } \ No newline at end of file diff --git a/Seyounth.Hyosung.Data/Models/Plc/PlcStackingInfo.cs b/Seyounth.Hyosung.Data/Models/Plc/PlcStackingInfo.cs index 0975857..873bcd1 100644 --- a/Seyounth.Hyosung.Data/Models/Plc/PlcStackingInfo.cs +++ b/Seyounth.Hyosung.Data/Models/Plc/PlcStackingInfo.cs @@ -2,9 +2,9 @@ namespace Seyounth.Hyosung.Data.Models.Plc; public class PlcStackingInfo { - public string TrayCode { get; set; } + public long TrayCode { get; set; } - public List YarnCode { get; set; } = new List(); + public List YarnCode { get; set; } = new (); public int YarnCount { get; set; } diff --git a/Seyounth.Hyosung.Data/Models/Tray.cs b/Seyounth.Hyosung.Data/Models/Tray.cs index dbb07df..26aec10 100644 --- a/Seyounth.Hyosung.Data/Models/Tray.cs +++ b/Seyounth.Hyosung.Data/Models/Tray.cs @@ -6,7 +6,7 @@ public class Tray { public int Id { get; set; } - public string TrayCode { get; set; } + public long TrayCode { get; set; } public int VarietyId { get; set; } diff --git a/Seyounth.Hyosung.Data/Models/Yarn.cs b/Seyounth.Hyosung.Data/Models/Yarn.cs index 3a19b26..8e6496e 100644 --- a/Seyounth.Hyosung.Data/Models/Yarn.cs +++ b/Seyounth.Hyosung.Data/Models/Yarn.cs @@ -9,7 +9,7 @@ public class Yarn public string QrCode { get; set; } - public string ScanCode { get; set; } + public long ScanCode { get; set; } public int Lot { get; set; } @@ -53,7 +53,7 @@ public class Yarn ProduceTime = parts[3], ScanTime = DateTime.Now, VarietyId = varietyId, - ScanCode = DateTime.Now.ToTimestamp().ToString(), + ScanCode = DateTime.Now.ToTimestamp(), TrayId = null }; yarn.WorkShift = parts[1] switch @@ -79,7 +79,7 @@ public class Yarn ScanTime = DateTime.Now, VarietyId = varietyId, TrayId = null, - ScanCode = DateTime.Now.ToTimestamp().ToString().PadLeft(10, '0'), + ScanCode = DateTime.Now.ToTimestamp(), }; yarn.WorkShift = parts[5] switch { diff --git a/Seyounth.Hyosung.Data/Services/ITrayService.cs b/Seyounth.Hyosung.Data/Services/ITrayService.cs index bc574f9..0741330 100644 --- a/Seyounth.Hyosung.Data/Services/ITrayService.cs +++ b/Seyounth.Hyosung.Data/Services/ITrayService.cs @@ -17,21 +17,21 @@ public interface ITrayService /// /// /// - Task GetIdByCode(string code); + Task GetIdByCode(long code); /// /// /// /// /// - Task GetByCode(string code); + Task GetByCode(long code); /// /// 生成控制号 /// /// /// - Task StorageAsync(string trayCode); + Task StorageAsync(long trayCode); /// /// 打印托盘 @@ -41,5 +41,5 @@ public interface ITrayService /// /// /// - Task PrintTrayAsync(string trayCode, int stackHeight, int controlNo, MST_ITEM_2240_V itemInfo); + Task PrintTrayAsync(long trayCode, int stackHeight, int controlNo, MST_ITEM_2240_V itemInfo); } \ No newline at end of file diff --git a/Seyounth.Hyosung.Data/Services/IYarnService.cs b/Seyounth.Hyosung.Data/Services/IYarnService.cs index 3a90579..43c72ac 100644 --- a/Seyounth.Hyosung.Data/Services/IYarnService.cs +++ b/Seyounth.Hyosung.Data/Services/IYarnService.cs @@ -5,21 +5,21 @@ namespace Seyounth.Hyosung.Data.Services; public interface IYarnService { - ConcurrentDictionary NoFinished { get; } + ConcurrentDictionary NoFinished { get; } Task AddYarnAsync(Yarn yarn); Task> GetYarnsByTrayIdAsync(int trayId); - Task GetYarnByCodeAsync(string code); + Task GetYarnByCodeAsync(long code); /// /// 完成指定纱 /// /// /// - Task FinishYarnAsync(string yarnCode); + Task FinishYarnAsync(long yarnCode); /// /// 绑定托盘号 @@ -27,5 +27,5 @@ public interface IYarnService /// /// /// - Task BindTrayAsync(string yarnCode, int trayId); + Task BindTrayAsync(long yarnCode, int trayId); } \ No newline at end of file diff --git a/Seyounth.Hyosung.Data/Services/TrayService.cs b/Seyounth.Hyosung.Data/Services/TrayService.cs index 143d75b..f0a2224 100644 --- a/Seyounth.Hyosung.Data/Services/TrayService.cs +++ b/Seyounth.Hyosung.Data/Services/TrayService.cs @@ -11,7 +11,7 @@ namespace Seyounth.Hyosung.Data.Services; public class TrayService : ITrayService { - private readonly ConcurrentDictionary _cache = new(); + private readonly ConcurrentDictionary _cache = new(); private readonly IRepository _repository; private readonly IHyosungWmsService _hyosungWmsService; @@ -30,7 +30,7 @@ public class TrayService : ITrayService { var tray = new Tray() { - TrayCode =DateTime.Now.ToTimestamp().ToString(), + TrayCode = DateTime.Now.ToTimestamp(), VarietyId = varietyId, CreateTime = DateTime.Now }; @@ -42,21 +42,19 @@ public class TrayService : ITrayService return tray; } - public async Task GetIdByCode(string code) + public async Task GetIdByCode(long code) { try { return _cache[code].Id; - } catch { return (await _repository.GetFirstAsync(d => d.TrayCode == code)).Id; } - } - public async Task GetByCode(string code) + public async Task GetByCode(long code) { return Tray.FromEntity(await _repository.GetSingleAsync(t => t.TrayCode == code)); } @@ -66,7 +64,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(long trayCode, int stackHeight, int controlNo, MST_ITEM_2240_V itemInfo) { Tray tray; try @@ -77,7 +75,7 @@ public class TrayService : ITrayService { tray = await GetByCode(trayCode); } - + tray.ControlNo = controlNo; tray.StackHeight = stackHeight; tray.Grade = itemInfo.GRADE; @@ -91,8 +89,7 @@ public class TrayService : ITrayService _cache.Remove(tray.TrayCode, out _); } - public async Task StorageAsync(string trayCode) + public async Task StorageAsync(long trayCode) { - } } \ No newline at end of file diff --git a/Seyounth.Hyosung.Data/Services/YarnService.cs b/Seyounth.Hyosung.Data/Services/YarnService.cs index 138993b..b55003f 100644 --- a/Seyounth.Hyosung.Data/Services/YarnService.cs +++ b/Seyounth.Hyosung.Data/Services/YarnService.cs @@ -13,7 +13,7 @@ public class YarnService : IYarnService public YarnService(IServiceProvider provider) { _yarnRepository = provider.CreateScope().ServiceProvider.GetRequiredService>(); - NoFinished = new ConcurrentDictionary(); + NoFinished = new ConcurrentDictionary(); var yarns = _yarnRepository.GetList(y => !y.IsFinished); foreach (var yarn in yarns) { @@ -21,7 +21,7 @@ public class YarnService : IYarnService } } - public ConcurrentDictionary NoFinished { get; } + public ConcurrentDictionary NoFinished { get; } public async Task AddYarnAsync(Yarn yarn) { @@ -37,7 +37,7 @@ public class YarnService : IYarnService .Select(Yarn.FromEntity).ToList(); } - public async Task GetYarnByCodeAsync(string code) + public async Task GetYarnByCodeAsync(long code) { try { @@ -50,7 +50,7 @@ public class YarnService : IYarnService } - public async Task FinishYarnAsync(string yarnCode) + public async Task FinishYarnAsync(long yarnCode) { var yarn = NoFinished[yarnCode]; yarn.IsFinished = true; @@ -58,7 +58,7 @@ public class YarnService : IYarnService NoFinished.TryRemove(yarnCode, out _); } - public async Task BindTrayAsync(string yarnCode, int trayId) + public async Task BindTrayAsync(long yarnCode, int trayId) { var yarn = NoFinished[yarnCode]; yarn.TrayId = trayId; diff --git a/Seyounth.Hyosung.Runtime/HyosungRuntime.cs b/Seyounth.Hyosung.Runtime/HyosungRuntime.cs index c85ea72..7165216 100644 --- a/Seyounth.Hyosung.Runtime/HyosungRuntime.cs +++ b/Seyounth.Hyosung.Runtime/HyosungRuntime.cs @@ -245,7 +245,7 @@ public class HyosungRuntime( /// /// /// - private async Task OnPlcRequestPackLineOption(string arg) + private async Task OnPlcRequestPackLineOption(long arg) { logger.LogInformation($"plc request pack line option"); try @@ -286,7 +286,7 @@ public class HyosungRuntime( /// /// /// - private async Task OnPlcRequestPrintLabel(int arg1, string trayCode, int height) + private async Task OnPlcRequestPrintLabel(int arg1, long trayCode, int height) { logger.LogInformation($"plc request print label:{arg1} {trayCode} {height}"); try diff --git a/Seyounth.Hyosung.Runtime/Models/StackStationModel.cs b/Seyounth.Hyosung.Runtime/Models/StackStationModel.cs index 2ba2c04..254d8ac 100644 --- a/Seyounth.Hyosung.Runtime/Models/StackStationModel.cs +++ b/Seyounth.Hyosung.Runtime/Models/StackStationModel.cs @@ -9,7 +9,7 @@ namespace Seyounth.Hyosung.Runtime.Models; public partial class StackStationModel { [ObservableProperty] [DefaultValue("NoData")] - private string trayCode; + private long trayCode; [ObservableProperty] [DefaultValue("NoData")] private string varietyCode;