diff options
Diffstat (limited to 'pttarget.py')
-rw-r--r-- | pttarget.py | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/pttarget.py b/pttarget.py index 48c2bee..ff05a1e 100644 --- a/pttarget.py +++ b/pttarget.py @@ -90,6 +90,7 @@ class PTUSB(PTPrinter): self.usbdev.bus, self.usbdev.address) def setup(self): + self.usbdev.default_timeout = 1000 for cfg in self.usbdev: iface = usb.util.find_descriptor(cfg, bInterfaceClass = 7) if iface is not None: @@ -116,12 +117,14 @@ class PTUSB(PTPrinter): self.if_wr.write('\x1biS') ar = array.array('B') start = time.time() - while len(ar) < 32 or time.time() > start + 0.1: + while len(ar) < 32 and time.time() < start + 0.25: ar += self.if_rd.read(16) if len(ar) != 32: raise IOError, 'failed to get status' if ar[0] != 0x80 or ar[1] != 32: raise IOError, 'invalid status (hdr: %02x %02x)' % (ar[0], ar[1]) + else: + ar = data self.err1 = ar[8] self.err2 = ar[9] @@ -139,7 +142,7 @@ class PTUSB(PTPrinter): if len(ar) == 0: return start = time.time() - while len(ar) < 32 or time.time() > start + 0.1: + while len(ar) < 32 and time.time() < start + 0.25: ar += self.if_rd.read(16) self.refresh_status(ar) @@ -202,10 +205,8 @@ class PTUSB(PTPrinter): class PTLabelData(object): def __init__(self): # margins: '\x1bid\x00\x00' + - self.init = '\x1biR\x01' + '\x1biM\x00' + self.init = '\x1biR\x01' + '\x1biM\x40' + '\x1bid\x00\x00' + '\x1biK\x00' self.raw = '' - # self.fini = '\x1a' # Z / feed ? - self.fini = '\x0c' def addpixels(self, raw): row = 'G' + struct.pack('<H', len(raw)) + raw @@ -236,8 +237,9 @@ class PTLabelData(object): pixels[py / 8] |= 1 << (7 - (py & 7)) self.addpixels(pixels) - def get(self): - return self.init + self.raw + self.fini + def get(self, feedncut = True): + fini = '\x1a' if feedncut else '\x0c' + return self.init + self.raw + fini class PTTape(object): tapes = [] |