TscZebra.Plugin 1.0.4

dotnet add package TscZebra.Plugin --version 1.0.4                
NuGet\Install-Package TscZebra.Plugin -Version 1.0.4                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="TscZebra.Plugin" Version="1.0.4" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add TscZebra.Plugin --version 1.0.4                
#r "nuget: TscZebra.Plugin, 1.0.4"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install TscZebra.Plugin as a Cake Addin
#addin nuget:?package=TscZebra.Plugin&version=1.0.4

// Install TscZebra.Plugin as a Cake Tool
#tool nuget:?package=TscZebra.Plugin&version=1.0.4                

TscZebra.Plugin

This NuGet package simplifies printer connectivity via TCP connection, enabling querying of printer status and sending print commands 🖨️

It exclusively supports ZPL labels for thermal printers 🔥

Support manufactures

Setup printer

This code creates IZplPrinter Instance without connecting

using TscZebra.Plugin;
using TscZebra.Plugin.Abstractions;

IZplPrinter Printer = 
    PrinterFactory.Create(IPAddress.Parse("127.0.0.1"), 9100, PrinterTypes.Tsc);

Connect

try
{
  await Printer.ConnectAsync();
} catch (PrinterConnectionException)
{
  // connection cannot be established
} 

Get status

By polling

This method request printer for status, every interval seconds. Invokes event OnStatusChanged.

Method auto disabled when printer disabled (always when IZplPrinter throws PrinterConnectionException). Use after ConnectAsync method

  Printer.StartStatusPolling(5);
  
  Printer.OnStatusChanged += Receive;

  private void Receive(object? sender, PrinterStatus status)
  {
    // Your logic here
  }
  
  Printer.StopStatusPolling();
  Printer.OnStatusChanged -= Receive;

By hand

This method also invokes event OnStatusChanged

  PrinterStatuses StatusByHand = await Printer.RequestStatusAsync();

Before printing, the printer requests its status and triggers all status events.

  try {
    Printer.PrintZplAsync(string zpl);
  } catch {
      
  }

This method validates the ZPL code for printing. If the ZPL code is not valid, it throws a PrinterCommandBodyException

   public async Task PrintZplAsync(string zpl)
    {
        if (!(zpl.StartsWith("^XA") && zpl.EndsWith("^XZ")))
            throw new PrinterCommandBodyException();
    }

If the printer is successfully connected but cannot print a label (e.g., the head is open), it throws a PrinterStatusException

    public async Task PrintZplAsync(string zpl)
    {
        if (Status is not (PrinterStatuses.Ready or PrinterStatuses.Busy))
            throw new PrinterStatusException();
    }

Disconnect

Printer.Disconnect();

or

Printer.Dispose();

Other Commands

You can find comprehensive documentation for IZplPrinter in the code.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.