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


Java DeviceHandle类代码示例

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


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

示例1: disconnect

import org.usb4java.DeviceHandle; //导入依赖的package包/类
/**
 * Disconnect from the USB device.
 */
public void disconnect ()
{
    if (this.handle == null)
        return;

    // Prevent further sending
    final DeviceHandle h = this.handle;
    this.handle = null;

    final int result = LibUsb.releaseInterface (h, INTERFACE_NUMBER);
    if (result != LibUsb.SUCCESS)
        throw new LibUsbException ("Unable to release interface", result);

    LibUsb.close (h);
    LibUsb.exit (null);
}
 
开发者ID:git-moss,项目名称:Push2Display,代码行数:20,代码来源:USBDisplay.java

示例2: setGPIOBit

import org.usb4java.DeviceHandle; //导入依赖的package包/类
/**
 * Sets the General Purpose Input/Output (GPIO) register bit
 *
 * @param handle - USB tuner device
 * @param bitMask - bit mask with one for targeted register bits and zero
 * for the non-targeted register bits
 * @param enabled - true to set the bit and false to clear the bit
 * @throws UsbDisconnectedException - if the tuner device is disconnected
 * @throws UsbException             - if there is a USB error while communicating with
 *                                  the device
 */
protected static void setGPIOBit(DeviceHandle handle,
                                 byte bitMask,
                                 boolean enabled) throws LibUsbException
{
    //Get current register value
    int value = readRegister(handle, Block.SYS, Address.GPO.getAddress(), 1);

    //Update the masked bits
    if(enabled)
    {
        value |= bitMask;
    }
    else
    {
        value &= ~bitMask;
    }

    //Write the change back to the device
    writeRegister(handle, Block.SYS, Address.GPO.getAddress(), value, 1);
}
 
开发者ID:DSheirer,项目名称:sdrtrunk,代码行数:32,代码来源:RTL2832TunerController.java

示例3: setGPIOOutput

import org.usb4java.DeviceHandle; //导入依赖的package包/类
/**
 * Enables GPIO Output
 *
 * @param handle - usb tuner device
 * @param bitMask - mask containing one bit value in targeted bit field(s)
 * @throws UsbDisconnectedException
 * @throws UsbException
 */
protected static void setGPIOOutput(DeviceHandle handle, byte bitMask)
    throws LibUsbException
{
    //Get current register value
    int value = readRegister(handle, Block.SYS, Address.GPD.getAddress(), 1);

    //Mask the value and rewrite it
    writeRegister(handle, Block.SYS, Address.GPO.getAddress(),
        value & ~bitMask, 1);

    //Get current register value
    value = readRegister(handle, Block.SYS, Address.GPOE.getAddress(), 1);

    //Mask the value and rewrite it
    writeRegister(handle, Block.SYS, Address.GPOE.getAddress(),
        value | bitMask, 1);
}
 
开发者ID:DSheirer,项目名称:sdrtrunk,代码行数:26,代码来源:RTL2832TunerController.java

示例4: enableI2CRepeater

import org.usb4java.DeviceHandle; //导入依赖的package包/类
protected static void enableI2CRepeater(DeviceHandle handle,
                                        boolean enabled)
    throws LibUsbException
{
    Page page = Page.ONE;
    short address = 1;
    int value;

    if(enabled)
    {
        value = 0x18; //ON
    }
    else
    {
        value = 0x10; //OFF
    }

    writeDemodRegister(handle, page, address, value, 1);
}
 
开发者ID:DSheirer,项目名称:sdrtrunk,代码行数:20,代码来源:RTL2832TunerController.java

示例5: writeI2CRegister

import org.usb4java.DeviceHandle; //导入依赖的package包/类
protected void writeI2CRegister(DeviceHandle handle,
                                byte i2CAddress,
                                byte i2CRegister,
                                byte value,
                                boolean controlI2CRepeater) throws LibUsbException
{

    short address = (short) (i2CAddress & 0xFF);

    ByteBuffer buffer = ByteBuffer.allocateDirect(2);
    buffer.put(i2CRegister);
    buffer.put(value);

    buffer.rewind();

    if(controlI2CRepeater)
    {
        enableI2CRepeater(handle, true);
        write(handle, address, Block.I2C, buffer);
        enableI2CRepeater(handle, false);
    }
    else
    {
        write(handle, address, Block.I2C, buffer);
    }
}
 
开发者ID:DSheirer,项目名称:sdrtrunk,代码行数:27,代码来源:RTL2832TunerController.java

示例6: readDemodRegister

import org.usb4java.DeviceHandle; //导入依赖的package包/类
protected static int readDemodRegister(DeviceHandle handle,
                                       Page page,
                                       short address,
                                       int length) throws LibUsbException
{
    short index = page.getPage();
    short newAddress = (short) ((address << 8) | 0x20);

    ByteBuffer buffer = ByteBuffer.allocateDirect(length);

    read(handle, newAddress, index, buffer);
    buffer.order(ByteOrder.LITTLE_ENDIAN);

    if(length == 2)
    {
        return (int) (buffer.getShort() & 0xFFFF);
    }
    else
    {
        return (int) (buffer.get() & 0xFF);
    }
}
 
开发者ID:DSheirer,项目名称:sdrtrunk,代码行数:23,代码来源:RTL2832TunerController.java

示例7: readRegister

import org.usb4java.DeviceHandle; //导入依赖的package包/类
protected static int readRegister(DeviceHandle handle,
                                  Block block,
                                  short address,
                                  int length) throws LibUsbException
{
    ByteBuffer buffer = ByteBuffer.allocateDirect(2);

    read(handle, address, block, buffer);

    buffer.order(ByteOrder.LITTLE_ENDIAN);

    if(length == 2)
    {
        return (int) (buffer.getShort() & 0xFFFF);
    }
    else
    {
        return (int) (buffer.get() & 0xFF);
    }
}
 
开发者ID:DSheirer,项目名称:sdrtrunk,代码行数:21,代码来源:RTL2832TunerController.java

示例8: init

import org.usb4java.DeviceHandle; //导入依赖的package包/类
/**
 * Initializes the controller by opening the USB device and claiming the
 * HID interface.
 *
 * Invoke this method after constructing this class to setup the
 * controller.
 *
 * @throws SourceException if cannot open and claim the USB device
 */
public void init() throws SourceException
{
    mDeviceHandle = new DeviceHandle();

    int result = LibUsb.open(mDevice, mDeviceHandle);

    if(result != LibUsb.SUCCESS)
    {
        mDeviceHandle = null;

        throw new SourceException("libusb couldn't open funcube usb device [" + LibUsb.errorName(result) + "]");
    }

    claimInterface();
}
 
开发者ID:DSheirer,项目名称:sdrtrunk,代码行数:25,代码来源:FCDTunerController.java

示例9: setGPIOBit

import org.usb4java.DeviceHandle; //导入依赖的package包/类
/**
 * Sets the General Purpose Input/Output (GPIO) register bit
 * 
 * @param handle - USB tuner device
 * @param bitMask - bit mask with one for targeted register bits and zero 
 *		for the non-targeted register bits
 * @param enabled - true to set the bit and false to clear the bit
 * @throws UsbDisconnectedException - if the tuner device is disconnected
 * @throws UsbException - if there is a USB error while communicating with 
 *		the device
 */
protected static void setGPIOBit( DeviceHandle handle, 
								  byte bitMask, 
								  boolean enabled )	throws LibUsbException
{
	//Get current register value
	int value = readRegister( handle, Block.SYS, Address.GPO.getAddress(), 1 );

	//Update the masked bits
	if( enabled )
	{
		value |= bitMask;
	}
	else
	{
		value &= ~bitMask;
	}

	//Write the change back to the device
	writeRegister( handle, Block.SYS, Address.GPO.getAddress(), value, 1 );
}
 
开发者ID:ac2cz,项目名称:FoxTelem,代码行数:32,代码来源:RTL2832TunerController.java

示例10: setGPIOOutput

import org.usb4java.DeviceHandle; //导入依赖的package包/类
/**
 * Enables GPIO Output
 * @param handle - usb tuner device
 * @param bitMask - mask containing one bit value in targeted bit field(s)
 * @throws UsbDisconnectedException 
 * @throws UsbException
 */
protected static void setGPIOOutput( DeviceHandle handle, byte bitMask )
					throws LibUsbException
{
	//Get current register value
	int value = readRegister( handle, Block.SYS, Address.GPD.getAddress(), 1 );

	//Mask the value and rewrite it
	writeRegister( handle, Block.SYS, Address.GPO.getAddress(), 
						value & ~bitMask, 1 );
	
	//Get current register value
	value = readRegister( handle, Block.SYS, Address.GPOE.getAddress(), 1 );

	//Mask the value and rewrite it
	writeRegister( handle, Block.SYS, Address.GPOE.getAddress(), 
						value | bitMask, 1 );
}
 
开发者ID:ac2cz,项目名称:FoxTelem,代码行数:25,代码来源:RTL2832TunerController.java

示例11: enableI2CRepeater

import org.usb4java.DeviceHandle; //导入依赖的package包/类
protected static void enableI2CRepeater( DeviceHandle handle, 
										 boolean enabled ) 
											 	throws LibUsbException
{
	Page page = Page.ONE;
	short address = 1;
	int value;
	
	if( enabled )
	{
		value = 0x18; //ON
	}
	else
	{
		value = 0x10; //OFF
	}

	writeDemodRegister( handle, page, address, value, 1 );
}
 
开发者ID:ac2cz,项目名称:FoxTelem,代码行数:20,代码来源:RTL2832TunerController.java

示例12: writeI2CRegister

import org.usb4java.DeviceHandle; //导入依赖的package包/类
protected void writeI2CRegister( DeviceHandle handle, 
								 byte i2CAddress,
								 byte i2CRegister, 
								 byte value,
								 boolean controlI2CRepeater ) throws LibUsbException
{
	
	short address = (short)( i2CAddress & 0xFF );

	ByteBuffer buffer = ByteBuffer.allocateDirect( 2 );
	buffer.put( i2CRegister );
	buffer.put( value );

	buffer.rewind();

	if( controlI2CRepeater )
	{
		enableI2CRepeater( handle, true );
		write( handle, address, Block.I2C, buffer );
		enableI2CRepeater( handle, false );
	}
	else
	{
		write( handle, address, Block.I2C, buffer );
	}
}
 
开发者ID:ac2cz,项目名称:FoxTelem,代码行数:27,代码来源:RTL2832TunerController.java

示例13: readDemodRegister

import org.usb4java.DeviceHandle; //导入依赖的package包/类
protected static int readDemodRegister( DeviceHandle handle, 
										Page page, 
										short address, 
										int length ) throws LibUsbException
{
	short index = page.getPage();
	short newAddress = (short)( ( address << 8 ) | 0x20 );
	
	ByteBuffer buffer = ByteBuffer.allocateDirect( length );
	
	read( handle, newAddress, index, buffer );
	buffer.order( ByteOrder.LITTLE_ENDIAN );

	if( length == 2 )
	{
		return (int)( buffer.getShort() & 0xFFFF );
	}
	else
	{
		return (int)( buffer.get() & 0xFF );
	}
}
 
开发者ID:ac2cz,项目名称:FoxTelem,代码行数:23,代码来源:RTL2832TunerController.java

示例14: readRegister

import org.usb4java.DeviceHandle; //导入依赖的package包/类
protected static int readRegister( DeviceHandle handle, 
								   Block block, 
								   short address, 
								   int length ) throws LibUsbException
{
	ByteBuffer buffer = ByteBuffer.allocateDirect( 2 );

	read( handle, address, block, buffer );

	buffer.order( ByteOrder.LITTLE_ENDIAN );
	
	if( length == 2 )
	{
		return (int)( buffer.getShort() & 0xFFFF );
	}
	else
	{
		return (int)( buffer.get() & 0xFF );
	}
}
 
开发者ID:ac2cz,项目名称:FoxTelem,代码行数:21,代码来源:RTL2832TunerController.java

示例15: raw_write

import org.usb4java.DeviceHandle; //导入依赖的package包/类
/**
 * Sends a message to the yubikey.
 * 
 * @param handle
 *            The USB device handle.
 * @param message
 *            The message to send.
 */
public static int raw_write(DeviceHandle handle, byte[] message)
{
    ByteBuffer buffer = ByteBuffer.allocateDirect(message.length);
    buffer.put(message);
    buffer.rewind();
    int transfered = LibUsb.controlTransfer(handle,
        (byte) (LibUsb.REQUEST_TYPE_CLASS | LibUsb.RECIPIENT_INTERFACE | _USB_ENDPOINT_OUT),
        _HID_SET_REPORT,
        (short)(_REPORT_TYPE_FEATURE << 8),//(short) 2,
        (short) 1, buffer, _USB_TIMEOUT_MS);
    
    if (transfered < 0)
        throw new LibUsbException("Control transfer failed", transfered);
    if (transfered != message.length)
        throw new RuntimeException("Not all data was sent to device");
    
    debug("Data sent to device: "+YubikeyUtil.toHexString(message));
    return transfered;
}
 
开发者ID:Toporin,项目名称:yubikey4java,代码行数:28,代码来源:YubikeyConnector.java


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