Cracker Module

The Cracker module includes all operations on the device, such as device configuration, data transmission, and acquisition.

_images/cracker_struct.drawio.png

CrackerBasic

class cracknuts.cracker.cracker_basic.ConfigBasic[source]

Bases: object

__init__()[source]
dump_to_json()[source]

Dump the configuration to a JSON string.

Returns:

JSON string representation of the configuration.

Return type:

str

load_from_json(json_str)[source]

Load configuration from a JSON string. If a value in the JSON string is null, it will be skipped and the default configuration will be used.

Parameters:

json_str (str) – JSON string to load configuration from.

Returns:

This configuration instance with values updated from the JSON string.

Return type:

ConfigBasic

class cracknuts.cracker.cracker_basic.CrackerBasic(address=None, bin_server_path=None, bin_bitstream_path=None)[source]

Bases: ABC, Generic

DISCONNECTED = -2
NON_PROTOCOL_ERROR = -1
__init__(address=None, bin_server_path=None, bin_bitstream_path=None)[source]
Parameters:
  • address (str | tuple | None) – Cracker device address (ip, port) or “[cnp://]<ip>[:port]”, If no configuration is provided here, it needs to be configured later by calling set_address, set_ip_port, or set_uri.

  • bin_server_path (str | None) – The bin_server (firmware) file for updates; normally, the user should not specify this.

  • bin_bitstream_path (str | None) – The bin_bitstream (firmware) file for updates; normally, the user should not specify this.

change_ip(new_ip, new_mask=None, new_gateway=None)[source]

Change the network address of the current target device.

This instance method uses the IP currently configured on this object as the target device IP, then delegates the network change to the shared CrackerManager instance. If the device is currently connected and the IP change succeeds, the object updates its own target address and reconnects when possible.

Parameters:
  • new_ip (str) – New device IP address, or "dhcp" to enable DHCP.

  • new_mask (str | None) – Subnet mask or prefix length for a static IP change. If omitted, the device’s current mask is reused.

  • new_gateway (str | None) – Default gateway for a static IP change. If omitted, the device’s current gateway is reused.

Returns:

True if the device accepted the change request, otherwise False.

Return type:

bool

connect(update_bin=True, force_update_bin=False, bin_server_path=None, bin_bitstream_path=None, force_write_default_config=False)[source]

Connect to cracker device.

Parameters:
  • update_bin (bool) – Whether to update the firmware.

  • force_update_bin (bool) – Whether to force update the firmware while the device is running normally (by default, firmware updates are not performed when the device is running normally).

  • bin_server_path (str | None) – The bin_server (firmware) file for updates.

  • bin_bitstream_path (str | None) – The bin_bitstream (firmware) file for updates.

  • force_write_default_config (bool) – Whether to force update the configuration while the device is running normally (by default, configuration updates are only performed when updating the firmware).

Return type:

None

Returns:

None

disconnect()[source]

Disconnect from cracker device.

Return type:

None

Returns:

None

classmethod discover_devices(broadcast='255.255.255.255', scan_interval=3.0, offline_grace=15.0, device_timeout=60.0)[source]

Discover devices on the local network once.

This class method reuses the shared CrackerManager instance and performs a single discovery scan without starting continuous background monitoring.

Parameters:
  • broadcast (str) – Broadcast address for discovery.

  • scan_interval (float) – Cached scan interval for the shared manager.

  • offline_grace (float) – Cached offline grace period for the shared manager.

  • device_timeout (float) – Cached device timeout for the shared manager.

Returns:

List of discovered device information dictionaries.

Return type:

list[dict]

dump_config(path=None)[source]

Dump the current config to a JSON file if a path is specified, or to a JSON string if no path is specified.

Parameters:

path (str | None) – the path to the JSON file

Returns:

the content of JSON string or None if no path is specified.

Return type:

str | None

get_address()[source]

Get the device address in tuple format.

Returns:

address in tuple format: (ip, port).

Return type:

tuple[str, int]

get_bitstream_version()[source]
get_connection_status()[source]

Get connection status.

Returns:

True for connected and False for disconnected.

Return type:

bool

get_current_config()[source]

Get current configuration of Cracker. Note: Currently, the configuration returned is recorded on the host computer, not the ACTUAL configuration of the device. In the future, it should be synchronized from the device to the host computer.

Returns:

Current configuration of Cracker.

Return type:

ConfigBasic

abstractmethod get_default_config()[source]

Get the default configuration. This method needs to be implemented by the specific device class, as different devices have different default configurations.

Returns:

The default config object(The specific subclass of CommonConfig).

Return type:

ConfigBasic

get_firmware_info()[source]
get_firmware_version()[source]

Get the version of the equipment.

Returns:

The equipment response status code and the version of the equipment.

Return type:

tuple[int, str | None]

get_hardware_model()[source]

Get the name of the equipment.

Returns:

The equipment response status code and the name of the equipment.

Return type:

tuple[int, str | None]

get_id()[source]

Get the ID of the equipment.

Returns:

The equipment response status code and the ID of the equipment.

Return type:

tuple[int, str | None]

get_uri()[source]

Get the device address in URI format.

Returns:

URI. if cracker address is not specified, None is returned.

Return type:

str | None

load_config_from_file(path)[source]

Load config from a JSON file.

Parameters:

path (str) – the path to the JSON file

Return type:

None

Returns:

None

load_config_from_str(json_str)[source]

Load config from a JSON string.

Parameters:

json_str (str) – the JSON string

Return type:

None

Returns:

None

osc_force()[source]

Force produce a wave data.

Returns:

The device response status

Return type:

tuple[int, None]

osc_get_analog_wave(channel, offset, sample_count)[source]

Get the analog wave.

Parameters:
  • channel (int|str) – The channel of the analog wave. It can be either 0, 1, or ‘A’, ‘B’.

  • offset (int) – the offset of the analog wave.

  • sample_count (int) – the sample count of the analog wave.

Returns:

the analog wave.

Return type:

tuple[int, np.ndarray]

osc_get_digital_wave(channel, offset, sample_count)[source]
Return type:

tuple[int, ndarray]

osc_get_wave(channel, offset, sample_count)[source]
Return type:

tuple[int, ndarray | None]

osc_is_triggered()[source]
Return type:

tuple[int, bool]

osc_single()[source]
Return type:

tuple[int, None]

reconnect()[source]

Reconnect to cracker device.

Returns:

None

send_and_receive(message)[source]

Send message to cracker device.

Parameters:

message (bytes) – The byte message to send.

Returns:

Received message in format: (status, message).

Return type:

tuple[int, bytes | None]

send_with_command(command, rfu=0, payload=None)[source]
Return type:

tuple[int, bytes | None]

set_address(address)[source]

Update the target cracker address stored in this instance.

This method updates the local target address metadata used by this object and synchronizes the inner SSHCracker target IP settings. It does not communicate with the device, so it does not modify the real device network configuration.

Parameters:

address (tuple[str, int] | str | None) – Device address as (ip, port), URI-like string, or None to clear the current target.

Return type:

None

Returns:

None

classmethod set_device_ip(target_ip, new_ip, mask='', gateway='', delay_ms=200, broadcast='255.255.255.255')[source]

Change the network address of a device identified by its current IP.

This class method reuses the shared CrackerManager instance and sends a single IP change request to the target device. When mask and gateway are omitted the device-side manager will apply its own defaults.

Parameters:
  • target_ip (str) – Current IP address of the target device.

  • new_ip (str) – New device IP address, or "dhcp" to enable DHCP.

  • mask (str) – Subnet mask. If omitted, the device-side manager handles it.

  • gateway (str) – Default gateway. If omitted, the device-side manager handles it.

  • delay_ms (int) – Delay before the device applies the change.

  • broadcast (str) – Broadcast address cached on the shared manager.

Returns:

ACK information from the device, or None on timeout.

Return type:

dict | None

set_ip_port(ip, port)[source]

Update the target cracker IP and port stored in this instance.

This method updates the local target address used by subsequent operations and synchronizes the inner SSHCracker object to the same target. It does not modify the real device network configuration.

Parameters:
  • ip (str) – IP address.

  • port (int) – Port.

Return type:

None

Returns:

None

set_logger_debug_payload_max_length(length)[source]
set_logger_info_payload_max_length(length)[source]
set_logging_level(level)[source]

Set the Cracker OS logging level.

Parameters:

level (str) – The logging level: debug, info, warning, or error.

Return type:

None

Returns:

None

set_uri(uri)[source]

Update the target cracker address stored in this instance from a URI.

This method parses and stores the local target address, then synchronizes the inner SSHCracker object to that target. It does not communicate with the device and does not modify the device IP.

Parameters:

uri (str) – Device URI in the form cnp://<ip>[:port] or <ip>[:port].

Return type:

None

Returns:

None

property shell: SSHClient | None

SSH connection to the device.

Use this to run commands or upload files on the device without configuring credentials yourself. Only generic SSH operations (exec, upload, etc.) are exposed through this interface.

write_config_to_cracker(config)[source]

Sync config to cracker.

To prevent configuration inconsistencies between the host and the device, so all configuration information needs to be written to the device. User should call this function before get data from device.

NOTE: This function is currently ignored and will be resumed after all Cracker functions are completed.

cracknuts.cracker.cracker_basic.connection_status_check(func)[source]

This is a decorator to check the connection status of the cracker device. user should use this directly.

CrackerS1

class cracknuts.cracker.cracker_s1.ConfigS1[source]

Bases: ConfigBasic

__init__()[source]
class cracknuts.cracker.cracker_s1.CrackerS1(address=None, bin_server_path=None, bin_bitstream_path=None)[source]

Bases: CrackerBasic[ConfigS1]

digital_pin_mode(pin_num, mode)[source]

Set the operating mode of a digital IO pin.

Parameters:
  • pin_num (int) – Pin number (zero-indexed); supports pins 5 and 6.

  • mode (int | str) – Pin operating mode: 1 for input, 0 for output, or "INPUT" / "OUTPUT".

Returns:

Device response status and received data: (status, response).

Return type:

tuple[int, bytes | None]

digital_read(pin_num)[source]

Read the level state of a digital IO pin.

Parameters:

pin_num (int) – Pin number (zero-indexed); supports pins 5 and 6.

Returns:

Device response status and pin level: (status, level).

Return type:

tuple[int, bytes | None | int]

digital_write(pin_num, value)[source]

Set the level state of a digital IO pin.

Parameters:
  • pin_num (int) – Pin number (zero-indexed); supports pins 5 and 6.

  • value (int) – Pin level state: 1 for high, 0 for low.

Returns:

Device response status and received data: (status, response).

Return type:

tuple[int, bytes | None]

get_current_config()[source]

Get current configuration of Cracker. Note: Currently, the configuration returned is recorded on the host computer, not the ACTUAL configuration of the device. In the future, it should be synchronized from the device to the host computer.

Returns:

Current configuration of Cracker.

Return type:

ConfigBasic

get_default_config()[source]

Get the default configuration. This method needs to be implemented by the specific device class, as different devices have different default configurations.

Returns:

The default config object(The specific subclass of CommonConfig).

Return type:

ConfigBasic

i2c_config(dev_addr=None, speed=None, enable_stretch=False)[source]

Configure the I2C interface.

Accepts enum members from cracknuts.cracker.serial or direct numeric/string values (eliminating the need to import the enum module). Invalid values are rejected with an error and the function returns (self.NON_PROTOCOL_ERROR, None).

Parameters:
  • dev_addr (int | str | None) – Device address (0-127). Can be an int (0-127), or string in hex format (“0x1A”, “1A”) or decimal format (“26”). Default: current config value.

  • speed (serial.I2cSpeed | int | str | None) – Bus speed. Can be a serial.I2cSpeed enum, int (100000, 400000, 1000000, 3400000, 5000000 Hz), or string (“100K”, “400K”, “1M”, “3400K”, “5M”). Default: current config value.

  • enable_stretch (bool) – Whether to enable clock stretching.

Returns:

Device response status and None.

Return type:

tuple[int, None]

i2c_disable()[source]

Disable the I2C interface.

Returns:

Device response status and received data: (status, response).

Return type:

tuple[int, None]

i2c_enable()[source]

Enable the I2C interface.

Returns:

Device response status and received data: (status, response).

Return type:

tuple[int, None]

i2c_receive(rx_count, is_trigger=False)[source]

Receive data over the I2C interface.

When is_trigger=True, the Trigger signal is pulled low at the start of reception and high upon completion:

TRIG: ───┐            ┌─── HIGH
         |            |
         └────────────┘    LOW
         ┌────────────┐
         │   rx_data  │
         └────────────┘

When is_trigger=False, the Trigger signal remains unchanged:

TRIG: ──────────────────── HIGH

                           LOW
         ┌────────────┐
         │   rx_data  │
         └────────────┘
Parameters:
  • rx_count (int) – Number of bytes to receive.

  • is_trigger (bool) – Whether to generate a trigger signal during data reception (pulled low at start, high at end).

Returns:

Device response status and received data: (status, response).

Return type:

tuple[int, bytes | None]

i2c_reset()[source]

Reset the I2C configuration.

Returns:

Device response status and received data: (status, response).

Return type:

tuple[int, None]

i2c_transceive(tx_data, rx_count, is_trigger=False)[source]

Send and receive data over I2C without any inter-phase delay.

When is_trigger=True, the Trigger signal is pulled low at the start of transmission and high upon completion:

TRIG: ───┐                         ┌─── HIGH
         |                         |
         └─────────────────────────┘    LOW
         ┌────────────┬────────────┐
         │  tx_data   │   rx_data  │
         └────────────┴────────────┘

When is_trigger=False, the Trigger signal remains unchanged:

TRIG: ──────────────────────────────── HIGH

                                       LOW
         ┌────────────┬────────────┐
         │  tx_data   │   rx_data  │
         └────────────┴────────────┘
Parameters:
  • tx_data (bytes | str | int) – Data to send. Accepts bytes, a hex string, or an integer (converted to big-endian bytes using the minimum required length).

  • rx_count (int) – Number of bytes to receive.

  • is_trigger (bool) – Whether to generate a trigger signal during transmission (pulled low at start, high at end).

Returns:

Device response status and received data: (status, response).

Return type:

tuple[int, bytes | None]

Raises:

TypeError – If tx_data is not bytes, str, or int.

i2c_transmit(tx_data, is_trigger=False)[source]

Send data over the I2C interface.

When is_trigger=True, the Trigger signal is pulled low at the start of transmission and high upon completion:

TRIG: ───┐            ┌─── HIGH
         |            |
         └────────────┘    LOW
         ┌────────────┐
         │   tx_data  │
         └────────────┘

When is_trigger=False, the Trigger signal remains unchanged:

TRIG: ──────────────────── HIGH

                           LOW
         ┌────────────┐
         │   tx_data  │
         └────────────┘
Parameters:
  • tx_data (bytes | str | int) – Data to send. Accepts bytes, a hex string, or an integer (converted to big-endian bytes using the minimum required length).

  • is_trigger (bool) – Whether to generate a trigger signal during transmission (pulled low at start, high at end).

Returns:

Device response status and None: (status, None).

Return type:

tuple[int, None]

Raises:

TypeError – If tx_data is not bytes, str, or int.

i2c_transmit_delay_receive(tx_data, delay, rx_count, is_trigger=False)[source]

Send data over I2C, wait for the specified delay, then receive data.

When is_trigger=True, the Trigger signal is pulled low at the start of transmission and high upon completion:

TRIG: ───┐            ┌────────────┐            ┌─── HIGH
         |            |            |            |
         └────────────┘            └────────────┘    LOW
         ┌────────────┬────────────┬────────────┐
         │  tx_data   │    delay   │   rx_data  │
         └────────────┴────────────┴────────────┘

When is_trigger=False, the Trigger signal remains unchanged:

TRIG: ────────────────────────────────────────────── HIGH

                                                     LOW
         ┌────────────┬────────────┬────────────┐
         │  tx_data   │    delay   │   rx_data  │
         └────────────┴────────────┴────────────┘
Parameters:
  • tx_data (bytes | str | int) – Data to send. Accepts bytes, a hex string, or an integer (converted to big-endian bytes using the minimum required length).

  • delay (int) – Delay between transmit and receive phases, in units of 10 nanoseconds.

  • rx_count (int) – Number of bytes to receive.

  • is_trigger (bool) – Whether to generate a trigger signal during transmission (pulled low at start, high at end).

Returns:

Device response status and received data: (status, response).

Return type:

tuple[int, bytes | None]

Raises:

TypeError – If tx_data is not bytes, str, or int.

nut_clock_disable()[source]

Disable the nut clock.

Returns:

The device response status

Return type:

tuple[int, None]

nut_clock_enable()[source]

Enable the nut clock.

Returns:

The device response status

Return type:

tuple[int, None]

nut_clock_freq(clock)[source]

Set nut clock.

Parameters:

clock (float | int | str) – The clock of the nut in kHz

Returns:

The device response status

Return type:

tuple[int, None]

nut_reset(polar=0, time=10)[source]

Reset the RESET pin of the nut chip. The reset level polarity and duration are configurable. By default the RESET pin is in tri-state input mode; the board design must ensure the default state is non-reset (e.g. pulled high). After calling nut_reset(), the RESET pin is driven to the configured polarity level for the specified duration.

polar=LOW
TRIG: ~~~ ┐            ┌ ~~~
          └────────────┘     LOW
          |<-  time  ->|

polar=HIGH
TRIG:    ┌────────────┐     HIGH
     ~~~ ┘            └ ~~~
         |<-  time  ->|
Parameters:
  • polar (int) – Polarity: 0 for low level, 1 for high level.

  • time (int) – Duration of the reset level (in milliseconds).

Returns:

Device response status and received data: (status, response).

Return type:

tuple[int, bytes | None]

nut_reset_io_enable(enable)[source]
nut_timeout_ms(timeout)[source]

Set nut timeout.

Parameters:

timeout (int) – Nut timeout.

Returns:

The device response status

Return type:

tuple[int, None]

nut_voltage(voltage)[source]

Set nut voltage.

Parameters:

voltage (float | str | int) – Nut voltage can be a number or a string. If the input is a float, the voltage will be treated as a V value. If the input is a string, you can specify the unit, ending with the value, using either mV or V.

Returns:

The device response status

Return type:

tuple[int, None]

nut_voltage_disable()[source]

Disable the nut voltage.

Returns:

The device response status

Return type:

tuple[int, None]

nut_voltage_enable()[source]

Enable the nut voltage.

Returns:

The device response status

Return type:

tuple[int, None]

osc_analog_disable(channel)[source]

Disable osc analog.

Parameters:

channel (int | str) – Channel to enable, it can be ‘A’ or ‘B’, or 0, 1

Returns:

The device response status

Return type:

tuple[int, None]

osc_analog_enable(channel)[source]

Enable osc analog.

Parameters:

channel (int | str) – Channel to enable, it can be ‘A’ or ‘B’, or 0, 1

Returns:

The device response status

Return type:

tuple[int, None]

osc_analog_gain(channel, gain)[source]

Set analog gain.

Parameters:
  • channel (int | str) – Analog channel, it can be ‘A’ or ‘B’, or 0, 1

  • gain (int) – Analog gain.

Returns:

The device response status

Return type:

tuple[int, None]

osc_sample_clock(clock)[source]

Set osc sample rate

Parameters:

clock (int | str) – The sample rate in kHz can be one of (65000, 48000, 24000, 12000, 8000) or a string in (65M, 48M, 24M, 12M, 8M).

Returns:

The device response status

Return type:

tuple[int, None]

osc_sample_clock_phase(phase)[source]

Set sample phase.

Parameters:

phase (int) – Sample phase.

Returns:

The device response status

Return type:

tuple[int, None]

osc_sample_delay(delay)[source]

Set sample delay.

Parameters:

delay (int) – Sample delay. It can be a number or a string, if the input is a string, you can specify the unit, ending with the value, using either ‘k’ (representing 1024) or ‘m’ (representing 1024^2). For example, “1k” means 1024 and “2m” means 2097152.

Returns:

The device response status

Return type:

tuple[int, None]

osc_sample_length(length)[source]

Set sample length.

Parameters:

length (int | str) – Sample length. It can be a number or a string, if the input is a string, you can specify the unit, ending with the value, using either ‘k’ (representing 1024) or ‘m’ (representing 1024^2). For example, “1k” means 1024 and “2m” means 2097152.

Returns:

The device response status

Return type:

tuple[int, None]

osc_trigger_edge(edge)[source]

Set trigger edge.

Parameters:

edge (int | str) – Trigger edge. (‘up’, ‘down’, ‘either’) or (‘u’, ‘d’, ‘e’) or 0, 1, 2 represent up, down, either, respectively.

Returns:

The device response status

Return type:

tuple[int, None]

osc_trigger_level(edge_level)[source]

Set trigger edge level.

Parameters:

edge_level (int) – Edge level.

Returns:

The device response status

Return type:

tuple[int, None]

osc_trigger_mode(mode)[source]

Set trigger mode.

Parameters:

mode (int | str) – Trigger mode. Trigger mode can be one of (“EDGE”, “PATTERN”) or (“E”, “P”), or the index of the string value.

Returns:

The device response status

Return type:

tuple[int, None]

osc_trigger_source(source)[source]

Set trigger source.

Parameters:

source (int | str) – Trigger source: It can be one of (‘N’, ‘A’, ‘B’, ‘P’, ‘R’, ‘V’) or (‘Nut’, ‘ChA’, ‘ChB’, ‘Protocol’, ‘Reset’, ‘Voltage’) or a number in 0 1 2 3 4 5 represent Nut, Channel A, Channel B, Protocol, Reset and Voltage respectively.

Returns:

The device response status

Return type:

tuple[int, None]

register_read(base_address, offset)[source]

Read register.

Parameters:
  • base_address (int) – Base address of the register.

  • offset (int) – Offset of the register.

Returns:

The device response status and the value read from the register or None if an exception is raised.

Return type:

tuple[int, bytes | None]

register_write(base_address, offset, data)[source]

Write register.

Parameters:
  • base_address (int) – Base address of the register.

  • offset (int) – Offset of the register.

  • data (bytes | int | str) – Data to write.

Returns:

The device response status

Return type:

tuple[int, None]

spi_config(speed=None, cpol=None, cpha=None, csn_auto=None, csn_delay=None)[source]

Configure the SPI interface parameters, including CPOL (clock polarity) and CPHA (clock phase).

Accepts enum members from cracknuts.cracker.serial or direct numeric/string values (eliminating the need to import the enum module). Invalid values are rejected with an error and the function returns (self.NON_PROTOCOL_ERROR, None).

Parameters:
  • speed (float | None) – Communication speed in kHz (default 10 kHz). Relationship to PSC register: speed = (100e6) / (2 * PSC). Default: current config value.

  • cpol (serial.SpiCpol | int | str | None) – Clock polarity. Can be a serial.SpiCpol enum, int (0=LOW, 1=HIGH), or string (“LOW”, “HIGH”, “0”, “1”). Default: current config value.

  • cpha (serial.SpiCpha | int | str | None) – Clock phase. Can be a serial.SpiCpha enum, int (0=LOW, 1=HIGH), or string (“LOW”, “HIGH”, “0”, “1”). Default: current config value.

  • csn_auto (bool | None) – If True, the chip-select (CSN) signal is pulled low only during data communication. If False, CSN remains low continuously. Default: current config value.

  • csn_delay (bool | None) – If True, the CSN signal stays low during the delay period. If False, CSN is high during the delay. Default: current config value.

Returns:

Device response status and optional error message.

Return type:

tuple[int, None | str]

spi_disable()[source]

Disable the SPI interface.

Returns:

Device response status and received data: (status, response).

Return type:

tuple[int, None]

spi_enable()[source]

Enable the SPI interface.

Returns:

Device response status and received data: (status, response).

Return type:

tuple[int, None]

spi_receive(rx_count, dummy=b'\\x00', is_trigger=False)[source]

Receive rx_count bytes over the SPI interface.

When is_trigger=True, the Trigger signal is pulled low at the start of transmission and high upon completion:

TRIG: ───┐            ┌─── HIGH
         |            |
         └────────────┘    LOW
         ┌────────────┐
         │   rx_data  │
         └────────────┘

When is_trigger=False, the Trigger signal remains unchanged:

TRIG: ──────────────────── HIGH

                           LOW
         ┌────────────┐
         │   rx_data  │
         └────────────┘
Parameters:
  • rx_count (int) – Number of bytes to read.

  • dummy (bytes | str) – Filler data sent during the SPI read phase.

  • is_trigger (bool) – Whether to generate a trigger signal during data transmission (pulled low at start, high at end).

Returns:

Device response status and received data: (status, response). Returns None if an exception is caught.

Return type:

tuple[int, bytes | None]

spi_reset()[source]

Reset the SPI hardware.

Returns:

Device response status and received data: (status, response).

Return type:

tuple[int, None]

spi_transceive(tx_data, rx_count=None, dummy=b'\\x00', is_trigger=False)[source]

Send tx_data over the SPI interface and receive data simultaneously. By default, the number of bytes received equals the length of tx_data.

When is_trigger=True, the Trigger signal is pulled low at the start of transmission and high upon completion:

TRIG: ───┐            ┌─── HIGH
         |            |
         └────────────┘    LOW
         ┌────────────┐
         │   tx_data  │
         └────────────┘
         ┌────────────┐
         │   rx_data  │
         └────────────┘

When is_trigger=False, the Trigger signal remains unchanged:

TRIG: ──────────────────── HIGH

                           LOW
         ┌────────────┐
         │   tx_data  │
         └────────────┘
         ┌────────────┐
         │   rx_data  │
         └────────────┘
Parameters:
  • tx_data (bytes | str | int) – Data to send. Accepts bytes, a hex string, or an integer (converted to big-endian bytes using the minimum required length).

  • rx_count (int) – Number of bytes to receive. Defaults to the length of tx_data. If specified: 1. When rx_count > len(tx_data), dummy bytes are appended to tx_data. 2. When rx_count < len(tx_data), the received data is truncated to rx_count.

  • dummy (bytes | str) – Filler byte used to pad tx_data when rx_count > len(tx_data).

  • is_trigger (bool) – Whether to generate a trigger signal during transmission (pulled low at start, high at end).

Returns:

Device response status and received data: (status, response).

Return type:

tuple[int, bytes | None]

Raises:

TypeError – If tx_data is not bytes, str, or int.

spi_transceive_delay_transceive(tx_data1, tx_data2, is_delay, delay, is_trigger)[source]

Send tx_data1 via SPI, wait for the specified delay (in units of 10 ns), then send tx_data2 and read back the response.

When is_trigger=True, the Trigger signal is pulled low at the start of transmission and high upon completion:

TRIG: ───┐            ┌────────────┐            ┌─── HIGH
         |            |            |            |
         └────────────┘            └────────────┘    LOW
         ┌────────────┬────────────┬────────────┐
         │  tx_data1  │    delay   │  tx_data2  │
         └────────────┴────────────┴────────────┘

When is_trigger=False, the Trigger signal remains unchanged:

TRIG: ────────────────────────────────────────────── HIGH

                                                     LOW
         ┌────────────┬────────────┬────────────┐
         │  tx_data1  │   timeout  │  rx_data2  │
         └────────────┴────────────┴────────────┘
Parameters:
  • tx_data1 (bytes | str | int | None) – Data to send in the first phase. Accepts bytes, a hex string, an integer (converted to big-endian bytes using the minimum required length), or None.

  • tx_data2 (bytes | str | int | None) – Data to send in the second phase. Same type rules as tx_data1.

  • is_delay (bool) – Whether to enable the inter-phase delay.

  • delay (int) – Delay between the two phases, in units of 10 nanoseconds.

  • is_trigger (bool) – Whether to generate a trigger signal during transmission (pulled low at start, high at end).

Returns:

Device response status and received data: (status, (response1, response2)).

Return type:

tuple[int, tuple[bytes | None, bytes | None] | None]

Raises:

TypeError – If tx_data1 or tx_data2 is not bytes, str, int, or None.

spi_transmit(tx_data, is_trigger=False)[source]

Send data over the SPI interface, optionally generating a trigger signal after transmission.

When is_trigger=True, the Trigger signal is pulled low at the start of transmission and high upon completion:

TRIG: ───┐            ┌─── HIGH
         |            |
         └────────────┘    LOW
         ┌────────────┐
         │   tx_data  │
         └────────────┘

When is_trigger=False, the Trigger signal remains unchanged:

TRIG: ──────────────────── HIGH

                           LOW
         ┌────────────┐
         │   tx_data  │
         └────────────┘
Parameters:
  • tx_data (bytes | str | int) – Data to send. Accepts bytes, a hex string, or an integer (converted to big-endian bytes using the minimum required length).

  • is_trigger (bool) – Whether to generate a trigger signal during transmission (pulled low at start, high at end).

Returns:

Device response status and None: (status, None).

Return type:

tuple[int, None]

spi_transmit_delay_receive(tx_data, delay, rx_count, dummy=b'\\x00', is_trigger=False)[source]

Send tx_data over SPI, wait for the specified delay (in units of 10 ns), then clock out rx_count dummy bytes and capture the slave’s response as rx_data.

When is_trigger=True, the Trigger signal is pulled low at the start of transmission and high upon completion:

TRIG: ───┐            ┌────────────┐            ┌─── HIGH
         |            |            |            |
         └────────────┘            └────────────┘    LOW
         ┌────────────┬────────────┬────────────┐
MASTER   │  tx_data   │    delay   │    dummy   │
         └────────────┴────────────┴────────────┘
         ┌────────────┬────────────┬────────────┐
SLAVE    │   dummy    │    delay   │   rx_data  │
         └────────────┴────────────┴────────────┘

When is_trigger=False, the Trigger signal remains unchanged:

TRIG: ────────────────────────────────────────────── HIGH

                                                     LOW
         ┌────────────┬────────────┬────────────┐
MASTER   │  tx_data   │    delay   │    dummy   │
         └────────────┴────────────┴────────────┘
         ┌────────────┬────────────┬────────────┐
SLAVE    │   dummy    │    delay   │   rx_data  │
         └────────────┴────────────┴────────────┘
Parameters:
  • tx_data (bytes | str | int) – Data to send. Accepts bytes, a hex string, or an integer (converted to big-endian bytes using the minimum required length).

  • delay (int) – Delay between transmit and receive phases, in units of 10 nanoseconds.

  • rx_count (int) – Number of bytes to read.

  • dummy (bytes | str) – Filler byte(s) clocked out during the receive phase.

  • is_trigger (bool) – Whether to generate a trigger signal during transmission (pulled low at start, high at end).

Returns:

Device response status and received data: (status, response).

Return type:

tuple[int, bytes | None]

uart_config(baudrate=None, bytesize=None, parity=None, stopbits=None)[source]

Configure the UART interface parameters.

Accepts enum members from cracknuts.cracker.serial or direct numeric/string values (eliminating the need to import the enum module). Invalid values are rejected with an error and the function returns (self.NON_PROTOCOL_ERROR, None).

Parameters:
  • baudrate (serial.Baudrate | int | str | None) – Baud rate. Can be a serial.Baudrate enum, int (9600, 19200, 38400, 57600, 115200, 1000000), or string (“9600”, “115200”, etc.). Default: current config value.

  • bytesize (serial.Bytesize | int | str | None) – Data bit length. Can be a serial.Bytesize enum, int (8), or string (“8”, “EIGHTBITS”). Default: current config value.

  • parity (serial.Parity | int | str | None) – Parity mode. Can be a serial.Parity enum, int (0=NONE, 1=EVEN, 2=ODD), or string (“NONE”, “EVEN”, “ODD”, “0”, “1”, “2”). Default: current config value.

  • stopbits (serial.Stopbits | int | str | None) – Stop bits. Can be a serial.Stopbits enum, int (1=ONE, 2=TWO), or string (“1”, “2”, “ONE”, “TWO”). Default: current config value.

Returns:

Device response status and None.

Return type:

tuple[int, None]

uart_disable()[source]

Disable the UART interface.

Deprecated since version 0.19.0: This function will be removed in a future version. Use uart_io_disable instead.

Returns:

Device response status and received data: (status, response).

Return type:

tuple[int, bytes | None]

uart_enable()[source]

Enable the UART interface.

Deprecated since version 0.19.0: This function will be removed in a future version. Use uart_io_enable instead.

Returns:

Device response status and received data: (status, response).

Return type:

tuple[int, bytes | None]

uart_io_disable()[source]

Disable the UART communication interface. After disabling, both TX and RX pins are set to a tri-state input.

Returns:

Device response status and received data: (status, response).

Return type:

tuple[int, bytes | None]

uart_io_enable()[source]

Enable the UART communication interface. After enabling, the TX pin goes high and the RX pin is set to a tri-state input.

Returns:

Device response status and received data: (status, response).

Return type:

tuple[int, bytes | None]

uart_receive(rx_count, timeout=10000, is_trigger=False)[source]

Receive data over the UART interface, optionally generating a trigger signal.

When is_trigger=True, the Trigger signal is pulled low at the start of reception and high upon completion:

TRIG: ───┐            ┌─── HIGH
         |            |
         └────────────┘    LOW
         ┌────────────┐
         │   rx_data  │
         └────────────┘

When is_trigger=False, the Trigger signal remains unchanged:

TRIG: ──────────────────── HIGH

                           LOW
         ┌────────────┐
         │   rx_data  │
         └────────────┘
Parameters:
  • rx_count (int) – Number of bytes to receive.

  • timeout (int) – Receive timeout in milliseconds.

  • is_trigger (bool) – Whether to generate a trigger signal upon reception completion. True: Trigger signal goes high when reception completes. False: Trigger signal remains unchanged.

Returns:

Device response status and received data: (status, response).

Return type:

tuple[int, bytes | None]

uart_receive_fifo_clear()[source]

Clear all remaining data in the UART receive FIFO.

Returns:

Device response status and received data: (status, response).

Return type:

tuple[int, bytes | None]

uart_receive_fifo_dump()[source]

Read all remaining data from the UART receive FIFO.

Returns:

Device response status and received data: (status, response).

Return type:

tuple[int, bytes | None]

uart_receive_fifo_remained()[source]

Read the number of unread bytes remaining in the UART receive FIFO.

Returns:

Device response status and the remaining byte count: (status, count).

Return type:

tuple[int, int]

uart_reset()[source]

Reset the UART hardware logic.

Returns:

Device response status and received data: (status, response).

Return type:

tuple[int, bytes | None]

uart_transmit(tx_data, is_trigger=False)[source]

Send data over the UART interface, optionally generating a trigger signal.

When is_trigger=True, the Trigger signal is pulled low at the start of transmission and high upon completion:

TRIG: ───┐            ┌─── HIGH
         |            |
         └────────────┘    LOW
         ┌────────────┐
         │  tx_data   │
         └────────────┘

When is_trigger=False, the Trigger signal remains unchanged:

TRIG: ──────────────────── HIGH

                           LOW
         ┌────────────┐
         │  tx_data   │
         └────────────┘
Parameters:
  • tx_data (str | bytes | int) – Data to send. Accepts bytes, a hex string, or an integer (converted to big-endian bytes using the minimum required length).

  • is_trigger (bool) – Whether to generate a trigger signal during transmission (pulled low at start, high at end).

Returns:

Device response status and None: (status, None).

Return type:

tuple[int, None]

uart_transmit_receive(tx_data=None, rx_count=0, timeout=10000, is_trigger=False)[source]

Send data over the UART interface, wait for a timeout period, then receive data.

When is_trigger=True, the Trigger signal is pulled low at the start of transmission and high upon completion:

TRIG: ───┐            ┌────────────┐            ┌─── HIGH
         |            |            |            |
         └────────────┘            └────────────┘    LOW
         ┌────────────┬────────────┬────────────┐
         │  tx_data   │   process  │   rx_data  │
         └────────────┴────────────┴────────────┘
                      | <------ timeout ------> |

When is_trigger=False, the Trigger signal remains unchanged:

TRIG: ────────────────────────────────────────────── HIGH

                                                     LOW
         ┌────────────┬────────────┬────────────┐
         │  tx_data   │   process  │   rx_data  │
         └────────────┴────────────┴────────────┘
                      | <------ timeout ------> |
Parameters:
  • tx_data (str | bytes | int | None) – Data to send. Accepts bytes, a hex string, an integer (converted to big-endian bytes using the minimum required length), or None.

  • rx_count (int) – Number of bytes to receive.

  • timeout (int) – Receive timeout in milliseconds.

  • is_trigger (bool) – Whether to generate a trigger signal during transmission (pulled low at start, high at end).

Returns:

Device response status and received data: (status, response).

Return type:

tuple[int, bytes | None]

Raises:

TypeError – If tx_data is not bytes, str, int, or None.

write_config_to_cracker(config)[source]

Sync config to cracker.

To prevent configuration inconsistencies between the host and the device, so all configuration information needs to be written to the device. User should call this function before get data from device.

NOTE: This function is currently ignored and will be resumed after all Cracker functions are completed.

CrackerG1

class cracknuts.cracker.cracker_g1.CommandG1[source]

Bases: Command

GLITCH_CLK_ARM = 816
GLITCH_CLK_CONFIG = 819
GLITCH_CLK_FORCE = 818
GLITCH_CLK_LEN_GLITCH = 822
GLITCH_CLK_LEN_NORMAL = 820
GLITCH_CLK_RESET = 817
GLITCH_CLK_WAVE_GLITCH = 823
GLITCH_CLK_WAVE_NORMAL = 821
GLITCH_GND_ARM = 800
GLITCH_GND_CONFIG = 803
GLITCH_GND_FORCE = 802
GLITCH_GND_NORMAL = 804
GLITCH_GND_RESET = 801
GLITCH_VCC_ARM = 784
GLITCH_VCC_CONFIG = 787
GLITCH_VCC_FORCE = 786
GLITCH_VCC_NORMAL = 788
GLITCH_VCC_RESET = 785
class cracknuts.cracker.cracker_g1.ConfigG1[source]

Bases: ConfigS1

__init__()[source]
class cracknuts.cracker.cracker_g1.CrackerG1(address=None, bin_server_path=None, bin_bitstream_path=None)[source]

Bases: CrackerS1

__init__(address=None, bin_server_path=None, bin_bitstream_path=None)[source]
Parameters:
  • address (str | tuple | None) – Cracker device address (ip, port) or “[cnp://]<ip>[:port]”, If no configuration is provided here, it needs to be configured later by calling set_address, set_ip_port, or set_uri.

  • bin_server_path (str | None) – The bin_server (firmware) file for updates; normally, the user should not specify this.

  • bin_bitstream_path (str | None) – The bin_bitstream (firmware) file for updates; normally, the user should not specify this.

get_current_config()[source]

Get current configuration of Cracker. Note: Currently, the configuration returned is recorded on the host computer, not the ACTUAL configuration of the device. In the future, it should be synchronized from the device to the host computer.

Returns:

Current configuration of Cracker.

Return type:

ConfigBasic

get_default_config()[source]

Get the default configuration. This method needs to be implemented by the specific device class, as different devices have different default configurations.

Returns:

The default config object(The specific subclass of CommonConfig).

Return type:

ConfigBasic

glitch_clock_arm()[source]
glitch_clock_config(wave, wait, delay, repeat)[source]
Return type:

tuple[int, None | bytes]

glitch_clock_force()[source]
glitch_clock_normal(wave)[source]
Return type:

tuple[int, None | bytes]

glitch_clock_normal_disable()[source]
glitch_clock_normal_enable()[source]
glitch_clock_reset()[source]
glitch_gnd_arm()[source]
glitch_gnd_config(wait, level, length, delay, repeat)[source]
glitch_gnd_force()[source]
glitch_gnd_normal(voltage)[source]
Return type:

tuple[int, None]

glitch_gnd_reset()[source]
glitch_vcc_arm()[source]

Set the glitch VCC to the armed state.

glitch_vcc_config(wait, level, length, delay, repeat)[source]

Configure the VCC glitch parameters:

v_normal────┬───────────────────┐       ┌────────────┐       ┌───────
            |       wait        | count |    delay   | count |
            |                   |       |            |       |
            |                   └───────┘            └───────┘ <--------- level voltage
            |                       └────────────────────┘
             Trigger                         repeat
Parameters:
  • wait (int) – Number of clock cycles to wait before the glitch is generated.

  • level (int | float | str) – Glitch DAC voltage value.

  • length (int) – Glitch duration in units of 10 ns.

  • delay (int) – Delay between glitch pulses.

  • repeat (int) – Number of glitch repetitions.

Returns:

Device response status and received data: (status, response).

Return type:

tuple[int, bytes | None]

glitch_vcc_force()[source]

Force-trigger the VCC glitch.

glitch_vcc_normal(voltage)[source]

Set the normal VCC voltage for the glitch module.

Parameters:

voltage (float | str | int) – Voltage value in Volts, or a string with unit suffix (e.g. "3.3V").

Returns:

Device response status and received data: (status, response).

Return type:

tuple[int, None]

glitch_vcc_reset()[source]

Reset the glitch VCC configuration.

nut_clock_freq(clock)[source]

Set nut clock.

Parameters:

clock (int | str) – Clock frequency in kHz or string with unit ‘M’, e.g., ‘8M’ for 8000 kHz

Returns:

The device response status

Return type:

tuple[int, None]

nut_voltage(voltage)[source]

Set nut voltage.

Parameters:

voltage (float | str | int) – Nut voltage can be a number or a string. If the input is a float, the voltage will be treated as a V value. If the input is a string, you can specify the unit, ending with the value, using either mV or V.

Returns:

The device response status

Return type:

tuple[int, None]

write_config_to_cracker(config)[source]

Sync config to cracker.

To prevent configuration inconsistencies between the host and the device, so all configuration information needs to be written to the device. User should call this function before get data from device.

NOTE: This function is currently ignored and will be resumed after all Cracker functions are completed.

cracknuts.cracker.cracker_g1.get_clock_from_wave_length(wave_len)[source]
Return type:

float

CrackerO1

class cracknuts.cracker.cracker_o1.ConfigO1[source]

Bases: ConfigG1

__init__()[source]
class cracknuts.cracker.cracker_o1.CrackerO1(address=None, bin_server_path=None, bin_bitstream_path=None)[source]

Bases: CrackerG1

__init__(address=None, bin_server_path=None, bin_bitstream_path=None)[source]

Initialize the CrackNuts O1 device interface.

Parameters:
  • address (tuple | str | None) – Device address as (ip, port), URI string, or None.

  • bin_server_path (str | None) – Path to the server firmware file for updates; normally not specified.

  • bin_bitstream_path (str | None) – Path to the bitstream firmware file for updates; normally not specified.

digital_pin_mode(pin_id, mode)[source]

Set the operating mode of a digital IO pin.

Parameters:
  • pin_id (str) – Pin identifier. Supported pins: GP0-GP7, GP21-GP27, A, A2-A5, IO2-IO9.

  • mode (int | str) – Pin operating mode: 1 for input, 0 for output, or "INPUT" / "OUTPUT".

Returns:

Device response status and received data: (status, response).

Return type:

tuple[int, bytes | None]

digital_read(pin_id)[source]

Read the level state of a digital IO pin. A high level requires more than 1.4 V.

Parameters:

pin_id (str) – Pin identifier. Supported pins: GP0-GP7, GP21-GP27, A, A2-A5, IO2-IO9.

Returns:

Device response status and pin level: (status, level).

Return type:

tuple[int, bytes | None | int]

digital_write(pin_id, value)[source]

Set the level state of a digital IO pin.

Parameters:
  • pin_id (str) – Pin identifier. Supported pins: GP0-GP7, GP21-GP27, A, A2-A5, IO2-IO9.

  • value (int) – Pin level state: 1 for high, 0 for low.

Returns:

Device response status and received data: (status, response).

Return type:

tuple[int, bytes | None]

get_switch_status_pl()[source]

Get the PL switch status.

Returns:

Status tuple (status, (sw1, sw2)), where status is the protocol status code and sw1 / sw2 are the two PL switch state bits (0 = open, 1 = closed).

Return type:

tuple[int, None | tuple[int, int]]

get_switch_status_ps()[source]

Get the PS switch status.

Returns:

Status tuple (status, (sw1, sw2)), where status is the protocol status code and sw1 / sw2 are the two PS switch state bits (0 = open, 1 = closed).

Return type:

tuple[int, None | tuple[int, int]]

get_voltage_a0()[source]

Get the voltage at measurement point A0.

Returns:

Device response status and measured voltage in Volts, or None on error.

Return type:

tuple[int, float] or None

get_voltage_a1()[source]

Get the voltage at measurement point A1.

Returns:

Device response status and measured voltage in Volts, or None on error.

Return type:

tuple[int, float] or None

set_led_content(t, x, y, c, w=None)[source]

Set the LED display content.

Parameters:
  • t (int) – Content type: 0 for text, 1 for image.

  • x (int) – X coordinate of the content in pixels.

  • y (int) – Y coordinate of the content in pixels.

  • c (bytes) – Content data: UTF-8 encoded string for text, or RGB888 byte array for images.

  • w (int | None) – Width of the content in pixels. For text, this is the pixel width of the content; for images, this is the image width.

Return type:

None

set_led_image(image_path, x=0, y=0, fit=True)[source]

Set the LED display image.

Parameters:
  • image_path (str) – Path to the image file; common formats such as PNG and JPEG are supported.

  • x (int) – X coordinate of the image in pixels.

  • y (int) – Y coordinate of the image in pixels.

  • fit (bool) – Whether to force-resize the image to 64x64 pixels. True: always resize to 64x64 regardless of original size. False: preserve the original image dimensions.

Return type:

None

set_led_text(text, x=0, y=0, auto_wrap=True)[source]

Set the LED display text. Only ASCII characters are supported. Each character is 5 pixels wide and 6 pixels tall with 1 pixel spacing. The screen resolution is 64x64 pixels with the origin at the top-left corner; x increases rightward and y increases downward.

Parameters:
  • text (str) – Text content to display.

  • x (int) – X coordinate of the text in pixels.

  • y (int) – Y coordinate of the text baseline in pixels. Note that the coordinate represents the baseline (bottom) of the text, so set y to 6 to display a complete first line.

  • auto_wrap (bool) – Whether to automatically wrap text when it exceeds the screen width.

Return type:

None

set_pwm(freq, duty_cycle)[source]

Set the PWM output on pin GP29.

Parameters:
  • freq (float | int) – PWM frequency in Hz.

  • duty_cycle (float) – PWM duty cycle as a fraction between 0 and 1.

Returns:

Device response status and received data: (status, response).

Return type:

tuple[int, None | bytes]

set_waveform_arbitrary(wave, wave_clk_div=1)[source]

Set the waveform generator output waveform.

Parameters:
  • wave (list[float]) – A sequence of voltage sample points for a single waveform period (unit: Volts). Each element represents the output voltage of one discrete sample point. The time interval per sample is 100 ns (corresponding to a 10 MHz sample rate). Samples are output in array order; one array represents one complete waveform period.

  • wave_clk_div (int) – Waveform clock divider (integer, default 1). Actual output frequency = DAC sample rate / (len(wave) * wave_clk_div).

Returns:

Execution status code and device response data.

Return type:

tuple[int, None | bytes]

set_waveform_dc(voltage)[source]

Set DC voltage output.

Parameters:

voltage (float) – Output DC voltage (Volts). Must be within the device’s allowed output range and must not be negative.

Returns:

Device response status and response data.

Return type:

tuple[int, None | bytes]

set_waveform_from_file(file_path)[source]

Load waveform data from a file and set the output waveform.

The file should contain a sequence of voltage sample points (unit: Volts), supporting comma-separated or newline-separated numeric formats. The maximum number of sample points is 2048.

Parameters:

file_path (str) – Path to a text file containing waveform data. Each numeric value in the file represents a voltage sample point (unit: V).

Returns:

Device response status and response data.

Return type:

tuple[int, None | bytes]

set_waveform_sawtooth(frequency, *, vpp=1.0, slope=1.0, phase=0.0, offset=None)[source]

Set sawtooth wave output.

Parameters:
  • frequency (float) – Output frequency (Hz).

  • vpp (float) – Peak-to-peak voltage (Volts). Default is 1.0.

  • slope (float) – Fraction of the period occupied by the rising edge (0–1). 1.0 = standard sawtooth (slow rise, fast fall); 0.5 = symmetric triangle; near 0 = fast rise, slow fall. Default is 1.0.

  • phase (float) – Initial phase in radians. Default is 0.0.

  • offset (float or None) – DC offset voltage (Volts).

Returns:

Device response status and response data.

Return type:

tuple[int, None | bytes]

set_waveform_sine(frequency, *, vpp=1.0, phase=0.0, offset=None)[source]

Set sine wave output.

Parameters:
  • frequency (float or str) – Output frequency (Hz). Accepts a numeric value or a string with unit suffix, e.g. 1e6, "1m", "1MHz", "10kHz".

  • vpp (float) – Peak-to-peak voltage (Volts). Default is 1.0.

  • phase (float) – Initial phase in radians. Default is 0.0.

  • offset (float or None) – DC offset voltage (Volts). If None, automatically set to vpp / 2 to avoid negative voltage.

Returns:

Device response status and response data.

Return type:

tuple[int, None | bytes]

set_waveform_square(frequency, *, duty=0.5, vpp=1.0, phase=0.0, offset=None)[source]

Set square wave output.

Parameters:
  • frequency (float) – Output frequency (Hz).

  • duty (float) – Duty cycle (0–1). 0.5 means a standard 50% square wave; 0.2 means high level occupies 20% of the period. Default is 0.5.

  • vpp (float) – Peak-to-peak voltage (Volts). Default is 1.0.

  • phase (float) – Initial phase in radians. Default is 0.0.

  • offset (float or None) – DC offset voltage (Volts).

Returns:

Device response status and response data.

Return type:

tuple[int, None | bytes]

set_waveform_standard(waveform, vpp, *, frequency=None, offset=None, duty=0.5, phase=0.0)[source]

Set standard waveform output.

This function generates a single-period waveform dataset in software according to the specified parameters, writes it into the device arbitrary waveform buffer, and the DAC loops over it.

Supported waveform types: "dc" (DC voltage), "sine" (sine wave), "square" (square wave), "triangle" (triangle wave), "sawtooth" (sawtooth wave).

Parameters:
  • waveform (str) – Waveform type name (case-insensitive).

  • vpp (float) – Peak-to-peak voltage (Volts). For non-DC waveforms, amplitude = vpp / 2.

  • frequency (float, str, or None) – Output frequency (Hz). May be omitted for "dc"; required for all others. Accepts a numeric value or a string with unit suffix (e.g. 1e6, "1MHz", "100kHz").

  • offset (float or None) – DC offset voltage (Volts). If None, defaults to vpp / 2 to keep the waveform non-negative.

  • duty (float) – Duty cycle or slope parameter between 0 and 1. For square, this is the fraction of the period at high level. For sawtooth, this is the fraction of the period occupied by the rising edge (near 1.0 means slow rise and fast fall; 0.5 gives a symmetric triangle; near 0.0 means fast rise and slow fall). Has no effect on sine or triangle.

  • phase (float) – Initial phase in radians (2π rad = one full period).

Returns:

Execution status code and device response data.

Return type:

tuple[int, None | bytes]

set_waveform_triangle(frequency, *, vpp=1.0, phase=0.0, offset=None)[source]

Set triangle wave output.

Parameters:
  • frequency (float) – Output frequency (Hz).

  • vpp (float) – Peak-to-peak voltage (Volts). Default is 1.0.

  • phase (float) – Initial phase in radians. Default is 0.0.

  • offset (float or None) – DC offset voltage (Volts).

Returns:

Device response status and response data.

Return type:

tuple[int, None | bytes]