TscZebra.Plugin.Abstractions 1.0.3

There is a newer version of this package available.
See the version list below for details.
dotnet add package TscZebra.Plugin.Abstractions --version 1.0.3                
NuGet\Install-Package TscZebra.Plugin.Abstractions -Version 1.0.3                
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.Abstractions" Version="1.0.3" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add TscZebra.Plugin.Abstractions --version 1.0.3                
#r "nuget: TscZebra.Plugin.Abstractions, 1.0.3"                
#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.Abstractions as a Cake Addin
#addin nuget:?package=TscZebra.Plugin.Abstractions&version=1.0.3

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

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 PrinterStatusChanged.

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

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

  private void Receive(object? sender, PrinterStatuses statuses)
  {
    // Your logic here
  }
  
  Printer.StopStatusPolling();
  Printer.PrinterStatusChanged -= Receive;

By hand

This method also invokes event PrinterStatusChanged

  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.
  • net8.0

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on TscZebra.Plugin.Abstractions:

Package Downloads
TscZebra.Plugin

C# nuget package for zpl printers (Zebra and TSC)

GitHub repositories

This package is not used by any popular GitHub repositories.