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


Java LibUsb.getDeviceList方法代码示例

本文整理汇总了Java中org.usb4java.LibUsb.getDeviceList方法的典型用法代码示例。如果您正苦于以下问题:Java LibUsb.getDeviceList方法的具体用法?Java LibUsb.getDeviceList怎么用?Java LibUsb.getDeviceList使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.usb4java.LibUsb的用法示例。


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

示例1: findDevice

import org.usb4java.LibUsb; //导入方法依赖的package包/类
public Device findDevice(short vendorId, short productId) {
	// Read the USB device list
	DeviceList list = new DeviceList();
	int result = LibUsb.getDeviceList(null, list);
	if (result < 0) throw new LibUsbException("Unable to get device list", result);

	try {
		// Iterate over all devices and scan for the right one
		for (Device device: list) {
			DeviceDescriptor descriptor = new DeviceDescriptor();
			result = LibUsb.getDeviceDescriptor(device, descriptor);
			if (result != LibUsb.SUCCESS) throw new LibUsbException("Unable to read device descriptor", result);
			if (descriptor.idVendor() == vendorId && descriptor.idProduct() == productId) return device;
		}
	} finally {
		// Ensure the allocated device list is freed
		LibUsb.freeDeviceList(list, true);
	}

	// Device not found
	return null;
}
 
开发者ID:pierre-muth,项目名称:selfpi,代码行数:23,代码来源:TMT20low.java

示例2: getDevices

import org.usb4java.LibUsb; //导入方法依赖的package包/类
public Device[] getDevices(int vendor_id, int product_id){
  
  DeviceList usb_device_list = new DeviceList();
  int result = LibUsb.getDeviceList(context, usb_device_list);
  if (result < 0){
    throw new LibUsbException("Unable to get device list", result);
  }
  
  ArrayList<Device> ps3_device_list = new ArrayList<Device>();
  
  try {

    for (Device usb_device : usb_device_list) {
      DeviceDescriptor descriptor = new DeviceDescriptor();
      result = LibUsb.getDeviceDescriptor(usb_device, descriptor);
      if (result != LibUsb.SUCCESS){
        throw new LibUsbException("Unable to read device descriptor", result);
      }

      if(descriptor.idVendor() == vendor_id && descriptor.idProduct() == product_id){
        DeviceHandle handle = new DeviceHandle();
        result = LibUsb.open(usb_device, handle);
        if (result != LibUsb.SUCCESS){
          throw new LibUsbException("Unable to open USB device", result);
        }
        
        LibUsb.close(handle);
        LibUsb.refDevice(usb_device);
        ps3_device_list.add(usb_device);
      }

    }
  } finally {
    LibUsb.freeDeviceList(usb_device_list, true);
  }
  
  return ps3_device_list.toArray(new Device[ps3_device_list.size()]);
}
 
开发者ID:diwi,项目名称:PS3Eye,代码行数:39,代码来源:USB.java

示例3: buildCompatibleDevicesList

import org.usb4java.LibUsb; //导入方法依赖的package包/类
private List<Device> buildCompatibleDevicesList() {
	final List<Device> compatibleDevicesListLocal = new ArrayList<>();

	final DeviceList devList = new DeviceList();
	LibUsb.getDeviceList(null, devList);

	final DeviceDescriptor devDesc = new DeviceDescriptor();

	for (final Device dev : devList) {

		LibUsb.getDeviceDescriptor(dev, devDesc);

		final ImmutablePair<Short, Short> vidPid = new ImmutablePair<>(devDesc.idVendor(), devDesc.idProduct());


		// Check that the device is not already bound to any other driver.
		final DeviceHandle devHandle = new DeviceHandle();
		int status = LibUsb.open(dev, devHandle);
		if (status != LibUsb.SUCCESS) {
			continue; // Skip device.
		}

		status = LibUsb.kernelDriverActive(devHandle, 0);

		LibUsb.close(devHandle);

		if (((status == LibUsb.ERROR_NOT_SUPPORTED) || (status == LibUsb.SUCCESS))
			&& vidPidToClassMap.containsKey(vidPid)) {
			// This is a VID/PID combination we support, so let's add the
			// device to the compatible
			// devices list and increase its reference count.
			compatibleDevicesListLocal.add(LibUsb.refDevice(dev));
		}
	}

	LibUsb.freeDeviceList(devList, true);

	return compatibleDevicesListLocal;
}
 
开发者ID:SensorsINI,项目名称:jaer,代码行数:40,代码来源:LibUsbHardwareInterfaceFactory.java

示例4: buildCompatibleDevicesList

import org.usb4java.LibUsb; //导入方法依赖的package包/类
private List<Device> buildCompatibleDevicesList() {
	final List<Device> compatibleDevicesListLocal = new ArrayList<>();

	final DeviceList devList = new DeviceList();
	LibUsb.getDeviceList(null, devList);

	final DeviceDescriptor devDesc = new DeviceDescriptor();

	for (final Device dev : devList) {
		LibUsb.getDeviceDescriptor(dev, devDesc);

		final ImmutablePair<Short, Short> vidPid = new ImmutablePair<>(devDesc.idVendor(), devDesc.idProduct());

		// Check that the device is not already bound to any other driver.
		final DeviceHandle devHandle = new DeviceHandle();
		int status = LibUsb.open(dev, devHandle);
		if (status != LibUsb.SUCCESS) {
			continue; // Skip device.
		}

		status = LibUsb.kernelDriverActive(devHandle, 0);

		LibUsb.close(devHandle);

		if (((status == LibUsb.ERROR_NOT_SUPPORTED) || (status == LibUsb.SUCCESS)) && vidPidToClassMap.containsKey(vidPid)) {
			// This is a VID/PID combination we support, so let's add the
			// device to the compatible
			// devices list and increase its reference count.
			compatibleDevicesListLocal.add(LibUsb.refDevice(dev));
		}
	}

	LibUsb.freeDeviceList(devList, true);

	return compatibleDevicesListLocal;
}
 
开发者ID:SensorsINI,项目名称:jaer,代码行数:37,代码来源:LibUsb3HardwareInterfaceFactory.java

示例5: getDevicesList

import org.usb4java.LibUsb; //导入方法依赖的package包/类
private static List<UsbDevice> getDevicesList() {
	final List<UsbDevice> usbDevices = new ArrayList<>();

	final DeviceList list = new DeviceList();

	if (LibUsb.getDeviceList(null, list) > 0) {
		final Iterator<Device> devices = list.iterator();

		while (devices.hasNext()) {
			final Device dev = devices.next();

			final DeviceDescriptor devDesc = new DeviceDescriptor();
			LibUsb.getDeviceDescriptor(dev, devDesc);

			if (Flashy.supportedVidPids.containsKey(devDesc.idVendor())) {
				final Map<Short, Class<? extends Controller>> pids = Flashy.supportedVidPids
					.get(devDesc.idVendor());

				if (pids.containsKey(devDesc.idProduct())) {
					usbDevices.add(new UsbDevice(dev));
				}
			}
		}

		LibUsb.freeDeviceList(list, true);
	}

	return (usbDevices);
}
 
开发者ID:inilabs,项目名称:flashy,代码行数:30,代码来源:Flashy.java

示例6: findYubikey

import org.usb4java.LibUsb; //导入方法依赖的package包/类
/**
 * Searches for the yubikey device and returns it. If there are
 * multiple yubikeys attached then this simple demo only returns
 * the first one.
 * 
 * @return The yubikey USB device or null if not found.
 */
public static Device findYubikey(short[] pids){
    // Read the USB device list
    DeviceList list = new DeviceList();
    int result = LibUsb.getDeviceList(null, list);
    if (result < 0){
        throw new RuntimeException("Unable to get device list. Result=" + result);
    }

    try{
        // Iterate over all devices and scan for the missile launcher
        for (Device device: list){
            DeviceDescriptor descriptor = new DeviceDescriptor();
            result = LibUsb.getDeviceDescriptor(device, descriptor);
            debug(descriptor.dump());
            
            if (result < 0){
                throw new RuntimeException("Unable to read device descriptor. Result=" + result);
            }
            if (descriptor.idVendor() == VENDOR_ID && contains(pids, descriptor.idProduct())) {
                debug("Found device:"+device.toString());
                return device;
            }
        }
    }
    finally{
        // Ensure the allocated device list is freed
        //LibUsb.freeDeviceList(list, true);
        LibUsb.freeDeviceList(list, false);
    }

    // No yubikey found
    return null;
}
 
开发者ID:Toporin,项目名称:yubikey4java,代码行数:41,代码来源:YubikeyConnector.java

示例7: getLibUsbDevice

import org.usb4java.LibUsb; //导入方法依赖的package包/类
/**
 * Returns the libusb device for the specified id. The device must be freed
 * after use.
 * 
 * @param id
 *            The id of the device to return. Must not be null.
 * @return device The libusb device. Never null.
 * @throws DeviceNotFoundException
 *             When the device was not found.
 * @throws UsbPlatformException
 *             When libusb reported an error while enumerating USB devices.
 */
public Device getLibUsbDevice(final DeviceId id) throws UsbPlatformException
{
    if (id == null) throw new IllegalArgumentException("id must be set");

    final DeviceList devices = new DeviceList();
    final int result = LibUsb.getDeviceList(this.context, devices);
    if (result < 0)
    {
        throw ExceptionUtils.createPlatformException(
            "Unable to get USB device list", result);
    }
    try
    {
        for (Device device: devices)
        {
            try
            {
                if (id.equals(createId(device)))
                {
                    LibUsb.refDevice(device);
                    return device;
                }
            }
            catch (UsbPlatformException e)
            {
                // Devices for which no ID can be created are ignored
                continue;
            }
        }
    }
    finally
    {
        LibUsb.freeDeviceList(devices, true);
    }

    throw new DeviceNotFoundException(id);
}
 
开发者ID:usb4java,项目名称:usb4java-javax,代码行数:50,代码来源:DeviceManager.java

示例8: findAllDevices

import org.usb4java.LibUsb; //导入方法依赖的package包/类
/**
	 * List all devices on the computer.
	 * 
	 * @return Vector<Device>
	 * @author yassir
	 */
	private void findAllDevices() {
		//Edited by: [email protected] 24/03/2015
		//Initialize the vector each time the method is called
		allDevices.clear();
		//
//		Vector<Device> v_dev = new Vector<Device>();
		DeviceList list = new DeviceList();
		//Edited by: [email protected] 20/03/2015
		//Context parameter is set to the current context
		int result = LibUsb.getDeviceList(this.context, list);
		//
		if (result < 0)
			throw new LibUsbException("Unable to get device list", result);
		try {
			for (Device device : list) {
				allDevices.add(device);
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			//Ensure the allocated device list is freed
			//Edited by: [email protected] 20/03/2015
			//The unrefDevices parameter is not set (=false)
			LibUsb.freeDeviceList(list, false);
			//
		}
	}
 
开发者ID:Plug-up,项目名称:daplug-java,代码行数:34,代码来源:DaplugDongleWinusb.java

示例9: findMissileLauncher

import org.usb4java.LibUsb; //导入方法依赖的package包/类
/**
 * Searches for the missile launcher device and returns it. If there are
 * multiple missile launchers attached then this simple demo only returns
 * the first one.
 * 
 * @return The missile launcher USB device or null if not found.
 */
public static Device findMissileLauncher()
{
    // Read the USB device list
    DeviceList list = new DeviceList();
    int result = LibUsb.getDeviceList(null, list);
    if (result < 0)
    {
        throw new RuntimeException(
            "Unable to get device list. Result=" + result);
    }

    try
    {
        // Iterate over all devices and scan for the missile launcher
        for (Device device: list)
        {
            DeviceDescriptor descriptor = new DeviceDescriptor();
            result = LibUsb.getDeviceDescriptor(device, descriptor);
            if (result < 0)
            {
                throw new RuntimeException(
                    "Unable to read device descriptor. Result=" + result);
            }
            if (descriptor.idVendor() == VENDOR_ID
                && descriptor.idProduct() == PRODUCT_ID) return device;
        }
    }
    finally
    {
        // Ensure the allocated device list is freed
        LibUsb.freeDeviceList(list, true);
    }

    // No missile launcher found
    return null;
}
 
开发者ID:usb4java,项目名称:usb4java-examples,代码行数:44,代码来源:MissileLauncher.java

示例10: main

import org.usb4java.LibUsb; //导入方法依赖的package包/类
/**
 * Main method.
 * 
 * @param args
 *            Command-line arguments (Ignored)
 */
public static void main(final String[] args)
{
    // Create the libusb context
    final Context context = new Context();

    // Initialize the libusb context
    int result = LibUsb.init(context);
    if (result < 0)
    {
        throw new LibUsbException("Unable to initialize libusb", result);
    }

    // Read the USB device list
    final DeviceList list = new DeviceList();
    result = LibUsb.getDeviceList(context, list);
    if (result < 0)
    {
        throw new LibUsbException("Unable to get device list", result);
    }

    try
    {
        // Iterate over all devices and dump them
        for (Device device: list)
        {
            dumpDevice(device);
        }
    }
    finally
    {
        // Ensure the allocated device list is freed
        LibUsb.freeDeviceList(list, true);
    }
    
    // Deinitialize the libusb context
    LibUsb.exit(context);
}
 
开发者ID:usb4java,项目名称:usb4java-examples,代码行数:44,代码来源:DumpDevices.java

示例11: makeDevice

import org.usb4java.LibUsb; //导入方法依赖的package包/类
public static AirspyDevice makeDevice() throws UsbException {
	DeviceList deviceList = new DeviceList();
	AirspyDevice dev = null;

	int result = LibUsb.init( null );

	if( result != LibUsb.SUCCESS ) {
		Log.errorDialog("ERROR", "unable to initialize libusb [" + 
				LibUsb.errorName( result ) + "]" );
	}
	else
	{
		Log.println( "LibUSB API Version: " + LibUsb.getApiVersion() );
		Log.println( "LibUSB Version: " + LibUsb.getVersion() );

		result = LibUsb.getDeviceList( null, deviceList );

		if( result < 0 )
		{
			Log.errorDialog( "ERROR","unable to get device list from libusb [" + result + " / " + 
					LibUsb.errorName( result ) + "]" );
		}
		else
		{
			Log.println( "discovered [" + result + "] attached USB devices" );
		}
	}

	for( Device device: deviceList )
	{
		DeviceDescriptor descriptor = new DeviceDescriptor();

		result = LibUsb.getDeviceDescriptor( device, descriptor );

		if( result != LibUsb.SUCCESS )
		{
			Log.errorDialog("ERROR", "unable to read device descriptor [" + 
					LibUsb.errorName( result ) + "]" );
		}
		else
		{
			if( device != null && descriptor != null )
			{
				TunerClass tunerClass = TunerClass.valueOf( descriptor.idVendor(), 
						descriptor.idProduct() );
				switch( tunerClass )
				{
				case AIRSPY:
					return initAirspyTuner( device, descriptor );
				default:
					break;
				}
				//	TunerInitStatus status = initTuner( device, descriptor );
				
			}
		}
	}

	LibUsb.freeDeviceList( deviceList, true );
	return dev;
}
 
开发者ID:ac2cz,项目名称:FoxTelem,代码行数:62,代码来源:AirspyDevice.java

示例12: makeDeviceList

import org.usb4java.LibUsb; //导入方法依赖的package包/类
/**
     * Loads all USB tuners and USB/Mixer tuner devices
     * @throws UsbException 
     */
    public <String>ArrayList makeDeviceList() throws UsbException	{
    	deviceNames = new ArrayList();
    	tunerControllerList = new ArrayList<TunerController>();
    	DeviceList deviceList = new DeviceList();
    	int result = LibUsb.init( null );
    	if( result != LibUsb.SUCCESS ){
    		Log.println( "unable to initialize libusb [" + 
    				LibUsb.errorName( result ) + "]" );
    	} else {
    		Log.println( "LibUSB API Version: " + LibUsb.getApiVersion() );
    		Log.println( "LibUSB Version: " + LibUsb.getVersion() );

    		result = LibUsb.getDeviceList( null, deviceList );

    		if( result < 0 ) {
    			Log.println( "unable to get device list from libusb [" + result + " / " + 
    					LibUsb.errorName( result ) + "]" );
    		} else {
    			Log.println( "discovered [" + result + "] attached USB devices" );
    		}
    	}

    	for( Device device: deviceList ) {
    		DeviceDescriptor descriptor = new DeviceDescriptor();
    		result = LibUsb.getDeviceDescriptor( device, descriptor );
    		if( result != LibUsb.SUCCESS ) {
    			Log.println( "unable to read device descriptor [" + 
    					LibUsb.errorName( result ) + "]" );
    		} else {
    			TunerController dev = initTuner( device, descriptor );
    			if (dev !=null) {
    				deviceNames.add((java.lang.String) dev.name);
    				tunerControllerList.add(dev);
    				StringBuilder sb = new StringBuilder();

    				sb.append( "usb device [" );
    				sb.append( descriptor.idVendor() );
//    				sb.append( String.format( "%04X", descriptor.idVendor() ) );
    				sb.append( ":" );
 //   				sb.append( String.format( "%04X", descriptor.idProduct() ) );
    				sb.append( descriptor.idProduct() );

    				Log.println( sb.toString() );
    			}
    		}
    	}

    	LibUsb.freeDeviceList( deviceList, true );
    	return deviceNames;
    }
 
开发者ID:ac2cz,项目名称:FoxTelem,代码行数:55,代码来源:TunerManager.java

示例13: updateDeviceList

import org.usb4java.LibUsb; //导入方法依赖的package包/类
/**
 * Updates the device list by adding newly connected devices to it and by
 * removing no longer connected devices.
 * 
 * @throws UsbPlatformException
 *             When libusb reported an error which we can't ignore during
 *             scan.
 */
private void updateDeviceList() throws UsbPlatformException
{
    final List<DeviceId> current = new ArrayList<DeviceId>();

    // Get device list from libusb and abort if it failed
    final DeviceList devices = new DeviceList();
    final int result = LibUsb.getDeviceList(this.context, devices);
    if (result < 0)
    {
        throw ExceptionUtils.createPlatformException(            
            "Unable to get USB device list", result);
    }

    try
    {
        // Iterate over all currently connected devices
        for (final Device libUsbDevice: devices)
        {
            try
            {
                final DeviceId id = createId(libUsbDevice);

                AbstractDevice device = this.devices.get(id);
                if (device == null)
                {
                    final Device parent = LibUsb.getParent(libUsbDevice);
                    final DeviceId parentId = parent == null ? null : 
                        createId(parent);
                    final int speed = LibUsb.getDeviceSpeed(libUsbDevice);
                    final boolean isHub = id.getDeviceDescriptor()
                        .bDeviceClass() == LibUsb.CLASS_HUB;
                    if (isHub)
                    {
                        device = new Hub(this, id, parentId,
                            speed, libUsbDevice);
                    }
                    else
                    {
                        device = new NonHub(this, id,
                            parentId, speed, libUsbDevice);
                    }

                    // Add new device to global device list.
                    this.devices.put(id, device);
                }

                // Remember current device as "current"
                current.add(id);
            }
            catch (UsbPlatformException e)
            {
                // Devices which can't be enumerated are ignored
                continue;
            }
        }

        this.devices.keySet().retainAll(current);
    }
    finally
    {
        LibUsb.freeDeviceList(devices, true);
    }
}
 
开发者ID:usb4java,项目名称:usb4java-javax,代码行数:72,代码来源:DeviceManager.java

示例14: main

import org.usb4java.LibUsb; //导入方法依赖的package包/类
/**
 * Main method.
 * 
 * @param args
 *            Command-line arguments (Ignored)
 */
public static void main(String[] args)
{
    // Create the libusb context
    Context context = new Context();

    // Initialize the libusb context
    int result = LibUsb.init(context);
    if (result < 0)
    {
        throw new LibUsbException("Unable to initialize libusb", result);
    }

    // Read the USB device list
    DeviceList list = new DeviceList();
    result = LibUsb.getDeviceList(context, list);
    if (result < 0)
    {
        throw new LibUsbException("Unable to get device list", result);
    }

    try
    {
        // Iterate over all devices and list them
        for (Device device: list)
        {
            int address = LibUsb.getDeviceAddress(device);
            int busNumber = LibUsb.getBusNumber(device);
            DeviceDescriptor descriptor = new DeviceDescriptor();
            result = LibUsb.getDeviceDescriptor(device, descriptor);
            if (result < 0)
            {
                throw new LibUsbException(
                    "Unable to read device descriptor", result);
            }
            System.out.format(
                "Bus %03d, Device %03d: Vendor %04x, Product %04x%n",
                busNumber, address, descriptor.idVendor(),
                descriptor.idProduct());
        }
    }
    finally
    {
        // Ensure the allocated device list is freed
        LibUsb.freeDeviceList(list, true);
    }

    // Deinitialize the libusb context
    LibUsb.exit(context);
}
 
开发者ID:usb4java,项目名称:usb4java-examples,代码行数:56,代码来源:ListDevices.java


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