aboutsummaryrefslogtreecommitdiff
path: root/dev.go
blob: d640e5f9fab04f8f54b6330e2c8b7f49eed865d0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package robo

import (
	"bufio"
	"io"
	"os"
	"syscall"
)

const (
	NUL = byte(0x00) // Null
	ETX = byte(0x03) // End of Text
	ESC = byte(0x1B) // Escape
	FS  = byte(0x1C) // File Separator
)

type Device interface {
	io.ReadWriteCloser
	ReadString() (string, error)
	WriteString(string) error
	Command([]byte) error
}

// Open is implemented in according GOOS files

// LP represents Line Printer
type LP struct {
	*os.File
}

func NewLP(path string) (LP, error) {
	f, err := os.OpenFile(path, os.O_RDWR, 0666)
	return LP{f}, err
}

func (d LP) Close() error {
	return d.File.Close()
}

func (d LP) SetNonblock() {
	fd := d.File.Fd()
	syscall.SetNonblock(int(fd), true)
}

func (d LP) Handle() *bufio.ReadWriter {
	r := bufio.NewReader(d.File)
	w := bufio.NewWriter(d.File)
	return bufio.NewReadWriter(r, w)
}