Kleidos API Search

In development. It changes without notice.

The command line

Every command of kleidos-meter: what it takes, what it exits with and an example. This page is written by scripts/gen_cli_doc.py from the commands' own parsers, and a test fails when the two differ; kleidos-meter --help and kleidos-meter SUBCOMMAND --help say the same at the terminal. How a measuring session goes is the usage guide, and the same instrument from Python is the Python API's reference.

Command Does
kleidos-meter Send program messages to the meter and print each response line.
kleidos-meter capture One capture, recorded to a run directory, with no panel.
kleidos-meter serve Hold the meter's port for the panel, and hand it back as found.
kleidos-meter calibrate The shunt calibration, step by step, with the owner at the bench; it files a registry event.
kleidos-meter calibration The instrument against the calibration registry: verify it, or restore its working copy.
kleidos-meter relay-timing Measure the relays' operate and release times through the shunt (0.13.0).
kleidos-meter pins The instrument's pin map: show it, stage a change, apply it, or put the rig's back.

What every command shares

  • The port is --port, or the environment's KLEIDOS_METER_PORT: the device node, or a pyserial URL (socket://127.0.0.1:5025, the passthrough of a running serve).
  • The port is opened exclusively. One that another program holds is refused at once; serve and capture name the holder when it left a note (“Start it” in the panel's guide).
  • --sim takes the simulated instrument instead, with nothing plugged in. It speaks the same protocol and nothing it says is a measurement.
  • Status 1 is also an error no command expects, its Python traceback on standard error: a port that does not exist, for one.
  • -h, --help prints what the command takes and exits with 0.

An example's output is what the command printed; what a run makes its own (a version, a date, a directory, a count of real time) differs in yours, and [...] stands for lines left out. The examples are run by host/tests/test_cli_doc.py, from the repository's root and in the order of the page.

kleidos-meter

Send program messages to the meter and print each response line.

kleidos-meter [-h] [--port PORT] [--sim] [--timeout TIMEOUT] messages [messages ...]

Each message is one argument, its response one line of standard output: the units, ; between them, after any block they carried. A response is awaited for every message and commands have none, so end each message with ;:SYST:ERR:ALL?, which answers and says whether anything in it was refused. A stream record that comes meanwhile is printed behind a #. The messages are the SCPI command set's, and the usage guide says which to send.

Argument Default What it is
messages [messages ...] required program messages, one per argument
--port PORT KLEIDOS_METER_PORT the device node or URL
--sim off talk to the simulated instrument
--timeout TIMEOUT 8.0 seconds to wait for each response
Status Says
0 every message was answered
1 the port is held elsewhere, the instrument did not answer the readiness check, or a message went unanswered within --timeout
2 a usage error (no message, or no port and no --sim)

Example, on the simulator:

$ kleidos-meter --sim 'MEAS:CURR?;:SYST:ERR:ALL?' 'SENS:PROF NONE;:SYST:ERR:ALL?'
# the instrument rebooted (*ESR? power-on bit set)
0.088600000;0,"No error"
-224,"Illegal parameter value;use SENSe:PROFile TRACe|STATe|SLEep|BURSt"

A refused message is answered like any other: the status says only that an answer came.

kleidos-meter capture

One capture, recorded to a run directory, with no panel.

kleidos-meter capture [-h] [--port PORT] [--sim] --profile PROFILE [--seconds SECONDS]
[--channels CHANNELS] [--label LABEL] [--out OUT] [--ready-timeout READY_TIMEOUT]

The run is a directory of its own, readable by you alone, with what the instrument wrote and a meta.json. The settings the capture changed are written back, and Ctrl-C ends it early and still finishes the run. “Record a capture” in the usage guide says which profile to take and how to export a run.

Argument Default What it is
--port PORT KLEIDOS_METER_PORT the device node or URL
--sim off capture from the simulated instrument
--profile PROFILE required TRACE, STATE, SLEEP or BURST
--seconds SECONDS – how long (a ring profile may leave it out)
--channels CHANNELS – CURR,VOLT,POW,TEMP (comma-separated) or DEF; the instrument's own by default
--label LABEL – a note kept in the run's meta.json
--out OUT – the data directory ($XDG_STATE_HOME/kleidos-meter/runs)
--ready-timeout READY_TIMEOUT 15.0 seconds to wait for the instrument to answer (15)
Status Says
0 the run is complete (every sample the instrument streamed is in it, or the dump holds the whole ring) and the settings were written back
1 the port is held elsewhere, the instrument does not answer or refuses the capture, the run is incomplete, or the settings could not be written back
2 a usage error (a data directory inside a git work tree among them)

Example, on the simulator:

$ kleidos-meter capture --sim --profile SLEEP --seconds 1 --out ~/meter-runs
capture: recording ~/meter-runs/20261124T060534Z-SLEEP-47e42b
capture: wrote back profile TRACE (it was SLEEP)
capture: wrote back channels "" (it was "CURR","VOLT","TEMP")
capture: run 20261124T060534Z-SLEEP-47e42b, ended by seconds, samples=16 dropped=0, stream=16 marks=0, complete

kleidos-meter serve

Hold the meter's port for the panel, and hand it back as found.

kleidos-meter serve [-h] [--port PORT] [--sim] [--sim-wiring PAIRS] [--bind BIND] [--http HTTP]
[--allow-remote] [--data-dir DATA_DIR] [--registry REGISTRY] [--elf ELF]
[--scpi-passthrough [PORT]] [--ready-timeout READY_TIMEOUT]

It is the port's one opener until it is stopped with Ctrl-C (or SIGTERM), and puts back the settings it changed on the way out. The panel's guide is how the panel is used and the HTTP API's reference what it answers.

Argument Default What it is
--port PORT KLEIDOS_METER_PORT the device node or URL
--sim off serve the simulated instrument
--sim-wiring PAIRS Wiring(sda=4, scl=5, alert=6, address=64, relay1=7, relay1_active='low', relay2=15, relay2_active='high') where the simulated board's parts are, key=value pairs over the rig's (sda=18,addr=0x41); the rig by default
--bind BIND 127.0.0.1 the panel's address (127.0.0.1)
--http HTTP 8040 the panel's port (8040; 0: any)
--allow-remote off let –bind name an address beyond the loopback (the panel is unauthenticated)
--data-dir DATA_DIR – where recordings go ($XDG_STATE_HOME/kleidos-meter/runs)
--registry REGISTRY – the calibration registry (the repository's calibration/)
--elf ELF this checkout's firmware/.pio/build/meter/firmware.elf the build's firmware.elf the instrument's elf= is compared with (the repository's meter build)
--scpi-passthrough [PORT] – give the line to one SCPI client at a time on 127.0.0.1 (port 5025; 0: any)
--ready-timeout READY_TIMEOUT 15.0 seconds to wait for the instrument to answer (15)
Status Says
0 a clean stop
1 the port is held elsewhere, the panel's or the passthrough's address cannot be bound, the instrument does not answer, or the settings could not be written back
2 a usage error (a data directory inside a git work tree among them)

Example, on the simulator:

$ kleidos-meter serve --sim
serve: KM-EE529C1B03, firmware 0.18.0, image meter, elf 5e1f0ba47c2291d3, q=cal
serve: reset poweron, up 1.1 s
serve: panel at http://127.0.0.1:8040/
serve: panel API at http://127.0.0.1:8040/api/
serve: recordings in ~/.local/state/kleidos-meter/runs
serve: holding the port; stop with Ctrl-C
serve: released the port

The last line is what Ctrl-C printed.

kleidos-meter calibrate

The shunt calibration, step by step, with the owner at the bench; it files a registry event.

kleidos-meter calibrate [-h] [--port PORT] [--sim] [--registry REGISTRY]
[--configuration CONFIGURATION] [--reference {vpg-y0785-100r}]
[--reference-ohm REFERENCE_OHM] [--reference-tolerance-ppm REFERENCE_TOLERANCE_PPM]
[--reference-tcr REFERENCE_TCR] [--yes] [--null-seconds NULL_SECONDS] [--samples SAMPLES]

It asks for each step at the bench, judges the session by the gates of its configuration and files it in the registry, accepted or refused. Nothing is committed. The calibration guide is the procedure: read it first. Without --registry the session is filed in this checkout, so a rehearsal names a copy.

Argument Default What it is
--port PORT KLEIDOS_METER_PORT the device node or URL
--sim off calibrate the simulated instrument
--registry REGISTRY this checkout's calibration/ the calibration/ directory
--configuration CONFIGURATION – the configuration of an instrument's first calibration
--reference {vpg-y0785-100r} vpg-y0785-100r the reference resistor fitted
--reference-ohm REFERENCE_OHM – another reference: its value
--reference-tolerance-ppm REFERENCE_TOLERANCE_PPM – another reference: its tolerance
--reference-tcr REFERENCE_TCR – another reference: its TCR, ppm/°C
--yes off answer every prompt (simulator, tests)
--null-seconds NULL_SECONDS 60 how long each null is
--samples SAMPLES 600 the samples of one point
Status Says
0 the session was accepted and filed
1 it could not start, or the registry's check found problems with what it filed; or an error ended it, its traceback on stderr: the port is held elsewhere, the instrument did not answer or refused a step
2 a gate failed: the session was filed as refused and no working copy was written; or a usage error

Example, on the simulator:

$ cp -R calibration ~/meter-registry
$ kleidos-meter calibrate --sim --yes --registry ~/meter-registry --configuration mjkdz-r100-relay2click
Instrument KM-EE529C1B03, firmware 0.18.0, configuration mjkdz-r100-relay2click
[...]
[ok] ranges within 1000 ppm of each other: 0 ppm
R = 100.123000 mΩ ± 0.059273 mΩ (k = 2; u_c 296 ppm)
Step 4 of 4. Put the bench back: the VBUS wire to its screw, the cell's + to the VBUS screw, the reference out, pigtail 3 back into the DUT.
Record: ~/meter-registry/records/KM-EE529C1B03/2026-11-24-01.md
Left to do: commit and push the registry here, then in the Kleidos firmware repository
python -m qa_lib.power meter-lock

The simulator takes no time over the nulls, and what it measures is its own.

kleidos-meter calibration

The instrument against the calibration registry: verify it, or restore its working copy.

kleidos-meter calibration [-h] [--port PORT] [--sim] [--registry REGISTRY] [--rev REV]
[--date DATE] [--json] [--yes] {verify,restore}

The registry is the calibration and the instrument holds a working copy of it, which a full erase loses. verify compares the two and changes neither; restore writes the registry's copy and verifies it. Run verify before the first number of a session (the usage guide); what each verdict means is in the calibration guide.

Argument Default What it is
{verify,restore} required compare the instrument with the registry, or write it the registry's copy
--port PORT KLEIDOS_METER_PORT the device node or URL
--sim off talk to the simulated instrument
--registry REGISTRY this checkout's calibration/ the calibration/ directory
--rev REV – read the registry at this git revision (git show)
--date DATE – as of this day (today)
--json off print the verdict as JSON (verify)
--yes off answer the confirmation (restore)
Status Says
0 the instrument holds the registry's working copy (applied)
1 an error ended the run, its traceback or its message on stderr: the port is held elsewhere, the instrument did not answer or refused the copy, or --rev holds no index
2 a usage error (a KLEIDOS_METER_SERIAL_ALIASES that is not serial pairs among them), or a restore with no terminal to answer its question and no --yes
3 it does not: the verdict says why

Example, on the simulator:

$ kleidos-meter calibration verify --sim --registry ~/meter-registry
KM-EE529C1B03: working_copy_lost
calibration 2026-11-24-01 (mjkdz-r100-relay2click), valid 2026-11-24 to 2027-11-24: range 0 100.123000 mΩ (u 296 ppm), range 1 100.123000 mΩ (u 296 ppm)
- the instrument holds no measured shunt (its calibration at the defaults)
$ kleidos-meter calibration restore --sim --yes --registry ~/meter-registry
KM-EE529C1B03: working_copy_lost
calibration 2026-11-24-01 (mjkdz-r100-relay2click), valid 2026-11-24 to 2027-11-24: range 0 100.123000 mΩ (u 296 ppm), range 1 100.123000 mΩ (u 296 ppm)
- the instrument holds no measured shunt (its calibration at the defaults)
Will send: SENS:CURR:SHUN 0.100123; CAL:TAG "R100_20261124"; CAL:DATE 2026,11,24; CAL:VBUS SOUR
KM-EE529C1B03: applied
calibration 2026-11-24-01 (mjkdz-r100-relay2click), valid 2026-11-24 to 2027-11-24: range 0 100.123000 mΩ (u 296 ppm), range 1 100.123000 mΩ (u 296 ppm)

The registry is the one calibrate filed above; each command starts a simulated instrument with nothing stored, so verify exits with 3.

kleidos-meter relay-timing

Measure the relays' operate and release times through the shunt (0.13.0).

kleidos-meter relay-timing [-h] [--port PORT] [--sim] --relay {k1,k2} [--repeats REPEATS]
[--hold HOLD] [--json]

It moves the relay under a TRACE capture and finds each step in the ring. k1 takes the DUT off its battery for --hold ms a move, so the DUT needs another supply or must stand it. What the rig's contacts measured is the relay timings.

Argument Default What it is
--port PORT KLEIDOS_METER_PORT the device node or URL
--sim off talk to the simulated instrument
--relay {k1,k2} required k1, the lead, or k2, the bypass; may be given again
--repeats REPEATS 5 moves per relay, 1 to 8
--hold HOLD 300 ms between the two orders
--json off print every edge as JSON
Status Says
0 every move was measured and the rig is back at rest
1 an error ended the run, its traceback on stderr: the port is held elsewhere, the instrument did not answer or refused an order, or the dump arrived damaged
2 a usage error

Example, on the simulator:

$ kleidos-meter relay-timing --sim --relay k1 --repeats 1 --hold 20
k1:closed: n=1 median=-5320 us range=-5320..-5320 us min_contrast=inf
k1:open: n=1 median=-5320 us range=-5320..-5320 us min_contrast=inf

The simulated DUT draws the same whatever the contact does, so its ring holds no step and these figures mean nothing; on the bench a delay is positive.

kleidos-meter pins

The instrument's pin map: show it, stage a change, apply it, or put the rig's back.

kleidos-meter pins [-h] [--port PORT] [--sim] [--sim-wiring PAIRS] [--pending]
{show,set,apply,defaults} [KEY=VALUE ...]

The pin map is which GPIO each of the instrument's five roles takes (the INA228's SDA, SCL and ALERT, Relay 1 and Relay 2), how each is pulled or driven, the INA228's address and the bus clock at boot (“The pin map” in the SCPI command set). show prints it; set stages a change on the instrument and prints the rules' verdict; apply stages the changes it is given and applies the staged map, which the instrument keeps only once the INA228 answers on it and puts back otherwise; defaults applies the rig's map and needs no INA228. With --sim, --sim-wiring says where the simulated board's parts are, so a map that is not the board's is reverted as the instrument would.

Argument Default What it is
{show,set,apply,defaults} required print the map, stage a change, stage and apply it, or apply the rig's map
[KEY=VALUE ...] – the changes to stage (set, apply): sda=18, relay1_active=high, addr=0x41
--port PORT KLEIDOS_METER_PORT the device node or URL
--sim off talk to the simulated instrument
--sim-wiring PAIRS Wiring(sda=4, scl=5, alert=6, address=64, relay1=7, relay1_active='low', relay2=15, relay2_active='high') where the simulated board's parts are, key=value pairs over the rig's (sda=18,addr=0x41); the rig by default
--pending off show the staged map (show)
Status Says
0 the map was shown, staged valid, or applied and proved
1 the port is held elsewhere or the instrument did not answer
2 a usage error (a change that does not read, no port and no --sim)
3 the instrument refused the change or put the last good map back: what it said is on stderr

Example, on the simulator:

$ kleidos-meter --sim pins show
pins: the live map, src=default verified=1 table=0x90072FE9 (this package's board)
SDA GPIO4 pull up
SCL GPIO5 pull up
ALERT GPIO6 pull up
Relay 1 GPIO7 active low
Relay 2 GPIO15 active high
address auto (a scan of 0x40 to 0x4F)
clock 400000 Hz at boot
$ kleidos-meter pins apply sda=18 --sim
# 117,"Pin map reverted;the INA228 did not answer on sda=18 scl=5 addr=auto: the last good map is back"
pins: reverted, reason no_chip, INA228 mfg - die -, self-test 1, saved 0
[...]
$ kleidos-meter pins apply sda=18 scl=21 --sim --sim-wiring sda=18,scl=21
pins: ok, reason -, INA228 mfg 0x5449 die 0x228, self-test 0, saved 1
pins: the live map, src=stored verified=1 table=0x90072FE9 (this package's board)
SDA GPIO18 pull up
SCL GPIO21 pull up
[...]

Each command starts a simulated instrument with the rig's map: the second finds no INA228 on GPIO18 and keeps the rig's, the third is told the board has it there.

Back to the top