Logo Search packages:      
Sourcecode: calibre version File versions

def calibre::devices::prs500::driver::PRS500::_bulk_write (   self,
  data,
  packet_size = 0x1000 
) [private]

Send data to device via a bulk transfer.
@type data: Any listable type supporting __getslice__
@param packet_size: Size of packets to be sent to device.
C{data} is broken up into packets to be sent to device.

Definition at line 342 of file driver.py.

00342                                                    :
        """
        Send data to device via a bulk transfer.
        @type data: Any listable type supporting __getslice__
        @param packet_size: Size of packets to be sent to device.
        C{data} is broken up into packets to be sent to device.
        """
        def bulk_write_packet(packet):
            self.handle.bulk_write(self.BULK_OUT_EP, packet)
            if self.log_packets:
                self.log_packet(Answer(packet), "Answer h->d")

        bytes_left = len(data)
        if bytes_left + 16 <= packet_size:
            packet_size = bytes_left +16
            first_packet = Answer(bytes_left+16)
            first_packet[16:] = data
            first_packet.length = len(data)
        else:
            first_packet = Answer(packet_size)
            first_packet[16:] = data[0:packet_size-16]
            first_packet.length = packet_size-16
        first_packet.number = 0x10005
        bulk_write_packet(first_packet)
        pos = first_packet.length
        bytes_left -= first_packet.length
        while bytes_left > 0:
            endpos = pos + packet_size if pos + packet_size <= len(data) \
                                       else len(data)
            bulk_write_packet(data[pos:endpos])
            bytes_left -= endpos - pos
            pos = endpos
        res = Response(self.handle.control_msg(0xc0, 0x81, Response.SIZE, \
                        timeout=5000))
        if self.log_packets:
            self.log_packet(res, "Response")
        if res.rnumber != 0x10005 or res.code != 0:
            raise ProtocolError("Sending via Bulk Transfer failed with response:\n"\
                                +str(res))
        if res.data_size != len(data):
            raise ProtocolError("Unable to transfer all data to device. "+\
                                "Response packet:\n"\
                                +str(res))


    def _bulk_read(self, bytes, command_number=0x00, packet_size=0x1000, \


Generated by  Doxygen 1.6.0   Back to index