Package jmri.util.usb

Class UsbUtil

java.lang.Object
jmri.util.usb.UsbUtil

public final class UsbUtil extends Object
USB utilities.
Since:
4.9.6
  • Method Details

    • getAllDevices

      public static List<javax.usb.UsbDevice> getAllDevices()
      Get all USB devices.
      Returns:
      a list of all UsbDevice's
    • getMatchingDevices

      public static List<javax.usb.UsbDevice> getMatchingDevices(short idVendor, short idProduct, @CheckForNull String serialNumber)
      Get matching USB devices.
      Parameters:
      idVendor - the vendor id to match (zero matches any)
      idProduct - the product id to match (zero matches any)
      serialNumber - the serial number to match (null matches any)
      Returns:
      a list of matching UsbDevices
    • getMatchingDevice

      @CheckForNull public static javax.usb.UsbDevice getMatchingDevice(short idVendor, short idProduct, @CheckForNull String serialNumber, @Nonnull String idLocation)
      Get matching USB device.
      Parameters:
      idVendor - the vendor id to match (zero matches any)
      idProduct - the product id to match (zero matches any)
      serialNumber - the serial number to match (null matches any)
      idLocation - the location to match
      Returns:
      the matching UsbDevice or null if no match could be found
    • getFullProductName

      @CheckForNull public static String getFullProductName(@Nonnull javax.usb.UsbDevice usbDevice)
      Get a USB device's full product (manufacturer + product) name.
      Parameters:
      usbDevice - the USB device to get the full product name of
      Returns:
      the full product name or null if the product name is not encoded in the device
    • getSerialNumber

      @CheckForNull public static String getSerialNumber(@Nonnull javax.usb.UsbDevice usbDevice)
      Get a USB device's serial number.
      Parameters:
      usbDevice - the USB device to get the serial number of
      Returns:
      serial number
    • getLocation

      public static String getLocation(@Nonnull javax.usb.UsbDevice usbDevice)
      Get a unique value that represents the device's location in the USB device topology.

      The location is a series of USB ports separated by colons (:) starting from the root hub (a virtual hub maintained by the operating system), represented as USB in the location, passing through hubs (which may be virtual or physical), to the port the requested device is plugged into.

      Note: this method should only be used to uniquely identify USB devices in combination with consideration of the USB device product ID, vendor ID, and serial number, as using this alone could mean that two devices with the same product and vendor IDs, but different serial numbers could be misidentified if unplugged and reconnected in ports previously used by the other device, or if the hub does not consistently enumerate ports the same way.

      Parameters:
      usbDevice - the device to get the location of
      Returns:
      the location
    • readMessage

      public static void readMessage(@Nonnull javax.usb.UsbInterface iface, byte endPoint)
      Read message synchronously.
      Parameters:
      iface - the interface
      endPoint - the end point
    • readMessageAsynch

      public static void readMessageAsynch(@Nonnull javax.usb.UsbInterface iface, byte endPoint)
      Read message asynchronously.
      Parameters:
      iface - the interface
      endPoint - the end point
    • getDeviceInterface

      public static javax.usb.UsbInterface getDeviceInterface(@Nonnull javax.usb.UsbDevice device, byte index)
      Get USB device interface.
      Parameters:
      device - the USB device
      index - the USB interface index
      Returns:
      the USB interface