public UsbInterfaceAssert hasEndpointCount(int count) { isNotNull(); int actualCount = actual.getEndpointCount(); Assertions.assertThat(actualCount) // .overridingErrorMessage("Expected endpoint count <%s> but was <%s>.", count, actualCount) // .isEqualTo(count); return this; }
public UsbInterfaceAssert hasInterfaceClass(int interfaceClass) { isNotNull(); int actualInterfaceClass = actual.getInterfaceClass(); Assertions.assertThat(actualInterfaceClass) // .overridingErrorMessage("Expected interface class <%s> but was <%s>.", interfaceClass, actualInterfaceClass) // .isEqualTo(interfaceClass); return this; }
public UsbInterfaceAssert hasInterfaceProtocol(int protocol) { isNotNull(); int actualProtocol = actual.getInterfaceProtocol(); Assertions.assertThat(actualProtocol) // .overridingErrorMessage("Expected interface protocol <%s> but was <%s>.", protocol, actualProtocol) // .isEqualTo(protocol); return this; }
private boolean openCP2130() { if(connection.claimInterface(mInterface, true)) { Log.i(CLASS_ID, "Interface succesfully claimed"); }else { Log.i(CLASS_ID, "Interface could not be claimed"); return false; } // Assign endpoints int numberEndpoints = mInterface.getEndpointCount(); for(int i=0;i<=numberEndpoints-1;i++) { UsbEndpoint endpoint = mInterface.getEndpoint(i); if(endpoint.getType() == UsbConstants.USB_ENDPOINT_XFER_BULK && endpoint.getDirection() == UsbConstants.USB_DIR_IN) { inEndpoint = endpoint; }else { outEndpoint = endpoint; } } return true; }
int endpointCount = usbInterface.getEndpointCount(); if (usbInterface.getInterfaceClass() == 1 && usbInterface.getInterfaceSubclass() == 3) { for (int endpointIndex = 0; endpointIndex < endpointCount; endpointIndex++) { UsbEndpoint endpoint = usbInterface.getEndpoint(endpointIndex); if (endpoint.getDirection() == direction) { return endpoint; UsbEndpoint endpoint = usbInterface.getEndpoint(endpointIndex); if ((endpoint.getType() == UsbConstants.USB_ENDPOINT_XFER_BULK || endpoint.getType() == UsbConstants.USB_ENDPOINT_XFER_INT)) { if (endpoint.getDirection() == direction) {
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()); for (int epi = 0; epi < mUsbInterface.getEndpointCount(); epi++) UsbEndpoint mEndpoint = mUsbInterface.getEndpoint(epi); Log.i(TAG," ++++ ++++ ++++"); Log.i(TAG," Endpoint index: " + epi);
public void open() throws IOException { if (!device_found) { throw new IOException("Device not Connected"); } mConnection = mUsbManager.openDevice(mUsbDevice); Log.d(TAG, "Claiming interfaces, count=" + mUsbDevice.getInterfaceCount()); mConnection.controlTransfer(0x21, 0x22, 0x1, 0, null, 0, 0); mControlInterface = mUsbDevice.getInterface(0); Log.d(TAG, "Control interface=" + mControlInterface); 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 = mUsbDevice.getInterface(1); Log.d(TAG, "data interface=" + mDataInterface); if (!mConnection.claimInterface(mDataInterface, true)) { throw new IOException("Could not claim data interface."); } mReadEndpoint = mDataInterface.getEndpoint(1); Log.d(TAG, "Read endpoint direction: " + mReadEndpoint.getDirection()); mWriteEndpoint = mDataInterface.getEndpoint(0); Log.d(TAG, "Write endpoint direction: " + mWriteEndpoint.getDirection()); connected = true; setBaudRate(1000000); //Thread.sleep(1000); clear(); }
/** * Enumerate the endpoints and interfaces on the connected device. * * @param device Device to query. * @return String description of the device configuration. */ public static String readDevice(UsbDevice device) { StringBuilder sb = new StringBuilder(); sb.append("Device Name: " + device.getDeviceName() + "\n"); sb.append(String.format( "Device Class: %s -> Subclass: 0x%02x -> Protocol: 0x%02x\n", nameForClass(device.getDeviceClass()), device.getDeviceSubclass(), device.getDeviceProtocol())); for (int i = 0; i < device.getInterfaceCount(); i++) { UsbInterface intf = device.getInterface(i); sb.append(String.format(Locale.US, "-- Interface %d Class: %s -> Subclass: 0x%02x -> Protocol: 0x%02x\n", intf.getId(), nameForClass(intf.getInterfaceClass()), intf.getInterfaceSubclass(), intf.getInterfaceProtocol())); sb.append(String.format(Locale.US, " -- Endpoint Count: %d\n", intf.getEndpointCount())); } return sb.toString(); }
if (iFace != null) { final TableLayout bottomTable = viewHolder.getBottomTable(); final String usbClass = UsbConstantResolver.resolveUsbClass((iFace.getInterfaceClass())); if (iFace.getEndpointCount() > 0) { String endpointText; for (int j = 0; j < iFace.getEndpointCount(); j++) { endpointText = getEndpointText(iFace.getEndpoint(j), j); addDataRow(inflater, bottomTable, getString(R.string.endpoint_), endpointText);
/** * Tests to see if a {@link android.hardware.usb.UsbDevice} * supports the PTP protocol (typically used by digital cameras) * * @param device the device to test * @return true if the device is a PTP device. */ static public boolean isCamera(UsbDevice device) { int count = device.getInterfaceCount(); for (int i = 0; i < count; i++) { UsbInterface intf = device.getInterface(i); if (intf.getInterfaceClass() == UsbConstants.USB_CLASS_STILL_IMAGE && intf.getInterfaceSubclass() == 1 && intf.getInterfaceProtocol() == 1) { return true; } } return false; }
public UsbInterfaceAssert hasId(int id) { isNotNull(); int actualId = actual.getId(); Assertions.assertThat(actualId) // .overridingErrorMessage("Expected id <%s> but was <%s>.", id, actualId) // .isEqualTo(id); return this; }
public UsbInterfaceAssert hasInterfaceSubclass(int subclass) { isNotNull(); int actualSubclass = actual.getInterfaceSubclass(); Assertions.assertThat(actualSubclass) // .overridingErrorMessage("Expected interface subclass <%s> but was <%s>.", subclass, actualSubclass) // .isEqualTo(subclass); return this; } }
if (mIntf.getEndpointCount() != 2) { Log.e(LOG_TAG, "Could not find endpoints"); return; UsbEndpoint ep = mIntf.getEndpoint(0); if (ep.getType() != UsbConstants.USB_ENDPOINT_XFER_BULK) { Log.e(LOG_TAG, "Endpoint is not of type bulk"); mEpIn = mIntf.getEndpoint(0); mEpOut = mIntf.getEndpoint(1); } else { mEpIn = mIntf.getEndpoint(1); mEpOut = mIntf.getEndpoint(0);
Log.i(logTag,"constructor: [interface 0] interface protocol: " + usbInterface.getInterfaceProtocol() + " subclass: " + usbInterface.getInterfaceSubclass()); Log.i(logTag,"constructor: [interface 0] interface class: " + usbInterface.getInterfaceClass()); Log.i(logTag,"constructor: [interface 0] endpoint count: " + usbInterface.getEndpointCount()); this.usbEndpointIN = usbInterface.getEndpoint(0); this.usbEndpointOUT = usbInterface.getEndpoint(1);
@Override public int write(byte[] src, int timeoutMillis) throws IOException { final UsbEndpoint endpoint = mDevice.getInterface(0).getEndpoint(1); int offset = 0; while (offset < src.length) { final int writeLength; final int amtWritten; synchronized (mWriteBufferLock) { final byte[] writeBuffer; writeLength = Math.min(src.length - offset, mWriteBuffer.length); if (offset == 0) { writeBuffer = src; } else { // bulkTransfer does not support offsets, make a copy. System.arraycopy(src, offset, mWriteBuffer, 0, writeLength); writeBuffer = mWriteBuffer; } amtWritten = mConnection.bulkTransfer(endpoint, writeBuffer, writeLength, timeoutMillis); } if (amtWritten <= 0) { throw new IOException("Error writing " + writeLength + " bytes at offset " + offset + " length=" + src.length); } Log.d(TAG, "Wrote amtWritten=" + amtWritten + " attempted=" + writeLength); offset += amtWritten; } return offset; }
for (int i = 0; i < count; i++) { UsbInterface intf = device.getInterface(i); if (matches(intf.getInterfaceClass(), intf.getInterfaceSubclass(), intf.getInterfaceProtocol())) { return true;
private byte[] getCTL() { byte[] data = new byte[2]; int response = connection.controlTransfer(XDCVCP_REQTYPE_DEVICE2HOST, XDCVCP_GET_LINE_CTL, 0, mInterface.getId(), data, data.length, USB_TIMEOUT ); Log.i(CLASS_ID,"Control Transfer Response: " + String.valueOf(response)); return data; }
public UsbInterfaceAssert hasInterfaceSubclass(int subclass) { isNotNull(); int actualSubclass = actual.getInterfaceSubclass(); Assertions.assertThat(actualSubclass) // .overridingErrorMessage("Expected interface subclass <%s> but was <%s>.", subclass, actualSubclass) // .isEqualTo(subclass); return this; } }
int endCount = mControlInterface.getEndpointCount(); Log.d(TAG,"not enough endpoints - need 3. count=" + mControlInterface.getEndpointCount()); throw new IOException("Insufficient number of endpoints(" + mControlInterface.getEndpointCount() + ")"); mWriteEndpoint = null; for (int i = 0; i < endCount; ++i) { UsbEndpoint ep = mControlInterface.getEndpoint(i); if ((ep.getDirection() == UsbConstants.USB_DIR_IN) && (ep.getType() == UsbConstants.USB_ENDPOINT_XFER_INT)) {
@Override public int write(byte[] src, int timeoutMillis) throws IOException { final UsbEndpoint endpoint = mDevice.getInterface(0).getEndpoint(1); int offset = 0; while (offset < src.length) { final int writeLength; final int amtWritten; synchronized (mWriteBufferLock) { final byte[] writeBuffer; writeLength = Math.min(src.length - offset, mWriteBuffer.length); if (offset == 0) { writeBuffer = src; } else { // bulkTransfer does not support offsets, make a copy. System.arraycopy(src, offset, mWriteBuffer, 0, writeLength); writeBuffer = mWriteBuffer; } amtWritten = mConnection.bulkTransfer(endpoint, writeBuffer, writeLength, timeoutMillis); } if (amtWritten <= 0) { throw new IOException("Error writing " + writeLength + " bytes at offset " + offset + " length=" + src.length); } Log.d(TAG, "Wrote amtWritten=" + amtWritten + " attempted=" + writeLength); offset += amtWritten; } return offset; }