Package jmri.util.usb
Class UsbUtil
java.lang.Object
jmri.util.usb.UsbUtil
USB utilities.
- Since:
- 4.9.6
-
Method Summary
Modifier and TypeMethodDescriptionstatic List<javax.usb.UsbDevice>Get all USB devices.static javax.usb.UsbInterfacegetDeviceInterface(javax.usb.UsbDevice device, byte index) Get USB device interface.static StringgetFullProductName(javax.usb.UsbDevice usbDevice) Get a USB device's full product (manufacturer + product) name.static StringgetLocation(javax.usb.UsbDevice usbDevice) Get a unique value that represents the device's location in the USB device topology.static javax.usb.UsbDevicegetMatchingDevice(short idVendor, short idProduct, String serialNumber, String idLocation) Get matching USB device.static List<javax.usb.UsbDevice>getMatchingDevices(short idVendor, short idProduct, String serialNumber) Get matching USB devices.static StringgetSerialNumber(javax.usb.UsbDevice usbDevice) Get a USB device's serial number.static voidreadMessage(javax.usb.UsbInterface iface, byte endPoint) Read message synchronously.static voidreadMessageAsynch(javax.usb.UsbInterface iface, byte endPoint) Read message asynchronously.
-
Method Details
-
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
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
Get a USB device's serial number.- Parameters:
usbDevice- the USB device to get the serial number of- Returns:
- serial number
-
getLocation
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
USBin 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
Read message synchronously.- Parameters:
iface- the interfaceendPoint- the end point
-
readMessageAsynch
Read message asynchronously.- Parameters:
iface- the interfaceendPoint- 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 deviceindex- the USB interface index- Returns:
- the USB interface
-