I have an Epson TM-T88III pos printer on a Linux machine hooked up on a USB port. All is working relative good, It gets recognised, I can open the device, I can echo "Hello World" on the commandline to the printer and it prints without problem.
However in golang when I open the device with os.OpenFile and write some test sequences either as byteslice or string it only prints that sequence after I do another write.
Can somebody explain if I miss something in what I need to do? I am a relative beginner in golang but I do program in other languages.
I open with:
f, err := os.OpenFile("/dev/usb/lppos",os.O_RDWR,0755)
if err != nil {
panic(err)
}
defer f.Close()
Then I define some esc commands and catch them in a byteslice (i use the escpos package of panjjo for that):
p := escposc.New()
p.Init()
p.SetSmooth(1)
p.SetFontSize(2, 3)
p.SetFont("A")
p.Write("test ")
p.SetFont("B")
p.Write("test2 ")
p.Formfeed()
p.SetFont("B")
p.SetFontSize(1, 1)
p.SetEmphasize(1)
p.Write("halle")
p.Formfeed()
p.SetUnderline(1)
p.SetFontSize(4, 4)
p.Write("halle")
p.SetReverse(1)
p.SetFontSize(2, 4)
p.Write("halle")
p.Formfeed()
p.FormfeedN(5)
p.Cut()
_,b:=p.Readbyte()
p.End()
Then I write the catched slice b to the device:
n,err:=f.Write(b)
if err != nil {
panic(err)
}
At this point nothing happens, and it took me a while to find out that if I do a last:
f.WriteString(" ")
Then all sequences get printed as should, with all the styling, linefeeds and cut. And all is well, but not without that last WriteString. Oh yes, It does need the space or other character, writing an empty string does not work.
I also tried to write a string of commands instead of a byteslice, but I need the same 2nd WriteString or it wont output on the paper roll.