Android UsbDeviceConnection - top ranked examples from Open Source projects

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

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
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: claimInterface
mDevice = device;
        mEndpointIntr = ep;
        if (device != null) {
            UsbDeviceConnection connection = mUsbManager.openDevice(device);
            if (connection != null && connection.claimInterface(intf, true)) {
                Log.d(TAG, "open SUCCESS");
                mConnection = connection;
                Thread thread = new Thread(this);
                thread.start();
 
            } else { 
                Log.d(TAG, "open FAIL");
                mConnection = null;
            } 
         } 
    } 
 
    private void sendCommand(int control) {
        synchronized (this) {
Full Snippet Info
5
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
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; 
    } 
 
} 
Full Snippet Info
5
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
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
Stop searching for code, let great code find you!  Add Codota to your java IDE
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;
Full Snippet Info
5
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE

Related Android UsbDeviceConnection Questions & Answers:

See Code Examples for Android UsbDeviceConnection Methods: