private static int countPorts(UsbDevice device) {
        int controlInterfaceCount = 0;
        int dataInterfaceCount = 0;
        for (int i = 0; i < device.getInterfaceCount(); i++) {
            if (device.getInterface(i).getInterfaceClass() == UsbConstants.USB_CLASS_COMM &&
                    device.getInterface(i).getInterfaceSubclass() == USB_SUBCLASS_ACM)
                controlInterfaceCount++;
            if (device.getInterface(i).getInterfaceClass() == UsbConstants.USB_CLASS_CDC_DATA)
                dataInterfaceCount++;
        }
        return Math.min(controlInterfaceCount, dataInterfaceCount);
    }
USB CDC/ACM serial driver implementation.

@author mike wakerly (opensource@hoho.com)
@see <a
     href="http://www.usb.org/developers/devclass_docs/usbcdc11.pdf">Universal
     Serial Bus Class Definitions for Communication Devices, v1.1</a>
usbSerialForAndroid/src/main/java/com/hoho/android/usbserial/driver/CdcAcmSerialDriver.java