libusbsio Python Wrapper

2.2.0 · active · verified Thu Apr 16

libusbsio is a Python wrapper for the NXP LIBUSBSIO C library, designed to facilitate interaction with NXP's USB-to-I2C/SPI/GPIO bridge devices. It provides a high-level API for enumerating, opening, and communicating with supported hardware from Python applications. The current version is 2.2.0, with updates typically tied to enhancements or bug fixes in the underlying C library or the Python binding itself.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to enumerate available NXP SiO devices and open the first one found. It uses a context manager (`with ... as`) to ensure the device is properly closed after use. Note that the underlying NXP LIBUSBSIO C library must be installed on your system for this code to run successfully.

import libusbsio

try:
    # Enumerate available SiO devices
    devices = libusbsio.SiOBus.enumerate()

    if not devices:
        print("No SiO devices found. Ensure device is connected and C library is installed.")
    else:
        print(f"Found {len(devices)} SiO devices:")
        for i, dev_info in enumerate(devices):
            print(f"  [{i}] Path: {dev_info.path}, Serial: {dev_info.serial_number}")

        # Example: Open the first detected device
        first_device_path = devices[0].path
        print(f"\nAttempting to open device at path: {first_device_path}")
        
        with libusbsio.SiODevice(first_device_path) as device:
            print(f"Successfully opened device: {first_device_path}")
            # Now you can interact with the device, e.g., read/write I2C/SPI
            # For example, to set an I2C speed (check your device capabilities):
            # device.set_i2c_speed(100000) # 100 kHz
            print("Device interaction complete. Device will close automatically.")

except libusbsio.SiOError as e:
    print(f"A libusbsio error occurred: {e}")
except Exception as e:
    print(f"An unexpected error occurred: {e}")

view raw JSON →