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(); }
public XdcVcpSerialDevice(UsbDevice device, UsbDeviceConnection connection, int iface) { super(device, connection); mInterface = device.getInterface(iface >= 0 ? iface : 0); }
public static boolean isCdcDevice(UsbDevice device) { int iIndex = device.getInterfaceCount(); for(int i=0;i<=iIndex-1;i++) { UsbInterface iface = device.getInterface(i); if(iface.getInterfaceClass() == UsbConstants.USB_CLASS_CDC_DATA) return true; } return false; }
public CP2130SpiDevice(UsbDevice device, UsbDeviceConnection connection, int iface) { super(device, connection); mInterface = device.getInterface(iface >= 0 ? iface : 0); currentChannel = 0; }
private static int findFirstCDC(UsbDevice device) { int interfaceCount = device.getInterfaceCount(); for (int iIndex = 0; iIndex < interfaceCount; ++iIndex) { if (device.getInterface(iIndex).getInterfaceClass() == UsbConstants.USB_CLASS_CDC_DATA) { return iIndex; } } Log.i(CLASS_ID, "There is no CDC class interface"); return -1; }
public CH34xSerialDevice(UsbDevice device, UsbDeviceConnection connection, int iface) { super(device, connection); rtsCtsEnabled = false; dtrDsrEnabled = false; mInterface = device.getInterface(iface >= 0 ? iface : 0); }
private UsbMidiDevice(UsbDevice device) { super(device); int ifaceCount = device.getInterfaceCount(); for (int i = 0; i < ifaceCount; ++i) { UsbMidiInterface iface = asMidiInterface(device.getInterface(i)); if (iface != null) { interfaces.add(iface); } } }
public CP2102SerialDevice(UsbDevice device, UsbDeviceConnection connection, int iface) { super(device, connection); rtsCtsEnabled = false; dtrDsrEnabled = false; ctsState = true; dsrState = true; mInterface = device.getInterface(iface >= 0 ? iface : 0); }
/** * Find {@link UsbInterface} from {@link UsbDevice} with the direction * * @param usbDevice the UsbDevice * @param direction {@link UsbConstants#USB_DIR_IN} or {@link UsbConstants#USB_DIR_OUT} * @param deviceFilters the List of {@link DeviceFilter} * @return {@link Set<UsbInterface>} always not null */ @NonNull public static Set<UsbInterface> findMidiInterfaces(@NonNull UsbDevice usbDevice, int direction, @NonNull List<DeviceFilter> deviceFilters) { Set<UsbInterface> usbInterfaces = new HashSet<>(); int count = usbDevice.getInterfaceCount(); for (int i = 0; i < count; i++) { UsbInterface usbInterface = usbDevice.getInterface(i); if (findMidiEndpoint(usbDevice, usbInterface, direction, deviceFilters) != null) { usbInterfaces.add(usbInterface); } } return Collections.unmodifiableSet(usbInterfaces); }
@Deprecated public BLED112SerialDevice(UsbDevice device, UsbDeviceConnection connection) { super(device, connection); mInterface = device.getInterface(1); // BLED112 Interface 0: Communications | Interface 1: CDC Data }
/** * Find all {@link UsbInterface} from {@link UsbDevice} * * @param usbDevice the UsbDevice * @param deviceFilters the List of {@link DeviceFilter} * @return {@link Set<UsbInterface>} always not null */ @NonNull public static Set<UsbInterface> findAllMidiInterfaces(@NonNull UsbDevice usbDevice, @NonNull List<DeviceFilter> deviceFilters) { Set<UsbInterface> usbInterfaces = new HashSet<>(); int count = usbDevice.getInterfaceCount(); for (int i = 0; i < count; i++) { UsbInterface usbInterface = usbDevice.getInterface(i); if (findMidiEndpoint(usbDevice, usbInterface, UsbConstants.USB_DIR_IN, deviceFilters) != null) { usbInterfaces.add(usbInterface); } if (findMidiEndpoint(usbDevice, usbInterface, UsbConstants.USB_DIR_OUT, deviceFilters) != null) { usbInterfaces.add(usbInterface); } } return Collections.unmodifiableSet(usbInterfaces); }
public PL2303SerialDevice(UsbDevice device, UsbDeviceConnection connection, int iface) { super(device, connection); if (iface > 1) { throw new IllegalArgumentException("Multi-interface PL2303 devices not supported!"); } mInterface = device.getInterface(iface >= 0 ? iface : 0); }
/** * 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 FTDISerialDevice(UsbDevice device, UsbDeviceConnection connection, int iface) { super(device, connection); ftdiUtilities = new FTDIUtilities(); rtsCtsEnabled = false; dtrDsrEnabled = false; ctsState = true; dsrState = true; firstTime = true; mInterface = device.getInterface(iface >= 0 ? iface : 0); }
private void openInterface() throws IOException { Log.d(TAG, "claiming interfaces, count=" + mDevice.getInterfaceCount()); 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); Log.d(TAG, "Read endpoint direction: " + mReadEndpoint.getDirection()); mWriteEndpoint = mDataInterface.getEndpoint(0); Log.d(TAG, "Write endpoint direction: " + mWriteEndpoint.getDirection()); }
public CDCSerialDevice(UsbDevice device, UsbDeviceConnection connection, int iface) { super(device, connection); mInterface = device.getInterface(iface >= 0 ? iface : findFirstCDC(device)); }
private void openInterface() throws IOException { Log.d(TAG, "claiming interfaces, count=" + mDevice.getInterfaceCount()); 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); Log.d(TAG, "Read endpoint direction: " + mReadEndpoint.getDirection()); mWriteEndpoint = mDataInterface.getEndpoint(0); Log.d(TAG, "Write endpoint direction: " + mWriteEndpoint.getDirection()); }
/** * Stops listening on all inputs and closes the current USB connection, if any. */ @Override public synchronized void close() { if (connection == null) return; for (UsbMidiInterface iface : interfaces) { iface.stop(); connection.releaseInterface(iface.getInterface()); } connection.close(); connection = null; }
@Override public void onConnect() { int ifIdx = 0; UsbInterface iface = usbDevice.getInterface(ifIdx); if (usbConnection.claimInterface(iface, true)) { logger.log("Interface claimed successfully\n"); } else { logger.log("ERROR - can't claim interface\n"); } super.onConnect(); }
@Override public void onConnect() { // Serial mode only // TODO: find the interface and endpoint indexes no matter what mode it is int ifIdx = 1; int epInIdx = 1; int epOutIdx = 0; UsbInterface iface = usbDevice.getInterface(ifIdx); if (usbConnection.claimInterface(iface, true)) { logger.log("Interface claimed successfully\n"); } else { logger.log("ERROR - can't claim interface\n"); return; } endpointIn = iface.getEndpoint(epInIdx); endpointOut = iface.getEndpoint(epOutIdx); super.onConnect(); }