larskanis/libusb

More explicit example in the main README?

rubyFeedback opened this issue · 1 comments

Hey there Lars,

Right now the samep code shows this:

usb = LIBUSB::Context.new
device = usb.devices(idVendor: 0x04b4, idProduct: 0x8613).first

I don't know how to obtain these 0x04b4 entries.

When I do this I get "nil" value.

Is there some way to obtain a list of all ids currently plugged in? I have an USB stick plugged in.

Not sure how to get the vendor id.

Could the example show this for when you insert a new USB device, how to find out the ID and
then use that to query content, or auto-mount at a later time? Right now this is an obstacle as
I don't know how to get the vendor id as such. Perhaps the example can be extended to
find out the IDs somehow. Thanks.

To retrieve all connected devices, it's best to use irb -rlibusb and call devices without arguments like so:

LIBUSB::Context.new.devices

It shows something like:

=> 
[#<LIBUSB::Device 4/1 1d6b:0003 ? ? ? (Hub (00,03))>,                                   
 #<LIBUSB::Device 3/1 1d6b:0002 ? ? ? (Hi-speed Hub with single TT)>,                   
 #<LIBUSB::Device 2/1 1d6b:0003 ? ? ? (Hub (00,03))>,                                   
 #<LIBUSB::Device 1/3 0489:e0a2 ? ? ? (Bluetooth)>,                                     
 #<LIBUSB::Device 1/2 0bda:58f4 ? ? ? (Interface Association Descriptor)>,              
 #<LIBUSB::Device 1/4 27c6:5385 ? ? ? (Interface Association Descriptor)>,              
 #<LIBUSB::Device 1/1 1d6b:0002 ? ? ? (Hi-speed Hub with single TT)>]                   

The left number is the vendor ID and the right number is the product ID.
Alternatively you can use lsusb on the command line.