summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Lamparter <equinox@diac24.net>2013-12-01 14:15:35 +0100
committerDavid Lamparter <equinox@diac24.net>2013-12-01 14:15:35 +0100
commita78e2255c43870dad6f0bed5ab582864a08f228e (patch)
tree08e1bcffbeacb3ba43d8e6cff92fb61ddb5ad300
parent8c849b650ed534362b107e5ac4d12fdee81908e1 (diff)
fix some status/timeout bugs
-rw-r--r--pttarget.py7
1 files 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)