问题
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)
the lsusb command shows it is a FTDI USB device Bus 009 Device 008: ID 0403:faf0 Future Technology Devices International, Ltd
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])
Backend:
In [10]: motor.dev.backend
Out[10]: <usb.backend.libusb1._LibUSB at 0x7fc2da558190>
Endpoint:
In [13]: motor.epi
Out[13]: <ENDPOINT 0x81: Bulk IN>
In [14]: motor.epo
Out[14]: <ENDPOINT 0x2: Bulk OUT>
it might be related to this question
Do I need to install a proper driver on my computer from the FTDI website?
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.
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.
回答1:
I don't have access to your hardware but I think your problem with libftdi/pylibftdi might be similar to this one:
Failed to Connect FT232RL Device with Pylibftdi (Thorlabs APT DC Motor Controller)
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.
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.
来源:https://stackoverflow.com/questions/56486431/pyusb-read-always-returns-the-same-value