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
Connect your IDE to all the code out there  Get Codota for Java
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) {
5
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
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
Connect your IDE to all the code out there  Get Codota for Java
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
Connect your IDE to all the code out there  Get Codota for Java
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
Connect your IDE to all the code out there  Get Codota for Java
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
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:claimInterface
        Log.d(TAG, "Claiming control interface.");
        mControlInterface = mDevice.getInterface(0);
        Log.d(TAG, "Control iface=" + mControlInterface);
        // class should be USB_CLASS_COMM 
 
        if (!mConnection.claimInterface(mControlInterface, true)) {
            throw new IOException("Could not claim control interface.");
        } 
        mControlEndpoint = mControlInterface.getEndpoint(0);
        Log.d(TAG, "Control endpoint direction: " + mControlEndpoint.getDirection());
 
        Log.d(TAG, "Claiming data interface.");
        mDataInterface = mDevice.getInterface(1);
        Log.d(TAG, "data iface=" + mDataInterface);
        // class should be USB_CLASS_CDC_DATA 
 
        if (!mConnection.claimInterface(mDataInterface, true)) {
            throw new IOException("Could not claim data interface.");
        } 
        mReadEndpoint = mDataInterface.getEndpoint(1);

3
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:close, releaseInterface
	private void destroy() 
	{ 
		/* 
		 * reinitialisation de l'interface 
		 */ 
		connection.releaseInterface(intf);
		connection.close();
 
		/* Reinitialisation de variables loacales */ 
		device = null;
		manager = null;
		handler = null;
		messageToSend = 0;
		closeRequested = false;
		connection = null;
		intf = null;
	} 
} 
4
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
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
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:close, releaseInterface
 
	// Sets the current USB device and interface 
	private boolean setUSBInterface(UsbDevice device, UsbInterface intf) {
		if (mUsbDeviceConnection != null) {
			if (mUsbInterface[0] != null) {
				mUsbDeviceConnection.releaseInterface(mUsbInterface[0]);
				mUsbInterface[0] = null;
			} 
			mUsbDeviceConnection.close();
			mUsbDevice = null;
			mUsbDeviceConnection = null;
		} 
 
		if (device != null && intf != null) {
			UsbDeviceConnection connection = mUsbManager.openDevice(device);
			if (connection != null) {
				if (connection.claimInterface(intf, false)) {
 
					if ((device.getVendorId() == DEVICE_VENDOR_ID)
							&& (device.getProductId() == DEVICE_PRODUCT_ID)) {
4
CodeRank
Connect your IDE to all the code out there  Get Codota for Java

Related Android UsbDeviceConnection Questions & Answers:

See Code Examples for Android UsbDeviceConnection Methods: