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(USBDeviceFilter filter)
      Gets a list of connected USB devices matching the specified filter.
      Parameters:
      filter - device filter
      Returns:
      list of USB devices
    • getDevices

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

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

      public static USBDevice getDevice(List<USBDeviceFilter> filters)
      Gets the first connected USB device matching any of the specified filters.
      Parameters:
      filters - list of device 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.
      Parameters:
      handler - handler function, or null to remove a previous handler