IO¶
- class pyniryo_nate.components.IO(http_client: HttpClient, mqtt_client: MqttClient, correlation_id: str)[source]¶
Bases:
BaseAPIComponentMethods
closeClose the component and release any resources if needed.
Get the current states of all digital and analog inputs and outputs.
Set a callback to be called when the state of the specified analog input changes.
Set a callback to be called when the state of the specified analog IO changes, whether it is an input or an output.
Set a callback to be called when the state of the specified analog output changes.
Set a callback to be called when the state of the specified digital input changes.
Set a callback to be called when the state of the specified digital IO changes, whether it is an input or an output.
Set a callback to be called when the state of the specified digital output changes.
Set the voltage of an analog output.
Set the state of a digital output.
Update the states of multiple digital and analog outputs at once.
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
valueset to None, seeAnalogIO.- Returns:
The state of every input and output.
- Return type:
- 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()andon_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
valueset to None, seeAnalogIO.
- 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.
- 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.
- 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()andon_digital_output()to follow one direction only.- Parameters:
- 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.
- 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.
- 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
valuereturns 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