예제 #1
0
        public static byte[] TwoDimensionCodes(ICommandEmitter e) =>
        ByteSplicer.Combine(
            e.PrintLine("PDF417:"),
            e.Print2DCode(TwoDimensionCodeType.PDF417, websiteString),
            e.PrintLine(),

            e.PrintLine("PDF417 (TINY):"),
            e.Print2DCode(TwoDimensionCodeType.PDF417, websiteString, Size2DCode.TINY),
            e.PrintLine(),

            e.PrintLine("PDF417 (LARGE):"),
            e.Print2DCode(TwoDimensionCodeType.PDF417, websiteString, Size2DCode.LARGE),
            e.PrintLine(),

            e.PrintLine("QRCODE MODEL 1:"),
            e.Print2DCode(TwoDimensionCodeType.QRCODE_MODEL1, websiteString),
            e.PrintLine(),

            e.PrintLine("QRCODE MODEL 2:"),
            e.PrintQRCode(websiteString),
            e.PrintLine(),

            e.PrintLine("QRCODE MICRO:"),
            e.Print2DCode(TwoDimensionCodeType.QRCODE_MICRO, websiteString),
            e.PrintLine(),

            e.PrintLine("QRCODE MODEL 1 (TINY):"),
            e.Print2DCode(TwoDimensionCodeType.QRCODE_MODEL1, websiteString, Size2DCode.TINY),
            e.PrintLine(),

            e.PrintLine("QRCODE MODEL 1 (LARGE):"),
            e.Print2DCode(TwoDimensionCodeType.QRCODE_MODEL1, websiteString, Size2DCode.LARGE),
            e.PrintLine()
            );
예제 #2
0
        public static void PrintReceipt(Horeka.Data.Occupancy occupancy)
        {
            try
            {
                if (occupancy != null)
                {
                    bool portExists = SerialPort.GetPortNames().Any(x => x == "COM7");

                    if (portExists)
                    {
                        printer = new SerialPrinter("COM7", 115200);
                        e       = new EPSON();
                        Setup();
                        printer.Write(Receipt.GetReceiptHeader(e, occupancy));
                        WriteProducts(occupancy);
                        printer.Write(Receipt.GetReceiptFooter(e));
                        Setup();
                        printer.Write(e.PartialCutAfterFeed(10));
                    }
                    else
                    {
                        throw new IOException("Port does not exist.");
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
예제 #3
0
 public static byte[] TextStyles(ICommandEmitter e)
 {
     return(ByteSplicer.Combine(
                e.SetStyles(PrintStyle.None),
                e.Print("Default: The quick brown fox jumped over the lazy dogs.\n"),
                e.SetStyles(PrintStyle.FontB),
                e.Print("Font B: The quick brown fox jumped over the lazy dogs.\n"),
                e.SetStyles(PrintStyle.Bold),
                e.Print("Bold: The quick brown fox jumped over the lazy dogs.\n"),
                e.SetStyles(PrintStyle.Underline),
                e.Print("Underline: The quick brown fox jumped over the lazy dogs.\n"),
                e.SetStyles(PrintStyle.DoubleWidth),
                e.Print("DoubleWidth: The quick brown fox jumped over the lazy dogs.\n"),
                e.SetStyles(PrintStyle.DoubleHeight),
                e.Print("DoubleHeight: The quick brown fox jumped over the lazy dogs.\n"),
                e.SetStyles(PrintStyle.FontB | PrintStyle.DoubleHeight | PrintStyle.DoubleWidth | PrintStyle.Underline |
                            PrintStyle.Bold),
                e.Print("All Styles: The quick brown fox jumped over the lazy dogs.\n"),
                e.SetStyles(PrintStyle.None),
                e.ReverseMode(true),
                e.PrintLine("REVERSE MODE: The quick brown fox jumped over the lazy dogs."),
                e.SetStyles(PrintStyle.FontB | PrintStyle.DoubleHeight | PrintStyle.DoubleWidth),
                e.PrintLine("REVERSE MODE: The quick brown fox jumped over the lazy dogs."),
                e.SetStyles(PrintStyle.None),
                e.ReverseMode(false),
                e.SetStyles(PrintStyle.None),
                e.RightCharacterSpacing(5),
                e.PrintLine("Right space 5: The quick brown fox jumped over the lazy dogs."),
                e.RightCharacterSpacing(0),
                e.SetStyles(PrintStyle.None),
                e.UpsideDownMode(true),
                e.PrintLine("Upside Down Mode: The quick brown fox jumped over the lazy dogs."),
                e.UpsideDownMode(false)
                ));
 }
예제 #4
0
파일: Test2DCodes.cs 프로젝트: orbing/citaq
        public static byte[][] TwoDimensionCodes(ICommandEmitter e) => new byte[][]
        {
            e.PrintLine("PDF417:"),
            e.Print2DCode(TwoDimensionCodeType.PDF417, websiteString),
            e.PrintLine(),

            e.PrintLine("PDF417 (TINY):"),
            e.Print2DCode(TwoDimensionCodeType.PDF417, websiteString, Size2DCode.TINY),
            e.PrintLine(),

            e.PrintLine("PDF417 (LARGE):"),
            e.Print2DCode(TwoDimensionCodeType.PDF417, websiteString, Size2DCode.LARGE),
            e.PrintLine(),

            e.PrintLine("QRCODE MODEL 1:"),
            e.Print2DCode(TwoDimensionCodeType.QRCODE_MODEL1, websiteString),
            e.PrintLine(),

            e.PrintLine("QRCODE MODEL 2:"),
            e.PrintQRCode(websiteString),
            e.PrintLine(),

            e.PrintLine("QRCODE MICRO:"),
            e.Print2DCode(TwoDimensionCodeType.QRCODE_MICRO, "github.com/lukevp"),
            e.PrintLine(),

            e.PrintLine("QRCODE MODEL 1 (TINY):"),
            e.Print2DCode(TwoDimensionCodeType.QRCODE_MODEL1, websiteString, Size2DCode.TINY),
            e.PrintLine(),

            e.PrintLine("QRCODE MODEL 1 (LARGE):"),
            e.Print2DCode(TwoDimensionCodeType.QRCODE_MODEL1, websiteString, Size2DCode.LARGE),
            e.PrintLine()
        };
예제 #5
0
        public void PrintQRCode_Failure(string emitter, TwoDimensionCodeType codeType)
        {
            var             type = Assembly.LoadFrom("ESCPOS_NET").GetType($"ESCPOS_NET.Emitters.{emitter}", true);
            ICommandEmitter e    = (ICommandEmitter)Activator.CreateInstance(type);

            Assert.Throws <ArgumentException>(() => e.PrintQRCode(WEBSITE_STRING, codeType));
        }
예제 #6
0
        public static byte[] Images(ICommandEmitter e)
        {
            Stopwatch s = Stopwatch.StartNew();

            return(ByteSplicer.Combine(
                       e.CenterAlign(),
                       e.PrintLine("Test PNG images with widths 100 - 600 px at native resolution"),
                       e.PrintLine("-- pd-logo-100.png --"),
                       e.PrintImage(File.ReadAllBytes("images/pd-logo-100.png"), true),
                       e.PrintLine("-- pd-logo-200.png --"),
                       e.PrintImage(File.ReadAllBytes("images/pd-logo-200.png"), true),
                       e.PrintLine("-- pd-logo-300.png --"),
                       e.PrintImage(File.ReadAllBytes("images/pd-logo-300.png"), true),
                       e.PrintLine("-- pd-logo-400.png --"),
                       e.PrintImage(File.ReadAllBytes("images/pd-logo-400.png"), true),
                       e.PrintLine("-- pd-logo-500.png --"),
                       e.PrintImage(File.ReadAllBytes("images/pd-logo-500.png"), true),
                       e.PrintLine("-- pd-logo-600.png --"),
                       e.PrintImage(File.ReadAllBytes("images/pd-logo-600.png"), true),
                       //e.PrintImage(File.ReadAllBytes("abe-lincoln.png"), true, 257),
                       e.PrintLine("Test resizing 600 px image to 300px"),
                       e.PrintLine("-- pd-logo-600.png /300 --"),
                       e.PrintImage(File.ReadAllBytes("images/pd-logo-600.png"), true, 300),
                       e.PrintLine("Test image with taller height than width"),
                       e.PrintLine("-- abe-lincoln.png /300 --"),
                       e.PrintImage(File.ReadAllBytes("images/abe-lincoln.png"), true, 300),
                       e.PrintLine("Test 300px image resized to all remainders of 8 to ensure overflow checking"),
                       e.PrintLine("-- pd-logo-300.png /296 (0 remainder) --"),
                       e.PrintImage(File.ReadAllBytes("images/pd-logo-300.png"), true, 296),
                       e.PrintLine("-- pd-logo-300.png /297 (1 remainder) --"),
                       e.PrintImage(File.ReadAllBytes("images/pd-logo-300.png"), true, 297),
                       e.PrintLine("-- pd-logo-300.png /298 (2 remainder) --"),
                       e.PrintImage(File.ReadAllBytes("images/pd-logo-300.png"), true, 298),
                       e.PrintLine("-- pd-logo-300.png /299 (3 remainder) --"),
                       e.PrintImage(File.ReadAllBytes("images/pd-logo-300.png"), true, 299),
                       e.PrintLine("-- pd-logo-300.png /300 (4 remainder) --"),
                       e.PrintImage(File.ReadAllBytes("images/pd-logo-300.png"), true, 300),
                       e.PrintLine("-- pd-logo-300.png /301 (5 remainder) --"),
                       e.PrintImage(File.ReadAllBytes("images/pd-logo-300.png"), true, 301),
                       e.PrintLine("-- pd-logo-300.png /302 (6 remainder) --"),
                       e.PrintImage(File.ReadAllBytes("images/pd-logo-300.png"), true, 302),
                       e.PrintLine("-- pd-logo-300.png /303 (7 remainder) --"),
                       e.PrintImage(File.ReadAllBytes("images/pd-logo-300.png"), true, 303),
                       e.PrintLine("Test 300px image in JPG format"),
                       e.PrintLine("-- pd-logo-300.jpg --"),
                       e.PrintImage(File.ReadAllBytes("images/pd-logo-300.jpg"), true),
                       e.PrintLine("Test 300px image in BMP format"),
                       e.PrintLine("-- pd-logo-300.jpg --"),
                       e.PrintImage(File.ReadAllBytes("images/pd-logo-300.bmp"), true),
                       e.PrintLine("Test 300px image in GIF format"),
                       e.PrintLine("-- pd-logo-300.jpg --"),
                       e.PrintImage(File.ReadAllBytes("images/pd-logo-300.gif"), true),
                       e.PrintLine("Test full color image converted to black and white"),
                       e.PrintLine("-- kitten.jpg --"),
                       e.PrintImage(File.ReadAllBytes("images/kitten.jpg"), true, 400),
                       e.PrintLine("Time taken: " + s.ElapsedMilliseconds + "ms")
                       ));
        }
예제 #7
0
 public static byte[] Images(ICommandEmitter e, bool isLegacy)
 {
     return(ByteSplicer.Combine(
                e.CenterAlign(),
                e.PrintLine("Test PNG images with widths 100 - 600 px,"),
                e.PrintLine("at native resolution"),
                e.PrintLine("-- pd-logo-100.png --"),
                e.PrintImage(File.ReadAllBytes("images/pd-logo-100.png"), true, isLegacy),
                e.PrintLine("-- pd-logo-200.png --"),
                e.PrintImage(File.ReadAllBytes("images/pd-logo-200.png"), true, isLegacy),
                e.PrintLine("-- pd-logo-300.png --"),
                e.PrintImage(File.ReadAllBytes("images/pd-logo-300.png"), true, isLegacy),
                e.PrintLine("-- pd-logo-400.png --"),
                e.PrintImage(File.ReadAllBytes("images/pd-logo-400.png"), true, isLegacy),
                e.PrintLine("-- pd-logo-500.png --"),
                e.PrintImage(File.ReadAllBytes("images/pd-logo-500.png"), true, isLegacy),
                e.PrintLine("-- pd-logo-600.png --"),
                e.PrintImage(File.ReadAllBytes("images/pd-logo-600.png"), true, isLegacy),
                e.PrintLine("Test resizing 600 px image to 300px"),
                e.PrintLine("-- pd-logo-600.png /300 --"),
                e.PrintImage(File.ReadAllBytes("images/pd-logo-600.png"), true, isLegacy, 300),
                e.PrintLine("Test image with taller height than width"),
                e.PrintLine("-- abe-lincoln.png /300 --"),
                e.PrintImage(File.ReadAllBytes("images/abe-lincoln.png"), true, isLegacy, 300),
                e.PrintLine("Test 300px image resized to all remainders of 8,"),
                e.PrintLine("to ensure overflow checking"),
                e.PrintLine("-- pd-logo-300.png /296 (0 remainder) --"),
                e.PrintImage(File.ReadAllBytes("images/pd-logo-300.png"), true, isLegacy, 296),
                e.PrintLine("-- pd-logo-300.png /297 (1 remainder) --"),
                e.PrintImage(File.ReadAllBytes("images/pd-logo-300.png"), true, isLegacy, 297),
                e.PrintLine("-- pd-logo-300.png /298 (2 remainder) --"),
                e.PrintImage(File.ReadAllBytes("images/pd-logo-300.png"), true, isLegacy, 298),
                e.PrintLine("-- pd-logo-300.png /299 (3 remainder) --"),
                e.PrintImage(File.ReadAllBytes("images/pd-logo-300.png"), true, isLegacy, 299),
                e.PrintLine("-- pd-logo-300.png /300 (4 remainder) --"),
                e.PrintImage(File.ReadAllBytes("images/pd-logo-300.png"), true, isLegacy, 300),
                e.PrintLine("-- pd-logo-300.png /301 (5 remainder) --"),
                e.PrintImage(File.ReadAllBytes("images/pd-logo-300.png"), true, isLegacy, 301),
                e.PrintLine("-- pd-logo-300.png /302 (6 remainder) --"),
                e.PrintImage(File.ReadAllBytes("images/pd-logo-300.png"), true, isLegacy, 302),
                e.PrintLine("-- pd-logo-300.png /303 (7 remainder) --"),
                e.PrintImage(File.ReadAllBytes("images/pd-logo-300.png"), true, isLegacy, 303),
                e.PrintLine("Test 300px image in JPG format"),
                e.PrintLine("-- pd-logo-300.jpg --"),
                e.PrintImage(File.ReadAllBytes("images/pd-logo-300.jpg"), true, isLegacy),
                e.PrintLine("Test 300px image in BMP format"),
                e.PrintLine("-- pd-logo-300.jpg --"),
                e.PrintImage(File.ReadAllBytes("images/pd-logo-300.bmp"), true, isLegacy),
                e.PrintLine("Test 300px image in GIF format"),
                e.PrintLine("-- pd-logo-300.jpg --"),
                e.PrintImage(File.ReadAllBytes("images/pd-logo-300.gif"), true, isLegacy),
                e.PrintLine("Test full color image converted"),
                e.PrintLine("to black and white and interpolated"),
                e.PrintLine("-- kitten.jpg --"),
                e.PrintImage(File.ReadAllBytes("images/kitten.jpg"), true, isLegacy, 500),
                e.PrintLine("-- portal companion cube.jpg --"),
                e.PrintImage(File.ReadAllBytes("images/Portal_Companion_Cube.jpg"), true, isLegacy, 500)));
 }
        public static byte[] BarcodeStyles(ICommandEmitter e) =>
        ByteSplicer.Combine(
            //TODO: test all widths and put bar in front in label
            e.PrintLine("Thinnest Width:"),
            e.SetBarcodeHeightInDots(300),
            e.SetBarWidth(BarWidth.Thinnest),
            e.PrintBarcode(BarcodeType.UPC_A, "012345678905"),

            e.PrintLine("Thin Width:"),
            e.SetBarcodeHeightInDots(300),
            e.SetBarWidth(BarWidth.Thin),
            e.PrintBarcode(BarcodeType.UPC_A, "012345678905"),

            e.PrintLine("Default Width:"),
            e.SetBarcodeHeightInDots(300),
            e.SetBarWidth(BarWidth.Default),
            e.PrintBarcode(BarcodeType.UPC_A, "012345678905"),

            e.PrintLine("Thicker Width:"),
            e.SetBarcodeHeightInDots(300),
            e.SetBarWidth(BarWidth.Thick),
            e.PrintBarcode(BarcodeType.UPC_A, "012345678905"),

            e.PrintLine("Thickest Width:"),
            e.SetBarcodeHeightInDots(300),
            e.SetBarWidth(BarWidth.Thickest),
            e.PrintBarcode(BarcodeType.UPC_A, "012345678905"),


            e.PrintLine("Short (50 dots):"),
            e.SetBarcodeHeightInDots(50),
            e.SetBarWidth(BarWidth.Default),
            e.PrintBarcode(BarcodeType.UPC_A, "012345678905"),

            e.PrintLine("Tall (255 dots):"),
            e.SetBarcodeHeightInDots(255),
            e.PrintBarcode(BarcodeType.UPC_A, "012345678905"),

            e.PrintLine("Label Above:"),
            e.SetBarcodeHeightInDots(50),
            e.SetBarLabelPosition(BarLabelPrintPosition.Above),
            e.PrintBarcode(BarcodeType.UPC_A, "012345678905"),

            e.PrintLine("Label Above and Below:"),
            e.SetBarLabelPosition(BarLabelPrintPosition.Both),
            e.PrintBarcode(BarcodeType.UPC_A, "012345678905"),

            e.PrintLine("Label Below:"),
            e.SetBarLabelPosition(BarLabelPrintPosition.Below),
            e.PrintBarcode(BarcodeType.UPC_A, "012345678905"),

            e.PrintLine("Font B Label Below:"),
            e.SetBarLabelFontB(true),
            e.PrintBarcode(BarcodeType.UPC_A, "012345678905")

            );
예제 #9
0
 public static byte[][] LineSpacing(ICommandEmitter e) => new byte[][]
 {
     e.SetLineSpacingInDots(200),
     e.PrintLine("This is the default spacing."),
     e.SetLineSpacingInDots(15),
     e.PrintLine("This has 200 dots of spacing above."),
     e.ResetLineSpacing(),
     e.PrintLine("This has 15 dots of spacing above."),
     e.PrintLine("This has the default spacing.")
 };
예제 #10
0
 public static byte[] LineSpacing(ICommandEmitter e)
 {
     return(ByteSplicer.Combine(
                e.SetLineSpacingInDots(200),
                e.PrintLine("This is the default spacing."),
                e.SetLineSpacingInDots(15),
                e.PrintLine("This has 200 dots of spacing above."),
                e.ResetLineSpacing(),
                e.PrintLine("This has 15 dots of spacing above."),
                e.PrintLine("This has the default spacing.")
                ));
 }
예제 #11
0
 public static byte[] BarcodeTypes(ICommandEmitter e)
 {
     return(ByteSplicer.Combine(
                e.SetBarcodeHeightInDots(600),
                e.SetBarWidth(BarWidth.Thinnest),
                e.SetBarLabelPosition(BarLabelPrintPosition.Below),
                e.PrintLine("CODABAR_NW_7:"),
                e.PrintBarcode(BarcodeType.CODABAR_NW_7, "A31117013206375B"),
                e.PrintLine("CODE128:"),
                e.PrintBarcode(BarcodeType.CODE128, "ESC_POS_NET"),
                e.PrintLine(),
                e.PrintLine("CODE128 Type C:"),
                e.PrintBarcode(BarcodeType.CODE128, "123456789101", BarcodeCode.CODE_C),
                e.PrintLine(),
                e.PrintLine("CODE39:"),
                e.PrintBarcode(BarcodeType.CODE39, "*ESC-POS-NET*"),
                e.PrintLine(),
                e.PrintLine("CODE93:"),
                e.PrintBarcode(BarcodeType.CODE93, "*ESC_POS_NET*"),
                e.PrintLine(),
                e.PrintLine("GS1_128:"),
                e.PrintBarcode(BarcodeType.GS1_128, "(01)9501234567890*"),
                e.PrintLine(),
                e.PrintLine("GS1_DATABAR_EXPANDED:"),
                e.PrintBarcode(BarcodeType.GS1_DATABAR_EXPANDED, "0001234567890"),
                e.PrintLine(),
                e.PrintLine("GS1_DATABAR_LIMITED:"),
                e.PrintBarcode(BarcodeType.GS1_DATABAR_LIMITED, "0001234567890"),
                e.PrintLine(),
                e.PrintLine("GS1_DATABAR_OMNIDIRECTIONAL:"),
                e.PrintBarcode(BarcodeType.GS1_DATABAR_OMNIDIRECTIONAL, "0001234567890"),
                e.PrintLine(),
                e.PrintLine("GS1_DATABAR_TRUNCATED:"),
                e.PrintBarcode(BarcodeType.GS1_DATABAR_TRUNCATED, "0001234567890"),
                e.PrintLine(),
                e.PrintLine("ITF:"),
                e.PrintBarcode(BarcodeType.ITF, "1234567895"),
                e.PrintLine(),
                e.PrintLine("JAN13_EAN13:"),
                e.PrintBarcode(BarcodeType.JAN13_EAN13, "5901234123457"),
                e.PrintLine(),
                e.PrintLine("JAN8_EAN8:"),
                e.PrintBarcode(BarcodeType.JAN8_EAN8, "96385074"),
                e.PrintLine(),
                e.PrintLine("UPC_A:"),
                e.PrintBarcode(BarcodeType.UPC_A, "042100005264"),
                e.PrintLine(),
                e.PrintLine("UPC_E:"),
                e.PrintBarcode(BarcodeType.UPC_E, "425261"),
                e.PrintLine()
                ));
 }
예제 #12
0
 public static byte[] Printing(ICommandEmitter e) =>
 ByteSplicer.Combine(
     e.Print("Multiline Test: Windows...\r\nOSX...\rUnix...\n"),
     //TODO: sanitize test.
     e.PrintLine("Feeding 250 dots."),
     e.FeedDots(250),
     e.PrintLine("Feeding 3 lines."),
     e.FeedLines(3),
     e.PrintLine("Done Feeding."),
     e.PrintLine("Reverse Feeding 6 lines."),
     e.FeedLinesReverse(6),
     e.PrintLine("Done Reverse Feeding.")
     );
예제 #13
0
        public void VerifyQRCodeIsSameAsCallingFromEmitter(string emitter)
        {
            var             type = Assembly.LoadFrom("ESCPOS_NET").GetType($"ESCPOS_NET.Emitters.{emitter}", true);
            ICommandEmitter e    = (ICommandEmitter)Activator.CreateInstance(type);

            //Use Print Command so Buffer is updated internally
            var directPrinter = new DirectPrinter(e, null);

            directPrinter.PrintQRCode("ABC");

            byte[] expected = e.PrintQRCode("ABC");
            Assert.Equal(expected, directPrinter.Buffer);
        }
예제 #14
0
        public void VerifyInternalBufferIsUpdated(string emitter)
        {
            var             type = Assembly.LoadFrom("ESCPOS_NET").GetType($"ESCPOS_NET.Emitters.{emitter}", true);
            ICommandEmitter e    = (ICommandEmitter)Activator.CreateInstance(type);

            //Use Print Command so Buffer is updated internally
            var directPrinter = new DirectPrinter(e, null);

            directPrinter.Print("ABC").Print("DEF");

            byte[] result = { 65, 66, 67, 68, 69, 70 };
            Assert.Equal(result, directPrinter.Buffer);
        }
예제 #15
0
파일: Receipt.cs 프로젝트: TiboVDS/Horeka
 public static byte[] GetReceiptFooter(ICommandEmitter e) =>
 ByteSplicer.Combine(
     e.LeftAlign(),
     e.PrintLine("SUBTOTAL"),
     e.PrintLine(),
     e.PrintLine(),
     e.CenterAlign(),
     e.SetStyles(PrintStyle.None),
     e.PrintLine($"{DateTime.Today.ToShortDateString()}"),
     e.PrintLine("Made With Love"),
     e.PrintLine("Tibo Van De Sijpe"),
     e.PrintLine("Bram Van den Abbeele"),
     e.PrintLine("Pierre Vanvolsem")
     );
예제 #16
0
        public void VerifyInternalBufferIsCleared(string emitter)
        {
            var             type = Assembly.LoadFrom("ESCPOS_NET").GetType($"ESCPOS_NET.Emitters.{emitter}", true);
            ICommandEmitter e    = (ICommandEmitter)Activator.CreateInstance(type);

            //Use Print Command so Buffer is updated internally
            var directPrinter = new DirectPrinter(e, null);

            directPrinter.Print("ABC").Print("DEF");

            //Clear Buffer and adds different bytes
            directPrinter.ClearAll();
            directPrinter.Print("GHI").Print("JKL");

            byte[] result = { 71, 72, 73, 74, 75, 76 };
            Assert.Equal(result, directPrinter.Buffer);
        }
예제 #17
0
파일: Barcode.cs 프로젝트: orbing/citaq
        public void PrintQRCode_Success(string emitter, TwoDimensionCodeType?codeType)
        {
            var             type = Assembly.LoadFrom("ESCPOS_NET").GetType($"ESCPOS_NET.Emitters.{emitter}", true);
            ICommandEmitter e    = (ICommandEmitter)Activator.CreateInstance(type);

            byte[] bytes;
            if (codeType is TwoDimensionCodeType codeTypeValue)
            {
                bytes = e.PrintQRCode(WEBSITE_STRING, codeTypeValue);
            }
            else
            {
                bytes = e.PrintQRCode(WEBSITE_STRING);
            }

            Assert.True(bytes.Length > 0);
        }
예제 #18
0
 public static byte[] Receipt(ICommandEmitter e)
 {
     return(ByteSplicer.Combine(
                e.CenterAlign(),
                e.PrintImage(File.ReadAllBytes("images/pd-logo-300.png"), true),
                e.PrintLine(),
                e.SetBarcodeHeightInDots(360),
                e.SetBarWidth(BarWidth.Default),
                e.SetBarLabelPosition(BarLabelPrintPosition.None),
                e.PrintBarcode(BarcodeType.ITF, "0123456789"),
                e.PrintLine(),
                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.PrintLine(),
                e.LeftAlign(),
                e.PrintLine("Order: 123456789        Date: 02/01/19"),
                e.PrintLine(),
                e.PrintLine(),
                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.PrintLine(),
                e.LeftAlign(),
                e.SetStyles(PrintStyle.Bold | PrintStyle.FontB),
                e.PrintLine("SOLD TO:                        SHIP TO:"),
                e.SetStyles(PrintStyle.FontB),
                e.PrintLine("  LUKE PAIREEPINART               LUKE PAIREEPINART"),
                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.PrintLine(),
                e.PrintLine()
                ));
 }
예제 #19
0
 public static byte[] TextStyles(ICommandEmitter e) =>
 ByteSplicer.Combine(
     e.SetStyles(PrintStyle.None),
     e.Print("Default: The quick brown fox jumped over the lazy dogs.\n"),
     e.SetStyles(PrintStyle.FontB),
     e.Print("Font B: The quick brown fox jumped over the lazy dogs.\n"),
     e.SetStyles(PrintStyle.Bold),
     e.Print("Bold: The quick brown fox jumped over the lazy dogs.\n"),
     e.SetStyles(PrintStyle.Underline),
     e.Print("Underline: The quick brown fox jumped over the lazy dogs.\n"),
     e.SetStyles(PrintStyle.DoubleWidth),
     e.Print("DoubleWidth: The quick brown fox jumped over the lazy dogs.\n"),
     e.SetStyles(PrintStyle.DoubleHeight),
     e.Print("DoubleHeight: The quick brown fox jumped over the lazy dogs.\n"),
     e.SetStyles(PrintStyle.FontB | PrintStyle.DoubleHeight | PrintStyle.DoubleWidth | PrintStyle.Underline | PrintStyle.Bold),
     e.Print("All Styles: The quick brown fox jumped over the lazy dogs.\n"),
     e.SetStyles(PrintStyle.None)
     );
예제 #20
0
파일: Receipt.cs 프로젝트: TiboVDS/Horeka
 public static byte[] GetReceiptHeader(ICommandEmitter e, Horeka.Data.Occupancy occupancy) =>
 ByteSplicer.Combine(
     e.CenterAlign(),
     e.PrintLine("HOREKA APPLICATIE"),
     e.PrintLine(),
     e.PrintLine(),
     e.PrintLine("Odisee Brussel"),
     e.PrintLine("Warmoesberg 26"),
     e.PrintLine("Belgium, Brussels, 1000"),
     e.PrintLine("0496/12.12.12"),
     e.SetStyles(PrintStyle.Underline),
     e.PrintLine("www.odisee.be"),
     e.SetStyles(PrintStyle.None),
     e.PrintLine(),
     e.LeftAlign(),
     e.PrintLine($"Order: {occupancy.ID}"),
     e.PrintLine(),
     e.PrintLine()
     );
예제 #21
0
        public static byte[][] CodePages(ICommandEmitter e, CodePage codePage)
        {
            List <byte[]> test = new List <byte[]>();

            test.Add(e.LeftAlign());
            test.Add(e.PrintLine("Empty space = space or non-printable character."));
            test.Add(e.PrintLine("Each row represents the first hex digit."));
            test.Add(e.PrintLine("Each column represents the second hex digit."));
            test.Add(e.PrintLine("For example, row 7, column A, represents"));
            test.Add(e.PrintLine("the character with hex 0x7A."));
            test.Add(e.PrintLine());
            test.Add(e.PrintLine("Character Table for Code Page:"));
            test.Add(e.PrintLine(codePage + "  (Page " + ((int)codePage) + ")"));
            test.Add(e.PrintLine("=========================="));
            test.Add(e.PrintLine());
            test.Add(e.PrintLine("   0 1 2 3 4 5 6 7 8 9 A B C D E F "));
            // Set CodePage to test codepage.
            test.Add(e.CodePage(codePage));
            for (int d1 = 0; d1 < 0x10; d1++)
            {
                var upperDigit = d1.ToString("x1").ToUpperInvariant();
                test.Add(e.Print(upperDigit + "  "));
                for (int d2 = 0; d2 < 0x10; d2++)
                {
                    var digit = d1 * 0x10 + d2;
                    if (digit <= 0x20)
                    {
                        digit = 0x20;
                    }
                    test.Add(e.Print((char)digit + " "));
                }
                test.Add(e.PrintLine());
            }
            // Set CodePage back to default
            test.Add(e.CodePage(CodePage.PC437_USA_STANDARD_EUROPE_DEFAULT));
            test.Add(e.PrintLine());
            return(test.ToArray());
        }
예제 #22
0
        static void Main(string[] args)
        {
            Console.WriteLine("ESCPOS_NET Test Application...");
            Console.WriteLine("1 ) Test Serial Port");
            Console.WriteLine("2 ) Test Network Printer");
            Console.Write("Choice: ");
            string comPort = "";
            string baudRate;
            string ip;
            string networkPort;
            var    response = Console.ReadLine();
            var    valid    = new List <string> {
                "1", "2"
            };

            if (!valid.Contains(response))
            {
                response = "1";
            }
            int choice = int.Parse(response);

            if (choice == 1)
            {
                if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
                {
                    while (!comPort.StartsWith("COM"))
                    {
                        Console.Write("COM Port (eg. COM20): ");
                        comPort = Console.ReadLine();
                        if (string.IsNullOrWhiteSpace(comPort))
                        {
                            comPort = "COM20";
                        }
                    }
                    Console.Write("Baud Rate (eg. 115200): ");
                    baudRate = Console.ReadLine();
                    if (string.IsNullOrWhiteSpace(baudRate))
                    {
                        baudRate = "115200";
                    }
                    printer = new SerialPrinter(comPort, int.Parse(baudRate));
                }
                else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
                {
                    Console.Write("File / virtual com path (eg. /dev/usb/lp0): ");
                    comPort = Console.ReadLine();
                    if (string.IsNullOrWhiteSpace(comPort))
                    {
                        comPort = "/dev/usb/lp0";
                    }
                    printer = new FilePrinter(comPort);
                }
            }
            else if (choice == 2)
            {
                Console.Write("IP Address (eg. 192.168.1.240): ");
                ip = Console.ReadLine();
                if (string.IsNullOrWhiteSpace(ip))
                {
                    ip = "192.168.1.240";
                }
                Console.Write("TCP Port (eg. 9000): ");
                networkPort = Console.ReadLine();
                if (string.IsNullOrWhiteSpace(networkPort))
                {
                    networkPort = "9000";
                }
                printer = new NetworkPrinter(ip, int.Parse(networkPort));
            }

            bool monitor = false;

            Console.Write("Turn on Live Status Back Monitoring? (y/n): ");
            response = Console.ReadLine().Trim().ToLowerInvariant();
            if (response.Length >= 1 && response[0] == 'y')
            {
                monitor = true;
            }

            e = new EPSON();
            List <string> testCases = new List <string>()
            {
                "Printing",
                "Line Spacing",
                "Barcode Styles",
                "Text Styles",
                "Full Receipt"
            };

            while (true)
            {
                int i = 0;
                foreach (var item in testCases)
                {
                    i += 1;
                    Console.WriteLine($"{i} : {item}");
                }
                Console.WriteLine("99 : Exit");
                Console.Write("Execute Test: ");

                try
                {
                    choice = Convert.ToInt32(Console.ReadLine());
                    if (choice != 99 && (choice < 1 || choice > testCases.Count))
                    {
                        throw new InvalidOperationException();
                    }
                }
                catch
                {
                    Console.WriteLine("Invalid entry. Please try again.");
                    continue;
                }

                if (choice == 99)
                {
                    return;
                }

                Console.Clear();

                if (monitor)
                {
                    printer.StartMonitoring();
                }
                Setup();
                printer.Write(e.PrintLine($"== [ Start {testCases[choice - 1]} ] =="));

                switch (choice)
                {
                case 1:
                    printer.Write(Tests.Printing(e));
                    break;

                case 2:
                    printer.Write(Tests.LineSpacing(e));
                    break;

                case 3:
                    printer.Write(Tests.BarcodeStyles(e));
                    break;

                case 4:
                    printer.Write(Tests.TextStyles(e));
                    break;

                case 5:
                    printer.Write(Tests.Receipt(e));
                    break;

                default:
                    Console.WriteLine("Invalid entry.");
                    break;
                }

                Setup();
                printer.Write(e.PrintLine($"== [ End {testCases[choice - 1]} ] =="));
                printer.Write(e.PartialCutAfterFeed(5));

                //TestCutter();
                //TestMultiLineWrite();
                //TestHEBReceipt();
                // TODO: write a sanitation check.
                // TODO: make DPI to inch conversion function
                // TODO: full cuts and reverse feeding not implemented on epson...  should throw exception?
                // TODO: make an input loop that lets you execute each test separately.
                // TODO: also make an automatic runner that runs all tests (command line).
                //Thread.Sleep(1000);
            }
        }
예제 #23
0
        static void Main(string[] args)
        {
            Console.WriteLine("ESCPOS_NET Test Application...");
            Console.WriteLine("1 ) Test Serial Port");
            Console.WriteLine("2 ) Test Network Printer");
            Console.Write("Choice: ");
            string comPort = "";
            string baudRate;
            string ip;
            string networkPort;
            var    response = Console.ReadLine();
            var    valid    = new List <string> {
                "1", "2"
            };

            if (!valid.Contains(response))
            {
                response = "1";
            }

            int choice = int.Parse(response);

            if (choice == 1)
            {
                if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
                {
                    while (!comPort.StartsWith("COM"))
                    {
                        Console.Write("COM Port (eg. COM5): ");
                        comPort = Console.ReadLine();
                        if (string.IsNullOrWhiteSpace(comPort))
                        {
                            comPort = "COM5";
                        }
                    }
                    Console.Write("Baud Rate (eg. 115200): ");
                    baudRate = Console.ReadLine();
                    if (string.IsNullOrWhiteSpace(baudRate))
                    {
                        baudRate = "115200";
                    }
                    printer = new SerialPrinter(portName: comPort, baudRate: int.Parse(baudRate));
                }
                else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
                {
                    Console.Write("File / virtual com path (eg. /dev/usb/lp0): ");
                    comPort = Console.ReadLine();
                    if (string.IsNullOrWhiteSpace(comPort))
                    {
                        comPort = "/dev/usb/lp0";
                    }
                    printer = new FilePrinter(filePath: comPort, false);
                }
            }
            else if (choice == 2)
            {
                Console.Write("IP Address (eg. 192.168.1.240): ");
                ip = Console.ReadLine();
                if (string.IsNullOrWhiteSpace(ip))
                {
                    ip = "192.168.1.240";
                }
                Console.Write("TCP Port (eg. 9000): ");
                networkPort = Console.ReadLine();
                if (string.IsNullOrWhiteSpace(networkPort))
                {
                    networkPort = "9000";
                }
                printer = new NetworkPrinter(ipAddress: ip, port: int.Parse(networkPort), reconnectOnTimeout: true);
            }

            bool monitor = false;

            Console.Write("Turn on Live Status Back Monitoring? (y/n): ");
            response = Console.ReadLine().Trim().ToLowerInvariant();
            if (response.Length >= 1 && response[0] == 'y')
            {
                monitor = true;
            }

            e = new EPSON();
            var testCases = new Dictionary <Option, string>()
            {
                { Option.Printing, "Printing" },
                { Option.LineSpacing, "Line Spacing" },
                { Option.BarcodeStyles, "Barcode Styles" },
                { Option.BarcodeTypes, "Barcode Types" },
                { Option.TwoDimensionCodes, "2D Codes" },
                { Option.TextStyles, "Text Styles" },
                { Option.FullReceipt, "Full Receipt" },
                { Option.CodePages, "Code Pages (Euro, Katakana, Etc)" },
                { Option.Images, "Images" },
                { Option.LegacyImages, "Legacy Images" },
                { Option.LargeByteArrays, "Large Byte Arrays" },
                { Option.CashDrawerPin2, "Cash Drawer Pin2" },
                { Option.CashDrawerPin5, "Cash Drawer Pin5" },
                { Option.Exit, "Exit" }
            };

            while (true)
            {
                foreach (var item in testCases)
                {
                    Console.WriteLine($"{(int)item.Key} : {item.Value}");
                }
                Console.Write("Execute Test: ");

                if (!int.TryParse(Console.ReadLine(), out choice) || !Enum.IsDefined(typeof(Option), choice))
                {
                    Console.WriteLine("Invalid entry. Please try again.");
                    continue;
                }

                var enumChoice = (Option)choice;
                if (enumChoice == Option.Exit)
                {
                    return;
                }

                Console.Clear();

                if (monitor)
                {
                    printer.StartMonitoring();
                }
                Setup(monitor);

                printer?.Write(e.PrintLine($"== [ Start {testCases[enumChoice]} ] =="));

                switch (enumChoice)
                {
                case Option.Printing:
                    printer.Write(Tests.Printing(e));
                    break;

                case Option.LineSpacing:
                    printer.Write(Tests.LineSpacing(e));
                    break;

                case Option.BarcodeStyles:
                    printer.Write(Tests.BarcodeStyles(e));
                    break;

                case Option.BarcodeTypes:
                    printer.Write(Tests.BarcodeTypes(e));
                    break;

                case Option.TwoDimensionCodes:
                    printer.Write(Tests.TwoDimensionCodes(e));
                    break;

                case Option.TextStyles:
                    printer.Write(Tests.TextStyles(e));
                    break;

                case Option.FullReceipt:
                    printer.Write(Tests.Receipt(e));
                    break;

                case Option.CodePages:
                    var codePage = CodePage.PC437_USA_STANDARD_EUROPE_DEFAULT;
                    Console.WriteLine("To run this test, you must select the index of a code page to print.");
                    Console.WriteLine("The default CodePage is typically CodePage 0 (USA/International).");
                    Console.WriteLine("Press enter to see the list of Code Pages.");
                    Console.ReadLine();
                    List <object> codePages = new List <object>();
                    foreach (var value in Enum.GetValues(typeof(CodePage)))
                    {
                        codePages.Add(value);
                    }
                    for (int i = 0; i < codePages.Count; i++)
                    {
                        Console.WriteLine(i.ToString() + ": " + codePages[i] + "  (Page " + ((int)codePages[i]) + ")");
                    }
                    Console.Write("Index for test Code Page (NOT Page #): ");
                    var page = Console.ReadLine();
                    try
                    {
                        codePage = (CodePage)codePages[int.Parse(page)];
                    }
                    catch
                    {
                        Console.WriteLine("Invalid code page selected, defaulting to CodePage 0.");
                    }

                    printer.Write(Tests.CodePages(e, codePage));
                    break;

                case Option.Images:
                    printer.Write(Tests.Images(e, false));
                    break;

                case Option.LegacyImages:
                    printer.Write(Tests.Images(e, true));
                    break;

                case Option.LargeByteArrays:
                    try
                    {
                        printer.Write(Tests.TestLargeByteArrays(e));
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine($"Aborting print due to test failure. Exception: {e?.Message}, Stack Trace: {e?.GetBaseException()?.StackTrace}");
                    }
                    break;

                case Option.CashDrawerPin2:
                    printer.Write(Tests.CashDrawerOpenPin2(e));
                    break;

                case Option.CashDrawerPin5:
                    printer.Write(Tests.CashDrawerOpenPin5(e));
                    break;

                default:
                    Console.WriteLine("Invalid entry.");
                    break;
                }

                Setup(monitor);
                printer?.Write(e.PrintLine($"== [ End {testCases[enumChoice]} ] =="));
                printer?.Write(e.PartialCutAfterFeed(5));

                // TODO: also make an automatic runner that runs all tests (command line).
            }
        }
예제 #24
0
 public static byte[] CashDrawerOpenPin2(ICommandEmitter e) =>
 ByteSplicer.Combine(
     e.CashDrawerOpenPin2(),    // Fire this twice ensures it's operation
     e.CashDrawerOpenPin2());
예제 #25
0
 public DirectPrinter(ICommandEmitter emitter, IPrinter printer)
 {
     this.Emitter = emitter;
     this.Printer = printer;
 }
예제 #26
0
        private static void Main(string[] args)
        {
            Console.WriteLine("ESCPOS_NET Test Application...");
            Console.WriteLine("1 ) Test Serial Port");
            Console.WriteLine("2 ) Test Network Printer");
            Console.Write("Choice: ");
            var    comPort = "";
            string baudRate;
            string ip;
            string networkPort;
            var    response = Console.ReadLine();
            var    valid    = new List <string> {
                "1", "2"
            };

            if (!valid.Contains(response))
            {
                response = "1";
            }

            var choice = int.Parse(response);

            if (choice == 1)
            {
                if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
                {
                    while (!comPort.StartsWith("COM"))
                    {
                        Console.Write("COM Port (eg. COM5): ");
                        comPort = Console.ReadLine();
                        if (string.IsNullOrWhiteSpace(comPort))
                        {
                            comPort = "COM5";
                        }
                    }

                    Console.Write("Baud Rate (eg. 115200): ");
                    baudRate = Console.ReadLine();
                    if (string.IsNullOrWhiteSpace(baudRate))
                    {
                        baudRate = "115200";
                    }
                    printer = new SerialPrinter(comPort, 115200);
                }
                else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
                {
                    Console.Write("File / virtual com path (eg. /dev/usb/lp0): ");
                    comPort = Console.ReadLine();
                    if (string.IsNullOrWhiteSpace(comPort))
                    {
                        comPort = "/dev/usb/lp0";
                    }
                    printer = new FilePrinter(comPort);
                }
            }
            else if (choice == 2)
            {
                Console.Write("IP Address (eg. 192.168.1.240): ");
                ip = Console.ReadLine();
                if (string.IsNullOrWhiteSpace(ip))
                {
                    ip = "192.168.1.240";
                }
                Console.Write("TCP Port (eg. 9000): ");
                networkPort = Console.ReadLine();
                if (string.IsNullOrWhiteSpace(networkPort))
                {
                    networkPort = "9000";
                }
                printer = new NetworkPrinter(ip, int.Parse(networkPort), true);
            }

            var monitor = false;

            Console.Write("Turn on Live Status Back Monitoring? (y/n): ");
            response = Console.ReadLine().Trim().ToLowerInvariant();
            if (response.Length >= 1 && response[0] == 'y')
            {
                monitor = true;
            }

            e = new EPSON();
            var testCases = new Dictionary <Option, string>
            {
                { Option.Printing, "Printing" },
                { Option.LineSpacing, "Line Spacing" },
                { Option.BarcodeStyles, "Barcode Styles" },
                { Option.BarcodeTypes, "Barcode Types" },
                { Option.TwoDimensionCodes, "2D Codes" },
                { Option.TextStyles, "Text Styles" },
                { Option.FullReceipt, "Full Receipt" },
                { Option.Images, "Images" },
                { Option.LegacyImages, "Legacy Images" },
                { Option.LargeByteArrays, "Large Byte Arrays" },
                { Option.CashDrawerPin2, "Cash Drawer Pin2" },
                { Option.CashDrawerPin5, "Cash Drawer Pin5" },
                { Option.Exit, "Exit" }
            };

            while (true)
            {
                foreach (var item in testCases)
                {
                    Console.WriteLine($"{(int) item.Key} : {item.Value}");
                }
                Console.Write("Execute Test: ");

                if (!int.TryParse(Console.ReadLine(), out choice) || !Enum.IsDefined(typeof(Option), choice))
                {
                    Console.WriteLine("Invalid entry. Please try again.");
                    continue;
                }

                var enumChoice = (Option)choice;
                if (enumChoice == Option.Exit)
                {
                    return;
                }

                Console.Clear();

                if (monitor)
                {
                    printer.StartMonitoring();
                }
                Setup(monitor);

                printer?.Write(e.PrintLine($"== [ Start {testCases[enumChoice]} ] =="));

                switch (enumChoice)
                {
                case Option.Printing:
                    printer.Write(Tests.Printing(e));
                    break;

                case Option.LineSpacing:
                    printer.Write(Tests.LineSpacing(e));
                    break;

                case Option.BarcodeStyles:
                    printer.Write(Tests.BarcodeStyles(e));
                    break;

                case Option.BarcodeTypes:
                    printer.Write(Tests.BarcodeTypes(e));
                    break;

                case Option.TwoDimensionCodes:
                    printer.Write(Tests.TwoDimensionCodes(e));
                    break;

                case Option.TextStyles:
                    printer.Write(Tests.TextStyles(e));
                    break;

                case Option.FullReceipt:
                    printer.Write(Tests.Receipt(e));
                    break;

                case Option.Images:
                    printer.Write(Tests.Images(e, false));
                    break;

                case Option.LegacyImages:
                    printer.Write(Tests.Images(e, true));
                    break;

                case Option.LargeByteArrays:
                    try
                    {
                        printer.Write(Tests.TestLargeByteArrays(e));
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(
                            $"Aborting print due to test failure. Exception: {e?.Message}, Stack Trace: {e?.GetBaseException()?.StackTrace}");
                    }

                    break;

                case Option.CashDrawerPin2:
                    printer.Write(Tests.CashDrawerOpenPin2(e));
                    break;

                case Option.CashDrawerPin5:
                    printer.Write(Tests.CashDrawerOpenPin5(e));
                    break;

                default:
                    Console.WriteLine("Invalid entry.");
                    break;
                }

                Setup(monitor);
                printer?.Write(e.PrintLine($"== [ End {testCases[enumChoice]} ] =="));
                printer?.Write(e.PartialCutAfterFeed(5));

                // TODO: write a sanitation check.
                // TODO: make DPI to inch conversion function
                // TODO: full cuts and reverse feeding not implemented on epson...  should throw exception?
                // TODO: make an input loop that lets you execute each test separately.
                // TODO: also make an automatic runner that runs all tests (command line).
                //Thread.Sleep(1000);
            }
        }
        public static byte[] TestLargeByteArrays(ICommandEmitter e)
        {
            var kitten         = e.PrintImage(File.ReadAllBytes("images/kitten.jpg"), true, true, 500);
            var cube           = e.PrintImage(File.ReadAllBytes("images/Portal_Companion_Cube.jpg"), true, true, 500);
            var expectedResult = ByteSplicer.Combine(
                e.CenterAlign(),
                kitten,
                cube,
                kitten,
                cube,
                kitten,
                cube,
                kitten,
                cube,
                kitten,
                cube,
                kitten,
                cube,
                kitten,
                cube,
                kitten,
                cube,
                kitten,
                cube,
                kitten,
                cube
                );
            MemoryPrinter mp = new MemoryPrinter();

            mp.Write(expectedResult);
            var  response  = mp.GetAllData();
            bool hasErrors = false;

            if (expectedResult.Length != response.Length)
            {
                Console.WriteLine($"Error: MemoryPrinter length mismatch - ${response.Length}, expected ${expectedResult.Length}");
                hasErrors = true;
            }
            else
            {
                for (int i = 0; i < expectedResult.Length; i++)
                {
                    if (expectedResult[i] != response[i])
                    {
                        Console.WriteLine($"Error: MemoryPrinter data mismatch - ${expectedResult[i]}, expected ${response[i]}, at location ${i}");
                        hasErrors = true;
                    }
                }
            }
            if (!hasErrors)
            {
                Console.WriteLine("MemoryPrinter: ALL OK!");
            }
            else
            {
                Console.WriteLine("MemoryPrinter: Errors occured during testing, aborting!");
                throw new ArgumentException();
            }

            Random r        = new Random();
            var    filename = $"{r.NextDouble().ToString()}.tmp";

            using (FilePrinter fp = new FilePrinter(filename, true))
            {
                fp.Write(expectedResult);
            }
            response  = File.ReadAllBytes(filename);
            hasErrors = false;
            if (expectedResult.Length != response.Length)
            {
                Console.WriteLine($"Error: FilePrinter length mismatch - ${response.Length}, expected ${expectedResult.Length}");
                hasErrors = true;
            }
            else
            {
                for (int i = 0; i < expectedResult.Length; i++)
                {
                    if (expectedResult[i] != response[i])
                    {
                        Console.WriteLine($"Error: FilePrinter data mismatch - ${expectedResult[i]}, expected ${response[i]}, at location ${i}");
                        hasErrors = true;
                    }
                }
            }

            if (!hasErrors)
            {
                Console.WriteLine("FilePrinter: ALL OK!");
            }
            else
            {
                Console.WriteLine("FilePrinter: Errors occured during testing, aborting!");
                throw new ArgumentException();
            }

            return(expectedResult);
        }
예제 #28
0
파일: Receipt.cs 프로젝트: TiboVDS/Horeka
 public static byte[] GetReceiptProduct(ICommandEmitter e, Horeka.Data.Sale sale, int i) =>
 ByteSplicer.Combine(
     e.SetStyles(PrintStyle.FontB),
     e.LeftAlign(),
     e.PrintLine($"{i}. {sale.Product.Name} - € {sale.Product.Price}")
     );
예제 #29
0
 public static byte[][] CashDrawerOpenPin2(ICommandEmitter e) => new byte[][]
 {
     e.CashDrawerOpenPin2()
 };
예제 #30
0
        static void Main(string[] args)
        {
            Console.WriteLine("Welcome to the ESCPOS_NET Test Application!");
            Console.Write("Would you like to see all debug messages? (y/n): ");
            var response = Console.ReadLine().Trim().ToLowerInvariant();
            var logLevel = LogLevel.Information;

            if (response.Length >= 1 && response[0] == 'y')
            {
                Console.WriteLine("Debugging enabled!");
                logLevel = LogLevel.Trace;
            }
            var factory = LoggerFactory.Create(b => b.AddConsole().SetMinimumLevel(logLevel));
            var logger  = factory.CreateLogger <Program>();

            ESCPOS_NET.Logging.Logger = logger;

            Console.WriteLine("1 ) Test Serial Port");
            Console.WriteLine("2 ) Test Network Printer");
            Console.Write("Choice: ");
            string comPort = "";
            string baudRate;
            string ip;
            string networkPort;

            response = Console.ReadLine();
            var valid = new List <string> {
                "1", "2"
            };

            if (!valid.Contains(response))
            {
                response = "1";
            }

            int choice = int.Parse(response);

            if (choice == 1)
            {
                if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
                {
                    while (!comPort.StartsWith("COM"))
                    {
                        Console.Write("COM Port (enter for default COM5): ");
                        comPort = Console.ReadLine();
                        if (string.IsNullOrWhiteSpace(comPort))
                        {
                            comPort = "COM5";
                        }
                    }
                    Console.Write("Baud Rate (enter for default 115200): ");
                    baudRate = Console.ReadLine();
                    if (string.IsNullOrWhiteSpace(baudRate))
                    {
                        baudRate = "115200";
                    }
                    printer = new SerialPrinter(portName: comPort, baudRate: 115200);
                }
                else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
                {
                    Console.Write("File / virtual com path (eg. /dev/usb/lp0): ");
                    comPort = Console.ReadLine();
                    if (string.IsNullOrWhiteSpace(comPort))
                    {
                        comPort = "/dev/usb/lp0";
                    }
                    printer = new FilePrinter(filePath: comPort, false);
                }
            }
            else if (choice == 2)
            {
                Console.Write("IP Address (eg. 192.168.1.240): ");
                ip = Console.ReadLine();
                if (string.IsNullOrWhiteSpace(ip))
                {
                    ip = "192.168.254.202";
                }
                Console.Write("TCP Port (enter for default 9100): ");
                networkPort = Console.ReadLine();
                if (string.IsNullOrWhiteSpace(networkPort))
                {
                    networkPort = "9100";
                }
                printer = new NetworkPrinter(ipAddress: ip, port: int.Parse(networkPort), reconnectOnTimeout: true);
            }

            bool monitor = false;

            Thread.Sleep(500);
            Console.Write("Turn on Live Status Back Monitoring? (y/n): ");
            response = Console.ReadLine().Trim().ToLowerInvariant();
            if (response.Length >= 1 && response[0] == 'y')
            {
                monitor = true;
            }

            e = new EPSON();
            var testCases = new Dictionary <Option, string>()
            {
                { Option.SingleLinePrinting, "Single Line Printing" },
                { Option.MultiLinePrinting, "Multi-line Printing" },
                { Option.LineSpacing, "Line Spacing" },
                { Option.BarcodeStyles, "Barcode Styles" },
                { Option.BarcodeTypes, "Barcode Types" },
                { Option.TwoDimensionCodes, "2D Codes" },
                { Option.TextStyles, "Text Styles" },
                { Option.FullReceipt, "Full Receipt" },
                { Option.CodePages, "Code Pages (Euro, Katakana, Etc)" },
                { Option.Images, "Images" },
                { Option.LegacyImages, "Legacy Images" },
                { Option.LargeByteArrays, "Large Byte Arrays" },
                { Option.CashDrawerPin2, "Cash Drawer Pin2" },
                { Option.CashDrawerPin5, "Cash Drawer Pin5" },
                { Option.Exit, "Exit" }
            };

            while (true)
            {
                foreach (var item in testCases)
                {
                    Console.WriteLine($"{(int)item.Key} : {item.Value}");
                }
                Console.Write("Execute Test: ");

                if (!int.TryParse(Console.ReadLine(), out choice) || !Enum.IsDefined(typeof(Option), choice))
                {
                    Console.WriteLine("Invalid entry. Please try again.");
                    continue;
                }

                var enumChoice = (Option)choice;
                if (enumChoice == Option.Exit)
                {
                    return;
                }

                Console.Clear();

                if (monitor)
                {
                    printer.StartMonitoring();
                }
                Setup(monitor);

                printer?.Write(e.PrintLine($"== [ Start {testCases[enumChoice]} ] =="));

                switch (enumChoice)
                {
                case Option.SingleLinePrinting:
                    printer.Write(Tests.SingleLinePrinting(e));
                    break;

                case Option.MultiLinePrinting:
                    printer.Write(Tests.MultiLinePrinting(e));
                    break;

                case Option.LineSpacing:
                    printer.Write(Tests.LineSpacing(e));
                    break;

                case Option.BarcodeStyles:
                    printer.Write(Tests.BarcodeStyles(e));
                    break;

                case Option.BarcodeTypes:
                    printer.Write(Tests.BarcodeTypes(e));
                    break;

                case Option.TwoDimensionCodes:
                    printer.Write(Tests.TwoDimensionCodes(e));
                    break;

                case Option.TextStyles:
                    printer.Write(Tests.TextStyles(e));
                    break;

                case Option.FullReceipt:
                    printer.Write(Tests.Receipt(e));
                    break;

                case Option.Images:
                    printer.Write(Tests.Images(e, false));
                    break;

                case Option.LegacyImages:
                    printer.Write(Tests.Images(e, true));
                    break;

                case Option.LargeByteArrays:
                    try
                    {
                        printer.Write(Tests.TestLargeByteArrays(e));
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine($"Aborting print due to test failure. Exception: {e?.Message}, Stack Trace: {e?.GetBaseException()?.StackTrace}");
                    }
                    break;

                case Option.CashDrawerPin2:
                    printer.Write(Tests.CashDrawerOpenPin2(e));
                    break;

                case Option.CashDrawerPin5:
                    printer.Write(Tests.CashDrawerOpenPin5(e));
                    break;

                default:
                    Console.WriteLine("Invalid entry.");
                    break;
                }

                Setup(monitor);
                printer?.Write(e.PrintLine($"== [ End {testCases[enumChoice]} ] =="));
                printer?.Write(e.PartialCutAfterFeed(5));

                // TODO: also make an automatic runner that runs all tests (command line).
            }
        }