本文整理汇总了Java中org.usb4java.DeviceHandle类的典型用法代码示例。如果您正苦于以下问题:Java DeviceHandle类的具体用法?Java DeviceHandle怎么用?Java DeviceHandle使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DeviceHandle类属于org.usb4java包,在下文中一共展示了DeviceHandle类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: read_response
import org.usb4java.DeviceHandle; //导入依赖的package包/类
public static byte[] read_response(DeviceHandle handle, boolean may_block){
//""" Wait for a response to become available, and read it. """
// wait for response to become available
ByteBuffer buff= ByteBuffer.allocate(48);
byte[] res = waitforSet(handle, RESP_PENDING_FLAG, may_block);
buff.put(res, 0, 7);
// continue reading while response pending is set
while (true){
res = read(handle);
byte flags = res[7];
if ((flags & RESP_PENDING_FLAG)!=0){
byte seq = (byte)(flags & RESP_TIMEOUT_WAIT_MASK);
if (seq == 0)
break;
buff.put(res, 0, 7);
}
else{
break;
}
}
write_reset(handle);
return buff.array();
}
开发者ID:Toporin,项目名称:yubikey4java,代码行数:24,代码来源:YubikeyConnector.java
示例17: read
import org.usb4java.DeviceHandle; //导入依赖的package包/类
public static byte[] read(DeviceHandle handle)
{
ByteBuffer buffer = ByteBuffer.allocateDirect(_FEATURE_RPT_SIZE);
buffer.rewind();
int transfered = LibUsb.controlTransfer(handle,
(byte) (LibUsb.REQUEST_TYPE_CLASS | LibUsb.RECIPIENT_INTERFACE | _USB_ENDPOINT_IN),
_HID_GET_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 != _FEATURE_RPT_SIZE)
throw new RuntimeException("Not all data was received from device:"+transfered);
byte[] data= new byte[_FEATURE_RPT_SIZE];
buffer.rewind();
for (int i=0; i<_FEATURE_RPT_SIZE; i++){
data[i]= buffer.get();
}
debug("Data received from device: "+YubikeyUtil.toHexString(data));
return data;
}
开发者ID:Toporin,项目名称:yubikey4java,代码行数:25,代码来源:YubikeyConnector.java
示例18: getUsbStringDescriptor
import org.usb4java.DeviceHandle; //导入依赖的package包/类
@Override
public final UsbStringDescriptor getUsbStringDescriptor(final byte index)
throws UsbException
{
checkConnected();
final short[] languages = getLanguages();
final DeviceHandle handle = open();
final short langId = languages.length == 0 ? 0 : languages[0];
final ByteBuffer data = ByteBuffer.allocateDirect(256);
final int result =
LibUsb.getStringDescriptor(handle, index, langId, data);
if (result < 0)
{
throw ExceptionUtils.createPlatformException(
"Unable to get string descriptor " + index + " from device "
+ this, result);
}
return new SimpleUsbStringDescriptor(data);
}
开发者ID:usb4java,项目名称:usb4java-javax,代码行数:20,代码来源:AbstractDevice.java
示例19: getLanguages
import org.usb4java.DeviceHandle; //导入依赖的package包/类
/**
* Returns the languages the specified device supports.
*
* @return Array with supported language codes. Never null. May be empty.
* @throws UsbException
* When string descriptor languages could not be read.
*/
private short[] getLanguages() throws UsbException
{
final DeviceHandle handle = open();
final ByteBuffer buffer = ByteBuffer.allocateDirect(256);
final int result = LibUsb.getDescriptor(handle, LibUsb.DT_STRING,
(byte) 0, buffer);
if (result < 0)
{
throw ExceptionUtils.createPlatformException(
"Unable to get string descriptor languages", result);
}
if (result < 2)
throw new UsbException("Received illegal descriptor length: "
+ result);
final short[] languages = new short[(result - 2) / 2];
if (languages.length == 0) return languages;
buffer.position(2);
buffer.order(ByteOrder.LITTLE_ENDIAN).asShortBuffer().get(languages);
return languages;
}
开发者ID:usb4java,项目名称:usb4java-javax,代码行数:28,代码来源:AbstractDevice.java
示例20: write
import org.usb4java.DeviceHandle; //导入依赖的package包/类
/**
* Writes the specified bytes to a interrupt endpoint.
*
* @param data
* The data array with the bytes to write.
* @param offset
* The offset in the data array to write.
* @param len
* The number of bytes to write.
* @throws UsbException
* When transfer fails.
* @return The number of written bytes.
*/
private int write(final byte[] data, final int offset, final int len)
throws UsbException
{
final UsbEndpointDescriptor descriptor = getEndpointDescriptor();
final byte type = this.pipe.getUsbEndpoint().getType();
final DeviceHandle handle = getDevice().open();
int written = 0;
while (written < len)
{
final int size =
Math.min(len - written, descriptor.wMaxPacketSize() & 0xffff);
final ByteBuffer buffer = ByteBuffer.allocateDirect(size);
buffer.put(data, offset + written, size);
buffer.rewind();
final int result = transfer(handle, descriptor, type, buffer);
written += result;
// Short packet detected, aborting
if (result < size) break;
}
return written;
}
开发者ID:usb4java,项目名称:usb4java-javax,代码行数:36,代码来源:IrpQueue.java
注:本文中的org.usb4java.DeviceHandle类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论