当前位置: 首页>>代码示例>>Java>>正文


Java UsbDevice类代码示例

本文整理汇总了Java中javax.usb.UsbDevice的典型用法代码示例。如果您正苦于以下问题:Java UsbDevice类的具体用法?Java UsbDevice怎么用?Java UsbDevice使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


UsbDevice类属于javax.usb包,在下文中一共展示了UsbDevice类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: initialize

import javax.usb.UsbDevice; //导入依赖的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();
			}
		}
	}
}
 
开发者ID:yadarts,项目名称:yadarts,代码行数:22,代码来源:SimplifiedEmprexUSBDriver.java

示例2: find

import javax.usb.UsbDevice; //导入依赖的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;
}
 
开发者ID:loreii,项目名称:jLedStripe,代码行数:25,代码来源:LedStripe.java

示例3: sendUsbControlIrp

import javax.usb.UsbDevice; //导入依赖的package包/类
/**
 * Send the UsbControlIrp to the UsbDevice on the DCP.
 *
 * @param usbDevice
 *            The UsbDevice.
 * @param usbControlIrp
 *            The UsbControlIrp.
 * @return If the submission was successful.
 */
public static boolean sendUsbControlIrp(UsbDevice usbDevice, UsbControlIrp usbControlIrp) {
    try {
        /*
         * This will block until the submission is complete.
         * Note that submissions (except interrupt and bulk in-direction)
         * will not block indefinitely, they will complete or fail within a finite
         * amount of time. See MouseDriver.HidMouseRunnable for more details.
         */
        usbDevice.syncSubmit(usbControlIrp);
        return true;
    } catch (UsbException uE) {
        mLogger.error("DCP submission failed : " + uE.getMessage());
        return false;
    }
}
 
开发者ID:fredg02,项目名称:se.bitcraze.crazyflie.lib,代码行数:25,代码来源:UsbLinkJava.java

示例4: findUsbDevices

import javax.usb.UsbDevice; //导入依赖的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;
}
 
开发者ID:fredg02,项目名称:se.bitcraze.crazyflie.lib,代码行数:18,代码来源:UsbLinkJava.java

示例5: findUsb

import javax.usb.UsbDevice; //导入依赖的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;
}
 
开发者ID:pierre-muth,项目名称:selfpi,代码行数:19,代码来源:EpsonESCPOSPrinter.java

示例6: findScale

import javax.usb.UsbDevice; //导入依赖的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);
  }
}
 
开发者ID:RaspberryPiWithJava,项目名称:JavaScale,代码行数:19,代码来源:UsbScale.java

示例7: dump

import javax.usb.UsbDevice; //导入依赖的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);
        }
    }
}
 
开发者ID:swordmaster2k,项目名称:robotarmedge,代码行数:22,代码来源:DeviceManager.java

示例8: retrieveKnownDevices

import javax.usb.UsbDevice; //导入依赖的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;
}
 
开发者ID:quirinobrizi,项目名称:jax10,代码行数:19,代码来源:X10UsbControllerProvider.java

示例9: findDevice

import javax.usb.UsbDevice; //导入依赖的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;
}
 
开发者ID:quirinobrizi,项目名称:jax10,代码行数:19,代码来源:X10UsbControllerProvider.java

示例10: testProvideControllerFromDefinition

import javax.usb.UsbDevice; //导入依赖的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());
}
 
开发者ID:quirinobrizi,项目名称:jax10,代码行数:23,代码来源:UsbScannerTest.java

示例11: findMissileLauncher

import javax.usb.UsbDevice; //导入依赖的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;
}
 
开发者ID:usb4java,项目名称:usb4java-javax-examples,代码行数:30,代码来源:MissileLauncher.java

示例12: sendMessage

import javax.usb.UsbDevice; //导入依赖的package包/类
/**
 * Sends a message to the missile launcher.
 * 
 * @param device
 *            The USB device handle.
 * @param message
 *            The message to send.
 * @throws UsbException
 *             When sending the message failed.
 */
public static void sendMessage(UsbDevice device, byte[] message)
    throws UsbException
{
    UsbControlIrp irp = device.createUsbControlIrp(
        (byte) (UsbConst.REQUESTTYPE_TYPE_CLASS |
        UsbConst.REQUESTTYPE_RECIPIENT_INTERFACE), (byte) 0x09,
        (short) 2, (short) 1);
    irp.setData(message);
    device.syncSubmit(irp);
}
 
开发者ID:usb4java,项目名称:usb4java-javax-examples,代码行数:21,代码来源:MissileLauncher.java

示例13: sendCommand

import javax.usb.UsbDevice; //导入依赖的package包/类
/**
 * Sends a command to the missile launcher.
 * 
 * @param device
 *            The USB device handle.
 * @param command
 *            The command to send.
 * @throws UsbException
 *             When USB communication failed.
 */
public static void sendCommand(UsbDevice device, int command)
    throws UsbException
{
    byte[] message = new byte[64];
    message[1] = (byte) ((command & CMD_LEFT) > 0 ? 1 : 0);
    message[2] = (byte) ((command & CMD_RIGHT) > 0 ? 1 : 0);
    message[3] = (byte) ((command & CMD_UP) > 0 ? 1 : 0);
    message[4] = (byte) ((command & CMD_DOWN) > 0 ? 1 : 0);
    message[5] = (byte) ((command & CMD_FIRE) > 0 ? 1 : 0);
    message[6] = 8;
    message[7] = 8;
    sendMessage(device, INIT_A);
    sendMessage(device, INIT_B);
    sendMessage(device, message);
}
 
开发者ID:usb4java,项目名称:usb4java-javax-examples,代码行数:26,代码来源:MissileLauncher.java

示例14: findDevice

import javax.usb.UsbDevice; //导入依赖的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;
}
 
开发者ID:yadarts,项目名称:yadarts,代码行数:20,代码来源:SimplifiedEmprexUSBDriver.java

示例15: traverse

import javax.usb.UsbDevice; //导入依赖的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);
        }
    }
}
 
开发者ID:sahara-labs,项目名称:rig-client-commons,代码行数:27,代码来源:Labjack.java


注:本文中的javax.usb.UsbDevice类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。