Package libprs500 :: Module communicate :: Class PRS500Device
[hide private]
[frames] | no frames]

Class PRS500Device

source code


Contains the logic for performing various tasks on the reader.

The implemented tasks are:
  1. Getting information about the device
  2. Getting a file from the device
  3. Listing of directories. See the list method.


Instance Methods [hide private]
  __init__(self, log_packets=False)
  open(self)
Claim an interface on the device for communication.
  close(self)
Release device interface
  _send_command(self, command, response_type=<class 'libprs500.prstypes.Response'>, timeout=100)
Send command to device and return its response.
  _send_validated_command(self, command, cnumber=None, response_type=<class 'libprs500.prstypes.Response'>, timeout=100)
Wrapper around _send_command that checks if the Response.rnumber == cnumber or command.number if cnumber==None.
  _bulk_read_packet(self, data_type=<class 'libprs500.prstypes.Answer'>, size=4096)
Read in a data packet via a Bulk Read.
  _bulk_read(self, bytes, command_number=0x00, packet_size=4096, data_type=<class 'libprs500.prstypes.Answer'>)
Read in bytes bytes via a bulk transfer in packets of size ≤ packet_size
  _test_bulk_reads(self)
Carries out a test of bulk reading as part of session initialization.
  _start_session(self)
Send the initialization sequence to the device.
  _end_session(self)
Send the end session command to the device.
  _run_session(self, *args)
Wrapper that automatically calls _start_session and _end_session.
  _get_device_information(self, args)
Ask device for device information.
  get_device_information(self)
Return (device name, device version, software version on device, mime type).
  _get_path_properties(self, path)
Send command asking device for properties of path.
  get_file(self, path, outfile)
Read the file at path on the device and write it to outfile.
  _get_file(self, args)
Fetch a file from the device and write it to an output stream.
  _list(self, args)
Ask the device to list a path.
  list(self, path, recurse=False)
Return a listing of path.

Inherited from object: __delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __str__


Class Methods [hide private]
  _validate_response(cls, res, type=0x00, number=0x00)
Raise a ProtocolError if the type and number of res is not the same as type and number.

Class Variables [hide private]
  SONY_VENDOR_ID = 1356
SONY Vendor Id
  PRS500_PRODUCT_ID = 667
Product Id for the PRS-500
  PRS500_INTERFACE_ID = 0
The interface we use to talk to the device
  PRS500_BULK_IN_EP = 129
Endpoint for Bulk reads
  PRS500_BULK_OUT_EP = 2
Endpoint for Bulk writes

Properties [hide private]

Inherited from object: __class__


Method Details [hide private]

__init__(self, log_packets=False)
(Constructor)

source code 
Parameters:
  • log_packets - If true the packet stream to/from the device is logged
Overrides: object.__init__

_validate_response(cls, res, type=0x00, number=0x00)
Class Method

source code 
Raise a ProtocolError if the type and number of res is not the same as type and number.
Decorators:

open(self)

source code 
Claim an interface on the device for communication. Requires write privileges to the device file.

To Do: Check this on Mac OSX

close(self)

source code 
Release device interface

_send_command(self, command, response_type=<class 'libprs500.prstypes.Response'>, timeout=100)

source code 
Send command to device and return its response.
Parameters:
  • command - an object of type Command or one of its derived classes
  • response_type - an object of type 'type'. The return packet from the device is returned as an object of type response_type.
  • timeout - the time to wait for a response from the device, in milliseconds. If there is no response, a usb.USBError is raised.

_send_validated_command(self, command, cnumber=None, response_type=<class 'libprs500.prstypes.Response'>, timeout=100)

source code 
Wrapper around _send_command that checks if the Response.rnumber == cnumber or command.number if cnumber==None. Also check that Response.type == Command.type.

_bulk_read_packet(self, data_type=<class 'libprs500.prstypes.Answer'>, size=4096)

source code 
Read in a data packet via a Bulk Read.
Parameters:
  • data_type - an object of type type. The data packet is returned as an object of type data_type.
  • size - the expected size of the data packet.

_bulk_read(self, bytes, command_number=0x00, packet_size=4096, data_type=<class 'libprs500.prstypes.Answer'>)

source code 
Read in bytes bytes via a bulk transfer in packets of size ≤ packet_size

_test_bulk_reads(self)

source code 
Carries out a test of bulk reading as part of session initialization.

_start_session(self)

source code 
Send the initialization sequence to the device. See the code for details. This method should be called before any real work is done. Though most things seem to work without it.

_end_session(self)

source code 
Send the end session command to the device. Causes the device to change status from "Do not disconnect" to "USB Connected"

_run_session(self, *args)

source code 
Wrapper that automatically calls _start_session and _end_session.
Parameters:
  • args - An array whose first element is the method to call and whose remaining arguments are passed to that mathos as an array.

_get_device_information(self, args)

source code 
Ask device for device information. See DeviceInfoQuery.

get_device_information(self)

source code 
Return (device name, device version, software version on device, mime type). See _get_device_information

_get_path_properties(self, path)

source code 
Send command asking device for properties of path. Return (Response, Answer).

get_file(self, path, outfile)

source code 
Read the file at path on the device and write it to outfile. For the logic see _get_file.
Parameters:
  • outfile - file object like sys.stdout or the result of an open call

_get_file(self, args)

source code 

Fetch a file from the device and write it to an output stream.

The data is fetched in chunks of size ≤ 32K. Each chunk is make of packets of size ≤ 4K. See FileOpen, FileRead and FileClose for details on the command packets used.
Parameters:
  • args - path, outfile = arg[0], arg[1]

_list(self, args)

source code 
Ask the device to list a path. See the code for details. See DirOpen, DirRead and DirClose for details on the command packets used.
Parameters:
  • args - path=args[0]
Returns:
A list of tuples. The first element of each tuple is a string, the path. The second is a FileProperties. If the path points to a file, the list will have length 1.

list(self, path, recurse=False)

source code 

Return a listing of path.

See _list for the communication logic.
Parameters:
  • path (string) - The path to list
  • recurse (boolean) - If true do a recursive listing
Returns:
A list of tuples. The first element of each tuple is a path. The second element is a list of Files. The path is the path we are listing, the Files are the files/directories in that path. If it is a recursive list, then the first element will be (path, children), the next will be (child, its children) and so on.

Class Variable Details [hide private]

SONY_VENDOR_ID

SONY Vendor Id
Value:
1356                                                                  
      

PRS500_PRODUCT_ID

Product Id for the PRS-500
Value:
667                                                                   
      

PRS500_INTERFACE_ID

The interface we use to talk to the device
Value:
0                                                                     
      

PRS500_BULK_IN_EP

Endpoint for Bulk reads
Value:
129                                                                   
      

PRS500_BULK_OUT_EP

Endpoint for Bulk writes
Value:
2