pyUSB read()始终返回相同的值 [英] pyUSB read() always returns the same value

查看:492
本文介绍了pyUSB read()始终返回相同的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在python中使用USB库.我可以看到该设备,可以对其进行配置.但是当我读出来的时候,我总是得到相同的东西数组('B',[17,96]).注意,即使我不写端点输出,当我读时我仍然会得到相同的结果.我还可以根据需要多次阅读,但仍然得到相同的结果(请参见下面的完整代码)

I am using USB library in python. I can see the device, i can configure it. but when I read out of it I always get the same stuff array('B', [17, 96]). Note, even if I don't write into the endpoint output I still get the same result when I read; I can also read as many times as I want and still get the same result (see full code below)

lsusb命令显示它是FTDI USB设备 总线009设备008:ID 0403:faf0未来技术设备国际有限公司

the lsusb command shows it is a FTDI USB device Bus 009 Device 008: ID 0403:faf0 Future Technology Devices International, Ltd

过去,我可以与其他USB设备通信吗?我不明白这是怎么回事.有人可以指出正确的方向吗?我查看了 pylibftdi ,但是我什至看不到带有pylibftdi库的USB设备.

in past, i was able to communicate with other usb devices? I don't understand what is happening with this one. Could someone point to the right direction? I looked into pylibftdi but I cannot even see this usb device with the pylibftdi library.

>>> 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>

它可能与此问题

我是否需要从 FTDI网站在计算机上安装正确的驱动程序 ?

Do I need to install a proper driver on my computer from the FTDI website?

我知道通信协议,并且在将该USB设备切换到VCP(虚拟COM端口)后,能够在Windows上与它进行通信.这样做会使我丢失诸如序列号之类的信息,这些信息存储在USB芯片上,并且在设备处于VCP模式时无法访问.我也想从Windows切换到Linux.

I know the communication protocol and I was able to communicate with it on Windows after switching this USB device to VCP (Virtual COM port). By doing so I am losing information such as serial numbers that are stored on USB chip and are not accessible when the device is in VCP mode. I also want to switch from Windows to Linux.

此刻,我研究了哪些驱动程序已绑定到我的USB电机控制器上,然后又恢复为空.

I have looked into what drivers are bound to my USB motor controllers at the moment and it came back as empty.

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

我想知道是否需要将特定的驱动程序绑定到我的电机控制器上.

I wonder if I need to bound a specific driver to my motor controllers.

推荐答案

我无权访问您的硬件,但我认为您的 libftdi/pylibftdi 问题可能与此类似:

I don't have access to your hardware but I think your problem with libftdi/pylibftdi might be similar to this one:

无法连接FT232RL具有Pylibftdi(Thorlabs APT直流电动机控制器)的设备

Thorlab的APT协议似乎有几种实现.请参阅以下示例: https://github.com/MaxP92/thorlabs_python_low-level

It seems there are several implementations of Thorlab's APT protocol. See fon instance this one: https://github.com/MaxP92/thorlabs_python_low-level

可能有一些项目可以回收利用.

There might be something you can recycle for your project.

我想您有使用FTDI设备的USB端的理由,但我不确信无法从串行设备访问序列号.根据协议手册,有一个MGMSG_HW_GET_INFO命令可以应该提供序列号,型号,固件版本等信息.再说一次,我没有硬件可以尝试一下,但是也许这是一个让您看看的主意.

I guess you have your reasons to use the USB side of the FTDI device, but I'm not convinced about serial numbers not being accessible from the serial device. According to the protocol manual, there is a MGMSG_HW_GET_INFO command that should give you serial number, model number, firmware version and more. Again, I don't have the hardware to try this out, but maybe it's an idea for you to take a look.

这篇关于pyUSB read()始终返回相同的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆