initial commit
This commit is contained in:
52
Instructions/BarcodeInstruction.cs
Normal file
52
Instructions/BarcodeInstruction.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text.Json.Serialization;
|
||||
using ESCPOS_NET.Emitters;
|
||||
|
||||
public class BarcodeInstruction : BaseInstruction
|
||||
{
|
||||
|
||||
[JsonConverter(typeof(JsonStringEnumConverter))]
|
||||
public BarcodeType barcodeType { get; set; } = BarcodeType.CODE128;
|
||||
|
||||
[DataMember(IsRequired = true)]
|
||||
public string? barcode { get; set; }
|
||||
|
||||
[JsonConverter(typeof(JsonStringEnumConverter))]
|
||||
public BarcodeCode barcodeCode { get; set; } = BarcodeCode.CODE_B;
|
||||
|
||||
[JsonConverter(typeof(JsonStringEnumConverter))]
|
||||
public BarWidth width { get; set; } = BarWidth.Default;
|
||||
|
||||
public int height { get; set; } = 0;
|
||||
|
||||
public override List<byte[]> GetInstructions()
|
||||
{
|
||||
var e = new EPSON();
|
||||
var commands = new List<byte[]>();
|
||||
|
||||
if (width != BarWidth.Default)
|
||||
{
|
||||
commands.Add(e.SetBarWidth(width));
|
||||
|
||||
}
|
||||
|
||||
if (height > 0)
|
||||
{
|
||||
commands.Add(e.SetBarcodeHeightInDots(height));
|
||||
}
|
||||
|
||||
commands.Add(e.PrintBarcode(barcodeType, barcode, barcodeCode));
|
||||
|
||||
if (width != BarWidth.Default)
|
||||
{
|
||||
commands.Add(e.SetBarWidth(BarWidth.Default));
|
||||
}
|
||||
|
||||
if (height > 0)
|
||||
{
|
||||
commands.Add(e.SetBarcodeHeightInDots(0));
|
||||
}
|
||||
|
||||
return commands;
|
||||
}
|
||||
}
|
||||
9
Instructions/BaseInstruction.cs
Normal file
9
Instructions/BaseInstruction.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
public abstract class BaseInstruction
|
||||
{
|
||||
[DataMember(IsRequired = true)]
|
||||
public string? type { get; set; }
|
||||
|
||||
public abstract List<byte[]> GetInstructions();
|
||||
}
|
||||
30
Instructions/PrintInstruction.cs
Normal file
30
Instructions/PrintInstruction.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text.Json.Serialization;
|
||||
using ESCPOS_NET.Emitters;
|
||||
using ESCPOS_NET.Utilities;
|
||||
|
||||
public class PrintInstruction : BaseInstruction
|
||||
{
|
||||
[DataMember(IsRequired = true)]
|
||||
public string? text { get; set; }
|
||||
|
||||
public bool newLine { get; set; } = true;
|
||||
public override List<byte[]> GetInstructions()
|
||||
{
|
||||
var e = new EPSON();
|
||||
var commands = new List<byte[]>();
|
||||
|
||||
if (newLine)
|
||||
{
|
||||
commands.Add(e.PrintLine(text));
|
||||
}
|
||||
else
|
||||
{
|
||||
commands.Add(e.Print(text));
|
||||
}
|
||||
|
||||
return commands;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user