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.

class Printer(BaseDevice): ...

Remarks​

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

Constructors​

Printer(string deviceName)​

def __init__(self, deviceName: str):

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

Properties​

DeviceId​

DeviceId: str # @property

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

Returns string

Status​

Status: PrinterStatus # @property

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

Returns PrinterStatus

WriteTimeout​

WriteTimeout: int # @property / @setter

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)​

def Read(self, buffer: Span[int], timeout: int) -> int:

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)​

def Write(self, text: str) -> int:

Sends text to the printer, as UTF-8.

Returns int

Write(ReadOnlySpan<byte> data)​

def Write(self, data: ReadOnlySpan[int]) -> int:

Sends bytes to the printer.

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