lukevp / ESC-POS-.NET

Efficient, Easy to Use Thermal Printing & POS (Windows/Linux/OSX, WiFi/BT/USB/Ethernet)
MIT License
500 stars 161 forks source link

Intermittent Printing Issues on Cash Register Computers with Epson TM-T20III and ESCPOS_NET #271

Open Yalcinmehmet opened 2 months ago

Yalcinmehmet commented 2 months ago

Environment:

` private async Task PrintSale(Sale sale) { try { string printerIPAddress = this.PrinterIPAddressTextBox.Text; IPAddress ipAddress; bool isValidIP = IPAddress.TryParse(printerIPAddress, out ipAddress);

    if (!isValidIP)
    {
        MessageBox.Show($"'{printerIPAddress}' is not a valid IP address.");
        return;
    }

    string hostName = ipAddress.ToString();
    Advertisement advertisement = this.GetRandomAdvertisementFromList();
    var printer = new ImmediateNetworkPrinter(new ImmediateNetworkPrinterSettings { ConnectionString = $"{hostName}:{port}", PrinterName = printerName });

    var epson = new EPSON();

    await printer.WriteAsync(epson.Initialize());
    await printer.WriteAsync(
      ByteSplicer.Combine(
        epson.CodePage(CodePage.WPC1254_TURKISH),
        epson.RightAlign(),
        advertisement?.LogoPath == null ? epson.Print("\n") : epson.PrintImage(File.ReadAllBytes(advertisement.LogoPath), false),
        epson.LeftAlign(),
        epson.SetStyles(PrintStyle.None),
        epson.SetStyles(PrintStyle.DoubleWidth | PrintStyle.DoubleHeight | PrintStyle.Bold),
        epson.LeftAlign(),
        epson.PrintLine($"{sale.Item.Name}"),
        epson.Print("\n"),
        epson.SetStyles(PrintStyle.None),
        epson.SetStyles(PrintStyle.Bold),
        epson.Print($"{sale.Item.Number} Ad. {sale.Item.Sum} Euro"),
        epson.Print("\n"),
        epson.SetStyles(PrintStyle.None),
        epson.Print("\n"),
        epson.PrintLine($" {sale.SaleTime.ToString("dd.MM.yyyy - HH:mm:ss")}"),
        epson.Print("\n"),
        epson.PartialCutAfterFeed(5)
      )
    );

    printer = null;
    await Task.Delay(1000);
}
catch (Exception ex)
{
    MessageBox.Show(ex.Message);
}

}`

Issue Description: The application works as expected on my development machine, allowing me to print multiple receipts consecutively without issues. However, on the cash register computers, which are less powerful, prints are intermittently aborted. After a print job is aborted, the printer becomes unresponsive and cannot be accessed until it is restarted.

Yalcinmehmet commented 2 months ago

I'm planning to change the implementation of our printing process to potentially solve the intermittent printing issues on the cash register computers. Instead of sending print commands consecutively via PrintAsync for each part of the receipt, I intend to gather all the data first into a single byte array. This array will then be sent to the printer in one go. This approach should help in reducing the overhead of multiple network transactions and may manage printer resources more efficiently. I'll update this thread with the results of this modification to see if it resolves the unresponsiveness and failure issues we are experiencing.

igorocampos commented 1 month ago

Sounds like your solution is what I would suggest :)

Hope it went well.