Skip to main content

riden

A simple synchronous, single-threaded client for Riden laboratory power supplies (RD6006, RD6006P, RD6012, RD6012P, RD6018, RD6024, RK6006).

It speaks Modbus RTU over a regular serial port or Bluetooth SPP (RFCOMM) on Linux.

Features

  • synchronous API with no background event loop: with Riden.connect(...) as rd: ...;
  • Bluetooth on Linux via bt:// URLs (AF_BLUETOOTH + RFCOMM);
  • batched I/O instead of one transaction per field: any set of fields is read in one Modbus transaction, and written in one transaction per contiguous register block;
  • automatic model and voltage/current scale detection on connect;
  • ready-made transport stack: transaction pacing, reconnect, logging, and optional keepalive pings;
  • encrypted Bluetooth link by default, which keeps idle connections alive.

Requirements

  • Python 3.14 or newer;
  • Linux with BlueZ for Bluetooth SPP;
  • any OS supported by pyserial for USB serial.

Install

uv add riden

or with pip:

pip install riden

From source:

git clone https://github.com/acc15/riden
cd riden
uv sync

Quick start

from riden import Riden

with Riden.connect("bt://E2:F9:C6:24:71:C8?channel=1&timeout=0.5") as rd:
    print(rd.status())

    # Several fields — a single device transaction.
    v, i, p = rd.read("v", "i", "p").values()
    print(v, i, p)

    # Adjacent registers — a single write transaction.
    rd.write(v_set=5.0, i_set=0.1)
    rd.write(en=True)

For USB serial, pass the device path:

with Riden.connect("/dev/ttyUSB0") as rd:
    ...

Field names are case-insensitive, so "V" and "v" refer to the same field.

Example: voltage sweep + status

import time

from riden import Riden

with Riden.connect("bt://E2:F9:C6:24:71:C8?channel=1&timeout=0.5") as rd:
    try:
        rd.write(v_set=0.0, i_set=0.1, en=True)

        for voltage in range(0, 60, 5):
            rd.write(v_set=float(voltage))
            time.sleep(2)
            print(rd.status())
    finally:
        rd.write(v_set=0.0, en=False)

Bluetooth on Linux

Pair the device once before the first connection (the PIN is usually 1234):

bluetoothctl pair AA:BB:CC:DD:EE:FF

bluetoothctl trust is not required: it only affects connections managed by bluetoothd (auto-reconnect, incoming connections), not the RFCOMM socket this library opens.

URL format:

bt://AA:BB:CC:DD:EE:FF?channel=1&timeout=0.5
Parameter Default Meaning
channel 1 RFCOMM channel, 1..30
timeout 0.5 read/write timeout, seconds
connect_timeout 10 connection timeout, seconds
security medium low, medium, high, fips (see below)

Only the parameters present in the URL are passed on; the defaults live in BtSerial. An unknown parameter or an invalid value raises ValueError. BtSerial is registered as a pyserial URL handler, so bt:// works anywhere a regular serial port is accepted.

Security level

security sets the RFCOMM socket security level (BT_SECURITY in BlueZ), which the kernel enforces before the connection is used:

Level Requirement
low no authentication, no encryption
medium authenticated and encrypted link; any stored link key will do
high as medium, but the link key must be MITM-protected
fips Secure Connections only

The default is medium. A plain Linux RFCOMM socket uses low, and with it the Bluetooth module of the Riden supply (tested on RK6012) drops the link after about 8–10 s without traffic: the next request fails with TimeoutError: [Errno 110] Connection timed out. In an HCI capture (btmon) this is Disconnect Complete with reason Connection Timeout (0x08): the PSU stops answering at the radio level, while the host never asks to disconnect. With an encrypted link the same device stays connected while idle (verified for 60 s). The behaviour did not depend on the USB dongle (reproduced on Realtek and Broadcom controllers). Android apps are not affected because Android opens secure RFCOMM sockets by default.

medium needs a paired device: the kernel authenticates with the stored link key, without any prompt. high usually fails with Riden supplies, because a key from legacy pairing with a 4-digit PIN is not considered MITM-protected. Use security=low only for a device that cannot be paired, and enable keepalive pings in that case:

with Riden.connect("bt://AA:BB:CC:DD:EE:FF?security=low", keepalive=5.0) as rd:
    ...

When constructing BtSerial directly, pass the enum:

from riden.bt import BtSerial, SecurityLevel

port = BtSerial("AA:BB:CC:DD:EE:FF", security=SecurityLevel.LOW)

Performance

Reads and writes are batched differently, because Modbus can read a register range with gaps in it, but it cannot write a sparse list of registers.

read() always uses one transaction. It computes the overall address range of the requested fields and reads all of it at once, including any registers between them, then decodes the fields:

# V (10), I (11), P (12-13): 1 transaction, registers 10-13
v, i, p = rd.read("v", "i", "p").values()

# V_SET (8) and EN (18): still 1 transaction, but registers 8-18 (11 registers)
rd.read("v_set", "en")

Fields far apart make that one transaction longer, so grouping nearby fields is preferable.

write() uses one transaction per contiguous block. It encodes and validates all values first, then merges fields whose registers follow each other without a gap into one block. Every gap starts a new block and a new transaction:

# V_SET (8) and I_SET (9) are adjacent: 1 transaction
rd.write(v_set=5.0, i_set=0.1)

# V_SET (8), I_SET (9) and EN (18): 2 transactions,
# registers 8-9, then register 18
rd.write(v_set=5.0, i_set=0.1, en=True)

Since every value is validated before the first transaction, an invalid value never leaves the device partially updated. A link failure between the transactions still can: if the second write fails, the first one has already been applied.

Development

uv sync
uv build          # sdist + wheel in dist/
just check        # ty + ruff + pytest

Releasing

Releases are prepared with bump-my-version (configured in pyproject.toml). It bumps the version, runs just check, updates uv.lock, builds the artifacts, commits and creates an annotated v<version> tag:

just bump patch           # bump, build, commit and tag
just bump minor           # minor (or major)
just bump minor --dry-run # verify without changing anything
just publish              # upload dist/ to PyPI
just publish --dry-run    # verify the upload without sending
git push --follow-tags    # bump-my-version does not push

The version part is required by bump-my-version: just bump without patch/minor/major fails. just publish uploads the existing dist/ artifacts; just bump already builds them, or run just build explicitly.

Publishing tokens are read from .env (see .env.example). The working tree must be clean: bump-my-version refuses to bump otherwise.

just publish-test uploads the current dist/ to TestPyPI without bumping or tagging. TestPyPI never accepts the same filename twice, even after the release is deleted, so a repeated test needs a new version.

Scripts in scripts/ are run through uv run:

uv run scripts/v_sweep.py
uv run scripts/link_test.py "bt://E2:F9:C6:24:71:C8?channel=1&timeout=0.5"

just --list shows the remaining tasks.

License

MIT — see LICENSE.

Metadata

Release files for riden 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for riden 0.2.0
File Size Uploaded Provenance Actions
riden-0.2.0.tar.gz 20.2 kB Without provenance Details for riden-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for riden 0.2.0
File Interpreter ABI Platform Actions
riden-0.2.0-py3-none-any.whl Python 3 none any Details for riden-0.2.0-py3-none-any.whl

Total release size: 45.5 kB

Release files / riden-0.2.0.tar.gz

Download URL riden-0.2.0.tar.gz
Size 20.2 kB
Tags Source
SHA-256 checksum
How to use checksums
962d9ee0d79bba68f8594153af1c6e8a8f504e2421d7819d1788b6128e4d00ab
BLAKE2b-256 checksum
How to use checksums
362627f9cdde988d999b1c5c2610559966b86563f0fb6ca17bcb9af03708fe08
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.7 {"installer":{"name":"uv","version":"0.13.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Arch Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / riden-0.2.0-py3-none-any.whl

Download URL riden-0.2.0-py3-none-any.whl
Size 25.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
25781d2ccaa3588887616308635e501d218f794c0a2e0c5d7aa455636e07144a
BLAKE2b-256 checksum
How to use checksums
b8318d75286470a3cfd47567482c4a1d1f4f06bfac4843233eaa006a70210c83
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.7 {"installer":{"name":"uv","version":"0.13.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Arch Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for riden 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page