int main(void) usb_context *ctx = NULL; usb_device *dev = NULL; uint8_t buffer[512]; int rc;
# Create a build directory mkdir build && cd build
usbutil_close(dev); usbutil_exit(ctx); return 0;
# Install (optional, system‑wide) sudo cmake --install . | Language | Package Manager | Install Command | |----------|-----------------|-----------------| | Python | pip | pip install usbutil-py | | Rust | cargo | cargo add usbutil | | .NET | NuGet | dotnet add package UsbUtil.Net | thmyl brnamj usbutil v2.2
def device_left(dev): print("Device removed") dev.release_interface(0) dev.close()
def device_arrived(dev): print(f"Device arrived: dev.vendor_id:04x:dev.product_id:04x") # Open and claim interface 0 dev.open() dev.claim_interface(0)
async fn async_bulk_read(dev: &UsbDevice) -> TransferResult let mut buf = vec![0u8; 1024]; dev.bulk_read_async(0x82, &mut buf).await int main(void) usb_context *ctx = NULL; usb_device *dev
All packages ship pre‑compiled binaries for the most common architectures (x86_64, ARM64, ARMv7). 6.1 C/C++ (Bulk Transfer) #include "usbutil.h" #include <stdio.h>
# Build cmake --build . --config Release
// Spawn the async task on the built‑in scheduler let result = block_on(async_bulk_read(&dev))?; println!("Read {} bytes", result.bytes_transferred); Ok(()) } | Header / Module | Important Types | Representative Functions | |-----------------|-----------------|---------------------------| | usbutil.h | usb_context , usb_device , usb_endpoint | usbutil_init() , usbutil_open_by_vidpid() , usbutil_bulk_write() , usbutil_control() | | usbutil_async.h | usb_future , usb_promise | usbutil_bulk_read_async() , usbutil_submit_transfer() | | usbutil_plugin.h | usb_plugin , usb_plugin_api | usbutil_plugin_load() , usbutil_plugin_register_class() | | Python usbutil module | Device , EventLoop | Device.open() , Device.control_transfer() , EventLoop.run() | | Rust crate usbutil | UsbContext , UsbDevice , Transfer | UsbDevice::control() , UsbDevice::bulk_read_async() | | .NET UsbUtil.Net | UsbDevice , UsbTransfer | UsbDevice.Open() , UsbDevice.ReadAsync() | --config Release // Spawn the async task on
Note: The embedded ports ship a reduced feature set (no hot‑plug, no plug‑in manager) to keep RAM footprint < 64 KB. | Milestone | Target Release | Planned Features | |-----------|----------------|----------------
# Configure (add -DUSBUTIL_SECURE=ON for secure mode) cmake .. -DCMAKE_BUILD_TYPE=Release -DUSBUTIL_SECURE=ON
fn main() -> usbutil::Result<()> { let ctx = UsbContext::new()?; let dev = ctx.open_device(0x1234, 0x5678)?;