IO

class pyniryo_nate.components.IO(http_client: HttpClient, mqtt_client: MqttClient, correlation_id: str)[source]

Bases: BaseAPIComponent

Methods

close

Close the component and release any resources if needed.

get_all

Get the current states of all digital and analog inputs and outputs.

on_analog_input

Set a callback to be called when the state of the specified analog input changes.

on_analog_io

Set a callback to be called when the state of the specified analog IO changes, whether it is an input or an output.

on_analog_output

Set a callback to be called when the state of the specified analog output changes.

on_digital_input

Set a callback to be called when the state of the specified digital input changes.

on_digital_io

Set a callback to be called when the state of the specified digital IO changes, whether it is an input or an output.

on_digital_output

Set a callback to be called when the state of the specified digital output changes.

set_analog_output

Set the voltage of an analog output.

set_digital_output

Set the state of a digital output.

update_states

Update the states of multiple digital and analog outputs at once.

wait_for_digital_io

Block until a digital input or output holds the given value.

Parameters:
  • http_client (HttpClient)

  • mqtt_client (MqttClient)

  • correlation_id (str)

get_all() → IOStates[source]

Get the current states of all digital and analog inputs and outputs.

The states are keyed by label, with a label this client does not know keyed by its raw string, see parse().

An analog input that measures nothing is reported with value set to None, see AnalogIO.

Returns:

The state of every input and output.

Return type:

IOStates

set_digital_output(io_id: IOLabel | str, value: bool) → None[source]

Set the state of a digital output.

Parameters:
  • io_id (IOLabel | str) – The label of the digital output to set (e.g., IOLabel.CDO1, ‘tdo2’).

  • value (bool) – The value to set (True for HIGH, False for LOW).

Raises:

ClientError – If the robot refuses the write.

Return type:

None

set_analog_output(io_id: IOLabel | str, value: float) → None[source]

Set the voltage of an analog output.

Parameters:
  • io_id (IOLabel | str) – The label of the analog output to set (e.g., IOLabel.CAO1, ‘cao2’). The tool connector carries no analog output, see Tool inputs and outputs.

  • value (float) – The voltage to apply, in volts. The robot owns the range of the channel and refuses a value outside it.

Raises:

ClientError – If the robot refuses the write.

Return type:

None

update_states(outputs: list[DigitalIO | AnalogIO]) → None[source]

Update the states of multiple digital and analog outputs at once.

Parameters:

outputs (list[DigitalIO | AnalogIO]) – A list of DigitalIO and AnalogIO objects representing the outputs to update.

Raises:
  • ValueError – If an analog output carries no value to write.

  • ClientError – If the robot refuses the write.

Return type:

None

on_analog_io(io_id: IOLabel | str, callback: Callable[[AnalogIO], None]) → Callable[[], None][source]

Set a callback to be called when the state of the specified analog IO changes, whether it is an input or an output. See on_analog_input() and on_analog_output() to follow one direction only.

Parameters:
  • io_id (IOLabel | str) – An IO label to monitor (e.g., IOLabel.CAI1).

  • callback (Callable[[AnalogIO], None]) – A function that takes an AnalogIO object as an argument and returns None. This function will be called whenever the state of the specified analog IOs changes. An input that measures nothing is passed with value set to None, see AnalogIO.

Return type:

Callable[[], None]

on_analog_input(io_id: IOLabel | str, callback: Callable[[AnalogIO], None]) → Callable[[], None][source]

Set a callback to be called when the state of the specified analog input changes. The state is retained, so the callback receives the current state as soon as the subscription is in place.

Parameters:
  • io_id (IOLabel | str) – An analog input label (e.g., IOLabel.CAI1, IOLabel.TAI1).

  • callback (Callable[[AnalogIO], None]) – A function that takes an AnalogIO object as an argument and returns None.

Return type:

Callable[[], None]

on_analog_output(io_id: IOLabel | str, callback: Callable[[AnalogIO], None]) → Callable[[], None][source]

Set a callback to be called when the state of the specified analog output changes. The state is retained, so the callback receives the current state as soon as the subscription is in place.

Parameters:
  • io_id (IOLabel | str) – An analog output label (e.g., IOLabel.CAO1). The tool carries no analog output.

  • callback (Callable[[AnalogIO], None]) – A function that takes an AnalogIO object as an argument and returns None.

Return type:

Callable[[], None]

on_digital_io(io_id: IOLabel | str, callback: Callable[[DigitalIO], None]) → Callable[[], None][source]

Set a callback to be called when the state of the specified digital IO changes, whether it is an input or an output. See on_digital_input() and on_digital_output() to follow one direction only.

Parameters:
  • io_id (IOLabel | str) – An IO label to monitor (e.g., IOLabel.CDI1).

  • callback (Callable[[DigitalIO], None]) – A function that takes a DigitalIO object as an argument and returns None. This function will be called whenever the state of the specified digital IOs changes.

Return type:

Callable[[], None]

on_digital_input(io_id: IOLabel | str, callback: Callable[[DigitalIO], None]) → Callable[[], None][source]

Set a callback to be called when the state of the specified digital input changes. The state is retained, so the callback receives the current state as soon as the subscription is in place.

Parameters:
  • io_id (IOLabel | str) – A digital input label (e.g., IOLabel.CDI1, IOLabel.TDI1).

  • callback (Callable[[DigitalIO], None]) – A function that takes a DigitalIO object as an argument and returns None.

Return type:

Callable[[], None]

on_digital_output(io_id: IOLabel | str, callback: Callable[[DigitalIO], None]) → Callable[[], None][source]

Set a callback to be called when the state of the specified digital output changes. The state is retained, so the callback receives the current state as soon as the subscription is in place.

Parameters:
  • io_id (IOLabel | str) – A digital output label (e.g., IOLabel.CDO1, IOLabel.TDO1).

  • callback (Callable[[DigitalIO], None]) – A function that takes a DigitalIO object as an argument and returns None.

Return type:

Callable[[], None]

wait_for_digital_io(io_id: IOLabel | str, value: bool, timeout: float = -1) → None[source]

Block until a digital input or output holds the given value.

The current state is read once the subscription is in place, so an IO that already holds value returns at once and a change happening meanwhile is not missed.

Parameters:
  • io_id (IOLabel | str) – The label of the IO to wait on (e.g., IOLabel.CDI1).

  • value (bool) – The value to wait for.

  • timeout (float) – Maximum time to wait, in seconds. Zero or a negative value waits indefinitely.

Raises:
  • DataValidationError – If the robot serves no digital IO under this label.

  • TimeoutError – If the timeout expires before the IO holds the value.

Return type:

None