Skip to main content

riden

An asynchronous client for Riden laboratory power supplies (RD6006, RD6006P, RD6006-Max, RD6012, RD6012P, RD6012H, RD6018, RD6018P, RD6024, RD6030, RK6006, RK6006H, RK6012, RK6018, RK4206H, RK8009).

It speaks Modbus RTU over a regular serial port or Bluetooth Low Energy (BLE).

Features

  • asyncio API: async with Riden.connect(...) as rd: ...;
  • Bluetooth LE via bt:// URLs on Linux, macOS and Windows (bleak);
  • Modbus RTU through tmodbus, including CRC/framing, timeouts and automatic reconnect;
  • 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 detection and per-model voltage/current scaling, including the RD6012P switchable current range.

Requirements

  • Python 3.14 or newer;
  • tmodbus[async-serial] for Modbus RTU (installed automatically);
  • bleak for Bluetooth LE (installed automatically);
  • Linux with BlueZ, macOS, or Windows for BLE; any OS supported by serialx 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

import asyncio

from riden import Riden


async def main() -> None:
    async with Riden.connect("bt://E1:F9:C6:24:71:C8") as rd:
        print(await rd.status())

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

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


if __name__ == "__main__":
    asyncio.run(main())

The address above is the BLE address, not the Classic SPP MAC. All Riden modules advertise under the same name (RK6006), so the URL takes an address; a device name cannot tell several supplies apart.

For USB serial, pass the device path:

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

The USB port is opened at 115200 baud, the factory setting. If the baud rate was changed in the device menu (9600, 19200, 38400, 57600), pass it explicitly. timeout is the Modbus response timeout in seconds (default 1.0), and delay is the pause between transactions (default 0.02):

async with Riden.connect("/dev/ttyUSB0", baudrate=9600, timeout=0.5) as rd:
    ...

BLE has no baud rate; baudrate applies only to serial ports. The BLE connection timeout is the connect_timeout argument of Riden.connect.

auto_reconnect (default True) enables tmodbus's automatic reconnect. Set it to False for a strict one-shot session.

Construction parses the URL and builds the tmodbus client without I/O. async with connects and reads the identity; a failed open closes the client again. close() is idempotent.

USB works only when the USB interface is selected in the device menu.

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

Several supplies in one loop

All clients share the caller's asyncio loop; no threads are involved:

import asyncio

from riden import Riden


async def main() -> None:
    async with (
        Riden.connect("bt://<MAC1>") as master,
        Riden.connect("bt://<MAC2>") as follower1,
        Riden.connect("bt://<MAC3>") as follower2,
    ):
        while True:
            values = await master.read("v", "i")
            v, i = values["v"], values["i"]

            await asyncio.gather(
                follower1.write({"v_set": v, "i_set": i}),
                follower2.write({"v_set": v, "i_set": i}),
            )
            await asyncio.sleep(2)


if __name__ == "__main__":
    asyncio.run(main())

async with opens the clients sequentially, which also avoids BlueZ's InProgress error from simultaneous discoveries. To connect several supplies in parallel, scan once and pass the discovered BLEDevice objects directly:

import asyncio

from bleak import BleakScanner
from riden import Riden

MAC1, MAC2, MAC3 = "E1:F9:C6:24:71:C8", "26:05:E9:A3:00:37", "AA:BB:CC:DD:EE:FF"


async def main() -> None:
    found = await BleakScanner.discover(timeout=5, return_adv=True)
    devices = [
        device for address, (device, _adv) in found.items()
        if address in {MAC1, MAC2, MAC3}
    ]

    rds = [Riden.connect(device) for device in devices]
    await asyncio.gather(*(rd.open() for rd in rds))
    try:
        ...
    finally:
        await asyncio.gather(*(rd.close() for rd in rds))


asyncio.run(main())

BleTransport is still exported for custom UUIDs or timeouts; Riden.connect accepts a prebuilt transport as well.

Example: voltage sweep + status

import asyncio

from riden import Riden


async def main() -> None:
    async with Riden.connect("bt://E1:F9:C6:24:71:C8") as rd:
        try:
            await rd.write(v_set=0.0, i_set=0.1, en=True)

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


asyncio.run(main())

Bluetooth LE

The BLE transport uses bleak and works on Linux, macOS and Windows. The Riden module does not require pairing: power the supply on and connect. All modules advertise as RK6006, so use the BLE address, not the name. On the tested RK6006/RK6012 the BLE address is the Classic SPP MAC minus one; a BLE scan (bluetoothctl, BleakScanner) shows the exact address. On macOS the BLE address is a CoreBluetooth UUID rather than a MAC.

The bt:// scheme is accepted. Everything after :// is passed to bleak as the BLE address; there is no URL query parsing:

async with Riden.connect(
    "bt://E1:F9:C6:24:71:C8", connect_timeout=5
) as rd:
    ...

timeout, delay and connect_timeout are regular arguments of Riden.connect, as with any other port.

No keepalive is needed: both tested Riden BLE modules keep an idle link for at least a minute. If a particular adapter drops an idle link, tmodbus's automatic reconnect opens it again on the next transaction.

RD6012P / RD6012PW current range

These models have two current ranges, switched on the front panel: 6 A with 0.1 mA resolution and 12 A with 1 mA resolution. The selected range is reported in register 20 (Field.I_RANGE: 0 is 6 A, otherwise 12 A), and the library scales every output current by the range that is actually selected: 10000 for 6 A, 1000 for 12 A.

Reading a current also reads the range, in the same transaction:

# I (11) and I_RANGE (20): one read, registers 11-20
i = (await rd.read("i"))["i"]

A write needs the range to encode the current, so the range is read first and then the setpoint is written. If the caller supplies i_range, it is used as-is, nothing is read, and the range register is written before the current:

# 1 read of I_RANGE, then 1 write of I_SET
await rd.write(i_set=0.5)

# No reads: I_RANGE is written first, then I_SET
await rd.write(i_set=0.5, i_range=0)

Every preset M0..M9 has its own range register, so a preset takes five registers instead of four (V, I, OVP, OCP, I_RANGE):

Preset V I OVP OCP I_RANGE
M0 80 81 82 83 84
M1 85 86 87 88 89
...
M9 125 126 127 128 129

M*_I and M*_OCP are scaled by their own M*_I_RANGE, so a complete preset is still one transaction and needs no reads:

# One write of five registers starting at 85
await rd.write(m1_v=5.0, m1_i=1.0, m1_ovp=60.0, m1_ocp=1.0, m1_i_range=0)

On models without a selectable range, M0_I_RANGE..M9_I_RANGE are virtual: reading them returns False, and writing them is accepted but changes nothing. I_RANGE is a real register on all models; models without a range switch report 0.

The 12 A range also has its own output-current calibration pair, Field.CAL_I12_ZERO / Field.CAL_I12_SCALE (registers 63 and 64).

One thing is not verified on hardware: whether the device rescales currents already stored in a preset when the front-panel range changes. The library always writes a preset's currents together with its range register, so a freshly written preset is consistent.

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 = (await rd.read("v", "i", "p")).values()

# V_SET (8) and EN (18): still 1 transaction, but registers 8-18 (11 registers)
await 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. A value scaled by another field needs that field first: a missing dependency is read in one transaction, while a dependency passed by the caller is used as-is.

# V_SET (8) and I_SET (9) are adjacent: 1 transaction
await 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
await 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://E1:F9:C6:24:71:C8"

just --list shows the remaining tasks.

License

MIT — see LICENSE.

Metadata

Release files for riden 1.0.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 1.0.0
File Size Uploaded Provenance Actions
riden-1.0.0.tar.gz 21.7 kB Without provenance Details for riden-1.0.0.tar.gz

Built distribution (wheel)

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

Total release size: 45.7 kB

Release files / riden-1.0.0.tar.gz

Download URL riden-1.0.0.tar.gz
Size 21.7 kB
Tags Source
SHA-256 checksum
How to use checksums
08e9fcf9ed51ad85661de0617d9784319e026d49c7f5e215c66b83511a0b9f4f
BLAKE2b-256 checksum
How to use checksums
477638d0de5f6672ab587dfd256630f9c2763e6e13a56b47e56a8ccaf01c24b7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.8 {"installer":{"name":"uv","version":"0.13.8","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-1.0.0-py3-none-any.whl

Download URL riden-1.0.0-py3-none-any.whl
Size 24.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
129edba9d7543ffd0918e457d321c4003c72c4564d58d8b85ee38becf8869c14
BLAKE2b-256 checksum
How to use checksums
31e9d993974a97912b4d4d4351b2c4df423ad073086825417a955221afc26624
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.8 {"installer":{"name":"uv","version":"0.13.8","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 1.0.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