pub fn sync_read_cb<'a, F>(
		&'a mut self,
		motor_ids: &'a [u8],
		address: u16,
		count: u16,
		mut on_response: F,
	) -> Result<(), WriteError>
	where
		F: FnMut(Result<SyncData<&[u8]>, ReadError>),
	{
		self.write_instruction(packet_id::BROADCAST, instruction_id::SYNC_READ, 4 + motor_ids.len(), |buffer| {
			write_u16_le(&mut buffer[0..], address);
			write_u16_le(&mut buffer[2..], count);
			buffer[4..].copy_from_slice(motor_ids);
		})?;
		for &motor_id in motor_ids {
			let response = self.read_status_response().and_then(|response| {
				crate::InvalidPacketId::check(response.packet_id(), motor_id)?;
				crate::InvalidParameterCount::check(response.parameters().len(), count.into())?;
				Ok(response)
			});

			match response {
				Ok(response) => on_response(Ok(SyncData {
					motor_id,
					data: response.parameters(),
				})),
				Err(e) => on_response(Err(e)),
			}
		}
		Ok(())
	}
/// Synchronously read an arbitrary number of bytes from multiple motors in one command.
///
/// The `on_response` function is called for the reply from each motor.
/// If the function fails to write the instruction, an error is returned and the function is not called.
Synchronously read an arbitrary number of bytes from multiple motors in one command.
The `on_response` function is called for the reply from each motor.
If the function fails to write the instruction, an error is returned and the function is not called.
Synchronously read an arbitrary number of bytes from multiple motors in one command . The ` on_response ` function is called for the reply from each motor . If the function fails to write the instruction an error is returned and the function is not called .
pub fn sync_read_cb<'a, F>(
		&'a mut self,
		motor_ids: &'a [u8],
		address: u16,
		count: u16,
		mut on_response: F,
	) -> Result<(), WriteError>
	where
		F: FnMut(Result<SyncData<&[u8]>, ReadError>),
	{
		self.write_instruction(packet_id::BROADCAST, instruction_id::SYNC_READ, 4 + motor_ids.len(), |buffer| {
			write_u16_le(&mut buffer[0..], address);
			write_u16_le(&mut buffer[2..], count);
			buffer[4..].copy_from_slice(motor_ids);
		})?;
		for &motor_id in motor_ids {
			let response = self.read_status_response().and_then(|response| {
				crate::InvalidPacketId::check(response.packet_id(), motor_id)?;
				crate::InvalidParameterCount::check(response.parameters().len(), count.into())?;
				Ok(response)
			});
			match response {
				Ok(response) => on_response(Ok(SyncData {
					motor_id,
					data: response.parameters(),
				})),
				Err(e) => on_response(Err(e)),
			}
		}
		Ok(())
	}
pub fn sync_read_cb < ' a , F > ( & ' a mut self , motor_ids : & ' a [ u8 ] , address : u16 , count : u16 , mut on_response : F , ) -> Result < ( ) , WriteError > where F : FnMut ( Result < SyncData < & [ u8 ] > , ReadError > ) , { self . write_instruction ( packet_id :: BROADCAST , instruction_id :: SYNC_READ , 4 + motor_ids . len ( ) , | buffer | { write_u16_le ( & mut buffer [ 0 .. ] , address ) ; write_u16_le ( & mut buffer [ 2 .. ] , count ) ; buffer [ 4 .. ] . copy_from_slice ( motor_ids ) ; } ) ? ; for & motor_id in motor_ids { let response = self . read_status_response ( ) . and_then ( | response | { crate :: InvalidPacketId :: check ( response . packet_id ( ) , motor_id ) ? ; crate :: InvalidParameterCount :: check ( response . parameters ( ) . len ( ) , count . into ( ) ) ? ; Ok ( response ) } ) ; match response { Ok ( response ) => on_response ( Ok ( SyncData { motor_id , data : response . parameters ( ) , } ) ) , Err ( e ) => on_response ( Err ( e ) ) , } } Ok ( ( ) ) }
Synchronously read an arbitrary number of bytes from multiple motors in one command.
Synchronously read an arbitrary number of bytes from multiple motors in one command .
&'a mut self
motor_ids
&'a [u8]
address
u16
count
u16
on_response
F
&'a mut self
motor_ids
&'a [u8]
address
u16
count
u16
on_response
F