aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2016-09-24 03:52:12 +0200
committerDimitri Sokolyuk <demon@dim13.org>2016-09-24 03:52:12 +0200
commit13449c468512cd81ec5c05bf77655c22a17b39f0 (patch)
tree3126976a94b5ba9745faab0bab56a04c5877df03
parent09067cfbedb18de674595c56425953afd493c57c (diff)
Device struct
-rw-r--r--dev.go5
-rw-r--r--dev_darwin.go6
-rw-r--r--dev_linux.go10
-rw-r--r--dev_openbsd.go10
4 files changed, 22 insertions, 9 deletions
diff --git a/dev.go b/dev.go
index 000b182..dc1c5b5 100644
--- a/dev.go
+++ b/dev.go
@@ -2,10 +2,15 @@ package robo
import (
"bufio"
+ "io"
"os"
"syscall"
)
+type Device struct {
+ io.ReadWriteCloser
+}
+
// LP represents Line Printer
type LP struct {
*os.File
diff --git a/dev_darwin.go b/dev_darwin.go
index dcf208b..d93f5c4 100644
--- a/dev_darwin.go
+++ b/dev_darwin.go
@@ -8,7 +8,11 @@ import (
)
func Open() (io.ReadWriteCloser, error) {
- return NewUSB()
+ dev, err := NewUSB()
+ if err != nil {
+ return Device{}, err
+ }
+ return Device{dev}, nil
}
type USB struct {
diff --git a/dev_linux.go b/dev_linux.go
index 66cb3f1..dd8a5a3 100644
--- a/dev_linux.go
+++ b/dev_linux.go
@@ -1,7 +1,9 @@
package robo
-import "io"
-
-func Open() (io.ReadWriteCloser, error) {
- return NewLP("/dev/usb/lp0")
+func Open() (Device, error) {
+ dev, err := NewLP("/dev/usb/lp0")
+ if err != nil {
+ return Device{}, nil
+ }
+ return Device{dev}
}
diff --git a/dev_openbsd.go b/dev_openbsd.go
index cb35e8e..edba157 100644
--- a/dev_openbsd.go
+++ b/dev_openbsd.go
@@ -1,8 +1,10 @@
package robo
-import "io"
-
-func Open() (io.ReadWriteCloser, error) {
+func Open() (Device, error) {
// note: ulpt* doesn't support read(), thus this dev is broken atm.
- return NewLP("/dev/ulpt0")
+ dev, err := NewLP("/dev/ulpt0")
+ if err != nil {
+ return Device{}, nil
+ }
+ return Device{dev}
}