escpos

package module
v0.0.0-...-c246800 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 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 (
	// ASCII DLE (DataLinkEscape)
	DLE byte = 0x10

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

	// ASCII GS (Group Separator)
	GS byte = 0x1D
)
View Source
const (
	GS8L_MAX_Y = 1662
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Escpos

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

func New

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

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

send cash

func (*Escpos) Cut

func (e *Escpos) Cut()

send cut

func (*Escpos) CutPartial

func (e *Escpos) CutPartial()

send cut minus one point (partial cut)

func (*Escpos) End

func (e *Escpos) End()

end output

func (*Escpos) Feed

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

feed the printer

func (*Escpos) FeedAndCut

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

feed and cut based on parameters

func (*Escpos) Formfeed

func (e *Escpos) Formfeed()

send formfeed

func (*Escpos) FormfeedN

func (e *Escpos) FormfeedN(n int)

send N formfeeds

func (*Escpos) Image

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

write an image

func (*Escpos) Init

func (e *Escpos) Init()

init/reset printer settings

func (*Escpos) Linefeed

func (e *Escpos) Linefeed()

send linefeed

func (*Escpos) Pulse

func (e *Escpos) Pulse()

pulse (open the drawer)

func (*Escpos) Raster

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

func (*Escpos) ReadRaw

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

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

send emphasize / doublestrike

func (*Escpos) SendFontSize

func (e *Escpos) SendFontSize()

func (*Escpos) SendMoveX

func (e *Escpos) SendMoveX(x uint16)

send move x

func (*Escpos) SendMoveY

func (e *Escpos) SendMoveY(y uint16)

send move y

func (*Escpos) SendReverse

func (e *Escpos) SendReverse()

send reverse

func (*Escpos) SendRotate

func (e *Escpos) SendRotate()

send rotate

func (*Escpos) SendSmooth

func (e *Escpos) SendSmooth()

send smooth

func (*Escpos) SendUnderline

func (e *Escpos) SendUnderline()

send underline

func (*Escpos) SendUpsidedown

func (e *Escpos) SendUpsidedown()

send upsidedown

func (*Escpos) SetAlign

func (e *Escpos) SetAlign(align string)

set alignment

func (*Escpos) SetEmphasize

func (e *Escpos) SetEmphasize(u uint8)

set emphasize

func (*Escpos) SetFont

func (e *Escpos) SetFont(font string)

set font

func (*Escpos) SetFontSize

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

set font size

func (*Escpos) SetLang

func (e *Escpos) SetLang(lang string)

set language -- ESC R

func (*Escpos) SetReverse

func (e *Escpos) SetReverse(v uint8)

set reverse

func (*Escpos) SetRotate

func (e *Escpos) SetRotate(v uint8)

set rotate

func (*Escpos) SetSmooth

func (e *Escpos) SetSmooth(v uint8)

set smooth

func (*Escpos) SetTable

func (e *Escpos) SetTable(code int)

set character code table

func (*Escpos) SetUnderline

func (e *Escpos) SetUnderline(v uint8)

set underline

func (*Escpos) SetUpsidedown

func (e *Escpos) SetUpsidedown(v uint8)

set upsidedown

func (*Escpos) Text

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

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)

write a "node" to the printer

func (*Escpos) WriteRaw

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

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