otii-usb-mcp
[](https://github.com/bitqan-ae/otii-ace-mcp/actions/workflows/ci.yml?query=branch%3Amain)
> [!WARNING]
> **Unofficial software.** This is an independent project. It is not affiliated with, endorsed,
> sponsored or supported by Qoitech AB. *Qoitech* and *Otii* are names of Qoitech AB, used here
> only to identify the hardware this software works with. For official software and support,
> contact Qoitech.
>
> **Use at your own risk.** This software switches electrical power to connected equipment. It
> is provided "as is", without warranty of any kind, express or implied (see sections 7 and 8 of
> the [Apache License 2.0](LICENSE)). You are solely responsible for its use and for any damage
> or loss that results, including damage to the instrument, to devices under test or to other
> equipment, loss of data, or injury. Check its behaviour with your own setup before relying on
> it.
# otii-ace-mcp
Python driver, interactive CLI and MCP server for the **Qoitech Otii Ace Pro** power analyzer.
It talks to the device directly over USB and turns it into a building block for automation:
scripts, CI pipelines, lab test benches, and AI agents that debug hardware on their own.
> **Tested device:** Otii Ace Pro (hardware rev 2, firmware 3.2.5). The driver identifies the
> device on connection and refuses to operate any other device type, protocol or firmware
> version.

The power-up of a Zynq-7000 board at 5 V with a 2 A current limit, recorded in the interactive
shell (serial numbers and paths masked):

The bottom panel lines the board's console up with its power on one time axis, so each boot
stage can be read off against the current it draws. The boot loader reports at 0.647 s that it
loaded the 4.9 MB kernel image in 393 ms: the plateau of about 1.65 W before it is that load. The
kernel's own `init at 0.14 s`, arriving at 0.917 s, puts the kernel start at about 0.78 s, where
the power rises and turns busy; the shell prompt at 0.947 s shows the console up. From about
1.52 s the board settles at around 1.45 W. The faint orange steps behind the text show how many
characters per second arrived (right axis).
The board's USB serial adapter is powered by the board itself, so `/dev/ttyUSB0` does not exist
until the output is switched on, and it disappears again when it goes off. `otii-usb` therefore
looks for the port every 5 ms during the recording and opens it the moment it appears, here
475 ms after the switch-on (the shaded part of the panel); after a disconnect it waits for the
port to come back. It joins while the board is already printing: whatever was sent before is
lost, and the first printable character after the port opened starts a line. Arrival times are
measured on the host and placed on the Otii's time axis to about a millisecond.
## Why
**Automation.** Everything the tool does is a Python call or a one-line command with JSON
output: power the device under test, measure voltage, current and power at 50 kS/s, record to CSV
and plots, power-cycle. No GUI in the loop, so the same steps run on a desk, in CI and on a test
rack.
**Automated debugging over MCP.** The MCP server gives an agent hands and eyes on the hardware.
It can flash new firmware, power-cycle the board, record the boot current and read the numbers
back, then compare against the last build: a sleep current that went from 3 µA to 300 µA, a
brown-out at start-up, a radio that never powers down. The agent closes the loop itself
(change → power → measure → reason → change) and leaves CSV files and plots behind for you to
check. Safety is built in: outputs are off and limits are set (5 V, 500 mA) whenever the server
starts or stops, and tools that switch power are marked so the client asks first.
**Easy to extend in Python.** The layers are small and typed. A new device setting is one
`PropertySpec` line; a new analysis is a `SampleSink` that receives numpy arrays; a new command
appears in the CLI, the interactive shell and its completion from one entry in the command
catalogue. The built-in simulator lets you develop and test all of it without hardware.
## Quickstart
### First-time setup
```sh
git clone https://github.com/bitqan-ae/otii-ace-mcp.git
cd otii-ace-mcp
python3 -m venv .venv # create the virtual environment (once)
source .venv/bin/activate # load it
pip install -r requirements.txt # dependencies + this package (editable)
otii-usb --simulate status # works without hardware
```
Plug in the Otii Ace Pro over USB; it shows up as `/dev/ttyACM*` (`lsusb`: `0fce:d1e6`). If the
port is not accessible, add yourself to the `dialout` group and log in again.
### Every new terminal
```sh
cd otii-ace-mcp
source .venv/bin/activate # load the venv; `deactivate` leaves it
otii-usb status
```
Without activating, call the tools directly: `.venv/bin/otii-usb`, `.venv/bin/otii-usb-mcp`.
## Command line
```sh
otii-usb status # identity, output state, setpoint, current limit
otii-usb measure -t 2 # 2 s average/min/max of voltage, current, power
otii-usb record -t 60 # 60 s to otii-<timestamp>.csv and .png
otii-usb record -t 10 --csv run.csv # CSV only (1000 averaged rows per second)
otii-usb record -t 5 --png boot.png # plot only
otii-usb record --png --title "Sensor board, boot" # own plot title (default: model and S/N)
otii-usb record --png --footer "ACME lab" # own note at the bottom right; --no-footer for none
otii-usb record -t 2 --csv fast.csv --raw # every sample (50 kHz)
otii-usb record -t 1 --power-on # output on 50 ms into the recording: the power-up
otii-usb record -t 5 --power-on --png boot.png --serial /dev/ttyUSB0 # with the boot log
otii-usb output on | off # switch the main output
otii-usb power-cycle -o 2 # off for 2 s, then on
otii-usb safe # all outputs off, 5 V setpoint, 500 mA limit
otii-usb --json measure # machine-readable output
otii-usb record --help # options and examples for any command
```
Ctrl-C (or SIGTERM/SIGHUP) stops the running command, switches all outputs off and restores the
5 V / 500 mA defaults. Timed operations show a progress bar on the terminal.
`record --power-on` captures the first milliseconds after powering the device under test. The
main output must be off; it is switched on `--pre` seconds (default 0.05) into the recording and
off again at the end, also on errors. The time the switch-on command was sent (the end of the
last data packet received before it) is reported as `command_sent_s`, drawn as a dashed line in
the plot, and marked in the CSV by an extra column `output_on` (0 before, 1 from the row that
contains it). The output then ramps up a few milliseconds later; the recording shows it.
`record --serial PORT` (with `--baud RATE`, default 115200, 8N1) reads the serial console of the
device under test during the recording and adds a fourth panel below the voltage, labelled with
the port; the example at the top shows one, and how a port that appears only with the power is
found. Each line is marked by a faint vertical line at the arrival of its first printable
character, with the arrival time (bold green) and the received text (black) written upwards behind
the marker. Behind the text, a faint orange distribution shows the printable characters per second
(right axis, topped by the busiest of 250 bins over the recording). Labels never overlap: a line
close to the previous marker gets no marker of its own but follows that marker's label in the next
column, with its own arrival time, as long as it ends before the next marker; lines that do not
fit are left out, and the note at the bottom left says how many lines are shown. The port is only
read, never written. The result reports the line count and when the port was open.
## Interactive mode
```sh
otii-usb -i # or: otii-usb --simulate -i to try it without hardware
```
The shell starts with a banner, puts the device into the safe state and shows the main output
state in the prompt. Tab completes commands, options and file names; ↑ and Ctrl-R search the
history (kept in `~/.local/state/otii-usb/history`); grey text suggests from history.
Example session (values depend on your device under test):
```text
___ _____ ___ ___ _ ____ _____
/ _ \ |_ _||_ _||_ _| / \ / ___|| ____|
| | | | | | | | | | / _ \ | | | _|
| |_| | | | | | | | / ___ \ | |___ | |___
\___/ |_| |___||___| /_/ \_\ \____||_____|
Otii Ace Pro · USB control & measurement · otii-usb 0.1.0
Otii Ace Pro S/N <serial> · board <board serial> · fw 3.2.5 · protocol 3 · /dev/ttyACM0
✔ safe state: outputs OFF, 5 V setpoint, 500 mA limit
otii Ace Pro ○ OFF ❯ output on
✔ main output OFF -> ON
otii Ace Pro ● ON ❯ measure -t 2
✔ main output ON, 2 s window
channel avg min max std samples
mv 5.0000 V 4.9986 V 5.0031 V 452.1 µV 100,050
mc 12.3184 mA 11.9620 mA 12.7741 mA 97.4 µA 100,050
mp 61.5922 mW 59.8094 mW 63.8817 mW 487.2 µW 100,050
otii Ace Pro ● ON ❯ record -t 30 --csv boot.csv --png boot.png
| recording ━━━━━━━━━━━━━━━━━━╸━━━━━━━━━━━━━━━━━━ 52% 0:00:15 eta 0:00:14
✔ recorded 30 s
csv ~/boot.csv (30001 rows, 1000 rows/s)
png ~/boot.png
otii Ace Pro ● ON ❯ power-cycle -o 2
✔ main output ON -> OFF for 2 s -> ON
otii Ace Pro ● ON ❯ help record
otii Ace Pro ● ON ❯ exit
switching outputs off ...
✔ outputs OFF, defaults restored. bye.
```
More examples at the prompt:
```text
help list all commands with an example each
help power-cycle options and examples for one command
status device identity and state
measure -t 0.1 quick 100 ms reading
record 10 s, CSV and PNG with timestamped names
record -t 60 --csv --png both outputs, timestamped names
record --csv slow.csv --rate 10 10 averaged rows per second
record --png a.png --title "Board A" plot titled "Board A"; each record takes its own title
safe --voltage 3.3 --current-limit 0.1 outputs off, then 3.3 V and 100 mA
clear clear the screen
```
Ctrl-C at the prompt clears the line; during a command it stops the command and switches the
outputs off. `exit`, `quit` or Ctrl-D leave the shell with the outputs off.
While the shell is idle it polls the device once per second (`--poll SECONDS`, `0` = off) and
warns in **bold red** when the current reaches the current limit or the device switches the
output off by itself, and in yellow above 90 % of the limit:
```text
⚠ 14:02:17 OVERCURRENT: peak 500.0000 mA reached the current limit 500.0000 mA (polled)
⚠ 14:02:18 main output was switched OFF by the device, not by otii-usb (current limit or protection tripped?)
```
## MCP server
```sh
otii-usb-mcp # stdio server for the attached Otii
otii-usb-mcp --simulate # same, against the simulator
otii-usb-mcp --voltage 3.3 --current-limit 0.1 --output-dir ~/otii-records
```
Register it with Claude Code (from the repository, with the venv set up):
```sh
claude mcp add otii -- "$PWD/.venv/bin/otii-usb-mcp"
```
or use the [`.mcp.json`](.mcp.json) in this repository, which starts `.venv/bin/otii-usb-mcp` when Claude Code
is opened in this directory. Other MCP clients start the same command over stdio.
| Tool | What it does |
|---|---|
| `status` | model, serial number, firmware, output state, voltage setpoint, current limit |
| `measure(duration_s)` | avg/min/max/std of voltage, current and power (≤ 10 s) |
| `record(duration_s, csv, png, rate_hz, name, power_on, pre_trigger_s, title, footer, serial_port, baud)` | CSV and/or PNG plot in the output directory (≤ 600 s); `title` replaces the plot's default title, `footer` its project note (`""` for none); `power_on` switches the output on inside the recording and off at the end (marked destructive); `serial_port` (under `/dev/`) adds the serial console panel |
| `set_output(on)` | switch the main output (marked destructive) |
| `power_cycle(off_s)` | off, wait, on; always ends on (marked destructive) |
At start-up and at shutdown (client disconnect, Ctrl-C, SIGTERM, SIGHUP) the server switches the
main and expansion-port outputs off and sets 5 V / 500 mA. A tool that is still running is
cancelled first. The server logs the device's identity at start-up and polls it for
overcurrent while idle; warnings are added to the next tool result as `warnings`.
## Python API
```python
from otii_usb import ChannelId, OtiiDevice
with OtiiDevice.open() as otii: # auto-detects the device, checks it is supported
print(otii.model, otii.info().serial_number)
otii.apply_safe_defaults() # outputs off, 5 V, 500 mA
otii.set_output(True)
summary = otii.measure(1.0)
print(summary.current.mean, summary.power.maximum)
recording = otii.record(2.0) # numpy float64 arrays per channel
current = recording[ChannelId.MC] # amperes, 50 kS/s
otii.capture(10.0, csv="run.csv", png="run.png")
otii.set_output(False)
```
Extending it, for example with a new device setting:
```python
from otii_usb import OtiiDevice
from otii_usb.device import PropertySpec, ScaledIntCodec
from otii_usb.protocol import PropertyId
EXPANSION_VOLTAGE = PropertySpec("expvolt", PropertyId.EXPANSION_VOLTAGE, ScaledIntCodec(1e-6),
unit="V")
with OtiiDevice.open() as otii:
print(otii.get(EXPANSION_VOLTAGE)) # read-only unless writable=True
```
or with a live analysis that receives every packet as numpy arrays:
```python
from otii_usb import ChannelId, OtiiDevice
from otii_usb.measurement import SampleSink
class PeakCurrent(SampleSink):
def __init__(self):
self.peak = 0.0
def write(self, sequence, samples): # one call per 1 ms packet
if ChannelId.MC in samples:
self.peak = max(self.peak, float(samples[ChannelId.MC].max()))
with OtiiDevice.open() as otii:
sink = PeakCurrent()
otii.stream(sink, 5.0)
print(f"peak current {sink.peak * 1e3:.3f} mA")
```
## Safety
* Only the tested device (Otii Ace Pro, firmware 3.2.5) is operated; identification only reads.
* Safe state (main and expansion outputs off, 5 V, 500 mA) when the MCP server or interactive
shell starts, and on every exit; Ctrl-C/SIGTERM/SIGHUP switch the outputs off within
milliseconds, also while a long recording runs.
* Only explicitly writable settings can be changed, and every change is read back.
* Overcurrent protection is done by the Otii itself: when the main output current reaches the
current limit, the device acts on its own (limiting or switching off, according to its
current-limit mode). `otii-usb` sets the limit (500 mA by default) and reports when it is
reached or when the device switched the output off; it does not switch it off itself.
The numbered safety and design requirements and the architecture are in
[docs/contributor/design.md](docs/contributor/design.md); the protocol is explained in
[docs/contributor/protocol.md](docs/contributor/protocol.md).
## Development
```sh
source .venv/bin/activate
python -m pytest # runs entirely against the simulator
otii-usb --debug --simulate measure # protocol traffic as hex
```
CI runs the tests on Python 3.12, 3.13 and 3.14. Agent and contributor guidance is in
[AGENTS.md](AGENTS.md).
## License
Copyright (c) 2026 Milosch Meriac, developed at Bitqan Systems Design (bitqan.ae).
Licensed under the [Apache License 2.0](LICENSE).
This project was developed with the help of Anthropic's Claude Code.
TDQS
Scored across 5 tools
The five tools mostly have distinct roles: status reports device state, set_output toggles power, power_cycle performs a timed off/on cycle, and measure/record differ by returning live statistics versus saving files. The main overlap is between measure and record, since both sample voltage/current/power over a duration, but the descriptions make the file-saving and longer-recording distinction reasonably clear.
The naming is mixed: power_cycle and set_output use verb_noun snake_case, measure and record are bare verbs, and status is a bare noun. It remains readable and domain-appropriate, but there is no single predictable pattern across the set.
Five tools is well-scoped for a USB power analyzer/control server. Each tool corresponds to a core operation: status, measurement, recording, output control, and power cycling.
The surface covers device status, measurement, recording, and output on/off/cycling, but it cannot set the main output voltage or current limit even though status reports those values. For a programmable power supply/analyzer, the lack of setpoint control is a notable functional gap.