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


Java LibUsb.claimInterface方法代码示例

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


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

示例1: acquireDevice

import org.usb4java.LibUsb; //导入方法依赖的package包/类
/**
 * acquire a device for exclusive use, other processes can't open the device
 * anymore used for example for continuous sequencing in matlab
 */
public void acquireDevice() throws HardwareInterfaceException {
    SiLabsC8051F320_LibUsb.log.log(Level.INFO, "{0} acquiring device for exclusive access", this);

    final int status = LibUsb.claimInterface(retinahandle, 0);
    if (status != LibUsb.SUCCESS) {
        if (status == LibUsb.ERROR_BUSY) {
            try {
                sleep(3000);
            } catch (InterruptedException ex) {

            }
        }
        throw new HardwareInterfaceException("Unable to acquire device for exclusive use: "
                + LibUsb.errorName(status));
    }
}
 
开发者ID:SensorsINI,项目名称:jaer,代码行数:21,代码来源:SiLabsC8051F320_LibUsb.java

示例2: acquireDevice

import org.usb4java.LibUsb; //导入方法依赖的package包/类
/**
 * acquire a device for exclusive use, other processes can't open the device
 * anymore
 * used for example for continuous sequencing in matlab
 */
public void acquireDevice() throws HardwareInterfaceException {
	CypressFX2.log.log(Level.INFO, "{0} acquiring device for exclusive access", this);

	final int status = LibUsb.claimInterface(deviceHandle, 0);
	if (status != LibUsb.SUCCESS) {
		throw new HardwareInterfaceException("Unable to acquire device for exclusive use: "
			+ LibUsb.errorName(status));
	}
}
 
开发者ID:SensorsINI,项目名称:jaer,代码行数:15,代码来源:CypressFX2.java

示例3: acquireDevice

import org.usb4java.LibUsb; //导入方法依赖的package包/类
/**
 * acquire a device for exclusive use, other processes can't open the device
 * anymore
 * used for example for continuous sequencing in matlab
 */
public void acquireDevice() throws HardwareInterfaceException {
	CypressFX3.log.log(Level.INFO, "{0} acquiring device for exclusive access", this);

	final int status = LibUsb.claimInterface(deviceHandle, 0);
	if (status != LibUsb.SUCCESS) {
		throw new HardwareInterfaceException("Unable to acquire device for exclusive use: " + LibUsb.errorName(status));
	}
}
 
开发者ID:SensorsINI,项目名称:jaer,代码行数:14,代码来源:CypressFX3.java

示例4: connect

import org.usb4java.LibUsb; //导入方法依赖的package包/类
/**
 * Connect to the USB port and claim the display interface.
 */
public void connect ()
{
    int result = LibUsb.init (null);
    if (result != LibUsb.SUCCESS)
        throw new LibUsbException ("Unable to initialize libusb.", result);

    this.handle = openDeviceWithVidPid (VENDOR_ID, PRODUCT_ID);
    if (this.handle == null)
        throw new LibUsbException ("Device not found.", LibUsb.ERROR_NO_DEVICE);

    result = LibUsb.claimInterface (this.handle, INTERFACE_NUMBER);
    if (result != LibUsb.SUCCESS)
        throw new LibUsbException ("Unable to claim interface.", result);
}
 
开发者ID:git-moss,项目名称:Push2Display,代码行数:18,代码来源:USBDisplay.java

示例5: claimInterface

import org.usb4java.LibUsb; //导入方法依赖的package包/类
/**
 * Claims the USB interface.  Attempts to detach the active kernel driver
 * if one is currently attached.
 */
public static void claimInterface(DeviceHandle handle) throws SourceException
{
    if(handle != null)
    {
        int result = LibUsb.kernelDriverActive(handle, USB_INTERFACE);

        if(result == 1)
        {
            result = LibUsb.detachKernelDriver(handle, USB_INTERFACE);

            if(result != LibUsb.SUCCESS)
            {
                mLog.error("failed attempt to detach kernel driver [" +
                    LibUsb.errorName(result) + "]");

                throw new SourceException("couldn't detach kernel driver "
                    + "from device");
            }
        }

        result = LibUsb.claimInterface(handle, USB_INTERFACE);

        if(result != LibUsb.SUCCESS)
        {
            throw new SourceException("couldn't claim usb interface [" +
                LibUsb.errorName(result) + "]");
        }
    }
    else
    {
        throw new SourceException("couldn't claim usb interface - no "
            + "device handle");
    }
}
 
开发者ID:DSheirer,项目名称:sdrtrunk,代码行数:39,代码来源:RTL2832TunerController.java

示例6: claimInterface

import org.usb4java.LibUsb; //导入方法依赖的package包/类
/**
 * Claims the USB interface.  Attempts to detach the active kernel driver if
 * one is currently attached.
 */
private void claimInterface() throws SourceException
{
    if(mDeviceHandle != null)
    {
        int result = LibUsb.kernelDriverActive(mDeviceHandle, FCD_INTERFACE);

        if(result == 1)
        {
            result = LibUsb.detachKernelDriver(mDeviceHandle, FCD_INTERFACE);

            if(result != LibUsb.SUCCESS)
            {
                mLog.error("failed attempt to detach kernel driver [" + LibUsb.errorName(result) + "]");
            }
        }

        result = LibUsb.claimInterface(mDeviceHandle, FCD_INTERFACE);

        if(result != LibUsb.SUCCESS)
        {
            throw new SourceException("couldn't claim usb interface [" + LibUsb.errorName(result) + "]");
        }
    }
    else
    {
        throw new SourceException("couldn't claim usb hid interface - no device handle");
    }
}
 
开发者ID:DSheirer,项目名称:sdrtrunk,代码行数:33,代码来源:FCDTunerController.java

示例7: claimInterface

import org.usb4java.LibUsb; //导入方法依赖的package包/类
/**
 * Claims the USB interface.  If another application currently has
 * the interface claimed, the USB_FORCE_CLAIM_INTERFACE setting
 * will dictate if the interface is forcibly claimed from the other
 * application
 */
private void claimInterface() throws SourceException
{
    if(mDeviceHandle != null)
    {
        int result = LibUsb.kernelDriverActive(mDeviceHandle, USB_INTERFACE);

        if(result == 1)
        {
            result = LibUsb.detachKernelDriver(mDeviceHandle, USB_INTERFACE);

            if(result != LibUsb.SUCCESS)
            {
                mLog.error("failed attempt to detach kernel driver [" +
                    LibUsb.errorName(result) + "]");

                throw new SourceException("couldn't detach kernel driver "
                    + "from device");
            }
        }

        result = LibUsb.claimInterface(mDeviceHandle, USB_INTERFACE);

        if(result != LibUsb.SUCCESS)
        {
            throw new SourceException("couldn't claim usb interface [" +
                LibUsb.errorName(result) + "]");
        }
    }
    else
    {
        throw new SourceException("couldn't claim usb interface - no "
            + "device handle");
    }
}
 
开发者ID:DSheirer,项目名称:sdrtrunk,代码行数:41,代码来源:HackRFTunerController.java

示例8: claimInterface

import org.usb4java.LibUsb; //导入方法依赖的package包/类
/**
 * Claims the USB interface.  Attempts to detach the active kernel driver
 * if one is currently attached.
 */
public static void claimInterface( DeviceHandle handle ) throws DeviceException
{
	if( handle != null )
	{
		int result = LibUsb.kernelDriverActive( handle, USB_INTERFACE );
				
		if( result == 1 )
		{
			result = LibUsb.detachKernelDriver( handle, USB_INTERFACE );

			if( result != LibUsb.SUCCESS )
			{
				Log.errorDialog( "ERROR", "failed attempt to detach kernel driver [" + 
						LibUsb.errorName( result ) + "]" );
				
				throw new DeviceException( "couldn't detach kernel driver "
						+ "from device" );
			}
		}
		
		result = LibUsb.claimInterface( handle, USB_INTERFACE );
		
		if( result != LibUsb.SUCCESS )
		{
			throw new DeviceException( "couldn't claim usb interface [" + 
				LibUsb.errorName( result ) + "]" );
		}
	}
	else
	{
		throw new DeviceException( "couldn't claim usb interface - no "
				+ "device handle" );
	}
}
 
开发者ID:ac2cz,项目名称:FoxTelem,代码行数:39,代码来源:RTL2832TunerController.java

示例9: TMT20low

import org.usb4java.LibUsb; //导入方法依赖的package包/类
public TMT20low() throws SecurityException, UsbException {
	// Search for epson TM-T20

	context = new Context();
	int result = LibUsb.init(context);
	if (result != LibUsb.SUCCESS) throw new LibUsbException("Unable to initialize libusb.", result);

	device = findDevice(VENDOR_ID, PRODUCT_ID);
	if (device == null) {
		System.err.println("not found.");
		System.exit(1);
		return;
	}

	handle = new DeviceHandle();
	result = LibUsb.open(device, handle);
	if (result != LibUsb.SUCCESS) throw new LibUsbException("Unable to open USB device", result);
	
	// Check if kernel driver must be detached
	boolean detach = LibUsb.hasCapability(LibUsb.CAP_SUPPORTS_DETACH_KERNEL_DRIVER) && (LibUsb.kernelDriverActive(handle, 0) > 0);
	System.out.println("hasCapability: "+LibUsb.hasCapability(LibUsb.CAP_SUPPORTS_DETACH_KERNEL_DRIVER)+
			", kernelDriverActive: "+LibUsb.kernelDriverActive(handle, 0));

	// Detach the kernel driver
	if (detach) {
	    result = LibUsb.detachKernelDriver(handle,  0);
	    if (result != LibUsb.SUCCESS) throw new LibUsbException("Unable to detach kernel driver", result);
	}

	result = LibUsb.claimInterface(handle, 0);
	if (result != LibUsb.SUCCESS) throw new LibUsbException("Unable to claim interface", result);
}
 
开发者ID:pierre-muth,项目名称:selfpi,代码行数:33,代码来源:TMT20low.java

示例10: main

import org.usb4java.LibUsb; //导入方法依赖的package包/类
/**
 * Main method.
 * 
 * @param args
 *            Command-line arguments (Ignored)
 * @throws Exception
 *             When something goes wrong.
 */
public static void main(String[] args) throws Exception
{
    // Initialize the libusb context
    int result = LibUsb.init(null);
    if (result != LibUsb.SUCCESS)
    {
        throw new LibUsbException("Unable to initialize libusb", result);
    }

    // Open test device (Samsung Galaxy Nexus)
    DeviceHandle handle = LibUsb.openDeviceWithVidPid(null, VENDOR_ID,
        PRODUCT_ID);
    if (handle == null)
    {
        System.err.println("Test device not found.");
        System.exit(1);
    }

    // Claim the ADB interface
    result = LibUsb.claimInterface(handle, INTERFACE);
    if (result != LibUsb.SUCCESS)
    {
        throw new LibUsbException("Unable to claim interface", result);
    }

    // Send ADB CONNECT message
    write(handle, CONNECT_HEADER);
    write(handle, CONNECT_BODY);

    // Receive the header of the ADB answer (Most likely an AUTH message)
    ByteBuffer header = read(handle, 24);
    header.position(12);
    int dataSize = header.asIntBuffer().get();

    // Receive the body of the ADB answer
    @SuppressWarnings("unused")
    ByteBuffer data = read(handle, dataSize);

    // Release the ADB interface
    result = LibUsb.releaseInterface(handle, INTERFACE);
    if (result != LibUsb.SUCCESS)
    {
        throw new LibUsbException("Unable to release interface", result);
    }

    // Close the device
    LibUsb.close(handle);

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

示例11: claimInterface

import org.usb4java.LibUsb; //导入方法依赖的package包/类
/**
 * Claims the USB interface.  If another application currently has
 * the interface claimed, the USB_FORCE_CLAIM_INTERFACE setting
 * will dictate if the interface is forcibly claimed from the other
 * application
 */
private void claimInterface() throws SourceException
{
    if(mDeviceHandle != null)
    {
        int result = LibUsb.kernelDriverActive(mDeviceHandle, USB_INTERFACE);

        if(result == 1)
        {

            result = LibUsb.detachKernelDriver(mDeviceHandle, USB_INTERFACE);

            if(result != LibUsb.SUCCESS)
            {
                mLog.error("failed attempt to detach kernel driver [" +
                    LibUsb.errorName(result) + "]");

                throw new SourceException("couldn't detach kernel driver "
                    + "from device");
            }
        }

        result = LibUsb.setConfiguration(mDeviceHandle, 1);

        if(result != LibUsb.SUCCESS)
        {
            throw new SourceException("couldn't set USB configuration 1 [" +
                LibUsb.errorName(result) + "]");
        }

        result = LibUsb.claimInterface(mDeviceHandle, USB_INTERFACE);

        if(result != LibUsb.SUCCESS)
        {
            throw new SourceException("couldn't claim usb interface [" +
                LibUsb.errorName(result) + "]");
        }
    }
    else
    {
        throw new SourceException("couldn't claim usb interface - no "
            + "device handle");
    }
}
 
开发者ID:DSheirer,项目名称:sdrtrunk,代码行数:50,代码来源:AirspyTunerController.java

示例12: claimInterface

import org.usb4java.LibUsb; //导入方法依赖的package包/类
/**
 * Claims the USB interface.  If another application currently has
 * the interface claimed, the USB_FORCE_CLAIM_INTERFACE setting
 * will dictate if the interface is forcibly claimed from the other 
 * application
 */
private void claimInterface() throws DeviceException
{
	if( mDeviceHandle != null )
	{
		int result = LibUsb.kernelDriverActive( mDeviceHandle, USB_INTERFACE );
				
		if( result == 1 )
		{
			
			result = LibUsb.detachKernelDriver( mDeviceHandle, USB_INTERFACE );

			if( result != LibUsb.SUCCESS )
			{
				Log.errorDialog("ERROR", "failed attempt to detach kernel driver [" + 
						LibUsb.errorName( result ) + "]" );
				
				throw new DeviceException( "couldn't detach kernel driver "
						+ "from device" );
			}
		}

		result = LibUsb.setConfiguration( mDeviceHandle, 1 );
		
		if( result != LibUsb.SUCCESS )
		{
			throw new DeviceException( "couldn't set USB configuration 1 [" + 
				LibUsb.errorName( result ) + "]" );
		}

		result = LibUsb.claimInterface( mDeviceHandle, USB_INTERFACE );
		
		if( result != LibUsb.SUCCESS )
		{
			throw new DeviceException( "couldn't claim usb interface [" + 
				LibUsb.errorName( result ) + "]" );
		}
	}
	else
	{
		throw new DeviceException( "couldn't claim usb interface - no "
				+ "device handle" );
	}
}
 
开发者ID:ac2cz,项目名称:FoxTelem,代码行数:50,代码来源:AirspyDevice.java


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