• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java LibUsbException类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: disconnect

import org.usb4java.LibUsbException; //导入依赖的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: writeMaskedE4KRegister

import org.usb4java.LibUsbException; //导入依赖的package包/类
private void writeMaskedE4KRegister(Register register,
                                      byte mask,
                                      byte value,
                                      boolean controlI2CRepeater) throws LibUsbException
  {
      int temp = readE4KRegister(register, controlI2CRepeater);

/* If the register is not set to the masked value, then change it */
      if((byte) (temp & mask) != value)
      {
          writeE4KRegister(register,
              (byte) ((temp & ~mask) | (value & mask)),
              controlI2CRepeater);

          readE4KRegister(register, controlI2CRepeater);
      }
  }
 
开发者ID:DSheirer,项目名称:sdrtrunk,代码行数:18,代码来源:E4KTunerController.java


示例3: setIFFrequency

import org.usb4java.LibUsbException; //导入依赖的package包/类
public void setIFFrequency(int frequency) throws LibUsbException
  {
      long ifFrequency = ((long) TWO_TO_22_POWER * (long) frequency) /
          (long) mOscillatorFrequency * -1;

/* Write byte 2 (high) */
      writeDemodRegister(mDeviceHandle,
          Page.ONE,
          (short) 0x19,
          (short) (Long.rotateRight(ifFrequency, 16) & 0x3F),
          1);

/* Write byte 1 (middle) */
      writeDemodRegister(mDeviceHandle,
          Page.ONE,
          (short) 0x1A,
          (short) (Long.rotateRight(ifFrequency, 8) & 0xFF),
          1);

/* Write byte 0 (low) */
      writeDemodRegister(mDeviceHandle,
          Page.ONE,
          (short) 0x1B,
          (short) (ifFrequency & 0xFF),
          1);
  }
 
开发者ID:DSheirer,项目名称:sdrtrunk,代码行数:27,代码来源:RTL2832TunerController.java


示例4: findDevice

import org.usb4java.LibUsbException; //导入依赖的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


示例5: setGPIOOutput

import org.usb4java.LibUsbException; //导入依赖的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


示例6: enableI2CRepeater

import org.usb4java.LibUsbException; //导入依赖的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


示例7: writeI2CRegister

import org.usb4java.LibUsbException; //导入依赖的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


示例8: readDemodRegister

import org.usb4java.LibUsbException; //导入依赖的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


示例9: readRegister

import org.usb4java.LibUsbException; //导入依赖的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


示例10: setSampleRate

import org.usb4java.LibUsbException; //导入依赖的package包/类
/**
 * Sets the sample rate to the rate specified by the index value in the
 * available sample rates map
 *
 * @param rate to a sample rate in the available samples rates map.
 * @throws IllegalArgumentException if index is not a valid rate index
 * @throws LibUsbException          if there was a read error or if this operation
 *                                  is not supported by the current firmware
 * @throws UsbException             if there was a USB error
 */
public void setSampleRate(AirspySampleRate rate) throws
    LibUsbException, UsbException, SourceException
{
    if(rate.getRate() != mSampleRate)
    {
        int result = readByte(Command.SET_SAMPLE_RATE, 0, rate.getIndex(), true);

        if(result != 1)
        {
            throw new UsbException("Error setting sample rate [" +
                rate + "] rate - return value [" + result + "]");
        }
        else
        {
            mSampleRate = rate.getRate();
            mFrequencyController.setSampleRate(mSampleRate);
        }
    }
}
 
开发者ID:DSheirer,项目名称:sdrtrunk,代码行数:30,代码来源:AirspyTunerController.java


示例11: setLNAGain

import org.usb4java.LibUsbException; //导入依赖的package包/类
/**
 * Sets LNA gain
 *
 * @param gain - value within range of LNA_GAIN_MIN to LNA_GAIN_MAX
 * @throws LibUsbException          on error in java USB wrapper
 * @throws UsbException             on error in USB transfer
 * @throws IllegalArgumentException if gain value is invalid
 */
public void setLNAGain(int gain)
    throws LibUsbException, UsbException, IllegalArgumentException
{
    if(LNA_GAIN_MIN <= gain && gain <= LNA_GAIN_MAX)
    {
        int result = readByte(Command.SET_LNA_GAIN, 0, gain, true);

        if(result != LibUsb.SUCCESS)
        {
            throw new UsbException("Couldnt set LNA gain to: " + gain);
        }
    }
    else
    {
        throw new IllegalArgumentException("LNA gain value [" + gain +
            "] is outside value range: " + LNA_GAIN_MIN + "-" + LNA_GAIN_MAX);
    }
}
 
开发者ID:DSheirer,项目名称:sdrtrunk,代码行数:27,代码来源:AirspyTunerController.java


示例12: setMixerGain

import org.usb4java.LibUsbException; //导入依赖的package包/类
/**
 * Sets Mixer gain
 *
 * @param gain - value within range of MIXER_GAIN_MIN to MIXER_GAIN_MAX
 * @throws LibUsbException          on error in java USB wrapper
 * @throws UsbException             on error in USB transfer
 * @throws IllegalArgumentException if gain value is invalid
 */
public void setMixerGain(int gain)
    throws LibUsbException, UsbException, IllegalArgumentException
{
    if(MIXER_GAIN_MIN <= gain && gain <= MIXER_GAIN_MAX)
    {
        int result = readByte(Command.SET_MIXER_GAIN, 0, gain, true);

        if(result != LibUsb.SUCCESS)
        {
            throw new UsbException("Couldnt set mixer gain to: " + gain);
        }
    }
    else
    {
        throw new IllegalArgumentException("Mixer gain value [" + gain +
            "] is outside value range: " + MIXER_GAIN_MIN + "-" + MIXER_GAIN_MAX);
    }
}
 
开发者ID:DSheirer,项目名称:sdrtrunk,代码行数:27,代码来源:AirspyTunerController.java


示例13: setIFGain

import org.usb4java.LibUsbException; //导入依赖的package包/类
/**
 * Sets IF (VGA) gain
 *
 * @param gain - value within range of VGA_GAIN_MIN to VGA_GAIN_MAX
 * @throws LibUsbException          on error in java USB wrapper
 * @throws UsbException             on error in USB transfer
 * @throws IllegalArgumentException if gain value is invalid
 */
public void setIFGain(int gain)
    throws LibUsbException, UsbException, IllegalArgumentException
{
    if(IF_GAIN_MIN <= gain && gain <= IF_GAIN_MAX)
    {
        int result = readByte(Command.SET_VGA_GAIN, 0, gain, true);

        if(result != LibUsb.SUCCESS)
        {
            throw new UsbException("Couldnt set VGA gain to: " + gain);
        }
    }
    else
    {
        throw new IllegalArgumentException("VGA gain value [" + gain +
            "] is outside value range: " + IF_GAIN_MIN + "-" + IF_GAIN_MAX);
    }
}
 
开发者ID:DSheirer,项目名称:sdrtrunk,代码行数:27,代码来源:AirspyTunerController.java


示例14: prepareTransfers

import org.usb4java.LibUsbException; //导入依赖的package包/类
/**
 * Prepares (allocates) a set of transfer buffers for use in transferring data from the USB device via the bulk
 * interface.  Since we're using direct allocation (native), buffers are retained and reused across multiple
 * start/stop cycles.
 */
private void prepareTransfers() throws LibUsbException
{
    while(mAvailableTransfers.size() < TRANSFER_BUFFER_POOL_SIZE)
    {
        Transfer transfer = LibUsb.allocTransfer();

        if(transfer == null)
        {
            throw new LibUsbException("Couldn't allocate USB transfer buffer", LibUsb.ERROR_NO_MEM);
        }

        final ByteBuffer buffer = ByteBuffer.allocateDirect(mBufferSize);

        LibUsb.fillBulkTransfer(transfer, mDeviceHandle, USB_BULK_TRANSFER_ENDPOINT, buffer, this,
            "Buffer", USB_TIMEOUT_MS);

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


示例15: setIFFrequency

import org.usb4java.LibUsbException; //导入依赖的package包/类
public void setIFFrequency( int frequency ) throws LibUsbException
{
	long ifFrequency = ( (long)TWO_TO_22_POWER * (long)frequency ) / 
					   (long)mOscillatorFrequency * -1;

	/* Write byte 2 (high) */
	writeDemodRegister( mDeviceHandle, 
						Page.ONE, 
						(short)0x19, 
						(short)( Long.rotateRight( ifFrequency, 16 ) & 0x3F ), 
						1 );
	
	/* Write byte 1 (middle) */
	writeDemodRegister( mDeviceHandle, 
						Page.ONE, 
						(short)0x1A, 
						(short)( Long.rotateRight( ifFrequency, 8 ) & 0xFF ), 
						1 );
	
	/* Write byte 0 (low) */
	writeDemodRegister( mDeviceHandle, 
						Page.ONE, 
						(short)0x1B, 
						(short)( ifFrequency & 0xFF ), 
						1 );
}
 
开发者ID:ac2cz,项目名称:FoxTelem,代码行数:27,代码来源:RTL2832TunerController.java


示例16: setGPIOBit

import org.usb4java.LibUsbException; //导入依赖的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


示例17: setGPIOOutput

import org.usb4java.LibUsbException; //导入依赖的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


示例18: enableI2CRepeater

import org.usb4java.LibUsbException; //导入依赖的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


示例19: writeI2CRegister

import org.usb4java.LibUsbException; //导入依赖的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


示例20: readDemodRegister

import org.usb4java.LibUsbException; //导入依赖的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



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java VKScope类代码示例发布时间:2022-05-22
下一篇:
Java CreateServiceInstanceAppBindingResponse类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap