diff --git a/EpsonPrintService/Program.cs b/EpsonPrintService/Program.cs index 098654a..2d4f8fc 100644 --- a/EpsonPrintService/Program.cs +++ b/EpsonPrintService/Program.cs @@ -35,6 +35,7 @@ kernel.Bind().ToMethod(ctx => var loggerFactory = LoggerFactory.Create(builder => { builder.AddConsole(); + builder.SetMinimumLevel(LogLevel.Trace); }); return loggerFactory.CreateLogger("EpsonPrintService"); }); @@ -48,10 +49,12 @@ kernel.Bind().ToSelf().InSingletonScope(); kernel.Bind().ToSelf().InSingletonScope(); var printLoop = kernel.Get(); - +var printServer = kernel.Get(); var discoveryTask = kernel.Get(); var heartbeatTask = kernel.Get(); +//printServer.RegisterPrinter("10.0.20.12"); + await printLoop.StartAsync(); diff --git a/EpsonTest/Program.cs b/EpsonTest/Program.cs index 1bf2ce4..475b650 100644 --- a/EpsonTest/Program.cs +++ b/EpsonTest/Program.cs @@ -378,12 +378,14 @@ receipt.Gangs[0].Dishes.Add(new Dish(1, "Salmon Taco") var serializedReceipt = JsonSerializer.Serialize(receipt, new JsonSerializerOptions { WriteIndented = true }); var deserializedReceipt = JsonSerializer.Deserialize(serializedReceipt); -KitchenReceiptConverter converter = new KitchenReceiptConverter(bigLineWidth: 20, lineWidth: 33); +KitchenReceiptConverter converter = new KitchenReceiptConverter(bigLineWidth: 18, lineWidth: 33); var printCommands = converter.ConvertToPrintCommands(deserializedReceipt); Console.WriteLine("=== PRINT COMMANDS ===\n"); -var printer = new HtmlPrinter(@".\test.html", paperWidth: 258); -await printer.ConnectAsync(""); +//var printer = new HtmlPrinter(@".\test.html", paperWidth: 258); +//await printer.ConnectAsync(""); +var printer = new EpsonPrinter(); +await printer.ConnectAsync("127.0.0.1",8888); await Task.Delay(200); await printer.FeedLinesAsync(1); await printer.SetCustomLineSpacing(22); @@ -395,28 +397,26 @@ foreach (var command in printCommands) if (command.IsRed) attributes += "[RED] "; Console.WriteLine($"{attributes}{command.Text}"); + await printer.SetBiggerFontTM220(command.IsBig); + - if (command.IsBig) - { - await printer.SetFontSizeAsync(2, 1); - } - else - { - await printer.SetFontSizeAsync(1, 1); - } + await Task.Delay(200); await printer.SetRedColor(command.IsRed); - //await Task.Delay(200); + await Task.Delay(200); await printer.SetEmphasized(command.IsBold); - //await Task.Delay(200); + await Task.Delay(200); await printer.PrintTextAsync(command.Text + "\n"); - //await Task.Delay(200); + await Task.Delay(200); } +await printer.FeedLinesAsync(5); +await Task.Delay(200*5); +await printer.CutAsync(); //await printer.SetDefaultLineSpacing(); //await printer.PrintTextAsync( diff --git a/Inspectron.Epson/EpsonPrinter.cs b/Inspectron.Epson/EpsonPrinter.cs index 140a948..9649074 100644 --- a/Inspectron.Epson/EpsonPrinter.cs +++ b/Inspectron.Epson/EpsonPrinter.cs @@ -304,15 +304,27 @@ public class EpsonPrinter : IEpsonPrinter _logger?.LogInformation("Selecting font: {Font}", font); await SendRawAsync(command); } - - public async Task SetBiggerFontTM220(bool enabled) + /// + /// Change to bigger font mode for TM-T20/220 printers + /// + /// + /// + /// + /// + public async Task SetBiggerFontTM220(bool biggerWidth, bool biggerHeight=false, bool secondaryFont=true) { - _logger?.LogInformation("{Action} bigger font mode for TM-T20/220", - enabled ? "Enabling" : "Disabling"); - if (enabled) - await SendRawCommandAsync([0x1b, 0x21, 0x20 + 0x01]); - else - await SendRawCommandAsync([0x1b, 0x21, 0x00]); + _logger?.LogInformation("Setting bigger font mode: Width={BiggerWidth}, Height={BiggerHeight}, SecondaryFont={SecondaryFont}", + biggerWidth, biggerHeight, secondaryFont); + + byte value = 0x00; + if (biggerWidth) + value += 0x10; + if (biggerHeight) + value += 0x20; + if (secondaryFont) + value += 0x01; + + await SendRawCommandAsync([0x1b, 0x21, value]); } diff --git a/Inspectron.Epson/HtmlPrinter.cs b/Inspectron.Epson/HtmlPrinter.cs index 9662888..914d3a3 100644 --- a/Inspectron.Epson/HtmlPrinter.cs +++ b/Inspectron.Epson/HtmlPrinter.cs @@ -31,7 +31,8 @@ public class HtmlPrinter : IEpsonPrinter private bool _isEmphasized; private bool _isRedColor; private bool _isQuadrupleMode; - private bool _isBiggerFontTM220; + private bool _isBiggerFontWidthTM220; + private bool _isBiggerFontHeightTM220; private int _lineSpacing = 14; // Default line spacing in pixels (scaled for screen) private int _absolutePosition; // Current X position offset @@ -239,10 +240,13 @@ public class HtmlPrinter : IEpsonPrinter } /// - public Task SetBiggerFontTM220(bool enabled) + public Task SetBiggerFontTM220(bool biggerWidth, bool biggerHeight = false, bool secondaryFont = true) { - _logger?.LogInformation("HtmlPrinter: {Action} bigger font mode for TM-T20/220", enabled ? "Enabling" : "Disabling"); - _isBiggerFontTM220 = enabled; + _logger?.LogInformation("HtmlPrinter: Setting bigger font mode: Width={BiggerWidth}, Height={BiggerHeight}, SecondaryFont={SecondaryFont}", + biggerWidth, biggerHeight, secondaryFont); + _isBiggerFontWidthTM220 = biggerWidth; + _isBiggerFontHeightTM220 = biggerHeight; + // Note: secondaryFont is ignored in HTML simulation as it only affects the physical printer's font selection return Task.CompletedTask; } @@ -468,7 +472,8 @@ public class HtmlPrinter : IEpsonPrinter _isEmphasized = false; _isRedColor = false; _isQuadrupleMode = false; - _isBiggerFontTM220 = false; + _isBiggerFontWidthTM220 = false; + _isBiggerFontHeightTM220 = false; _lineSpacing = 14; _absolutePosition = 0; } @@ -490,11 +495,16 @@ public class HtmlPrinter : IEpsonPrinter effectiveHeightMultiplier *= 2; } - if (_isBiggerFontTM220) + if (_isBiggerFontWidthTM220) { effectiveWidthMultiplier *= 2; } + if (_isBiggerFontHeightTM220) + { + effectiveHeightMultiplier *= 2; + } + int fontSize = baseHeight * effectiveHeightMultiplier; styles.Add($"font-size: {fontSize}px"); diff --git a/Inspectron.Epson/IEpsonPrinter.cs b/Inspectron.Epson/IEpsonPrinter.cs index d3008b1..a4a375f 100644 --- a/Inspectron.Epson/IEpsonPrinter.cs +++ b/Inspectron.Epson/IEpsonPrinter.cs @@ -90,7 +90,7 @@ public interface IEpsonPrinter : IAsyncDisposable /// /// Enable or disable bigger font mode for TM-T20/220 /// - Task SetBiggerFontTM220(bool enabled); + Task SetBiggerFontTM220(bool biggerWidth, bool biggerHeight = false, bool secondaryFont = true); /// /// Print text to the printer diff --git a/Inspectron.Epson/PrintServer/PrintServices/EpsonPrintService.cs b/Inspectron.Epson/PrintServer/PrintServices/EpsonPrintService.cs index 6438847..63f004a 100644 --- a/Inspectron.Epson/PrintServer/PrintServices/EpsonPrintService.cs +++ b/Inspectron.Epson/PrintServer/PrintServices/EpsonPrintService.cs @@ -34,6 +34,8 @@ public class EpsonPrintService: IPrintService var printerId = await epsonPrinter.GetPrinterIdAsync(); + _logger.LogInformation("Printer ID({ip}): {PrinterId}", printerIp, printerId); + var status = await epsonPrinter.GetPrinterStatusAsync(); if (!status.IsOnline) { diff --git a/Inspectron.Epson/PrintServer/Printers/TM-T30IIITranslated.cs b/Inspectron.Epson/PrintServer/Printers/TM-T30IIITranslated.cs index 6b167c7..db808f5 100644 --- a/Inspectron.Epson/PrintServer/Printers/TM-T30IIITranslated.cs +++ b/Inspectron.Epson/PrintServer/Printers/TM-T30IIITranslated.cs @@ -42,6 +42,13 @@ public class TM_T30IIITranslated : IPrinter foreach (var command in commands) { + if(command.SetLineSpacing.HasValue) + { + Console.WriteLine($"Setting line spacing to {command.SetLineSpacing.Value}"); + await _printer.SetCustomLineSpacing(command.SetLineSpacing.Value); + Console.WriteLine($"------------------------------------------------------"); + continue; + } if (command.IsBig) { await _printer.SetFontSizeAsync(2, 1);