Click or drag to resize

PrinterStatus Class

A class used to obtain the status of a Zebra printer.
Inheritance Hierarchy
SystemObject
  Zebra.Sdk.PrinterPrinterStatus

Namespace:  Zebra.Sdk.Printer
Assembly:  SdkApi.Core (in SdkApi.Core.dll) Version: 2.15.2634
Syntax
public abstract class PrinterStatus

The PrinterStatus type exposes the following members.

Constructors
  NameDescription
Public methodPrinterStatus
Constructs a PrinterStatus instance that can be used to determine the status of a printer.
Top
Methods
  NameDescription
Public methodEquals
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Public methodGetHashCode
Serves as the default hash function.
(Inherited from Object.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Top
Fields
  NameDescription
Public fieldisHeadCold
true if the head is cold. For CPCL printers this is always false
Public fieldisHeadOpen
true if the head is open.
Public fieldisHeadTooHot
true if the head is too hot. For CPCL printers this is always false
Public fieldisPaperOut
true if the paper is out.
Public fieldisPartialFormatInProgress
true if there is a partial format in progress. For CPCL printers this is always false.
Public fieldisPaused
true if the printer is paused. For CPCL printers this is always false
Public fieldisReadyToPrint
true if the printer reports back that it is ready to print
Public fieldisReceiveBufferFull
true if the receive buffer is full. For CPCL printers this is always false
Public fieldisRibbonOut
true if the ribbon is out.
Public fieldlabelLengthInDots
The length of the label in dots. For CPCL printers this is always 0.
Public fieldlabelsRemainingInBatch
The number of labels remaining in the batch. For CPCL printers this is always 0.
Public fieldnumberOfFormatsInReceiveBuffer
The number of formats currently in the receive buffer of the printer. For CPCL printers this is always 0.
Public fieldprintMode
The print mode. For CPCL printers this is always UNKNOWN
Top
Examples
Desktop
using System;
using Zebra.Sdk.Comm;
using Zebra.Sdk.Printer;

public class PrinterStatusExample {

    public static void Main(string[] args) {
        Connection connection = new TcpConnection("192.168.1.100", TcpConnection.DEFAULT_ZPL_TCP_PORT);
        try {
            connection.Open();
            ZebraPrinter printer = ZebraPrinterFactory.GetInstance(connection);

            PrinterStatus printerStatus = printer.GetCurrentStatus();
            if (printerStatus.isReadyToPrint) {
                Console.WriteLine("Ready To Print");
            } else if (printerStatus.isPaused) {
                Console.WriteLine("Cannot Print because the printer is paused.");
            } else if (printerStatus.isHeadOpen) {
                Console.WriteLine("Cannot Print because the printer head is open.");
            } else if (printerStatus.isPaperOut) {
                Console.WriteLine("Cannot Print because the paper is out.");
            } else {
                Console.WriteLine("Cannot Print.");
            }
        } catch (ConnectionException e) {
            Console.WriteLine(e.ToString());
        } catch (ZebraPrinterLanguageUnknownException e) {
            Console.WriteLine(e.ToString());
        } finally {
            connection.Close();
        }
    }
}
Examples
Android™
using Android.App;
using Android.OS;
using Android.Views;
using Android.Widget;
using System;
using System.Threading.Tasks;
using Zebra.Sdk.Comm;
using Zebra.Sdk.Printer;

public class PrinterStatusExample : Activity {

    protected override void OnCreate(Bundle savedInstanceState) {
        base.OnCreate(savedInstanceState);

        LinearLayout layout = (LinearLayout)View.Inflate(this, Android.Resource.Layout.ActivityListItem, null);
        layout.Orientation = Orientation.Vertical;

        Button testButton = new Button(this) {
            Text = "Get Printer Status",
            LayoutParameters = new ViewGroup.LayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent))
        };
        layout.AddView(testButton);

        SetContentView(layout);

        testButton.Click += async (sender, e) => {
            await Task.Run(() => {
                string ipAddress = "1.2.3.4";
                GetPrinterStatus(ipAddress);     
            });
        };
    }

    public void GetPrinterStatus(string ipAddress) {
        Connection connection = new TcpConnection(ipAddress, TcpConnection.DEFAULT_ZPL_TCP_PORT);
        try {
            connection.Open();
            ZebraPrinter printer = ZebraPrinterFactory.GetInstance(connection);

            PrinterStatus printerStatus = printer.GetCurrentStatus();

            string status = "";
            if (printerStatus.isReadyToPrint) {
                status = "Ready To Print";
            } else if (printerStatus.isPaused) {
                status = "Cannot Print because the printer is paused.";
            } else if (printerStatus.isHeadOpen) {
                status = "Cannot Print because the printer head is open.";
            } else if (printerStatus.isPaperOut) {
                status = "Cannot Print because the paper is out.";
            } else {
                status = "Cannot Print.";
            }

            RunOnUiThread(() => {
                Toast.MakeText(ApplicationContext, $"Printer status: {status}", ToastLength.Long).Show();
            });
        } catch (ConnectionException e) {
            Console.WriteLine(e.ToString());
        } catch (ZebraPrinterLanguageUnknownException e) {
            Console.WriteLine(e.ToString());
        } finally {
            connection.Close();
        }
    }
}
Examples
iOS
using CoreGraphics;
using System;
using System.Threading.Tasks;
using UIKit;
using Zebra.Sdk.Comm;
using Zebra.Sdk.Printer;

public class PrinterStatusExample : UIViewController {

    public PrinterStatusExample(IntPtr handle) : base(handle) {
        UIButton testButton = new UIButton(UIButtonType.System) {
            Frame = new CGRect(25, 25, 300, 150)
        };

        testButton.SetTitle("Get Printer Status", UIControlState.Normal);

        testButton.TouchUpInside += async (sender, e) => {
            await Task.Run(() => {
                string ipAddress = "1.2.3.4";
                GetPrinterStatus(ipAddress);
            });
        };

        View.AddSubview(testButton);
    }

    public void GetPrinterStatus(string ipAddress) {
        Connection connection = new TcpConnection(ipAddress, TcpConnection.DEFAULT_ZPL_TCP_PORT);
        try {
            connection.Open();
            ZebraPrinter printer = ZebraPrinterFactory.GetInstance(connection);

            PrinterStatus printerStatus = printer.GetCurrentStatus();

            string status = "";
            if (printerStatus.isReadyToPrint) {
                status = "Ready To Print";
            } else if (printerStatus.isPaused) {
                status = "Cannot Print because the printer is paused.";
            } else if (printerStatus.isHeadOpen) {
                status = "Cannot Print because the printer head is open.";
            } else if (printerStatus.isPaperOut) {
                status = "Cannot Print because the paper is out.";
            } else {
                status = "Cannot Print.";
            }

            ShowAlertMessage("GetPrinterStatus", $"Printer Status: {status}");
        } catch (ConnectionException e) {
            Console.WriteLine(e.ToString());
        } catch (ZebraPrinterLanguageUnknownException e) {
            Console.WriteLine(e.ToString());
        } finally {
            connection.Close();
        }
    }

    private void ShowAlertMessage(string title, string message) {
        InvokeOnMainThread(() => {
            UIAlertController alertController = UIAlertController.Create(title, message, UIAlertControllerStyle.Alert);
            alertController.AddAction(UIAlertAction.Create("OK", UIAlertActionStyle.Default, null));
            PresentViewController(alertController, true, null);
        });
    }
}
See Also