Java Code Examples for android.hardware.usb.UsbConstants#USB_CLASS_CDC_DATA

The following examples show how to use android.hardware.usb.UsbConstants#USB_CLASS_CDC_DATA . 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: CdcAcmSerialDriver.java    From usb-serial-for-android with GNU Lesser General Public License v2.1 6 votes vote down vote up
public CdcAcmSerialDriver(UsbDevice device) {
    mDevice = device;
    mPorts = new ArrayList<>();

    int controlInterfaceCount = 0;
    int dataInterfaceCount = 0;
    for( int i = 0; i < device.getInterfaceCount(); i++) {
        if(device.getInterface(i).getInterfaceClass() == UsbConstants.USB_CLASS_COMM)
            controlInterfaceCount++;
        if(device.getInterface(i).getInterfaceClass() == UsbConstants.USB_CLASS_CDC_DATA)
            dataInterfaceCount++;
    }
    for( int port = 0; port < Math.min(controlInterfaceCount, dataInterfaceCount); port++) {
        mPorts.add(new CdcAcmSerialPort(mDevice, port));
    }
    if(mPorts.size() == 0) {
        mPorts.add(new CdcAcmSerialPort(mDevice, -1));
    }
}
 
Example 2
Source File: UsbHelper.java    From sample-usbenum with Apache License 2.0 5 votes vote down vote up
public static String nameForClass(int classType) {
    switch (classType) {
        case UsbConstants.USB_CLASS_APP_SPEC:
            return String.format("Application Specific 0x%02x", classType);
        case UsbConstants.USB_CLASS_AUDIO:
            return "Audio";
        case UsbConstants.USB_CLASS_CDC_DATA:
            return "CDC Control";
        case UsbConstants.USB_CLASS_COMM:
            return "Communications";
        case UsbConstants.USB_CLASS_CONTENT_SEC:
            return "Content Security";
        case UsbConstants.USB_CLASS_CSCID:
            return "Content Smart Card";
        case UsbConstants.USB_CLASS_HID:
            return "Human Interface Device";
        case UsbConstants.USB_CLASS_HUB:
            return "Hub";
        case UsbConstants.USB_CLASS_MASS_STORAGE:
            return "Mass Storage";
        case UsbConstants.USB_CLASS_MISC:
            return "Wireless Miscellaneous";
        case UsbConstants.USB_CLASS_PER_INTERFACE:
            return "(Defined Per Interface)";
        case UsbConstants.USB_CLASS_PHYSICA:
            return "Physical";
        case UsbConstants.USB_CLASS_PRINTER:
            return "Printer";
        case UsbConstants.USB_CLASS_STILL_IMAGE:
            return "Still Image";
        case UsbConstants.USB_CLASS_VENDOR_SPEC:
            return String.format("Vendor Specific 0x%02x", classType);
        case UsbConstants.USB_CLASS_VIDEO:
            return "Video";
        case UsbConstants.USB_CLASS_WIRELESS_CONTROLLER:
            return "Wireless Controller";
        default:
            return String.format("0x%02x", classType);
    }
}
 
Example 3
Source File: UsbUtils.java    From FireFiles with Apache License 2.0 5 votes vote down vote up
private static String nameForClass(UsbDevice usbDevice) {
    int classType = usbDevice.getDeviceClass();
    switch (classType) {
        case UsbConstants.USB_CLASS_AUDIO:
            return "Audio";
        case UsbConstants.USB_CLASS_CDC_DATA:
            return "CDC Control";
        case UsbConstants.USB_CLASS_COMM:
            return "Communications";
        case UsbConstants.USB_CLASS_CONTENT_SEC:
            return "Content Security";
        case UsbConstants.USB_CLASS_CSCID:
            return "Content Smart Card";
        case UsbConstants.USB_CLASS_HID:
            return "Human Interface Device";
        case UsbConstants.USB_CLASS_HUB:
            return "Hub";
        case UsbConstants.USB_CLASS_MASS_STORAGE:
            return "Mass Storage";
        case UsbConstants.USB_CLASS_MISC:
            return "Wireless Miscellaneous";
        case UsbConstants.USB_CLASS_PHYSICA:
            return "Physical";
        case UsbConstants.USB_CLASS_PRINTER:
            return "Printer";
        case UsbConstants.USB_CLASS_STILL_IMAGE:
            return "Still Image";
        case UsbConstants.USB_CLASS_VENDOR_SPEC:
            return String.format("Vendor Specific 0x%02x", classType);
        case UsbConstants.USB_CLASS_VIDEO:
            return "Video";
        case UsbConstants.USB_CLASS_WIRELESS_CONTROLLER:
            return "Wireless Controller";
        default:
            return "";
    }
}
 
Example 4
Source File: UsbUtils.java    From FireFiles with Apache License 2.0 5 votes vote down vote up
private static String nameForClass(UsbDevice usbDevice) {
    int classType = usbDevice.getDeviceClass();
    switch (classType) {
        case UsbConstants.USB_CLASS_AUDIO:
            return "Audio";
        case UsbConstants.USB_CLASS_CDC_DATA:
            return "CDC Control";
        case UsbConstants.USB_CLASS_COMM:
            return "Communications";
        case UsbConstants.USB_CLASS_CONTENT_SEC:
            return "Content Security";
        case UsbConstants.USB_CLASS_CSCID:
            return "Content Smart Card";
        case UsbConstants.USB_CLASS_HID:
            return "Human Interface Device";
        case UsbConstants.USB_CLASS_HUB:
            return "Hub";
        case UsbConstants.USB_CLASS_MASS_STORAGE:
            return "Mass Storage";
        case UsbConstants.USB_CLASS_MISC:
            return "Wireless Miscellaneous";
        case UsbConstants.USB_CLASS_PHYSICA:
            return "Physical";
        case UsbConstants.USB_CLASS_PRINTER:
            return "Printer";
        case UsbConstants.USB_CLASS_STILL_IMAGE:
            return "Still Image";
        case UsbConstants.USB_CLASS_VENDOR_SPEC:
            return String.format("Vendor Specific 0x%02x", classType);
        case UsbConstants.USB_CLASS_VIDEO:
            return "Video";
        case UsbConstants.USB_CLASS_WIRELESS_CONTROLLER:
            return "Wireless Controller";
        default:
            return "";
    }
}
 
Example 5
Source File: UsbUtils.java    From FireFiles with Apache License 2.0 5 votes vote down vote up
private static String nameForClass(UsbDevice usbDevice) {
    int classType = usbDevice.getDeviceClass();
    switch (classType) {
        case UsbConstants.USB_CLASS_AUDIO:
            return "Audio";
        case UsbConstants.USB_CLASS_CDC_DATA:
            return "CDC Control";
        case UsbConstants.USB_CLASS_COMM:
            return "Communications";
        case UsbConstants.USB_CLASS_CONTENT_SEC:
            return "Content Security";
        case UsbConstants.USB_CLASS_CSCID:
            return "Content Smart Card";
        case UsbConstants.USB_CLASS_HID:
            return "Human Interface Device";
        case UsbConstants.USB_CLASS_HUB:
            return "Hub";
        case UsbConstants.USB_CLASS_MASS_STORAGE:
            return "Mass Storage";
        case UsbConstants.USB_CLASS_MISC:
            return "Wireless Miscellaneous";
        case UsbConstants.USB_CLASS_PHYSICA:
            return "Physical";
        case UsbConstants.USB_CLASS_PRINTER:
            return "Printer";
        case UsbConstants.USB_CLASS_STILL_IMAGE:
            return "Still Image";
        case UsbConstants.USB_CLASS_VENDOR_SPEC:
            return String.format("Vendor Specific 0x%02x", classType);
        case UsbConstants.USB_CLASS_VIDEO:
            return "Video";
        case UsbConstants.USB_CLASS_WIRELESS_CONTROLLER:
            return "Wireless Controller";
        default:
            return "";
    }
}
 
Example 6
Source File: UsbSerialDevice.java    From UsbSerial with MIT License 5 votes vote down vote up
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;
}
 
Example 7
Source File: CDCSerialDevice.java    From UsbSerial with MIT License 5 votes vote down vote up
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;
}
 
Example 8
Source File: CdcAcmSerialDriver.java    From usb-serial-for-android with GNU Lesser General Public License v2.1 4 votes vote down vote up
private void openInterface() throws IOException {
    Log.d(TAG, "claiming interfaces, count=" + mDevice.getInterfaceCount());

    int controlInterfaceCount = 0;
    int dataInterfaceCount = 0;
    mControlInterface = null;
    mDataInterface = null;
    for (int i = 0; i < mDevice.getInterfaceCount(); i++) {
        UsbInterface usbInterface = mDevice.getInterface(i);
        if (usbInterface.getInterfaceClass() == UsbConstants.USB_CLASS_COMM) {
            if(controlInterfaceCount == mPortNumber) {
                mControlIndex = i;
                mControlInterface = usbInterface;
            }
            controlInterfaceCount++;
        }
        if (usbInterface.getInterfaceClass() == UsbConstants.USB_CLASS_CDC_DATA) {
            if(dataInterfaceCount == mPortNumber) {
                mDataInterface = usbInterface;
            }
            dataInterfaceCount++;
        }
    }

    if(mControlInterface == null) {
        throw new IOException("No control interface");
    }
    Log.d(TAG, "Control iface=" + mControlInterface);

    if (!mConnection.claimInterface(mControlInterface, true)) {
        throw new IOException("Could not claim control interface");
    }

    mControlEndpoint = mControlInterface.getEndpoint(0);
    if (mControlEndpoint.getDirection() != UsbConstants.USB_DIR_IN || mControlEndpoint.getType() != UsbConstants.USB_ENDPOINT_XFER_INT) {
        throw new IOException("Invalid control endpoint");
    }

    if(mDataInterface == null) {
        throw new IOException("No data interface");
    }
    Log.d(TAG, "data iface=" + mDataInterface);

    if (!mConnection.claimInterface(mDataInterface, true)) {
        throw new IOException("Could not claim data interface");
    }

    for (int i = 0; i < mDataInterface.getEndpointCount(); i++) {
        UsbEndpoint ep = mDataInterface.getEndpoint(i);
        if (ep.getDirection() == UsbConstants.USB_DIR_IN && ep.getType() == UsbConstants.USB_ENDPOINT_XFER_BULK)
            mReadEndpoint = ep;
        if (ep.getDirection() == UsbConstants.USB_DIR_OUT && ep.getType() == UsbConstants.USB_ENDPOINT_XFER_BULK)
            mWriteEndpoint = ep;
    }
}