lukevp / ESC-POS-.NET

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

C# Api implementation error #203

Open maximilianoCalderon opened 1 year ago

maximilianoCalderon commented 1 year ago

Hi Team, first of all i want to thank for this great and useful work! I have an API implementation for a POS Software (C#, .NET 5.0), i was using the 1.6.0 version and was running perfectly. This is my code

 [HttpPost("test")]
        public IActionResult test()
        {
            var printer = new SerialPrinter(portName: "COM4", baudRate: 115200);
            try
            {
                var e = new EPSON();
                printer.Write( // or, if using and immediate printer, use await printer.WriteAsync
                  ByteSplicer.Combine(
                    e.CenterAlign(),
                    //e.PrintImage(File.ReadAllBytes("images/pd-logo-300.png"), true),
                    e.FeedDots(4),
                    e.SetBarcodeHeightInDots(360),
                    e.SetBarWidth(BarWidth.Default),
                    e.SetBarLabelPosition(BarLabelPrintPosition.None),
                    e.PrintBarcode(BarcodeType.ITF, "0123456789"),
                    e.FeedLines(1),
                    e.PrintLine("B&H PHOTO & VIDEO"),
                    e.PrintLine("420 NINTH AVE."),
                    e.PrintLine("NEW YORK, NY 10001"),
                    e.PrintLine("(212) 502-6380 - (800)947-9975"),
                    e.SetStyles(PrintStyle.Underline),
                    e.PrintLine("www.bhphotovideo.com"),
                    e.SetStyles(PrintStyle.None),
                    e.FeedLines(1),
                    e.LeftAlign(),
                    e.PrintLine("Order: 123456789        Date: 02/01/19"),
                    e.FeedLines(2),
                    e.SetStyles(PrintStyle.FontB),
                    e.PrintLine("1   TRITON LOW-NOISE IN-LINE MICROPHONE PREAMP"),
                    e.PrintLine("    TRFETHEAD/FETHEAD                        89.95         89.95"),
                    e.PrintLine("----------------------------------------------------------------"),
                    e.RightAlign(),
                    e.PrintLine("SUBTOTAL         89.95"),
                    e.PrintLine("Total Order:         89.95"),
                    e.PrintLine("Total Payment:         89.95"),
                    e.FeedLines(1),
                    e.LeftAlign(),
                    e.SetStyles(PrintStyle.Bold | PrintStyle.FontB),
                    e.PrintLine("SOLD TO:                        SHIP TO:"),
                    e.SetStyles(PrintStyle.FontB),
                    e.PrintLine("  FIRSTN LASTNAME                 FIRSTN LASTNAME"),
                    e.PrintLine("  123 FAKE ST.                    123 FAKE ST."),
                    e.PrintLine("  DECATUR, IL 12345               DECATUR, IL 12345"),
                    e.PrintLine("  (123)456-7890                   (123)456-7890"),
                    e.PrintLine("  CUST: 87654321"),
                    e.FeedLines(2),
                    e.FullCutAfterFeed(4)
                  )
                );
                printer.Dispose();
                return Ok();
            }
            catch (Exception ex)
            {
                return BadRequest(ex.Message);
            } finally
            {
                printer.Dispose();
            }
        }

I changed to the newest version (3.0.0) and it doesn't work, there is something that i had missed?

koo9 commented 1 year ago

I think the issue that im experiencing is the same as your. see the description here. https://github.com/lukevp/ESC-POS-.NET/issues/194

one of the workaround for that it's to make sure that the printer is connected before printing. the problem with that is it's not certain when the printer will be connected in version 3.0. so I reversed back to the 1.6.0 and it works fine.

maximilianoCalderon commented 1 year ago

@koo9 Yes it is, i have the same issue than you, the only way to print in 3.0 its debugging and adding a breakpoint.

koo9 commented 1 year ago

@koo9 Yes it is, i have the same issue than you, the only way to print in 3.0 its debugging and adding a breakpoint.

yes breakpoint will give it enough time to connect to the printer.

orlandommb commented 1 year ago

@koo9 Yes it is, i have the same issue than you, the only way to print in 3.0 its debugging and adding a breakpoint.

yes breakpoint will give it enough time to connect to the printer.

Not an expert or have any experience using this nuget, came here to check it out for a project, i was reading the documentation and saw that it has support for inmediate network printing and you need to use await printer.WriteAsync, maybe that gives you time to connect to the printer.