riden
A simple synchronous, single-threaded 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 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 detection and per-model voltage/current scaling, including the RD6012P switchable current range;
- 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") 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:
...
The 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 read timeout in seconds (default 1.0), write_timeout the
write timeout (default None, writes block, as in pyserial):
with Riden.connect("/dev/ttyUSB0", baudrate=9600, timeout=0.5) as rd:
...
RFCOMM has no baud rate, so for bt:// the baudrate value only sets the
Modbus inter-frame timing.
For any other port setting (parity, stop bits, flow control, ...), create the port with pyserial and pass the object:
import serial
port = serial.serial_for_url(
"/dev/ttyUSB0", baudrate=115200, parity=serial.PARITY_EVEN, timeout=1.0,
do_not_open=True,
)
with Riden.connect(port) as rd:
...
baudrate, timeout and write_timeout apply only when the library creates
the port from a string. A port object keeps its own settings, so pyserial
defaults apply to anything not set: 9600 baud and timeout=None, which blocks
a read forever on a silent device. Set both explicitly.
The client takes over the port's lifetime: leaving with (or close())
closes it, and a reconnect reopens it, even if it was passed in already open.
do_not_open=True is not required, but without it the port (for bt://, the
Bluetooth connection) is opened immediately rather than by with.
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.
Example: voltage sweep + status
import time
from riden import Riden
with Riden.connect("bt://E2:F9:C6:24:71:C8?channel=1") 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&security=medium
| Parameter | Default | Meaning |
|---|---|---|
channel |
1 |
RFCOMM channel, 1..30 |
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.
The URL holds only link settings. timeout (read) and write_timeout are
regular port settings, passed as arguments, with pyserial semantics: None
blocks, 0 does not block, a positive value is a deadline for the whole call.
Riden.connect("bt://...", timeout=0.5) defaults to 1.0 s;
serial.serial_for_url("bt://...", timeout=0.5) and BtSerial(mac, timeout=0.5)
default to None, as pyserial does.
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)
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 = 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
rd.write(i_set=0.5)
# No reads: I_RANGE is written first, then I_SET
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
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 = 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. 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
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"
just --list shows the remaining tasks.
License
MIT — see LICENSE.
Metadata
Release files for riden 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| riden-0.3.0.tar.gz | 29.3 kB | Without provenance | Details for riden-0.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| riden-0.3.0-py3-none-any.whl | Python 3 | none | any | Details for riden-0.3.0-py3-none-any.whl |
Total release size: 64.4 kB
Release files / riden-0.3.0.tar.gz
| Download URL | riden-0.3.0.tar.gz |
|---|---|
| Size | 29.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
84869e683c5a78dcef7226f64cced2a24d5712844668fffeb6397d5f96d3538f
|
|
BLAKE2b-256 checksum How to use checksums |
08c57362d2d42482230e4084fce867fd58a5f988cb65573c1475235bb025589f
|
| 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.3.0-py3-none-any.whl
| Download URL | riden-0.3.0-py3-none-any.whl |
|---|---|
| Size | 35.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
bb7023f91bb2f8a40f81c8cd6278a43f92a3868088f7bccd72fa576021fb6a4b
|
|
BLAKE2b-256 checksum How to use checksums |
90effd6941fcd2222cdb170a9ff1eade6564031cc97235d005e2c0423635201a
|
| 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.3.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.