Skip to content

Adapter Class

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

Adapter class

Adapter is a high-level interface for interacting with a Silicon Labs adapter (a kit or debugger such as the WSTK, WPK, or Simplicity Link Debugger). Its convenience methods rely on features that exist only on Silicon Labs adapters and are not available with a generic J-Link adapter.

from pycommander import Adapter
from pycommander_core.types import VcomHandshake

adapter = Adapter(serial_number="440055955", target_device="EFR32MG24")
print(adapter.info())

adapter.setVoltage(1.8)
adapter.setVcomConfig(115200, VcomHandshake.RTSCTS, store=True)

Construction

Adapter takes the shared connection/debug parameters (see Python-API-Overview) plus two composition parameters:

  • When you construct a flavor Adapter (from pycommander import Adapter), a Commander is created for you and exposed as adapter._commander. If you pass target_device, a [[Target-Class|Target]] is also created and attached as adapter.target.
  • The underlying AdapterBase additionally accepts an existing commander= and/or target= for advanced composition (e.g. to share a logging-enabled Commander):
from pathlib import Path
from pycommander import Adapter, Commander

commander = Commander(serial_number="440055955", log_file_path=Path("pc.log"))
adapter = Adapter(commander=commander, target_device="EFR32MG24")

Multiple Adapter instances represent multiple kits and operate independently.

Methods

info() -> AdapterInfo | None

Return rich information about the adapter as an AdapterInfo — connected boards, firmware info, J-Link serial, VCOM port and capabilities, IP/MAC, nickname, kit name/part number, AEM support, debug mode. Returns None if it could not be retrieved.

reset() -> bool

Reset the adapter. Returns True on success.

upgradeFirmware(filename: Path | None = None) -> AdapterFwUpgradeResult | None

Upgrade the adapter firmware.

  • If filename is omitted, Commander's bundled firmware is used and the upgrade is only performed if the bundled version is newer than the installed one.
  • If filename is given, that firmware package (*.emz) is flashed.

Returns an AdapterFwUpgradeResult (package_was_installed, currently_installed_version), or None on failure.

getVoltage() -> AdapterVoltageInfo | None

Read the target supply voltage configuration. Returns an AdapterVoltageInfo containing per-rail AdapterRailInfo entries (configured vs. measured voltage, powered state), or None.

setVoltage(voltage: float, calibrate: bool = True) -> bool

Set the target supply voltage. With calibrate=True (default), the adapter recalibrates automatically if the voltage changed. Returns True on success.

setVcomConfig(baudrate: int, handshake: VcomHandshake, store: bool = False) -> bool

Configure the adapter's VCOM. handshake must be a VcomHandshake enum value (NONE, RTSCTS, AUX) — anything else raises ValueError. With store=True the configuration is persisted on the adapter. Returns True on success.

from pycommander_core.types import VcomHandshake
adapter.setVcomConfig(baudrate=115200, handshake=VcomHandshake.RTSCTS, store=True)

analyzeEnergyUsage(duration_s, get_distribution=False, cluster_states=False, detect_period=False) -> AemAnalysisResult | None

Capture and analyze the target's energy usage over duration_s seconds using the Advanced Energy Monitor. At least one of the three analyses must be enabled (otherwise ValueError):

  • get_distribution — current/time distribution histogram.
  • cluster_states — Bayesian-blocks clustering into distinct power states.
  • detect_period — periodicity detection (needs at least ~5 periods captured).

Returns an AemAnalysisResult with distribution, clustering, period_detection and signal_characteristics, or None on failure.

result = adapter.analyzeEnergyUsage(duration_s=10, cluster_states=True, detect_period=True)
print(result.clustering.unique_states)
print(result.signal_characteristics.min_current_ma, result.signal_characteristics.max_current_ma)

For continuous, open-ended capture rather than a fixed-window analysis, use [[AEM-and-Energy-Measurement|AemStream]].

Reaching the target and the raw CLI

  • adapter.target — the attached [[Target-Class|Target]] (present when target_device was provided). Use it for flashing, CTUNE, security, etc.
  • The underlying Commander is available for anything the helpers don't cover; see Commander-Class.
adapter.target.flashApplication(filenames=[Path("firmware.hex")])
ctune = adapter.target.getCTUNE()
adapter.target.setCTUNE(ctune.board)

Capability summary

The Adapter class focuses on tasks that involve the adapter hardware itself (Silicon Labs only):

  • Reading adapter and kit information
  • Resetting the adapter
  • Upgrading the adapter's firmware
  • Configuring the target device's supply voltage
  • Setting the adapter's VCOM configuration
  • Analyzing the target device's energy usage

Tasks involving the device (flashing, erasing, security, …) live on [[Target-Class|Target]], which works with any supported debug adapter.

Clone this wiki locally