dynamixel2/instructions/
action.rs

1use super::{instruction_id, packet_id};
2use crate::{Bus, Response, TransferError, WriteError};
3
4impl<ReadBuffer, WriteBuffer> Bus<ReadBuffer, WriteBuffer>
5where
6	ReadBuffer: AsRef<[u8]> + AsMut<[u8]>,
7	WriteBuffer: AsRef<[u8]> + AsMut<[u8]>,
8{
9	/// Send an action command to trigger a previously registered instruction.
10	///
11	/// You may specify [`crate::instructions::packet_id::BROADCAST`] as motor ID.
12	/// If you do, none of the devices will reply with a response, and this function will not wait for any.
13	///
14	/// If you want to broadcast this instruction, it may be more convenient to use [`Self::broadcast_action()`] instead.
15	pub fn action(&mut self, motor_id: u8) -> Result<Response<()>, TransferError> {
16		self.write_instruction(motor_id, instruction_id::ACTION, 0, |_| ())?;
17		Ok(super::read_response_if_not_broadcast(self, motor_id)?)
18	}
19
20	/// Broadcast an action command to all connected motors to trigger a previously registered instruction.
21	pub fn broadcast_action(&mut self) -> Result<(), WriteError> {
22		self.write_instruction(packet_id::BROADCAST, instruction_id::ACTION, 0, |_| ())
23	}
24}