tsc

package
v0.0.0-...-d153ec4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 26, 2022 License: BSD-2-Clause Imports: 10 Imported by: 0

Documentation

Overview

Package tsc provides helper functions to work with TSC label printers.

Index

Constants

View Source
const (
	DefaultPort     = 9100
	DefaultReadSize = 1024
	DefaultTimeout  = 250 * time.Millisecond
)
View Source
const CmdStatus = "\x1B!?" // 1

Variables

This section is empty.

Functions

func DiscoverDev

func DiscoverDev() (devs []string, err error)

Discover discovers and returns usb devices paths that pass a status check. For now it only checks /dev/usb/libN on linux machines.

func PrintDuration

func PrintDuration(count, dots, dpi, speed int) time.Duration

PrintDurations estimates the time it takes to print a number of labels

Types

type Conn

type Conn struct {
	Dev     string
	Conn    ReadWriteCloser
	Timeout time.Duration
}

Conn represents a connection to a TSC printer either using a device file or net connection.

func Auto

func Auto(dev string, timeout time.Duration) (c *Conn, err error)

func Dial

func Dial(addr string) (*Conn, error)

Dial opens and returns a network printer connection or returns an error.

func DialTimeout

func DialTimeout(addr string, timeout time.Duration) (*Conn, error)

func Open

func Open(dev string) (*Conn, error)

Open opens the devices file dev and returns a new connection or an error.

func (*Conn) Close

func (p *Conn) Close() error

Close closes the underlying connection

func (*Conn) Recv

func (p *Conn) Recv() ([]byte, error)

Recv receives a message with default read size and returns it or an error.

func (*Conn) RecvN

func (p *Conn) RecvN(readSize int) ([]byte, error)

RecvN receives a message with read size and returns it or an error.

func (*Conn) Req

func (p *Conn) Req(cmd string) ([]byte, error)

Req sends cmd and reads the result

func (*Conn) Send

func (p *Conn) Send(cmd string) error

Send sends a message to the server or returns an error.

func (*Conn) Status

func (p *Conn) Status() (Status, error)

Status requests a printer status message and returns it or an error.

func (*Conn) WaitReady

func (p *Conn) WaitReady(poll time.Duration) error

WaitReady waits until the printer is ready or has a blocking status and sleeps for poll duration.

type NetDiscovery

type NetDiscovery struct {
	Port    int
	Bcast   net.IP
	Timeout time.Duration
	Log     func(error)
}

func NewNetDiscovery

func NewNetDiscovery(timeout time.Duration) *NetDiscovery

func (*NetDiscovery) Run

func (d *NetDiscovery) Run(handler func(NetInfo) bool) error

type NetInfo

type NetInfo struct {
	IP     string
	Mac    string
	Name   string
	Status Status
}

func DiscoverNet

func DiscoverNet(timeout time.Duration) ([]NetInfo, error)

DiscoverNet discovers and returns a list of checked local network device infos or an error.

type ReadWriteCloser

type ReadWriteCloser interface {
	io.Reader
	io.WriteCloser
	SetReadDeadline(t time.Time) error
}

ReadWriteCloser is the abstraction covering both printer device files and net connections.

type Status

type Status uint8
const (
	StatusOpened Status = 1 << iota
	StatusPaperJam
	StatusNoPaper
	StatusNoRibbon
	StatusPaused
	StatusPrinting

	StatusOther
	StatusReady Status = 0
)

func (Status) String

func (s Status) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL