diff --git a/ESCPOS_NET.ConsoleTest/Program.cs b/ESCPOS_NET.ConsoleTest/Program.cs index a5a2222..08e4726 100644 --- a/ESCPOS_NET.ConsoleTest/Program.cs +++ b/ESCPOS_NET.ConsoleTest/Program.cs @@ -9,12 +9,33 @@ namespace ESCPOS_NET.ConsoleTest internal class Program { private static BasePrinter printer; - private static ICommandEmitter e; + private static ICommandEmitter emitter; static void Main(string[] args) { Console.WriteLine("ESCPOS_NET Test Application..."); + + Console.WriteLine($"{(int)PrinterTypeOption.EPSON} {PrinterTypeOption.EPSON} Printer"); + Console.WriteLine($"{(int)PrinterTypeOption.CUSTOM} {PrinterTypeOption.CUSTOM} Printer"); + Console.Write("Choice: "); + var response = Console.ReadLine(); + var valid = new List { ((int)PrinterTypeOption.EPSON).ToString(), ((int)PrinterTypeOption.CUSTOM).ToString() }; + if (!valid.Contains(response)) + { + response = ((int)PrinterTypeOption.EPSON).ToString(); + } + int choice = int.Parse(response); + switch((PrinterTypeOption)choice) + { + case PrinterTypeOption.EPSON: + emitter = new EPSON(); + break; + case PrinterTypeOption.CUSTOM: + emitter = new CUSTOM(); + break; + } + Console.WriteLine("1 ) Test Serial Port"); Console.WriteLine("2 ) Test Network Printer"); Console.Write("Choice: "); @@ -22,14 +43,14 @@ static void Main(string[] args) string baudRate; string ip; string networkPort; - var response = Console.ReadLine(); - var valid = new List { "1", "2" }; + response = Console.ReadLine(); + valid = new List { "1", "2" }; if (!valid.Contains(response)) { response = "1"; } - int choice = int.Parse(response); + choice = int.Parse(response); if (choice == 1) { @@ -88,7 +109,6 @@ static void Main(string[] args) monitor = true; } - e = new EPSON(); var testCases = new Dictionary() { { Option.Printing, "Printing" }, @@ -134,41 +154,41 @@ static void Main(string[] args) } Setup(monitor); - printer?.Write(e.PrintLine($"== [ Start {testCases[enumChoice]} ] ==")); + printer?.Write(emitter.PrintLine($"== [ Start {testCases[enumChoice]} ] ==")); switch (enumChoice) { case Option.Printing: - printer.Write(Tests.Printing(e)); + printer.Write(Tests.Printing(emitter)); break; case Option.LineSpacing: - printer.Write(Tests.LineSpacing(e)); + printer.Write(Tests.LineSpacing(emitter)); break; case Option.BarcodeStyles: - printer.Write(Tests.BarcodeStyles(e)); + printer.Write(Tests.BarcodeStyles(emitter)); break; case Option.BarcodeTypes: - printer.Write(Tests.BarcodeTypes(e)); + printer.Write(Tests.BarcodeTypes(emitter)); break; case Option.TwoDimensionCodes: - printer.Write(Tests.TwoDimensionCodes(e)); + printer.Write(Tests.TwoDimensionCodes(emitter)); break; case Option.TextStyles: - printer.Write(Tests.TextStyles(e)); + printer.Write(Tests.TextStyles(emitter)); break; case Option.FullReceipt: - printer.Write(Tests.Receipt(e)); + printer.Write(Tests.Receipt(emitter)); break; case Option.Images: - printer.Write(Tests.Images(e, false)); + printer.Write(Tests.Images(emitter, false)); break; case Option.LegacyImages: - printer.Write(Tests.Images(e, true)); + printer.Write(Tests.Images(emitter, true)); break; case Option.LargeByteArrays: try { - printer.Write(Tests.TestLargeByteArrays(e)); + printer.Write(Tests.TestLargeByteArrays(emitter)); } catch (Exception e) { @@ -176,10 +196,10 @@ static void Main(string[] args) } break; case Option.CashDrawerPin2: - printer.Write(Tests.CashDrawerOpenPin2(e)); + printer.Write(Tests.CashDrawerOpenPin2(emitter)); break; case Option.CashDrawerPin5: - printer.Write(Tests.CashDrawerOpenPin5(e)); + printer.Write(Tests.CashDrawerOpenPin5(emitter)); break; default: Console.WriteLine("Invalid entry."); @@ -187,8 +207,8 @@ static void Main(string[] args) } Setup(monitor); - printer?.Write(e.PrintLine($"== [ End {testCases[enumChoice]} ] ==")); - printer?.Write(e.PartialCutAfterFeed(5)); + printer?.Write(emitter.PrintLine($"== [ End {testCases[enumChoice]} ] ==")); + printer?.Write(emitter.PartialCutAfterFeed(5)); // TODO: write a sanitation check. // TODO: make DPI to inch conversion function @@ -199,6 +219,12 @@ static void Main(string[] args) } } + public enum PrinterTypeOption + { + EPSON = 1, + CUSTOM = 2, + } + public enum Option { Printing = 1, @@ -234,11 +260,11 @@ private static void Setup(bool enableStatusBackMonitoring) printer.StatusChanged += StatusChanged; _hasEnabledStatusMonitoring = true; } - printer?.Write(e.Initialize()); - printer?.Write(e.Enable()); + printer?.Write(emitter.Initialize()); + printer?.Write(emitter.Enable()); if (enableStatusBackMonitoring) { - printer.Write(e.EnableAutomaticStatusBack()); + printer.Write(emitter.EnableAutomaticStatusBack()); } } } diff --git a/ESCPOS_NET.UnitTest/GlobalTests/Barcode.cs b/ESCPOS_NET.UnitTest/GlobalTests/Barcode.cs index bbde0b9..10d2ebb 100644 --- a/ESCPOS_NET.UnitTest/GlobalTests/Barcode.cs +++ b/ESCPOS_NET.UnitTest/GlobalTests/Barcode.cs @@ -14,6 +14,10 @@ public class Barcode [InlineData("EPSON", TwoDimensionCodeType.QRCODE_MODEL2)] [InlineData("EPSON", TwoDimensionCodeType.QRCODE_MICRO)] [InlineData("EPSON", null)] + [InlineData("CUSTOM", TwoDimensionCodeType.QRCODE_MODEL1)] + [InlineData("CUSTOM", TwoDimensionCodeType.QRCODE_MODEL2)] + [InlineData("CUSTOM", TwoDimensionCodeType.QRCODE_MICRO)] + [InlineData("CUSTOM", null)] public void PrintQRCode_Success(string emitter, TwoDimensionCodeType? codeType) { var type = Assembly.LoadFrom("ESCPOS_NET").GetType($"ESCPOS_NET.Emitters.{emitter}", true); @@ -30,6 +34,7 @@ public void PrintQRCode_Success(string emitter, TwoDimensionCodeType? codeType) [Theory] [InlineData("EPSON", TwoDimensionCodeType.PDF417)] + [InlineData("CUSTOM", TwoDimensionCodeType.PDF417)] public void PrintQRCode_Failure(string emitter, TwoDimensionCodeType codeType) { var type = Assembly.LoadFrom("ESCPOS_NET").GetType($"ESCPOS_NET.Emitters.{emitter}", true); diff --git a/ESCPOS_NET/Emitters/BaseCommandEmitter/ActionCommands.cs b/ESCPOS_NET/Emitters/BaseCommandEmitter/ActionCommands.cs index e713659..b0f253a 100644 --- a/ESCPOS_NET/Emitters/BaseCommandEmitter/ActionCommands.cs +++ b/ESCPOS_NET/Emitters/BaseCommandEmitter/ActionCommands.cs @@ -1,16 +1,14 @@ -using ESCPOS_NET.Emitters.BaseCommandValues; - -namespace ESCPOS_NET.Emitters +namespace ESCPOS_NET.Emitters { - public abstract partial class BaseCommandEmitter : ICommandEmitter + public abstract partial class BaseCommandEmitter : ICommandEmitter { /* Action Commands */ - public virtual byte[] FullCut() => new byte[] { Cmd.GS, Ops.PaperCut, Functions.PaperCutFullCut }; + public virtual byte[] FullCut() => new byte[] { Values.GS, Values.PaperCut, Values.PaperCutFullCut }; - public virtual byte[] PartialCut() => new byte[] { Cmd.GS, Ops.PaperCut, Functions.PaperCutPartialCut }; + public virtual byte[] PartialCut() => new byte[] { Values.GS, Values.PaperCut, Values.PaperCutPartialCut }; - public virtual byte[] FullCutAfterFeed(int lineCount) => new byte[] { Cmd.GS, Ops.PaperCut, Functions.PaperCutFullCutWithFeed, (byte)lineCount }; + public virtual byte[] FullCutAfterFeed(int lineCount) => new byte[] { Values.GS, Values.PaperCut, Values.PaperCutFullCutWithFeed, (byte)lineCount }; - public virtual byte[] PartialCutAfterFeed(int lineCount) => new byte[] { Cmd.GS, Ops.PaperCut, Functions.PaperCutPartialCutWithFeed, (byte)lineCount }; + public virtual byte[] PartialCutAfterFeed(int lineCount) => new byte[] { Values.GS, Values.PaperCut, Values.PaperCutPartialCutWithFeed, (byte)lineCount }; } } diff --git a/ESCPOS_NET/Emitters/BaseCommandEmitter/BarcodeCommands.cs b/ESCPOS_NET/Emitters/BaseCommandEmitter/BarcodeCommands.cs index 63f27ae..6a86c2f 100644 --- a/ESCPOS_NET/Emitters/BaseCommandEmitter/BarcodeCommands.cs +++ b/ESCPOS_NET/Emitters/BaseCommandEmitter/BarcodeCommands.cs @@ -1,5 +1,4 @@ using ESCPOS_NET.DataValidation; -using ESCPOS_NET.Emitters.BaseCommandValues; using ESCPOS_NET.Extensions; using System; using System.Collections.Generic; @@ -8,7 +7,7 @@ namespace ESCPOS_NET.Emitters { - public abstract partial class BaseCommandEmitter : ICommandEmitter + public abstract partial class BaseCommandEmitter : ICommandEmitter { /* Barcode Commands */ public virtual byte[] PrintBarcode(BarcodeType type, string barcode, BarcodeCode code = BarcodeCode.CODE_B) @@ -38,7 +37,7 @@ protected virtual byte[] BarcodeBytes(BarcodeType type, string barcode, BarcodeC barcode = $"{(char)0x7B}{(char)code}" + barcode; } - var command = new List { Cmd.GS, Barcodes.PrintBarcode, (byte)type, (byte)barcode.Length }; + var command = new List { Values.GS, Values.PrintBarcode, (byte)type, (byte)barcode.Length }; command.AddRange(barcode.ToCharArray().Select(x => (byte)x)); return command.ToArray(); } @@ -62,39 +61,39 @@ public virtual byte[] Print2DCode(TwoDimensionCodeType type, string data, Size2D protected virtual byte[] TwoDimensionCodeBytes(TwoDimensionCodeType type, string data, Size2DCode size, CorrectionLevel2DCode correction) { List command = new List(); - byte[] initial = { Cmd.GS, Barcodes.Set2DCode, Barcodes.PrintBarcode }; + byte[] initial = { Values.GS, Values.Set2DCode, Values.PrintBarcode }; switch (type) { case TwoDimensionCodeType.PDF417: - command.AddRange(initial, Barcodes.SetPDF417NumberOfColumns, Barcodes.AutoEnding); - command.AddRange(initial, Barcodes.SetPDF417NumberOfRows, Barcodes.AutoEnding); - command.AddRange(initial, Barcodes.SetPDF417DotSize, (byte)size); - command.AddRange(initial, Barcodes.SetPDF417CorrectionLevel, (byte)correction); + command.AddRange(initial, Values.SetPDF417NumberOfColumns, Values.AutoEnding); + command.AddRange(initial, Values.SetPDF417NumberOfRows, Values.AutoEnding); + command.AddRange(initial, Values.SetPDF417DotSize, (byte)size); + command.AddRange(initial, Values.SetPDF417CorrectionLevel, (byte)correction); // k = (pL + pH * 256) - 3 --> But pH is always 0. int k = data.Length; int l = k + 3; - command.AddRange(initial, (byte)l, Barcodes.StorePDF417Data); + command.AddRange(initial, (byte)l, Values.StorePDF417Data); command.AddRange(data.ToCharArray().Select(x => (byte)x)); // Prints stored PDF417 - command.AddRange(initial, Barcodes.PrintPDF417); + command.AddRange(initial, Values.PrintPDF417); break; case TwoDimensionCodeType.QRCODE_MODEL1: case TwoDimensionCodeType.QRCODE_MODEL2: case TwoDimensionCodeType.QRCODE_MICRO: - command.AddRange(initial, Barcodes.SelectQRCodeModel, (byte)type, Barcodes.AutoEnding); - command.AddRange(initial, Barcodes.SetQRCodeDotSize, (byte)size); - command.AddRange(initial, Barcodes.SetQRCodeCorrectionLevel, (byte)correction); + command.AddRange(initial, Values.SelectQRCodeModel, (byte)type, Values.AutoEnding); + command.AddRange(initial, Values.SetQRCodeDotSize, (byte)size); + command.AddRange(initial, Values.SetQRCodeCorrectionLevel, (byte)correction); int num = data.Length + 3; int pL = num % 256; int pH = num / 256; - command.AddRange(initial, (byte)pL, (byte)pH, Barcodes.StoreQRCodeData); + command.AddRange(initial, (byte)pL, (byte)pH, Values.StoreQRCodeData); command.AddRange(data.ToCharArray().Select(x => (byte)x)); // Prints stored QRCode - command.AddRange(initial, Barcodes.PrintQRCode); + command.AddRange(initial, Values.PrintQRCode); break; default: @@ -104,12 +103,12 @@ protected virtual byte[] TwoDimensionCodeBytes(TwoDimensionCodeType type, string return command.ToArray(); } - public virtual byte[] SetBarcodeHeightInDots(int height) => new byte[] { Cmd.GS, Barcodes.SetBarcodeHeightInDots, (byte)height }; + public virtual byte[] SetBarcodeHeightInDots(int height) => new byte[] { Values.GS, Values.SetBarcodeHeightInDots, (byte)height }; - public virtual byte[] SetBarWidth(BarWidth width) => new byte[] { Cmd.GS, Barcodes.SetBarWidth, (byte)width }; + public virtual byte[] SetBarWidth(BarWidth width) => new byte[] { Values.GS, Values.SetBarWidth, (byte)width }; - public virtual byte[] SetBarLabelPosition(BarLabelPrintPosition position) => new byte[] { Cmd.GS, Barcodes.SetBarLabelPosition, (byte)position }; + public virtual byte[] SetBarLabelPosition(BarLabelPrintPosition position) => new byte[] { Values.GS, Values.SetBarLabelPosition, (byte)position }; - public virtual byte[] SetBarLabelFontB(bool fontB) => new byte[] { Cmd.GS, Barcodes.SetBarLabelFont, (byte)(fontB ? 1 : 0) }; + public virtual byte[] SetBarLabelFontB(bool fontB) => new byte[] { Values.GS, Values.SetBarLabelFont, (byte)(fontB ? 1 : 0) }; } } diff --git a/ESCPOS_NET/Emitters/BaseCommandEmitter/BaseCommandEmitter.cs b/ESCPOS_NET/Emitters/BaseCommandEmitter/BaseCommandEmitter.cs new file mode 100644 index 0000000..4bccefb --- /dev/null +++ b/ESCPOS_NET/Emitters/BaseCommandEmitter/BaseCommandEmitter.cs @@ -0,0 +1,7 @@ +namespace ESCPOS_NET.Emitters +{ + public abstract partial class BaseCommandEmitter : ICommandEmitter where TCommandValues : ICommandValues, new() + { + TCommandValues Values = new TCommandValues(); + } +} diff --git a/ESCPOS_NET/Emitters/BaseCommandEmitter/CashDrawerCommands.cs b/ESCPOS_NET/Emitters/BaseCommandEmitter/CashDrawerCommands.cs index b237f3e..099a37d 100644 --- a/ESCPOS_NET/Emitters/BaseCommandEmitter/CashDrawerCommands.cs +++ b/ESCPOS_NET/Emitters/BaseCommandEmitter/CashDrawerCommands.cs @@ -1,12 +1,10 @@ -using ESCPOS_NET.Emitters.BaseCommandValues; - -namespace ESCPOS_NET.Emitters +namespace ESCPOS_NET.Emitters { - public abstract partial class BaseCommandEmitter : ICommandEmitter + public abstract partial class BaseCommandEmitter : ICommandEmitter { /* Cash Drawer Commands */ - public virtual byte[] CashDrawerOpenPin2() => new byte[] { Cmd.ESC, Ops.CashDrawerPulse, 0x00 }; + public virtual byte[] CashDrawerOpenPin2() => new byte[] { Values.ESC, Values.CashDrawerPulse, 0x00 }; - public virtual byte[] CashDrawerOpenPin5() => new byte[] { Cmd.ESC, Ops.CashDrawerPulse, 0x01 }; + public virtual byte[] CashDrawerOpenPin5() => new byte[] { Values.ESC, Values.CashDrawerPulse, 0x01 }; } } diff --git a/ESCPOS_NET/Emitters/BaseCommandEmitter/CharacterCommands.cs b/ESCPOS_NET/Emitters/BaseCommandEmitter/CharacterCommands.cs index 7700d79..a540a28 100644 --- a/ESCPOS_NET/Emitters/BaseCommandEmitter/CharacterCommands.cs +++ b/ESCPOS_NET/Emitters/BaseCommandEmitter/CharacterCommands.cs @@ -1,20 +1,18 @@ -using ESCPOS_NET.Emitters.BaseCommandValues; - -namespace ESCPOS_NET.Emitters +namespace ESCPOS_NET.Emitters { - public abstract partial class BaseCommandEmitter : ICommandEmitter + public abstract partial class BaseCommandEmitter : ICommandEmitter { /* Character Commands */ - public virtual byte[] SetStyles(PrintStyle style) => new byte[] { Cmd.ESC, Chars.StyleMode, (byte)style }; + public virtual byte[] SetStyles(PrintStyle style) => new byte[] { Values.ESC, Values.StyleMode, (byte)style }; - public virtual byte[] LeftAlign() => new byte[] { Cmd.ESC, Chars.Alignment, (byte)Align.Left }; + public virtual byte[] LeftAlign() => new byte[] { Values.ESC, Values.Alignment, (byte)Align.Left }; - public virtual byte[] CenterAlign() => new byte[] { Cmd.ESC, Chars.Alignment, (byte)Align.Center }; + public virtual byte[] CenterAlign() => new byte[] { Values.ESC, Values.Alignment, (byte)Align.Center }; - public virtual byte[] RightAlign() => new byte[] { Cmd.ESC, Chars.Alignment, (byte)Align.Right }; + public virtual byte[] RightAlign() => new byte[] { Values.ESC, Values.Alignment, (byte)Align.Right }; - public virtual byte[] RightCharacterSpacing(int spaceCount) => new byte[] { Cmd.ESC, Chars.RightCharacterSpacing, (byte)spaceCount }; + public virtual byte[] RightCharacterSpacing(int spaceCount) => new byte[] { Values.ESC, Values.RightCharacterSpacing, (byte)spaceCount }; - public virtual byte[] CodePage(CodePage codePage) => new byte[] { Cmd.ESC, Chars.CodePage, (byte)codePage }; + public virtual byte[] CodePage(CodePage codePage) => new byte[] { Values.ESC, Values.CodePage, (byte)codePage }; } } diff --git a/ESCPOS_NET/Emitters/BaseCommandEmitter/DisplayCommands.cs b/ESCPOS_NET/Emitters/BaseCommandEmitter/DisplayCommands.cs index ba6c170..97b67fd 100644 --- a/ESCPOS_NET/Emitters/BaseCommandEmitter/DisplayCommands.cs +++ b/ESCPOS_NET/Emitters/BaseCommandEmitter/DisplayCommands.cs @@ -1,10 +1,8 @@ -using ESCPOS_NET.Emitters.BaseCommandValues; - -namespace ESCPOS_NET.Emitters +namespace ESCPOS_NET.Emitters { - public abstract partial class BaseCommandEmitter : ICommandEmitter + public abstract partial class BaseCommandEmitter : ICommandEmitter { /* Display Commands */ - public virtual byte[] Clear() => new byte[] { Display.CLR }; + public virtual byte[] Clear() => new byte[] { Values.CLR }; } } diff --git a/ESCPOS_NET/Emitters/BaseCommandEmitter/ImageCommands.cs b/ESCPOS_NET/Emitters/BaseCommandEmitter/ImageCommands.cs index 6b247d2..a3f99da 100644 --- a/ESCPOS_NET/Emitters/BaseCommandEmitter/ImageCommands.cs +++ b/ESCPOS_NET/Emitters/BaseCommandEmitter/ImageCommands.cs @@ -1,10 +1,9 @@ -using ESCPOS_NET.Emitters.BaseCommandValues; using ESCPOS_NET.Utilities; using SixLabors.ImageSharp; namespace ESCPOS_NET.Emitters { - public abstract partial class BaseCommandEmitter : ICommandEmitter + public abstract partial class BaseCommandEmitter : ICommandEmitter { private byte[] GetImageHeader(int commandLength) { @@ -19,11 +18,11 @@ private byte[] GetImageHeader(int commandLength) if (i >= 3) { - return new byte[] { Cmd.GS, Images.ImageCmd8, Images.ImageCmdL, lengths[0], lengths[1], lengths[2], lengths[3] }; + return new byte[] { Values.GS, Values.ImageCmd8, Values.ImageCmdL, lengths[0], lengths[1], lengths[2], lengths[3] }; } else { - return new byte[] { Cmd.GS, Images.ImageCmdParen, Images.ImageCmdL, lengths[0], lengths[1] }; + return new byte[] { Values.GS, Values.ImageCmdParen, Values.ImageCmdL, lengths[0], lengths[1] }; } } @@ -74,7 +73,7 @@ public virtual byte[] BufferImage(byte[] image, int maxWidth = -1, bool isLegacy var byteWidth = (width + 7 & -8) / 8; byte widthL = (byte)byteWidth; byte widthH = (byte)(byteWidth >> 8); - imageCommand.Append(new byte[] { Cmd.GS, Images.ImageCmdLegacy, 0x30, 0x00, widthL, widthH, heightL, heightH }); + imageCommand.Append(new byte[] { Values.GS, Values.ImageCmdLegacy, 0x30, 0x00, widthL, widthH, heightL, heightH }); } else { diff --git a/ESCPOS_NET/Emitters/BaseCommandEmitter/LineSpacingCommands.cs b/ESCPOS_NET/Emitters/BaseCommandEmitter/LineSpacingCommands.cs index 69e4f70..728c154 100644 --- a/ESCPOS_NET/Emitters/BaseCommandEmitter/LineSpacingCommands.cs +++ b/ESCPOS_NET/Emitters/BaseCommandEmitter/LineSpacingCommands.cs @@ -1,11 +1,9 @@ -using ESCPOS_NET.Emitters.BaseCommandValues; - -namespace ESCPOS_NET.Emitters +namespace ESCPOS_NET.Emitters { - public abstract partial class BaseCommandEmitter : ICommandEmitter + public abstract partial class BaseCommandEmitter : ICommandEmitter { - public virtual byte[] ResetLineSpacing() => new byte[] { Cmd.ESC, Whitespace.ResetLineSpacing }; + public virtual byte[] ResetLineSpacing() => new byte[] { Values.ESC, Values.ResetLineSpacing }; - public virtual byte[] SetLineSpacingInDots(int dots) => new byte[] { Cmd.ESC, Whitespace.LineSpacingInDots, (byte)dots }; + public virtual byte[] SetLineSpacingInDots(int dots) => new byte[] { Values.ESC, Values.LineSpacingInDots, (byte)dots }; } } diff --git a/ESCPOS_NET/Emitters/BaseCommandEmitter/OperationalCommands.cs b/ESCPOS_NET/Emitters/BaseCommandEmitter/OperationalCommands.cs index 8f40497..a5768c1 100644 --- a/ESCPOS_NET/Emitters/BaseCommandEmitter/OperationalCommands.cs +++ b/ESCPOS_NET/Emitters/BaseCommandEmitter/OperationalCommands.cs @@ -1,14 +1,12 @@ -using ESCPOS_NET.Emitters.BaseCommandValues; - -namespace ESCPOS_NET.Emitters +namespace ESCPOS_NET.Emitters { - public abstract partial class BaseCommandEmitter : ICommandEmitter + public abstract partial class BaseCommandEmitter : ICommandEmitter { /* Operational Commands */ - public virtual byte[] Initialize() => new byte[] { Cmd.ESC, Ops.Initialize }; + public virtual byte[] Initialize() => new byte[] { Values.ESC, Values.Initialize }; - public virtual byte[] Enable() => new byte[] { Cmd.ESC, Ops.EnableDisable, 1 }; + public virtual byte[] Enable() => new byte[] { Values.ESC, Values.EnableDisable, 1 }; - public virtual byte[] Disable() => new byte[] { Cmd.ESC, Ops.EnableDisable, 0 }; + public virtual byte[] Disable() => new byte[] { Values.ESC, Values.EnableDisable, 0 }; } } diff --git a/ESCPOS_NET/Emitters/BaseCommandEmitter/PrintCommands.cs b/ESCPOS_NET/Emitters/BaseCommandEmitter/PrintCommands.cs index 725a300..abd1dc0 100644 --- a/ESCPOS_NET/Emitters/BaseCommandEmitter/PrintCommands.cs +++ b/ESCPOS_NET/Emitters/BaseCommandEmitter/PrintCommands.cs @@ -1,9 +1,8 @@ using System.Linq; -using ESCPOS_NET.Emitters.BaseCommandValues; namespace ESCPOS_NET.Emitters { - public abstract partial class BaseCommandEmitter : ICommandEmitter + public abstract partial class BaseCommandEmitter : ICommandEmitter { /* Printing Commands */ public virtual byte[] Print(string data) @@ -26,14 +25,14 @@ public virtual byte[] PrintLine(string line) return Print(line.Replace("\r", string.Empty).Replace("\n", string.Empty) + "\n"); } - public virtual byte[] FeedLines(int lineCount) => new byte[] { Cmd.ESC, Whitespace.FeedLines, (byte)lineCount }; + public virtual byte[] FeedLines(int lineCount) => new byte[] { Values.ESC, Values.FeedLines, (byte)lineCount }; - public virtual byte[] FeedLinesReverse(int lineCount) => new byte[] { Cmd.ESC, Whitespace.FeedLinesReverse, (byte)lineCount }; + public virtual byte[] FeedLinesReverse(int lineCount) => new byte[] { Values.ESC, Values.FeedLinesReverse, (byte)lineCount }; - public virtual byte[] FeedDots(int dotCount) => new byte[] { Cmd.ESC, Whitespace.FeedDots, (byte)dotCount }; + public virtual byte[] FeedDots(int dotCount) => new byte[] { Values.ESC, Values.FeedDots, (byte)dotCount }; - public virtual byte[] ReverseMode(bool enable) => new byte[] { Cmd.GS, Chars.ReversePrintMode, enable ? (byte)0x01 : (byte)0x00 }; + public virtual byte[] ReverseMode(bool enable) => new byte[] { Values.GS, Values.ReversePrintMode, enable ? (byte)0x01 : (byte)0x00 }; - public virtual byte[] UpsideDownMode(bool enable) => new byte[] { Cmd.ESC, Chars.UpsideDownMode, enable ? (byte)0x01 : (byte)0x00 }; + public virtual byte[] UpsideDownMode(bool enable) => new byte[] { Values.ESC, Values.UpsideDownMode, enable ? (byte)0x01 : (byte)0x00 }; } } diff --git a/ESCPOS_NET/Emitters/BaseCommandEmitter/StatusCommands.cs b/ESCPOS_NET/Emitters/BaseCommandEmitter/StatusCommands.cs index 964dda4..4e15c7e 100644 --- a/ESCPOS_NET/Emitters/BaseCommandEmitter/StatusCommands.cs +++ b/ESCPOS_NET/Emitters/BaseCommandEmitter/StatusCommands.cs @@ -1,12 +1,10 @@ -using ESCPOS_NET.Emitters.BaseCommandValues; - -namespace ESCPOS_NET.Emitters +namespace ESCPOS_NET.Emitters { - public abstract partial class BaseCommandEmitter : ICommandEmitter + public abstract partial class BaseCommandEmitter : ICommandEmitter { /* Status Commands */ - public virtual byte[] EnableAutomaticStatusBack() => new byte[] { Cmd.GS, Status.AutomaticStatusBack, 0xFF }; + public virtual byte[] EnableAutomaticStatusBack() => new byte[] { Values.GS, Values.AutomaticStatusBack, 0xFF }; - public virtual byte[] EnableAutomaticInkStatusBack() => new byte[] { Cmd.GS, Status.AutomaticInkStatusBack, 0xFF }; + public virtual byte[] EnableAutomaticInkStatusBack() => new byte[] { Values.GS, Values.AutomaticInkStatusBack, 0xFF }; } } diff --git a/ESCPOS_NET/Emitters/BaseCommandValues/Barcodes.cs b/ESCPOS_NET/Emitters/BaseCommandValues/Barcodes.cs index 3b1fd80..e4718a8 100644 --- a/ESCPOS_NET/Emitters/BaseCommandValues/Barcodes.cs +++ b/ESCPOS_NET/Emitters/BaseCommandValues/Barcodes.cs @@ -1,26 +1,26 @@ -namespace ESCPOS_NET.Emitters.BaseCommandValues +namespace ESCPOS_NET.Emitters { - public static class Barcodes + public partial class BaseCommandValues : ICommandValues { - public static readonly byte PrintBarcode = 0x6B; - public static readonly byte SetBarcodeHeightInDots = 0x68; - public static readonly byte SetBarWidth = 0x77; - public static readonly byte SetBarLabelPosition = 0x48; - public static readonly byte SetBarLabelFont = 0x66; + public virtual byte PrintBarcode => 0x6B; + public virtual byte SetBarcodeHeightInDots => 0x68; + public virtual byte SetBarWidth => 0x77; + public virtual byte SetBarLabelPosition => 0x48; + public virtual byte SetBarLabelFont => 0x66; - public static readonly byte Set2DCode = 0x28; - public static readonly byte AutoEnding = 0x00; - public static readonly byte[] SetPDF417NumberOfColumns = { 0x03, 0x00, 0x30, 0x41 }; - public static readonly byte[] SetPDF417NumberOfRows = { 0x03, 0x00, 0x30, 0x42 }; - public static readonly byte[] SetPDF417DotSize = { 0x03, 0x00, 0x30, 0x43 }; - public static readonly byte[] SetPDF417CorrectionLevel = { 0x04, 0x00, 0x30, 0x45, 0x30 }; - public static readonly byte[] StorePDF417Data = { 0x00, 0x30, 0x50, 0x30 }; - public static readonly byte[] PrintPDF417 = { 0x03, 0x00, 0x30, 0x51, 0x30 }; + public virtual byte Set2DCode => 0x28; + public virtual byte AutoEnding => 0x00; + public virtual byte[] SetPDF417NumberOfColumns => new byte[] { 0x03, 0x00, 0x30, 0x41 }; + public virtual byte[] SetPDF417NumberOfRows => new byte[] { 0x03, 0x00, 0x30, 0x42 }; + public virtual byte[] SetPDF417DotSize => new byte[] { 0x03, 0x00, 0x30, 0x43 }; + public virtual byte[] SetPDF417CorrectionLevel => new byte[] { 0x04, 0x00, 0x30, 0x45, 0x30 }; + public virtual byte[] StorePDF417Data => new byte[] { 0x00, 0x30, 0x50, 0x30 }; + public virtual byte[] PrintPDF417 => new byte[] { 0x03, 0x00, 0x30, 0x51, 0x30 }; - public static readonly byte[] SelectQRCodeModel = { 0x04, 0x00, 0x31, 0x41 }; - public static readonly byte[] SetQRCodeDotSize = { 0x03, 0x00, 0x31, 0x43 }; - public static readonly byte[] SetQRCodeCorrectionLevel = { 0x03, 0x00, 0x31, 0x45 }; - public static readonly byte[] StoreQRCodeData = { 0x31, 0x50, 0x30 }; - public static readonly byte[] PrintQRCode = { 0x03, 0x00, 0x31, 0x51, 0x30 }; + public virtual byte[] SelectQRCodeModel => new byte[] { 0x04, 0x00, 0x31, 0x41 }; + public virtual byte[] SetQRCodeDotSize => new byte[] { 0x03, 0x00, 0x31, 0x43 }; + public virtual byte[] SetQRCodeCorrectionLevel => new byte[] { 0x03, 0x00, 0x31, 0x45 }; + public virtual byte[] StoreQRCodeData => new byte[] { 0x31, 0x50, 0x30 }; + public virtual byte[] PrintQRCode => new byte[] { 0x03, 0x00, 0x31, 0x51, 0x30 }; } } diff --git a/ESCPOS_NET/Emitters/BaseCommandValues/Chars.cs b/ESCPOS_NET/Emitters/BaseCommandValues/Chars.cs index 03321ab..1da46be 100644 --- a/ESCPOS_NET/Emitters/BaseCommandValues/Chars.cs +++ b/ESCPOS_NET/Emitters/BaseCommandValues/Chars.cs @@ -1,12 +1,12 @@ -namespace ESCPOS_NET.Emitters.BaseCommandValues +namespace ESCPOS_NET.Emitters { - public static class Chars + public partial class BaseCommandValues : ICommandValues { - public static readonly byte StyleMode = 0x21; - public static readonly byte Alignment = 0x61; - public static readonly byte ReversePrintMode = 0x42; - public static readonly byte RightCharacterSpacing = 0x20; - public static readonly byte UpsideDownMode = 0x7B; - public static readonly byte CodePage = 0x74; + public virtual byte StyleMode => 0x21; + public virtual byte Alignment => 0x61; + public virtual byte ReversePrintMode => 0x42; + public virtual byte RightCharacterSpacing => 0x20; + public virtual byte UpsideDownMode => 0x7B; + public virtual byte CodePage => 0x74; } } diff --git a/ESCPOS_NET/Emitters/BaseCommandValues/Cmd.cs b/ESCPOS_NET/Emitters/BaseCommandValues/Cmd.cs index 40b4662..efccf7a 100644 --- a/ESCPOS_NET/Emitters/BaseCommandValues/Cmd.cs +++ b/ESCPOS_NET/Emitters/BaseCommandValues/Cmd.cs @@ -1,8 +1,8 @@ -namespace ESCPOS_NET.Emitters.BaseCommandValues +namespace ESCPOS_NET.Emitters { - public static class Cmd + public partial class BaseCommandValues : ICommandValues { - public static readonly byte ESC = 0x1B; - public static readonly byte GS = 0x1D; + public virtual byte ESC => 0x1B; + public virtual byte GS => 0x1D; } } diff --git a/ESCPOS_NET/Emitters/BaseCommandValues/Display.cs b/ESCPOS_NET/Emitters/BaseCommandValues/Display.cs index e14d0f0..974adb4 100644 --- a/ESCPOS_NET/Emitters/BaseCommandValues/Display.cs +++ b/ESCPOS_NET/Emitters/BaseCommandValues/Display.cs @@ -1,7 +1,7 @@ -namespace ESCPOS_NET.Emitters.BaseCommandValues +namespace ESCPOS_NET.Emitters { - public static class Display + public partial class BaseCommandValues : ICommandValues { - public static readonly byte CLR = 0x0C; + public virtual byte CLR => 0x0C; } } diff --git a/ESCPOS_NET/Emitters/BaseCommandValues/Functions.cs b/ESCPOS_NET/Emitters/BaseCommandValues/Functions.cs index fbd9856..8dbf9e2 100644 --- a/ESCPOS_NET/Emitters/BaseCommandValues/Functions.cs +++ b/ESCPOS_NET/Emitters/BaseCommandValues/Functions.cs @@ -1,10 +1,10 @@ -namespace ESCPOS_NET.Emitters.BaseCommandValues +namespace ESCPOS_NET.Emitters { - public static class Functions + public partial class BaseCommandValues : ICommandValues { - public static readonly byte PaperCutFullCut = 0x00; - public static readonly byte PaperCutFullCutWithFeed = 0x41; - public static readonly byte PaperCutPartialCut = 0x01; - public static readonly byte PaperCutPartialCutWithFeed = 0x42; + public virtual byte PaperCutFullCut => 0x00; + public virtual byte PaperCutFullCutWithFeed => 0x41; + public virtual byte PaperCutPartialCut => 0x01; + public virtual byte PaperCutPartialCutWithFeed => 0x42; } } diff --git a/ESCPOS_NET/Emitters/BaseCommandValues/Images.cs b/ESCPOS_NET/Emitters/BaseCommandValues/Images.cs index 7f4cb99..10e9e45 100644 --- a/ESCPOS_NET/Emitters/BaseCommandValues/Images.cs +++ b/ESCPOS_NET/Emitters/BaseCommandValues/Images.cs @@ -1,10 +1,10 @@ -namespace ESCPOS_NET.Emitters.BaseCommandValues +namespace ESCPOS_NET.Emitters { - public static class Images + public partial class BaseCommandValues : ICommandValues { - public static readonly byte ImageCmdParen = 0x28; - public static readonly byte ImageCmdLegacy = 0x76; - public static readonly byte ImageCmd8 = 0x38; - public static readonly byte ImageCmdL = 0x4C; + public virtual byte ImageCmdParen => 0x28; + public virtual byte ImageCmdLegacy => 0x76; + public virtual byte ImageCmd8 => 0x38; + public virtual byte ImageCmdL => 0x4C; } } diff --git a/ESCPOS_NET/Emitters/BaseCommandValues/Ops.cs b/ESCPOS_NET/Emitters/BaseCommandValues/Ops.cs index 9cf4263..eac0ffd 100644 --- a/ESCPOS_NET/Emitters/BaseCommandValues/Ops.cs +++ b/ESCPOS_NET/Emitters/BaseCommandValues/Ops.cs @@ -1,10 +1,10 @@ -namespace ESCPOS_NET.Emitters.BaseCommandValues +namespace ESCPOS_NET.Emitters { - public static class Ops + public partial class BaseCommandValues : ICommandValues { - public static readonly byte Initialize = 0x40; - public static readonly byte EnableDisable = 0x3D; - public static readonly byte PaperCut = 0x56; - public static readonly byte CashDrawerPulse = 0x70; + public virtual byte Initialize => 0x40; + public virtual byte EnableDisable => 0x3D; + public virtual byte PaperCut => 0x56; + public virtual byte CashDrawerPulse => 0x70; } } diff --git a/ESCPOS_NET/Emitters/BaseCommandValues/Status.cs b/ESCPOS_NET/Emitters/BaseCommandValues/Status.cs index 70e547f..5461054 100644 --- a/ESCPOS_NET/Emitters/BaseCommandValues/Status.cs +++ b/ESCPOS_NET/Emitters/BaseCommandValues/Status.cs @@ -1,8 +1,8 @@ -namespace ESCPOS_NET.Emitters.BaseCommandValues +namespace ESCPOS_NET.Emitters { - public static class Status + public partial class BaseCommandValues : ICommandValues { - public static readonly byte AutomaticStatusBack = 0x61; - public static readonly byte AutomaticInkStatusBack = 0x6A; + public virtual byte AutomaticStatusBack => 0x61; + public virtual byte AutomaticInkStatusBack => 0x6A; } } diff --git a/ESCPOS_NET/Emitters/BaseCommandValues/Whitespace.cs b/ESCPOS_NET/Emitters/BaseCommandValues/Whitespace.cs index f679a76..6f33fb3 100644 --- a/ESCPOS_NET/Emitters/BaseCommandValues/Whitespace.cs +++ b/ESCPOS_NET/Emitters/BaseCommandValues/Whitespace.cs @@ -1,13 +1,13 @@ -namespace ESCPOS_NET.Emitters.BaseCommandValues +namespace ESCPOS_NET.Emitters { - public static class Whitespace + public partial class BaseCommandValues : ICommandValues { // TODO: tabs? - public static readonly byte Linefeed = 0x0A; - public static readonly byte FeedLines = 0x64; - public static readonly byte FeedLinesReverse = 0x65; - public static readonly byte FeedDots = 0x4A; - public static readonly byte ResetLineSpacing = 0x32; - public static readonly byte LineSpacingInDots = 0x33; + public virtual byte Linefeed => 0x0A; + public virtual byte FeedLines => 0x64; + public virtual byte FeedLinesReverse => 0x65; + public virtual byte FeedDots => 0x4A; + public virtual byte ResetLineSpacing => 0x32; + public virtual byte LineSpacingInDots => 0x33; } } diff --git a/ESCPOS_NET/Emitters/CUSTOM.cs b/ESCPOS_NET/Emitters/CUSTOM.cs new file mode 100644 index 0000000..344d4c0 --- /dev/null +++ b/ESCPOS_NET/Emitters/CUSTOM.cs @@ -0,0 +1,10 @@ +namespace ESCPOS_NET.Emitters +{ + /// + /// CUSTOM Printer (https://www.custom.biz/) implementation of the ESC \ POS protocol. The majority of the commands are identical. However, a small + /// number of them are unique to the CUSTOM implementation. + /// + public class CUSTOM : CustomCommandEmitter + { + } +} \ No newline at end of file diff --git a/ESCPOS_NET/Emitters/CustomCommandEmitter/CustomCommandEmitter.cs b/ESCPOS_NET/Emitters/CustomCommandEmitter/CustomCommandEmitter.cs new file mode 100644 index 0000000..76e50bc --- /dev/null +++ b/ESCPOS_NET/Emitters/CustomCommandEmitter/CustomCommandEmitter.cs @@ -0,0 +1,7 @@ +namespace ESCPOS_NET.Emitters +{ + public abstract partial class CustomCommandEmitter : BaseCommandEmitter + { + /* Any commands that need to be overridden would be added here */ + } +} diff --git a/ESCPOS_NET/Emitters/CustomCommandValues/Barcodes.cs b/ESCPOS_NET/Emitters/CustomCommandValues/Barcodes.cs new file mode 100644 index 0000000..9dfbb63 --- /dev/null +++ b/ESCPOS_NET/Emitters/CustomCommandValues/Barcodes.cs @@ -0,0 +1,15 @@ +namespace ESCPOS_NET.Emitters +{ + public partial class CustomCommandValues + { + /// + /// CUSTOM implements the Store QR Code Data slightly differently than the base implementation + /// + public override byte[] StoreQRCodeData => new byte[] { 0x31, 0x50, 0x31 }; + + /// + /// CUSTOM implements the Print QR Code slightly differently than the base implementation + /// + public override byte[] PrintQRCode => new byte[] { 0x03, 0x00, 0x31, 0x51, 0x31 }; + } +} diff --git a/ESCPOS_NET/Emitters/CustomCommandValues/CustomCommandValues.cs b/ESCPOS_NET/Emitters/CustomCommandValues/CustomCommandValues.cs new file mode 100644 index 0000000..386ff11 --- /dev/null +++ b/ESCPOS_NET/Emitters/CustomCommandValues/CustomCommandValues.cs @@ -0,0 +1,6 @@ +namespace ESCPOS_NET.Emitters +{ + public partial class CustomCommandValues : BaseCommandValues + { + } +} diff --git a/ESCPOS_NET/Emitters/EPSON.cs b/ESCPOS_NET/Emitters/EPSON.cs index 8648b63..65bca38 100644 --- a/ESCPOS_NET/Emitters/EPSON.cs +++ b/ESCPOS_NET/Emitters/EPSON.cs @@ -1,6 +1,6 @@ namespace ESCPOS_NET.Emitters { - public class EPSON : BaseCommandEmitter + public class EPSON : BaseCommandEmitter { } } diff --git a/ESCPOS_NET/Emitters/Enums/CodePage.cs b/ESCPOS_NET/Emitters/Enums/CodePage.cs index 37ecf2d..0e106e1 100644 --- a/ESCPOS_NET/Emitters/Enums/CodePage.cs +++ b/ESCPOS_NET/Emitters/Enums/CodePage.cs @@ -1,5 +1,6 @@ namespace ESCPOS_NET.Emitters { + [System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.SpacingRules", "SA1025:Code should not contain multiple whitespace in a row", Justification = "Enums are easier to read if they have whitespace alignment.")] public enum CodePage { PC437_USA = 0, diff --git a/ESCPOS_NET/Emitters/ICommandValues.cs b/ESCPOS_NET/Emitters/ICommandValues.cs new file mode 100644 index 0000000..56f8a3c --- /dev/null +++ b/ESCPOS_NET/Emitters/ICommandValues.cs @@ -0,0 +1,72 @@ +namespace ESCPOS_NET.Emitters +{ + public interface ICommandValues + { + /* Barcodes */ + byte PrintBarcode { get; } + byte SetBarcodeHeightInDots { get; } + byte SetBarWidth { get; } + byte SetBarLabelPosition { get; } + byte SetBarLabelFont { get; } + + byte Set2DCode { get; } + byte AutoEnding { get; } + byte[] SetPDF417NumberOfColumns { get; } + byte[] SetPDF417NumberOfRows { get; } + byte[] SetPDF417DotSize { get; } + byte[] SetPDF417CorrectionLevel { get; } + byte[] StorePDF417Data { get; } + byte[] PrintPDF417 { get; } + + byte[] SelectQRCodeModel { get; } + byte[] SetQRCodeDotSize { get; } + byte[] SetQRCodeCorrectionLevel { get; } + byte[] StoreQRCodeData { get; } + byte[] PrintQRCode { get; } + + /* Characters */ + byte StyleMode { get; } + byte Alignment { get; } + byte ReversePrintMode { get; } + byte RightCharacterSpacing { get; } + byte UpsideDownMode { get; } + byte CodePage { get; } + + /* Command */ + byte ESC { get; } + byte GS { get; } + + /* Display */ + byte CLR { get; } + + /* Functions */ + byte PaperCutFullCut { get; } + byte PaperCutFullCutWithFeed { get; } + byte PaperCutPartialCut { get; } + byte PaperCutPartialCutWithFeed { get; } + + /* Images */ + byte ImageCmdParen { get; } + byte ImageCmdLegacy { get; } + byte ImageCmd8 { get; } + byte ImageCmdL { get; } + + /* Operational */ + byte Initialize { get; } + byte EnableDisable { get; } + byte PaperCut { get; } + byte CashDrawerPulse { get; } + + /* Status */ + byte AutomaticStatusBack { get; } + byte AutomaticInkStatusBack { get; } + + /* Whitespace */ + byte Linefeed { get; } + byte FeedLines { get; } + byte FeedLinesReverse { get; } + byte FeedDots { get; } + byte ResetLineSpacing { get; } + byte LineSpacingInDots { get; } + } +} \ No newline at end of file