/** * Re-scans the bus for devices. <i>ScanForDevices()</i> is called automatically by <i>{@link * #open() open()}</i>. <i>You must terminate use of all USB devices before calling * scanForDevices()!</i> After calling <i>scanForDevices()</i> you can reestablish connections to * USB devices. * * @return This device manager, useful for chaining together multiple operations. * @throws OperationFailedException */ public USBDeviceManager scanForDevices() { if (isOpen()) { deviceList.clear(); final int MAX_DEVICES = 100; int devices[] = new int[1 + MAX_DEVICES * 2]; // device index-product ID pairs final int result = getDeviceByProductID(MIN_PRODUCT_ID, MAX_PRODUCT_ID, devices); // get all devices if (result != SUCCESS) throw new OperationFailedException(result); final int numDevices = devices[0]; for (int index = 0; index < numDevices; index++) { USBDevice device = null; final int deviceIndex = devices[1 + index * 2]; final int productID = devices[1 + index * 2 + 1]; if (USB_AI16_Family.isSupportedProductID(productID)) { device = new USB_AI16_Family(productID, deviceIndex); } else if (USB_AO16_Family.isSupportedProductID(productID)) { device = new USB_AO16_Family(productID, deviceIndex); } else if (USB_CTR_15_Family.isSupportedProductID(productID)) { device = new USB_CTR_15_Family(productID, deviceIndex); } else if (USB_DA12_8A_Family.isSupportedProductID(productID)) { device = new USB_DA12_8A_Family(productID, deviceIndex); } else if (USB_DA12_8E_Family.isSupportedProductID(productID)) { device = new USB_DA12_8E_Family(productID, deviceIndex); } else if (USB_DIO_16_Family.isSupportedProductID(productID)) { device = new USB_DIO_16_Family(productID, deviceIndex); } else if (USB_DIO_32_Family.isSupportedProductID(productID)) { device = new USB_DIO_32_Family(productID, deviceIndex); } else if (USB_DIO_Family.isSupportedProductID(productID)) { device = new USB_DIO_Family(productID, deviceIndex); } // else if( USB_DIO_Family.isSupportedProductID( ... if (device != null) deviceList.add(device); } // for( int index ... } else throw new OperationFailedException(MESSAGE_NOT_OPEN); return this; } // scanForDevices()
/** * "Closes" the USB device manager for use. When finished using the USB device manager, and * assuming <i>{@link #open() open()}</i> was properly called, <i>close()</i> must be called. * <i>Close()</i> terminates use of the underlying AIOUSB module and discards the list of devices * found. <i>You must terminate use of all USB devices before calling close()!</i> You can call * <i>open()</i> again to reinitialize things and reestablish connections to USB devices. * * @return This device manager, useful for chaining together multiple operations. * @throws OperationFailedException */ public USBDeviceManager close() { if (isOpen()) { deviceList.clear(); openStatus = 0; exit(); } else throw new OperationFailedException(MESSAGE_NOT_OPEN); return this; } // close()