Skip to main content

Silicon Labs PyCommander

Unit tests

Introduction

This Python package wraps Simplicity Commander functionality and exposes a native Python API for interacting with Commander in your scripts.

Requirements

This package requires Python 3.10 or newer. Required PyPI packages are:

  • platformdirs
  • pyyaml

Additionally, Simplicity Commander requires the SEGGER J-Link drivers to be installed on your system.

Installation

pip install "silabs-pycommander"

To launch the GUI from the pycommander command, install the gui extra:

pip install "silabs-pycommander[gui]"

Usage

More details about Simplicity Commander and its Command Line Interface can be found in the official documentation for Simplicity Commander. The documentation is also helpful when using the Python API, as the command names and available options are the same.

Command Line Interface

This is the only package that installs the pycommander command. It runs the Simplicity Commander CLI executable:

pycommander --help
pycommander --version
pycommander <command> [options]
pycommander <command> <subcommand> [options]

With the gui extra installed, pycommander and pycommander gui launch the GUI executable. Every other command line still runs the CLI executable. Without the GUI package, the pycommander gui command is not supported.

pycommander
pycommander gui

The CLI and GUI executables share the same commander.ini. The Python API does not use that file.

To run one executable directly:

python -m pycommander_cli <command> [options]
python -m pycommander_gui <command> [options]

Python API

Import the API from pycommander. These classes call the CLI executable. Imports from pycommander_gui still resolve to the same classes, but they emit a DeprecationWarning and will be removed in a future release.

At the lowest level, the Commander class provides all the CLI commands as methods to the class. These methods return a dictionary containing the command output, similarly to what the Simplicity Commander CLI does when the --json flag is used.

from pycommander import Commander

# Instantiate the Commander class with a serial number
commander = Commander(serial_number="440055955")

# Perform the 'commander device info' command
print(commander.device.info(target_device="EFR32MG24"))

# Perform the 'commander util appinfo' command
print(commander.util.appinfo(filename="firmware.hex"))

# Perform the 'commander flash' command
print(commander.flash.flash(filenames=["firmware.hex"], address=0x08000000))

# Perform the 'commander writemem' command
print(commander.writemem.writemem(filename="data.bin", address=0x20000000))

The Commander class also exposes a few standalone helpers; for example, getVersion() returns the embedded Simplicity Commander, J-Link, EMDLL and other component versions as a CommanderVersionInfo object:

from pycommander import Commander

commander = Commander()

# Get the version of the embedded Simplicity Commander, J-Link, EMDLL and other components
print(commander.getVersion())

listAvailableAdapters() is a helper method that can be used to (unintrusively) scan for available adapters. This method returns a list of BasicAdapterInfo objects, each carrying jlink_serial_number, ip_address and nickname (any of which may be None):

from pycommander import Commander

commander = Commander()

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

# List network adapters
adapters = commander.listAvailableAdapters(list_network_adapters=True)
for adapter in adapters:
  print(adapter.ip_address, adapter.nickname)

Please note that not all commands are available to the Commander class. Moreover, some commands in the Commander class have stricter requirements for the arguments than their CLI counterparts. For example, the aem dump command requires the outfile and duration arguments to be provided. For long-running captures, prefer the stream classes below.

For ad-hoc invocations of commands that are not exposed by the typed API, you can fall back to Commander.runCommand(...), which forwards arguments directly to the underlying Simplicity Commander CLI:

# Run a raw Commander CLI command and capture its output
result = commander.runCommand("rtt", "--help", json_formatted_output=False)
print(result.stdout)
print(result.stderr)

The Adapter and Target classes

pycommander exposes several convenience methods for common tasks related to the adapter and the target device. These methods return different data types depending on the command. The types are available in the pycommander_core.types module, and the tasks include:

  • Locking/unlocking the device for debug access
  • Setting the CTUNE value
  • Setting the adapter's VCOM configuration
  • Configuring the target device's voltage
  • Flashing firmware to the device
  • Erasing the device's flash
  • Reading memory from the device
  • Configuring code regions (Series 3 only)
  • +++

When instantiating the Adapter class, a Commander class instance is created and made available as an attribute of the Adapter class. If a target_device is provided to the Adapter class, a Target class instance is created and made available as an attribute of the Adapter class as well.

An Adapter class instance (with a potential Target class instance) should be used to represent a connection to a single adapter (with target device). Multiple Adapter class instances can be used to represent connections to multiple adapters (with or without their respective target devices):

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())

A typical session against a single adapter may look like this:

from pycommander import Adapter
from pycommander_core.types import AdapterInfo, AdapterVoltageInfo, VcomHandshake, CtuneValue

# Instantiate the Adapter class with a serial number and target device
adapter = Adapter(serial_number="440055955", target_device="EFR32MG24")

# Get the adapter information
adapter_info: AdapterInfo = adapter.info()

# Get the voltage information
voltage_info: AdapterVoltageInfo | None = adapter.getVoltage()

# Set the VCOM configuration of the adapter
adapter.setVcomConfig(115200, VcomHandshake.RTSCTS, True)

# Get the CTUNE value of the target device
ctune_value: CtuneValue = adapter.target.getCTUNE()

# Set the CTUNE value of the target device
adapter.target.setCTUNE(ctune_value.board)

A common high-level task is flashing firmware. Target.flashApplication() accepts one or more files (.hex, .s37, .bin, .gbl or .rps) and handles the underlying flash, verify and reset steps:

from pathlib import Path
from pycommander import Adapter

adapter = Adapter(serial_number="440055955", target_device="EFR32MG24")

success: bool = adapter.target.flashApplication(filenames=[Path("firmware.hex")])

Stream classes

Long-running Commander captures are wrapped as iterable stream objects: AemStream, SwoConsoleStream, RttConsoleStream, VcomConsoleStream and VuartConsoleStream. They share the same lifecycle.

Entering a with block (or calling open()) starts Commander. Iterate the object to receive data as it arrives, and stop at any time. Leaving the with block, or calling close(), shuts Commander down cleanly.

AemStream yields AemMeasurement objects (timestamp, current, voltage, and calculated power). The console streams yield device output as it arrives. Commander status stays on its own stdout; error lines raise a RuntimeError exception.

Most streams accept serial_number or ip_address as connection parameters. VuartConsoleStream is IP-only and therefore requires ip_address. Options such as timeout_s, endmarker, lineending, command and hex_output are available where the underlying Commander command supports them.

AemStream

Advanced Energy Monitor measurements from a Silicon Labs adapter. Configure the data rate, an optional duration, and simple start triggers.

from pycommander import AemStream

with AemStream(serial_number="440055955", datarate_hz=100, duration_s=10) as aem_stream:
  for measurement in aem_stream:
    print(measurement)
from pycommander import AemStream

aem_stream = AemStream(serial_number="440055955", datarate_hz=100)
aem_stream.open()
for measurement in aem_stream:
  print(measurement)
aem_stream.close()
SwoConsoleStream

Serial Wire Output (SWO) from the target device. Supports SWO speed, ITM channel, idle timeout, end marker, monitoring all channels for end conditions, hexadecimal output, and skipping the target reset.

from pycommander import SwoConsoleStream

with SwoConsoleStream(serial_number="440055955", timeout_s=5, endmarker="--finished--") as swo_stream:
  for line in swo_stream:
    print(line, end="", flush=True)
from pycommander import SwoConsoleStream

swo_stream = SwoConsoleStream(serial_number="440055955", swospeed_hz=875000)
swo_stream.open()
for line in swo_stream:
  print(line, end="", flush=True)
swo_stream.close()
RttConsoleStream

Segger Real Time Transfer (RTT) from the target device. Supports control-block address, read and write buffers, virtual terminal, idle timeout, end marker, line endings, skipping the target reset, and one-shot startup commands.

from pycommander import RttConsoleStream

with RttConsoleStream(serial_number="440055955", timeout_s=5, endmarker="DONE", command="status") as rtt_stream:
  for line in rtt_stream:
    print(line, end="", flush=True)
from pycommander import RttConsoleStream

rtt_stream = RttConsoleStream(serial_number="440055955")
rtt_stream.open()
for line in rtt_stream:
  print(line, end="", flush=True)
rtt_stream.close()
VcomConsoleStream

Virtual COM port on Silicon Labs adapters. Supports hexadecimal output, restarting the target in ISP mode, line endings, and one-shot startup commands. Configure baudrate and handshake separately with Commander.vcom.config or Adapter.setVcomConfig.

from pycommander import VcomConsoleStream

with VcomConsoleStream(serial_number="440055955", command="status") as vcom_stream:
  for line in vcom_stream:
    print(line, end="", flush=True)
from pycommander import VcomConsoleStream

vcom_stream = VcomConsoleStream(serial_number="440055955")
vcom_stream.open()
for line in vcom_stream:
  print(line, end="", flush=True)
vcom_stream.close()
VuartConsoleStream

Virtual UART (VUART) over IP (requires ip_address). Supports idle timeout, end marker, line endings, and one-shot startup commands.

from pycommander import VuartConsoleStream

with VuartConsoleStream(ip_address="192.168.1.100", timeout_s=5, endmarker="DONE", command="status") as vuart_stream:
  for line in vuart_stream:
    print(line, end="", flush=True)
from pycommander import VuartConsoleStream

vuart_stream = VuartConsoleStream(ip_address="192.168.1.100")
vuart_stream.open()
for line in vuart_stream:
  print(line, end="", flush=True)
vuart_stream.close()

Error handling

Failed Commander invocations raise typed exceptions, so your automation scripts can react to them in a structured way. Three exception classes are exposed from pycommander_core.errors:

  • PyCommanderInputError — Commander rejected the arguments (return code -1 / 255).
  • PyCommanderRuntimeError — Commander failed at runtime, e.g. the adapter could not be reached or the operation timed out (return code -2 / 254).
  • PyCommanderError — base class for any other non-zero return code, and parent of the two above.
from pathlib import Path
from pycommander import Adapter
from pycommander_core.errors import PyCommanderError, PyCommanderRuntimeError

adapter = Adapter(serial_number="440055955", target_device="EFR32MG24")

try:
  adapter.target.flashApplication(filenames=[Path("firmware.hex")])
except PyCommanderRuntimeError as e:
  print(f"Commander failed at runtime: {e}")
except PyCommanderError as e:
  print(f"Other Commander error: {e}")

Logging

All Commander invocations can be logged to a file by passing the log_file_path argument to the Commander constructor. Each invocation is recorded with a timestamp, which is handy when diagnosing issues in long-running automations or production-test rigs.

from pathlib import Path
from pycommander import Adapter, Commander

# Build a Commander with logging enabled, then attach it to an Adapter
commander = Commander(serial_number="440055955", log_file_path=Path("pycommander.log"))
adapter = Adapter(commander=commander, target_device="EFR32MG24")

Metadata

Release files for silabs-pycommander 1.5.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for silabs-pycommander 1.5.0
File Actions
silabs_pycommander-1.5.0-py3-none-win_amd64.whl Python 3 none Windows x86-64 Details for silabs_pycommander-1.5.0-py3-none-win_amd64.whl
silabs_pycommander-1.5.0-py3-none-manylinux2014_x86_64.whl Python 3 none Linux glibc 2.17+ x86-64 Details for silabs_pycommander-1.5.0-py3-none-manylinux2014_x86_64.whl
silabs_pycommander-1.5.0-py3-none-manylinux2014_armv7l.whl Python 3 none Linux glibc 2.17+ ARMv7l Details for silabs_pycommander-1.5.0-py3-none-manylinux2014_armv7l.whl
silabs_pycommander-1.5.0-py3-none-manylinux2014_aarch64.whl Python 3 none Linux glibc 2.17+ ARM64 Details for silabs_pycommander-1.5.0-py3-none-manylinux2014_aarch64.whl
silabs_pycommander-1.5.0-py3-none-macosx_10_9_universal2.whl Python 3 none macOS 10.9+ universal2 (ARM64, x86-64) Details for silabs_pycommander-1.5.0-py3-none-macosx_10_9_universal2.whl

Total release size: 39.5 kB

Release files / silabs_pycommander-1.5.0-py3-none-win_amd64.whl

Download URL silabs_pycommander-1.5.0-py3-none-win_amd64.whl
Size 7.9 kB
Tags Python 3 Windows x86-64
SHA-256 checksum
How to use checksums
ad031dd12d0f546c4cdab8684a3345c4b0b7955988f0559472588a6d4cbff76c
BLAKE2b-256 checksum
How to use checksums
7a37e1239095ceda0c7a4b23c04f994a41ff1ac2ee3b093e3dc80dc126e64fc5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.22

Release files / silabs_pycommander-1.5.0-py3-none-manylinux2014_x86_64.whl

Download URL silabs_pycommander-1.5.0-py3-none-manylinux2014_x86_64.whl
Size 7.9 kB
Tags Linux glibc 2.17+ x86-64 Python 3
SHA-256 checksum
How to use checksums
8de34984d3490b6562468850bf0bb824c6eebe4c2dd46757fcf663b1a784ec48
BLAKE2b-256 checksum
How to use checksums
c8d605a8eb5b3574fc869681f84c712802cbe3f4fdc4a835726dd9329991bcc0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.22

Release files / silabs_pycommander-1.5.0-py3-none-manylinux2014_armv7l.whl

Download URL silabs_pycommander-1.5.0-py3-none-manylinux2014_armv7l.whl
Size 7.9 kB
Tags Linux glibc 2.17+ ARMv7l Python 3
SHA-256 checksum
How to use checksums
a202bab8641c8fd7cdb24ee27d97574a600ce6a88ac3c6fd0b0e200d21bc6a06
BLAKE2b-256 checksum
How to use checksums
8cce952114c54732d8cb1ddfac2c5669ca3a49bb8e950ff67c1a4aff1ae737c2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.22

Release files / silabs_pycommander-1.5.0-py3-none-manylinux2014_aarch64.whl

Download URL silabs_pycommander-1.5.0-py3-none-manylinux2014_aarch64.whl
Size 7.9 kB
Tags Linux glibc 2.17+ ARM64 Python 3
SHA-256 checksum
How to use checksums
eb179e5351031567cfa1ff44cb67e32d6195331ee18671575a933042f62708f4
BLAKE2b-256 checksum
How to use checksums
7add25c90fbdc3a9ae26fd4430c0615cbafe08fb0525f15f6a83f119ee7c7cda
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.22

Release files / silabs_pycommander-1.5.0-py3-none-macosx_10_9_universal2.whl

Download URL silabs_pycommander-1.5.0-py3-none-macosx_10_9_universal2.whl
Size 7.9 kB
Tags Python 3 macOS 10.9+ universal2 (ARM64, x86-64)
SHA-256 checksum
How to use checksums
59831854487f53502dd2c9ce941f8199fa5eb5df2253e914162e2eea5f65207a
BLAKE2b-256 checksum
How to use checksums
41cc7ed83137fb34464c38a934eb4544ce174430fe8c3510edf4e6305de803f8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.22

Security for silabs-pycommander 1.5.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page