Write on thermal printer device in golang
up vote
1
down vote
favorite
I have a thermal printer(ESC/POS) already configured on my linux machine and using the terminal command (as root) I can make it print:
echo "Hello!" > /dev/usb/lp0
However, doing the same procedure in golang nothing happens:
package main
import (
"fmt"
"os"
)
func main()
fmt.Println("Hello Would!")
f, err := os.Open("/dev/usb/lp0")
if err != nil
panic(err)
defer f.Close()
f.Write(byte("Hello world!"))
What am I doing wrong?
linux go thermal-printer
add a comment |
up vote
1
down vote
favorite
I have a thermal printer(ESC/POS) already configured on my linux machine and using the terminal command (as root) I can make it print:
echo "Hello!" > /dev/usb/lp0
However, doing the same procedure in golang nothing happens:
package main
import (
"fmt"
"os"
)
func main()
fmt.Println("Hello Would!")
f, err := os.Open("/dev/usb/lp0")
if err != nil
panic(err)
defer f.Close()
f.Write(byte("Hello world!"))
What am I doing wrong?
linux go thermal-printer
Maybe something like godoc.org/github.com/google/gousb?
– grooveplex
Nov 10 at 0:17
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I have a thermal printer(ESC/POS) already configured on my linux machine and using the terminal command (as root) I can make it print:
echo "Hello!" > /dev/usb/lp0
However, doing the same procedure in golang nothing happens:
package main
import (
"fmt"
"os"
)
func main()
fmt.Println("Hello Would!")
f, err := os.Open("/dev/usb/lp0")
if err != nil
panic(err)
defer f.Close()
f.Write(byte("Hello world!"))
What am I doing wrong?
linux go thermal-printer
I have a thermal printer(ESC/POS) already configured on my linux machine and using the terminal command (as root) I can make it print:
echo "Hello!" > /dev/usb/lp0
However, doing the same procedure in golang nothing happens:
package main
import (
"fmt"
"os"
)
func main()
fmt.Println("Hello Would!")
f, err := os.Open("/dev/usb/lp0")
if err != nil
panic(err)
defer f.Close()
f.Write(byte("Hello world!"))
What am I doing wrong?
linux go thermal-printer
linux go thermal-printer
asked Nov 10 at 0:13
Augusto Pimenta
134
134
Maybe something like godoc.org/github.com/google/gousb?
– grooveplex
Nov 10 at 0:17
add a comment |
Maybe something like godoc.org/github.com/google/gousb?
– grooveplex
Nov 10 at 0:17
Maybe something like godoc.org/github.com/google/gousb?
– grooveplex
Nov 10 at 0:17
Maybe something like godoc.org/github.com/google/gousb?
– grooveplex
Nov 10 at 0:17
add a comment |
1 Answer
1
active
oldest
votes
up vote
8
down vote
accepted
As described in the documentation os.Open()
opens a file read-only.
You would have discovered the problem if you had checked the return from your Write()
call. Always check errors. Don't ignore them, even in tiny programs like this; they will give you a clue as to what is wrong.
To fix the problem, open the device special for writing with os.OpenFile()
.
f, err := os.OpenFile("/dev/usb/lp0", os.O_RDWR, 0)
2
upvote forAlways check errors
:)
– Dmitry Harnitski
Nov 10 at 0:59
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
8
down vote
accepted
As described in the documentation os.Open()
opens a file read-only.
You would have discovered the problem if you had checked the return from your Write()
call. Always check errors. Don't ignore them, even in tiny programs like this; they will give you a clue as to what is wrong.
To fix the problem, open the device special for writing with os.OpenFile()
.
f, err := os.OpenFile("/dev/usb/lp0", os.O_RDWR, 0)
2
upvote forAlways check errors
:)
– Dmitry Harnitski
Nov 10 at 0:59
add a comment |
up vote
8
down vote
accepted
As described in the documentation os.Open()
opens a file read-only.
You would have discovered the problem if you had checked the return from your Write()
call. Always check errors. Don't ignore them, even in tiny programs like this; they will give you a clue as to what is wrong.
To fix the problem, open the device special for writing with os.OpenFile()
.
f, err := os.OpenFile("/dev/usb/lp0", os.O_RDWR, 0)
2
upvote forAlways check errors
:)
– Dmitry Harnitski
Nov 10 at 0:59
add a comment |
up vote
8
down vote
accepted
up vote
8
down vote
accepted
As described in the documentation os.Open()
opens a file read-only.
You would have discovered the problem if you had checked the return from your Write()
call. Always check errors. Don't ignore them, even in tiny programs like this; they will give you a clue as to what is wrong.
To fix the problem, open the device special for writing with os.OpenFile()
.
f, err := os.OpenFile("/dev/usb/lp0", os.O_RDWR, 0)
As described in the documentation os.Open()
opens a file read-only.
You would have discovered the problem if you had checked the return from your Write()
call. Always check errors. Don't ignore them, even in tiny programs like this; they will give you a clue as to what is wrong.
To fix the problem, open the device special for writing with os.OpenFile()
.
f, err := os.OpenFile("/dev/usb/lp0", os.O_RDWR, 0)
answered Nov 10 at 0:50
Michael Hampton
7,15733168
7,15733168
2
upvote forAlways check errors
:)
– Dmitry Harnitski
Nov 10 at 0:59
add a comment |
2
upvote forAlways check errors
:)
– Dmitry Harnitski
Nov 10 at 0:59
2
2
upvote for
Always check errors
:)– Dmitry Harnitski
Nov 10 at 0:59
upvote for
Always check errors
:)– Dmitry Harnitski
Nov 10 at 0:59
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53234875%2fwrite-on-thermal-printer-device-in-golang%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Maybe something like godoc.org/github.com/google/gousb?
– grooveplex
Nov 10 at 0:17