openlifu.io.LIFUTXDevice.TxDevice¶
- class openlifu.io.LIFUTXDevice.TxDevice(uart: LIFUUart, module_invert: bool | list[bool] = False)[source]¶
Bases:
object- __init__(uart: LIFUUart, module_invert: bool | list[bool] = False)[source]¶
Initialize the TxDevice.
- Parameters:
uart (LIFUUart) – The LIFUUart instance for communication.
- apply_all_registers()[source]¶
Apply all registers to the TX device.
- Raises:
ValueError – If the device is not connected.
- async_mode(enable: bool | None = None) bool[source]¶
Enable or disable asynchronous mode for the TX device.
- Parameters:
enable (bool | None) – If True, enable async mode; if False, disable it; if None read the current state.
- Returns:
True if async mode is enabled, False otherwise.
- Return type:
bool
- Raises:
ValueError – If the UART is not connected.
Exception – If an error occurs while setting async mode.
- demo_tx7332(identifier: int) bool[source]¶
Sets all TX7332 chip registers with a test waveform.
- Returns:
True if all chips are programmed successfully, False otherwise.
- Return type:
bool
- Raises:
ValueError – If the UART is not connected.
- echo(module: int = 0, echo_data=None) tuple[bytes, int][source]¶
Send an echo command to the device with data and receive the same data in response.
- Parameters:
echo_data (bytes) – The data to send (must be a byte array).
- Returns:
The echoed data and its length.
- Return type:
tuple[bytes, int]
- Raises:
ValueError – If the UART is not connected.
TypeError – If the echo_data is not a byte array.
Exception – If an error occurs during the echo process.
- enter_dfu(module: int = 0) bool[source]¶
Perform a soft reset to enter DFU mode on TX device.
- Returns:
True if the reset was successful, False otherwise.
- Return type:
bool
- Raises:
ValueError – If the UART is not connected.
Exception – If an error occurs while resetting the device.
- enum_tx7332_devices(num_devices: int | None = None) int[source]¶
Enumerate TX7332 devices connected to the TX device.
- Parameters:
num_transmitters (int) – The number of transmitters expected to be enumerated. If None, the number of transmitters will be determined from the response. If provided and the number enumerated does not match the expected number, an error will be raised. If the UART is in demo mode, this argument is used to set the number of transmitters for the demo (or set to a default if omitted/None)
- Returns:
number of devices detected.
- Return type:
n_transmitters
- Raises:
ValueError – If the UART is not connected.
Exception – If an error occurs during enumeration.
- get_ambient_temperature(module: int = 0) float[source]¶
Retrieve the ambient temperature reading from the TX device.
- Returns:
Temperature value in Celsius.
- Return type:
float
- Raises:
ValueError – If the UART is not connected.
Exception – If an error occurs or the received data length is invalid.
- get_hardware_id(module: int = 0) str[source]¶
Retrieve the hardware ID of the TX device.
- Returns:
Hardware ID in hexadecimal format.
- Return type:
str
- Raises:
ValueError – If the UART is not connected.
Exception – If an error occurs while retrieving the hardware ID.
- get_module_count() int[source]¶
Return the number of connected LIFU transmitter modules (including master).
Sends
OW_CMD_GET_MODULE_COUNT(0x10) to the firmware. Falls back to deriving the count from the TX7332 chip count when the firmware does not yet support the command.
- get_temperature(module: int = 1) float[source]¶
Retrieve the temperature reading from the TX device.
- Returns:
Temperature value in Celsius.
- Return type:
float
- Raises:
ValueError – If the UART is not connected.
Exception – If an error occurs or the received data length is invalid.
- get_trigger()[source]¶
Retrieve the current trigger configuration from the TX device.
- Returns:
The trigger configuration as a dictionary.
- Return type:
dict
- Raises:
ValueError – If the UART is not connected.
Exception – If an error occurs while fetching the trigger configuration.
- get_trigger_json() dict[source]¶
Start the trigger on the TX device.
- Returns:
True if the trigger was started successfully, False otherwise.
- Return type:
bool
- Raises:
ValueError – If the UART is not connected.
Exception – If an error occurs while starting the trigger.
- get_tx_module_count() int[source]¶
Retrieve the number of detected Transmit modules.
Args: :returns: number of transmitter modules connected. :rtype: tx_module_count
- Raises:
ValueError – If the UART is not connected.
Exception – If an error occurs during enumeration.
- get_version(module: int = 0) str[source]¶
Retrieve the firmware version of the TX device.
- Returns:
Firmware version in the format ‘vX.Y.Z’.
- Return type:
str
- Raises:
ValueError – If the UART is not connected.
Exception – If an error occurs while fetching the version.
- is_connected() bool[source]¶
Check if the TX device is connected.
- Returns:
True if the device is connected, False otherwise.
- Return type:
bool
- ping(module: int = 0) bool[source]¶
Send a ping command to the TX device to verify connectivity.
- Raises:
ValueError – If the UART is not connected.
Exception – If an error occurs during the ping process.
- property print: None¶
Print TX device information.
- Raises:
None –
- read_block(identifier: int, start_address: int, count: int) List[int] | None[source]¶
Read a block of consecutive register values from the TX device.
- Parameters:
identifier (int) – TX chip index.
start_address (int) – The starting register address to read from.
count (int) – Number of registers to read.
- Returns:
List of register values, or None on error.
- Return type:
List[int]
- Raises:
ValueError – If the device is not connected or parameters are invalid.
Exception – If an unexpected error occurs.
- read_config(module: int = 0) LifuUserConfig | None[source]¶
Read the user configuration from device flash.
The configuration is stored as JSON with metadata (magic, version, sequence, CRC).
- Returns:
Parsed configuration object, or None on error
- Return type:
- Raises:
ValueError – If the UART is not connected
Exception – If an error occurs during communication
- read_register(identifier: int, address: int) int[source]¶
Read a register value from the TX device.
- Parameters:
address (int) – The register address to read.
- Returns:
The value of the register if successful, or 0 on failure.
- Return type:
int
- Raises:
ValueError – If the identifier is not set or is out of range.
Exception – If an unexpected error occurs during the operation.
- set_module_invert(module_invert: bool | List[bool]) None[source]¶
Set the module invert configuration for the TX device.
- Parameters:
module_invert (bool | List[bool]) – The module invert configuration to set.
- set_solution(pulse: Dict, delays: ndarray, apodizations: ndarray, sequence: Dict, trigger_mode: Literal['sequence', 'continuous', 'single'] = 'sequence', profile_index: int = 1, profile_increment: bool = True)[source]¶
Set the solution parameters on the TX device.
- Parameters:
pulse (Dict) – The pulse parameters to set.
delays (list) – The delays to set.
apodizations (list) – The apodizations to set.
sequence (Dict) – The sequence parameters to set.
mode – The trigger mode to use.
profile_index (int) – The pulse profile to use.
profile_increment (bool) – Whether to increment the pulse profile.
- set_trigger(pulse_interval: float, pulse_count: int = 1, pulse_width: int = 20, pulse_train_interval: float = 0.0, pulse_train_count: int = 1, trigger_mode: Literal['sequence', 'continuous', 'single'] = 'sequence', profile_index: int = 0, profile_increment: bool = True) dict[source]¶
Set the trigger configuration on the TX device.
- Parameters:
pulse_interval (float) – The time interval between pulses in seconds.
pulse_count (int) – The number of pulses to generate.
pulse_width (int) – The pulse width in microseconds.
pulse_train_interval (float) – The time interval between pulse trains in seconds.
pulse_train_count (int) – The number of pulse trains to generate.
mode (TriggerModeOpts) – The trigger mode to use.
profile_index (int) – The pulse profile to use.
profile_increment (bool) – Whether to increment the pulse profile.
- set_trigger_json(data=None) dict[source]¶
Set the trigger configuration on the TX device.
- Parameters:
data (dict) – A dictionary containing the trigger configuration.
- Returns:
JSON response from the device.
- Return type:
dict
- Raises:
ValueError – If data is None or the UART is not connected.
Exception – If an error occurs while setting the trigger.
- soft_reset(module: int = 0) bool[source]¶
Perform a soft reset on the TX device.
- Returns:
True if the reset was successful, False otherwise.
- Return type:
bool
- Raises:
ValueError – If the UART is not connected.
Exception – If an error occurs while resetting the device.
- start_trigger() bool[source]¶
Start the trigger on the TX device.
- Returns:
True if the trigger was started successfully, False otherwise.
- Return type:
bool
- Raises:
ValueError – If the UART is not connected.
Exception – If an error occurs while starting the trigger.
- stop_trigger() bool[source]¶
Stop the trigger on the TX device.
This method sends a command to stop the software trigger on the TX device. It checks the device’s connection status and handles errors appropriately.
- Returns:
True if the trigger was successfully stopped, False otherwise.
- Return type:
bool
- Raises:
ValueError – If the UART is not connected.
Exception – If an error occurs during the operation.
- toggle_led(module: int = 0) bool[source]¶
Toggle the LED on the TX device.
- Raises:
ValueError – If the UART is not connected.
Exception – If an error occurs while toggling the LED.
- update_firmware(module: int, package_file: str, vid: int = 1155, pid: int = 57105, libusb_dll: str | None = None, i2c_addr: int = 114, dfu_wait_s: float = 5.0, progress_callback=None) bool[source]¶
Update firmware on a single module.
Module 0 (USB master): host → USB DFU. Module 1+ (I2C slaves): host → UART OW → master → I2C 0x72 (DFU bootloader).
- Parameters:
module – Module index (0 = USB master).
package_file – Path to the signed firmware package file.
vid – USB VID for module 0 DFU (default 0x0483).
pid – USB PID for module 0 DFU (default 0xDF11).
libusb_dll – Optional path to libusb-1.0.dll (Windows).
i2c_addr – I2C address of the slave DFU bootloader (default 0x72).
dfu_wait_s – Seconds to wait after DFU-enter for bootloader to boot.
progress_callback – Optional
(written, total, label)callable.
- Returns:
True on success.
- Return type:
bool
- Raises:
ValueError – If the UART is not connected.
RuntimeError – If DFU entry cannot be verified or programming fails.
- write_block(identifier: int, start_address: int, reg_values: List[int]) bool[source]¶
Write a block of register values to the TX device.
- Parameters:
start_address (int) – The starting register address to write to.
reg_values (List[int]) – List of register values to write.
- Returns:
True if the block write operation was successful, False otherwise.
- Return type:
bool
- Raises:
ValueError – If the device is not connected, the identifier is invalid, or parameters are out of range.
- write_block_verify(start_address: int, reg_values: List[int]) bool[source]¶
Write a block of register values to the TX device with verification.
- Parameters:
start_address (int) – The starting register address to write to.
reg_values (List[int]) – List of register values to write.
- Returns:
True if the block write operation was successful, False otherwise.
- Return type:
bool
- Raises:
ValueError – If the device is not connected, the identifier is invalid, or parameters are out of range.
- write_config(config: LifuUserConfig, module: int = 0) LifuUserConfig | None[source]¶
Write user configuration to device flash.
Can pass either: - Full wire format (header + JSON) - Raw JSON bytes (device will parse as JSON)
- Parameters:
config – LifuUserConfig object to write
- Returns:
Updated configuration from device (with new seq/crc), or None on error
- Return type:
- Raises:
ValueError – If the UART is not connected
Exception – If an error occurs during communication
- write_config_json(json_str: str, module: int = 0) LifuUserConfig | None[source]¶
Write user configuration from a JSON string.
This is a convenience method that creates a LifuUserConfig from JSON and writes it to the device.
- Parameters:
json_str – JSON string to write
- Returns:
Updated configuration from device, or None on error
- Return type:
- Raises:
ValueError – If JSON is invalid or UART is not connected
Exception – If an error occurs during communication
- write_register(identifier: int, address: int, value: int) bool[source]¶
Write a value to a register in the TX device.
- Parameters:
address (int) – The register address to write to.
value (int) – The value to write to the register.
- Returns:
True if the write operation was successful, False otherwise.
- Return type:
bool
- Raises:
ValueError – If the device is not connected, or the identifier is invalid.
Exception – If an unexpected error occurs during the operation.
- write_register_verify(address: int, value: int) bool[source]¶
Write a value to a register in the TX device with verification.
- Parameters:
address (int) – The register address to write to.
value (int) – The value to write to the register.
- Returns:
True if the write operation was successful, False otherwise.
- Return type:
bool
- Raises:
ValueError – If the device is not connected, or the identifier is invalid.
Exception – If an unexpected error occurs during the operation.
- write_ti_config_to_tx_device(file_path: str, txchip_id: int) bool[source]¶
Parse a TI configuration file and write the register values to the TX device.
- Parameters:
file_path (str) – Path to the TI configuration file.
txchip_id (int) – The ID of the TX chip to write the registers to.
- Returns:
True if all registers were written successfully, False otherwise.
- Return type:
bool