1. Ben Bass
  2. pylibftdi


pylibftdi / doc / how_to.rst

pylibftdi questions

None of these are yet frequently asked, and perhaps they never will be... But they are still questions, and they relate to pylibftdi.

How do I set the baudrate?

In both serial and parallel mode, the internal baudrate generator (BRG) is set using the baudrate property of the Device instance. Reading this will show the current baudrate (which defaults to 9600); writing to it will attempt to set the BRG to that value.

On failure to set the baudrate, it will remain at its previous setting.

In parallel mode, the actual bytes-per-second rate of parallel data is 16x the programmed BRG value. This is an effect of the FTDI devices themselves, and is not hidden by pylibftdi.

How do I send unicode over a serial connection?

If a Device instance is created with mode='t', then text-mode is activated. This is analogous to opening files; after all, the API is intentionally modelled on file objects whereever possible.

When text-mode is used, an encoding can be specified. The default is latin-1 for the very practical reason that it is transparent to 8-bit binary data; by default a text-mode serial connection looks just like a binary mode one.

An alternative encoding can be used provided in the same constructor call used to instantiate the Device class, e.g.:

>>> dev = Device(mode='t', encoding='utf-8')

Read and write operations will then return / take unicode values.

Whether it is sensible to try and send unicode over a ftdi connection is a separate issue... At least consider doing codec operations at a higher level in your application.

How do I run the tests?

Tests aren't included in the distutils distribution, so clone the repository and run from there:

$ hg clone http://bitbucket.org/codedstructure/pylibftdi
<various output stuff>
$ cd pylibftdi
$ python -m unittest discover
Ran 16 tests in 0.025s


How do I use multiple-interface devices?

Some FTDI devices have multiple interfaces, for example the FT2232H has 2 and the FT4232H has four. In terms of accessing them, they can be considered as independent devices; once a connection is established to one of them, it is isolated from the other interfaces.

To select which interface to use when opening a connection to a specific interface on a multiple-interface device, use the interface parameter of the Device (or BitBangDevice) class constructor. The value should be one of the following values:

interface value Meaning
0 Any interface

You should be able to open multiple Devices with different interface settings. Thanks to Daniel Forer for testing multiple device support.