Logo Search packages:      
Sourcecode: calibre version File versions

def calibre::devices::prs500::driver::PRS500::open (   self  ) 

Claim an interface on the device for communication.
Requires write privileges to the device file.
Also initialize the device.
See the source code for the sequence of initialization commands.

Reimplemented from calibre::devices::interface::DevicePlugin.

Definition at line 239 of file driver.py.

00239                    :
        """
        Claim an interface on the device for communication.
        Requires write privileges to the device file.
        Also initialize the device.
        See the source code for the sequence of initialization commands.
        """
        if not hasattr(self, 'key'):
            self.key = '-1\0\0\0\0\0\0'
        self.device = get_device_by_id(self.VENDOR_ID, self.PRODUCT_ID)
        if not self.device:
            raise DeviceError()
        configs = self.device.configurations
        try:
            self.handle = self.device.open()
            config = configs[0]
            try:
                self.handle.set_configuration(configs[0])
            except USBError:
                self.handle.set_configuration(configs[1])
                config = configs[1]
            _id = config.interface.contents.altsetting.contents
            ed1 = _id.endpoint[0]
            ed2 = _id.endpoint[1]
            if ed1.EndpointAddress == self.BULK_IN_EP:
                red, wed = ed1, ed2
            else:
                red, wed = ed2, ed1
            self.bulk_read_max_packet_size = red.MaxPacketSize
            self.bulk_write_max_packet_size = wed.MaxPacketSize
            self.handle.claim_interface(self.INTERFACE_ID)
        except USBError, err:
            raise DeviceBusy(str(err))
        # Large timeout as device may still be initializing
        res = self.send_validated_command(GetUSBProtocolVersion(), timeout=20000)
        if res.code != 0:
            raise ProtocolError("Unable to get USB Protocol version.")
        version = self._bulk_read(24, data_type=USBProtocolVersion)[0].version
        if version not in KNOWN_USB_PROTOCOL_VERSIONS:
            print >> sys.stderr, "WARNING: Usb protocol version " + \
                                hex(version) + " is unknown"
        res = self.send_validated_command(SetBulkSize(\
                          chunk_size = 512*self.bulk_read_max_packet_size, \
                          unknown = 2))
        if res.code != 0:
            raise ProtocolError("Unable to set bulk size.")
        res = self.send_validated_command(UnlockDevice(key=self.key))#0x312d))
        if res.code != 0:
            raise DeviceLocked()
        res = self.send_validated_command(SetTime())
        if res.code != 0:
            raise ProtocolError("Could not set time on device")

    def eject(self):


Generated by  Doxygen 1.6.0   Back to index