hoin

package module
v0.0.0-...-5ca0284 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2022 License: MIT Imports: 7 Imported by: 2

README

hoin-printer

Go Report Card Software License GoDoc tests

This is a package for writing to a HOIN POS-80-Series Thermal Printer

Connect to the printer with an io.ReadWriter and then send commands

package main

import (
	"fmt"
	"net"

	"github.com/joeyak/hoin-printer"
)

func main() {

	conn, err := net.Dial("tcp", "192.168.1.23:9100")
	if err != nil {
		fmt.Println("unable to dial:", err)
		return
	}
	defer conn.Close()

	printer := hoin.NewPrinter(conn)

	for i := 0; i < 5; i++ {
		printer.Println("Hello World!")
	}

	printer.FeedLines(5)
	printer.Cut()
}

Documentation

Index

Constants

View Source
const (
	HT  = 0x09
	LF  = 0x0A
	CR  = 0x0D
	GS  = 0x1D
	ESC = 0x1B
	DLE = 0x10
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BarCode

type BarCode int
const (
	BcUPCA BarCode = iota
	BcUPCE
	BcJAN13
	BcJAN8
	BcCODE39
	BcITF
	BcCODABAR
	BcCODE93  BarCode = 72
	BcCODE123 BarCode = 73
)

type Density

type Density int

Density represents the DPI to use when printing images.

const (
	// SingleDensity is 90dpi
	SingleDensity Density = iota
	// DoubleDensity is 180dpi
	DoubleDensity
)

type ErrorStatus

type ErrorStatus struct {
	AutoCutter, UnRecoverable, AutoRecoverable bool
}

type Font

type Font int
const (
	FontA Font = iota
	FontB
)

type HRIPosition

type HRIPosition int
const (
	HRINone HRIPosition = iota
	HRIAbove
	HRIBelow
	HRIBoth
)

type Justification

type Justification int
const (
	LeftJustify Justification = iota
	CenterJustify
	RightJustify
)

type OfflineStatus

type OfflineStatus struct {
	CoverOpen, FeedButton, PrintingStopped, ErrorOccured bool
}

type PaperSensorStatus

type PaperSensorStatus struct {
	NearEnd, RollEnd bool
}

type Printer

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

func NewIpPrinter

func NewIpPrinter(addr string) (Printer, error)

func NewPrinter

func NewPrinter(dst io.ReadWriter) Printer

func (Printer) Beep

func (p Printer) Beep(n, t int) error

Beep makes a beep sound n times for t duration

Duration is dependent on the model. For the HOP-E802 each duration is around 100ms

func (Printer) CR

func (p Printer) CR() error

CR prints and does a carriage return

func (Printer) Close

func (p Printer) Close() error

func (Printer) Cut

func (p Printer) Cut() error

Cut cuts the paper

func (Printer) CutFeed

func (p Printer) CutFeed(n int) error

CutFeed feeds the paper n units and then cuts it

func (Printer) Feed

func (p Printer) Feed(n int) error

Feed feeds the paper n units

func (Printer) FeedLines

func (p Printer) FeedLines(n int) error

FeedLines feeds the paper n lines

func (Printer) HT

func (p Printer) HT() error

HT moves the print position to the next horizontal tab position

By default HT will do nothing if SetHT is not called with tab positions

func (Printer) Initialize

func (p Printer) Initialize() error

func (Printer) Justify

func (p Printer) Justify(j Justification) error

Justify sets the alignment to n

func (Printer) LF

func (p Printer) LF() error

LF prints the data in the print buffer and feeds one line

func (Printer) Morse

func (p Printer) Morse(message string) error

Morse beeps out the message in morse code

func (Printer) MorsePrint

func (p Printer) MorsePrint(message string) error

MorsePrint beeps out the morse message but also prints it to the paper

func (Printer) Print

func (p Printer) Print(a ...any) error

func (Printer) PrintBarCode

func (p Printer) PrintBarCode(barcodeType BarCode, data string) error

PrintBarCode prints the bar code passed in with data.

The size ranges are as follows in (Type: min, max):

BcUPCA: 11, 12
BcUPCE: 6, 7
BcJAN13: 12, 13
BcJAN8: 7, 8
BcCODE39: 0, 14
BcITF: 0, 22
BcCODABAR: 2, 19
BcCODE93: 1, 17
BcCODE123: 0, 65

For the accepted data values:

BcUPCA, BcUPCE, BcJAN13, BcJAN8, BcITF all only accept [0123456789]
BcCODE39, BcCODE93, BcCODE123 can accept [ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-.*$/+% ]
BcCODABAR:
  The first and last character of the CODABAR code bar has to be one of [ABCD]
  and the rest of the characters in between can be one of [0123456789-$:/.+]

Note on the CODE123 length:

...the docs say it's between 2 and 255 but the printer
does not have that limit. On one hand it can go down to 0 character, but also I could
not find the limit for max characters. At 15 characters it went off the page with a
HOP-E802 printer and at 34 characters it starts printing the HRI weird. At 66 0s
repeating it seems to break and stop printing, and the same at 65 As repeating.
Long story short...I think they didn't finish programming the checks on CODE123

func (Printer) PrintImage24

func (p Printer) PrintImage24(img image.Image, density Density) error

PrintImage24 prints an image in the 24-bit row format. In this format each row is 24 dots tall.

This works the same as PrintImage8() with the only difference being the DPI of the printed image. SingleDensity is 90dpi while DoubleDensity is 180dpi. Vertical DPI is always 180dpi for 24-bit image data.

func (Printer) PrintImage8

func (p Printer) PrintImage8(img image.Image, density Density) error

PrintImage8 prints an image in the 8-bit row format. In this format each row is 8 dots tall.

The density selects the horizontal DPI of the image. SingleDensity is 90dpi while DoubleDensity is 180dpi. Vertical DPI is always 60dpi for 8-bit image data.

No black and white conversion is performed on the provided image. The image should be converted before calling this function.

func (Printer) Printf

func (p Printer) Printf(format string, a ...any) error

func (Printer) Println

func (p Printer) Println(a ...any) error

func (Printer) Read

func (p Printer) Read(b []byte) (int, error)

func (Printer) ResetBarCodeHeight

func (p Printer) ResetBarCodeHeight() error

ResetBarCodeHeight sets the bar code height to 162

func (Printer) ResetLineSpacing

func (p Printer) ResetLineSpacing() error

ResetLineSpacing sets the spacing to the default which is 1/6-inch lines (approx. 4.23mm)

func (Printer) SetBarCodeHeight

func (p Printer) SetBarCodeHeight(n int) error

SetBarCodeHeight sets the bar code height in n dots

func (Printer) SetBold

func (p Printer) SetBold(b bool) error

SetBold turns emphasized mode on or off

func (Printer) SetFont

func (p Printer) SetFont(f Font) error

SetFont changes the font

n=0 selects font A n=1 selects font B

func (Printer) SetHRIPosition

func (p Printer) SetHRIPosition(hp HRIPosition) error

SetHRIPosition sets the printing position of the HRI characters in relation to the barcode

func (Printer) SetHT

func (p Printer) SetHT(positions ...int) error

SetHT sets the horizontal tab positions

This command cancels previous SetHT commands Multiple positions can be set for tabbing A max of 32 positions can be set Calling SetHT with no argments resets the tab positions

func (Printer) SetLineSpacing

func (p Printer) SetLineSpacing(n int) error

SetLineSpacing sets the line spacing to n * v/h motion units in inches

func (Printer) SetReversePrinting

func (p Printer) SetReversePrinting(b bool) error

SetReversePrinting sets the white/black printing mode

If b is true then it will print black text on white background If b is false then it will print white text on black background

func (Printer) SetRotate90

func (p Printer) SetRotate90(b bool) error

SetRotate90 turns on 90 clockwise rotation mode for the text

When text is double-width or double-height the text will be mirrored

func (Printer) TransmitErrorStatus

func (p Printer) TransmitErrorStatus() (ErrorStatus, error)

func (Printer) TransmitOfflineStatus

func (p Printer) TransmitOfflineStatus() (OfflineStatus, error)

func (Printer) TransmitPaperSensorStatus

func (p Printer) TransmitPaperSensorStatus() (PaperSensorStatus, error)

func (Printer) TransmitPrinterStatus

func (p Printer) TransmitPrinterStatus() (PrinterStatus, error)

func (Printer) Write

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

type PrinterStatus

type PrinterStatus struct {
	DrawerOpen bool
}

Jump to

Keyboard shortcuts

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