mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-08-11 09:13:57 -04:00
Added proper handling of sessions. Thanks to scotty for pointing that out.
This commit is contained in:
parent
487764bcc9
commit
51b5017b43
@ -165,10 +165,14 @@ class PRS500Device(Device):
|
|||||||
try:
|
try:
|
||||||
if not dev.handle:
|
if not dev.handle:
|
||||||
dev.open()
|
dev.open()
|
||||||
|
if not dev.in_session:
|
||||||
|
dev.send_validated_command(BeginEndSession(end=False))
|
||||||
|
dev.in_session = True
|
||||||
res = func(*args, **kwargs)
|
res = func(*args, **kwargs)
|
||||||
except ArgumentError:
|
except ArgumentError:
|
||||||
if not kwargs.has_key("end_session") or kwargs["end_session"]:
|
if not kwargs.has_key("end_session") or kwargs["end_session"]:
|
||||||
dev.send_validated_command(EndSession())
|
dev.send_validated_command(BeginEndSession(end=True))
|
||||||
|
dev.in_session = False
|
||||||
raise
|
raise
|
||||||
except USBError, err:
|
except USBError, err:
|
||||||
if "No such device" in str(err):
|
if "No such device" in str(err):
|
||||||
@ -183,7 +187,8 @@ class PRS500Device(Device):
|
|||||||
dev.close()
|
dev.close()
|
||||||
raise
|
raise
|
||||||
if not kwargs.has_key("end_session") or kwargs["end_session"]:
|
if not kwargs.has_key("end_session") or kwargs["end_session"]:
|
||||||
dev.send_validated_command(EndSession())
|
dev.send_validated_command(BeginEndSession(end=True))
|
||||||
|
dev.in_session = False
|
||||||
return res
|
return res
|
||||||
|
|
||||||
return run_session
|
return run_session
|
||||||
@ -201,6 +206,7 @@ class PRS500Device(Device):
|
|||||||
self.device = get_device_by_id(self.VENDOR_ID, self.PRODUCT_ID)
|
self.device = get_device_by_id(self.VENDOR_ID, self.PRODUCT_ID)
|
||||||
# Handle that is used to communicate with device. Setup in L{open}
|
# Handle that is used to communicate with device. Setup in L{open}
|
||||||
self.handle = None
|
self.handle = None
|
||||||
|
self.in_session = False
|
||||||
self.log_packets = log_packets
|
self.log_packets = log_packets
|
||||||
self.report_progress = report_progress
|
self.report_progress = report_progress
|
||||||
if len(key) > 8:
|
if len(key) > 8:
|
||||||
@ -286,6 +292,7 @@ class PRS500Device(Device):
|
|||||||
except Exception, err:
|
except Exception, err:
|
||||||
print >> sys.stderr, err
|
print >> sys.stderr, err
|
||||||
self.handle, self.device = None, None
|
self.handle, self.device = None, None
|
||||||
|
self.in_session = False
|
||||||
|
|
||||||
def _send_command(self, command, response_type=Response, timeout=1000):
|
def _send_command(self, command, response_type=Response, timeout=1000):
|
||||||
"""
|
"""
|
||||||
|
@ -386,15 +386,15 @@ class DirClose(ShortCommand):
|
|||||||
ShortCommand.__init__(self, number=DirClose.NUMBER, type=0x01,
|
ShortCommand.__init__(self, number=DirClose.NUMBER, type=0x01,
|
||||||
command=_id)
|
command=_id)
|
||||||
|
|
||||||
class EndSession(ShortCommand):
|
class BeginEndSession(ShortCommand):
|
||||||
"""
|
"""
|
||||||
Ask device to change status to 'USB connected' i.e., tell the
|
Ask device to either start or end a session.
|
||||||
device that the present sequence of commands is complete
|
|
||||||
"""
|
"""
|
||||||
NUMBER = 0x1 #: Command number
|
NUMBER = 0x01 #: Command number
|
||||||
def __init__(self):
|
def __init__(self, end=True):
|
||||||
|
command = 0x00 if end else 0x01
|
||||||
ShortCommand.__init__(self, \
|
ShortCommand.__init__(self, \
|
||||||
number=EndSession.NUMBER, type=0x01, command=0x00)
|
number=BeginEndSession.NUMBER, type=0x01, command=command)
|
||||||
|
|
||||||
class GetUSBProtocolVersion(ShortCommand):
|
class GetUSBProtocolVersion(ShortCommand):
|
||||||
""" Get USB Protocol version used by device """
|
""" Get USB Protocol version used by device """
|
||||||
|
Loading…
x
Reference in New Issue
Block a user