pylibftdi Package¶
pylibftdi
Package¶
pylibftdi - python wrapper for libftdi
Copyright (c) 2010-2014 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-2014 Ben Bass <benbass@codedstructure.net> See LICENSE file for details and (absence of) warranty
device
Module¶
pylibftdi.device - access to individual FTDI devices
Copyright (c) 2010-2014 Ben Bass <benbass@codedstructure.net> See LICENSE file for details and (absence of) warranty
pylibftdi: http://bitbucket.org/codedstructure/pylibftdi
-
class
pylibftdi.device.
Device
(device_id=None, mode='b', encoding='latin1', lazy_open=False, chunk_size=0, interface_select=None, device_index=0, **kwargs)[source]¶ Bases:
object
Represents a connection to a single FTDI device
-
__init__
(device_id=None, mode='b', encoding='latin1', lazy_open=False, chunk_size=0, interface_select=None, device_index=0, **kwargs)[source]¶ Device([device_id[, mode, [OPTIONS ...]]) -> Device instance
represents a single FTDI device accessible via the libftdi driver. Supports a basic file-like interface (open/close/read/write, context manager support).
Parameters: - device_id – an optional serial number of the device to open. if omitted, this refers to the first device found, which is convenient if only one device is attached, but otherwise fairly useless.
- mode – either ‘b’ (binary) or ‘t’ (text). This primarily affects Python 3 calls to read() and write(), which will accept/return unicode strings which will be encoded/decoded according to the given...
- encoding – the codec name to be used for text operations.
- lazy_open – if True, then the device will not be opened immediately - the user must perform an explicit open() call prior to other operations.
- chunk_size – if non-zero, split read and write operations into chunks of this size. With large or slow accesses, interruptions (i.e. KeyboardInterrupt) may not happen in a timely fashion.
- interface_select – select interface to use on multi-interface devices
- device_index – optional index of the device to open, in the event of multiple matches for other parameters (PID, VID, device_id). Defaults to zero (the first device found).
-
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:
Parameters: flush_what – select what to flush: FLUSH_BOTH (default); FLUSH_INPUT (just the rx buffer); FLUSH_OUTPUT (just the tx buffer)
-
next
()¶
-
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
-
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.
Parameters: lines – sequence of lines to write
-
baudrate
¶ get or set the baudrate of the FTDI device. Re-read after setting to ensure baudrate was accepted by the driver.
-
closed
¶ The Python file API defines a read-only ‘closed’ attribute
-
ftdi_fn
¶ 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) ...
-
driver
Module¶
pylibftdi.driver - interface to the libftdi library
Copyright (c) 2010-2014 Ben Bass <benbass@codedstructure.net> See LICENSE file for details and (absence of) warranty
pylibftdi: http://bitbucket.org/codedstructure/pylibftdi
-
class
pylibftdi.driver.
Driver
(libftdi_search=None)[source]¶ Bases:
object
This is where it all happens... We load the libftdi library, and use it.
-
__init__
(libftdi_search=None)[source]¶ Parameters: libftdi_search (string or sequence of strings) – force a particular version of libftdi to be used
-
bitbang
Module¶
pylibftdi - python wrapper for libftdi
Copyright (c) 2010-2014 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.device.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.
-
__init__
(device_id=None, direction=255, lazy_open=False, sync=True, bitbang_mode=1, interface_select=None, **kwargs)[source]¶
-
read_pins
()[source]¶ read the current ‘actual’ state of the pins
Returns: 8-bit binary representation of pin state Return type: int
-
direction
¶ get or set the direction of each of the IO lines. LSB=D0, MSB=D7 1 for output, 0 for input
-
latch
¶ 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
-
port
¶ 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.
serial_device
Module¶
pylibftdi - python wrapper for libftdi
Copyright (c) 2010-2014 Ben Bass <benbass@codedstructure.net> See LICENSE file for details and (absence of) warranty
pylibftdi: http://bitbucket.org/codedstructure/pylibftdi
-
class
pylibftdi.serial_device.
SerialDevice
(device_id=None, mode='b', encoding='latin1', lazy_open=False, chunk_size=0, interface_select=None, device_index=0, **kwargs)[source]¶ Bases:
pylibftdi.device.Device
simple subclass to support serial(rs232) lines
cts, dsr, ri - input dtr, rts - output
Note: These lines are all active-low by default, though this can be changed in the EEPROM settings. pylibftdi does not attempt to hide these settings, and simply writes out the given values (i.e. ‘1’ will typically make an output line ‘active’ - and therefore low)
-
cts
¶ get the state of CTS (1 = ‘active’)
-
dsr
¶ get the state of DSR (1 = ‘active’)
-
dtr
¶ set (or get the previous set) state of the DTR line
Returns: the state of the DTR line; None if not previously set
-
ri
¶ get the state of RI (1 = ‘active’)
-
rts
¶ set (or get the previous set) state of the DTR line
Returns: the state of the RTS line; None if not previously set
-
util
Module¶
pylibftdi - python wrapper for libftdi
Copyright (c) 2010-2014 Ben Bass <benbass@codedstructure.net> See LICENSE file for details and (absence of) warranty
pylibftdi: http://bitbucket.org/codedstructure/pylibftdi
-
class
pylibftdi.util.
Bus
(offset, width=1)[source]¶ Bases:
object
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.