2

I'm connecting to 2 identical microphone arrays using the pyusb library, but they have the same idVendor and idProduct numbers. The only way to differentiate the 2 devices is by address, but I'm unable to figure out how to connect using address.

Is there any way to make a usb connection using a device's address instead of idVendor or idProduct?

Here is the code

import usb.core
import usb.util
import time
from tuning import Tuning
import dfu

device_list = dfu.DFU.find()
print(device_list)

dev1 = usb.core.find(idVendor=0x2886, idProduct=0x0018) #address = 0x013
dev2 = usb.core.find(idVendor=0x2886, idProduct=0x0018) #address = 0x012

if dev1:
    Mic_tuning1 = Tuning(dev1)
    Mic_tuning2 = Tuning(dev2)

    print(Mic_tuning1.direction)
    print(Mic_tuning2.direction)

    while True:
        try:
            print(Mic_tuning1.direction)
            print(Mic_tuning2.direction)
            time.sleep(1)
        except KeyboardInterrupt:
            break
        
else: print('failed to find microphone')
a_person
  • 21
  • 2

1 Answers1

0

Disclaimer: I'm not familiar with pyusb, but I'm a little bit familiar with libusb, which is the underlying library used.


The function you're calling to get 'dev1' and 'dev2' is likely calling libusb_open_device_with_vid_pid() under the hood.

https://libusb.sourceforge.io/api-1.0/group__libusb__dev.html#ga10d67e6f1e32d17c33d93ae04617392e

This [libusb] method was added for convenience, as the usual way of accessing a device is by iterating through the list of devices to find the one you want to connect to. In libusb, this done via libusb_get_device_list(). You would iterate through the list of devices, calling libusb_get_device_address() on each until you find the one with the desired address:

https://libusb.sourceforge.io/api-1.0/group__libusb__dev.html#gac0fe4b65914c5ed036e6cbec61cb0b97

Does the documentation for pyusb mention anything that resembles as 'get_device_list()' method? That's effectively what you'll need.

Raleigh L.
  • 599
  • 2
  • 13
  • 18