Documentation
¶
Overview ¶
Package tmt88v provides a comprehensive Go library for the Epson TM-T88V (M244A) thermal receipt printer. It supports all ESC/POS commands supported by the TM-T88V, with both a low-level command builder API and a high-level receipt builder API.
Connection ¶
Connect to the printer via USB (/dev/usb/lp0) using FileTransport, or via direct USB bulk transfer using USBTransport (requires libusb-1.0).
Usage ¶
p, err := tmt88v.Open("/dev/usb/lp0")
if err != nil {
log.Fatal(err)
}
defer p.Close()
p.Receipt().
Header("My Shop").
Text("Item 1").
Cut().
Print()
Index ¶
- Variables
- func EvaluateStatus(s Status) (ok bool, reason string)
- func USBPreflightCode(err error) string
- type ErrorCode
- type FileTransport
- type MonitorMode
- type MonitorOption
- type Option
- func WithBufferSize(n int) Option
- func WithDithering(enabled bool) Option
- func WithFileNoSyscallWrite() Option
- func WithFileOpenMode(flags int) Option
- func WithFileSyscallWrite() Option
- func WithFileWriteOnly() Option
- func WithPaperWidth(dots int) Option
- func WithSerial(serial string) Option
- func WithTextEncoding(name string) Option
- func WithUSBConfig(number int) Option
- func WithUSBEndpoints(outAddress, inAddress uint8) Option
- func WithUSBInterface(number, altSetting int) Option
- func WithUSBTransferTimeout(timeout time.Duration) Option
- func WithVIDPID(vid, pid uint16) Option
- type Printer
- func (p *Printer) Close() error
- func (p *Printer) Cut() error
- func (p *Printer) Feed(lines int) error
- func (p *Printer) FeedDots(dots int) error
- func (p *Printer) Flush() error
- func (p *Printer) Init() error
- func (p *Printer) OpenDrawer() error
- func (p *Printer) OpenDrawerPin(pin escpos.DrawerPin) error
- func (p *Printer) PartialCut() error
- func (p *Printer) PrintBarcode(system escpos.BarcodeSystem, data []byte) error
- func (p *Printer) PrintImage(img image.Image) error
- func (p *Printer) PrintImageFromRaster(r imaging.Raster, mode escpos.ImageMode) error
- func (p *Printer) PrintQRCode(data []byte) error
- func (p *Printer) PrintRaster(data []byte, width, height int, mode escpos.ImageMode) error
- func (p *Printer) PrintText(text string) error
- func (p *Printer) PrinterID() (string, error)
- func (p *Printer) Raw(data []byte) error
- func (p *Printer) Receipt() *ReceiptBuilder
- func (p *Printer) SetAlignment(alignment escpos.Alignment) error
- func (p *Printer) SetBold(enabled bool) error
- func (p *Printer) SetCharSize(width, height uint8) error
- func (p *Printer) SetFont(f escpos.Font) error
- func (p *Printer) SetUnderline(mode escpos.Underline) error
- func (p *Printer) Status() (Status, error)
- type PrinterError
- type ReceiptBuilder
- func (rb *ReceiptBuilder) Barcode(system escpos.BarcodeSystem, data string) *ReceiptBuilder
- func (rb *ReceiptBuilder) Bold(text string) *ReceiptBuilder
- func (rb *ReceiptBuilder) Center(text string) *ReceiptBuilder
- func (rb *ReceiptBuilder) Cut() *ReceiptBuilder
- func (rb *ReceiptBuilder) Feed(lines int) *ReceiptBuilder
- func (rb *ReceiptBuilder) Header(text string) *ReceiptBuilder
- func (rb *ReceiptBuilder) Image(img image.Image) *ReceiptBuilder
- func (rb *ReceiptBuilder) LineItem(name string, price string) *ReceiptBuilder
- func (rb *ReceiptBuilder) Print() error
- func (rb *ReceiptBuilder) QRCode(data string) *ReceiptBuilder
- func (rb *ReceiptBuilder) Separator(char string) *ReceiptBuilder
- func (rb *ReceiptBuilder) Text(text string) *ReceiptBuilder
- type Status
- type StatusMonitor
- type Transport
- type USBReadinessResult
- type USBTransport
Constants ¶
This section is empty.
Variables ¶
var (
ErrMonitorAlreadyStarted = errors.New("status monitor already started")
)
Functions ¶
func EvaluateStatus ¶
EvaluateStatus returns ok=true when the printer reports no fault conditions. If ok is false, reason contains a stable machine-readable identifier. PaperNearEnd is treated as a warning only and does not cause ok=false.
func USBPreflightCode ¶
Types ¶
type FileTransport ¶
type FileTransport struct {
// contains filtered or unexported fields
}
FileTransport implements Transport using a file descriptor (e.g., /dev/usb/lp0). It uses buffered writes for efficiency and supports bidirectional communication via the usblp kernel driver.
func OpenFile ¶
func OpenFile(path string, opts ...Option) (*FileTransport, error)
OpenFile opens a file-based transport to the printer device. path is typically "/dev/usb/lp0" for USB-connected printers.
func (*FileTransport) Close ¶
func (t *FileTransport) Close() error
Close flushes and closes the file descriptor.
func (*FileTransport) Flush ¶
func (t *FileTransport) Flush() error
Flush flushes the write buffer to the device.
type MonitorOption ¶
type MonitorOption func(*monitorConfig)
func WithMonitorASBMask ¶
func WithMonitorASBMask(mask byte) MonitorOption
func WithMonitorMode ¶
func WithMonitorMode(mode MonitorMode) MonitorOption
func WithMonitorPollInterval ¶
func WithMonitorPollInterval(interval time.Duration) MonitorOption
type Option ¶
type Option func(*config)
Option is a functional option for configuring the printer or transport.
func WithBufferSize ¶
WithBufferSize sets the write buffer size for FileTransport.
func WithDithering ¶
WithDithering controls whether Floyd-Steinberg dithering is used when converting image.Image to raster data via PrintImage. Default is false (threshold-based conversion).
func WithFileNoSyscallWrite ¶
func WithFileNoSyscallWrite() Option
WithFileNoSyscallWrite disables syscall.Write in FileTransport.
func WithFileOpenMode ¶
WithFileOpenMode sets os.OpenFile flags used by FileTransport. Use os.O_WRONLY for write-only devices like /dev/usb/lp0.
func WithFileSyscallWrite ¶
func WithFileSyscallWrite() Option
WithFileSyscallWrite forces FileTransport to use syscall.Write.
func WithFileWriteOnly ¶
func WithFileWriteOnly() Option
WithFileWriteOnly is a shorthand for WithFileOpenMode(os.O_WRONLY).
func WithPaperWidth ¶
WithPaperWidth sets the maximum paper width in dots used when converting image.Image to raster data via PrintImage. Default is 576 (80mm at 203 dpi).
func WithSerial ¶
WithSerial selects a USB device serial number.
func WithTextEncoding ¶
func WithUSBConfig ¶
WithUSBConfig sets the USB configuration number.
func WithUSBEndpoints ¶
WithUSBEndpoints sets USB endpoint addresses used by USBTransport.
func WithUSBInterface ¶
WithUSBInterface sets the USB interface and alt-setting numbers.
func WithUSBTransferTimeout ¶
WithUSBTransferTimeout sets read/write transfer timeout for USBTransport.
func WithVIDPID ¶
WithVIDPID sets USB vendor/product IDs used by USBTransport.
type Printer ¶
type Printer struct {
// contains filtered or unexported fields
}
func (*Printer) OpenDrawer ¶
func (*Printer) OpenDrawerPin ¶
OpenDrawerPin kicks the cash drawer using the specified pin. Use escpos.DrawerPin2 or escpos.DrawerPin5 to select the connector pin.
func (*Printer) PartialCut ¶
func (*Printer) PrintBarcode ¶
func (p *Printer) PrintBarcode(system escpos.BarcodeSystem, data []byte) error
func (*Printer) PrintImage ¶
PrintImage converts an image.Image to a raster image and prints it. It uses the paper width and dithering settings configured via WithPaperWidth and WithDithering.
func (*Printer) PrintImageFromRaster ¶
func (*Printer) PrintQRCode ¶
func (*Printer) PrintRaster ¶
func (*Printer) Receipt ¶
func (p *Printer) Receipt() *ReceiptBuilder
func (*Printer) SetCharSize ¶
type PrinterError ¶
PrinterError represents an error returned by the printer.
func (*PrinterError) Error ¶
func (e *PrinterError) Error() string
Error implements the error interface.
type ReceiptBuilder ¶
type ReceiptBuilder struct {
// contains filtered or unexported fields
}
func (*ReceiptBuilder) Barcode ¶
func (rb *ReceiptBuilder) Barcode(system escpos.BarcodeSystem, data string) *ReceiptBuilder
func (*ReceiptBuilder) Bold ¶
func (rb *ReceiptBuilder) Bold(text string) *ReceiptBuilder
func (*ReceiptBuilder) Center ¶
func (rb *ReceiptBuilder) Center(text string) *ReceiptBuilder
func (*ReceiptBuilder) Cut ¶
func (rb *ReceiptBuilder) Cut() *ReceiptBuilder
func (*ReceiptBuilder) Feed ¶
func (rb *ReceiptBuilder) Feed(lines int) *ReceiptBuilder
func (*ReceiptBuilder) Header ¶
func (rb *ReceiptBuilder) Header(text string) *ReceiptBuilder
func (*ReceiptBuilder) Image ¶
func (rb *ReceiptBuilder) Image(img image.Image) *ReceiptBuilder
func (*ReceiptBuilder) LineItem ¶
func (rb *ReceiptBuilder) LineItem(name string, price string) *ReceiptBuilder
func (*ReceiptBuilder) Print ¶
func (rb *ReceiptBuilder) Print() error
func (*ReceiptBuilder) QRCode ¶
func (rb *ReceiptBuilder) QRCode(data string) *ReceiptBuilder
func (*ReceiptBuilder) Separator ¶
func (rb *ReceiptBuilder) Separator(char string) *ReceiptBuilder
func (*ReceiptBuilder) Text ¶
func (rb *ReceiptBuilder) Text(text string) *ReceiptBuilder
type Status ¶
type Status struct {
// Printer status (DLE EOT n=1)
Online bool // true if printer is online
DrawerOpen bool // true if cash drawer is open (pin 3 high)
// Offline status (DLE EOT n=2)
CoverOpen bool // true if printer cover is open
PaperFeedButton bool // true if paper feed button is pressed
WaitingForOnline bool // true if waiting to go online
// Error status (DLE EOT n=3)
RecoverableError bool // true if recoverable error occurred
AutocutterError bool // true if autocutter error occurred
UnrecoverableError bool // true if unrecoverable error occurred
AutoRecoverableError bool // true if auto-recoverable error occurred
// Paper sensor status (DLE EOT n=4)
PaperNearEnd bool // true if paper is near end
PaperEnd bool // true if paper is out
}
Status represents the current status of the printer. Fields are populated from DLE EOT status responses.
func ParseErrorStatus ¶
ParseErrorStatus parses the DLE EOT n=3 response byte. Bit layout:
bit 2: recoverable error (1=error) bit 3: autocutter error (1=error) bit 5: unrecoverable error (1=error) bit 6: auto-recoverable error (1=error)
func ParseOfflineStatus ¶
ParseOfflineStatus parses the DLE EOT n=2 response byte. Bit layout:
bit 2: cover open (1=open) bit 3: paper feed button (1=pressed) bit 6: waiting for online (1=waiting)
func ParsePaperStatus ¶
ParsePaperStatus parses the DLE EOT n=4 response byte. Bit layout:
bit 2-3: paper near-end sensor (11=near end) bit 5-6: paper end sensor (11=paper end)
func ParsePrinterStatus ¶
ParsePrinterStatus parses the DLE EOT n=1 response byte. Bit layout per ESC/POS spec:
bit 2: drawer kick-out connector pin 3 (1=high) bit 3: online (0=online, 1=offline)
type StatusMonitor ¶
type StatusMonitor struct {
// contains filtered or unexported fields
}
func NewStatusMonitor ¶
func NewStatusMonitor(t Transport, callback func(Status), opts ...MonitorOption) *StatusMonitor
func (*StatusMonitor) LastStatus ¶
func (m *StatusMonitor) LastStatus() Status
func (*StatusMonitor) Stop ¶
func (m *StatusMonitor) Stop()
type Transport ¶
type Transport interface {
io.ReadWriteCloser
// Flush sends any buffered data to the printer.
Flush() error
}
Transport represents a connection to a printer. It provides bidirectional communication for sending ESC/POS commands and receiving status responses.
type USBReadinessResult ¶
type USBReadinessResult struct {
Ready bool
Code string // canonical preflight code if not ready; empty when Ready=true
}
USBReadinessResult holds the result of a USB readiness probe.
func ProbeUSBReadiness ¶
func ProbeUSBReadiness(opts ...Option) USBReadinessResult
ProbeUSBReadiness attempts to open the USB context and device to check readiness. It returns Ready=true if the device can be opened, or Ready=false with a canonical code from USBPreflightCode if it cannot. Resources are always cleaned up.
type USBTransport ¶
type USBTransport struct {
// contains filtered or unexported fields
}
USBTransport implements Transport using USB bulk endpoints.
func (*USBTransport) Close ¶
func (t *USBTransport) Close() error
Close releases interface, config, device, and context resources.
func (*USBTransport) Flush ¶
func (t *USBTransport) Flush() error
Flush is a no-op for USB bulk transfers.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
tmt88v
command
|
|
|
Package encoding provides character encoding support for the Epson TM-T88V printer.
|
Package encoding provides character encoding support for the Epson TM-T88V printer. |
|
Package escpos provides low-level ESC/POS command building for the Epson TM-T88V printer.
|
Package escpos provides low-level ESC/POS command building for the Epson TM-T88V printer. |
|
examples
|
|
|
barcode
command
|
|
|
basic
command
|
|
|
image
command
|
|
|
receipt
command
|
|
|
status
command
|
|
|
Package imaging provides image processing and printing support for the Epson TM-T88V printer.
|
Package imaging provides image processing and printing support for the Epson TM-T88V printer. |