-
Notifications
You must be signed in to change notification settings - Fork 0
Python API Overview
PyCommander's Python API is layered. From lowest to highest level:
-
Commander— a 1:1 mirror of the Simplicity Commander CLI. Each command suite is a sub-object and each method returns the raw command 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.
All four are importable straight from the flavor-aware top-level package:
from pycommander import Commander, Adapter, Target, AemStreamTyped 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, set CTUNE, provision keys, lock/unlock, region config | Target |
| Continuously read current/voltage/power | AemStream |
The high-level classes are built on top of Commander — you can always drop down a level when you need an option the helpers don't expose.
Every entry-point class accepts the same connection parameters. Provide at most one of these to select the adapter (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).
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, the following optional parameters map directly to Commander's debug options and are applied to the 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 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.
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 · extflash
- security
- tokens · nvm3 · littlefs
- convert · ebl · gbl3 · gbl4 · ota · rps · postbuild
- util · serial · mfg917
Contributing