2

I have a problem obtaining information about /dev/usb/lp* devices.

The lsusb command gives me USB bus and device IDs, and a name of the device but I can't figure out how to get it to tell me the name of the corresponding /dev/usb/lp* device.

I don't have CUPS available.

EndruPL
  • 141
  • 1
  • 7
  • What do you want to do? Go from the `lsusb` output to `/dev/usb/lp*`? Or from `/dev/usb/lp*` to the USB device? – rodrigo Sep 25 '15 at 13:43
  • I want to go from `lsusb` output to `/dev/usb/lp*`. I need to do this to map `lp*` devices to printers connected to my system and display some info like manufacturer, model etc. and be able to `cat` files to the device (which I seem to be unable to do via `/dev/usb/BUS/ID`). – EndruPL Sep 28 '15 at 12:51

1 Answers1

4

You can use libudev to get the equivalent of the following command:

$ udevadm info -a /dev/usb/lp*

In my PC it prints something like:

  looking at device '/devices/pci0000:00/0000:00:1a.0/usb1/1-1/1-1.3/1-1.3:1.1/usbmisc/lp2':
    KERNEL=="lp2"
    SUBSYSTEM=="usbmisc"
    DRIVER==""

  looking at parent device '/devices/pci0000:00/0000:00:1a.0/usb1/1-1/1-1.3/1-1.3:1.1':
    KERNELS=="1-1.3:1.1"
    SUBSYSTEMS=="usb"
    DRIVERS=="usblp"
    ...

  looking at parent device '/devices/pci0000:00/0000:00:1a.0/usb1/1-1/1-1.3':
    KERNELS=="1-1.3"
    SUBSYSTEMS=="usb"
    DRIVERS=="usb"
    ...
    ATTRS{idProduct}=="341b"
    ATTRS{idVendor}=="04e8"
    ...

And there they are! The wanted idProduct and the idVendor

You can also get the information by navigating the /sys directory manually:

$ ls -l /dev/usb/lp2
crw-rw---- 1 root lp 180, 2 Sep 27 11:46 /dev/usb/lp2

$ readlink -f /sys/dev/char/180:2
/sys/devices/pci0000:00/0000:00:1a.0/usb1/1-1/1-1.3/1-1.3:1.1/usbmisc/lp2

$ cat /sys/devices/pci0000:00/0000:00:1a.0/usb1/1-1/1-1.3/{idVendor,idProduct}
04e8
341b
rodrigo
  • 94,151
  • 12
  • 143
  • 190