pylibftdi Package

pylibftdi Package

pylibftdi - python wrapper for libftdi

Copyright (c) 2010-2013 Ben Bass <benbass@codedstructure.net> See LICENSE file for details and (absence of) warranty

pylibftdi: http://bitbucket.org/codedstructure/pylibftdi

libftdi can be found at:
http://www.intra2net.com/en/developer/libftdi/

Neither libftdi nor Intra2net are associated with this project; if something goes wrong here, it’s almost definitely my fault rather than a problem with the libftdi library.

_base Module

pylibftdi - python wrapper for libftdi

Copyright (c) 2010-2013 Ben Bass <benbass@codedstructure.net> See LICENSE file for details and (absence of) warranty

pylibftdi: http://bitbucket.org/codedstructure/pylibftdi

exception pylibftdi._base.FtdiError[source]

Bases: exceptions.Exception

bitbang Module

pylibftdi - python wrapper for libftdi

Copyright (c) 2010-2013 Ben Bass <benbass@codedstructure.net> See LICENSE file for details and (absence of) warranty

pylibftdi: http://bitbucket.org/codedstructure/pylibftdi

class pylibftdi.bitbang.BitBangDevice(device_id=None, direction=255, lazy_open=False, sync=True, bitbang_mode=1, interface_select=None, **kwargs)[source]

Bases: pylibftdi.driver.Device

simple subclass to support bit-bang mode

Internally uses async mode at the moment, but provides a ‘sync’ flag (defaulting to True) which controls the behaviour of port reading and writing - if set, the FIFOs are ignored (read) or cleared (write) so operations will appear synchronous

Adds two read/write properties to the base class:
direction: 8 bit input(0)/output(1) direction control. port: 8 bit IO port, as defined by direction.
direction[source]

get or set the direction of each of the IO lines. LSB=D0, MSB=D7 1 for output, 0 for input

latch[source]

latch property - the output latch (in-memory representation of output pin state)

Note _latch is not masked by direction (except on initialisation), as otherwise a loop incrementing a mixed input/output port would not work, as it would ‘stop’ on input pins. This is the primary use case for ‘latch’. It’s basically a port which ignores input.

Returns:the state of the output latch
open()[source]

open connection to a FTDI device

port[source]

get or set the state of the IO lines. The value of output lines is persisted in this object for the purposes of reading, so read-modify-write operations (e.g. drv.port+=1) are valid.

read_pins()[source]

read the current ‘actual’ state of the pins

Returns:8-bit binary representation of pin state
Return type:int

driver Module

pylibftdi - python wrapper for libftdi

Copyright (c) 2010-2013 Ben Bass <benbass@codedstructure.net> See LICENSE file for details and (absence of) warranty

pylibftdi: http://bitbucket.org/codedstructure/pylibftdi

class pylibftdi.driver.Device(device_id=None, mode='b', encoding='latin1', lazy_open=False, chunk_size=0, interface_select=None, **kwargs)[source]

Bases: object

Represents a connection to a single FTDI device

baudrate[source]

get or set the baudrate of the FTDI device. Re-read after setting to ensure baudrate was accepted by the driver.

close()[source]

close our connection, free resources

closed[source]

The Python file API defines a read-only ‘closed’ attribute

flush(flush_what=1)[source]

Instruct the FTDI device to flush its FIFO buffers

By default both the input and output buffers will be flushed, but the caller can selectively chose to only flush the input or output buffers using flush_what:

FLUSH_BOTH - (default) FLUSH_INPUT - (just the rx buffer) FLUSH_OUTPUT - (just the tx buffer)
flush_input()[source]

flush the device input buffer

flush_output()[source]

flush the device output buffer

ftdi_fn[source]

this allows the vast majority of libftdi functions which are called with a pointer to a ftdi_context struct as the first parameter to be called here preventing the need to leak self.ctx into the user code (and import byref from ctypes):

>>> with Device() as dev:
...     # set 8 bit data, 2 stop bits, no parity
...     dev.ftdi_fn.ftdi_set_line_property(8, 2, 0)
...
get_error_string()[source]
Returns:error string from libftdi driver
next()
open()[source]

open connection to a FTDI device

read(length) → bytes/string of up to `length` bytes.[source]

read upto length bytes from the FTDI device :param length: maximum number of bytes to read :return: value read from device :rtype: bytes if self.mode is ‘b’, else decode with self.encoding

readline(size=0)[source]

readline() for file-like compatibility.

Parameters:size – maximum amount of data to read looking for a line
Returns:a line of text, or size bytes if no line-ending found

This only works for mode=’t’ on Python3

readlines(sizehint=None)[source]

readlines() for file-like compatibility.

write(data) → count of bytes actually written[source]

write given data string to the FTDI device

Parameters:data (string or bytes) – string to be written
Returns:count of bytes written, which may be less than len(data)
writelines(lines)[source]

writelines for file-like compatibility.

class pylibftdi.driver.Driver(libftdi_search=None)[source]

Bases: object

This is where it all happens... We load the libftdi library, and use it.

libftdi_version()[source]

return the version of the underlying library being used

list_devices()[source]

return a list of triples (manufacturer, description, serial#) for each attached device, e.g.: [(‘FTDI’, ‘UM232R USB <-> Serial’, ‘FTE4FFVQ’),

(‘FTDI’, ‘UM245R’, ‘FTE00P4L’)]

the serial number can be used to open specific devices

class pylibftdi.driver.ftdi_device_list[source]

Bases: _ctypes.Structure

dev

Structure/Union member

next

Structure/Union member

class pylibftdi.driver.ftdi_version_info[source]

Bases: _ctypes.Structure

major

Structure/Union member

micro

Structure/Union member

minor

Structure/Union member

snapshot_str

Structure/Union member

version_str

Structure/Union member

util Module

pylibftdi - python wrapper for libftdi

Copyright (c) 2010-2013 Ben Bass <benbass@codedstructure.net> See LICENSE file for details and (absence of) warranty

pylibftdi: http://bitbucket.org/codedstructure/pylibftdi

pylibftdi.util.Bus[source]

This class is a descriptor for a bus of a given width starting at a given offset (0 = LSB). The device which does the actual reading and writing is assumed to be a BitBangDevice instance in the ‘device’ attribute of the object to which this is attached.

Read the Docs v: 0.13
Versions
latest
0.13
0.12
0.11
Downloads
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.