Raulp
Raulp

Reputation: 8196

Enumerating a USB device in Linux

Is there a command to enumerate the USB device (HID) programmatically or through some commands?

In Windows we can do the same using Device Manager or devcon. I tried doing rmmod and insmoding the device driver, but it didn't enumerate the device.

Upvotes: 0

Views: 5599

Answers (2)

boardrider
boardrider

Reputation: 6185

To see all USB devices' data:

#!/usr/bin/env python
import sys
import usb.core

# find USB devices
devices = usb.core.find(find_all=True)
# loop through devices, printing vendor and product ids in decimal and hex
for cfg in devices:
  sys.stdout.write('Decimal VendorID=' + str(cfg.idVendor) + ' & ProductID=' + str(cfg.idProduct) + '\n')
  sys.stdout.write('Hexadecimal VendorID=' + hex(cfg.idVendor) + ' & ProductID=' + hex(cfg.idProduct) + '\n\n')

(Source: enter link description here)

Upvotes: 1

jcoppens
jcoppens

Reputation: 5440

Generally, USB devices are 'enumerated' internally in the kernel driver. Any time you list them with lsusb, this will show the actual devices present at that time. If you want a detailed listing of each devices, add -v (or --verbose) to the command.

Is that the information you are looking for?

Upvotes: 0

Related Questions