Can we query USB Port Link state in Python using USBLPM tool?

Shivaprasad Prabhu 1 Reputation point
2022-08-12T09:13:47.563+00:00

I'm aware that USB3.0 low power states like U1, U2, U3 can be triggered using Microsoft's test tool like USBLPM and DEVCON tool in python script for external USB device.

USBLPM (U1/U2):
UsbLPM.exe /enable U1
UsbLPM.exe /enable U2

DEVCON (U3):
subprocess.run([devcon, 'disable', parsedHwid])

I just wonder is there any way we can query the USB Link Power state from python script? To make sure device has accepted link commands or not!

Windows for business Windows Client for IT Pros User experience Other
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Limitless Technology 39,916 Reputation points
    2022-08-18T07:30:59.667+00:00

    Hello there,

    All USB ports can be accessed via /dev/bus/usb/< bus >/< device >

    For the ID generated, even if you unplug the device and reattach it [ could be some other port ]. It will be the same.

    import re
    import subprocess
    device_re = re.compile("Bus\s+(?P<bus>\d+)\s+Device\s+(?P<device>\d+).+ID\s(?P<id>\w+:\w+)\s(?P<tag>.+)$", re.I)
    df = subprocess.check_output("lsusb")
    devices = []
    for i in df.split('\n'):
    if i:
    info = device_re.match(i)
    if info:
    dinfo = info.groupdict()
    dinfo['device'] = '/dev/bus/usb/%s/%s' % (dinfo.pop('bus'), dinfo.pop('device'))
    devices.append(dinfo)
    print devices

    ---------------------------------------------------------------------------------------------------------------------------------------------------------

    --If the reply is helpful, please Upvote and Accept it as an answer–


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.