Class USB

java.lang.Object
net.codecrete.usb.USB

public class USB extends Object
Provides access to USB devices.
  • Method Details

    • getAllDevices

      public static List<USBDevice> getAllDevices()
      Gets a list of all connected USB devices.

      Depending on the operating system, the list might or might not include USB hubs and USB host controllers.

      Returns:
      list of USB devices
    • getDevices

      public static List<USBDevice> getDevices(USBDevicePredicate predicate)
      Gets a list of connected USB devices matching the specified predicate.
      Parameters:
      predicate - device predicate/filter
      Returns:
      list of USB devices
    • getDevices

      public static List<USBDevice> getDevices(List<USBDevicePredicate> predicates)
      Gets a list of connected USB devices matching any of the specified predicates/filters.
      Parameters:
      predicates - list of device predicates/filters
      Returns:
      list of USB devices
    • getDevice

      public static USBDevice getDevice(USBDevicePredicate predicate)
      Gets the first connected USB device matching the specified predicate.
      Parameters:
      predicate - device predicate/filter
      Returns:
      USB device, or null if no device matches
    • getDevice

      public static USBDevice getDevice(List<USBDevicePredicate> predicates)
      Gets the first connected USB device matching any of the specified predicates.
      Parameters:
      predicates - list of device predicates/filters
      Returns:
      USB device, or null if no device matches
    • setOnDeviceConnected

      public static void setOnDeviceConnected(Consumer<USBDevice> handler)
      Sets the handler to be called when a USB device is connected.
      Parameters:
      handler - handler function, or null to remove a previous handler
    • setOnDeviceDisconnected

      public static void setOnDeviceDisconnected(Consumer<USBDevice> handler)
      Sets the handler to be called when a USB device is disconnected.

      When the handler is called, the USBDevice instance has already been closed. Descriptive information (such as vendor and product ID, serial number, interfaces, endpoints) can still be accessed.

      Parameters:
      handler - handler function, or null to remove a previous handler