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:
objectAsync 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
DIOliteral type.- Returns:
Mapping of channel name to its current boolean state.
- Return type:
- Raises:
KeyError – If any channel name is not a valid DIO channel.
Notes
Channels are read in a single BCSz
get_dicall. The responsedatafield 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:
- Return type:
None
- Raises:
KeyError – If
channelis not a valid DIO channel name.ValueError – If
valueis not a bool or int (e.g. a float is passed).ShutterError – If the BCSz
set_docall 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”).