escpos

package module
v0.0.0-...-75fddf5 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2020 License: MIT Imports: 6 Imported by: 0

README

About escpos

This is a simple Golang 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/knq/escpos

Example epos-server

An example EPOS server implementation is available in the 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/knq/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
  • Update code to be idiomatic Go
  • Fix example server implementation

Documentation

Index

Constants

View Source
const (
	// DLE ASCII DLE (DataLinkEscape)
	DLE byte = 0x10

	// EOT ASCII EOT (EndOfTransmission)
	EOT byte = 0x04

	// GS ASCII GS (Group Separator)
	GS byte = 0x1D
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Escpos

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

Escpos container

func New

func New(dst io.ReadWriter) (e *Escpos)

New create Escpos printer

func (*Escpos) Barcode

func (e *Escpos) Barcode(barcode string, format int)

Barcode sends a barcode to the printer.

func (*Escpos) Cash

func (e *Escpos) Cash()

Cash send cash

func (*Escpos) Cut

func (e *Escpos) Cut()

Cut send cut

func (*Escpos) CutPartial

func (e *Escpos) CutPartial()

CutPartial send cut minus one point (partial cut)

func (*Escpos) End

func (e *Escpos) End()

End end output

func (*Escpos) Feed

func (e *Escpos) Feed(params map[string]string)

Feed feed the printer

func (*Escpos) FeedAndCut

func (e *Escpos) FeedAndCut(params map[string]string)

FeedAndCut feed and cut based on parameters

func (*Escpos) Formfeed

func (e *Escpos) Formfeed()

Formfeed send formfeed

func (*Escpos) FormfeedN

func (e *Escpos) FormfeedN(n int)

FormfeedN send N formfeeds

func (*Escpos) Image

func (e *Escpos) Image(params map[string]string, data string)

Image write an image

func (*Escpos) Init

func (e *Escpos) Init()

Init init/reset printer settings

func (*Escpos) Linefeed

func (e *Escpos) Linefeed()

Linefeed send linefeed

func (*Escpos) Pulse

func (e *Escpos) Pulse()

Pulse pulse (open the drawer)

func (*Escpos) Raster

func (e *Escpos) Raster(width, height, bytesWidth int, imgBw []byte)

Raster rasterize image

func (*Escpos) ReadRaw

func (e *Escpos) ReadRaw(data []byte) (n int, err error)

ReadRaw read raw bytes from printer

func (*Escpos) ReadStatus

func (e *Escpos) ReadStatus(n byte) (byte, error)

ReadStatus Read the status n from the printer

func (*Escpos) SendEmphasize

func (e *Escpos) SendEmphasize()

SendEmphasize send emphasize / doublestrike

func (*Escpos) SendFontSize

func (e *Escpos) SendFontSize()

SendFontSize sent font size

func (*Escpos) SendMoveX

func (e *Escpos) SendMoveX(x uint16)

SendMoveX send move x

func (*Escpos) SendMoveY

func (e *Escpos) SendMoveY(y uint16)

SendMoveY send move y

func (*Escpos) SendReverse

func (e *Escpos) SendReverse()

SendReverse send reverse

func (*Escpos) SendRotate

func (e *Escpos) SendRotate()

SendRotate send rotate

func (*Escpos) SendSmooth

func (e *Escpos) SendSmooth()

SendSmooth send smooth

func (*Escpos) SendUnderline

func (e *Escpos) SendUnderline()

SendUnderline send underline

func (*Escpos) SendUpsidedown

func (e *Escpos) SendUpsidedown()

SendUpsidedown send upsidedown

func (*Escpos) SetAlign

func (e *Escpos) SetAlign(align string)

SetAlign set alignment

func (*Escpos) SetEmphasize

func (e *Escpos) SetEmphasize(u uint8)

SetEmphasize set emphasize

func (*Escpos) SetFont

func (e *Escpos) SetFont(font string)

SetFont set font

func (*Escpos) SetFontSize

func (e *Escpos) SetFontSize(width, height uint8)

SetFontSize set font size

func (*Escpos) SetLang

func (e *Escpos) SetLang(lang string)

SetLang set language -- ESC R

func (*Escpos) SetReverse

func (e *Escpos) SetReverse(v uint8)

SetReverse set reverse

func (*Escpos) SetRotate

func (e *Escpos) SetRotate(v uint8)

SetRotate set rotate

func (*Escpos) SetSmooth

func (e *Escpos) SetSmooth(v uint8)

SetSmooth set smooth

func (*Escpos) SetUnderline

func (e *Escpos) SetUnderline(v uint8)

SetUnderline set underline

func (*Escpos) SetUpsidedown

func (e *Escpos) SetUpsidedown(v uint8)

SetUpsidedown set upsidedown

func (*Escpos) Text

func (e *Escpos) Text(params map[string]string, data string)

Text do a block of text

func (*Escpos) Write

func (e *Escpos) Write(data string) (int, error)

write a string to the printer

func (*Escpos) WriteNode

func (e *Escpos) WriteNode(name string, params map[string]string, data string)

WriteNode write a "node" to the printer

func (*Escpos) WriteRaw

func (e *Escpos) WriteRaw(data []byte) (n int, err error)

WriteRaw write raw bytes to printer

Directories

Path Synopsis
example

Jump to

Keyboard shortcuts

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