From a78e2255c43870dad6f0bed5ab582864a08f228e Mon Sep 17 00:00:00 2001 From: David Lamparter Date: Sun, 1 Dec 2013 14:15:35 +0100 Subject: fix some status/timeout bugs --- pttarget.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pttarget.py b/pttarget.py index d8f9eb2..cb4c118 100644 --- a/pttarget.py +++ b/pttarget.py @@ -48,6 +48,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: @@ -74,12 +75,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] @@ -103,7 +106,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) -- cgit v1.2.1