printer-api/Instructions/BarcodeInstruction.cs
2022-02-17 18:29:41 +01:00

47 lines
1.1 KiB
C#

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 Alignment alignment {get; set; } = Alignment.Left;
// [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));
// }
commands.Add(alignmentCommand(alignment));
if (height > 0)
{
commands.Add(e.SetBarcodeHeightInDots(height));
}
commands.Add(e.PrintBarcode(barcodeType, barcode, barcodeCode));
return commands;
}
}