Targets

The Target class provides an interface for interacting with imperix controllers, similar to using the Target configuration tab in Cockpit.

Note

To interact with running user code (e.g., to read and write variables, or acquire Scope data) a project must be used.

Listing available imperix controllers

The following example instructs Cockpit to refresh its target list (which triggers an Ethernet network scan) and iterates through all detected controllers. This code snippet serves as the “Hello World” example in the getting started guide.

from imperix import Cockpit

with Cockpit() as cockpit:

   # Instructs Cockpit to run an Ethernet network scan and refresh its target list
   print("Refreshing target list...")
   cockpit.targets.refresh()

   # Retrieve the list of detected targets
   targets = cockpit.targets.list()
   print(f"{len(targets)} target(s) found:")

   # Display the hostname and IP address of each target
   for target in targets:
      print(f"  {target.hostname} ({target.ip})")

Retrieving a specific imperix controller

A controller is uniquely identified by its MAC address, and Cockpit automatically tracks its IP address.

The code below demonstrates how to verify that a specific controller is properly detected. To save time during multiple script executions, a network scan is performed only if the target is absent from the initial list.

from imperix import Cockpit

TARGET_MAC = "AA:BB:CC:DD:EE:FF"

with Cockpit() as cockpit:

   # Retrieve the target using its MAC address
   target = cockpit.targets.get(TARGET_MAC)

   if target is None:
      # The target was not found; run a network scan
      cockpit.targets.refresh()
      target = cockpit.targets.get(TARGET_MAC)

   if target is None:
      # The target is still not found; exit the script
      raise SystemExit(f"Target {TARGET_MAC} not found")

   # The rest of the script...

Waiting for a controller after a reboot

Rebooting an imperix controller takes approximately one minute, or longer if multiple controllers are networked together (e.g., in a master-slave or multi-master setup).

The following example illustrates how combining is_ready() with wait_until() blocks script execution until the controller is fully ready to accept code following a reboot.

from imperix import Cockpit

TARGET_MAC = "AA:BB:CC:DD:EE:FF"

with Cockpit() as cockpit:

   # Retrieve the target using its MAC address
   target = cockpit.targets.get(TARGET_MAC)

   # Upload a custom FPGA bitstream and reboot the target
   target.upload_bitstream(r"C:\imperix\custom_bitstream.bit")
   target.reboot()

   # Wait for the target to go offline
   cockpit.wait_until(
      lambda: not cockpit.targets.is_online(target),
      timeout=10.0,
      interval=3.0
   )

   # Wait for the target to reboot and become fully ready
   cockpit.wait_until(
      lambda: cockpit.targets.is_ready(target),
      timeout=120.0,
      interval=3.0,
   )

API Reference

class imperix.TargetCollection(cockpit: Cockpit)

Imperix controllers detected by Cockpit. Accessed via imperix.Cockpit.targets.

list(*, timeout: float | None | UseDefaultTimeout = UseDefaultTimeout.TOKEN) → list[Target]

Returns a list of the targets currently detected by Cockpit.

Parameters:

timeout – Maximum time to wait for a response in seconds.

Returns:

A list of Target instances.

Example:

for target in cockpit.targets.list():
    print(target.mac, target.ip)
refresh(*, timeout: float | None | UseDefaultTimeout = UseDefaultTimeout.TOKEN) → list[Target]

Runs an Ethernet network scan and returns a list of the targets currently detected by Cockpit.

Parameters:

timeout – Maximum time to wait for a response in seconds.

Returns:

A list of Target instances.

Example:

targets = cockpit.targets.refresh()
for target in targets:
    print(target.mac, target.ip)
get_realsync_network(mac: str, *, timeout: float | None | UseDefaultTimeout = UseDefaultTimeout.TOKEN) → list[Target]

Returns a list of all targets in the specified target’s RealSync network.

The targets are ordered by ascending RealSync ID.

Parameters:
  • mac – MAC address of any target in the RealSync network.

  • timeout – Maximum time to wait for a response in seconds.

Returns:

A list of Target instances.

Raises:

NotFoundError – If Cockpit does not know the target.

Example:

network = cockpit.targets.get_realsync_network("AA:BB:CC:DD:EE:FF")
for realsync_id, target in enumerate(network):
    print(realsync_id, target.mac)
update_firmware(targets: str | Target | Sequence[str | Target], *, timeout: float | None | UseDefaultTimeout = UseDefaultTimeout.TOKEN) → None

Updates targets to the firmware supplied with the current SDK.

User code must be stopped on all selected targets. To update a RealSync network, include all targets in that network. Targets are not rebooted after the update.

Parameters:
  • targets – MAC address(es) or Target instance(s).

  • timeout – Maximum time to wait per target, in seconds.

Raises:

Example:

network = cockpit.targets.get_realsync_network("AA:BB:CC:DD:EE:FF")
cockpit.targets.update_firmware(network)
is_online(targets: str | Target | Sequence[str | Target], *, timeout: float | None | UseDefaultTimeout = UseDefaultTimeout.TOKEN) → bool

Checks whether targets are currently online.

This method runs refresh() behind the scenes to ensure up-to-date results.

Parameters:
  • targets – MAC address(es) or Target instance(s).

  • timeout – Maximum time to wait for a response in seconds.

Returns:

True if all requested targets are online, False otherwise.

Example:

cockpit.targets.is_online(["AA:BB:CC:DD:EE:01", "AA:BB:CC:DD:EE:02"])
is_ready(targets: str | Target | Sequence[str | Target], *, timeout: float | None | UseDefaultTimeout = UseDefaultTimeout.TOKEN) → bool

Checks whether targets finished booting and are ready to receive a new user code.

This method runs refresh() behind the scenes to ensure up-to-date results.

Parameters:
  • targets – MAC address(es) or Target instance(s).

  • timeout – Maximum time to wait for a response in seconds.

Returns:

True if all requested targets are online, False otherwise.

Example:

cockpit.targets.is_ready(["AA:BB:CC:DD:EE:01", "AA:BB:CC:DD:EE:02"])
class imperix.Target(cockpit: Cockpit, data: dict[str, Any])

Represents an imperix controllers.

property mac: str

The MAC address of the target (primary identifier).

property hostname: str

The hostname of the target, if available.

property ip: str

The IP address of the target, if available.

property controller: Controller

The type of controller.

enable_pwm(*, timeout: float | None | UseDefaultTimeout = UseDefaultTimeout.TOKEN) → None

Enables the PWM outputs.

Parameters:

timeout – Override the default timeout (seconds).

Raises:

InvalidStateError – If user code is not running or the outputs cannot be enabled.

disable_pwm(*, timeout: float | None | UseDefaultTimeout = UseDefaultTimeout.TOKEN) → None

Disables the PWM outputs.

Parameters:

timeout – Maximum time to wait for a response in seconds.

Raises:

InvalidStateError – If user code is not running or the outputs cannot be disabled.

reboot(*, delay_ms: int | None = None, timeout: float | None | UseDefaultTimeout = UseDefaultTimeout.TOKEN) → None

Reboots the target.

This operation is not supported on B-Box 3 targets.

Parameters:
  • delay_ms – Delay in milliseconds before rebooting. None reboots immediately.

  • timeout – Maximum time to wait for a response in seconds.

Raises:

InvalidStateError – If the target cannot be rebooted.

upload_bitstream(path: str | PathLike[str], *, timeout: float | None | UseDefaultTimeout = UseDefaultTimeout.TOKEN) → None

Uploads a customized FPGA bitstream (.bit) to this target.

Parameters:
  • path – Absolute path to the bitstream file, as a string or Path.

  • timeout – Override the default timeout (seconds).

Raises:

InvalidStateError – If the file cannot be sent to the target.

Example:

target.upload_bitstream(r"C:\\imperix\\tests\\custom_bitstream.bit")
target.reboot()

# Wait for the target to go offline
cockpit.wait_until(
    lambda: not cockpit.targets.is_online(target),
    timeout=10.0,
    interval=3.0
)

# Wait for the target to reboot and be ready
cockpit.wait_until(
    lambda: cockpit.targets.is_ready(target),
    timeout=120.0,
    interval=3.0,
)
get_core_state(*, timeout: float | None | UseDefaultTimeout = UseDefaultTimeout.TOKEN) → CoreState

Returns the target’s current core state.

Parameters:

timeout – Override the default timeout (seconds).

Returns:

The CoreState reported by the target.

Raises:

NotFoundError – If the target cannot be found.

Example:

state = target.get_core_state()
get_timing_info(*, timeout: float | None | UseDefaultTimeout = UseDefaultTimeout.TOKEN) → TimingInfo

Returns the timing information of the user code running on the target.

Parameters:

timeout – Override the default timeout (seconds).

Returns:

A TimingInfo snapshot.

Raises:

Example:

info = target.get_timing_info()
print(f"CPU load: {info.cpu_load_percent.max:.1f} %")
get_firmware_version(*, timeout: float | None | UseDefaultTimeout = UseDefaultTimeout.TOKEN) → str

Returns the firmware version of the target.

Parameters:

timeout – Override the default timeout (seconds).

Returns:

The firmware version, for example "2026.3.2609081559".

Raises:

Example:

print(target.get_firmware_version())
get_user_code_info(*, timeout: float | None | UseDefaultTimeout = UseDefaultTimeout.TOKEN) → UserCodeInfo

Returns information about the user code loaded on the target and saved on its SD card.

Parameters:

timeout – Override the default timeout (seconds).

Returns:

A UserCodeInfo.

Raises:

Example:

code = target.get_user_code_info()
print(code.name, code.date)
get_bitstream_info(*, timeout: float | None | UseDefaultTimeout = UseDefaultTimeout.TOKEN) → BitstreamInfo

Returns information about the FPGA bitstream of the target.

Parameters:

timeout – Override the default timeout (seconds).

Returns:

A BitstreamInfo.

Raises:

Example:

bitstream = target.get_bitstream_info()
print(bitstream.build_id, bitstream.user_id)
get_license_info(*, timeout: float | None | UseDefaultTimeout = UseDefaultTimeout.TOKEN) → LicenseInfo

Returns information about the licenses of the target.

Parameters:

timeout – Override the default timeout (seconds).

Returns:

A LicenseInfo.

Raises:

Example:

production = target.get_license_info().production
if production is not None:
    print(production.used_tokens, "/", production.token_limit)
get_network_config(*, timeout: float | None | UseDefaultTimeout = UseDefaultTimeout.TOKEN) → NetworkConfig

Returns the network configuration of the target.

Parameters:

timeout – Override the default timeout (seconds).

Returns:

A NetworkConfig.

Raises:

Example:

print(target.get_network_config().static_ip)
get_chip_temperature(*, timeout: float | None | UseDefaultTimeout = UseDefaultTimeout.TOKEN) → float

Returns the junction temperature of the target processor.

Parameters:

timeout – Override the default timeout (seconds).

Returns:

The temperature in degrees Celsius, accurate to ±4 °C.

Raises:

Example:

print(f"{target.get_chip_temperature():.1f} °C")
run_speedtest(*, timeout: float | None | UseDefaultTimeout = UseDefaultTimeout.TOKEN) → float

Measures the network download speed from the target to this PC.

The test takes about 5 seconds and requires the user code to be stopped.

Parameters:

timeout – Override the default timeout (seconds).

Returns:

The download speed in Mb/s.

Raises:

Example:

print(f"{target.run_speedtest():.0f} Mb/s")
acknowledge_fault(*, timeout: float | None | UseDefaultTimeout = UseDefaultTimeout.TOKEN) → None

Acknowledges analog faults on this target (B-Box 4 and B-Box Micro only).

Parameters:

timeout – Override the default timeout (seconds).

Raises:

Example:

target.acknowledge_fault()
remove_bitstream(*, timeout: float | None | UseDefaultTimeout = UseDefaultTimeout.TOKEN) → None

Remove the saved custom FPGA bitstream from this target.

Waits for the target’s response. Does not reboot the target.

Parameters:

timeout – Override the default timeout (seconds).

Raises:

Example:

target.remove_bitstream()
load_license(path: str | PathLike[str], *, timeout: float | None | UseDefaultTimeout = UseDefaultTimeout.TOKEN) → None

Loads a license file (.lic) on this target.

Parameters:
  • path – Absolute path to the license file, as a string or Path.

  • timeout – Override the default timeout (seconds).

Raises:

Example:

target.load_license(r"C:\\imperix\\licenses\\production.lic")
upload_user_code(path: str | PathLike[str], *, timeout: float | None | UseDefaultTimeout = UseDefaultTimeout.TOKEN) → None

Upload a user code (.elf) file to this target.

Parameters:
  • path – Absolute path to the user code .elf file, as a string or Path.

  • timeout – Maximum time to wait for a response in seconds.

Raises:

InvalidStateError – If the file cannot be sent to the target.

Example::

target = cockpit.targets[“AA:BB:CC:DD:EE:FF”] target.stop_code() target.upload_user_code(r”C:\imperix\tests\motor_control.elf”) target.start_code()

start_code(*, bypass_warnings: bool | None = None, timeout: float | None | UseDefaultTimeout = UseDefaultTimeout.TOKEN) → None

Starts the user code execution on this target.

Parameters:
  • bypass_warnings – Whether to bypass Cockpit warning popups (e.g. “A code is already running on this target”).

  • timeout – Maximum time to wait for a response in seconds.

Raises:

InvalidStateError – If user code cannot be started.

stop_code(*, timeout: float | None | UseDefaultTimeout = UseDefaultTimeout.TOKEN) → None

Stops the user code execution on this target.

Parameters:

timeout – Maximum time to wait for a response in seconds.

Raises:

InvalidStateError – If user code cannot be stopped.

class imperix.TimingInfo(clk0_frequency_hz: float, clk1_frequency_hz: float | None, clk2_frequency_hz: float | None, clk3_frequency_hz: float | None, sclk_frequency_hz: float, cpu_frequency_hz: float, cpu_load_percent: TimingStats, cycle_delay_us: TimingStats)

Timing information of the user code running on a target, as shown in the Timings tab of Cockpit.

clk0_frequency_hz

Frequency of CLK0 in hertz.

Type:

float

clk1_frequency_hz

Frequency of CLK1 in hertz, None if unused.

Type:

float | None

clk2_frequency_hz

Frequency of CLK2 in hertz, None if unused.

Type:

float | None

clk3_frequency_hz

Frequency of CLK3 in hertz, None if unused.

Type:

float | None

sclk_frequency_hz

FPGA sampling frequency (SCLK) in hertz.

Type:

float

cpu_frequency_hz

Execution frequency of the control task in hertz.

Type:

float

cpu_load_percent

CPU load in percent.

Type:

imperix._targets.TimingStats

cycle_delay_us

Cycle delay in microseconds.

Type:

imperix._targets.TimingStats

class imperix.TimingStats(min: float, avg: float, max: float)

Minimum, average and maximum of a timing value measured by the target.

min

Minimum value.

Type:

float

avg

Average value.

Type:

float

max

Maximum value.

Type:

float

class imperix.UserCodeInfo(name: str | None, date: datetime | None, saved_name: str | None, saved_date: datetime | None, load_at_startup: bool)

Information about the user code loaded on a target and saved on its SD card.

name

File name of the last user code loaded on the target, None if no code was loaded since the target booted.

Type:

str | None

date

Date of the loaded user code file, None if unknown.

Type:

datetime.datetime | None

saved_name

File name of the user code saved on the SD card, None if no code is saved.

Type:

str | None

saved_date

Date of the saved user code file, None if unknown.

Type:

datetime.datetime | None

load_at_startup

Whether the saved user code starts when the target boots.

Type:

bool

class imperix.BitstreamInfo(build_id: int | None, user_id: int | None, name: str | None, date: datetime | None, load_at_startup: bool)

FPGA bitstream running on a target and custom bitstream saved on its SD card.

build_id

Build ID of the imperix firmware in the running bitstream, None if the target does not report it.

Type:

int | None

user_id

ID set by the user in a custom bitstream, 0 with the default bitstream, None if the target does not report it.

Type:

int | None

name

File name of the custom bitstream saved on the SD card, None if no custom bitstream is saved.

Type:

str | None

date

Date the saved custom bitstream was uploaded, in the local time of the PC that uploaded it, None if unknown.

Type:

datetime.datetime | None

load_at_startup

Whether the saved custom bitstream is loaded when the target boots.

Type:

bool

class imperix.LicenseInfo(acg: License | None, cpp: License | None, production: License | None)

Information about the licenses of a target.

acg

ACG SDK license, None if the target has none.

Type:

imperix._targets.License | None

cpp

C++ SDK license, None if the target has none.

Type:

imperix._targets.License | None

production

Production license, None if the target has none.

Type:

imperix._targets.License | None

class imperix.License(expiry: date | None, used_tokens: int | None, token_limit: int | None)

License loaded on a target.

expiry

Expiry date, None if the license never expires.

Type:

datetime.date | None

used_tokens

Number of production code loads already used, None if the license has no tokens.

Type:

int | None

token_limit

Number of production code loads allowed, None if the license has no tokens.

Type:

int | None

class imperix.NetworkConfig(static_ip: str | None, static_ip_2: str | None, dynamic_ip: str | None)

Network configuration of a target.

static_ip

First static IP address, None if not reported.

Type:

str | None

static_ip_2

Second static IP address, None if not configured.

Type:

str | None

dynamic_ip

Last IP address obtained by DHCP, or a self-assigned 169.254.x.x address when no DHCP server answered, None if none.

Type:

str | None

Enumerations

class imperix.CoreState(*values)

Core states reported by an imperix controller.

Values:
  • OFFLINE: User code is stopped.

  • CONFIG: User code initialization is in progress.

  • BLOCKED: User code is running with PWM outputs disabled.

  • OPERATING: User code is running with PWM outputs enabled.

  • FAULT: An analog fault is active.

OFFLINE = 'Offline'
CONFIG = 'Config'
BLOCKED = 'Blocked'
OPERATING = 'Operating'
FAULT = 'Fault'
class imperix.Controller(*values)

Types of imperix controllers.

Values:
  • B_BOX_3: B-Box 3.

  • B_BOX_4: B-Box 4.

  • B_BOX_3_MICRO: B-Box 3 Micro.

  • B_BOARD_3: B-Board 3.

  • TPI8032: TPI8032 programmable inverter.

  • UNKNOWN: Controller type not reported or not recognized.

B_BOX_3 = 'B-Box 3'
B_BOX_4 = 'B-Box 4'
B_BOX_3_MICRO = 'B-Box 3 Micro'
B_BOARD_3 = 'B-Board 3'
TPI8032 = 'TPI8032'
UNKNOWN = 'Unknown'