Skip to main content

Tool to map usb device port chain and port name

Project description

pyusb-chain

Support command line interface to get the port chain of USB devices(serial, audio, .etc) based on UsbDeviceTreeView.exe in windows.

Installation

The easiest (and best) way to install pyusb-chain is through pip:

pip install pyusb-chain

Sources packages are also available at git hub:

https://github.com/BillYuan/usb_port_path

Quickstart

The API to use pyusb_chain to map between port chain and port name.


from pyusb_chain.usb_tree_view_tool import UsbTreeViewTool

tool = UsbTreeViewTool()
tool.scan()  # scan first to get the latest USB devices information

# to get the port chain by COM port
portChain = tool.get_chain_from_port("COM16")  # "1-7-5" or "1-3-1:2" if there are multi-com ports in one USB device 

# to get the port chain by Audio Name
portChain = too.get_chain_from_port("Speakers (4- USB Audio Device)")  # "1-3-7-4:Speaker"
portChain = too.get_chain_from_port("Microphone (4- USB Audio Device)")  # "1-3-7-4:Microphone"


# to get port name by the port chain
portName = tool.get_port_from_chain("1-7-5")  # "COM16"
portName = tool.get_port_from_chain("1-3-1:2")  # "COM11"
portName = tool.get_port_from_chain("1-3-7-4:Speaker")  # "Speakers (4- USB Audio Device)"
portName = tool.get_port_from_chain("1-3-7-4:Microphone")  # "Microphone (4- USB Audio Device)"

Support command line standalone usage

usage: __main__.py [-h] [-g] [-l] [-a] [-f FILTER] [-e] [-v VERBOSE]

Command line for port path of USB devices (COM ports / Audio Devices)
Version:0.1.3

optional arguments:
  -h, --help            show this help message and exit
  -g, --gui             Launch GUI of USBTreeViewer.exe in Windows system
  -l, --list            List all USB devices information for COM ports and USB
                        Audio devices
  -a, --allinfo         List all information of USB device, include SN and
                        driver key
  -f FILTER, --filter FILTER
                        filter the key words of USB devices information
  -e, --export          export the json format with all connected USB devices
                        information
  -v VERBOSE, --verbose VERBOSE
                        verbose log mode, 'debug', 'fatal', 'error',
                        'warning', 'info'

For example,

  1. List all devices: >pyusb-chain --list --allinfo
Scanning all USB devices...


Port Chain Key    Port Name                       Device Name                                     SN                                                  Driver Key
----------------  ------------------------------  ----------------------------------------------  ------------------------------------------------  ------------
2-1-1                                             Altera USB-Blaster                              8a56TRPS                                                    28
2-1-5:Speaker     Headphones (Realtek USB Audio)  USB Composite Device - Realtek USB Audio        200901010001                                                 8
2-1-6                                             USB Composite Device - 2脳 Keyboard, 2脳 HID                                                                   9
2-1-7-3-2         COM16                           Silicon Labs CP210x USB to UART Bridge (COM16)  evkmimxrt1170_1_a                                           14
2-1-7-3-3         COM3                            mbed Composite Device - D:\, COM3, HID          022900001294098900000000000000000000000097969905            17
2-1-7-4-1         COM109                          USB-SERIAL CH340 (COM109)                                                                                   16
2-1-7-4-4                                         USB Input Device - Mouse                                                                                     7
2-1-7-7-1                                         Altera USB-Blaster                              8a56TQ1M                                                    27
2-1-7-7-3         COM11                           USB Composite Device - COM11, E:\               SDAF7507E73                                                 18
2-3-2                                             Realtek USB GbE Family Controller               000002000000                                                 7
3-2                                               Altera USB-Blaster                              8B951BA7                                                    26
3-5                                               USB Composite Device - Camera                                                                                7
3-7                                               Intel(R) Wireless Bluetooth(R) - Media, HID                                                                  0
3-10                                              USB Composite Device                                                                                         6
  1. Add filter to only list devices you required: >pyusb-chain --list Altera --allinfo
Port Chain Key    Port Name    Device Name         SN          Driver Key
----------------  -----------  ------------------  --------  ------------
2-1-1                          Altera USB-Blaster  8a56TRPS            28
2-1-7-7-1                      Altera USB-Blaster  8a56TQ1M            27
3-2                            Altera USB-Blaster  8B951BA7            26
  1. Export to the json file for all listed devices: >pyusb-chain --list Altera --export
Please get 'usb_port_chain_export.json' for dumped information!
{
    "2-1-1": {
        "Port Name": "",
        "Device Name": "Altera USB-Blaster",
        "SN": "8a56TRPS",
        "Location Info": "Port_#0001.Hub_#0004",
        "Device ID": "USB\\VID_09FB&PID_6001\\8A56TRPS",
        "Driver Key": 28
    },
    "2-1-7-7-1": {
        "Port Name": "",
        "Device Name": "Altera USB-Blaster",
        "SN": "8a56TQ1M",
        "Location Info": "Port_#0001.Hub_#0011",
        "Device ID": "USB\\VID_09FB&PID_6001\\8A56TQ1M",
        "Driver Key": 27
    },
    "3-2": {
        "Port Name": "",
        "Device Name": "Altera USB-Blaster",
        "SN": "8B951BA7",
        "Location Info": "Port_#0002.Hub_#0001",
        "Device ID": "USB\\VID_09FB&PID_6001\\8B951BA7",
        "Driver Key": 26
    }
}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyusb-chain-0.2.0.tar.gz (388.8 kB view details)

Uploaded Source

Built Distribution

pyusb_chain-0.2.0-py3-none-any.whl (390.9 kB view details)

Uploaded Python 3

File details

Details for the file pyusb-chain-0.2.0.tar.gz.

File metadata

  • Download URL: pyusb-chain-0.2.0.tar.gz
  • Upload date:
  • Size: 388.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.2

File hashes

Hashes for pyusb-chain-0.2.0.tar.gz
Algorithm Hash digest
SHA256 377b8c6510bb81a082694f468cba75f8065acdb537fe6b5bbb51b8433a3bd0e5
MD5 5818e8bb74fb67e1dc5ac8c0d248f591
BLAKE2b-256 0d93e799112ffe9d419137d4d5d165e11be5ef13054925769d2a8be85781e5b8

See more details on using hashes here.

File details

Details for the file pyusb_chain-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: pyusb_chain-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 390.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.2

File hashes

Hashes for pyusb_chain-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cc211303765505df8845de8604546aa9085c8f16f8590e73861f17a4715ba223
MD5 f59bb49d4aa4cc959f55012678dd9156
BLAKE2b-256 30df973da70746e0e6a3fd7b24fb9c8f2619c7fc3334230840651e1efb68dca2

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page