File: descriptors.rs

package info (click to toggle)
rust-nusb 0.1.13-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 548 kB
  • sloc: makefile: 2
file content (38 lines) | stat: -rw-r--r-- 943 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
use nusb::DeviceInfo;

fn main() {
    env_logger::init();
    for dev in nusb::list_devices().unwrap() {
        inspect_device(dev);
    }
}

fn inspect_device(dev: DeviceInfo) {
    println!(
        "Device {:03}.{:03} ({:04x}:{:04x}) {} {}",
        dev.bus_number(),
        dev.device_address(),
        dev.vendor_id(),
        dev.product_id(),
        dev.manufacturer_string().unwrap_or(""),
        dev.product_string().unwrap_or("")
    );
    let dev = match dev.open() {
        Ok(dev) => dev,
        Err(e) => {
            println!("Failed to open device: {}", e);
            return;
        }
    };

    match dev.active_configuration() {
        Ok(config) => println!("Active configuration is {}", config.configuration_value()),
        Err(e) => println!("Unknown active configuration: {e}"),
    }

    for config in dev.configurations() {
        println!("{config:#?}");
    }
    println!("");
    println!("");
}