Package jmri.util.usb

Class UsbUtil


  • public final class UsbUtil
    extends java.lang.Object
    USB utilities.
    Since:
    4.9.6
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.util.List<javax.usb.UsbDevice> getAllDevices()
      Get all USB devices.
      static javax.usb.UsbInterface getDeviceInterface​(javax.usb.UsbDevice device, byte index)
      Get USB device interface.
      static java.lang.String getFullProductName​(javax.usb.UsbDevice usbDevice)
      Get a USB device's full product (manufacturer + product) name.
      static java.lang.String getLocation​(javax.usb.UsbDevice usbDevice)
      Get a unique value that represents the device's location in the USB device topology.
      static javax.usb.UsbDevice getMatchingDevice​(short idVendor, short idProduct, java.lang.String serialNumber, java.lang.String idLocation)
      Get matching USB device.
      static java.util.List<javax.usb.UsbDevice> getMatchingDevices​(short idVendor, short idProduct, java.lang.String serialNumber)
      Get matching USB devices.
      static java.lang.String getSerialNumber​(javax.usb.UsbDevice usbDevice)
      Get a USB device's serial number.
      static void readMessage​(javax.usb.UsbInterface iface, byte endPoint)
      Read message synchronously.
      static void readMessageAsynch​(javax.usb.UsbInterface iface, byte endPoint)
      Read message asynchronously.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • getAllDevices

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

        public static java.util.List<javax.usb.UsbDevice> getMatchingDevices​(short idVendor,
                                                                             short idProduct,
                                                                             @CheckForNull
                                                                             java.lang.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
                                                            java.lang.String serialNumber,
                                                            @Nonnull
                                                            java.lang.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 java.lang.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 java.lang.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 java.lang.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