UsbDeviceConnection controlTransfer - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for UsbDeviceConnection controlTransfer method.

This code example shows how to use the following methods:controlTransfer
    } 
 
    @Override 
    public boolean InitialiseConnection(UsbDeviceConnection connection) {
 
    	connection.controlTransfer(0x40, 0, 0, 0, null, 0, 0);// reset
    	connection.controlTransfer(0x40, 0, 1, 0, null, 0, 0);// clear Rx
    	connection.controlTransfer(0x40, 0, 2, 0, null, 0, 0);// clear Tx
    	connection.controlTransfer(0x40, 0x02, 0x0000, 0, null, 0, 0); // flow control none
    	 
        /* 
         * Calculate a Divisor at 48MHz 9600 : 0x4138 11400 : 0xc107 19200 : 0x809c 
         * 38400 : 0xc04e 57600 : 0x0034 115200 : 0x001a 230400 : 0x000d 
         */ 
    	connection.controlTransfer(0x40, 0x03, 0x0034, 0, null, 0, 0);
    	 
        connection.controlTransfer(0x40, 0x04, 0x0008, 0, null, 0, 0); // n/8/1
    	 
    	return true; 
    } 

6
CodeRank
This code example shows how to use the following methods:controlTransfer
 
    @Override 
    public boolean InitialiseConnection(UsbDeviceConnection connection) {
 
        //Control codes for Silicon Labs CP201x USB to UART @ 250000 baud 
        connection.controlTransfer(0x40, 0x00, 0xff, 0xff, null, 0, 0);
        connection.controlTransfer(0x40, 0x01, 0x00, 0x02, null, 0, 0);
        connection.controlTransfer(0x40, 0x01, 0x0f, 0x00, null, 0, 0);
 
        return true; 
    } 
 
} 
5
CodeRank
This code example shows how to use the following methods:controlTransfer
        // horrific magic numbers gleaned from calculations based on the Linux kernel driver source. 
        // look for ch341.c, All the repetition of sending etc... is also based on the behaviour of ch341.c 
 
        //configure CH341: 
        byte buffer[] = new byte[8];
        connection.controlTransfer(USB_CONTROL_IN,  0x5f, 0x0000, 0x0000, buffer, 8, 0); //0x27 0x00
        connection.controlTransfer(USB_CONTROL_OUT, 0xa1, 0x0000, 0x0000, null, 0, 0);
 
        // set the baud rate to 57600 calculations used ch341_set_baudrate 
        connection.controlTransfer(USB_CONTROL_OUT, 0x9a, 0x1312, 0x9803, null, 0, 0);
        connection.controlTransfer(USB_CONTROL_OUT, 0x9a, 0x0f2c, 0x0010, null, 0, 0);
 
        connection.controlTransfer(USB_CONTROL_IN,  0x95, 0x2518, 0x0000, buffer, 8, 0); //0x56 0x00
        connection.controlTransfer(USB_CONTROL_OUT, 0x95, 0x2518, 0x0050, null, 0, 0);
 
        //Get Status: 
        connection.controlTransfer(USB_CONTROL_IN,  0x95, 0x0706, 0x0000, buffer, 8, 0); //0xff 0xee
 
        connection.controlTransfer(USB_CONTROL_OUT, 0xa1, 0x501f, 0xd90a, null, 0, 0);
 

6
CodeRank
This code example shows how to use the following methods:close, controlTransfer
    private static final int LENGTH = 64;
    private void getDeviceStatus(UsbDevice device) {
        UsbDeviceConnection connection = mUsbManager.openDevice(device);
        //Create a sufficiently large buffer for incoming data 
        byte[] buffer = new byte[LENGTH];
        connection.controlTransfer(REQUEST_TYPE, REQUEST, REQ_VALUE, REQ_INDEX,
                buffer, LENGTH, 2000);
        //Parse received data into a description 
        String description = parseConfigDescriptor(buffer);
         
        mDisplayText.setText(description);
        connection.close();
    } 
     
    /* 
     * Parse the USB configuration descriptor response per the 
     * USB Specification.  Return a printable description of 
     * the connected device. 
     */ 
    private static final int DESC_SIZE_CONFIG = 9;
5
CodeRank
This code example shows how to use the following methods:controlTransfer
        byte[] buffer = new byte[7];
         
        if (connection == null) throw new IOException("Connection closed");
         
        // Get current settings 
        connection.controlTransfer(GET_LINE_REQUEST_TYPE, GET_LINE_REQUEST, 0, 0, oldSettings, 7, 100);
         
        buffer = oldSettings;
         
        // Setup Baudrate 
        int baud;
        switch (R) {
        case B0: baud = 0; break;
        case B75: baud = 75; break;
        case B150: baud = 150; break;
        case B300: baud = 300; break;
        case B600: baud = 600; break;
        case B1200: baud = 1200; break;
        case B1800: baud = 1800; break;
        case B2400: baud = 2400; break;

5
CodeRank
This code example shows how to use the following methods:controlTransfer
		byte[] line_coding = new byte[0];
		 
		Integer baudRate = Integer.parseInt( s );
			 
		line_coding = new byte[]{(byte)(baudRate.intValue()&0xFF), (byte)((baudRate.intValue()>>8)&0xFF), (byte)((baudRate.intValue()>>16)&0xFF), (byte)((baudRate.intValue()>>24)&0xFF), (byte)0x00, (byte)0x00, (byte)0x08};
		connection.controlTransfer(0x21, 0x20, 0x0000, 0x0000, line_coding, line_coding.length, 20);
	} 
} 
3
CodeRank
This code example shows how to use the following methods:controlTransfer
		return false; 
	} 
	@SuppressLint("NewApi") 
	private boolean hidSetReport(byte [] data) {
		if (mConnection != null) {
			int nTransferred = mConnection.controlTransfer(
					UsbConstants.USB_TYPE_CLASS | UsbConstants.USB_DIR_OUT,		// output
					USBRQ_HID_SET_REPORT, USB_HID_REPORT_TYPE_FEATURE << 8,
					0, 
					data, data.length, 0);
			 
			return  (nTransferred > 0) ? true : false;
		} 
		return false; 
	} 
	 
	private boolean read(byte [] data) {
		return hidGetReport(data);
	} 
	 
3
CodeRank
This code example shows how to use the following methods:controlTransfer
    private static final int USB_RT_ACM = UsbConstants.USB_TYPE_CLASS | USB_RECIP_INTERFACE;
 
    private static final int SET_LINE_CODING = 0x20;  // USB CDC 1.1 section 6.2
 
    private int sendAcmControlMessage(int request, int value, byte[] buf) {
        return mConnection.controlTransfer(USB_RT_ACM, request, value, 0, buf, buf != null ? buf.length : 0, 5000);
    } 
 
    private int setAcmLineCoding(int bitRate, int stopBits, int parity, int dataBits) {
        byte[] msg = {
                (byte) ( bitRate & 0xff),
                (byte) ((bitRate >> 8 ) & 0xff),
                (byte) ((bitRate >> 16) & 0xff),
                (byte) ((bitRate >> 24) & 0xff),
 
                (byte) stopBits,
                (byte) parity,
                (byte) dataBits};
        return sendAcmControlMessage(SET_LINE_CODING, 0, msg);
    } 
4
CodeRank

Related UsbDeviceConnection controlTransfer Questions & Answers:

controlTransfer Method Overview
Performs a control transaction on endpoint zero for this device.
See Code Examples for other Android UsbDeviceConnection Methods: