{
UsbHub virtualRootUsbHub = UsbHostManager.getUsbServices().getRootUsbHub();
if (virtualRootUsbHub == null)
{
throw new CM19AException("No virtual root usb hub found");
}
/* Find the attached CM19a */
UsbDevice cm19a = findDevice(virtualRootUsbHub);
if (cm19a == null)
{
throw new CM19AException("No CM19a found; /dev/bus/usb permissions problem?");
}
if (logger.isDebugEnabled())
{
StringBuilder builder = new StringBuilder("Device found and configured is ");
if (!cm19a.isConfigured())
{
builder.append("not");
}
builder.append(" configured");
logger.debug(builder.toString());
}
UsbConfiguration config = cm19a.getActiveUsbConfiguration();
if (config == null)
{
throw new CM19AException("No active configuration found");
}
/* Get the first interface, there should only be one */
UsbInterface usbInterface = (UsbInterface) config.getUsbInterfaces().get(0);
logger.debug("Got device; Manufacturer is " + cm19a.getManufacturerString());
logger.debug("Got interface; Active is " + usbInterface.isActive() + " Claimed is " + usbInterface.isClaimed());
try
{
usbInterface.claim();
logger.debug("Interface has been claimed");
}
catch (UsbException ue)
{
throw new CM19AException("Couldn't claim interface. " + "Message is " + ue.getMessage());
}
return new UsbInterfaceInfos(usbInterface);
}