Skip to content

Commander Class

Espen Hovland edited this page Jun 5, 2026 · 3 revisions

Commander class

Commander is the lowest-level layer of the Python API: a direct, 1:1 mirror of the Simplicity Commander CLI. Each CLI command suite is exposed as a sub-object, and each method returns the command output as a dict — equivalent to running the CLI with --json.

from pathlib import Path
from pycommander import Commander

commander = Commander(serial_number="440055955")

print(commander.device.info(target_device="EFR32MG24"))
print(commander.util.appinfo(filename="firmware.hex"))
print(commander.flash.flash(filenames=["firmware.hex"], address=0x08000000))

Constructor

Commander(
    serial_number:   str  | None = None,
    ip_address:      str  | None = None,
    serial_port:     str  | None = None,
    target_device:   str  | None = None,
    debug_speed:     int  | None = None,
    debug_tif:       str  | None = None,
    debug_irpre:     int  | None = None,
    debug_drpre:     int  | None = None,
    log_file_path:   Path | None = None,
    executable_path: Path | None = None,
)

These parameters are shared across the API and described in Python-API-Overview. Highlights:

  • Provide at most one of serial_number / ip_address / serial_port (more than one raises ValueError).
  • target_device applies --device to commands that take it.
  • debug_* map to Commander's debug options.
  • log_file_path enables per-invocation Logging.
  • executable_path overrides the bundled Commander executable (must exist, or FileNotFoundError is raised).

The flavor packages set the CLI/GUI selection for you. If you instantiate pycommander_core.commander_base.CommanderBase directly, you must pass cli=True/cli=False (or an executable_path).

Command sub-objects

A Commander exposes the following command suites as attributes. Each links to its full reference.

Attribute Class Reference
commander.adapter AdapterCommand Reference-Adapter-AEM-VCOM
commander.aem AemCommand Reference-Adapter-AEM-VCOM
commander.vcom VcomCommand Reference-Adapter-AEM-VCOM
commander.ctune CtuneCommand Reference-Adapter-AEM-VCOM
commander.device DeviceCommand Reference-Device-Flash-Memory
commander.flash FlashCommand Reference-Device-Flash-Memory
commander.verify VerifyCommand Reference-Device-Flash-Memory
commander.readmem ReadmemCommand Reference-Device-Flash-Memory
commander.extflash ExtflashCommand Reference-Device-Flash-Memory
commander.security SecurityCommand Reference-Security
commander.tokens TokensCommand Reference-Tokens-NVM3-LittleFS
commander.nvm3 Nvm3Command Reference-Tokens-NVM3-LittleFS
commander.littlefs LittlefsCommand Reference-Tokens-NVM3-LittleFS
commander.convert ConvertCommand Reference-Image-Files
commander.ebl EblCommand Reference-Image-Files
commander.gbl3 Gbl3Command Reference-Image-Files
commander.gbl4 Gbl4Command Reference-Image-Files
commander.ota OtaCommand Reference-Image-Files
commander.rps RpsCommand Reference-Image-Files
commander.postbuild PostbuildCommand Reference-Image-Files
commander.util UtilCommand Reference-Utilities
commander.serial SerialCommand Reference-Utilities
commander.mfg917 Mfg917Command Reference-Utilities

Standalone helper methods

In addition to the command suites, Commander exposes a few convenience methods.

getVersion() -> CommanderVersionInfo | None

Returns the embedded Simplicity Commander, J-Link, EMDLL, mbed TLS and Qt component versions as a CommanderVersionInfo dataclass, or None if it could not be retrieved.

print(commander.getVersion())

listAvailableAdapters(list_usb_adapters=False, list_network_adapters=False) -> list[BasicAdapterInfo] | None

Performs an unintrusive scan for available adapters over USB or the network. Returns a list of BasicAdapterInfo objects (each carrying jlink_serial_number, ip_address, nickname — any of which may be None), or None on failure.

Exactly one of list_usb_adapters / list_network_adapters must be True (otherwise ValueError).

# USB adapters
for a in commander.listAvailableAdapters(list_usb_adapters=True):
    print(a.jlink_serial_number, a.nickname)

# Network adapters
for a in commander.listAvailableAdapters(list_network_adapters=True):
    print(a.ip_address, a.nickname)

runCommand(*args, json_formatted_output=True, **kwargs) -> dict | CommanderResult

Escape hatch for commands the typed API doesn't expose. Arguments are forwarded straight to the Commander CLI.

  • With json_formatted_output=True (default), returns the parsed JSON dict.
  • With json_formatted_output=False, returns a CommanderResult namedtuple (returncode, output) with the raw text output.
result = commander.runCommand("rtt", "--help", json_formatted_output=False)
print(result.output)

**kwargs accepts the same per-call override keys as command methods (serial_number, target_device, force, devicexml, the debug_* keys, …).

Limitations vs. the CLI

Not every CLI command is available on Commander. Commands designed for interactive CLI sessions are intentionally omitted — for example vcom, vuart, rtt and swo interactive flows. (A non-interactive vcom config is exposed; see Reference-Adapter-AEM-VCOM.)

Some methods are also stricter than their CLI counterparts because there is no interactive session to fall back on. For instance, aem dump requires outfile and duration to be provided. For flexible, open-ended AEM capture, use the [[AEM-and-Energy-Measurement|AemStream]] class instead.

For anything not surfaced by the typed API, fall back to runCommand(...).

Return-value shape

Command methods return the parsed JSON dict. Most Commander commands include a top-level success boolean and a result object; the higher-level Adapter-Class and Target-Class helpers exist precisely to parse these into typed dataclasses for you. If a command produces non-JSON output, _run still returns a dict shaped like {"success": True, "output": "..."} (or {"success": False, "error": "..."} on failure).

Clone this wiki locally