Skip to main content

Printer Class

Package: GHIElectronics.Endpoint.Devices.UsbHost
Namespace: GHIElectronics.Endpoint.Devices.UsbHost

A USB printer: the bytes it understands (ESC/POS for receipt printers, ZPL or EPL for label printers, PCL or PostScript for office printers) go to it as they are.

public class Printer : BaseDevice

Remarks​

Open it with the DeviceName of a Printer from UsbHostController ("/dev/usb/lp0").

Constructors​

Printer(string deviceName)​

public Printer(string deviceName)

Opens the printer that UsbHostController reported ("/dev/usb/lp0").

Properties​

DeviceId​

public string DeviceId { get; }

The printer's IEEE 1284 Device ID: "MFG:EPSON;CMD:ESC/POS;MDL:TM-T20II;CLS:PRINTER;"

Returns string

Status​

public PrinterStatus Status { get; }

Paper out, off line or an error, as the printer reports them (Ready: none).

Returns PrinterStatus

WriteTimeout​

public int WriteTimeout { get; set; }

How long Write waits for the printer to take the data, in milliseconds (Timeout.Infinite: as long as it takes).

Returns int

Methods​

Read(Span<byte> buffer, int timeout)​

public int Read(Span<byte> buffer, int timeout)

Reads what the printer answers (to a status request).

ParameterTypeDescription
bufferSpan<byte>Where the answer goes.
timeoutintHow long to wait, in milliseconds (Timeout.Infinite: as long as it takes).

Returns int: The answer's length, 0 if none came in time.

Write(string text)​

public int Write(string text)

Sends text to the printer, as UTF-8.

Returns int

Write(ReadOnlySpan<byte> data)​

public int Write(ReadOnlySpan<byte> data)

Sends bytes to the printer.

Returns int: The number of bytes sent: all of them.