本文整理汇总了Java中javax.usb.UsbHub类的典型用法代码示例。如果您正苦于以下问题:Java UsbHub类的具体用法?Java UsbHub怎么用?Java UsbHub使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
UsbHub类属于javax.usb包,在下文中一共展示了UsbHub类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initialize
import javax.usb.UsbHub; //导入依赖的package包/类
protected void initialize() throws SecurityException, UsbException {
UsbServices services = UsbHostManager.getUsbServices();
UsbHub usbHub = services.getRootUsbHub();
UsbDevice theDevice = findDevice(usbHub, targetVendor, targetProduct);
if (theDevice == null) {
logger.warn("Could not find the device. The driver is not operable.");
return;
}
for (Object i : theDevice.getActiveUsbConfiguration().getUsbInterfaces()) {
UsbInterface intf = (UsbInterface) i;
for (Object e : intf.getUsbEndpoints()) {
UsbEndpoint endp = (UsbEndpoint) e;
if (endp.getDirection() == UsbConst.ENDPOINT_DIRECTION_IN) {
this.pipe = endp.getUsbPipe();
}
}
}
}
示例2: find
import javax.usb.UsbHub; //导入依赖的package包/类
/**
* Find the device with vendorId and productId
*
* @param hub
* @param vendorId
* @param productId
* @return USB device or null if not found.
*/
private static UsbDevice find(UsbHub hub, short vendorId, short productId) {
UsbDevice launcher = null;
for (UsbDevice device : (List<UsbDevice>) hub.getAttachedUsbDevices()) {
if (device.isUsbHub()) {
launcher = find((UsbHub) device, vendorId, productId);
if (launcher != null)
return launcher;
} else {
UsbDeviceDescriptor desc = device.getUsbDeviceDescriptor();
if (desc.idVendor() == vendorId && desc.idProduct() == productId)
return device;
}
}
return null;
}
示例3: findUsbDevices
import javax.usb.UsbHub; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public static List<UsbDevice> findUsbDevices(UsbHub hub, short vendorId, short productId) {
List<UsbDevice> usbDeviceList = new ArrayList<UsbDevice>();
if (hub != null) {
for (UsbDevice device : (List<UsbDevice>) hub.getAttachedUsbDevices()) {
UsbDeviceDescriptor desc = device.getUsbDeviceDescriptor();
if (desc.idVendor() == vendorId && desc.idProduct() == productId){
mLogger.debug("Found USB device!");
usbDeviceList.add(device);
}
if (device.isUsbHub()) {
usbDeviceList.addAll(findUsbDevices((UsbHub) device, vendorId, productId));
}
}
}
return usbDeviceList;
}
示例4: findUsb
import javax.usb.UsbHub; //导入依赖的package包/类
private static UsbDevice findUsb(UsbHub hub) {
UsbDevice launcher = null;
for (UsbDevice device: (List<UsbDevice>) hub.getAttachedUsbDevices()) {
if (device.isUsbHub()) {
launcher = findUsb((UsbHub) device);
if (launcher != null) return launcher;
} else {
UsbDeviceDescriptor desc = device.getUsbDeviceDescriptor();
System.out.println("Found on USB: idVendor: "+desc.idVendor()+", idProduct: "+desc.idProduct());
if (desc.idVendor() == VENDOR_ID && desc.idProduct() == product_id) {
System.out.println("Got our printer.");
return device;
}
}
}
return null;
}
示例5: findScale
import javax.usb.UsbHub; //导入依赖的package包/类
public static Scale findScale() {
try {
UsbServices services = UsbHostManager.getUsbServices();
UsbHub rootHub = services.getRootUsbHub();
// Dymo M10 Scale:
UsbDevice device = findDevice(rootHub, (short) 0x0922, (short) 0x8003);
// Dymo M25 Scale:
if (device == null) {
device = findDevice(rootHub, (short) 0x0922, (short) 0x8004);
}
if (device == null) {
return null;
}
return new UsbScale(device);
} catch (UsbException ex) {
throw new IllegalStateException("Unable to find devices", ex);
}
}
示例6: dump
import javax.usb.UsbHub; //导入依赖的package包/类
/**
*
*
* @param device
*/
public static void dump(UsbDevice device)
{
UsbDeviceDescriptor desc = device.getUsbDeviceDescriptor();
System.out.format("%04x:%04x%n", desc.idVendor() & 0xffff,
desc.idProduct() & 0xffff);
if (device.isUsbHub())
{
UsbHub hub = (UsbHub) device;
for (UsbDevice child : (List<UsbDevice>) hub.getAttachedUsbDevices())
{
dump(child);
}
}
}
示例7: scan
import javax.usb.UsbHub; //导入依赖的package包/类
/**
* Scans the specified hub for changes.
*
* @param hub
* The hub to scan.
*/
public void scan(final UsbHub hub)
{
try
{
updateDeviceList();
}
catch (UsbException e)
{
throw new ScanException("Unable to scan for USB devices: " + e, e);
}
if (hub.isRootUsbHub())
{
final RootHub rootHub = (RootHub) hub;
scanRemovedDevices(rootHub);
scanNewDevices(rootHub, null);
}
else
{
final Hub nonRootHub = (Hub) hub;
scanRemovedDevices(nonRootHub);
scanNewDevices(nonRootHub, nonRootHub.getId());
}
}
示例8: retrieveKnownDevices
import javax.usb.UsbHub; //导入依赖的package包/类
private List<Controller> retrieveKnownDevices() throws UsbException {
List<Controller> controllers = new ArrayList<Controller>();
Module[] knownDevices = Module.values();
UsbHub retrieveUsbHub = this.usbServiceProvider.retrieveUsbHub();
for (Module knownDevice : knownDevices) {
LOGGER.info("inspecting USB bus for device {}", knownDevice);
try {
UsbDevice device = this.findDevice(retrieveUsbHub, knownDevice);
if (null != device) {
LOGGER.debug("found connected device for {}", knownDevice);
controllers.add(Module.buildControllerFor(device));
}
} catch (Exception e) {
LOGGER.warn("exception looking for device {} message {}", knownDevice, e.getMessage());
}
}
return controllers;
}
示例9: findDevice
import javax.usb.UsbHub; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private UsbDevice findDevice(UsbHub usbHub, Module definition) throws UsbException {
List<UsbDevice> attachedUsbDevices = usbHub.getAttachedUsbDevices();
for (UsbDevice usbDevice : attachedUsbDevices) {
UsbDeviceDescriptor desc = usbDevice.getUsbDeviceDescriptor();
if (definition.isBasedOn(desc.idVendor(), desc.idProduct())) {
LOGGER.info("found device: {}", definition);
return usbDevice;
}
if (usbDevice.isUsbHub()) {
usbDevice = findDevice((UsbHub) usbDevice, definition);
if (usbDevice != null) {
return usbDevice;
}
}
}
return null;
}
示例10: testProvideControllerFromDefinition
import javax.usb.UsbHub; //导入依赖的package包/类
@Test
public void testProvideControllerFromDefinition() throws UsbException {
Module expectedControllerDefinition = Module.CM15;
// setup
UsbServices usbServices = mock(UsbServices.class);
UsbHub usbHub = mock(UsbHub.class);
UsbDevice usbDevice = mock(UsbDevice.class);
UsbDeviceDescriptor usbDeviceDescriptor = mock(UsbDeviceDescriptor.class);
when(usbDeviceDescriptor.idVendor()).thenReturn(expectedControllerDefinition.getVendorId());
when(usbDeviceDescriptor.idProduct()).thenReturn(expectedControllerDefinition.getProductId());
when(usbDevice.getUsbDeviceDescriptor()).thenReturn(usbDeviceDescriptor);
List<UsbDevice> attachedDevices = Arrays.asList(usbDevice);
when(usbHub.getAttachedUsbDevices()).thenReturn(attachedDevices);
when(usbServices.getRootUsbHub()).thenReturn(usbHub);
when(this.usbServicesProvider.retrieveUsbHub()).thenReturn(usbHub);
// act
X10Controller actual = testObj.provideControllerBy(expectedControllerDefinition);
// assert
assertNotNull(actual);
assertEquals(expectedControllerDefinition.getProductId(), actual.productId());
assertEquals(expectedControllerDefinition.getVendorId(), actual.vendorId());
}
示例11: findMissileLauncher
import javax.usb.UsbHub; //导入依赖的package包/类
/**
* Recursively searches for the missile launcher device on the specified USB
* hub and returns it. If there are multiple missile launchers attached then
* this simple demo only returns the first one.
*
* @param hub
* The USB hub to search on.
* @return The missile launcher USB device or null if not found.
*/
public static UsbDevice findMissileLauncher(UsbHub hub)
{
UsbDevice launcher = null;
for (UsbDevice device: (List<UsbDevice>) hub.getAttachedUsbDevices())
{
if (device.isUsbHub())
{
launcher = findMissileLauncher((UsbHub) device);
if (launcher != null) return launcher;
}
else
{
UsbDeviceDescriptor desc = device.getUsbDeviceDescriptor();
if (desc.idVendor() == VENDOR_ID &&
desc.idProduct() == PRODUCT_ID) return device;
}
}
return null;
}
示例12: findDevice
import javax.usb.UsbHub; //导入依赖的package包/类
private UsbDevice findDevice(UsbHub usbHub, short defaultVendorId2, short defaultProductId2) {
UsbDevice result = null;
for (Object d : usbHub.getAttachedUsbDevices()) {
if (d instanceof UsbHub) {
result = findDevice((UsbHub) d, defaultVendorId2, defaultProductId2);
if (result != null) {
return result;
}
}
else if (d instanceof UsbDevice) {
UsbDevice device = (UsbDevice) d;
if (device.getUsbDeviceDescriptor().idProduct() == defaultProductId2
&& device.getUsbDeviceDescriptor().idVendor() == defaultVendorId2) {
return device;
}
}
}
return null;
}
示例13: traverse
import javax.usb.UsbHub; //导入依赖的package包/类
/**
* Recursively traverses the USB bus, adding any labjacks to a list.
* @param device the device to begin traversing through.
* @param list the list of UsbDevices to add matching devices to.
*/
private void traverse(UsbDevice device, List<UsbDevice> list)
{
if (device.isUsbHub())
{
// This is a USB Hub, traverse through the hub.
List attachedDevices = ((UsbHub) device).getAttachedUsbDevices();
for (int i=0; i<attachedDevices.size(); i++)
{
traverse((UsbDevice) attachedDevices.get(i), list);
}
}
else
{
/** If the device is a Labjack, add it to the list */
if (device.getUsbDeviceDescriptor().idVendor() == USB_VENDOR_ID
&& device.getUsbDeviceDescriptor().idProduct() == USB_PRODUCT_ID)
{
list.add(device);
}
}
}
示例14: getDevices
import javax.usb.UsbHub; //导入依赖的package包/类
/**
* Returns a List of currently connected usb devices
*/
public static List<UsbDevice> getDevices()
throws SecurityException, UsbException, UnsupportedEncodingException
{
ArrayList<UsbDevice> devices = new ArrayList<UsbDevice>();
UsbServices services = UsbHostManager.getUsbServices();
UsbHub root = services.getRootUsbHub();
devices.addAll( getHubDevices( root ) );
return devices;
}
示例15: getHubDevices
import javax.usb.UsbHub; //导入依赖的package包/类
/**
* Returns a list of devices attached to the hub
*/
public static List<UsbDevice> getHubDevices( UsbHub hub )
throws UnsupportedEncodingException, UsbException
{
ArrayList<UsbDevice> devices = new ArrayList<UsbDevice>();
@SuppressWarnings( "unchecked" )
List<UsbDevice> children = hub.getAttachedUsbDevices();
Iterator<UsbDevice> it = children.iterator();
while( it.hasNext() )
{
UsbDevice child = it.next();
if( child.isUsbHub() )
{
devices.addAll( getHubDevices( (UsbHub)child ) );
}
else
{
devices.add( child );
}
}
return devices;
}