#usb-device #cross-platform #devices #connected #id #product #vendor

usb_enumeration

A cross platform library that returns details of currently connected USB devices

5 unstable releases

0.2.1 Oct 28, 2024
0.2.0 Nov 30, 2022
0.1.2 May 10, 2021
0.1.1 Apr 1, 2021
0.0.3 Aug 21, 2020

#662 in Hardware support

Download history 28/week @ 2024-07-25 11/week @ 2024-08-01 8/week @ 2024-08-08 7/week @ 2024-08-15 2/week @ 2024-08-22 3/week @ 2024-08-29 2/week @ 2024-09-12 33/week @ 2024-09-19 25/week @ 2024-09-26 19/week @ 2024-10-03 4/week @ 2024-10-10 126/week @ 2024-10-24 36/week @ 2024-10-31 4/week @ 2024-11-07

167 downloads per month
Used in 5 crates (4 directly)

MIT license

24KB
451 lines

usb_enumeration

A cross platform Rust library that returns the vendor and product IDs of currently connected USB devices

Actions Status

Example

let devices = usb_enumeration::enumerate(None, None);

println!("{:#?}", devices);

// Outputs:
// [
//   UsbDevice {
//       id: "USB\\VID_0CE9&PID_1220\\0000000004BE",
//       vendor_id: 3305,
//       product_id: 4640,
//       description: Some(
//           "PicoScope 4000 series PC Oscilloscope",
//       ),
//   },
//   UsbDevice {
//       id: "USB\\VID_046D&PID_C52B\\5&17411534&0&11",
//       vendor_id: 1133,
//       product_id: 50475,
//       description: Some(
//           "USB Composite Device",
//       ),
//   },
//   UsbDevice {
//       id: "USB\\VID_046D&PID_C52B&MI_00\\6&12D311A2&0&0000",
//       vendor_id: 1133,
//       product_id: 50475,
//       description: Some(
//           "Logitech USB Input Device",
//       ),
//   },
//     etc...
// ]

You can also subscribe to events using the Observer:

use usb_enumeration::{Observer, Event};

let sub = Observer::new()
    .with_poll_interval(2)
    .with_vendor_id(0x1234)
    .with_product_id(0x5678)
    .subscribe();

// when sub is dropped, the background thread will close

for event in sub.rx_event.iter() {
    match event {
        Event::Initial(d) => println!("Initial devices: {:?}", d),
        Event::Connect(d) => println!("Connected device: {:?}", d),
        Event::Disconnect(d) => println!("Disconnected device: {:?}", d),
    }
}

License: MIT

Dependencies

~100–455KB