GithubHelp home page GithubHelp logo

pyftdi's Introduction

SWUbanner

PyFtdi

Python package Mock tests Syntax tests StandWithUkraine

PyPI Python Versions Downloads

Documentation

PyFtdi documentation is available from https://eblot.github.io/pyftdi/

Overview

PyFtdi aims at providing a user-space driver for popular FTDI devices, implemented in pure Python language.

Suported FTDI devices include:

  • UART and GPIO bridges

    • FT232R (single port, 3Mbps)
    • FT230X/FT231X/FT234X (single port, 3Mbps)
  • UART, GPIO and multi-serial protocols (SPI, I2C, JTAG) bridges

    • FT2232C/D (dual port, clock up to 6 MHz)
    • FT232H (single port, clock up to 30 MHz)
    • FT2232H (dual port, clock up to 30 MHz)
    • FT4232H (quad port, clock up to 30 MHz)
    • FT4232HA (quad port, clock up to 30 MHz)

Features

PyFtdi currently supports the following features:

  • UART/Serial USB converter, up to 12Mbps (depending on the FTDI device capability)
  • GPIO/Bitbang support, with 8-bit asynchronous, 8-bit synchronous and 8-/16-bit MPSSE variants
  • SPI master, with simultanous GPIO support, up to 12 pins per port, with support for non-byte sized transfer
  • I2C master, with simultanous GPIO support, up to 14 pins per port
  • Basic JTAG master capabilities
  • EEPROM support (some parameters cannot yet be modified, only retrieved)
  • Experimental CBUS support on selected devices, 4 pins per port

Supported host OSes

  • macOS
  • Linux
  • FreeBSD
  • Windows, although not officially supported

License

SPDX-License-Identifier: BSD-3-Clause

Warnings

Python support

PyFtdi requires Python 3.8+.

See pyftdi/doc/requirements.rst for more details.

pyftdi's People

Contributors

adamfeuer avatar ajsetter avatar alexforencich avatar anders-code avatar davidwc avatar dgarnier avatar dlharmon avatar eblot avatar hannesweisbach avatar henryay1 avatar jnmacd avatar kalofin avatar len0rd avatar longhairedhacker avatar markmelvin avatar markmentovai avatar newam avatar nopeppermint avatar richey-v avatar rogerhu avatar romavis avatar sgoadhouse avatar tai avatar tapetersen avatar tavip avatar tedkus avatar timlegrand avatar versat avatar vestom avatar vianney avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pyftdi's Issues

Support selection by "USB path" in URL

Currently the URL scheme is protocol://[vendor][:[product][:index|:serial]]/interface. Can you add a way to use the connected USB port (ie the USB path along all hub ports) to select a device? I often have the use case that multiple devices are attached and I'm working with a specific USB port.
USB Path could be: <root hub>-<port>[.<port>[.<port>[...]]]

Not sure is there is a nice way to add the path in the existing scheme:

  • protocol://[<usb-path>@][vendor][:[product][:index|:serial]]/interface
  • protocol://[vendor][:[product][:index|:serial]]/interface[@<usb-path>]

Furthermore, I've noticed that get_identifiers('ftdi:///?') does not list multiple devices if there is no serial (seem these are fake FTDI chip then anyway). There is only one entry for all devices. With the USB path feature from above the devices could be separated.

Axel

Full duplex mode ??

Dear Sir,
Is there any easy work around to get the FTDI ( FT232H in our case ) working in full duplex mode ?
Unfortunately we discovered a bit late that the sensor we want to use is a full duplex device and we started a board.
Seasons Greetings.
Best regards,
DM

index usage with Windows

I've noticed that you changed since a while the way usbtools is collecting usb devices using python "set" in place of "list". Unfortunately in Windows, the same FTDI device is visible through libusb-win32 as multiple devices in particular:
in case of an FTDI device with 2 ports: 3 usb devices are visible (1 with 2 interfaces and 2 with 1 interface)
in case of an FTDI device with 4 ports: 5 usb devices are visible (1 with 4 interfaces and 4 with 1 interface)

unfortunately python "set" are saved with no order so it is not possible once collected in the same set, to distinguish the device that has multiple interfaces while using list the first one in the list (means with index=0) is always the one with multiple interfaces. Could you consider a switch back into the old style list kind of usb device collection a non disruptive proposal?

MPSSE read error in last commit

Hi,
Thank you for the wonderful job you are doing.
I've been using pyftdi version 0.27.1 with the C232HM evaluation board and it has been working great.
Since the recent MPSSE interface commit (a4f6674), I get an ftdi mpsse error (device doesn't support MPSSE) every time I try to connect to the board. When observing the EEPROM descriptor string I see an odd seemingly random string, not matching the actual value.
For now I will keep working with v0.27.1 until fixed.

An unexpected NACK is sent by pyftdi read(), once total read bytes > 96

Hi Emmanuel,

I'm using pyftdi-0.28.8.
I would like to continuously read more than 96 bytes from an I2C slave.
But starting from 97th byte, the read data is all 0xFF.
Look into the waveform, after the 96th byte data is read back, pyftdi sends a NACK to slave.
Could you give me hints by using pyftdi I2C read() API.

My pseudo code is listed below.

    def r32_inc(self):
        buf = [0x00, 0x00, 0x00, 0x00] # write address
        self.port.write(buf)

        val = self.port.read(100) # expect to read 100 bytes
        return val

2018-5-2 12-37-55

usb.core.USBError: [Errno 13] Access denied (insufficient permissions)

Hello,

I have been facing the following error::
....
File "//anaconda/envs/adaptive_module_conda_env/lib/python3.5/site-packages/usb/backend/libusb1.py", line 595, in _check
raise USBError(_strerror(ret), ret, _libusb_errno[ret])
usb.core.USBError: [Errno 13] Access denied (insufficient permissions)

while executing the following command:
-> i2c.configure(url)

When I list the connected device:
i2c.configure('ftdi:///?')

This is what I get as url: ftdi://ftdi:232h:FT2H2BPY/1 (UM232H)

So I use this url as parameter for the configure function.

I am on macOS Sierra (10.12.6).

I am stuck on this, any idea to solve this issue ?

I2C read timing issue with FT2232H

I met a pyftdi I2C problem with FT2232H.

When I use pyftdi I2cPort.read(16), SCL timing interval between each read byte is too short (see below waveform). It makes the read data sometimes right and sometimes wrong.
Is there any way to increase SCL timing interval of each byte?

2018-2-22 09-00-50

Access ACBUS and use it as GPIO?

As I see the GPIO library only handle 8bits of the ADBUS,could it be possible to add ACBUS support in the GPIO part?

I used to use FTDI library from adafruit but that only works with python2,and I'm sure ACBUS is accessible to software interface.

FTDI maximum communication speed

In my setup I communicate via the C232HM FTDI cable with an ADXL345 accelerometer. I ran some tests to compare the communication speed with my former setup (GPIO Header of a RaspberryPi).

I read 20 twenty data sets 1000 times and documented the mean value. One data set contains 7 Bytes (1 to set the register + 6 read bytes). These are the results:

SPI Frequency | Time per data set via GPIO SPI | The per data set via FTDI SPI
4 MHz | 1.47 ms | 4.95 ms
2 MHz | 2.13 ms | 5.80 ms
1 MHz | 2.84 ms | 5.49 ms
0.5 MHz | 4.87 ms | 5.52 ms

It seems that higher SPI speeds do not really affect the measured time via FTDI, so I assume that either the communication between my PC and the FTDI device or the processing through different python libraries is the limiting factor.

Do you have any experience with that? Are there any known speed limits or methods to improve the communication speed via FTDI?
If not, do you believe I could improve it by using the C++ API and D2XX driver which is provided by FTDI?

Thank you very much for your time.

Host send a read cmd to slave, but none data is send from slave

I am using a customized I2C slave device. And I get a strange waveform with the test scenario:

  1. Host (FT2232H) sends a read cmd to slave, I2cController.read(2)
  2. In case slave has "none" data to send except for the ack

Then I will see the waveform as below.
My question is, what will pyftdi deal with SDA for such condition?

2018-2-26 07-04-56

configurable mpsse for jtag

there are several ftdi based jtag probes, like flyswatter2, bus blaster, xds100 and others
even all use same/similar chip, mpsse settings are different.
in pyftdi it is hardcoded. for example openocd has ftdi_layout_init config option for intial state and direction different for almost each ftdi adapter. and ftdi_layout_signal for custom signals

Extra 0xff byte on SPI when using cs other than 0

Hello!
First of all thanks for this great lib.
I'm using it to interface a FPGA via a FTDI4232 SPI on interface 2. It works
great, however if i use CS 1 or 2 i see an extra 8 1 Bits clocked in before CS goes up.
It is not a real problem, because i can just ignore that byte. But i'm wondering
nevertheless...
I've checked the pyftdi.spi code to the limited extend of my capabilities.
This is what i believe it does, when writing:

  • A byte sequence containing the MPSSE codes and the data is assembled
  • The sequence starts with setting SCLK, MOSI and the selected CS to low (line 189)
  • Next comes the data transmission command including data (line 236)
  • If turbo == True and complete == True and silent_clock == False, the sequence finishes with
    -- ftdi.WRITE_BITS_TMS_NVE (line 153)
    -- pulling up all outputs (line 155)

I am wondering wheter line 153 might be a problem. I believe it pulls up the
TMS/CS-pin for eight clock cycles, while still emitting said clock cycles, however
my application does not use the default CS, which would be 0, but another one,
and thus clocks out eight additional bits.


I've commented line 153 and the eight bits are gone.

Support for FT4222H

Does this support FT4222H?

I quickly tried some commands and get the below errors:

openedUSB = ctrl._ftdi.open_from_url('ftdi://ftdi:4222/1')
Traceback (most recent call last):
File "<pyshell#215>", line 1, in
openedUSB = ctrl._ftdi.open_from_url('ftdi://ftdi:4222/1')
File "C:\tools\python\lib\site-packages\pyftdi-0.22.0-py3.4.egg\pyftdi\ftdi.py", line 325, in open_from_url
vendor, product, index, serial, interface = self.get_identifiers(url)
File "C:\tools\python\lib\site-packages\pyftdi-0.22.0-py3.4.egg\pyftdi\ftdi.py", line 290, in get_identifiers
cls.SCHEME, cls.VENDOR_IDS, cls.PRODUCT_IDS, cls.DEFAULT_VENDOR)
File "C:\tools\python\lib\site-packages\pyftdi-0.22.0-py3.4.egg\pyftdi\usbtools.py", line 311, in parse_url
raise UsbToolsError('Product ID 0x%04x not supported' % product)
pyftdi.usbtools.UsbToolsError: Product ID 0x107e not supported

OR ...

ctrl._ftdi.open_mpsse(vendor=0x0403, product=0x601c)
Traceback (most recent call last):
File "<pyshell#200>", line 1, in
ctrl._ftdi.open_mpsse(vendor=0x0403, product=0x601c)
File "C:\tools\python\lib\site-packages\pyftdi-0.22.0-py3.4.egg\pyftdi\ftdi.py", line 364, in open_mpsse
raise FtdiError('This device does not support MPSSE')
pyftdi.ftdi.FtdiError: This device does not support MPSSE

However, I did try below ...

pyftdi.usbtools.UsbTools.get_device(vendor=0x0403, product=0x601c)
<DEVICE ID 0403:601c on Bus 000 Address 002>

(1)
Since I am using this (cool) library for the first time, maybe I am not doing it right. If so, let me know.

(2)
If this lib needs to be updated for FT4222H, since I have the device, I will be glad to contribute; however will need some hints on how to (update).

UsbError: [Errno 13] Access denied (insufficient permissions)

I am trying to interface with the FT232R. I am able to open the device successfully, but if I try to read data from it or write data to it I get this error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pyftdi/ftdi.py", line 685, in read_data
    return self.read_data_bytes(size).tostring()
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pyftdi/ftdi.py", line 674, in read_data_bytes
    raise FtdiError('UsbError: %s' % str(e))
pyftdi.ftdi.FtdiError: UsbError: [Errno 13] Access denied (insufficient permissions)

BITMODE_MASK has wrong value

Hi,

I've noticed today that your Fdti.set_bitmode method does not work for cbus bitbang on a FT230XS.
The root of the problem seem to be a wrong value for Ftdi.BITMODE_MASK, since Ftdi.BITMODE_MASK & Ftdi.BITMODE_CBUS = 0x00, which is unfortunately the same Ftdi.BITMODE_RESET.

I'd suggest using 0x7F as mask instead.

UsbTools.find_all error: 'int' object is not iterable

Hi, I'm trying to find my FT4232H Mini Module eval board with pyftdi from my Windows 10 machine.

From the interactive Python 3 console, I type
import pyftdi
vid=0x0403
pid=0x6011
pyftdi.usbtools.UsbTools.find_all(vid, pid)

To which I receive an error:
[...]
for v, p, in vps:
TypeError: 'int' object is not iterable

Is this a bug?

windows does not honor serial number in url

Attached is a minimal python script that locates all the FTDI FT232R devices on the system and then tries to open one device, with and without a serial number in the URL.

In summary, on a Windows system with two FT232R devices plugged in:

  • With a serial number in the URL, create_from_url() erroneously raises the error No USB device with S/N A932QG17A
  • Without a serial number in the URL, create_from_url() correctly raises the error 2 USB devices match URL

Here is a printout of the the results of the attached python script:

E:\>py -i ftdi-serial-number-test.py
Found the following ports with FT232R parts:
{
  "device": "COM9",
  "name": null,
  "description": "USB Serial Port (COM9)",
  "hwid": "USB VID:PID=0403:6001 SER=A932QG17A",
  "vid": 1027,
  "pid": 24577,
  "serial_number": "A932QG17A",
  "location": null,
  "manufacturer": "FTDI",
  "product": null,
  "interface": null
}
{
  "device": "COM11",
  "name": null,
  "description": "USB Serial Port (COM11)",
  "hwid": "USB VID:PID=0403:6001 SER=FT3BNM1OA",
  "vid": 1027,
  "pid": 24577,
  "serial_number": "FT3BNM1OA",
  "location": null,
  "manufacturer": "FTDI",
  "product": null,
  "interface": null
}
opening device with url =  ftdi://0x403:0x6001:A932QG17A/1
Error: No USB device with S/N A932QG17A
opening device with url =  ftdi://0x403:0x6001/1
Error: 2 USB devices match URL

(Note: the .py script has been renamed with a .txt script so github will accept it as an attachment.)

ftdi-serial-number-test.txt

jtag with olimex arm usb tiny

Hi! Thanks for the lib
I'm trying to use the jtag library with an olimex arm usb tiny, vendor=0x15ba, product=0x0004.
when i call
jtag = JtagEngine(trst=True, frequency=3E6) jtag.configure(vendor=0x15ba, product=0x0004, interface=1)
checking the logic levels with a logic analyzer it seems that come configurations are not correct, also sometimes the program returns seg fault or some errors
Exception ignored in: <bound method JtagController.__del__ of <jtag.JtagController object at 0x7fe9900a07b8>> Traceback (most recent call last): File "/home/riccardo/tesi/JTAG/python/jtag.py", line 195, in __del__ File "/home/riccardo/tesi/JTAG/python/jtag.py", line 208, in close File "/usr/local/lib/python3.5/dist-packages/pyftdi/ftdi.py", line 348, in close File "/usr/local/lib/python3.5/dist-packages/pyftdi/ftdi.py", line 575, in set_latency_timer File "/usr/local/lib/python3.5/dist-packages/pyftdi/ftdi.py", line 914, in _ctrl_transfer_out pyftdi.ftdi.FtdiError: UsbError: [Errno None] Other error
the jtag.py is the same file of the lib but with the configure modified using the non url version for ftdi
def configure(self, vendor, product, interface): """Configure the FTDI interface as a JTAG controller""" self._ftdi.open_mpsse( vendor=vendor, product=product, interface=interface, direction=self.direction, frequency=self._frequency) # FTDI requires to initialize all GPIOs before MPSSE kicks in cmd = Array('B', (Ftdi.SET_BITS_LOW, 0x0, self.direction)) self._ftdi.write_data(cmd)

Thanks in advance
riccardo

writing to GPIO pins

I'm able to get my FT232RQ into bitbang mode and read pins using ftdi.read_pins(), but I can't find documentation (nor even source code) that shows how to write to the pins. I thought maybe I should be using ftdi.write_data(), but that doesn't appear to be having the desired effect:

Here's what I tried and what I observed:

>>> from pyftdi.ftdi import Ftdi
>>> ftdi = Ftdi()
>>> ftdi.open_bitbang_from_url('ftdi:///1', direction=0xff)    # declare GPIO pins as outputs
>>> ftdi.read_pins()
2
>>> ftdi.write_data([0x0])
> (invalid output byte sequence)
1
>>> ftdi.read_pins()
255

Since read_pins() now returns 255, it appears that write_data([0x0]) had some effect (despite the error message), but it did not produce visible effects in my FT232RQ: there are LEDs on two of the GPIO pins and they did not light up as I would expect them to.

The fundamental question remains: how do I write to the GPIO port in bitbang mode?

update

I should make it clear that I'm trying to access the 4-bit CBUS rather than the 8-bit I/O bus.

spi exchange() generates extra 8 clock cycles after read

I've been using this lib with a FPGA dev board loaded with the ft2232HL.
The spi stuff works great, but there is an additional 8 clock cycles generated for every call to exhange().
The extra cycles happen at the very end of the exchange.
For example:

from pyftdi.spi import SpiController, SpiPort
spi = SpiController()
spi.configure(vendor=0x0403, product=0x6010, interface=1)
spiport = spi.get_port(1)
resp =  spiport.exchange([0x55, 0xAA, 0x5A], 3)
print str(resp)
spi.terminate()
exit(0)

This will generate 78 clock cycles instead of 68.
The additional cycles are even sent when the read count is zero.

This does not affect the number of bytes received by the computer, only the slave device.

UsbError on Ftdi.close()

Hi,

I am using the FTDI 232H as a GPIO controller. The device operates as expected, however, when my script finishes, the GpioController destructor raises an exception like this:

Exception ignored in: <bound method GpioController.__del__ of <pyftdi.gpio.GpioController object at 0x7fa2e0618128>> Traceback (most recent call last): File "/usr/local/lib/python3.5/dist-packages/pyftdi/gpio.py", line 48, in __del__ File "/usr/local/lib/python3.5/dist-packages/pyftdi/gpio.py", line 75, in close File "/usr/local/lib/python3.5/dist-packages/pyftdi/ftdi.py", line 348, in close File "/usr/local/lib/python3.5/dist-packages/pyftdi/ftdi.py", line 575, in set_latency_timer File "/usr/local/lib/python3.5/dist-packages/pyftdi/ftdi.py", line 914, in _ctrl_transfer_out pyftdi.ftdi.FtdiError: UsbError: [Errno None] Other error

I have tried commenting out the set_latency_timer call in the Ftdi.close() function and then, as expected, no exception is raised and script terminates successfully.

Has anybody else experienced this problem?

Thanks,
-Gerard

Maximum data length of one I2C write?

I sent an I2C write with data length > 255 bytes, by function I2cController.write(self, address, out, relax=True). And then I met an OverflowError as below.
Is there anyway to break the max length limitation of the byte array?

PS: I'm using i2c_read_pacing branch

    self.port.write(tx_buf)
  File "C:\Python36\lib\site-packages\pyftdi\i2c.py", line 120, in write
    relax=relax)
  File "C:\Python36\lib\site-packages\pyftdi\i2c.py", line 457, in write
    self._do_write(out)
  File "C:\Python36\lib\site-packages\pyftdi\i2c.py", line 680, in _do_write
    out = array('B', out)
OverflowError: unsigned byte integer is greater than maximum

Accessing serial and GPIO simultaneously

I have found that, on Linux, accessing FTDI GPIO causes the FTDI USB Serial Device to be disconnected:

[24051.378487] ftdi_sio ttyUSB0: FTDI USB Serial Device converter now disconnected from ttyUSB0

If I have the FTDI serial port (pyserial) open before accessing the FTDI GPIO, I get IO errors in pyserial after accessing the GPIO. I also noticed that calling GpioController.close() does not reload the FTDI USB Serial Device.

Is there a way to access both simultaneously or is this a know limitation? Do you have to use serialext to open a serial port? The docs aren't very clear on this:

The pyserial backend module is implemented as the serialext.protocol_ftdi module. It is not documented here as no direct call to this module is required, as the UART client should use the regular pyserial API.

Syntax Error during import

Hello,
I am trying to use the library on Windows 10 with pyusb-1.0.0 and pyserial-3.4. I want to use it for SPI-USB communication. But I get the following error when I try to import the library:

In [3]: from pyftdi.spi import SpiController

File "C:\Program Files\Anaconda3\lib\site-packages\pyftdi-0.27.2-py2.7.egg\pyftdi\usbtools.py", line 454
print("Available interfaces:", file=out)

SyntaxError: invalid syntax

Whats the issue with this?

JTAG shift register problem

Hi,
i have noticed that with some target i have problem with te result of the reading operation.
The shift/read function does not always read correctly the TDO any one have suggestions to fix this problem?

Nack in i2c read when transfer is split in multiple chunks

When I try to read a large number of bytes such that the I2C read needs to split into multiple chunks a NACK is send in-between the chunks. Due to the NACK the slave releases the bus and only 0xFF is read in the remaining chunks.
When I change the behavior of the _do_read function in I2C.py such that the read_last also sends an ACK I receive all the data. However, then also the very end of the transfer an ACK is send while this should be an NACK to end te transfer.
Could you please verify the splitting of the read-transfer into chunks. I guess chunks 0 to N-1 should Not include the read_last but chunk N should include it.

Simultaneous SPI and GPIO access

I have a question which may turn out to be a feature request.

We have a SPI peripheral connected to ADBUS0=CLK, ADBUS1=MOSI, ADBUS2=MISO, ADBUS7=CS.
In order to communicate with this device:
spi = SpiController(cs_count=5) spi.configure('ftdi://ftdi:2232h/1') slave = spi.get_port(cs=4, freq=1E6, mode=0)

This seems OK, but now I need to set a GPIO on ADBUS6 duiring the SPI transfer. Let's call it an additional CS pin. How can this be done? I have attempted with gpio.set_direction(0x40, 0x40) but then an error occurs because one is messing with SPI reserved pins. No luck with spi._ftdi.write_data(Array('B', [Ftdi.SET_BITS_LOW, 0x00, 0x40])) either.
Is is possible to either:

  1. Set cs_count=1 and just use ADBUS7 and leave the other pins between vacant?
  2. Use two CS pins at the same time?
  3. Get access to pins as GPIO's within the SPI CS range?

Toggling pins on ACBUSx works fine.

pip2 installs pyftdi version incompatible with python 2

This feels like a silly place to report this issue, but I didn't see an easy way to contact the project maintainers on pypi.python.org.

I tried to install pyftdi for Python 2.7 to get some old code to work, but Pip2 grabbed pyftdi version 0.22.0, which doesn't support python2, rather than pyftdi 0.13.0, which as far as I can tell is the latest version that supports python 2. I don't maintain any python packages, but if it's straightforward to help pip2 and pip3 get different and correct versions of this library, that would save some time for people like me.

Accessing GPIO on a device with custom PID

I see that the Ftdi class has a method to add a device with a custom PID, but how can I use the GpioController class with this device? I have a FT2232H but the PID is 0x8a98 so I'm getting the following error:

ERROR: test_gpio (__main__.GpioTestCase)
Simple test to demonstrate bit-banging.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "gpio.py", line 98, in test_gpio
    gpio.open(mask)
  File "gpio.py", line 47, in open
    self._gpio.open_from_url('ftdi://0x0403:0x8a98/1', direction=out_pins)
  File "/usr/lib/python3.6/site-packages/pyftdi/gpio.py", line 75, in open_from_url
    ftdi.open_bitbang_from_url(url, direction=direction, **kwargs)
  File "/usr/lib/python3.6/site-packages/pyftdi/ftdi.py", line 507, in open_bitbang_from_url
    vendor, product, index, serial, interface = self.get_identifiers(url)
  File "/usr/lib/python3.6/site-packages/pyftdi/ftdi.py", line 305, in get_identifiers
    cls.SCHEME, cls.VENDOR_IDS, cls.PRODUCT_IDS, cls.DEFAULT_VENDOR)
  File "/usr/lib/python3.6/site-packages/pyftdi/usbtools.py", line 359, in parse_url
    raise UsbToolsError('Product ID 0x%04x not supported' % product)
pyftdi.usbtools.UsbToolsError: Product ID 0x8a98 not supported

SpiPort "close" does not exist, but is called by _SpiFlashDevice

In serialflash.py, when an _SpiFlashDevice is closed it calls "self._spi.close()" to close the SPI port. But the SpiPort class in spi.py does not implement a close() method.

I am not sure what the close() method should do on SpiPort(), so I can't give you a patch here.

Pyinstaller, no usb backend

I have a GUI that Id like to turn into Windows 7/64bit EXE with Pyinstaller.

This GUI communicates to a device via an FTDI SPI controller. Ive used pyftdi to implement communication. GUI works great.

However, Im getting the "no backend available" when I try to run my EXE.

It boils down to this part of the code, which ive just shortened to include my candidate (\pyftdi\pyftdi\usbtools.py):

c = 'libusb0'
print 'usb candidate: ',c
m = getattr(um, c)
print 'm attr: ',m
backend = m.get_backend()
Running this in python works great. Running it in EXE, backend returns None.

I noticed that Pyinstaller does have hooks for matplotlib backend and usb hook, so i was hoping that my solution would be a combination of these two.

hooks/usb hook.py just finds the library, but does none of this backend stuff:

NOTE: Mind updating run-time hook when adding further libs.

libusb_candidates = (
# libusb10
'usb-1.0', 'usb', 'libusb-1.0',
# libusb01
'usb-0.1', 'libusb0',
# openusb
'openusb',
)

I do notice that the libusb0.dll is copied to my EXE directory.

I realize this is more of a PyInstaller question, but figured I would post here as well

So my questions are: 1)How can i get Pyinstaller to either copy the usb-backend files that contain what its searching for, but cant seem to find? or just use the in-place structure that regular python seems to have no problem using

2)Does this have anything to do with the dll being local to my EXE dir, and do i need to copy some other files? (I did try just moving usb/backend dir to my EXE dir... no luck)

3)Can this be solved by adding more to usb hook to try to mimic the matlab-backend hook?
thanks

jtag configure problem

running the test script for jtag, python reports a problem:
Traceback (most recent call last): File "test.py", line 17, in setUp self.jtag.configure(vendor=0x0403, product=0x6011, interface=0) File "/usr/local/lib/python3.5/dist-packages/pyftdi/jtag.py", line 426, in configure interface=interface) TypeError: configure() got an unexpected keyword argument 'vendor'
how can i solve this?

No such device (it may have been disconnected)

In an effort to make my script more robust, I am purposely disconnecting and connecting back my usb device. After doing this I get this error when I try to send any command to my Ftdi object:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/pyftdi/ftdi.py", line 1314, in _ctrl_transfer_out
    array('B').frombytes(data), self.usb_write_timeout)
  File "/usr/local/lib/python3.6/site-packages/usb/core.py", line 1043, in ctrl_transfer
    self.__get_timeout(timeout))
  File "/usr/local/lib/python3.6/site-packages/usb/backend/libusb1.py", line 883, in ctrl_transfer
    timeout))
  File "/usr/local/lib/python3.6/site-packages/usb/backend/libusb1.py", line 595, in _check
    raise USBError(_strerror(ret), ret, _libusb_errno[ret])
usb.core.USBError: [Errno 19] No such device (it may have been disconnected)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/pi/EPR/src/application/controller/controller.py", line 19, in open
    super(Controller, self).open(vendor = vendor, product = product)
  File "/usr/local/lib/python3.6/site-packages/pyftdi/ftdi.py", line 402, in open
    self.purge_buffers()
  File "/usr/local/lib/python3.6/site-packages/pyftdi/ftdi.py", line 735, in purge_buffers
    self.purge_rx_buffer()
  File "/usr/local/lib/python3.6/site-packages/pyftdi/ftdi.py", line 722, in purge_rx_buffer
    if self._ctrl_transfer_out(Ftdi.SIO_RESET, Ftdi.SIO_RESET_PURGE_RX):
  File "/usr/local/lib/python3.6/site-packages/pyftdi/ftdi.py", line 1316, in _ctrl_transfer_out
    raise FtdiError('UsbError: %s' % str(e))
pyftdi.ftdi.FtdiError: UsbError: [Errno 19] No such device (it may have been disconnected)

The only way I can bring my USB device back is to close my python process, restart it and reconnect to the Ftdi object. This is not very practical when I intend to deploy my device remotely without ssh access. Any suggestions on how to reconnect to the device within the python process? (I tried close() and then open() but no luck.

I2C with FT2232H?

It seems I2C is not supported on FT2232H yet (pyftdi v0.22.1):
pyftdi.ftdi.FtdiError: This device does not support drive-zero mode

Is there a workaround for that?

Example request combining SPI and GPIO

I'm using the SpiController and SPI communications are working great. But I also need to toggle a reset line. I tried looking at gpio.py, but it's not obvious how I should initialize both SpiController and GpioController to the same FT232H, without conflicting "_ftdi" objects as well as conflicting pin directions.

So far, I've tried assigning the _ftdi object from one controller to the other, but I'm stuck on how to set direction for the GpioController without interfering with the direction for the SpiController, or vice-versa.

Could you please explain, or provide an example on how this could be done?

double import

Why does pyftdi have two layers of directories named pyftdi and require things like "from pyftdi.pyftdi import ..."?
This seems unusual to me in the world of python packages. I don't know of another example like it.
If its something for a good reason and not to be fixed, it might make sense to explain in the README or FAQ.
Notwithstanding, this is a very useful little project and I greatly appreciate it. Thanks, Emmanuel!!!

Slow initialization on macOS Sierra (v10.12.3) - ~5s

I have just installed pyftdi today from pip. I am using Python 3.6 and pyftdi v0.22.0. I am seeing very slow initialization (ftdi.open) in my scripts.

I see this in the README

Slow initialisation on OS X El Capitan
It may take several seconds to open or enumerate FTDI devices.

If you run libusb <= v1.20.0, be sure to read the issue with OS X 10.11+.

I have to assume v1.20.0 is a typo since v1.0.21 is the latest version of libusb I currently see on the libusb website - libusb SourceForge.

I have verified that I am running libusb-v1.0.21 (installed through homebrew).

▶ ls /usr/local/Cellar/libusb/
1.0.21

I initially set DYLD_LIBRARY_PATH=/usr/local/lib since that is where homebrew installs libraries. If I ls that directory I see the following libusb related libraries (I also have libusb-compat installed).

▶ ls /usr/local/lib | grep libusb
libusb-0.1.4.dylib
libusb-1.0.0.dylib
libusb-1.0.a
libusb-1.0.dylib
libusb.a
libusb.dylib

Since I thought PyFTDI might be using one of the wrong libusb .dylibs I changed my DYLD_LIBRARY_PATH to just directly include the library in the homebrew cellar: DYLD_LIBRARY_PATH=/usr/local/Cellar/libusb/1.0.21/lib.

In all of these cases I see that it takes a very long time to open the ftdi device. I'm connecting to an ft232h chip, I see that it is listed in /dev as:

▶ ls /dev | grep tty.usb
tty.usbserial-FTYPX4XC

So I then run the following script:

from pyftdi.ftdi import Ftdi
import time

host = Ftdi()
ftdi_url = 'ftdi://ftdi:FTYPX4XC/1'
start_time = time.time()
host.open_from_url(ftdi_url)
end_time = time.time()

print("opened host in {}s".format(end_time - start_time))

import code
interpreter = code.InteractiveConsole(locals=locals())
interpreter.interact()

And I see that it prints opened host in 25.21956515312195s.

Is there something I'm doing wrong here? Any way to speed this up?

SPI features

Again,
Thank you for this useful code base.
Current SPI configuration does not allow pulling up cs line after every word is sent as is custom with many SPI slaves. Current SPI configuration also has a set time after every transaction before the cs line is pulled (regardless of protocol frequency), instead of waiting a configurable number of SPI clock cycles
So really the features I suggest adding are:
1. Allow configuring SPI to raise CS line after every word sent, and not only at the end of the transaction .
2. Wait a configurable amount of spi clock cycles before raising CS line after every transaction (default should be one)

Custom FTDI Device is not supported

in /pyftdi/pyftdi/ftdi.py the 'type' property does not support custom FTDI devices.

FTDI gave me a product ID number I can use with my board and pyftdi does not recognize it.

In order to fix it how about a static field called 'TYPES' in the FTDI class with the dictionary that is within the type function and a static method to allow users to add their device to the dictionary:

TYPES = { (0x0403, 0x6001, 0x200) : 'ft232am',                                                               
          (0x0403, 0x6001, 0x400) : 'ft232bm',                                                               
          (0x0403, 0x6001, 0x600) : 'ft232r',                                                                
          (0x0403, 0x6014, 0x900) : 'ft232h',                                                                
          (0x0403, 0x6010, 0x500) : 'ft2232d',                                                               
          (0x0403, 0x6010, 0x600) : 'ft232c',                                                                
          (0x0403, 0x6010, 0x700) : 'ft2232h',                                                               
          (0x0403, 0x6011, 0x800) : 'ft4232h' }                                                              

@staticmethod
def add_type(vendor, product, bcdDevice, data):
    Ftdi.TYPES[(vendor, product, bcdDevice)] = data 

SPI Module Using GPIO Issue---OverflowError: unsigned byte integer is greater than maximum

I use below code to control AC4&AC7 as gpio and spi port with cs0,but got OverflowError.
Chip:FT232H
OS:MacOS High Sierra
Python:3.6.3

# coding=utf-8
from pyftdi.spi import SpiController
from time import sleep

spi = SpiController()
spi.configure(url="ftdi://ftdi:232h/1/")
pe = spi.get_port(cs=0, freq=1E6, mode=0)

# enable 5v output on ac7,seprate D1 D2 on ac4
print('config and set gpio')
gpio = spi.get_gpio()
gpio.set_direction(0x9000,0x9000)
gpio.write(0x9000)

print('spi write out')
pe.write([0x01,0x00])


Error Message Below:

Traceback (most recent call last):
  File "/Users/lifetyper/Dropbox/Python/Utils/bug.py", line 23, in <module>
    pe.write([0x01,0x00])
  File "/usr/local/lib/python3.6/site-packages/pyftdi/spi.py", line 143, in write
    self._cpol, self._cpha)
  File "/usr/local/lib/python3.6/site-packages/pyftdi/spi.py", line 384, in exchange
    cpol, cpha)
  File "/usr/local/lib/python3.6/site-packages/pyftdi/spi.py", line 492, in _exchange_half_duplex
    cmd.extend((Ftdi.SET_BITS_LOW, ctrl, direction))
OverflowError: unsigned byte integer is greater than maximum

But if I re-config spi controller and spi port after setting and using gpio port,everything works fine:

# coding=utf-8
from pyftdi.spi import SpiController
from time import sleep

spi = SpiController()
spi.configure(url="ftdi://ftdi:232h/1/")
pe = spi.get_port(cs=0, freq=1E6, mode=0)


# enable 5v output on ac7,seprate D1 D2 on ac4
print('config and set gpio')
gpio = spi.get_gpio()
gpio.set_direction(0x9000,0x9000)
gpio.write(0x9000)


# re-config spi after gpio will Solve this issue
spi = SpiController()
spi.configure(url="ftdi://ftdi:232h/1/")
pe = spi.get_port(cs=0, freq=1E6, mode=0)

print('spi write out')
pe.write([0x01,0x00])



But If I use gpio on ADBUS only,this issue won't happen,code below works fine

# coding=utf-8
from pyftdi.spi import SpiController
from time import sleep

spi = SpiController()
spi.configure(url="ftdi://ftdi:232h/1/")
pe = spi.get_port(cs=0, freq=1E6, mode=0)


# If I use only gpio on ADBUS,this works fine
print('config and set gpio')
gpio = spi.get_gpio()
gpio.set_direction(0x80,0x80)
gpio.write(0x80)

print('spi write out')
pe.write([0x01,0x00])


I2C hold time after START seems to be too short

I'm currently seeing about 2.2 us time from when SDA goes low for START, to the time when SCL goes low. I'm running the bus at 100 kHz but the time seems to be the same at any speed.

image

However, the I2C bus specification requires this time (t HD;STA) to be atleast 4 us:

image

image

This seems to cause intermittent communication problems atleast with bq20z45 battery IC. What would be the easiest way to increase the delay?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.