java.lang.Object
net.codecrete.usb.USB
Provides access to USB devices.
-
Method Summary
Modifier and TypeMethodDescriptionGets a list of all connected USB devices.static USBDevicegetDevice(List<USBDevicePredicate> predicates) Gets the first connected USB device matching any of the specified predicates.static USBDevicegetDevice(USBDevicePredicate predicate) Gets the first connected USB device matching the specified predicate.getDevices(List<USBDevicePredicate> predicates) Gets a list of connected USB devices matching any of the specified predicates/filters.getDevices(USBDevicePredicate predicate) Gets a list of connected USB devices matching the specified predicate.static voidsetOnDeviceConnected(Consumer<USBDevice> handler) Sets the handler to be called when a USB device is connected.static voidsetOnDeviceDisconnected(Consumer<USBDevice> handler) Sets the handler to be called when a USB device is disconnected.
-
Method Details
-
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
Gets a list of connected USB devices matching the specified predicate.- Parameters:
predicate- device predicate/filter- Returns:
- list of USB devices
-
getDevices
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
Gets the first connected USB device matching the specified predicate.- Parameters:
predicate- device predicate/filter- Returns:
- USB device, or
nullif no device matches
-
getDevice
Gets the first connected USB device matching any of the specified predicates.- Parameters:
predicates- list of device predicates/filters- Returns:
- USB device, or
nullif no device matches
-
setOnDeviceConnected
Sets the handler to be called when a USB device is connected.- Parameters:
handler- handler function, ornullto remove a previous handler
-
setOnDeviceDisconnected
Sets the handler to be called when a USB device is disconnected.When the handler is called, the
USBDeviceinstance has already been closed. Descriptive information (such as vendor and product ID, serial number, interfaces, endpoints) can still be accessed.- Parameters:
handler- handler function, ornullto remove a previous handler
-