我有一个Thorlabs直流电机控制器,可以通过以下DMESG日志检测到:

usb 5-2: new full-speed USB device number 6 using uhci_hcd
usb 5-2: New USB device found, idVendor=0403, idProduct=faf0
usb 5-2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
usb 5-2: Product: APT DC Motor Controller
usb 5-2: Manufacturer: Thorlabs
usb 5-2: SerialNumber: 83858610
ftdi_sio 5-2:1.0: FTDI USB Serial Device converter detected
usb 5-2: Detected FT232RL
usb 5-2: Number of endpoints 2
usb 5-2: Endpoint 1 MaxPacketSize 64
usb 5-2: Endpoint 2 MaxPacketSize 64
usb 5-2: Setting MaxPacketSize 64
usb 5-2: FTDI USB Serial Device converter now attached to ttyUSB0

它也可以在lsusb下找到:
Bus 005 Device 007: ID 0403:faf0 Future Technology Devices International, Ltd

基于以上信息,我设置了/etc/udev/rules.d/99-libftdi.rules
SUBSYSTEMS=="usb", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="faf0", GROUP="dialout", MODE="0660"

(我也尝试过users组和0666模式。)
然后我运行命令
$ udevadm test -a -p  $(udevadm info -q path -n /dev/ttyUSB0)

会产生
GROUP 20 /etc/udev/rules.d/99-libftdi.rules:1
MODE 0660 /etc/udev/rules.d/99-libftdi.rules:1
handling device node '/dev/ttyUSB0', devnum=c188:0, mode=0660, uid=0, gid=20
preserve permissions /dev/ttyUSB0, 020660, uid=0, gid=20
preserve already existing symlink '/dev/char/188:0' to '../ttyUSB0'
found 'c188:0' claiming '/run/udev/links/\x2fserial\x2fby-id\x2fusb-Thorlabs_APT_DC_Motor_Controller_83858610-if00-port0'
creating link '/dev/serial/by-id/usb-Thorlabs_APT_DC_Motor_Controller_83858610-if00-port0' to '/dev/ttyUSB0'
preserve already existing symlink '/dev/serial/by-id/usb-Thorlabs_APT_DC_Motor_Controller_83858610-if00-port0' to '../../ttyUSB0'
found 'c188:0' claiming '/run/udev/links/\x2fserial\x2fby-path\x2fpci-0000:00:1d.0-usb-0:2:1.0-port0'
creating link '/dev/serial/by-path/pci-0000:00:1d.0-usb-0:2:1.0-port0' to '/dev/ttyUSB0'
preserve already existing symlink '/dev/serial/by-path/pci-0000:00:1d.0-usb-0:2:1.0-port0' to '../../ttyUSB0'

现在是软件方面。libftdi v1.0通过以下指令安装在Linux Mint 17下:
Pylibftdi library not working (serial mode, UM232H)
Pylibftdi通过PIP安装:
$ sudo -H env PATH=$PATH pip install pylibftdi

它可以回显libftdi的正确版本:
$ python -m pylibftdi.examples.info

pylibftdi version     : 0.15.0
libftdi version       : libftdi_version(major=1, minor=0, micro=0, version_str='1.0', snapshot_str='v1.0')
libftdi library name  : libftdi1.so.2
libusb version        : libusb_version(major=1, minor=0, micro=17, nano=10830, rc='', describe='http://libusbx.org')
libusb library name   : libusb-1.0.so.0
Python version        : 2.7.10
OS platform           : Linux-3.13.0-37-generic-x86_64-with-debian-jessie-sid

但是,它不会列出任何已连接的ftdi设备,即使使用sudo
$ sudo python -m pylibftdi.examples.list_devices
$ (nothing printed)

有没有办法单独测试libftdi和pylibftdi?或者,我们已经有足够的信息来完成这项工作了吗?提前谢谢。

最佳答案

未检测到该设备,因为它有一个奇怪的idProduct。官方问答提示了可行的解决方案:
http://pylibftdi.readthedocs.org/en/latest/how_to.html
打开.../pylibftdi/examples/list_devices.py并在第24行后添加以下行:

from pylibftdi import USB_PID_LIST
USB_PID_LIST.append(0xfaf0)

再次尝试启动命令:
$ python -m pylibftdi.examples.list_devices
Thorlabs:APT DC Motor Controller:83858610

10-05 18:10