Analog input accessor

AIAccessor provides typed analog input (AI) read and acquire operations for the beamline.

class resonance.api.core.ai.AIAccessor(conn: BCSz.BCSServer)[source]

Bases: object

Accessor for analog input channels via the BCS server.

Parameters:

conn (BCSz.BCSServer) – Active connection to the BCS hardware server.

Notes

Wraps acquire_data and get_acquired_array for typed, validated access to AI channels defined in resonance.api.types.AI.

Examples

>>> data = await bl.ai.read("Photodiode", "TEY signal", "AI 3 Izero")
>>> print(data)
{'Photodiode': [0.0], 'TEY signal': [0.0], 'AI 3 Izero': [0.0]}
async read(*channels: str) dict[str, list[float]][source]

Return the last-acquired raw array for each channel.

Parameters:

*channels (str) – One or more AI channel names from resonance.api.types.AI.

Returns:

Mapping of channel name to raw sample array.

Return type:

dict[str, list[float]]

Raises:
  • KeyError – If any channel name is not a valid AI channel.

  • AcquisitionError – If the BCS response contains an empty data array for a channel.

Notes

Does not trigger a new acquisition. Returns the most recent data buffered by BCS. Call trigger_and_read to acquire fresh data. Use read only when data was already acquired (e.g. after acquire_data was called externally).

async trigger_and_read(channels: list[str], acquisition_time: float = 1.0) dict[str, Variable][source]

Trigger acquisition and return mean and standard error per channel.

Parameters:
  • channels (list[str]) – AI channel names from resonance.api.types.AI.

  • acquisition_time (float, optional) – Duration of acquisition in seconds. Must be positive. Default is 1.0.

Returns:

Mapping of channel name to ufloat(mean, std_err).

Return type:

dict[str, Variable]

Raises:
  • KeyError – If any channel name is not a valid AI channel.

  • ValueError – If acquisition_time is not strictly positive.

  • AcquisitionError – If the BCS response contains an empty data array for a channel.

Notes

Performs a blocking acquisition of acquisition_time seconds. Use per scan point to get mean and standard error for each channel. Standard error is computed as std_dev / sqrt(N). For N=1, std_err is 0.

Examples

>>> data = await bl.ai.trigger_and_read(["Photodiode", "TEY signal"], acquisition_time=1.0)
>>> print(data["Photodiode"])  # ufloat(mean, std_err)