Java Code Examples for android.hardware.usb.UsbInterface#getEndpointCount()
The following examples show how to use
android.hardware.usb.UsbInterface#getEndpointCount() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Ch34xSerialDriver.java From usb-serial-for-android with GNU Lesser General Public License v2.1 | 6 votes |
@Override protected void openInt(UsbDeviceConnection connection) throws IOException { for (int i = 0; i < mDevice.getInterfaceCount(); i++) { UsbInterface usbIface = mDevice.getInterface(i); if (!mConnection.claimInterface(usbIface, true)) { throw new IOException("Could not claim data interface"); } } UsbInterface dataIface = mDevice.getInterface(mDevice.getInterfaceCount() - 1); for (int i = 0; i < dataIface.getEndpointCount(); i++) { UsbEndpoint ep = dataIface.getEndpoint(i); if (ep.getType() == UsbConstants.USB_ENDPOINT_XFER_BULK) { if (ep.getDirection() == UsbConstants.USB_DIR_IN) { mReadEndpoint = ep; } else { mWriteEndpoint = ep; } } } initialize(); setBaudRate(DEFAULT_BAUD_RATE); }
Example 2
Source File: Cp21xxSerialDriver.java From usb-serial-for-android with GNU Lesser General Public License v2.1 | 6 votes |
@Override protected void openInt(UsbDeviceConnection connection) throws IOException { mIsRestrictedPort = mDevice.getInterfaceCount() == 2 && mPortNumber == 1; if(mPortNumber >= mDevice.getInterfaceCount()) { throw new IOException("Unknown port number"); } UsbInterface dataIface = mDevice.getInterface(mPortNumber); if (!mConnection.claimInterface(dataIface, true)) { throw new IOException("Could not claim interface " + mPortNumber); } for (int i = 0; i < dataIface.getEndpointCount(); i++) { UsbEndpoint ep = dataIface.getEndpoint(i); if (ep.getType() == UsbConstants.USB_ENDPOINT_XFER_BULK) { if (ep.getDirection() == UsbConstants.USB_DIR_IN) { mReadEndpoint = ep; } else { mWriteEndpoint = ep; } } } setConfigSingle(SILABSER_IFC_ENABLE_REQUEST_CODE, UART_ENABLE); setConfigSingle(SILABSER_SET_MHS_REQUEST_CODE, MCR_ALL | CONTROL_WRITE_DTR | CONTROL_WRITE_RTS); // setConfigSingle(SILABSER_SET_BAUDDIV_REQUEST_CODE, BAUD_RATE_GEN_FREQ / DEFAULT_BAUD_RATE); // setParameters(DEFAULT_BAUD_RATE, DEFAULT_DATA_BITS, DEFAULT_STOP_BITS, DEFAULT_PARITY); }
Example 3
Source File: BTChipTransportAndroidHID.java From xmrwallet with Apache License 2.0 | 6 votes |
public static BTChipTransport open(UsbManager manager, UsbDevice device) throws IOException { UsbDeviceConnection connection = manager.openDevice(device); if (connection == null) throw new IOException("Device not connected"); // Must only be called once permission is granted (see http://developer.android.com/reference/android/hardware/usb/UsbManager.html) // Important if enumerating, rather than being awaken by the intent notification UsbInterface dongleInterface = device.getInterface(0); UsbEndpoint in = null; UsbEndpoint out = null; for (int i = 0; i < dongleInterface.getEndpointCount(); i++) { UsbEndpoint tmpEndpoint = dongleInterface.getEndpoint(i); if (tmpEndpoint.getDirection() == UsbConstants.USB_DIR_IN) { in = tmpEndpoint; } else { out = tmpEndpoint; } } connection.claimInterface(dongleInterface, true); return new BTChipTransportAndroidHID(connection, dongleInterface, in, out); }
Example 4
Source File: BTChipTransportAndroid.java From green_android with GNU General Public License v3.0 | 5 votes |
public static BTChipTransport open(UsbManager manager, UsbDevice device) { // Must only be called once permission is granted (see http://developer.android.com/reference/android/hardware/usb/UsbManager.html) // Important if enumerating, rather than being awaken by the intent notification UsbInterface dongleInterface = device.getInterface(0); UsbEndpoint in = null; UsbEndpoint out = null; boolean ledger; for (int i=0; i<dongleInterface.getEndpointCount(); i++) { UsbEndpoint tmpEndpoint = dongleInterface.getEndpoint(i); if (tmpEndpoint.getDirection() == UsbConstants.USB_DIR_IN) { in = tmpEndpoint; } else { out = tmpEndpoint; } } UsbDeviceConnection connection = manager.openDevice(device); if (connection == null) { return null; } connection.claimInterface(dongleInterface, true); ledger = ((device.getProductId() == PID_HID_LEDGER) || (device.getProductId() == PID_HID_LEDGER_PROTON) || (device.getProductId() == PID_NANOS) || (device.getProductId() == PID_BLUE) || (device.getProductId() == PID_NANOX)); if (device.getProductId() == PID_WINUSB) { return new BTChipTransportAndroidWinUSB(connection, dongleInterface, in, out, TIMEOUT); } else { return new BTChipTransportAndroidHID(connection, dongleInterface, in, out, TIMEOUT, ledger); } }
Example 5
Source File: BTChipTransportAndroid.java From WalletCordova with GNU Lesser General Public License v2.1 | 5 votes |
public static BTChipTransport open(UsbManager manager, UsbDevice device) { // Must only be called once permission is granted (see http://developer.android.com/reference/android/hardware/usb/UsbManager.html) // Important if enumerating, rather than being awaken by the intent notification UsbInterface dongleInterface = device.getInterface(0); UsbEndpoint in = null; UsbEndpoint out = null; boolean ledger; for (int i=0; i<dongleInterface.getEndpointCount(); i++) { UsbEndpoint tmpEndpoint = dongleInterface.getEndpoint(i); if (tmpEndpoint.getDirection() == UsbConstants.USB_DIR_IN) { in = tmpEndpoint; } else { out = tmpEndpoint; } } UsbDeviceConnection connection = manager.openDevice(device); connection.claimInterface(dongleInterface, true); ledger = ((device.getProductId() == PID_HID_LEDGER) || (device.getProductId() == PID_HID_LEDGER_PROTON) || (device.getProductId() == PID_NANOS) || (device.getProductId() == PID_BLUE)); if (device.getProductId() == PID_WINUSB) { return new BTChipTransportAndroidWinUSB(connection, dongleInterface, in, out, TIMEOUT); } else { return new BTChipTransportAndroidHID(connection, dongleInterface, in, out, TIMEOUT, ledger); } }
Example 6
Source File: BTChipTransportAndroid.java From GreenBits with GNU General Public License v3.0 | 5 votes |
public static BTChipTransport open(UsbManager manager, UsbDevice device) { // Must only be called once permission is granted (see http://developer.android.com/reference/android/hardware/usb/UsbManager.html) // Important if enumerating, rather than being awaken by the intent notification UsbInterface dongleInterface = device.getInterface(0); UsbEndpoint in = null; UsbEndpoint out = null; boolean ledger; for (int i=0; i<dongleInterface.getEndpointCount(); i++) { UsbEndpoint tmpEndpoint = dongleInterface.getEndpoint(i); if (tmpEndpoint.getDirection() == UsbConstants.USB_DIR_IN) { in = tmpEndpoint; } else { out = tmpEndpoint; } } UsbDeviceConnection connection = manager.openDevice(device); if (connection == null) { return null; } connection.claimInterface(dongleInterface, true); ledger = ((device.getProductId() == PID_HID_LEDGER) || (device.getProductId() == PID_HID_LEDGER_PROTON) || (device.getProductId() == PID_NANOS) || (device.getProductId() == PID_BLUE)); if (device.getProductId() == PID_WINUSB) { return new BTChipTransportAndroidWinUSB(connection, dongleInterface, in, out, TIMEOUT); } else { return new BTChipTransportAndroidHID(connection, dongleInterface, in, out, TIMEOUT, ledger); } }
Example 7
Source File: CH34xSerialDriver.java From Arduino-Serial-Controller with GNU Lesser General Public License v2.1 | 4 votes |
@Override public void open(UsbDeviceConnection connection) throws IOException { if (mConnection != null) { throw new IOException("Already opened."); } mConnection = connection; boolean opened = false; try { for (int i = 0; i < mDevice.getInterfaceCount(); i++) { UsbInterface usbIface = mDevice.getInterface(i); if (mConnection.claimInterface(usbIface, true)) { Log.d(TAG, "claimInterface " + i + " SUCCESS"); } else { Log.d(TAG, "claimInterface " + i + " FAIL"); } } UsbInterface dataIface = mDevice.getInterface(mDevice.getInterfaceCount() - 1); for (int i = 0; i < dataIface.getEndpointCount(); i++) { UsbEndpoint ep = dataIface.getEndpoint(i); if (ep.getType() == UsbConstants.USB_ENDPOINT_XFER_BULK) { if (ep.getDirection() == UsbConstants.USB_DIR_IN) { mReadEndpoint = ep; } else { mWriteEndpoint = ep; } } } initialize(); setBaudRate(DEFAULT_BAUD_RATE); opened = true; } finally { if (!opened) { try { close(); } catch (IOException e) { // Ignore IOExceptions during close() } } } }
Example 8
Source File: Cp21xxSerialDriver.java From Arduino-Serial-Controller with GNU Lesser General Public License v2.1 | 4 votes |
@Override public void open(UsbDeviceConnection connection) throws IOException { if (mConnection != null) { throw new IOException("Already opened."); } mConnection = connection; boolean opened = false; try { for (int i = 0; i < mDevice.getInterfaceCount(); i++) { UsbInterface usbIface = mDevice.getInterface(i); if (mConnection.claimInterface(usbIface, true)) { Log.d(TAG, "claimInterface " + i + " SUCCESS"); } else { Log.d(TAG, "claimInterface " + i + " FAIL"); } } UsbInterface dataIface = mDevice.getInterface(mDevice.getInterfaceCount() - 1); for (int i = 0; i < dataIface.getEndpointCount(); i++) { UsbEndpoint ep = dataIface.getEndpoint(i); if (ep.getType() == UsbConstants.USB_ENDPOINT_XFER_BULK) { if (ep.getDirection() == UsbConstants.USB_DIR_IN) { mReadEndpoint = ep; } else { mWriteEndpoint = ep; } } } setConfigSingle(SILABSER_IFC_ENABLE_REQUEST_CODE, UART_ENABLE); setConfigSingle(SILABSER_SET_MHS_REQUEST_CODE, MCR_ALL | CONTROL_WRITE_DTR | CONTROL_WRITE_RTS); setConfigSingle(SILABSER_SET_BAUDDIV_REQUEST_CODE, BAUD_RATE_GEN_FREQ / DEFAULT_BAUD_RATE); // setParameters(DEFAULT_BAUD_RATE, DEFAULT_DATA_BITS, DEFAULT_STOP_BITS, DEFAULT_PARITY); opened = true; } finally { if (!opened) { try { close(); } catch (IOException e) { // Ignore IOExceptions during close() } } } }
Example 9
Source File: Cp21xxSerialDriver.java From xDrip with GNU General Public License v3.0 | 4 votes |
@Override public void open(UsbDeviceConnection connection) throws IOException { if (mConnection != null) { throw new IOException("Already opened."); } mConnection = connection; boolean opened = false; try { for (int i = 0; i < mDevice.getInterfaceCount(); i++) { UsbInterface usbIface = mDevice.getInterface(i); if (mConnection.claimInterface(usbIface, true)) { Log.d(TAG, "claimInterface " + i + " SUCCESS"); } else { Log.d(TAG, "claimInterface " + i + " FAIL"); } } UsbInterface dataIface = mDevice.getInterface(mDevice.getInterfaceCount() - 1); for (int i = 0; i < dataIface.getEndpointCount(); i++) { UsbEndpoint ep = dataIface.getEndpoint(i); if (ep.getType() == UsbConstants.USB_ENDPOINT_XFER_BULK) { if (ep.getDirection() == UsbConstants.USB_DIR_IN) { mReadEndpoint = ep; } else { mWriteEndpoint = ep; } } } setConfigSingle(SILABSER_IFC_ENABLE_REQUEST_CODE, UART_ENABLE); setConfigSingle(SILABSER_SET_MHS_REQUEST_CODE, MCR_ALL | CONTROL_WRITE_DTR | CONTROL_WRITE_RTS); setConfigSingle(SILABSER_SET_BAUDDIV_REQUEST_CODE, BAUD_RATE_GEN_FREQ / DEFAULT_BAUD_RATE); // setParameters(DEFAULT_BAUD_RATE, DEFAULT_DATA_BITS, DEFAULT_STOP_BITS, DEFAULT_PARITY); opened = true; } finally { if (!opened) { try { close(); } catch (IOException e) { // Ignore IOExceptions during close() } } } }
Example 10
Source File: Cp21xxSerialDriver.java From xDrip-Experimental with GNU General Public License v3.0 | 4 votes |
@Override public void open(UsbDeviceConnection connection) throws IOException { if (mConnection != null) { throw new IOException("Already opened."); } mConnection = connection; boolean opened = false; try { for (int i = 0; i < mDevice.getInterfaceCount(); i++) { UsbInterface usbIface = mDevice.getInterface(i); if (mConnection.claimInterface(usbIface, true)) { Log.d(TAG, "claimInterface " + i + " SUCCESS"); } else { Log.d(TAG, "claimInterface " + i + " FAIL"); } } UsbInterface dataIface = mDevice.getInterface(mDevice.getInterfaceCount() - 1); for (int i = 0; i < dataIface.getEndpointCount(); i++) { UsbEndpoint ep = dataIface.getEndpoint(i); if (ep.getType() == UsbConstants.USB_ENDPOINT_XFER_BULK) { if (ep.getDirection() == UsbConstants.USB_DIR_IN) { mReadEndpoint = ep; } else { mWriteEndpoint = ep; } } } setConfigSingle(SILABSER_IFC_ENABLE_REQUEST_CODE, UART_ENABLE); setConfigSingle(SILABSER_SET_MHS_REQUEST_CODE, MCR_ALL | CONTROL_WRITE_DTR | CONTROL_WRITE_RTS); setConfigSingle(SILABSER_SET_BAUDDIV_REQUEST_CODE, BAUD_RATE_GEN_FREQ / DEFAULT_BAUD_RATE); // setParameters(DEFAULT_BAUD_RATE, DEFAULT_DATA_BITS, DEFAULT_STOP_BITS, DEFAULT_PARITY); opened = true; } finally { if (!opened) { try { close(); } catch (IOException e) { // Ignore IOExceptions during close() } } } }
Example 11
Source File: Trezor.java From GreenBits with GNU General Public License v3.0 | 4 votes |
public static Trezor getDevice(final Context context, final TrezorGUICallback guiFn, final Network network) { final UsbManager manager = (UsbManager)context.getSystemService(Context.USB_SERVICE); for (final UsbDevice device: manager.getDeviceList().values()) { // Check if the device is TREZOR (or AvalonWallet or BWALLET) final int vendorId = device.getVendorId(); final int productId = device.getProductId(); if ((vendorId != 0x534c || productId != 0x0001) && (vendorId != 0x1209 || productId != 0x53c0) && (vendorId != 0x1209 || productId != 0x53c1) && (vendorId != 0x10c4 || productId != 0xea80)) { continue; } Log.i(TAG, "Hardware Wallet device found"); if (device.getInterfaceCount() < 1) { Log.e(TAG, "Wrong interface count"); continue; } // Use first interface final UsbInterface iface = device.getInterface(0); // Try to find read/write endpoints UsbEndpoint readEndpoint = null, writeEndpoint = null; for (int i = 0; i < iface.getEndpointCount(); ++i) { final UsbEndpoint ep = iface.getEndpoint(i); if (readEndpoint == null && ep.getType() == UsbConstants.USB_ENDPOINT_XFER_INT && ep.getAddress() == 0x81) { // number = 1 ; dir = USB_DIR_IN readEndpoint = ep; continue; } if (writeEndpoint == null && ep.getType() == UsbConstants.USB_ENDPOINT_XFER_INT && (ep.getAddress() == 0x01 || ep.getAddress() == 0x02)) { // number = 1 ; dir = USB_DIR_OUT writeEndpoint = ep; continue; } Log.e(TAG, String.format("ep %d", ep.getAddress())); } if (!isEndpointOK(readEndpoint, "read") || !isEndpointOK(writeEndpoint, "write")) continue; // Try to open the device final UsbDeviceConnection conn = manager.openDevice(device); if (conn == null || !conn.claimInterface(iface, true)) { Log.e(TAG, conn == null ? "Could not open connection" : "Could not claim interface"); continue; } // All OK - return the class return new Trezor(guiFn, device, conn, readEndpoint, writeEndpoint, network); } return null; }
Example 12
Source File: Cp21xxSerialDriver.java From xDrip-plus with GNU General Public License v3.0 | 4 votes |
@Override public void open(UsbDeviceConnection connection) throws IOException { if (mConnection != null) { throw new IOException("Already opened."); } mConnection = connection; boolean opened = false; try { for (int i = 0; i < mDevice.getInterfaceCount(); i++) { UsbInterface usbIface = mDevice.getInterface(i); if (mConnection.claimInterface(usbIface, true)) { Log.d(TAG, "claimInterface " + i + " SUCCESS"); } else { Log.d(TAG, "claimInterface " + i + " FAIL"); } } UsbInterface dataIface = mDevice.getInterface(mDevice.getInterfaceCount() - 1); for (int i = 0; i < dataIface.getEndpointCount(); i++) { UsbEndpoint ep = dataIface.getEndpoint(i); if (ep.getType() == UsbConstants.USB_ENDPOINT_XFER_BULK) { if (ep.getDirection() == UsbConstants.USB_DIR_IN) { mReadEndpoint = ep; } else { mWriteEndpoint = ep; } } } setConfigSingle(SILABSER_IFC_ENABLE_REQUEST_CODE, UART_ENABLE); setConfigSingle(SILABSER_SET_MHS_REQUEST_CODE, MCR_ALL | CONTROL_WRITE_DTR | CONTROL_WRITE_RTS); setConfigSingle(SILABSER_SET_BAUDDIV_REQUEST_CODE, BAUD_RATE_GEN_FREQ / DEFAULT_BAUD_RATE); // setParameters(DEFAULT_BAUD_RATE, DEFAULT_DATA_BITS, DEFAULT_STOP_BITS, DEFAULT_PARITY); opened = true; } finally { if (!opened) { try { close(); } catch (IOException e) { // Ignore IOExceptions during close() } } } }
Example 13
Source File: Cp21xxSerialDriver.java From xDrip with GNU General Public License v3.0 | 4 votes |
@Override public void open(UsbDeviceConnection connection) throws IOException { if (mConnection != null) { throw new IOException("Already opened."); } mConnection = connection; boolean opened = false; try { for (int i = 0; i < mDevice.getInterfaceCount(); i++) { UsbInterface usbIface = mDevice.getInterface(i); if (mConnection.claimInterface(usbIface, true)) { Log.d(TAG, "claimInterface " + i + " SUCCESS"); } else { Log.d(TAG, "claimInterface " + i + " FAIL"); } } UsbInterface dataIface = mDevice.getInterface(mDevice.getInterfaceCount() - 1); for (int i = 0; i < dataIface.getEndpointCount(); i++) { UsbEndpoint ep = dataIface.getEndpoint(i); if (ep.getType() == UsbConstants.USB_ENDPOINT_XFER_BULK) { if (ep.getDirection() == UsbConstants.USB_DIR_IN) { mReadEndpoint = ep; } else { mWriteEndpoint = ep; } } } setConfigSingle(SILABSER_IFC_ENABLE_REQUEST_CODE, UART_ENABLE); setConfigSingle(SILABSER_SET_MHS_REQUEST_CODE, MCR_ALL | CONTROL_WRITE_DTR | CONTROL_WRITE_RTS); setConfigSingle(SILABSER_SET_BAUDDIV_REQUEST_CODE, BAUD_RATE_GEN_FREQ / DEFAULT_BAUD_RATE); // setParameters(DEFAULT_BAUD_RATE, DEFAULT_DATA_BITS, DEFAULT_STOP_BITS, DEFAULT_PARITY); opened = true; } finally { if (!opened) { try { close(); } catch (IOException e) { // Ignore IOExceptions during close() } } } }
Example 14
Source File: MedtronicCnlService.java From 600SeriesAndroidUploader with MIT License | 4 votes |
private void getUsbInfo() { UsbManager mManager = (UsbManager) getSystemService(Context.USB_SERVICE); HashMap<String, UsbDevice> deviceList = mManager.getDeviceList(); Iterator<UsbDevice> deviceIterator = deviceList.values().iterator(); while (deviceIterator.hasNext()) { UsbDevice device = deviceIterator.next(); Log.i(TAG, "Model: " + device.getDeviceName()); Log.i(TAG, "ID: " + device.getDeviceId()); Log.i(TAG, "Class: " + device.getDeviceClass()); Log.i(TAG, "Protocol: " + device.getDeviceProtocol()); Log.i(TAG, "Vendor ID " + device.getVendorId()); Log.i(TAG, "Product ID: " + device.getProductId()); Log.i(TAG, "Interface count: " + device.getInterfaceCount()); Log.i(TAG, "---------------------------------------"); // Get interface details for (int index = 0; index < device.getInterfaceCount(); index++) { UsbInterface mUsbInterface = device.getInterface(index); Log.i(TAG, " ***** *****"); Log.i(TAG, " Interface index: " + index); Log.i(TAG, " Interface ID: " + mUsbInterface.getId()); Log.i(TAG, " Inteface class: " + mUsbInterface.getInterfaceClass()); Log.i(TAG, " Interface protocol: " + mUsbInterface.getInterfaceProtocol()); Log.i(TAG, " Endpoint count: " + mUsbInterface.getEndpointCount()); // Get endpoint details for (int epi = 0; epi < mUsbInterface.getEndpointCount(); epi++) { UsbEndpoint mEndpoint = mUsbInterface.getEndpoint(epi); Log.i(TAG, " ++++ ++++ ++++"); Log.i(TAG, " Endpoint index: " + epi); Log.i(TAG, " Attributes: " + mEndpoint.getAttributes()); Log.i(TAG, " Direction: " + mEndpoint.getDirection()); Log.i(TAG, " Number: " + mEndpoint.getEndpointNumber()); Log.i(TAG, " Interval: " + mEndpoint.getInterval()); Log.i(TAG, " Packet size: " + mEndpoint.getMaxPacketSize()); Log.i(TAG, " Type: " + mEndpoint.getType()); } } } Log.i(TAG, " No more devices connected."); }
Example 15
Source File: UsbIpService.java From USBIPServerForAndroid with GNU General Public License v3.0 | 4 votes |
private int detectSpeed(UsbDevice dev, UsbDeviceDescriptor devDesc) { int possibleSpeeds = FLAG_POSSIBLE_SPEED_LOW | FLAG_POSSIBLE_SPEED_FULL | FLAG_POSSIBLE_SPEED_HIGH; for (int i = 0; i < dev.getInterfaceCount(); i++) { UsbInterface iface = dev.getInterface(i); for (int j = 0; j < iface.getEndpointCount(); j++) { UsbEndpoint endpoint = iface.getEndpoint(j); if ((endpoint.getType() == UsbConstants.USB_ENDPOINT_XFER_BULK) || (endpoint.getType() == UsbConstants.USB_ENDPOINT_XFER_ISOC)) { // Low speed devices can't implement bulk or iso endpoints possibleSpeeds &= ~FLAG_POSSIBLE_SPEED_LOW; } if (endpoint.getType() == UsbConstants.USB_ENDPOINT_XFER_CONTROL) { if (endpoint.getMaxPacketSize() > 8) { // Low speed devices can't use control transfer sizes larger than 8 bytes possibleSpeeds &= ~FLAG_POSSIBLE_SPEED_LOW; } if (endpoint.getMaxPacketSize() < 64) { // High speed devices can't use control transfer sizes smaller than 64 bytes possibleSpeeds &= ~FLAG_POSSIBLE_SPEED_HIGH; } } else if (endpoint.getType() == UsbConstants.USB_ENDPOINT_XFER_INT) { if (endpoint.getMaxPacketSize() > 8) { // Low speed devices can't use interrupt transfer sizes larger than 8 bytes possibleSpeeds &= ~FLAG_POSSIBLE_SPEED_LOW; } if (endpoint.getMaxPacketSize() > 64) { // Full speed devices can't use interrupt transfer sizes larger than 64 bytes possibleSpeeds &= ~FLAG_POSSIBLE_SPEED_FULL; } } else if (endpoint.getType() == UsbConstants.USB_ENDPOINT_XFER_BULK) { // A bulk endpoint alone can accurately distiniguish between // full and high speed devices if (endpoint.getMaxPacketSize() == 512) { // High speed devices can only use 512 byte bulk transfers possibleSpeeds = FLAG_POSSIBLE_SPEED_HIGH; } else { // Otherwise it must be full speed possibleSpeeds = FLAG_POSSIBLE_SPEED_FULL; } } else if (endpoint.getType() == UsbConstants.USB_ENDPOINT_XFER_ISOC) { // If the transfer size is 1024, it must be high speed if (endpoint.getMaxPacketSize() == 1024) { possibleSpeeds = FLAG_POSSIBLE_SPEED_HIGH; } } } } if (devDesc != null) { if (devDesc.bcdUSB < 0x200) { // High speed only supported on USB 2.0 or higher possibleSpeeds &= ~FLAG_POSSIBLE_SPEED_HIGH; } } // Return the lowest speed that we're compatible with System.out.printf("Speed heuristics for device %d left us with 0x%x\n", dev.getDeviceId(), possibleSpeeds); if ((possibleSpeeds & FLAG_POSSIBLE_SPEED_LOW) != 0) { return UsbIpDevice.USB_SPEED_LOW; } else if ((possibleSpeeds & FLAG_POSSIBLE_SPEED_FULL) != 0) { return UsbIpDevice.USB_SPEED_FULL; } else if ((possibleSpeeds & FLAG_POSSIBLE_SPEED_HIGH) != 0) { return UsbIpDevice.USB_SPEED_HIGH; } else { // Something went very wrong in speed detection return UsbIpDevice.USB_SPEED_UNKNOWN; } }
Example 16
Source File: Ch34xSerialDriver.java From usb-with-serial-port with Apache License 2.0 | 4 votes |
@Override public void open(UsbDeviceConnection connection) throws IOException { if (mConnection != null) { throw new IOException("Already opened."); } mConnection = connection; boolean opened = false; try { for (int i = 0; i < mDevice.getInterfaceCount(); i++) { UsbInterface usbIface = mDevice.getInterface(i); if (mConnection.claimInterface(usbIface, true)) { L.INSTANCE.d("claimInterface " + i + " SUCCESS"); } else { L.INSTANCE.d("claimInterface " + i + " FAIL"); } } UsbInterface dataIface = mDevice.getInterface(mDevice.getInterfaceCount() - 1); for (int i = 0; i < dataIface.getEndpointCount(); i++) { UsbEndpoint ep = dataIface.getEndpoint(i); if (ep.getType() == UsbConstants.USB_ENDPOINT_XFER_BULK) { if (ep.getDirection() == UsbConstants.USB_DIR_IN) { mReadEndpoint = ep; } else { mWriteEndpoint = ep; } } else { L.INSTANCE.d("ep.getType():" + ep.getType()); } } initialize(); setBaudRate(DEFAULT_BAUD_RATE); opened = true; } finally { if (!opened) { try { close(); } catch (IOException e) { // Ignore IOExceptions during close() } } } }
Example 17
Source File: Cp21xxSerialDriver.java From OkUSB with Apache License 2.0 | 4 votes |
@Override public void open(UsbDeviceConnection connection) throws IOException { if (mConnection != null) { throw new IOException("Already opened."); } mConnection = connection; boolean opened = false; try { for (int i = 0; i < mDevice.getInterfaceCount(); i++) { UsbInterface usbIface = mDevice.getInterface(i); if (mConnection.claimInterface(usbIface, true)) { Log.d(TAG, "claimInterface " + i + " SUCCESS"); } else { Log.d(TAG, "claimInterface " + i + " FAIL"); } } UsbInterface dataIface = mDevice.getInterface(mDevice.getInterfaceCount() - 1); for (int i = 0; i < dataIface.getEndpointCount(); i++) { UsbEndpoint ep = dataIface.getEndpoint(i); if (ep.getType() == UsbConstants.USB_ENDPOINT_XFER_BULK) { if (ep.getDirection() == UsbConstants.USB_DIR_IN) { mReadEndpoint = ep; } else { mWriteEndpoint = ep; } } } setConfigSingle(SILABSER_IFC_ENABLE_REQUEST_CODE, UART_ENABLE); setConfigSingle(SILABSER_SET_MHS_REQUEST_CODE, MCR_ALL | CONTROL_WRITE_DTR | CONTROL_WRITE_RTS); setConfigSingle(SILABSER_SET_BAUDDIV_REQUEST_CODE, BAUD_RATE_GEN_FREQ / DEFAULT_BAUD_RATE); // setParameters(DEFAULT_BAUD_RATE, DEFAULT_DATA_BITS, DEFAULT_STOP_BITS, DEFAULT_PARITY); opened = true; } finally { if (!opened) { try { close(); } catch (IOException e) { // Ignore IOExceptions during close() } } } }
Example 18
Source File: Ch34xSerialDriver.java From OkUSB with Apache License 2.0 | 4 votes |
@Override public void open(UsbDeviceConnection connection) throws IOException { if (mConnection != null) { throw new IOException("Already opened."); } mConnection = connection; boolean opened = false; try { for (int i = 0; i < mDevice.getInterfaceCount(); i++) { UsbInterface usbIface = mDevice.getInterface(i); if (mConnection.claimInterface(usbIface, true)) { Log.d(TAG, "claimInterface " + i + " SUCCESS"); } else { Log.d(TAG, "claimInterface " + i + " FAIL"); } } UsbInterface dataIface = mDevice.getInterface(mDevice.getInterfaceCount() - 1); for (int i = 0; i < dataIface.getEndpointCount(); i++) { UsbEndpoint ep = dataIface.getEndpoint(i); if (ep.getType() == UsbConstants.USB_ENDPOINT_XFER_BULK) { if (ep.getDirection() == UsbConstants.USB_DIR_IN) { mReadEndpoint = ep; } else { mWriteEndpoint = ep; } } } initialize(); setBaudRate(DEFAULT_BAUD_RATE); opened = true; } finally { if (!opened) { try { close(); } catch (IOException e) { // Ignore IOExceptions during close() } } } }
Example 19
Source File: Ch34xSerialDriver.java From Chorus-RF-Laptimer with MIT License | 4 votes |
@Override public void open(UsbDeviceConnection connection) throws IOException { if (mConnection != null) { throw new IOException("Already opened."); } mConnection = connection; boolean opened = false; try { for (int i = 0; i < mDevice.getInterfaceCount(); i++) { UsbInterface usbIface = mDevice.getInterface(i); if (mConnection.claimInterface(usbIface, true)) { Log.d(TAG, "claimInterface " + i + " SUCCESS"); } else { Log.d(TAG, "claimInterface " + i + " FAIL"); } } UsbInterface dataIface = mDevice.getInterface(mDevice.getInterfaceCount() - 1); for (int i = 0; i < dataIface.getEndpointCount(); i++) { UsbEndpoint ep = dataIface.getEndpoint(i); if (ep.getType() == UsbConstants.USB_ENDPOINT_XFER_BULK) { if (ep.getDirection() == UsbConstants.USB_DIR_IN) { mReadEndpoint = ep; } else { mWriteEndpoint = ep; } } } initialize(); setBaudRate(DEFAULT_BAUD_RATE); opened = true; } finally { if (!opened) { try { close(); } catch (IOException e) { // Ignore IOExceptions during close() } } } }
Example 20
Source File: Trezor.java From green_android with GNU General Public License v3.0 | 4 votes |
public static Trezor getDevice(final Context context) { final UsbManager manager = (UsbManager)context.getSystemService(Context.USB_SERVICE); for (final UsbDevice device: manager.getDeviceList().values()) { // Check if the device is TREZOR (or AvalonWallet or BWALLET) final int vendorId = device.getVendorId(); final int productId = device.getProductId(); if ((vendorId != 0x534c || productId != 0x0001) && (vendorId != 0x1209 || productId != 0x53c0) && (vendorId != 0x1209 || productId != 0x53c1) && (vendorId != 0x10c4 || productId != 0xea80)) { continue; } Log.d(TAG, "Hardware Wallet device found"); if (device.getInterfaceCount() < 1) { Log.e(TAG, "Wrong interface count"); continue; } // Use first interface final UsbInterface iface = device.getInterface(0); // Try to find read/write endpoints UsbEndpoint readEndpoint = null, writeEndpoint = null; for (int i = 0; i < iface.getEndpointCount(); ++i) { final UsbEndpoint ep = iface.getEndpoint(i); if (readEndpoint == null && ep.getType() == UsbConstants.USB_ENDPOINT_XFER_INT && ep.getAddress() == 0x81) { // number = 1 ; dir = USB_DIR_IN readEndpoint = ep; continue; } if (writeEndpoint == null && ep.getType() == UsbConstants.USB_ENDPOINT_XFER_INT && (ep.getAddress() == 0x01 || ep.getAddress() == 0x02)) { // number = 1 ; dir = USB_DIR_OUT writeEndpoint = ep; continue; } Log.d(TAG, String.format("ep %d", ep.getAddress())); } if (isEndpointBad(readEndpoint, "read") || isEndpointBad(writeEndpoint, "write")) continue; // Try to open the device final UsbDeviceConnection conn = manager.openDevice(device); if (conn == null || !conn.claimInterface(iface, true)) { Log.e(TAG, conn == null ? "Could not open connection" : "Could not claim interface"); continue; } // All OK - return the class return new Trezor(device, conn, readEndpoint, writeEndpoint); } return null; }