4
votes

I have a lot identical devices with STM32 VCP. Windows 8.1 creates serial COM port for device. If I connect ONE device to any PC USB port, windows will bind to it the same COM port. After the connection of the second device to other USB port, it will create the next COM port with different serial COM number. If I unplug these devices and connect in different order, COM ports will be switched between devices. It's a problem, because I need the same order COM ports order (physically) each time. Using USBlyzer software I can see what some kind of USB port number is different for each physical USB port:

enter image description here

So I would like to access (get the current device) by these devices by port number. Or list all devices and get this port number from device object?

In libusb documentation found it has such a method:

uint8_t libusb_get_port_number (libusb_device *dev)
Get the number of the port that a device is connected to.

link: http://libusb.sourceforge.net/api-1.0/group__dev.html

Maybe PyUSB has it too...

1
I've never seen Windows behave that way. If the devices are identical (and don't have USB serial numbers), then the COM port number that they are assigned should only depend on what port they are plugged into, and not what order they were plugged in. But I admit I don't test USB devices without serial numbers very often and maybe something changed. What version of Windows is this?David Grayson

1 Answers

2
votes

Found other solution to my problem. Using windows DeviceManager API Get Port and hub number (USB physical identification) from location info and friendly name of device with COM port number in it. Parsing this information and have information for Serial communication.

from infi.devicemanager import DeviceManager
dm = DeviceManager()
dm.root.rescan()

devices = dm.all_devices


for i in devices:
    try:
        print '{} : address: {}, bus: {}, location: {}'.format(i.friendly_name, i.address, i.bus_number, i.location)
    except Exception:
        pass