Tabnine Logo
UsbDevice.getInterface
Code IndexAdd Tabnine to your IDE (free)

How to use
getInterface
method
in
android.hardware.usb.UsbDevice

Best Java code snippets using android.hardware.usb.UsbDevice.getInterface (Showing top 20 results out of 315)

origin: fossasia/pslab-android

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();
}
origin: felHR85/UsbSerial

public XdcVcpSerialDevice(UsbDevice device, UsbDeviceConnection connection, int iface)
{
  super(device, connection);
  mInterface = device.getInterface(iface >= 0 ? iface : 0);
}
origin: felHR85/UsbSerial

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;
}
origin: felHR85/UsbSerial

public CP2130SpiDevice(UsbDevice device, UsbDeviceConnection connection, int iface)
{
  super(device, connection);
  mInterface = device.getInterface(iface >= 0 ? iface : 0);
  currentChannel = 0;
}
origin: felHR85/UsbSerial

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;
}
origin: felHR85/UsbSerial

public CH34xSerialDevice(UsbDevice device, UsbDeviceConnection connection, int iface)
{
  super(device, connection);
  rtsCtsEnabled = false;
  dtrDsrEnabled = false;
  mInterface = device.getInterface(iface >= 0 ? iface : 0);
}
origin: nettoyeurny/btmidi

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);
  }
 }
}
origin: felHR85/UsbSerial

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);
}
origin: kshoji/USB-MIDI-Driver

/**
 * 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);
}

origin: felHR85/UsbSerial

@Deprecated
public BLED112SerialDevice(UsbDevice device, UsbDeviceConnection connection)
{
  super(device, connection);
  mInterface = device.getInterface(1); // BLED112 Interface 0: Communications | Interface 1: CDC Data
}
origin: kshoji/USB-MIDI-Driver

/**
 * 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);
}
origin: felHR85/UsbSerial

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);
}
origin: grzegorznittner/chanu

/**
 * 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;
}
origin: felHR85/UsbSerial

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);
}
origin: voroshkov/Chorus-RF-Laptimer

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());
}
origin: felHR85/UsbSerial

public CDCSerialDevice(UsbDevice device, UsbDeviceConnection connection, int iface)
{
  super(device, connection);
  mInterface = device.getInterface(iface >= 0 ? iface : findFirstCDC(device));
}
origin: zhouzhuo810/OkUSB

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());
}
origin: nettoyeurny/btmidi

/**
 * 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;
}
origin: google/walt

@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();
}
origin: google/walt

@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();
}
android.hardware.usbUsbDevicegetInterface

Popular methods of UsbDevice

  • getVendorId
  • getProductId
  • getDeviceName
  • getInterfaceCount
  • getDeviceClass
  • getDeviceId
  • getDeviceSubclass
  • getDeviceProtocol
  • equals
  • getProductName
  • getManufacturerName
  • toString
  • getManufacturerName,
  • toString,
  • getConfiguration,
  • getConfigurationCount

Popular in Java

  • Start an intent from android
  • scheduleAtFixedRate (Timer)
  • compareTo (BigDecimal)
  • startActivity (Activity)
  • Kernel (java.awt.image)
  • Timer (java.util)
    Timers schedule one-shot or recurring TimerTask for execution. Prefer java.util.concurrent.Scheduled
  • Modifier (javassist)
    The Modifier class provides static methods and constants to decode class and member access modifiers
  • JTextField (javax.swing)
  • Get (org.apache.hadoop.hbase.client)
    Used to perform Get operations on a single row. To get everything for a row, instantiate a Get objec
  • Location (org.springframework.beans.factory.parsing)
    Class that models an arbitrary location in a Resource.Typically used to track the location of proble
  • From CI to AI: The AI layer in your organization
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now