/// Sends a command to the target, optionally send data and optionally read data back. Returns a
/// tuple with the data length written and read.
Sends a command to the target, optionally send data and optionally read data back. Returns a
tuple with the data length written and read.
Sends a command to the target optionally send data and optionally read data back . Returns a tuple with the data length written and read .
fn send_command(
        &mut self,
        cmd: Command,
        write_data: &[u8],
        read_data: &mut [u8],
    ) -> Result<(usize, usize)> {
        self.usb_device_handle.claim_interface(0)?;
        self.usb_device_handle.write_control(
            rusb::request_type(
                rusb::Direction::Out,
                rusb::RequestType::Vendor,
                rusb::Recipient::Device,
            ),
            cmd as u8,
            0,
            0,
            &[0u8; 0],
            TIMEOUT,
        )?;
        let mut written = 0;
        let mut read = 0;
        // If there is data to send, send it via bulk endpoint 2
        if !write_data.is_empty() {
            written = self
                .usb_device_handle
                .write_bulk(0x02, &write_data, TIMEOUT)?;
        }
        // If some bytes should be read back, read them from bulk endpoint 1
        if !read_data.is_empty() {
            read = self.usb_device_handle.read_bulk(0x81, read_data, TIMEOUT)?;
        }
        self.usb_device_handle.release_interface(0)?;
        Ok((written, read))
    }
fn send_command ( & mut self , cmd : Command , write_data : & [ u8 ] , read_data : & mut [ u8 ] , ) -> Result < ( usize , usize ) > { self . usb_device_handle . claim_interface ( 0 ) ? ; self . usb_device_handle . write_control ( rusb :: request_type ( rusb :: Direction :: Out , rusb :: RequestType :: Vendor , rusb :: Recipient :: Device , ) , cmd as u8 , 0 , 0 , & [ 0u8 ; 0 ] , TIMEOUT , ) ? ; let mut written = 0 ; let mut read = 0 ; // If there is data to send, send it via bulk endpoint 2 if ! write_data . is_empty ( ) { written = self . usb_device_handle . write_bulk ( 0x02 , & write_data , TIMEOUT ) ? ; } // If some bytes should be read back, read them from bulk endpoint 1 if ! read_data . is_empty ( ) { read = self . usb_device_handle . read_bulk ( 0x81 , read_data , TIMEOUT ) ? ; } self . usb_device_handle . release_interface ( 0 ) ? ; Ok ( ( written , read ) ) }
Sends a command to the target, optionally send data and optionally read data back.
Sends a command to the target optionally send data and optionally read data back .
&mut self
cmd
Command
write_data
&[u8]
read_data
&mut [u8]