97 lines
3.0 KiB
C#
97 lines
3.0 KiB
C#
using Inspectron.Epson.PrintServer.Printers.Utils;
|
|
using Inspectron.Epson.PrintServer.PrintServices;
|
|
|
|
namespace Inspectron.Epson.PrintServer.Printers;
|
|
|
|
/// <summary>
|
|
/// Adapter for the POS895 / POS896, SPRT-family ESC/POS clones on an 80 mm,
|
|
/// 576-dot line (Font A = 48 columns).
|
|
///
|
|
/// Cloned from TM_T30IIITranslated with three differences, each confirmed on
|
|
/// hardware and recorded in POS895_POS896_integration_notes.md:
|
|
///
|
|
/// 1. ESC d n is ignored by this firmware, so feeding uses literal LF bytes.
|
|
/// Using ESC d would cut the receipt through its last line.
|
|
/// 2. GS ( L prints nothing, so the logo goes out as ESC * bit-image.
|
|
/// 3. The line is 576 dots, not 384, and the logo spans it from position 0,
|
|
/// which avoids ESC $ (still unverified here).
|
|
/// </summary>
|
|
public class POS895 : IPrinter
|
|
{
|
|
/// <summary>Dots per line. Font A is 12 dots wide, giving 48 columns.</summary>
|
|
public const int PaperWidthDots = 576;
|
|
|
|
private const byte LineFeed = 0x0A;
|
|
private const int FeedLinesBeforeCut = 10;
|
|
|
|
private readonly IEpsonPrinter _printer;
|
|
|
|
public bool SkipDelays { get; set; }
|
|
|
|
public POS895(IEpsonPrinter printer)
|
|
{
|
|
_printer = printer;
|
|
}
|
|
|
|
public Task InitAsync()
|
|
{
|
|
return _printer.InitAsync();
|
|
}
|
|
|
|
public async Task PrintImageAsync(string path)
|
|
{
|
|
await FeedAsync(1);
|
|
await _printer.PrintImageBitModeAsync(
|
|
path, EpsonCommands.BitImageMode.DoubleDensity24Dot, PaperWidthDots);
|
|
if (!SkipDelays) await Task.Delay(100);
|
|
await FeedAsync(1);
|
|
}
|
|
|
|
public async Task PrintAsync(List<PrintCommand> commands)
|
|
{
|
|
await _printer.SetCustomLineSpacing(22);
|
|
|
|
foreach (var command in commands)
|
|
{
|
|
if (command.IsCut)
|
|
{
|
|
await FeedAsync(FeedLinesBeforeCut);
|
|
await _printer.CutAsync(false);
|
|
continue;
|
|
}
|
|
|
|
if (command.SetLineSpacing.HasValue)
|
|
{
|
|
await _printer.SetCustomLineSpacing(command.SetLineSpacing.Value);
|
|
continue;
|
|
}
|
|
|
|
await _printer.SetFontSizeAsync(command.IsBig ? 2 : 1, command.IsTall ? 2 : 1);
|
|
await _printer.SetEmphasized(command.IsBold);
|
|
await _printer.PrintTextAsync(command.Text + "\n");
|
|
}
|
|
|
|
await _printer.SetDefaultLineSpacing();
|
|
await FeedAsync(FeedLinesBeforeCut);
|
|
if (!SkipDelays) await Task.Delay(200);
|
|
}
|
|
|
|
public async Task Cut()
|
|
{
|
|
await _printer.CutAsync();
|
|
if (!SkipDelays) await Task.Delay(200);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Feeds with literal LF bytes. IEpsonPrinter.FeedLinesAsync emits ESC d,
|
|
/// which this firmware ignores, and the Epson models depend on that method
|
|
/// staying as it is.
|
|
/// </summary>
|
|
private Task FeedAsync(int lines)
|
|
{
|
|
var bytes = new byte[lines];
|
|
Array.Fill(bytes, LineFeed);
|
|
return _printer.SendRawCommandAsync(bytes);
|
|
}
|
|
}
|