我在python中使用USB库。我可以看到该设备,可以对其进行配置。但是当我读出来的时候,我总是得到相同的东西数组('B',[17,96])。注意,即使我不写端点输出,当我读时我仍然得到相同的结果。我还可以根据需要多次阅读,但仍然得到相同的结果(请参见下面的完整代码)
lsusb命令显示它是FTDI USB设备 总线009设备008:ID 0403:faf0未来技术设备国际有限公司
过去,我可以与其他USB设备通信吗?我不明白这是怎么回事。有人可以指出正确的方向吗?我调查了pylibftdi,但什至看不到带有pylibftdi库的USB设备。
>>> import usb
serial_number = '83836244'
dev = None
devices = list(usb.core.find(idVendor=0x0403, idProduct=0xFAF0, find_all = True))
for dev in devices:
if dev.serial_number == serial_number:
break
dev = dev
reattach = False
if self.dev.is_kernel_driver_active(0):
reattach = True
self.dev.detach_kernel_driver(0)
# set the active configuration. With no arguments, the first
# configuration will be the active one
self.dev.set_configuration()
# get an endpoint instance
cfg = self.dev.get_active_configuration()
intf = cfg[(1,1)]
epo = usb.util.find_descriptor(
intf,
# match the first OUT endpoint
custom_match = \
lambda e: \
usb.util.endpoint_direction(e.bEndpointAddress) == \
usb.util.ENDPOINT_OUT)
epi = usb.util.find_descriptor(
intf,
# match the first IN endpoint
custom_match = \
lambda e: \
usb.util.endpoint_direction(e.bEndpointAddress) == \
usb.util.ENDPOINT_IN)
assert self.epo is not None
assert self.epi is not None
epi.wMaxPacketSize = 72000
epo.wMaxPacketSize = 72000
epi.bmAttributes = 1
epi.bInterval = 100
usb_buff = int(self.epi.wMaxPacketSize/100)
dev.read(epi,100,1000)
array('B', [17, 96])
后端:
In [10]: motor.dev.backend
Out[10]: <usb.backend.libusb1._LibUSB at 0x7fc2da558190>
端点:
In [13]: motor.epi
Out[13]: <ENDPOINT 0x81: Bulk IN>
In [14]: motor.epo
Out[14]: <ENDPOINT 0x2: Bulk OUT>
它可能与this question
有关我是否需要从the FTDI website在计算机上安装适当的驱动程序?
我知道通信协议,并且在将该USB设备切换到VCP(虚拟COM端口)后,能够在Windows上与之通信。这样做会使我丢失诸如序列号之类的信息,这些信息存储在USB芯片上,并且在设备处于VCP模式时无法访问。我也想从Windows切换到Linux。
此刻,我研究了哪些驱动程序已绑定到我的USB电机控制器上,并且恢复为空。
lsusb -t
/: Bus 10.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/1p, 5000M
/: Bus 09.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/1p, 480M
|__ Port 1: Dev 2, If 0, Class=Hub, Driver=hub/7p, 480M
|__ Port 1: Dev 3, If 0, Class=Vendor Specific Class, Driver=, 12M
|__ Port 2: Dev 4, If 0, Class=Vendor Specific Class, Driver=, 12M
|__ Port 3: Dev 5, If 0, Class=Vendor Specific Class, Driver=, 12M
|__ Port 4: Dev 6, If 0, Class=Vendor Specific Class, Driver=, 12M
|__ Port 5: Dev 7, If 0, Class=Vendor Specific Class, Driver=, 12M
|__ Port 6: Dev 8, If 0, Class=Vendor Specific Class, Driver=usbfs, 12M
/: Bus 08.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/1p, 5000M
/: Bus 07.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/1p, 480M
|__ Port 1: Dev 2, If 0, Class=Hub, Driver=hub/7p, 480M
|__ Port 1: Dev 3, If 0, Class=Vendor Specific Class, Driver=, 12M
|__ Port 2: Dev 4, If 0, Class=Vendor Specific Class, Driver=, 12M
|__ Port 3: Dev 5, If 0, Class=Vendor Specific Class, Driver=, 12M
|__ Port 4: Dev 6, If 0, Class=Vendor Specific Class, Driver=, 12M
|__ Port 5: Dev 7, If 0, Class=Vendor Specific Class, Driver=, 12M
|__ Port 6: Dev 8, If 0, Class=Vendor Specific Class, Driver=, 12M
/: Bus 06.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/1p, 5000M
/: Bus 05.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/1p, 480M
|__ Port 1: Dev 2, If 0, Class=Hub, Driver=hub/7p, 480M
|__ Port 1: Dev 3, If 0, Class=Vendor Specific Class, Driver=, 12M
|__ Port 2: Dev 4, If 0, Class=Vendor Specific Class, Driver=, 12M
|__ Port 3: Dev 5, If 0, Class=Vendor Specific Class, Driver=, 12M
|__ Port 4: Dev 6, If 0, Class=Vendor Specific Class, Driver=, 12M
|__ Port 5: Dev 7, If 0, Class=Vendor Specific Class, Driver=, 12M
|__ Port 6: Dev 8, If 0, Class=Vendor Specific Class, Driver=, 12M
/: Bus 04.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/1p, 5000M
/: Bus 03.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/1p, 480M
|__ Port 1: Dev 2, If 0, Class=Hub, Driver=hub/7p, 480M
|__ Port 5: Dev 3, If 0, Class=Vendor Specific Class, Driver=, 12M
|__ Port 6: Dev 4, If 0, Class=Vendor Specific Class, Driver=, 12M
/: Bus 02.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/10p, 10000M
/: Bus 01.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/16p, 480M
|__ Port 12: Dev 2, If 0, Class=Vendor Specific Class, Driver=rtsx_usb, 480M
我想知道是否需要将特定的驱动程序绑定到我的电机控制器上。
答案 0 :(得分:0)
我无法访问您的硬件,但我认为您的 libftdi / pylibftdi 问题可能与此类似:
Failed to Connect FT232RL Device with Pylibftdi (Thorlabs APT DC Motor Controller)
Thorlab的APT协议似乎有几种实现。请参阅这个实例:https://github.com/MaxP92/thorlabs_python_low-level
可能有一些项目可以回收利用。
我想您有使用FTDI设备的USB端的理由,但是我不确信无法从串行设备访问序列号。根据{{3}},有一个MGMSG_HW_GET_INFO
命令应提供序列号,型号,固件版本等信息。再说一次,我没有硬件可以尝试一下,但是也许这是一个让您看看的主意。