Initial commit

Initial commit til Git.
V2 er deployed
This commit is contained in:
2026-06-13 17:31:50 +02:00
parent 9fcd2b145e
commit 41e23b6184
375 changed files with 15956 additions and 0 deletions

View File

@@ -0,0 +1,16 @@
using ESCPOS_NET.Emitters.BaseCommandValues;
namespace ESCPOS_NET.Emitters
{
public abstract partial class BaseCommandEmitter : ICommandEmitter
{
/* Action Commands */
public virtual byte[] FullCut() => new byte[] { Cmd.GS, Ops.PaperCut, Functions.PaperCutFullCut };
public virtual byte[] PartialCut() => new byte[] { Cmd.GS, Ops.PaperCut, Functions.PaperCutPartialCut };
public virtual byte[] FullCutAfterFeed(int lineCount) => new byte[] { Cmd.GS, Ops.PaperCut, Functions.PaperCutFullCutWithFeed, (byte)lineCount };
public virtual byte[] PartialCutAfterFeed(int lineCount) => new byte[] { Cmd.GS, Ops.PaperCut, Functions.PaperCutPartialCutWithFeed, (byte)lineCount };
}
}

View File

@@ -0,0 +1,115 @@
using ESCPOS_NET.DataValidation;
using ESCPOS_NET.Emitters.BaseCommandValues;
using ESCPOS_NET.Extensions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ESCPOS_NET.Emitters
{
public abstract partial class BaseCommandEmitter : ICommandEmitter
{
/* Barcode Commands */
public virtual byte[] PrintBarcode(BarcodeType type, string barcode, BarcodeCode code = BarcodeCode.CODE_B)
{
DataValidator.ValidateBarcode(type, code, barcode);
return BarcodeBytes(type, barcode, code);
}
protected virtual byte[] BarcodeBytes(BarcodeType type, string barcode, BarcodeCode code)
{
// For CODE128, prepend the first 2 characters as 0x7B and the CODE type, and escape 0x7B characters.
if (type == BarcodeType.CODE128)
{
if (code == BarcodeCode.CODE_C)
{
byte[] b = Encoding.ASCII.GetBytes(barcode);
byte[] ob = new byte[b.Length / 2];
for (int i = 0, obc = 0; i < b.Length; i += 2)
{
ob[obc++] = (byte)(((b[i] - '0') * 10) + (b[i + 1] - '0'));
}
barcode = Encoding.ASCII.GetString(ob);
}
barcode = barcode.Replace("{", "{{");
barcode = $"{(char)0x7B}{(char)code}" + barcode;
}
var command = new List<byte> { Cmd.GS, Barcodes.PrintBarcode, (byte)type, (byte)barcode.Length };
command.AddRange(barcode.ToCharArray().Select(x => (byte)x));
return command.ToArray();
}
public virtual byte[] PrintQRCode(string data, TwoDimensionCodeType type = TwoDimensionCodeType.QRCODE_MODEL2, Size2DCode size = Size2DCode.NORMAL, CorrectionLevel2DCode correction = CorrectionLevel2DCode.PERCENT_7)
{
if (type == TwoDimensionCodeType.PDF417)
{
throw new ArgumentException($"{nameof(TwoDimensionCodeType.PDF417)} is not a valid QRCode type. Please use {nameof(Print2DCode)} method", nameof(type));
}
return Print2DCode(type, data, size, correction);
}
public virtual byte[] Print2DCode(TwoDimensionCodeType type, string data, Size2DCode size = Size2DCode.NORMAL, CorrectionLevel2DCode correction = CorrectionLevel2DCode.PERCENT_7)
{
DataValidator.Validate2DCode(type, data);
return TwoDimensionCodeBytes(type, data, size, correction);
}
protected virtual byte[] TwoDimensionCodeBytes(TwoDimensionCodeType type, string data, Size2DCode size, CorrectionLevel2DCode correction)
{
List<byte> command = new List<byte>();
byte[] initial = { Cmd.GS, Barcodes.Set2DCode, Barcodes.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);
// 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(data.ToCharArray().Select(x => (byte)x));
// Prints stored PDF417
command.AddRange(initial, Barcodes.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);
int num = data.Length + 3;
int pL = num % 256;
int pH = num / 256;
command.AddRange(initial, (byte)pL, (byte)pH, Barcodes.StoreQRCodeData);
command.AddRange(data.ToCharArray().Select(x => (byte)x));
// Prints stored QRCode
command.AddRange(initial, Barcodes.PrintQRCode);
break;
default:
throw new NotImplementedException($"2D Code '{type}' was not implemented yet.");
}
return command.ToArray();
}
public virtual byte[] SetBarcodeHeightInDots(int height) => new byte[] { Cmd.GS, Barcodes.SetBarcodeHeightInDots, (byte)height };
public virtual byte[] SetBarWidth(BarWidth width) => new byte[] { Cmd.GS, Barcodes.SetBarWidth, (byte)width };
public virtual byte[] SetBarLabelPosition(BarLabelPrintPosition position) => new byte[] { Cmd.GS, Barcodes.SetBarLabelPosition, (byte)position };
public virtual byte[] SetBarLabelFontB(bool fontB) => new byte[] { Cmd.GS, Barcodes.SetBarLabelFont, (byte)(fontB ? 1 : 0) };
}
}

View File

@@ -0,0 +1,16 @@
using ESCPOS_NET.Emitters.BaseCommandValues;
namespace ESCPOS_NET.Emitters
{
public abstract partial class BaseCommandEmitter : ICommandEmitter
{
/* Cash Drawer Commands */
public virtual byte[] CashDrawerOpenPin2(int pulseOnTimeMs = 120, int pulseOffTimeMs = 240) {
return new byte[] { Cmd.ESC, Ops.CashDrawerPulse, 0x00, (byte) (pulseOnTimeMs / 2), (byte) (pulseOffTimeMs / 2) };
}
public virtual byte[] CashDrawerOpenPin5(int pulseOnTimeMs = 120, int pulseOffTimeMs = 240) {
return new byte[] { Cmd.ESC, Ops.CashDrawerPulse, 0x01, (byte) (pulseOnTimeMs / 2), (byte) (pulseOffTimeMs / 2) };
}
}
}

View File

@@ -0,0 +1,22 @@
using ESCPOS_NET.Emitters.BaseCommandValues;
namespace ESCPOS_NET.Emitters
{
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[] LeftAlign() => new byte[] { Cmd.ESC, Chars.Alignment, (byte)Align.Left };
public virtual byte[] CenterAlign() => new byte[] { Cmd.ESC, Chars.Alignment, (byte)Align.Center };
public virtual byte[] RightAlign() => new byte[] { Cmd.ESC, Chars.Alignment, (byte)Align.Right };
public virtual byte[] RightCharacterSpacing(int spaceCount) => new byte[] { Cmd.ESC, Chars.RightCharacterSpacing, (byte)spaceCount };
public virtual byte[] CodePage(CodePage codePage) => new byte[] { Cmd.ESC, Chars.CodePage, (byte)codePage };
public virtual byte[] Color(Color color) => new byte[] { Cmd.ESC, Chars.Color, (byte)color };
}
}

View File

@@ -0,0 +1,10 @@
using ESCPOS_NET.Emitters.BaseCommandValues;
namespace ESCPOS_NET.Emitters
{
public abstract partial class BaseCommandEmitter : ICommandEmitter
{
/* Display Commands */
public virtual byte[] Clear() => new byte[] { Display.CLR };
}
}

View File

@@ -0,0 +1,122 @@
using ESCPOS_NET.Emitters.BaseCommandValues;
using ESCPOS_NET.Utilities;
using SixLabors.ImageSharp;
namespace ESCPOS_NET.Emitters
{
public abstract partial class BaseCommandEmitter : ICommandEmitter
{
private byte[] GetImageHeader(int commandLength)
{
byte[] lengths = new byte[4];
int i = 0;
while (commandLength > 0)
{
lengths[i] = (byte)(commandLength & 0xFF);
commandLength >>= 8;
i++;
}
if (i >= 3)
{
return new byte[] { Cmd.GS, Images.ImageCmd8, Images.ImageCmdL, lengths[0], lengths[1], lengths[2], lengths[3] };
}
else
{
return new byte[] { Cmd.GS, Images.ImageCmdParen, Images.ImageCmdL, lengths[0], lengths[1] };
}
}
/* Image Commands */
public virtual byte[] SetImageDensity(bool isHiDPI)
{
ByteArrayBuilder builder = new ByteArrayBuilder();
byte dpiSetting = isHiDPI ? (byte)0x33 : (byte)0x32; // TODO: is this right??
byte[] baseCommand = new byte[] { 0x30, 0x31, dpiSetting, dpiSetting };
builder.Append(GetImageHeader(baseCommand.Length));
builder.Append(baseCommand);
return builder.ToArray();
}
public virtual byte[] BufferImage(byte[] image, int maxWidth = -1, bool isLegacy = false, int color = 1)
{
ByteArrayBuilder imageCommand = new ByteArrayBuilder();
byte colorByte;
switch (color)
{
case 2:
colorByte = 0x32;
break;
case 3:
colorByte = 0x33;
break;
default:
colorByte = 0x31;
break;
}
int width;
int height;
byte[] imageData;
using (var img = Image.Load(image))
{
imageData = img.ToSingleBitPixelByteArray(maxWidth: maxWidth == -1 ? (int?)null : maxWidth);
height = img.Height;
width = img.Width;
}
byte heightL = (byte)height;
byte heightH = (byte)(height >> 8);
if (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 });
}
else
{
byte widthL = (byte)width;
byte widthH = (byte)(width >> 8);
imageCommand.Append(new byte[] { 0x30, 0x70, 0x30, 0x01, 0x01, colorByte, widthL, widthH, heightL, heightH });
}
imageCommand.Append(imageData);
// Load image to print buffer
ByteArrayBuilder response = new ByteArrayBuilder();
byte[] imageCommandBytes = imageCommand.ToArray();
if (!isLegacy)
{
response.Append(GetImageHeader(imageCommandBytes.Length));
}
response.Append(imageCommandBytes);
return response.ToArray();
}
public virtual byte[] WriteImageFromBuffer()
{
// Print image that's already buffered.
ByteArrayBuilder response = new ByteArrayBuilder();
byte[] printCommandBytes = new byte[] { 0x30, 0x32 };
response.Append(GetImageHeader(printCommandBytes.Length));
response.Append(printCommandBytes);
return response.ToArray();
}
public virtual byte[] PrintImage(byte[] image, bool isHiDPI, bool isLegacy = false, int maxWidth = -1, int color = 1)
{
if (isLegacy)
{
return ByteSplicer.Combine(BufferImage(image, maxWidth, isLegacy));
}
else
{
return ByteSplicer.Combine(SetImageDensity(isHiDPI), BufferImage(image, maxWidth, isLegacy, color), WriteImageFromBuffer());
}
}
}
}

View File

@@ -0,0 +1,11 @@
using ESCPOS_NET.Emitters.BaseCommandValues;
namespace ESCPOS_NET.Emitters
{
public abstract partial class BaseCommandEmitter : ICommandEmitter
{
public virtual byte[] ResetLineSpacing() => new byte[] { Cmd.ESC, Whitespace.ResetLineSpacing };
public virtual byte[] SetLineSpacingInDots(int dots) => new byte[] { Cmd.ESC, Whitespace.LineSpacingInDots, (byte)dots };
}
}

View File

@@ -0,0 +1,14 @@
using ESCPOS_NET.Emitters.BaseCommandValues;
namespace ESCPOS_NET.Emitters
{
public abstract partial class BaseCommandEmitter : ICommandEmitter
{
/* Operational Commands */
public virtual byte[] Initialize() => new byte[] { Cmd.ESC, Ops.Initialize };
public virtual byte[] Enable() => new byte[] { Cmd.ESC, Ops.EnableDisable, 1 };
public virtual byte[] Disable() => new byte[] { Cmd.ESC, Ops.EnableDisable, 0 };
}
}

View File

@@ -0,0 +1,39 @@
using System.Linq;
using ESCPOS_NET.Emitters.BaseCommandValues;
namespace ESCPOS_NET.Emitters
{
public abstract partial class BaseCommandEmitter : ICommandEmitter
{
/* Printing Commands */
public virtual byte[] Print(string data)
{
// Fix OSX or Windows-style newlines
data = data.Replace("\r\n", "\n");
data = data.Replace("\r", "\n");
// TODO: Sanitize...
return data.ToCharArray().Select(x => (byte)x).ToArray();
}
public virtual byte[] PrintLine(string line)
{
if (line == null)
{
return Print("\n");
}
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[] FeedLinesReverse(int lineCount) => new byte[] { Cmd.ESC, Whitespace.FeedLinesReverse, (byte)lineCount };
public virtual byte[] FeedDots(int dotCount) => new byte[] { Cmd.ESC, Whitespace.FeedDots, (byte)dotCount };
public virtual byte[] ReverseMode(bool enable) => new byte[] { Cmd.GS, Chars.ReversePrintMode, enable ? (byte)0x01 : (byte)0x00 };
public virtual byte[] UpsideDownMode(bool enable) => new byte[] { Cmd.ESC, Chars.UpsideDownMode, enable ? (byte)0x01 : (byte)0x00 };
}
}

View File

@@ -0,0 +1,18 @@
using ESCPOS_NET.Emitters.BaseCommandValues;
namespace ESCPOS_NET.Emitters
{
public abstract partial class BaseCommandEmitter : ICommandEmitter
{
/* Status Commands */
public virtual byte[] EnableAutomaticStatusBack() => new byte[] { Cmd.GS, Status.AutomaticStatusBack, 0xFF };
public virtual byte[] EnableAutomaticInkStatusBack() => new byte[] { Cmd.GS, Status.AutomaticInkStatusBack, 0xFF };
public virtual byte[] DisableAutomaticStatusBack() => new byte[] { Cmd.GS, Status.AutomaticStatusBack, 0x00 };
public virtual byte[] DisableAutomaticInkStatusBack() => new byte[] { Cmd.GS, Status.AutomaticInkStatusBack, 0x00 };
public virtual byte[] RequestPaperStatus() => new byte[] { Cmd.GS, Status.RequestStatus, 0x31 };
public virtual byte[] RequestDrawerStatus() => new byte[] { Cmd.GS, Status.RequestStatus, 0x32 };
public virtual byte[] RequestInkStatus() => new byte[] { Cmd.GS, Status.RequestStatus, 0x34 };
}
}

View File

@@ -0,0 +1,26 @@
namespace ESCPOS_NET.Emitters.BaseCommandValues
{
public static class Barcodes
{
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 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 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 };
}
}

View File

@@ -0,0 +1,13 @@
namespace ESCPOS_NET.Emitters.BaseCommandValues
{
public static class Chars
{
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 static readonly byte Color = 0x72;
}
}

View File

@@ -0,0 +1,8 @@
namespace ESCPOS_NET.Emitters.BaseCommandValues
{
public static class Cmd
{
public static readonly byte ESC = 0x1B;
public static readonly byte GS = 0x1D;
}
}

View File

@@ -0,0 +1,7 @@
namespace ESCPOS_NET.Emitters.BaseCommandValues
{
public static class Display
{
public static readonly byte CLR = 0x0C;
}
}

View File

@@ -0,0 +1,10 @@
namespace ESCPOS_NET.Emitters.BaseCommandValues
{
public static class Functions
{
public static readonly byte PaperCutFullCut = 0x00;
public static readonly byte PaperCutFullCutWithFeed = 0x41;
public static readonly byte PaperCutPartialCut = 0x01;
public static readonly byte PaperCutPartialCutWithFeed = 0x42;
}
}

View File

@@ -0,0 +1,10 @@
namespace ESCPOS_NET.Emitters.BaseCommandValues
{
public static class Images
{
public static readonly byte ImageCmdParen = 0x28;
public static readonly byte ImageCmdLegacy = 0x76;
public static readonly byte ImageCmd8 = 0x38;
public static readonly byte ImageCmdL = 0x4C;
}
}

View File

@@ -0,0 +1,10 @@
namespace ESCPOS_NET.Emitters.BaseCommandValues
{
public static class Ops
{
public static readonly byte Initialize = 0x40;
public static readonly byte EnableDisable = 0x3D;
public static readonly byte PaperCut = 0x56;
public static readonly byte CashDrawerPulse = 0x70;
}
}

View File

@@ -0,0 +1,9 @@
namespace ESCPOS_NET.Emitters.BaseCommandValues
{
public static class Status
{
public static readonly byte AutomaticStatusBack = 0x61;
public static readonly byte AutomaticInkStatusBack = 0x6A;
public static readonly byte RequestStatus = 0x72;
}
}

View File

@@ -0,0 +1,13 @@
namespace ESCPOS_NET.Emitters.BaseCommandValues
{
public static class Whitespace
{
// 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;
}
}

View File

@@ -0,0 +1,6 @@
namespace ESCPOS_NET.Emitters
{
public class EPSON : BaseCommandEmitter
{
}
}

View File

@@ -0,0 +1,30 @@
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 TwoDimensionCodeType
{
PDF417 = 0,
QRCODE_MODEL1 = 49,
QRCODE_MODEL2 = 50,
QRCODE_MICRO = 51,
}
[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 Size2DCode
{
TINY = 2,
SMALL = 3,
NORMAL = 4,
LARGE = 5,
EXTRA = 6,
}
[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 CorrectionLevel2DCode
{
PERCENT_7 = 48,
PERCENT_15 = 49,
PERCENT_25 = 50,
PERCENT_30 = 51,
}
}

View File

@@ -0,0 +1,10 @@
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 Align
{
Left = 0,
Center = 1,
Right = 2,
}
}

View File

@@ -0,0 +1,11 @@
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 BarLabelPrintPosition
{
None = 0,
Above = 1,
Below = 2,
Both = 3,
}
}

View File

@@ -0,0 +1,12 @@
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 BarWidth
{
Thinnest = 2,
Thin = 3,
Default = 4,
Thick = 5,
Thickest = 6,
}
}

View File

@@ -0,0 +1,9 @@
namespace ESCPOS_NET.Emitters
{
public enum BarcodeCode
{
CODE_A = 0x41,
CODE_B = 0x42,
CODE_C = 0x43,
}
}

View File

@@ -0,0 +1,21 @@
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 BarcodeType // All from Function B
{
UPC_A = 0x41,
UPC_E = 0x42,
JAN13_EAN13 = 0x43,
JAN8_EAN8 = 0x44,
CODE39 = 0x45,
ITF = 0x46,
CODABAR_NW_7 = 0x47,
CODE93 = 0x48,
CODE128 = 0x49,
GS1_128 = 0x4A,
GS1_DATABAR_OMNIDIRECTIONAL = 0x4B,
GS1_DATABAR_TRUNCATED = 0x4C,
GS1_DATABAR_LIMITED = 0x4D,
GS1_DATABAR_EXPANDED = 0x4E,
}
}

View File

@@ -0,0 +1,68 @@
namespace ESCPOS_NET.Emitters
{
#pragma warning disable SA1602 // Enumeration items should be documented
#pragma warning disable SA1600 // Elements should be documented
public enum CodePage
{
PC437_USA_STANDARD_EUROPE_DEFAULT = 0,
KATAKANA = 1,
PC850_MULTILINGUAL = 2,
PC860_PORTUGUESE = 3,
PC863_CANADIAN_FRENCH = 4,
PC865_NORDIC = 5,
HIRAGANA = 6,
ONE_PASS_KANJI = 7,
ONE_PASS_KANJI2 = 8,
PC851_GREEK = 11,
PC853_TURKISH = 12,
PC857_TURKISH = 13,
PC737_GREEK = 14,
ISO8859_7_GREEK = 15,
WPC1252 = 16,
PC866_CYRILLIC2 = 17,
PC852_LATIN2 = 18,
PC858_EURO = 19,
KU42_THAI = 20,
TIS11_THAI = 21,
TIS13_THAI = 22,
TIS14_THAI = 23,
TIS16_THAI = 24,
TIS17_THAI = 25,
TIS18_THAI = 26,
TCVN3_VIETNAMESE_L = 30,
TCVN3_VIETNAMESE_U = 31,
PC720_ARABIC = 32,
WPC775_BALTIC_RIM = 33,
PC855_CYRILLIC = 34,
PC861_ICELANDIC = 35,
PC862_HEBREW = 36,
PC864_ARABIC = 37,
PC869_GREEK = 38,
ISO8859_2_LATIN2 = 39,
ISO8859_15_LATIN9 = 40,
PC1098_FARSI = 41,
PC1118_LITHUANIAN = 42,
PC1119_LITHUANIAN = 43,
PC1125_UKRANIAN = 44,
WPC1250_LATIN2 = 45,
WPC1251_CYRILLIC = 46,
WPC1253_GREEK = 47,
WPC1254_TURKISH = 48,
WPC1255_HEBREW = 49,
WPC1256_ARABIC = 50,
WPC1257_BALTIC_RIM = 51,
WPC1258_VIETNAMESE = 52,
KZ1048_KAZAKHSTAN = 53,
DEVANAGARI = 66,
BENGALI = 67,
TAMIL = 68,
TELUGU = 69,
ASSAMESE = 70,
ORIYA = 71,
KANNADA = 72,
MALAYALAM = 73,
GUJARATI = 74,
PUNJABI = 75,
MARATHI = 82,
}
}

View File

@@ -0,0 +1,12 @@
using System;
namespace ESCPOS_NET.Emitters
{
[Flags]
[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 Color
{
Black = 0,
Red = 1
}
}

View File

@@ -0,0 +1,16 @@
using System;
namespace ESCPOS_NET.Emitters
{
[Flags]
[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 PrintStyle
{
None = 0,
FontB = 1,
Bold = 1 << 3,
DoubleHeight = 1 << 4,
DoubleWidth = 1 << 5,
Underline = 1 << 7,
}
}

View File

@@ -0,0 +1,92 @@
namespace ESCPOS_NET.Emitters
{
public interface ICommandEmitter
{
/* Print Commands */
byte[] PrintLine(string line = null);
byte[] Print(string line);
byte[] FeedLines(int lineCount);
byte[] FeedLinesReverse(int lineCount);
byte[] FeedDots(int dotCount);
/* Line Spacing Commands */
byte[] ResetLineSpacing();
byte[] SetLineSpacingInDots(int dots);
/* Operational Commands */
byte[] Initialize();
byte[] Enable();
byte[] Disable();
/* Cash Drawer Commands */
byte[] CashDrawerOpenPin2(int pulseOnTimeMs = 120, int pulseOffTimeMs = 240);
byte[] CashDrawerOpenPin5(int pulseOnTimeMs = 120, int pulseOffTimeMs = 240);
/* Character Commands */
byte[] SetStyles(PrintStyle style);
byte[] LeftAlign();
byte[] RightAlign();
byte[] CenterAlign();
byte[] ReverseMode(bool activate);
byte[] RightCharacterSpacing(int spaceCount);
byte[] UpsideDownMode(bool activate);
byte[] CodePage(CodePage codePage);
byte[] Color(Color color);
/* Action Commands */
byte[] FullCut();
byte[] PartialCut();
byte[] FullCutAfterFeed(int lineCount);
byte[] PartialCutAfterFeed(int lineCount);
/* Image Commands */
byte[] SetImageDensity(bool isHiDPI);
byte[] BufferImage(byte[] image, int maxWidth, bool isLegacy = false, int color = 1);
byte[] WriteImageFromBuffer();
byte[] PrintImage(byte[] image, bool isHiDPI, bool isLegacy = false, int maxWidth = -1, int color = 1);
/* Status Commands */
byte[] EnableAutomaticStatusBack();
byte[] EnableAutomaticInkStatusBack();
/* Barcode Commands */
byte[] PrintBarcode(BarcodeType type, string barcode, BarcodeCode code = BarcodeCode.CODE_B);
byte[] PrintQRCode(string data, TwoDimensionCodeType type = TwoDimensionCodeType.QRCODE_MODEL2, Size2DCode size = Size2DCode.NORMAL, CorrectionLevel2DCode correction = CorrectionLevel2DCode.PERCENT_7);
byte[] Print2DCode(TwoDimensionCodeType type, string data, Size2DCode size = Size2DCode.NORMAL, CorrectionLevel2DCode correction = CorrectionLevel2DCode.PERCENT_7);
byte[] SetBarcodeHeightInDots(int height);
byte[] SetBarWidth(BarWidth width);
byte[] SetBarLabelPosition(BarLabelPrintPosition position);
byte[] SetBarLabelFontB(bool fontB);
/* 2D-Code Commands */
}
}