escpos

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

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

Go to latest
Published: Feb 17, 2020 License: BSD-3-Clause Imports: 7 Imported by: 0

README

About escpos

This is a Golang package that provides ESC-POS library functions to help with sending control codes to a ESC-POS thermal printer.

Installation

Install the package via the following:

go get -u github.com/seer-robotics/escpos

Usage

The escpos package can be used as the following:

package main

import (
    "bufio"
    "net"

    "github.com/seer-robotics/escpos"
)

func main() {
    socket, err := net.Dial("tcp", "192.168.2.210:9100")
      if err != nil {
      println(err.Error())
    }
    defer socket.Close()

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

    p.Verbose = true

    p.Init()
    p.SetFontSize(2, 3)
    p.SetFont("A")
    p.Write("test1")
    p.SetFont("B")
    p.Write("test2")

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

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

    p.SetReverse(1)
    p.SetFontSize(2, 4)
    p.Write("hello")
    p.FormfeedN(10)

    p.SetAlign("center")
    p.Write("test")
    p.Linefeed()
    p.Write("test")
    p.Linefeed()
    p.Write("test")
    p.FormfeedD(200)

    p.Cut()

    w.Flush()
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Escpos

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

Escpos struct

func New

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

New create a Escpos printer

func (*Escpos) BanFeedButton

func (e *Escpos) BanFeedButton(n uint8)

BanFeedButton 禁止面板按键 \x1Bc5n => ESC c 5 n n= 0, 1(禁止)

func (*Escpos) Beep

func (e *Escpos) Beep(n uint8)

Beep ... \x1BBnt => ESC B n t 蜂鸣器 n 为次数

func (*Escpos) Cut

func (e *Escpos) Cut()

Cut the paper \x1DVA0 => GS V A 0

func (*Escpos) Feed

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

Feed ...

func (*Escpos) FeedAndCut

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

FeedAndCut ...

func (*Escpos) Formfeed

func (e *Escpos) Formfeed()

Formfeed ... 打印并进纸1行

func (*Escpos) FormfeedD

func (e *Escpos) FormfeedD(n uint8)

FormfeedD ... \x1BJn => ESC J n 打印并进纸n*0.125mm 0<=n<=255

func (*Escpos) FormfeedN

func (e *Escpos) FormfeedN(n uint8)

FormfeedN ... \x1Bdn => ESC d n 打印并进纸n行 0<=n<=255

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 printer settings \x1B@ => ESC @ 初始化打印机

func (*Escpos) Linefeed

func (e *Escpos) Linefeed()

Linefeed ... 换行

func (*Escpos) Pulse

func (e *Escpos) Pulse()

Pulse (open the drawer) 发送脉冲,用来打开钱箱

func (*Escpos) SetAlign

func (e *Escpos) SetAlign(align string)

SetAlign ... \x1Ban => ESC a n 选择对齐方式

func (*Escpos) SetEmphasize

func (e *Escpos) SetEmphasize(u uint8)

SetEmphasize ... \x1BGn => ESC E n 设定/解除粗体打印 n = 0, 1

func (*Escpos) SetFont

func (e *Escpos) SetFont(font string)

SetFont ... \x1BMn => ESC M n 选择字型 A(12*24) B(9*17) C(don't know)

func (*Escpos) SetFontSize

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

SetFontSize ... \x1D!n => GS ! n 设定字符大小 高度大于5倍时,打印机会挂掉,不知道为什么

func (*Escpos) SetLineSpace

func (e *Escpos) SetLineSpace(n ...uint8)

SetLineSpace ... \x1B3n => ESC 3 n 行间距n*0.125mm

func (*Escpos) SetMoveX

func (e *Escpos) SetMoveX(x uint16)

SetMoveX ... \x1B$nLnH => ESC $ nL nH x方向绝对定位

func (*Escpos) SetReverse

func (e *Escpos) SetReverse(v uint8)

SetReverse ... GS B n 设定/解除反白打印模式 n = 0, 1

func (*Escpos) SetRotate

func (e *Escpos) SetRotate(v uint8)

SetRotate ... \x1BVn => ESC V n 字符180度旋转

func (*Escpos) SetUnderline

func (e *Escpos) SetUnderline(v uint8)

SetUnderline ... \x1B-n => ESC - n 设定/解除下划线 n = 0(解除), 1(1点粗), 2(2点粗)

func (*Escpos) SetUpsidedown

func (e *Escpos) SetUpsidedown(v uint8)

SetUpsidedown ... \x1B{n => ESC { n 设置/解除颠倒打印模式 n = 0, 1

func (*Escpos) Text

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

Text ...

func (*Escpos) Write

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

Write a string to the printer

func (*Escpos) WriteGBK

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

WriteGBK write a string to the printer with GBK encode

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

func (*Escpos) WriteWEU

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

WriteWEU write a string to the printer with Western European encode

Jump to

Keyboard shortcuts

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