Python 2.7 如何使用pylibftdi连接到FT230?

Python 2.7 如何使用pylibftdi连接到FT230?,python-2.7,ftdi,Python 2.7,Ftdi,我正好有一个FTDI 连接到我的机器。 我可以使用lsusb查看设备: $ lsusb Bus 002 Device 005: ID 051d:0002 American Power Conversion Uninterruptible Power Supply Bus 002 Device 004: ID 046d:c408 Logitech, Inc. Marble Mouse (4-button) ... Bus 003 Device 010: ID 0403:6015 Future Te

我正好有一个FTDI 连接到我的机器。 我可以使用lsusb查看设备:

$ lsusb
Bus 002 Device 005: ID 051d:0002 American Power Conversion Uninterruptible Power Supply
Bus 002 Device 004: ID 046d:c408 Logitech, Inc. Marble Mouse (4-button)
...
Bus 003 Device 010: ID 0403:6015 Future Technology Devices International, Ltd Bridge(I2C/SPI/UART/FIFO)
...
0403:6015
条目是FT230X。 我想用Python来讨论这件事,我们也是这样做的

>>> import pylibftdi
>>> dev = pylibftdi.Device()
但是读取时会收到错误消息

~/.virtualenvs/labrad/local/lib/python2.7/site-packages/pylibftdi/device.pyc in __init__(self, device_id, mode, encoding, lazy_open, chunk_size, interface_select, device_index, auto_detach, **kwargs)
    114         # lazy_open tells us not to open immediately.
    115         if not lazy_open:
--> 116             self.open()
    117 
    118     def __del__(self):

~/.virtualenvs/labrad/local/lib/python2.7/site-packages/pylibftdi/device.pyc in open(self)
    154             self.fdll.ftdi_deinit(byref(self.ctx))
    155             del self.ctx
--> 156             raise FtdiError(msg)
    157 
    158         if self.auto_detach and self.driver.libftdi_version().major > 0:

FtdiError: device not found (-3)
我们还可以尝试显式指定序列号:

>>> import usb.core
>>> devs = list(usb.core.find(find_all=True))
>>> for x in str(devs).split(','):
        print(x)
[<DEVICE ID 051d:0002 on Bus 002 Address 005>
<DEVICE ID 046d:c408 on Bus 002 Address 004>
<DEVICE ID 04ca:006e on Bus 002 Address 003>
<DEVICE ID 8087:0024 on Bus 002 Address 002>
<DEVICE ID 1d6b:0002 on Bus 002 Address 001>
<DEVICE ID 1d6b:0003 on Bus 004 Address 001>
<DEVICE ID 1366:0101 on Bus 003 Address 009>
<DEVICE ID 0403:6015 on Bus 003 Address 010>  # <-- that one
<DEVICE ID 1d6b:0002 on Bus 003 Address 001>
<DEVICE ID 1050:0211 on Bus 001 Address 003>
<DEVICE ID 8087:0024 on Bus 001 Address 002>
<DEVICE ID 1d6b:0002 on Bus 001 Address 001>]

>>> my_dev = devs[7]
>>> ser = devs.serial_number
>>> import pylibftdi
>>> pylibftdi.Device(ser)
导入usb.core >>>devs=list(usb.core.find(find_all=True)) >>>对于str(devs)中的x.split(','): 打印(x) [ #>>my_dev=devs[7] >>>ser=devs.序列号 >>>进口pylibftdi >>>pylibftdi.装置(ser) 同样的错误

为什么会这样? 声明
设备
构造函数应该获取第一个可用的设备,在我的例子中只有一个。
显示“未找到设备”的错误消息使我怀疑pylibftdi正在使用的驱动程序是否支持FT230X,我认为在我的情况下,该驱动程序是
libftdi1

pylibftdi有一个硬编码的USB产品ID列表(idProduct)它将在pylibftdi.driver.USB_PID_列表中搜索。这不包括FT230X芯片,并且它不会查询libftdi以查找基础库支持的芯片:

从pylibftdi/driver.py:

# Opening / searching for a device uses this list of IDs to search
# by default. These can be extended directly after import if required.
FTDI_VENDOR_ID = 0x0403
USB_VID_LIST = [FTDI_VENDOR_ID]
USB_PID_LIST = [0x6001, 0x6010, 0x6011, 0x6014]
不幸的是,这似乎不起作用:

>>> import pylibftdi
>>> pylibftdi.driver.USB_PID_LIST.append(0x6015)
>>> print(["%04x " % x for x in pylibftdi.USB_PID_LIST])
['6001 ', '6010 ', '6011 ', '6014 ', '6015 ']
>>> dev = pylibftdi.Device()  
Segmentation fault
这里的问题似乎是当pylibftdi调用libusb设置自动分离时。如果我执行以下操作,它似乎可以工作:

>>> import pylibftdi
>>> pylibftdi.driver.USB_PID_LIST.append(0x6015)
>>> print(["%04x " % x for x in pylibftdi.USB_PID_LIST])  
['6001 ', '6010 ', '6011 ', '6014 ', '6015 ']
>>> dev = pylibftdi.Device(auto_detach=False)  
>>> dev
<pylibftdi.device.Device at 0x7f586d08f350>
导入pylibftdi >>>pylibftdi.driver.USB_PID_LIST.append(0x6015) >>>打印([%04x”%x代表pylibftdi.USB\u PID\u列表中的x]) ['6001 ', '6010 ', '6011 ', '6014 ', '6015 '] >>>dev=pylibftdi.Device(自动分离=False) >>>发展 对我来说,这并不能阻止libftdi成功地分离内核驱动程序(/dev/ttyUSB0在我运行它时消失),但它确实阻止了会话关闭后重新连接