Package libprs500 :: Module prstypes :: Class TransferBuffer
[hide private]
[frames] | no frames]

Class TransferBuffer

source code


Represents raw (unstructured) data packets sent over the usb bus.

TransferBuffer is a wrapper around the tuples used by PyUSB for communication. It has convenience methods to read and write data from the underlying buffer. See TransferBuffer.pack and TransferBuffer.unpack.

Instance Methods [hide private]
  __init__(self, packet)
Create a TransferBuffer from packet or an empty buffer.
  __add__(self, tb)
Return a TransferBuffer rather than a list as the sum
  __getslice__(self, start, end)
Return a TransferBuffer rather than a list as the slice
  __str__(self)
Return a string representation of this buffer.
  unpack(self, fmt=DWORD, start=0)
Return decoded data from buffer.
  pack(self, val, fmt=DWORD, start=0)
Encode val and write it to buffer.
  _normalize(self)
Replace negative bytes in self by 256 + byte

Inherited from list: __contains__, __delitem__, __delslice__, __eq__, __ge__, __getattribute__, __getitem__, __gt__, __hash__, __iadd__, __imul__, __iter__, __le__, __len__, __lt__, __mul__, __ne__, __new__, __repr__, __reversed__, __rmul__, __setitem__, __setslice__, append, count, extend, index, insert, pop, remove, reverse, sort

Inherited from object: __delattr__, __reduce__, __reduce_ex__, __setattr__


Class Methods [hide private]
  phex(cls, num)
Return the hex representation of num without the 0x prefix.

Properties [hide private]

Inherited from object: __class__


Method Details [hide private]

__init__(self, packet)
(Constructor)

source code 
Create a TransferBuffer from packet or an empty buffer.
Parameters:
  • packet (integer or listable object) - If packet is a list, it is copied into the TransferBuffer and then normalized (see TransferBuffer._normalize). If it is an integer, a zero buffer of that length is created.
Overrides: list.__init__

__add__(self, tb)
(Addition operator)

source code 
Return a TransferBuffer rather than a list as the sum
Overrides: list.__add__

__getslice__(self, start, end)
(Slicling operator)

source code 
Return a TransferBuffer rather than a list as the slice
Overrides: list.__getslice__

__str__(self)
(Informal representation operator)

source code 

Return a string representation of this buffer.

Packets are represented as hex strings, in 2-byte pairs, ≤ 16 bytes to a line. An ASCII representation is included. For example:
   0700 0100 0000 0000 0000 0000 0c00 0000         ................
   0200 0000 0400 0000 4461 7461                   ........Data
Overrides: object.__str__

unpack(self, fmt=DWORD, start=0)

source code 
Return decoded data from buffer.
Parameters:
  • fmt - See struct
  • start - Position in buffer from which to decode

pack(self, val, fmt=DWORD, start=0)

source code 
Encode val and write it to buffer.
Parameters:
  • fmt - See struct
  • start - Position in buffer at which to write encoded data

_normalize(self)

source code 
Replace negative bytes in self by 256 + byte

phex(cls, num)
Class Method

source code 

Return the hex representation of num without the 0x prefix.

If the hex representation is only 1 digit it is padded to the left with a zero. Used in TransferBuffer.__str__.
Decorators: