Ejemplo n.º 1
0
 /**
  * Gets a list of all the devices found on the bus matching the specified serial number. Only
  * devices exactly matching the specified serial number will be returned. In theory, there ought
  * to be only one device matching a given serial number, but this method returns a vector in order
  * to be consistent with the other search methods, and in unlikely event that multiple devices do
  * share the same serial number.
  *
  * @param serialNumber the serial number to search for.
  * @return An array of all the devices found. If no devices were found matching the specified
  *     serial number, the array will be empty (i.e. contain zero items).
  */
 public USBDevice[] getDeviceBySerialNumber(long serialNumber) {
   Vector<USBDevice> devices = new Vector<USBDevice>();
   for (int index = 0; index < deviceList.size(); index++) {
     if (deviceList.get(index).getSerialNumber() == serialNumber)
       devices.add(deviceList.get(index));
   } // for( int index ...
   return devices.toArray(new USBDevice[0]);
 } // getDeviceBySerialNumber()
Ejemplo n.º 2
0
 /**
  * Gets a list of all the devices found on the bus matching the specified product ID range. Any
  * device with a product ID greater than or equal to <i>minProductID</i> and less than or equal to
  * <i>maxProductID</i> will be returned. You can obtain the entire list of devices detected by
  * passing a value of 0 for <i>minProductID</i> and a value of 0xffff for <i>maxProductID</i>.
  * Then you can search the list obtained using your own search criteria.
  *
  * @param minProductID the minimum product ID to search for.
  * @param maxProductID the maximum product ID to search for.
  * @return An array of all the devices found. If no devices were found matching the specified
  *     product ID range, the array will be empty (i.e. contain zero items).
  * @throws IllegalArgumentException
  */
 public USBDevice[] getDeviceByProductID(int minProductID, int maxProductID) {
   if (minProductID < MIN_PRODUCT_ID
       || minProductID > MAX_PRODUCT_ID
       || maxProductID < minProductID
       || maxProductID > MAX_PRODUCT_ID)
     throw new IllegalArgumentException(
         "Invalid product IDs: " + minProductID + ", " + maxProductID);
   Vector<USBDevice> devices = new Vector<USBDevice>();
   for (int index = 0; index < deviceList.size(); index++) {
     final int productID = deviceList.get(index).getProductID();
     if (productID >= minProductID && productID <= maxProductID)
       devices.add(deviceList.get(index));
   } // for( int index ...
   return devices.toArray(new USBDevice[0]);
 } // getDeviceByProductID()
Ejemplo n.º 3
0
 /**
  * Gets a list of all the devices found on the bus matching the specified set of product IDs. Any
  * device with a product ID equal to one of the products listed in <i>productIDs[]</i> will be
  * returned. You can search for devices by product name using {@link #productNameToID( String[]
  * productName ) productNameToID()}, like so:
  *
  * <pre>USBDevice[] devices = deviceManager.getDeviceByProductID(
  *  deviceManager.productNameToID( new String[] { "USB-AO16-16A", "USB-AO16-16" } ) );</pre>
  *
  * @param productIDs an array containing one or more product IDs to search for.
  * @return An array of all the devices found. If no devices were found matching the specified set
  *     of product IDs, the array will be empty (i.e. contain zero items).
  * @throws IllegalArgumentException
  */
 public USBDevice[] getDeviceByProductID(int[] productIDs) {
   if (productIDs == null || productIDs.length < 1)
     throw new IllegalArgumentException("Invalid product ID array");
   for (int index = 0; index < productIDs.length; index++) {
     if (productIDs[index] < MIN_PRODUCT_ID || productIDs[index] > MAX_PRODUCT_ID)
       throw new IllegalArgumentException("Invalid product ID: " + productIDs[index]);
   } // for( int index ...
   int[] sortedProductIDs = productIDs.clone();
   Arrays.sort(sortedProductIDs);
   Vector<USBDevice> devices = new Vector<USBDevice>();
   for (int index = 0; index < deviceList.size(); index++) {
     final int productID = deviceList.get(index).getProductID();
     if (Arrays.binarySearch(sortedProductIDs, productID) >= 0) devices.add(deviceList.get(index));
   } // for( int index ...
   return devices.toArray(new USBDevice[0]);
 } // getDeviceByProductID()