escpos

package module
v0.0.0-...-50a50ef Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2018 License: MIT Imports: 14 Imported by: 0

README

About escpos

This is a simple Go package that provides ESC-POS library functions to help with sending control codes to a ESC-POS capable printer such as an Epson TM-T82 or similar.

These printers are often used in retail environments in conjunction with a point-of-sale (POS) system.

Installation

Install the package via the following:

go get -u github.com/kenshaw/escpos

Example epos-server

An example EPOS server implementation is available in the cmd/epos-server subdirectory of this project. This example server is more or less compatible with Epson TM-Intelligent printers and print server implementations.

Usage

The escpos package can be used similarly to the following:

package main

import (
    "bufio"
    "os"

    "github.com/kenshaw/escpos"
)

func main() {
    f, err := os.Open("/dev/usb/lp3")
    if err != nil {
        panic(err)
    }
    defer f.Close()

    w := bufio.NewWriter(f)
    p := escpos.New(w)

    p.Init()
    p.SetSmooth(1)
    p.SetFontSize(2, 3)
    p.SetFont("A")
    p.Write("test ")
    p.SetFont("B")
    p.Write("test2 ")
    p.SetFont("C")
    p.Write("test3 ")
    p.Formfeed()

    p.SetFont("B")
    p.SetFontSize(1, 1)

    p.SetEmphasize(1)
    p.Write("halle")
    p.Formfeed()

    p.SetUnderline(1)
    p.SetFontSize(4, 4)
    p.Write("halle")

    p.SetReverse(1)
    p.SetFontSize(2, 4)
    p.Write("halle")
    p.Formfeed()

    p.SetFont("C")
    p.SetFontSize(8, 8)
    p.Write("halle")
    p.FormfeedN(5)

    p.Cut()
    p.End()

    w.Flush()
}

TODO

  • Fix barcode/image support

Documentation

Index

Constants

View Source
const (
	// DefaultEndpoint is the default server endpoint for ePOS printers.
	DefaultEndpoint = "/cgi-bin/epos/service.cgi"
)

Variables

View Source
var (
	// ErrBodyElementEmpty is the body element empty error.
	ErrBodyElementEmpty = errors.New("Body element empty")
)

Functions

This section is empty.

Types

type Printer

type Printer struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Printer wraps sending ESC-POS commands to a io.Writer.

func NewPrinter

func NewPrinter(w io.Writer) (*Printer, error)

NewPrinter creates a new printer using the specified writer.

func (*Printer) Barcode

func (p *Printer) Barcode(barcode string, format int)

Barcode sends a barcode to the printer.

func (*Printer) Cash

func (p *Printer) Cash()

Cash writes the cash code to the printer.

func (*Printer) Cut

func (p *Printer) Cut()

Cut writes the cut code to the printer.

func (*Printer) End

func (p *Printer) End()

End terminates the printer session.

func (*Printer) Feed

func (p *Printer) Feed(params map[string]string)

Feed feeds the printer, applying the supplied params as necessary.

func (*Printer) FeedAndCut

func (p *Printer) FeedAndCut(params map[string]string)

FeedAndCut feeds the printer using the supplied params and then sends a cut command.

func (*Printer) Formfeed

func (p *Printer) Formfeed()

Formfeed writes 1 formfeed to the printer.

func (*Printer) FormfeedN

func (p *Printer) FormfeedN(n int)

FormfeedN writes N formfeeds to the printer.

func (*Printer) Image

func (p *Printer) Image(params map[string]string, data string)

Image writes an image using the supplied params.

func (*Printer) Init

func (p *Printer) Init()

Init resets the state of the printer, and writes the initialize code.

func (*Printer) Linefeed

func (p *Printer) Linefeed()

Linefeed writes a line end to the printer.

func (*Printer) Pulse

func (p *Printer) Pulse()

Pulse sends the pulse (open drawer) code to the printer.

func (*Printer) Raster

func (p *Printer) Raster(width, height, lineWidth int, imgBw []byte)

Raster writes a rasterized version of a black and white image to the printer with the specified width, height, and lineWidth bytes per line.

func (*Printer) Reset

func (p *Printer) Reset()

Reset resets the printer state.

func (*Printer) SendEmphasize

func (p *Printer) SendEmphasize()

SendEmphasize sends the emphasize / doublestrike command to the printer.

func (*Printer) SendFontSize

func (p *Printer) SendFontSize()

SendFontSize sends the font size command to the printer.

func (*Printer) SendMoveX

func (p *Printer) SendMoveX(x uint16)

SendMoveX sends the move x command to the printer.

func (*Printer) SendMoveY

func (p *Printer) SendMoveY(y uint16)

SendMoveY sends the move y command to the printer.

func (*Printer) SendReverse

func (p *Printer) SendReverse()

SendReverse sends the reverse command to the printer.

func (*Printer) SendRotate

func (p *Printer) SendRotate()

SendRotate sends the rotate command to the printer.

func (*Printer) SendSmooth

func (p *Printer) SendSmooth()

SendSmooth sends the smooth command to the printer.

func (*Printer) SendUnderline

func (p *Printer) SendUnderline()

SendUnderline sends the underline command to the printer.

func (*Printer) SendUpsidedown

func (p *Printer) SendUpsidedown()

SendUpsidedown sends the upsidedown command to the printer.

func (*Printer) SetAlign

func (p *Printer) SetAlign(align string)

SetAlign sets the alignment state and sends it to the printer.

func (*Printer) SetEmphasize

func (p *Printer) SetEmphasize(u byte)

SetEmphasize sets the emphasize state and sends it to the printer.

func (*Printer) SetFont

func (p *Printer) SetFont(font string)

SetFont sets the font on the printer.

func (*Printer) SetFontSize

func (p *Printer) SetFontSize(width, height byte)

SetFontSize sets the font size state and sends the command to the printer.

func (*Printer) SetLang

func (p *Printer) SetLang(lang string)

SetLang sets the language state and sends it to the printer.

func (*Printer) SetReverse

func (p *Printer) SetReverse(v byte)

SetReverse sets the reverse state and sends it to the printer.

func (*Printer) SetRotate

func (p *Printer) SetRotate(v byte)

SetRotate sets the rotate state and sends it to the printer.

func (*Printer) SetSmooth

func (p *Printer) SetSmooth(v byte)

SetSmooth sets the smooth state and sends it to the printer.

func (*Printer) SetUnderline

func (p *Printer) SetUnderline(v byte)

SetUnderline sets the underline state and sends it to the printer.

func (*Printer) SetUpsidedown

func (p *Printer) SetUpsidedown(v byte)

SetUpsidedown sets the upsidedown state and sends it to the printer.

func (*Printer) Text

func (p *Printer) Text(params map[string]string, text string)

Text sends a block of text to the printer using the formatting parameters in params.

func (*Printer) Write

func (p *Printer) Write(buf []byte) (int, error)

Write writes buf to printer.

func (*Printer) WriteNode

func (p *Printer) WriteNode(name string, params map[string]string, data string)

WriteNode writes a node of type name with the supplied params and data to the printer.

func (*Printer) WriteString

func (p *Printer) WriteString(s string) (int, error)

WriteString writes a string to the printer.

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server wrap

func NewServer

func NewServer(w io.Writer, opts ...ServerOption) (*Server, error)

NewServer creates a new ePOS server.

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(res http.ResponseWriter, req *http.Request)

ServeHTTP handles OPTIONS, Origin, and POST for an ePOS server.

type ServerOption

type ServerOption func(*Server) error

ServerOption is a server option.

func WithLog

func WithLog(f func(string, ...interface{})) ServerOption

WithLog is a server option to set a logging func.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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