Skip to main content

Python implementation of the cusb interface for managed USB hubs

Project description

pycusb

A python library for managed USB hubs that are usually operated by a command line tool called cusbi (Linux Intel), cusba (Linux Arm), cusbm (Mac), or CUSBC/CUSBCTL (Windows), e.g., hubs from the companies EXSYS and StarTech.

Usage

Usage as library

from cusb import CUsb
import time

# Example:
path_to_device = "/dev/serial/by-id/usb-FTDI_FT232R_USB_UART_B0036Y2H-if00-port0"
port = 1

with CUsb(path_to_device) as hub:
    hub.port_power_on(port, False)
    time.sleep(1)
    hub.port_power_on(port, True)

Usage as CLI tool

$ pycusb --help
CUSB Hub Control

This CLI tool is able to *set* or *get* the state of the managed USB hub. It
can *save* the current state as the default, so after a power loss, this state
will be restored. The hub can also be *reset*, or a *factory reset* can be
issued, resetting any stored state and/or set password.

If a password is required, it can be provided to all commands as an option. By
default the implementation uses "pass", which is the factory default. The *get*
command does not need the password to succeed.

Usage:
  pycusb [options] get <port> PATH
  pycusb [options] set <port> (on|off) PATH
  pycusb [options] save PATH
  pycusb [options] reset PATH
  pycusb [options] factory_reset PATH
  pycusb -h | --help

Arguments:
  PATH                      Path to serial device file controlling the hub.

Options:
  -p --password=<password>  Password for the hub [default: pass].
  --force                   Continue despite unknown firmware version. This may
                            have unknown consequences and could cause damage.

Example: switch off port 1 for 1 second

pycusb set 1 off /dev/serial/by-id/usb-FTDI_FT232R_USB_UART_B0036Y2H-if00-port0
sleep 1
pycusb set 1 on /dev/serial/by-id/usb-FTDI_FT232R_USB_UART_B0036Y2H-if00-port0

Installation

Installation as library

Add pycusb to your pyproject.toml:

[project]
dependencies = [
    "pycusb",
]

Installation as CLI tool

Create and activate a virtual environment, then run

pip install pycusb

Development

Clone the repo, create and activate a virtual environment, then install dependencies with:

pip install -e '.[dev]'

Test with

pytest test/test.py

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pycusb-0.3.2.tar.gz (5.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pycusb-0.3.2-py2.py3-none-any.whl (6.2 kB view details)

Uploaded Python 2Python 3

File details

Details for the file pycusb-0.3.2.tar.gz.

File metadata

  • Download URL: pycusb-0.3.2.tar.gz
  • Upload date:
  • Size: 5.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pycusb-0.3.2.tar.gz
Algorithm Hash digest
SHA256 31132ed45682d8848346b2d1f2d9f774738daee0b77724ee17075b6789acb773
MD5 1c6fbdef4ec3880b4839d057e1c51348
BLAKE2b-256 19b0b06e975039b053ef6a93de29ca0e0d999986051438320cdf6f1d0169c036

See more details on using hashes here.

Provenance

The following attestation bundles were made for pycusb-0.3.2.tar.gz:

Publisher: release.yaml on gschwaer/pycusb

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pycusb-0.3.2-py2.py3-none-any.whl.

File metadata

  • Download URL: pycusb-0.3.2-py2.py3-none-any.whl
  • Upload date:
  • Size: 6.2 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pycusb-0.3.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 3fa9303847b26de1e2159627b734ba6284819335784a909c31728df85f9dcfdc
MD5 712bb6c79cd27dd7b0f79bb5541f0f21
BLAKE2b-256 7fa84d03ad500c47a23b035b4416895b8bd5878f56a03343aa05b2bb8356a5d7

See more details on using hashes here.

Provenance

The following attestation bundles were made for pycusb-0.3.2-py2.py3-none-any.whl:

Publisher: release.yaml on gschwaer/pycusb

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page