Digital I/O accessor

DIOAccessor provides typed digital I/O read and set operations (e.g. shutter control).

class resonance.api.core.dio.DIOAccessor(conn: BCSz.BCSServer)[source]

Bases: object

Async interface for reading and writing BCS digital I/O channels.

Parameters:

conn (BCSz.BCSServer) – Active BCSz server connection.

Notes

Wraps BCSz digital I/O channels. read reads digital inputs; set writes digital outputs. The shutter channel (“Light Output”, “Shutter Output”, etc.) is the most common use case. Values are always coerced to bool.

Examples

>>> state = await bl.dio.read("Shutter Output", "Light Output")
>>> print(state)
{'Shutter Output': True, 'Light Output': True}
>>> await bl.dio.set("Shutter Output", False)
>>> await bl.dio.set("Light Output", True)
>>> state = await bl.dio.read("Shutter Output", "Light Output")
>>> print(state)
{'Shutter Output': False, 'Light Output': True}
async read(*channels: str) dict[str, bool][source]

Read current state of one or more digital I/O channels.

Parameters:

*channels (str) – One or more DIO channel names to read. Must be members of the DIO literal type.

Returns:

Mapping of channel name to its current boolean state.

Return type:

dict[str, bool]

Raises:

KeyError – If any channel name is not a valid DIO channel.

Notes

Channels are read in a single BCSz get_di call. The response data field is coerced to bool for each channel.

async set(channel: str, value: bool | int) None[source]

Set a digital output channel to True (on) or False (off).

Parameters:
  • channel (str) – DIO channel name to write. Must be a member of the DIO literal type.

  • value (bool or int) – Output value to set. Non-zero integers map to True, zero maps to False.

Return type:

None

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

  • ValueError – If value is not a bool or int (e.g. a float is passed).

  • ShutterError – If the BCSz set_do call raises an exception.

Notes

Value is coerced to bool: any non-zero int is True, 0 is False. Typical use is controlling the beamline shutter (e.g. channel=”Light Output”).