0
votes

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 know what are you trying to do here. What do you want out of the serial port? If you extend your code or explain what you want I can try to reproduce it. But I think if you don't want to use the VCP you'll need the D2xx driver to talk to the device.Marcos G.
@MarcosG. I have successfully communicated with the device using VCP on Windows 7 using pyserial. Now, I am trying to communicate with the same device on Linux using pyUSB. I can see the device, I can see all the details. However, I cannot successfully communicate with it. I have seen this D2xx driver. And I have suspected that I will need to get D2xx driver. I have found a related question which might help with my problem. stackoverflow.com/questions/33649296/…Valentyn
@MarcosG. I have ~ 20 of identical devices that are connected to the same computer. They are all ThorLabs motor controllers. I want to use serial numbers to uniquely identify each device. However, the serial numbers are stored on the FTDI chip itself and not in the controller memory. Hence, I cannot retrieve serial numbers when I communicate with it via VCP on windows. I am switching to Linux and pyUSB so I can uniquely identify each controller.Valentyn
Thank you for the details Valentyn, now I understand what you want to do, . I have used pyftdi and the D2xx driver successfully on Linux. To be able to talk to the device through pyusb I think you need to install the D2xx driver. Let me take a look at your code and I'll come back with some more comments.Marcos G.
I think your best shot is to use pylibftdi or pyftdi. I can write an answer with all installation and testing details but rereading your question I got the feeling you have already done that. Have you ever been able to list any FTDI devices with pylibfti? or you never managed to get anything out of itMarcos G.

1 Answers

0
votes

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.