forked from emilevs/label_printer
Dead end, my brain can't handle writing this bridge rn
This commit is contained in:
parent
37fa022a50
commit
d6c4bab52e
3 changed files with 59 additions and 6 deletions
|
@ -21,11 +21,59 @@ import (
|
|||
|
||||
import "C"
|
||||
|
||||
//export printimg
|
||||
func printimg(path *C.char) {
|
||||
fmt.Print(C.GoString(path))
|
||||
var err error
|
||||
|
||||
p, err := escpos.StartUSBPrinter(C.GoString(path), protocol.TMT88IV, escpos.FlagNone)
|
||||
func printer_init(path string, speed int) (*escpos.Printer) {
|
||||
p, err := escpos.StartUSBPrinter(path, protocol.TMT88IV, escpos.FlagNone)
|
||||
if err != nil {
|
||||
log.Fatalf("failed to start printer: %v", err)
|
||||
}
|
||||
|
||||
if err := p.EnableASB(protocol.ASBReportAll); err != nil {
|
||||
p.Close()
|
||||
log.Fatalf("failed to enable ASB: %v", err)
|
||||
}
|
||||
|
||||
go func() {
|
||||
for status := range p.ASBStatus() {
|
||||
log.Printf("received ASB status: %#v\n", status)
|
||||
}
|
||||
}()
|
||||
|
||||
if err := p.SetPrintSpeed(speed); err != nil {
|
||||
log.Fatalf("failed to set print speed: %v\n", err)
|
||||
}
|
||||
|
||||
return p
|
||||
}
|
||||
|
||||
//export cut
|
||||
func cut(path *C.char) {
|
||||
p := printer_init(C.GoString(path), 1)
|
||||
|
||||
if err = p.CutPaper(); err != nil {
|
||||
log.Fatalf("failed to cut paper: %v", err)
|
||||
}
|
||||
|
||||
if err = p.Wait(); err != nil {
|
||||
log.Fatalf("failed to print: %v\n", err)
|
||||
}
|
||||
}
|
||||
|
||||
//export print_text
|
||||
func print_text(path *C.char, str *C.char) {
|
||||
p := printer_init(C.GoString(path), 1)
|
||||
|
||||
fmt.Fprint(p, C.GoString(str))
|
||||
fmt.Fprint(p, "\n")
|
||||
|
||||
if err = p.Wait(); err != nil {
|
||||
log.Fatalf("failed to print: %v\n", err)
|
||||
}
|
||||
}
|
||||
|
||||
func printimg(path *C.char) {
|
||||
p, err := escpos.StartUSBPrinter("/dev/usb/lp0", protocol.TMT88IV, escpos.FlagNone)
|
||||
if err != nil {
|
||||
log.Fatalf("failed to start printer: %v\n", err)
|
||||
}
|
||||
|
|
|
@ -74,7 +74,8 @@ typedef struct { void *data; GoInt len; GoInt cap; } GoSlice;
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern void printimg(char* path);
|
||||
extern void cut(char* path);
|
||||
extern void print_text(char* path, char* str);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
6
test.py
6
test.py
|
@ -2,4 +2,8 @@ import ctypes
|
|||
|
||||
mylib = ctypes.CDLL('./library_bridge.so')
|
||||
|
||||
mylib.printimg("/dev/usb/lp0".encode('utf-8'))
|
||||
mylib.print_text("/dev/usb/lp0".encode('utf-8'), "test\n".encode('utf-8'))
|
||||
mylib.print_text("/dev/usb/lp0".encode('utf-8'), "test\n".encode('utf-8'))
|
||||
mylib.print_text("/dev/usb/lp0".encode('utf-8'), "test\n".encode('utf-8'))
|
||||
|
||||
mylib.cut("/dev/usb/lp0".encode('utf-8'))
|
||||
|
|
Loading…
Reference in a new issue