paritytech/libusb-rs

Name: libusb-rs

Owner: Parity Technologies

Description: A safe Rust wrapper for libusb.

Forked from: dcuddeback/libusb-rs

Created: 2017-01-31 14:28:43.0

Updated: 2018-02-20 04:36:06.0

Pushed: 2018-01-15 09:06:16.0

Homepage:

Size: 841

Language: Rust

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Libusb

This crate provides a safe wrapper around the native libusb library. It applies the RAII pattern and Rust lifetimes to ensure safe usage of all libusb functionality. The RAII pattern ensures that all acquired resources are released when they're no longer needed, and Rust lifetimes ensure that resources are released in a proper order.

Dependencies

In order to use the libusb crate, you must have the native libusb library installed where it can be found by pkg-config.

All systems supported by the native libusb library are also supported by the libusb crate. It's been tested on Linux, OS X, and Windows.

Cross-Compiling

The libusb crate can be used when cross-compiling to a foreign target. Details on how to cross-compile libusb are explained in the libusb-sys crate's README.

Usage

Add libusb as a dependency in Cargo.toml:

endencies]
sb = "0.3"

Import the libusb crate. The starting point for nearly all libusb functionality is to create a context object. With a context object, you can list devices, read their descriptors, open them, and communicate with their endpoints:

rn crate libusb;

ain() {
let mut context = libusb::Context::new().unwrap();

for mut device in context.devices().unwrap().iter() {
    let device_desc = device.device_descriptor().unwrap();

    println!("Bus {:03} Device {:03} ID {:04x}:{:04x}",
        device.bus_number(),
        device.address(),
        device_desc.vendor_id(),
        device_desc.product_id());
}

Contributors
License

Copyright © 2015 David Cuddeback

Distributed under the MIT License.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.