Demo: Belt Connection¶
Script: respyra/demos/demo_belt_connection.py
What it demonstrates: Basic belt connectivity and polling — no PsychoPy required.
How to run¶
python -m respyra.demos.demo_belt_connection
What it does¶
Connects via BLE using proximity pairing (nearest device). If BLE fails, automatically falls back to USB.
Prints device info from the internal gdx object.
Reads 100 samples (~10 seconds at 10 Hz), printing each timestamp and force reading.
Stops the belt cleanly in a
finallyblock.
Key code patterns¶
BLE-first with USB fallback¶
try:
belt = BreathBelt(connection='ble', device_to_open='proximity_pairing')
belt.start()
except BreathBeltError:
belt = BreathBelt(connection='usb', device_to_open=None)
belt.start()
Polling with get_latest()¶
sample = belt.get_latest()
if sample is not None:
timestamp, force = sample
get_latest() returns the most recent sample and discards any older queued samples. Returns None if no new data is available. This is ideal for display updates where only the current value matters.
Expected output¶
Attempting BLE connection (proximity pairing)...
[belt] Scanning BLE...
[belt] Device found. Configuring sensors [1]...
BLE connection succeeded.
Device info: {'name': 'GDX-RB 081000A1', ...}
Reading 100 samples (press Ctrl-C to abort)...
[ 0] t=1740441234.567 force=4.32 N
[ 1] t=1740441234.667 force=4.28 N
...
Belt stopped. Done.