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


Java LibUsb.SUCCESS属性代码示例

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


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

示例1: sendVendorRequest

/**
 * Sends a vendor request with data (including special bits). This is a
 * blocking method.
 *
 * @param requestType
 *            the vendor requestType byte (used for special cases, usually
 *            0)
 * @param request
 *            the vendor request byte, identifies the request on the device
 * @param value
 *            the value of the request (bValue USB field)
 * @param index
 *            the "index" of the request (bIndex USB field)
 * @param dataBuffer
 *            the data which is to be transmitted to the device (null means
 *            no data)
 */
synchronized public void sendVendorRequest(final byte request, final short value, final short index,
	ByteBuffer dataBuffer) throws HardwareInterfaceException {
	if (!isOpen()) {
		open();
	}

	if (dataBuffer == null) {
		dataBuffer = BufferUtils.allocateByteBuffer(0);
	}

	final byte bmRequestType = (byte) (LibUsb.ENDPOINT_OUT | LibUsb.REQUEST_TYPE_VENDOR | LibUsb.RECIPIENT_DEVICE);

	final int status = LibUsb.controlTransfer(deviceHandle, bmRequestType, request, value, index, dataBuffer, 0);
	if (status < LibUsb.SUCCESS) {
		throw new HardwareInterfaceException("Unable to send vendor OUT request " + String.format("0x%x", request)
			+ ": " + LibUsb.errorName(status));
	}

	if (status != dataBuffer.capacity()) {
		throw new HardwareInterfaceException("Wrong number of bytes transferred, wanted: " + dataBuffer.capacity()
			+ ", got: " + status);
	}
}
 
开发者ID:SensorsINI,项目名称:jaer,代码行数:40,代码来源:CypressFX2.java

示例2: acquireDevice

/**
 * 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,代码行数:20,代码来源:SiLabsC8051F320_LibUsb.java

示例3: sendVendorRequest

/**
 * Sends a vendor request with data (including special bits). This is a
 * blocking method.
 *
 * @param request
 *            the vendor request byte, identifies the request on the device
 * @param value
 *            the value of the request (bValue USB field)
 * @param index
 *            the "index" of the request (bIndex USB field)
 * @param dataBuffer
 *            the data which is to be transmitted to the device (null means
 *            no data)
 *
 * @throws Exception
 *             on any exception
 */
public synchronized void sendVendorRequest(final byte request, final short value, final short index,
	final ByteBuffer buf) throws IOException {
	if (devHandle == null) {
		throw new IllegalStateException("Device is not open, cannot send vendor request.");
	}

	ByteBuffer dataBuffer = buf;
	if (dataBuffer == null) {
		dataBuffer = BufferUtils.allocateByteBuffer(0);
	}

	final byte bmRequestType = (byte) (LibUsb.ENDPOINT_OUT | LibUsb.REQUEST_TYPE_VENDOR | LibUsb.RECIPIENT_DEVICE);

	final int status = LibUsb.controlTransfer(devHandle, bmRequestType, request, value, index, dataBuffer, 0);
	if (status < LibUsb.SUCCESS) {
		throw new IOException("Unable to send vendor OUT request " + String.format("0x%x", request) + ": "
			+ LibUsb.errorName(status));
	}

	if (status != dataBuffer.capacity()) {
		throw new IOException(
			"Wrong number of bytes transferred, wanted: " + dataBuffer.capacity() + ", got: " + status);
	}
}
 
开发者ID:inilabs,项目名称:flashy,代码行数:41,代码来源:UsbDevice.java

示例4: disconnect

/**
 * 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,代码行数:19,代码来源:USBDisplay.java

示例5: init

/**
 * 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,代码行数:24,代码来源:FCDTunerController.java

示例6: write

/**
 * Performs an interrupt write to the OUT endpoint.
 *
 * @param buffer - direct allocated buffer.  Must be 64 bytes in length.
 * @throws LibUsbException on error
 */
private void write(ByteBuffer buffer) throws LibUsbException
{
    if(mDeviceHandle != null)
    {
        IntBuffer transferred = IntBuffer.allocate(1);

        int result = LibUsb.interruptTransfer(mDeviceHandle, FCD_ENDPOINT_OUT, buffer, transferred, 500l);

        if(result != LibUsb.SUCCESS)
        {
            throw new LibUsbException("error writing byte buffer", result);
        }
    }
    else
    {
        throw new LibUsbException("device handle is null", LibUsb.ERROR_NO_DEVICE);
    }
}
 
开发者ID:DSheirer,项目名称:sdrtrunk,代码行数:24,代码来源:FCDTunerController.java

示例7: setLNAGain

/**
 * 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,代码行数:26,代码来源:AirspyTunerController.java

示例8: setMixerGain

/**
 * 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 DeviceException on error in USB transfer
 * @throws IllegalArgumentException if gain value is invalid
 */
public void setMixerGain( int gain ) 
		throws LibUsbException, DeviceException, 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 DeviceException( "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:ac2cz,项目名称:FoxTelem,代码行数:27,代码来源:AirspyDevice.java

示例9: setLNAGain

/**
 * 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 DeviceException on error in USB transfer
 * @throws IllegalArgumentException if gain value is invalid
 */
public void setLNAGain( int gain ) 
		throws LibUsbException, DeviceException, 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 DeviceException( "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:ac2cz,项目名称:FoxTelem,代码行数:27,代码来源:AirspyDevice.java

示例10: run

@Override
public void run()
{
    while ( !mAbort )
    {
        int result = LibUsb.handleEventsTimeout( null, 1000 );
        
        if ( result != LibUsb.SUCCESS )
        {
            mAbort = true;

            Log.errorDialog("ERROR", "error handling usb events [" + 
        			LibUsb.errorName( result ) + "]" );
            
            throw new LibUsbException("Unable to handle USB "
            		+ "events", result );
        }
    }
}
 
开发者ID:ac2cz,项目名称:FoxTelem,代码行数:19,代码来源:RTL2832TunerController.java

示例11: findAllDevices

/**
 * List all Devices on the Computer with a specific vid and pid value
 * 
 * @param vid short
 * @param pid short
 * @return Vector<Device> 
	 * @author yassir
	 */
private Vector<Device> findAllDevices(short vid, short pid) {
	Vector<Device> v_dev = new Vector<Device>();
	try {
		// Iterate over all devices and scan for the right one
		for (Device device : allDevices) {
			DeviceDescriptor descriptor = new DeviceDescriptor();
			int result = LibUsb.getDeviceDescriptor(device, descriptor);
			if (result != LibUsb.SUCCESS)
				throw new LibUsbException(
						"Unable to read device descriptor", result);
			if (descriptor.idVendor() == vid
					&& descriptor.idProduct() == pid)
				v_dev.add(device); // return device;
		}
	} catch (Exception e) {
		e.printStackTrace();
	}
	return v_dev;
}
 
开发者ID:Plug-up,项目名称:daplug-java,代码行数:27,代码来源:DaplugDongleWinusb.java

示例12: openDaplugWinusb

/**
 * Open DaplugDongle with a specific vendor_id and product_id
 * @param vid short the product vendor_id
 * @param pid short the product product_id
 * @return Vector<String> open Daplug Dongle
 * @author yassir
 */
private Vector<Device> openDaplugWinusb(short vid, short pid) {
	Vector<Device> v_dev = new Vector<Device>();
	for (Device device : allDevices) {
		DeviceDescriptor descriptor = new DeviceDescriptor();
		int result = LibUsb.getDeviceDescriptor(device, descriptor);
		if (result != LibUsb.SUCCESS)
			throw new LibUsbException(
					"Unable to read device descriptor", result);
		if (descriptor.idVendor() == vid
				&& descriptor.idProduct() == pid) {
			v_dev.add(device);
		}
	}
	return v_dev;
}
 
开发者ID:Plug-up,项目名称:daplug-java,代码行数:22,代码来源:DaplugDongleWinusb.java

示例13: write

/**
 * Asynchronously writes some data to the device.
 * 
 * @param handle
 *            The device handle.
 * @param data
 *            The data to send to the device.
 * @param callback
 *            The callback to execute when data has been transfered.
 */
public static void write(DeviceHandle handle, byte[] data,
    TransferCallback callback)
{
    ByteBuffer buffer = BufferUtils.allocateByteBuffer(data.length);
    buffer.put(data);
    Transfer transfer = LibUsb.allocTransfer();
    LibUsb.fillBulkTransfer(transfer, handle, OUT_ENDPOINT, buffer,
        callback, null, TIMEOUT);
    System.out.println("Sending " + data.length + " bytes to device");
    int result = LibUsb.submitTransfer(transfer);
    if (result != LibUsb.SUCCESS)
    {
        throw new LibUsbException("Unable to submit transfer", result);
    }
}
 
开发者ID:usb4java,项目名称:usb4java-examples,代码行数:25,代码来源:AsyncBulkTransfer.java

示例14: read

/**
 * Asynchronously reads some data from the device.
 * 
 * @param handle
 *            The device handle.
 * @param size
 *            The number of bytes to read from the device.
 * @param callback
 *            The callback to execute when data has been received.
 */
public static void read(DeviceHandle handle, int size,
    TransferCallback callback)
{
    ByteBuffer buffer = BufferUtils.allocateByteBuffer(size).order(
        ByteOrder.LITTLE_ENDIAN);
    Transfer transfer = LibUsb.allocTransfer();
    LibUsb.fillBulkTransfer(transfer, handle, IN_ENDPOINT, buffer,
        callback, null, TIMEOUT);
    System.out.println("Reading " + size + " bytes from device");
    int result = LibUsb.submitTransfer(transfer);
    if (result != LibUsb.SUCCESS)
    {
        throw new LibUsbException("Unable to submit transfer", result);
    }
}
 
开发者ID:usb4java,项目名称:usb4java-examples,代码行数:25,代码来源:AsyncBulkTransfer.java

示例15: init

public void init(int log_level){
  if(context != null){
    return;
  }

  int result = LibUsb.init(context);
  if (result != LibUsb.SUCCESS) {
    throw new LibUsbException("Unable to initialize libusb.", result);
  }
  
  LibUsb.setDebug(context, log_level);
}
 
开发者ID:diwi,项目名称:PS3Eye,代码行数:12,代码来源:USB.java


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