Repository navigation
Python API Overview
PyCommander's Python API includes a command layer, task-oriented helpers, and live streams:
-
Commander— a low-level wrapper for supported Simplicity Commander commands. Command suites are sub-objects; command methods return output as adict(as if you had run the CLI with--json). -
Adapter— task-oriented helpers for Silicon Labs adapters (kit/debugger). -
Target— task-oriented helpers for the target device (MCU/SoC). -
AemStream— a Pythonic, unbounded stream of energy measurements. -
Console streams —
SwoConsoleStream,RttConsoleStream,VcomConsoleStream, andVuartConsoleStreamcapture target console output.
All are importable straight from the flavor-aware top-level package:
from pycommander import (
Commander, Adapter, Target, AemStream,
SwoConsoleStream, RttConsoleStream, VcomConsoleStream, VuartConsoleStream,
)Typed return values live in the pycommander_core.types module, and exceptions in pycommander_core.errors. See Data-Types and Error-Handling.
Import source.
from pycommander import ...resolves to the GUI flavor if installed, otherwise the CLI flavor. You can also import explicitly frompycommander_cliorpycommander_gui; the classes are identical apart from which Commander executable they run. See Architecture-and-Packages.
| You want to… | Use |
|---|---|
| Run an arbitrary CLI command and read its JSON | Commander |
| Configure VCOM / supply voltage / read kit info / analyze energy | Adapter |
| Flash, erase, read memory, set CTUNE, provision keys, lock/unlock, region config | Target |
| Continuously read current/voltage/power | AemStream |
| Continuously read SWO, RTT, VCOM, or VUART output | The matching console stream class |
The high-level helpers and streams use Commander internally. For options they do not expose, use the lower-level API or the pycommander CLI.
Commander and Adapter accept these adapter selectors. Provide at most one (passing more than one raises ValueError):
| Parameter | Selects the adapter by | CLI equivalent |
|---|---|---|
serial_number |
J-Link serial number | --serialno |
ip_address |
network address | --ip |
serial_port |
serial port | --identifybyserialport |
If you provide none, Commander uses its default selection (e.g. the only connected adapter).
AemStream, SwoConsoleStream, RttConsoleStream, and VcomConsoleStream accept serial_number or ip_address. VuartConsoleStream requires ip_address; it does not accept a serial number. See Console-Streams for the exact constructors. Target takes a Commander object rather than selecting an adapter itself.
from pycommander import Commander
by_serial = Commander(serial_number="440055955")
by_ip = Commander(ip_address="192.168.1.42")
by_port = Commander(serial_port="/dev/tty.usbmodem1234")Pass target_device (the part number, e.g. "EFR32MG24") to apply --device to commands that need it. On Adapter, providing target_device also auto-creates a Target and attaches it as adapter.target.
For advanced debug setups, Commander and Adapter accept the following optional parameters. They map directly to Commander's debug options and are applied to commands that support them:
| Parameter | CLI equivalent | Meaning |
|---|---|---|
debug_speed |
--speed |
Debug clock speed |
debug_tif |
--tif |
Target interface (e.g. SWD/JTAG) |
debug_irpre |
--irpre |
IR pre value (JTAG chain) |
debug_drpre |
--drpre |
DR pre value (JTAG chain) |
Two more Commander constructor options are commonly useful:
-
log_file_path— apathlib.Path; when set, every Commander invocation is appended to this file with a timestamp. See Logging. -
executable_path— apathlib.Pathto a specific Commander executable, bypassing the bundled one. Useful for testing against a particular Commander build.
from pathlib import Path
from pycommander import Commander
commander = Commander(
serial_number="440055955",
target_device="EFR32MG24",
log_file_path=Path("pycommander.log"),
)Most Commander command methods accept **kwargs that let you override connection/debug/device options for a single call without rebuilding the object. Recognized keys include serial_number, ip_address, serial_port, debug_speed, debug_tif, debug_irpre, debug_drpre, target_device, force, and devicexml.
commander = Commander() # no fixed adapter
commander.device.info(serial_number="440055955", target_device="EFR32MG24")
commander.device.info(serial_number="440055956", target_device="EFR32FG28")Create one entry-point object per kit. They are independent:
from pycommander import Adapter
serial_numbers = ["440055955", "440055956", "440055957"]
adapters = [Adapter(serial_number=sn, target_device="EFR32MG24") for sn in serial_numbers]
for adapter in adapters:
print(adapter.info())-
Commandermethods return adict— the parsed JSON output of the underlying command (typically containing asuccessflag and aresultobject). For non-JSON output, seerunCommandon the Commander-Class. -
Adapter/Targetmethods return typed dataclasses from Data-Types, or simplebool/Nonevalues for actions and look-ups that can fail. By convention, a query that fails returnsNone, and an action returnsTrue/False.Target.readmemreturns abytearray, orNoneif the read failed.
A failed Commander invocation raises one of PyCommanderInputError, PyCommanderRuntimeError, or the base PyCommanderError. A timeout raises TimeoutError. Argument validation in the helpers raises ValueError / FileNotFoundError before Commander is even invoked. Full details and examples: Error-Handling.
PyCommander · GitHub · Simplicity Commander docs · Licensed under the Silicon Labs MSLA
Getting started
Using PyCommander
Topics
Command reference
- Overview
- adapter · aem · vcom · ctune
- device · flash · verify · readmem · writemem · extflash
- security
- tokens · nvm3 · littlefs
- convert · ebl · gbl3 · gbl4 · ota · rps · postbuild
- util · serial · mfg917
Contributing