Browse Source

Flush input buffers on printer initialization

Seems to be necessary, not sure why.
master
Přemysl Janouch 1 year ago
parent
commit
412efcb1ae
Signed by: Přemysl Janouch <p@janouch.name> GPG Key ID: A0420B94F92B9493
2 changed files with 13 additions and 13 deletions
  1. +7
    -9
      ql/ql_linux.go
  2. +6
    -4
      sklad/main.go

+ 7
- 9
ql/ql_linux.go View File

@@ -108,16 +108,14 @@ func (p *Printer) Initialize() error {

// Flush any former responses in the printer's queue.
//
// I'm not sure if this is necessary, or rather whether the kernel driver
// does any buffering that could cause data to be returned at this point.
/*
var dummy [32]byte
for {
if _, err := f.Read(dummy[:]); err == io.EOF {
break
}
// I haven't checked if this is the kernel driver or the printer doing
// the buffering that causes data to be returned at this point.
var dummy [32]byte
for {
if _, err := p.File.Read(dummy[:]); err == io.EOF {
break
}
*/
}

return nil
}

+ 6
- 4
sklad/main.go View File

@@ -185,10 +185,12 @@ func printLabel(id string) error {
}
defer printer.Close()

printer.StatusNotify = func(status *ql.Status) {
log.Printf("\x1b[1mreceived status\x1b[m\n%+v\n%s",
status[:], status)
}
/*
printer.StatusNotify = func(status *ql.Status) {
log.Printf("\x1b[1mreceived status\x1b[m\n%+v\n%s",
status[:], status)
}
*/

if err := printer.Initialize(); err != nil {
return err

Loading…
Cancel
Save